Due to Server-Relocation there might be downtimes for Forum/Supportdesk/Online-Services (Profiles/Snippets) from 19th-21st July 2019. To prevent problems it will not be possible to purchase any licenses in this period.

Arduino - Serial Device

Discussion about special hardware
User avatar
Oz Flyer
Betatester
Posts: 673
Joined: 23 Sep 2015, 10:10
Location: YMMB, Melbourne, Australia
Contact:
Status: Offline

Arduino - Serial Device

Post by Oz Flyer » 01 Jul 2019, 00:16

Started first project:

Starting on a Radio Stack using the Arduino Mega2560.
First tests are going well using an LCD at this time for testing but hope to move to 7 Segment displays later down the line.

Startup Screen.
P1010120.JPG
COM1 ACT & Standby Freq Display.
P1010121.JPG
Will share more as I go.

Tell us what projects are the rest of you all looking at?
You do not have the required permissions to view the files attached to this post.
David
OZ Flyer
Near YMMB
40+ year of Flight Siming.
subLOGIC/Microsoft Flight Sim/DTG, Microsoft Flight, DTG FSW.

User avatar
Oz Flyer
Betatester
Posts: 673
Joined: 23 Sep 2015, 10:10
Location: YMMB, Melbourne, Australia
Contact:
Status: Offline

Re: Arduino - Serial Device

Post by Oz Flyer » 01 Jul 2019, 00:24

Update: (Copied from Support).
lesoreilly wrote:
30 Jun 2019, 18:46

Can you share where you are at with that -- ie the Arduino Project?

Might be quicker building point that the example that people are having issue with....I was making a TXPDR out of the same Shield you have but on an UNO....Though now I am thinking to try to make a "stack" out of the 4 Line Display module instead..
RE Example - Are you using the GITHUB version? if you are using the old one from the Wiki page then re-download from GITHUB.

So far I have only got it displaying the Freq as displayed in photo.
I have add COM:2 on the 2nd line now.

Have not got the ACT/STBY switch working yet.
David
OZ Flyer
Near YMMB
40+ year of Flight Siming.
subLOGIC/Microsoft Flight Sim/DTG, Microsoft Flight, DTG FSW.

aeronauta
Betatester
Posts: 555
Joined: 13 Mar 2015, 03:06
Location: Melbourne Australia YMMB
Status: Offline

Re: Arduino - Serial Device

Post by aeronauta » 01 Jul 2019, 00:40

I would like some more info , the cmdmessenger examples from the lib are very basic and do not explain the workings of Ulricch .ino .
Is there a place to learn ao a more in depth info link somewhere...? so far all the work seems to e with numbers , I tried bool function and could not get it to work...

Jorge

User avatar
Oz Flyer
Betatester
Posts: 673
Joined: 23 Sep 2015, 10:10
Location: YMMB, Melbourne, Australia
Contact:
Status: Offline

Re: Arduino - Serial Device

Post by Oz Flyer » 01 Jul 2019, 04:59

aeronauta wrote:
01 Jul 2019, 00:40
I would like some more info , the cmdmessenger examples from the lib are very basic and do not explain the workings of Ulricch .ino .
Is there a place to learn ao a more in depth info link somewhere...? so far all the work seems to e with numbers , I tried bool function and could not get it to work...

Jorge
I am NO programmer but if you send me the code I will take a quick look at it if you would like.
David
OZ Flyer
Near YMMB
40+ year of Flight Siming.
subLOGIC/Microsoft Flight Sim/DTG, Microsoft Flight, DTG FSW.

aeronauta
Betatester
Posts: 555
Joined: 13 Mar 2015, 03:06
Location: Melbourne Australia YMMB
Status: Offline

Re: Arduino - Serial Device

Post by aeronauta » 01 Jul 2019, 06:25

I got it , just the way the expose has to be Bool and the bool (lower case) and messengerreadBoolArg... that fixed it ... here is my ino with alt hdg and parking brake, it uses pin 7 and 8 plus the original 13

