Hi,
I set up a three node network in Digimesh using S1 radios. Each node is configured to send and receive data from other node and it is happening fine which I checked with X-CTU console.
Now I need to know how to program to take the serially communicated data and display in serial monitor when they are connected with Arduino. Each node must be able to send to and receive data from other two nodes and able to identify from which node it came and display the received data in serial monitor.
I set up a three node network in Digimesh using S1 radios.
How? A series 1 radio communicates with one other radio.
Each node is configured to send and receive data from other node
To and from which other node?
Now I need to know how to program to take the serially communicated data
That depends on how the XBee is connected to the Arduino.
Each node must be able to send to and receive data from other two nodes and able to identify from which node it came and display the received data in serial monitor.
Without using API mode, you can't do this. With API mode, and Andrew Rapp's XBee library, it is trivial. Believe it or not, there are even examples provided with the library.
How? A series 1 radio communicates with one other radio.
To and from which other node?
The node 1 can send and receieve data from node 2 and 3.Similarly each node can send and receive data from other two nodes.
This is carried out by configuring them in Digimesh mode.
That depends on how the XBee is connected to the Arduino.
Xbee is connected to the arduino using x-bee shield.here is the link for the product
http://shieldlist.org/libelium/xbee
Each node must be able to send to and receive data from other two nodes and able to identify from which node it came and display the received data in serial monitor.
I sent an address identifier say 1 for node 1,2 for node 2 and so on along with data for each node. I want the receiver to identify the source of the data by identifying this identifier.
code at the sender:
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print('l');
Serial.print('H');
delay(1000);
Serial.print('l');
Serial.print('L');
delay(1000);
}
code at the receiver:
int incomingByte; //a variable to read data
int add;// a variable to read identifier
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 1) {
Serial.print("start");
add=Serial.read();
//if identifier is 1,print the received data
if (add==1)
{
Serial.println("first node");
incomingByte = Serial.read();
Serial.write(incomingByte);
}
}
}
On the sender, you send an identifier of '1', but on the receiver, you check the value against 1. '1' and 1 aren't the same value.
You also don't read the second byte if the identifier doesn't match. That will cause it to get it off sync very fast.
Hi Arrch,
Thanks for pointing out.I thought both represent numeral 1. I was wondering Why the control doesn't enter the loop.Now I get it.
So should the program at the receiver must be modified like this?
if (add=='1')
{
Serial.println("first node");
incomingByte = Serial.read();
Serial.write(incomingByte);
}
I am beginner. So please pardon me if I am making some silly mistakes
Hi paulS,
Without using API mode, you can't do this. With API mode, and Andrew Rapp's XBee library, it is trivial. Believe it or not, there are even examples provided with the library.
Can you send me those examples which you mentioned?
Can you send me those examples which you mentioned?
Why? They come with the library. If you have the library, you have the examples. If you don't, then code I sent you wouldn't compile, so I'd be wasting my time.
viz_90:
Hi Arrch,
Thanks for pointing out.I thought both represent numeral 1. I was wondering Why the control doesn't enter the loop.Now I get it.
So should the program at the receiver must be modified like this?if (add=='1')
{
Serial.println("first node");
incomingByte = Serial.read();
Serial.write(incomingByte);
}
I am beginner. So please pardon me if I am making some silly mistakes
There is no loop in what you posted, post your entire sketch. You also shouldn't be using Serial to communicate with both the serial monitor AND the other Arduino.
this is the code at receivers end
int incomingByte; //a variable to read data
int add;// a variable to read identifier
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 1) {
Serial.print("start");
add=Serial.read();
//if identifier is 1,print the received data
if (add=='1')
{
Serial.println("first node");
incomingByte = Serial.read();
Serial.write(incomingByte);
}
}
}
You also shouldn't be using Serial to communicate with both the serial monitor AND the other Arduino.
Is there any other way to communicate to serial monitor other than serial?
How to communicate then with serial other than
int incomingByte; //a variable to read data
int add;// a variable to read identifier
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 1) {
Serial.print("start");
add=Serial.read();
//if identifier is 1,print the received data
if (add=='1')
{
Serial.println("first node");
incomingByte = Serial.read();
Serial.write(incomingByte);
}
}
}
Again:
You also don't read the second byte if the identifier doesn't match. That will cause it to get it off sync very fast.
Even if you were to read both regardless of if the identifier matches, a single missed digit and you're out of sync. I think you should re-think your strategy. State machines are the best way to handle this. You would send a "start packet" byte, then the identifier, then the value. If the length of the value could vary, you would want to also send a "stop packet" byte. The state machine would accept the incoming byte as its input and have states such as SEEKING_START_BYTE, SEEKING_IDENTIFIER and SEEKING_VALUE.
Is there any other way to communicate to serial monitor other than serial?
Not with a regular Arduino
How to communicate then with serial other than
Assuming you're using an Uno or other single UART device, you can use the SoftwareSerial library.
Hi arrch,
State machines are the best way to handle this
what do you mean by state machine?.API mode?
you can use the SoftwareSerial library.
Do you have any examples for this?
Do you have any examples for this?
There aren't any. No one else has ever use SoftwareSerial.
what do you mean by state machine?
Have your google skills completely gone away?