Hints/help needed: Send data from MSFS2020 via Serial port

Hi,
I’m currently building a button box as extension for the X52 throttle base.
For this I need some serial communication. Mobiflight doesn’t help there because I’ve written my own Arduino sketch because of button array and such things.

The Arduino Pro Micro (atmega32u4) waits for some strings through serial to set new colors to SK8612 LEDs.
Those LEDs are the background lighting of a button array which works as an Autopilot panel (AP on/off, FD on/off, ALT on/off and so on).
So I want to send the current AP states from MSFS to the Arduino through serial but only when changed so the LEDs indicate the actual state of each AP mode.

Any ideas how to do this?
I tried SimConnect and Python but since I’m absolutely new to Python I don’t know how to write a Python script that runs continously and reads the values (I got it working when I run the script once, the state gets read from SimConnect and sent to the Arduino, but I don’t know how to do it as “service” or such).

I am doing exactly this via SimConnect in C++.
Works like a charme.

I could help you later but im at work currently.

C++ would be also okay. I’m not good at programming but I learn it by doing my projects instead of reading books or tutorials…and since Arduino is also C it shouldn’t be hard to understand.
It would help if you can tell me just how the script gets executed.

this example from the P3D SimConnect SDK should be helpful:

You could try Mobiflight (https://mobiflight.com)

If you want to learn how to do it I suggest the simconnect route. Im also working on a arduino library and connector if you’d happen to be interested. https://youtu.be/HdnnXQ6SBhg the main point was to avoid having to use or pay something like fsuipc. Disclaimer its still in development so not full fledged. This week I’m releasing a batch of gear, flaps, rudder and trim data. The connector passes the value with a prefix to a selected serial port. The library then stores that value (or you can just split the prefix from the string yourself if desired).

MobiFlight doesn’t work for me since it’s using a dedicated Arduino firmware which doesn’t work with my circuit.

@ffsDaveffs This looks good, I’ll try it when I have time again!

Hi Jannomag

I have a bit more time to respond to your post now, so let’s get at it.

My first thought here, since you are using an atmega32u4, is to forget about serial and just setup your microcontroller as an HID device. Like this you don’t need SimConnect at all and you can just do your bindings in the MFS menu like you would do with other controllers like your x52.
This is by far the easiest approach since you don’t have to anything on the sim side. Youz only need to program your microctroller (btw the “Arduino Pro Micro” is NOT an arduino).
The downside is, that there isn’t so many bindings available in the sim itself. So check first if what you need is available trough direct sim bindings. If not you might need to take the SimConnect Route.

If you decide to go down the SimConnect rabbithole be prepared to sink in some time into that project. I personally started out programming C++ with Arduino and using the Arduino Framework. Looking at some SimConnect code examples it was soon obvious that i need to get a bit more familiar with the C++ standard library and learn to code more like a programmer than an arduino tinkerer. So I was learning more C++ and found this guy Cherno on Youtube. IMO he makes the best C++ videos if you are intrested i will post the link:

Cherno->He has a whole Playlist with about 100 vids on C++

So next talk about IDE’s. I would recommend something a bit more sophisticated than the arduino IDE for the microcontroller programming. I would recommend Visual Studio Code with PlatformIO as a plugin which turns VSCode into a beatifull microcontroller IDE. Try it…
For the Interface that you need to program which will run on your computer and will act as your SimConnect/Serial interface i would recommend Visual Studio(note: Visual Studio and Visual Studio Code are two different programs). There is also a nice video from cherno on how to setup Visual Studio in a nice way:

So now it’s time to download the MFS SDK, setup a C++ project and include the SimConnect library.
Here it’s shown pretty well how to do it:

After all of this you should be able to setup your own C++ project and include SimConnect.h

Now it’s time to play around with SimConnect
Read the MFS SDK Documentation for SimConnect(which is still ■■■■■■ unfortunately) and more important read the P3D SimConnect documentation. There you will find code examples that will help you a lot to get going.
Here is the online P3D SDK documentation:
https://www.prepar3d.com/SDKv5/LearningCenter.php
The documentation from MFS you will download with the SDK that you download.

At this stage you will be able to interface SimConnect but what about Serial Communication?

You will need your own Serial Class. If your a passionate and experienced coder you would probably just write this on your own. It was a bit much for me to do this myself so i’m just using Serial.h/Serial.cpp from this github-> Connect-And-Use-Arduino-via-Cpp-Software-Made-In-Any-IDE/Arduino2PC_SC at master · ZainUlMustafa/Connect-And-Use-Arduino-via-Cpp-Software-Made-In-Any-IDE · GitHub
I modified it a bit for my purposes but it should work right away

So, i guess that will get you started. Have fun!
Cheers André

2 Likes

I will read this when I have the time for this again, thanks.

The Atmega32u2 already works like a HID using the joystick library.
I need the communication from MSFS to Arduino - therefore the serial port.

I’m using an Arduino Uno for 4 rotary encoders(hdg, obs1, obs2, altimeter) & 3way flap switch.
I used Visual Studio to make a simple C# program communicating with MSFS via simconnect.

Used Prepar3d SDK examples (available online here) to put it together.