My attempt is to know how to identify the board I'll be sending parameters to in a serial connection like rs485. I'm asking because I will have about 11 or so mcu's as "Rx slaves" while my pc is the Master "Tx". I want to know how my code block is being sent to a specific board will be received by just that board and not all the other boards connected to that Rx port COM?
If I send 'LT2|LP3|LM5|LR4|LI6' and I want that to be for one specific Arduino, I don't want all the other 10 arduinos to take those parameters in this serial Rx line.
@Federico Fissore you mentioned in another post "Some boards, when connected to a computer, publish their serial number. My Arduino Uno R3 says"
[16818.451423] usb 3-2: SerialNumber: 85235353137351E02242
how and where can i find this info?
-
You can't; it's locked up in the other chip.Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2015年09月03日 16:55:03 +00:00Commented Sep 3, 2015 at 16:55
-
@ Ignacio Vazquez-Abram dam! ok thanks thought i can just use that to add to my const unique address before i Tx to serialFrank– Frank2015年09月03日 17:20:21 +00:00Commented Sep 3, 2015 at 17:20
-
The simplest thing would be to burn a serial number into each chip's EEPROM, and interrogate that at startup.Nick Gammon– Nick Gammon ♦2015年09月03日 21:39:29 +00:00Commented Sep 3, 2015 at 21:39
-
@Nick Gammon i dont think that could have sounded more advance for me then anything thus far lol any links on how to go about that ? im just not getting the big picture thanks!Frank– Frank2015年09月04日 00:08:57 +00:00Commented Sep 4, 2015 at 0:08
-
Related to your other thread: I'm looking for a way to Serially communicate with a multi mesh Arduino Slave NetworkNick Gammon– Nick Gammon ♦2015年09月04日 05:37:25 +00:00Commented Sep 4, 2015 at 5:37
2 Answers 2
I dont think that could have sounded more advanced for me then anything thus far. Any links on how to go about that?
First, run a sketch like this for each board:
#include <EEPROM.h>
const int SERIAL_NUMBER_ADDRESS = 1023;
const byte SERIAL_NUMBER = 42;
void setup ()
{
// don't do it if it has been done before
if (EEPROM.read(SERIAL_NUMBER_ADDRESS) != SERIAL_NUMBER)
EEPROM.write(SERIAL_NUMBER_ADDRESS, SERIAL_NUMBER);
} // end of setup
void loop () { }
The serial number address can be any address in range for that chip - a Uno has 1024 bytes. I chose 1023 to leave the other addresses free, but it could be 0. Anything you don't need for any other purpose.
Then write a different serial number to each board (eg. 42, 43, 44, 45). Obviously you change the sketch each time you upload to a different board.
Once you have done this (once per board) now each board "knows" its serial number. You can detect this in your main sketch:
#include <EEPROM.h>
const int SERIAL_NUMBER_ADDRESS = 1023;
byte serialNumber;
void setup ()
{
Serial.begin (115200);
Serial.println ();
serialNumber = EEPROM.read(SERIAL_NUMBER_ADDRESS);
Serial.print (F("Serial number of this board is: "));
Serial.println (int (serialNumber));
} // end of setup
void loop () { }
Output for me in this case was:
Serial number of this board is: 42
Also I have a post about RS485 on my forum.
Just assign every node a variable like "const int ID = 5" and so on and then before sending the instructions send a line terminator, the ID, line terminator and the data you need to send to the nodes. Every device listens but they all wait their ID to accept the commands. For example:
Serial.write('\n');
Serial.print(ID);
Serial.write('\n');
Serial.print(|LT2|LP3|LM5|LR4|LI6);
Serial.write('\n');
NOTE: This is the easiest way. Most likely not the most reliable or optimized.
-
Comments are not for extended discussion; this conversation has been moved to chat. (cc @Frank'sDesig'Nature)Anonymous Penguin– Anonymous Penguin2015年09月04日 00:58:49 +00:00Commented Sep 4, 2015 at 0:58
-
2why not just use a usb tower and connect all my arduino's to that tower usb style just like when they plug into my pc and connect the other end of the usb tower into my pc ? doesn't that sound more easy and less complex? this way i can just use the # of the com port as the address?Frank– Frank2015年09月04日 17:51:10 +00:00Commented Sep 4, 2015 at 17:51
-
@Frank Yes that would work.Avamander– Avamander2016年01月21日 21:15:34 +00:00Commented Jan 21, 2016 at 21:15