sending data back to the arduino

Peer support for Air Manager desktop users

Moderators: russ, Ralph

Post Reply
Message
Author
dpiddy
Posts: 12
Joined: Mon Apr 25, 2022 1:20 pm

sending data back to the arduino

#1 Post 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

User avatar
Keith Baxter
Posts: 4685
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: sending data back to the arduino

#2 Post by Keith Baxter »

Hi

Why are you using message port ?

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

dpiddy
Posts: 12
Joined: Mon Apr 25, 2022 1:20 pm

Re: sending data back to the arduino

#3 Post 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?

User avatar
jph
Posts: 2856
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: sending data back to the arduino

#4 Post 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.
Joe. CISSP, MSc.

dpiddy
Posts: 12
Joined: Mon Apr 25, 2022 1:20 pm

Re: sending data back to the arduino

#5 Post 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

User avatar
Keith Baxter
Posts: 4685
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: sending data back to the arduino

#6 Post 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
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

dpiddy
Posts: 12
Joined: Mon Apr 25, 2022 1:20 pm

Re: sending data back to the arduino

#7 Post 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

User avatar
Ralph
Posts: 7924
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: sending data back to the arduino

#8 Post 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 :)

User avatar
jph
Posts: 2856
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: sending data back to the arduino

#9 Post 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.
Joe. CISSP, MSc.

dpiddy
Posts: 12
Joined: Mon Apr 25, 2022 1:20 pm

Re: sending data back to the arduino

#10 Post 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!

Post Reply