Current SPAD.neXt Release: 0.9.12.123
This forum has closed. Please join our Discord Community.
SPAD.neXt online services are no longer available for SPAD.neXt Versions < 0.9.11.5
Some hints for Arduino + SPAD.next (FS2020)
Some hints for Arduino + SPAD.next (FS2020)
I don't have the energy to write a complete guide, but I want to share some info that would have saved me a lot of time in the last week trying to figure out how the Arduino interface works with FS2020.
This is for people already experienced with arduinos, but struggling to figure out how the serialdemo sketch from https://github.com/c0nnex/SPAD.neXt/tree/master/Scripts works with the limited amount of documentation.
Again, not a guide, just some important hints.
This does *not* use an arduino pro micro configured as a joystick, but any arduino using normal serial communication on a usb port. (I'm using an arduino nano)
First, this video helps explain the serial device connection and debugging: https://www.youtube.com/watch?v=Vs8Yf5Q9xNY
After uploading your sketch to the Arduino using the Arduino IDE:
In settings, go to serial devices, add new device. Select the correct com port, 115200, dtr off, 32 bit off.
Restart SPAD.next and go back to the serial devices. There should now be a device listed with a disconnect and connect button. Connect to use it with FS2020, disconnect to free the com port to upload using Arduino IDE.
Arduino sketch tips
To toggle a single switch in FS2020:
messenger.sendCmd(kSimCommand,"SIMCONNECT:AP_PANEL_HEADING_HOLD");
when a hardware button is pressed. (You don't have to add anything to the command list or callbacks to send SimCommands).
Some useful switches that works(toggle):
SIMCONNECT:AP_PANEL_HEADING_HOLD
MSFS:FLIGHT_LEVEL_CHANGE
SIMCONNECT:AP_ALT_HOLD
SIMCONNECT:AP_PANEL_VS_HOLD
SIMCONNECT:TOGGLE_GPS_DRIVES_NAV1
SIMCONNECT:AP_NAV_SELECT_SET
To directly control autopilot value (for example with a rotary encoder):
Add a function to the command list
kAltitude = 12, //(increment the number for each command(?))
Add a callback:
// Request Altitude Lock Dir Updates
messenger.sendCmdStart(kCommand);
messenger.sendCmdArg("SUBSCRIBE");
messenger.sendCmdArg(kAltitude);
messenger.sendCmdArg("SIMCONNECT:AUTOPILOT ALTITUDE LOCK VAR");
messenger.sendCmdEnd();
Send the value from the encoders. I send them 10 times per second as I don't know the performance impact of sending continously.
messenger.sendCmd(kAltitude,testValue);
I don't know if this is the correct way to do it, but it works. I now have 5 rotary encoders on an arduino nano controlling the most important functions of the autopilot.
Good luck experimenting!
This is for people already experienced with arduinos, but struggling to figure out how the serialdemo sketch from https://github.com/c0nnex/SPAD.neXt/tree/master/Scripts works with the limited amount of documentation.
Again, not a guide, just some important hints.
This does *not* use an arduino pro micro configured as a joystick, but any arduino using normal serial communication on a usb port. (I'm using an arduino nano)
First, this video helps explain the serial device connection and debugging: https://www.youtube.com/watch?v=Vs8Yf5Q9xNY
After uploading your sketch to the Arduino using the Arduino IDE:
In settings, go to serial devices, add new device. Select the correct com port, 115200, dtr off, 32 bit off.
Restart SPAD.next and go back to the serial devices. There should now be a device listed with a disconnect and connect button. Connect to use it with FS2020, disconnect to free the com port to upload using Arduino IDE.
Arduino sketch tips
To toggle a single switch in FS2020:
messenger.sendCmd(kSimCommand,"SIMCONNECT:AP_PANEL_HEADING_HOLD");
when a hardware button is pressed. (You don't have to add anything to the command list or callbacks to send SimCommands).
Some useful switches that works(toggle):
SIMCONNECT:AP_PANEL_HEADING_HOLD
MSFS:FLIGHT_LEVEL_CHANGE
SIMCONNECT:AP_ALT_HOLD
SIMCONNECT:AP_PANEL_VS_HOLD
SIMCONNECT:TOGGLE_GPS_DRIVES_NAV1
SIMCONNECT:AP_NAV_SELECT_SET
To directly control autopilot value (for example with a rotary encoder):
Add a function to the command list
kAltitude = 12, //(increment the number for each command(?))
Add a callback:
// Request Altitude Lock Dir Updates
messenger.sendCmdStart(kCommand);
messenger.sendCmdArg("SUBSCRIBE");
messenger.sendCmdArg(kAltitude);
messenger.sendCmdArg("SIMCONNECT:AUTOPILOT ALTITUDE LOCK VAR");
messenger.sendCmdEnd();
Send the value from the encoders. I send them 10 times per second as I don't know the performance impact of sending continously.
messenger.sendCmd(kAltitude,testValue);
I don't know if this is the correct way to do it, but it works. I now have 5 rotary encoders on an arduino nano controlling the most important functions of the autopilot.
Good luck experimenting!
Re: Some hints for Arduino + SPAD.next (FS2020)
Well, now we're getting somwhere....
Thanks a lot.
Thanks a lot.
Re: Some hints for Arduino + SPAD.next (FS2020)
You actually don't need to subscribe to a value to change it, like I wrote in the previous post. You only need to subscribe to read it.
To send a command with a variable:
messenger.sendCmdStart(kSimCommand);
messenger.sendCmdArg("HEADING_BUG_SET");
messenger.sendCmdArg(HeadingVariable);
messenger.sendCmdEnd();
When sending a command directly like this, use an event name from the joystick input list, not from the simconnect output list.
To send a command with a variable:
messenger.sendCmdStart(kSimCommand);
messenger.sendCmdArg("HEADING_BUG_SET");
messenger.sendCmdArg(HeadingVariable);
messenger.sendCmdEnd();
When sending a command directly like this, use an event name from the joystick input list, not from the simconnect output list.
Re: Some hints for Arduino + SPAD.next (FS2020)
Can someone help me how to read variable from simulator. I want read "SIMCONNECT:AUTOPILOT ALTITUDE LOCK VAR"
Re: Some hints for Arduino + SPAD.next (FS2020)
example:
//add Global variable
long altitude;
enum{
//add
kAltitude = 12,
}
void attachCommandCallbacks(){
//add
messenger.attach(kAltitude , onAltitudeLockChanged);
}
if (strcmp(szRequest, "CONFIG") == 0) {
//add
messenger.sendCmdStart(kCommand);
messenger.sendCmdArg("SUBSCRIBE");
messenger.sendCmdArg(kAltitude);
messenger.sendCmdArg("SIMCONNECT:AUTOPILOT ALTITUDE LOCK VAR");
messenger.sendCmdEnd();
//add
void onAltitudeLockChanged()
{
altitude = messenger.readInt32Arg();
messenger.sendCmd(kDebug, altitude); //It's for debugging, so it doesn't have to be
}
Please add it referring to "Heading" in the sample.
In this case, "long altitude" is the value of Altitude.
It is a little different from getting the current value because it is the value after the change.
If you want to send a command, you can write it on one line.
messenger.sendCmd(kSimCommand,"SIMCONNECT:AP_ALT_VAR_SET_ENGLISH,5000");
I hope it will be helpful.
//add Global variable
long altitude;
enum{
//add
kAltitude = 12,
}
void attachCommandCallbacks(){
//add
messenger.attach(kAltitude , onAltitudeLockChanged);
}
if (strcmp(szRequest, "CONFIG") == 0) {
//add
messenger.sendCmdStart(kCommand);
messenger.sendCmdArg("SUBSCRIBE");
messenger.sendCmdArg(kAltitude);
messenger.sendCmdArg("SIMCONNECT:AUTOPILOT ALTITUDE LOCK VAR");
messenger.sendCmdEnd();
//add
void onAltitudeLockChanged()
{
altitude = messenger.readInt32Arg();
messenger.sendCmd(kDebug, altitude); //It's for debugging, so it doesn't have to be
}
Please add it referring to "Heading" in the sample.
In this case, "long altitude" is the value of Altitude.
It is a little different from getting the current value because it is the value after the change.
If you want to send a command, you can write it on one line.
messenger.sendCmd(kSimCommand,"SIMCONNECT:AP_ALT_VAR_SET_ENGLISH,5000");
I hope it will be helpful.
Re: Some hints for Arduino + SPAD.next (FS2020)
Thanks! Really helpful.
Re: Some hints for Arduino + SPAD.next (FS2020)
The "Connect/Disconnect" buttons are not even visible when I add the serial port that my clone Mega2560 is on.
What do I need to do to get it to recognize it?
What do I need to do to get it to recognize it?
- c0nnex
- Site Admin
- Posts: 5469
- Joined: 10 Mar 2015, 21:52
- Location: Munich, Germany
- Contact:
- Status: Offline
Re: Some hints for Arduino + SPAD.next (FS2020)
Make sure DTR and 32Bit Settings are correct.
Re: Some hints for Arduino + SPAD.next (FS2020)
Morning all,
Could I bring your attention to this post.
Really appreciate some help with the final step.
Pete.
Could I bring your attention to this post.
Really appreciate some help with the final step.
Pete.
I'm Pete, AKA: Redscouse, owner and creator of Scouse Airlines.
Since MS2000, I've been tinkering with liveries, missions and scenery etc.
Check out the download section of my website and grab some free stuff!
Since MS2000, I've been tinkering with liveries, missions and scenery etc.
Check out the download section of my website and grab some free stuff!