Arduino Uno not connecting

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Arduino Uno not connecting

#11 Post by Sling »

JohnF wrote: Sun Jun 13, 2021 10:12 am I have had this working on Uno and Mega, I have tried the demo sketch now and it works, however loading my sketch does not, I have checked all the message port code and it is identical to the demo but it does not work. Is there a critical time between ticks??
Clearly it isn’t identical else it would work seeing as you have proven the demo works. It’s obviously something you are adding so without seeing your code it’s gonna hard to guess. Usual troubleshooting techniques should narrow down the culprit.

JohnF
Posts: 45
Joined: Tue Feb 02, 2021 10:51 am

Re: Arduino Uno not connecting

#12 Post by JohnF »

OK after much head scratching, I put some error checking code in which used the serial port, and it is this that was affecting the connection.

JohnF
Posts: 45
Joined: Tue Feb 02, 2021 10:51 am

Re: Arduino Uno not connecting

#13 Post by JohnF »

I have solved one problem which was the serial port I added to fault find on code, It stops the coms to Airmanager.
The next problem is that if you try and send a message via message port before the connect between Airmanager and Arduino id established , this causes Airmanager not to connect to the Arduino. Is there a way to detect when Airmanager has established a connection with the Arduino?

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Arduino Uno not connecting

#14 Post by Sling »

Try the hw_connected() function.

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

Re: Arduino Uno not connecting

#15 Post by jph »

Sling wrote: Mon Jun 14, 2021 8:51 am Try the hw_connected() function.
I dont believe that is for the actual connection of the device !, it is for the ancillary items.

@JohnF
The issue seems to be that you are overloading the receive buffer in AM with constant sending which would not happen in real world use (although I haven't seen your code) - if, for example, you comment out one of the test examples in the basic example code, then you will be hammering the output / hence rx buffer which would be unrealistic as in normal use the Arduino would only send code to AM in the case of an event - ie - something changing.

Please try to get into the habit of NEVER using 'delay' etc in Arduino code (or any really ;) )

Try the example below with a single example tx uncommented, but with a delay added - that still allows program execution. This is more akin to Real World.
#include <si_message_port.hpp>

SiMessagePort* messagePort;

// for our delay interval
int interval = 3000;
unsigned long millis_now = 0;

static void new_message_callback(uint16_t message_id, struct SiMessagePortPayload* payload) {
// We received a message from Air Manager or Air Player
}

void setup() {
// Init library on channel A and Arduino type MEGA 2560
messagePort = new SiMessagePort(SI_MESSAGE_PORT_DEVICE_ARDUINO_LEONARDO, SI_MESSAGE_PORT_CHANNEL_C, new_message_callback);
}

void loop() {
// Make sure this function is called regularly
messagePort->Tick();


if(millis() >= millis_now + interval){
millis_now += interval;
// Send a message with id 777 and three bytes payload to the instrument
//uint8_t payload[3] = { 0x00, 0x01, 0x02 };
//messagePort->SendMessage(777, payload, 3);

// There are multiple payload types available (integer, float, byte and string)
messagePort->SendMessage(777, "hello world"); // String
//messagePort->SendMessage(777, (int32_t)-890); // Integer
//messagePort->SendMessage(777, 5.6f); // Float
}
}
Last edited by jph on Mon Jun 14, 2021 9:20 am, edited 1 time in total.
Joe. CISSP, MSc.

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

Re: Arduino Uno not connecting

#16 Post by jph »

@JohnF
John,
you can adjust the 'int interval = value to virtually anything you want to simulate the update of your code TX NOT THE TICK()

For example, the same code based on the above but with a 50mS update for data without effecting tick()
Works fine - Forget that it signs on as Leonardo - that bit is purely a name, the code is the same. You can change it to Mega or Uno etc.
#include <si_message_port.hpp>

SiMessagePort* messagePort;

// for our delay interval
int interval = 50;
unsigned long millis_now = 0;

static void new_message_callback(uint16_t message_id, struct SiMessagePortPayload* payload) {
// We received a message from Air Manager or Air Player
}

void setup() {
// Init library on channel A and Arduino type MEGA 2560
messagePort = new SiMessagePort(SI_MESSAGE_PORT_DEVICE_ARDUINO_LEONARDO, SI_MESSAGE_PORT_CHANNEL_C, new_message_callback);
}

void loop() {
// Make sure this function is called regularly
messagePort->Tick();


if(millis() >= millis_now + interval){
millis_now += interval;
// Send a message with id 777 and three bytes payload to the instrument
//uint8_t payload[3] = { 0x00, 0x01, 0x02 };
//messagePort->SendMessage(777, payload, 3);

// There are multiple payload types available (integer, float, byte and string)
messagePort->SendMessage(777, "hello world"); // String
//messagePort->SendMessage(777, (int32_t)-890); // Integer
//messagePort->SendMessage(777, 5.6f); // Float
}
}
It is also important that you do not send a constant non-changing value - for example reading an adc every loop and sending the data regardless of if it has changed or not. ! . the data from Arduino to am only need to be sent WHEN it changes hence your code should look at the incoming data from your connected devices - to the Arduino - and only send when needed. For example, in the case of an ADC input etc, then very small fluctuations can be applied to a filter prior to determining if the value has actually changed in a meaningful manner. Perhaps @Corjan could comment ?
Joe
Joe. CISSP, MSc.

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Arduino Uno not connecting

#17 Post by Sling »

jph wrote: Mon Jun 14, 2021 9:09 am
Sling wrote: Mon Jun 14, 2021 8:51 am Try the hw_connected() function.
I dont believe that is for the actual connection of the device !, it is for the ancillary items.
If hw_connected() returns true then the device is connected. So yes it can be used to check the connection.

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

Re: Arduino Uno not connecting

#18 Post by jph »


If hw_connected() returns true then the device is connected. So yes it can be used to check the connection.
Please define a 'device' in relation to a complete board connection ? (as opposed to looking at individual ancillary connections to the device). That would be informative.
Joe. CISSP, MSc.

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Arduino Uno not connecting

#19 Post by Sling »

jph wrote: Mon Jun 14, 2021 10:24 am

If hw_connected() returns true then the device is connected. So yes it can be used to check the connection.
Please define a 'device' in relation to a complete board connection ? (as opposed to looking at individual ancillary connections to the device). That would be informative.
Device is irrelevant in this context. If an individual pin returns as connected then by definition the board must be connected.

JohnF
Posts: 45
Joined: Tue Feb 02, 2021 10:51 am

Re: Arduino Uno not connecting

#20 Post by JohnF »

I Have that bit working now, Thanks.

Post Reply