Page 1 of 1

sending data back to the arduino

Posted: Thu Jul 14, 2022 3:20 pm
by dpiddy
I have connected dozens of knobs, devices etc. via Arduino to air manager and the data flows from the arduino one way to air manager. Now for the first time I have the need for air manager to send data back to the arduino but i just cant seem to get it to function.

When I do this inside air manager -

-- This function will be called when a message is received from the Arduino.
function new_message(id, payload)


hw_message_port_send(id, 77) -- the offending line, just hard coding while testing

-- COM1
if (id ==1) then

print(" com1 " .. payload .. " " .. id)

if payload == "ON" then
new_comtransfer()
end

end

end


I get this in the console

ERROR - logic.lua:266: Argument 'id(1)' in function 'hw_message_port_send' is not a valid reference, which is not allowed



Back at the arduino, this is where I would expect to see the data from air manager

static void new_message_callback(uint16_t message_id, struct SiMessagePortPayload* payload) {

//
// // We received a message from Air Manager or Air Player
//
Serial.println("FROM AIRMANAGER");
Serial.println( message_id);

display.showNumber(77.77);

}


Any assistance would be appreciate or even just some working source code i could peruse.

Dave

Re: sending data back to the arduino

Posted: Thu Jul 14, 2022 3:29 pm
by Keith Baxter
Hi

Why are you using message port ?

Keith

Re: sending data back to the arduino

Posted: Thu Jul 14, 2022 4:07 pm
by dpiddy
On the air manager example site, the example says -

-- Send a message to the Arduino with id 777 and 3 bytes as payload (0x01, 0x02, 0x03)
hw_message_port_send(id, 777, "BYTE[3]", { 1, 2, 3 })


am i missing something?

Re: sending data back to the arduino

Posted: Thu Jul 14, 2022 4:14 pm
by jph
Start at the very beginning.
What exactly are you trying to achieve ?

Give a simple example -

For instance --- maybe you want to turn an an LED when 'x' happens ....

As Keith said, why are you using messageport ?

Just tell us what you want to do - start simple.

Re: sending data back to the arduino

Posted: Thu Jul 14, 2022 4:49 pm
by dpiddy
I'm using message port because that is the only example I have found.

This is for a comm stack. When the rotary encoder connected to the arduino or a button is pressed, it updates the frequency in air manager. Also, if the comm frequency is updated using the mouse on the air manager panel I need the code on the arduino to react to the updated comm frequency value. I am trying to send that value back to the arduino so the 7 segment display can be updated.


is this the wrong place to find an example?
https://siminnovations.com/wiki/index.php?title=Arduino

Re: sending data back to the arduino

Posted: Thu Jul 14, 2022 5:27 pm
by Keith Baxter
Hi
What you try is MOSTLY available from the store.There are many hardware "Radios" that use the basic AM interface to arduino.

It would help if the Airframe and sim platform are you working with is revealed so that better answers could assist you.

Keith

Re: sending data back to the arduino

Posted: Mon Jul 18, 2022 7:41 pm
by dpiddy
I am using MS flight simulator 2020 and an arduino uno

Is this documentation simply wrong?
https://siminnovations.com/wiki/index.php?title=Arduino

Re: sending data back to the arduino

Posted: Mon Jul 18, 2022 9:20 pm
by Ralph
No, but as the red message says, you don't have to use the library. As Keith mentioned, most functionality can be found pre scripted. Unless you want to do it all yourself :)

Re: sending data back to the arduino

Posted: Tue Jul 19, 2022 10:37 am
by jph
@dpiddy
It looks like you re trying to use a TM1637 from the display.shownumber you used in your arduino code in the text

You do not need to use siMessagePort at all for this, that is for advanced functionality only. You only need to flash the arduino, exactly as as you have done in the past as you say you have already connected lots of buttons etc into Air Manager, but not sent any data yet FROM am.

If you are using a TM1637 4 digit then all you need is this -

Code: Select all

-- Create a new TM1637 based character display
display_chr_id = hw_chr_display_add("NAV1 frequency", "TM1637", 4)

-- Set text "77.77"
hw_chr_display_set_text(display_chr_id,"77.77")
The pin selection on the arduino is the same method as used on your buttons, switches etc.

As per your inputs that you already used, you can check what is already built into AM for outputs by looking here https://siminnovations.com/wiki/index.p ... _Logic_API and checking under the 'hardware' section.

Again, you do not need messageport at all.

Re: sending data back to the arduino

Posted: Wed Jul 20, 2022 7:23 pm
by dpiddy
I found the issue with my code, my original code was:

id = hw_message_port_add("ARDUINO_MEGA2560_A", new_message)

then in my function:
function new_message(id, payload)

hw_message_port_send(id, 77) -- the offending line, the problem is the local id variable is confused with the global id.

changing the variable to something else and it all worked perfectly!
xid = hw_message_port_add("ARDUINO_MEGA2560_A", new_message)


what a rookie mistake!