// *** SNDEMO ***

// This example shows how to autoconnect between the SPAD.neXt and Arduino.
//
// It demonstrates how to
// - Respond to a connection request from SPAD.neXt
// - Use a identifier to handshake
// - Expose a data value to SPAD.neXt
// - Request Data Updates from SPAD.neXt

#include <CmdMessenger.h> // CmdMessenger

// Internal led
const int ledPin = 13;
const int Pin8led = 8;
const int Pin7led = 7;

// Listen on serial connection for messages from the pc
CmdMessenger messenger(Serial);

// This is the list of recognized commands. These can be commands that can either be sent
// or received.
// In order to receive, attach a callback function to these events
enum
{
kRequest = 0, // Request from SPAD.neXt
kCommand = 1, // Command to SPAD.neXt
kEvent = 2, // Events from SPAD.neXt
kDebug = 3, // Debug strings to SPAD.neXt Logfile
kLedH = 10, // CMDID for exposed data to SPAD.neXt
kLedP = 11, // CMDID for exposed data to SPAD.neXt
kHeading = 12, // CMDID for data updates from SPAD.neXt
kAltitude = 13, //CMDID for data updates from Spad.nex
kPBrake = 14 // CMDID for data updates from Spad.next
};

void attachCommandCallbacks()
{
// Attach callback methods
messenger.attach(onUnknownCommand);
messenger.attach(kRequest , onIdentifyRequest);
messenger.attach(kLedH , onTurnLedOn);
messenger.attach(kLedP , onTurnLedOn);
messenger.attach(kHeading , onHeadingLockChanged);
messenger.attach(kAltitude , onAltitudeChanged);
messenger.attach(kPBrake , onPBrakeChanged);
}

// ------------------ C A L L B A C K S -----------------------

// Called when a received command has no attached function
void onUnknownCommand()
{
messenger.sendCmdStart(kDebug);
messenger.sendCmdArg("UNKNOWN COMMAND");
// messenger.sendCmdArg(messenger.lastCommandId);
// messenger.sendCmdArg(messenger.commandBuffer);
messenger.sendCmdEnd();
}

// Callback function to respond to indentify request. This is part of the
// Auto connection handshake.
void onIdentifyRequest()
{
char *szRequest = messenger.readStringArg();

if (strcmp(szRequest, "INIT") == 0) {
messenger.sendCmdStart(kRequest);
messenger.sendCmdArg("SPAD");
// Unique Device ID
messenger.sendCmdArg(F("{DD7E3826-E439-4484-B186-A1443F3BC521}"));
// Device Name for UI
messenger.sendCmdArg("Arduino Jorge");
messenger.sendCmdEnd();
return;
}

if (strcmp(szRequest, "PING") == 0) {
messenger.sendCmdStart(kRequest);
messenger.sendCmdArg("PONG");
messenger.sendCmdArg(messenger.readInt32Arg());
messenger.sendCmdEnd();
return;
}
if (strcmp(szRequest, "CONFIG") == 0) {

// Expose System LED
messenger.sendCmdStart(kCommand);
messenger.sendCmdArg("ADD");
messenger.sendCmdArg(kLedH);
messenger.sendCmdArg("leds/systemled"); // will become "SERIAL:<guid>/leds/systemled"
messenger.sendCmdArg("U8");
messenger.sendCmdArg("RW");
messenger.sendCmdArg("LedH");
messenger.sendCmdArg("Toggle LED on/off");
messenger.sendCmdEnd();

// Request Heading Lock Dir Updates
messenger.sendCmdStart(kCommand);
messenger.sendCmdArg("SUBSCRIBE");
messenger.sendCmdArg(kHeading);
messenger.sendCmdArg("SIMCONNECT:AUTOPILOT HEADING LOCK DIR");
messenger.sendCmdEnd();

// Expose 8 LED
messenger.sendCmdStart(kCommand);
messenger.sendCmdArg("ADD");
messenger.sendCmdArg(kLedP);
messenger.sendCmdArg("leds/Pin8led"); // will become "SERIAL:<guid>/leds/Pin8led"
messenger.sendCmdArg("U8");
messenger.sendCmdArg("RW");
messenger.sendCmdArg("LedP");
messenger.sendCmdArg("Toggle LED on/off");
messenger.sendCmdEnd();

// Request Altitude Updates
messenger.sendCmdStart(kCommand);
messenger.sendCmdArg("SUBSCRIBE");
messenger.sendCmdArg(kAltitude);
messenger.sendCmdArg("SIMCONNECT:AUTOPILOT ALTITUDE LOCK VAR");
messenger.sendCmdEnd();

// Expose 7 LED
messenger.sendCmdStart(kCommand);
messenger.sendCmdArg("ADD");
messenger.sendCmdArg(kPBrake);
messenger.sendCmdArg("leds/Pin7led"); // will become "SERIAL:<guid>/leds/Pin7led"
messenger.sendCmdArg("Bool");
messenger.sendCmdArg("RW");
messenger.sendCmdArg("PBrake");
messenger.sendCmdArg("Toggle LED on/off");
messenger.sendCmdEnd();

// Request Parking Brake Updates
messenger.sendCmdStart(kCommand);
messenger.sendCmdArg("SUBSCRIBE");
messenger.sendCmdArg(kPBrake);
messenger.sendCmdArg("SIMCONNECT:BRAKE PARKING INDICATOR");
messenger.sendCmdEnd();


// tell SPAD.neXT we are done with config
messenger.sendCmd(kRequest, "CONFIG");
return;
}
}

