Arduino MessagePort not working (mac)

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Post Reply
Message
Author
Mickolodias
Posts: 69
Joined: Mon Sep 13, 2021 3:21 am

Arduino MessagePort not working (mac)

#1 Post by Mickolodias »

Hi all
Just doing a basic test on a Leonardo - Push a button, see a log in AM. Push a button in AM, see something in the serial monitor of the arduino
I don't see anything either end. My guess is the Arduino is not connecteing to AM at all, I can;t see anything in AM that it is.

Any ideas?

Arduino code:

Code: Select all

#include <si_message_port.hpp>
SiMessagePort* messagePort;
byte btn_state = 1;

static void new_message_callback(uint16_t message_id, struct SiMessagePortPayload* payload) {
  Serial.println(payload->data_string);
}

void setup() {
  Serial.begin(9600);
  messagePort = new SiMessagePort(SI_MESSAGE_PORT_DEVICE_ARDUINO_LEONARDO, SI_MESSAGE_PORT_CHANNEL_G, new_message_callback);
  
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(2,   INPUT_PULLUP);
}

void loop() {
  messagePort->Tick();
  
  byte btn = digitalRead(2);
  if(btn != btn_state) {
    btn_state = btn;
    digitalWrite(LED_BUILTIN,!btn_state);
    messagePort->SendMessage(777, "Hello");
  }
}
AM Code

Code: Select all

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

id = hw_message_port_add("ARDUINO_LEONARDO_G", new_message)

function pressed_callback()
  hw_message_port_send(id, 777, "STRING", "Hiii")
  log("sending")
end

my_button = button_add("image_normal.png", "image_pressed.png", 0, 0, 200, 200, pressed_callback)
I'm one of 'those' mac guys. (and I have no idea why I can't afford to eat)

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

Re: Arduino MessagePort not working (mac)

#2 Post by jph »

Hi,
Have you actually added the 'device' to AM ?

Once the arduino is programmed and connected to the computer, (without opening serial monitor as this needs to be removed! . See below) . Under the HOME tab in AM you need to click the 'device' button in AM, select 'arduino', select the com port and click 'add' (NOTE _ not 'flash' - Device and then Add)
you should then see the Messageport device in the left hand pane after a few seconds - usually 5 to 15 seconds.
If you are seeing that device then it 'should' work but I am not allowed to run a 'mac' on religious grounds ;)

The send from the button on the arduino works as it should on my Kosha Windows PC :D , but note - You can't use the serial print to a console in Arduino as the serial(0) port is already in use by Messageport !. That is how it communicates to AM. It is set to Serial(0) 115Kb n the MP library. - your serial begin etc is overwritten and of no use. If you are opening serial monitor before AM you will stop the port being seen jn AM,! You may well be doing this if you HAVE added the device. That would cause it to never see the device. Remove all your serial statements ant prints.
You can send a 'debug' message instead - back to AM, or you could, if you REALLY wanted to use serial monitor, use an FTDI USB/SERIAL to the second HW serial port on Serial(1) on the Leonardo.

It should look like this -
mptest.jpg
Joe
Joe. CISSP, MSc.

Mickolodias
Posts: 69
Joined: Mon Sep 13, 2021 3:21 am

Re: Arduino MessagePort not working (mac)

#3 Post by Mickolodias »

Ah thanks Joe, I thought it would be something simple.
Of course I hadn't added it to AirManager as a device! Was half asleep trying to get it to work and was looking to the right in the devices section - Shutdown/Flash and couldn't find a way to add it, so figured it must be polling in the background.... duh
I think my brain is so used to ignoring that first button lol.

And thanks for the tip on the serial monitor - I figured it was in use when my text kept appearing without any prints. I'll use the a LED and the debug command to test I've got comms working back to the board.
I'm one of 'those' mac guys. (and I have no idea why I can't afford to eat)

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

Re: Arduino MessagePort not working (mac)

#4 Post by jph »

Hi, no worries :D
It is not the most intuitive at first but probably one of the most exciting parts of AM. It opens up a world of possibilities.
We just need a higher speed data transfer than the 115Kb serial it is fixed to at present. A nice 8 bit parallel transfer or preferably ethernet . (Flutters eyebrows at @Ralph ) :lol:
Glad you got it sorted.
Joe
Joe. CISSP, MSc.

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

Re: Arduino MessagePort not working (mac)

#5 Post by Ralph »

You mean the ESP?

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

Re: Arduino MessagePort not working (mac)

#6 Post by jph »

Ralph wrote: Thu Jul 07, 2022 7:36 amYou mean the ESP?
Oooooooooooo :o tell me more oh wise one :D .... (More fluttering of eyelashes) :oops: :mrgreen:

It needs to be something that works with Arduino IDE and fully programmable - Arduino IDE as virtually every useful device is programmable with the Arduino IDE - even the PICO and new Teensy 4.1 at 600mhz !.

It doesn't have to have a full AM UPD / IP protocol as it can use a simple transfer of data type of system. SISMO use a similar thing and they publish their protocol - it is a fairly simple 20 byte payload.
Joe. CISSP, MSc.

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

Re: Arduino MessagePort not working (mac)

#7 Post by jph »

Just out of interest @Ralph

What sismo do is basically use UDP with a similar format to

UDP data block consisting of -
Init , Mac Address, Port address, Direction in or out identifier, Destination sub board ID, Data byte block

No different data types to bother about, just bytes. Really simple protocol UDP only.
Nice thing is that ANY board that is programmable in arduino IDE can already use a 5 euro ethernet adapter. Adding a 'destination' / address byte allows the user to route the data to sub boards using I2C or SPI - just as you do with the Messageport identifier at the moment.

really simple and nothing of AM proprietary tech exposed at all, yet, offers amazing expansion. In fact is messageport was expanded to up to, say, a max of 32 bytes payload and just stuck to a 'byte' data type then if that was MAC and PORT addressable over UDP that would work really well.
Joe
Joe. CISSP, MSc.

Post Reply