// Callback to perform some action
void onTurnLedOn()
{
int32_t newLed = messenger.readInt32Arg();
if (newLed == 1)
{
digitalWrite(ledPin, HIGH);
digitalWrite(Pin8led, HIGH);
digitalWrite(Pin7led, HIGH);
messenger.sendCmd(kDebug, "LED COMMAND ON");
}
else
{
digitalWrite(ledPin, LOW);
digitalWrite(Pin8led, LOW);
digitalWrite(Pin7led, LOW);
messenger.sendCmd(kDebug, "LED COMMAND OFF");

// When we turned it off we unsubscribe from the heading lock for demo purpose
messenger.sendCmdStart(kCommand);
messenger.sendCmdArg("UNSUBSCRIBE");
messenger.sendCmdArg(kHeading);
messenger.sendCmdArg("SIMCONNECT:AUTOPILOT HEADING LOCK DIR");
messenger.sendCmdEnd();

messenger.sendCmdStart(kCommand);
messenger.sendCmdArg("UNSUBSCRIBE");
messenger.sendCmdArg(kAltitude);
messenger.sendCmdArg("SIMCONNECT:AUTOPILOT ALTITUDE LOCK VAR");
messenger.sendCmdEnd();

messenger.sendCmdStart(kCommand);
messenger.sendCmdArg("UNSUBSCRIBE");
messenger.sendCmdArg(kPBrake);
messenger.sendCmdArg("SIMCONNECT:BRAKE PARKING INDICATOR");
messenger.sendCmdEnd();

}
}

// LED on if Heading > 180 else off;
void onHeadingLockChanged()
{
int32_t newHeading = messenger.readInt32Arg();
if (newHeading > 180)
{
digitalWrite(ledPin, HIGH);
messenger.sendCmd(kDebug, "HEADING > 180");
}
else
{
digitalWrite(ledPin, LOW);
messenger.sendCmd(kDebug, "HEADING < 180");
}
}

// LED on if ALT LOCK > 500 else off;
void onAltitudeChanged()
{
int32_t Altitude = messenger.readInt32Arg();
if (Altitude > 500 )
{
digitalWrite(Pin8led, HIGH);
messenger.sendCmd(kDebug, "Altitude > 500");
}
else
{
digitalWrite(Pin8led, LOW);
messenger.sendCmd(kDebug, "Altitude < 500");
}
}

// LED on if Parking Brake ON else off;
void onPBrakeChanged()
{
bool ParkingBrake = messenger.readBoolArg();
if (ParkingBrake == 1 )
{
digitalWrite(Pin7led, HIGH);
messenger.sendCmd(kDebug, "Parking == 1");
}
else
{
digitalWrite(Pin7led, LOW);
messenger.sendCmd(kDebug, "Parking == 0");
}
}

// ------------------ M A I N ----------------------

// Setup function
void setup()
{
// Listen on serial connection for messages from the pc

// 115200 is typically the maximum speed for serial over USB
Serial.begin(115200);

// Attach my application's user-defined callback methods
attachCommandCallbacks();

// initialize the digital pin as an output.
pinMode(ledPin, OUTPUT);
pinMode(Pin8led, OUTPUT);
pinMode(Pin7led, OUTPUT);

// Make sure led is turned off after start or reset

digitalWrite(ledPin, LOW);
digitalWrite(Pin8led, LOW);
digitalWrite(Pin7led, LOW);

}

// Loop function
void loop()
{
// Process incoming serial data, and perform callbacks
messenger.feedinSerialData();
}


Is there a way to attach files or make the att smaller??

Jorge

aeronauta
Betatester
Posts: 555
Joined: 13 Mar 2015, 03:06
Location: Melbourne Australia YMMB
Status: Offline

Re: Arduino - Serial Device

Post by aeronauta » 01 Jul 2019, 08:38

I guess reading an LVAR would be the same as reading simconnect call it L;xxxx , will try this next and then the oposite , make a sw in the Arduino do somethng in the SIM...

any clues?? the examples in the cmdmessenger don't show anything...


Jorge

User avatar
Oz Flyer
Betatester
Posts: 673
Joined: 23 Sep 2015, 10:10
Location: YMMB, Melbourne, Australia
Contact:
Status: Offline

Re: Arduino - Serial Device

Post by Oz Flyer » 01 Jul 2019, 11:57

Calling LVAR's

After talking with Ulrich, this is what is needed for LVAR's:
1) Find LVAR you want
2) Use "addons/EXPRESSIONS / Add Expression / Add DAta" to check exact name.
Ie. my CH-47 has an LVAR of "ac bus1" when listed in the monitor when check it is "AC BUS1"
3) So you would use "LVAR:AC BUS1"

Line would be:
messenger.sendCmdArg("LVAR:AC BUS1");
David
OZ Flyer
Near YMMB
40+ year of Flight Siming.
subLOGIC/Microsoft Flight Sim/DTG, Microsoft Flight, DTG FSW.

aeronauta
Betatester
Posts: 555
Joined: 13 Mar 2015, 03:06
Location: Melbourne Australia YMMB
Status: Offline

Re: Arduino - Serial Device

Post by aeronauta » 02 Jul 2019, 00:45

Yes thank you , I had the LVARS sorted also , all the reading from Spad is OK , I need now some way to write to Spad with switches... no idea!!...

Jorge

aeronauta
Betatester
Posts: 555
Joined: 13 Mar 2015, 03:06
Location: Melbourne Australia YMMB
Status: Offline

Re: Arduino - Serial Device

Post by aeronauta » 03 Jul 2019, 07:56

I have downloaded the latst version of the demo , it contains some changes that correct the ready state of the dev and some code at the end that I thought was updating the led state in Spad monitor , but I do not see any change , still shows -1 ..

Jorge

aeronauta
Betatester
Posts: 555
Joined: 13 Mar 2015, 03:06
Location: Melbourne Australia YMMB
Status: Offline

Re: Arduino - Serial Device

Post by aeronauta » 04 Jul 2019, 08:19

Running the latest version , looked at the log to understand a bit more and found a few "Unknown Command" among the correct 3, heading < 180" and > 180...as I changed the HDG

Here is the log

Jorge
You do not have the required permissions to view the files attached to this post.

Post Reply