xbee with arduino

Good night guys, I'm developing a project for measuring electrical current with Xbee for remote transmission. I am using two Arduinos, two Xbee, and a current sensor sct-013-000. Each Xbee is connected to an Arduino through Xbee Shield. 

The measurement of electrical current could have, but did not know how to convey an Arduino to another. And this you receive need to print the Serial Monitor. 

Sorry for the english, I'm using the translator. I'm here in Brazil.

Robert Wall's picture

Re: xbee with arduino

I found this page with Google search for "arduino xbee serial communication"
http://arduino.cc/en/Guide/ArduinoWirelessShieldS2
It tells me that after you have set the Xbee, the Arduinos will talk using serial. But you have only one serial port on each Arduino! You must have two, one for the Xbee and one for your computer.
This page https://learn.sparkfun.com/tutorials/xbee-shield-hookup-guide tells me that you must have an Explorer board that allows you to connect an XBee to your computer in place of one Arduino.

leandro.garcao's picture

Re: xbee with arduino

Thanks for your help friend, but I really need to make communication with each side of an Arduino. It is my final course project, is complex, but I'll get ...

leandro.garcao's picture

Re: xbee with arduino

Anyone have any other idea?

leandro.garcao's picture

Re: xbee with arduino

Good evening friends, I managed communication between XBee modules, but the information reaches the receiver in ASCII, how can I convert to decimal?

Robert Wall's picture

Re: xbee with arduino

You receive the characters '1' '2' '3' and you want the integer 0x7B for example?
You could try the C standard library (scanf), but that is likely to be expensive on memory. If the possible range of formats and values is limited - ['0'-'9' and '.'], you might be better writing your own routine, checking each character as it comes in and building up the result character by character.

leandro.garcao's picture

Re: xbee with arduino

When a value 2 is sent, the receiver reaches 50. I need to know how I'm going to present the other side float values ​​like 12.80 for example. I do some conversion, but how?

Robert Wall's picture

Re: xbee with arduino

50 is the decimal ASCII code for the character '2'. If you subtract 48 - the decimal ASCII code for the character '0' - from 50, you have the decimal value 2, which is what you want. Then, if there is another character waiting, you multiply 2 by ten, calculate the value of the next character that was waiting and add it. And so on until you get a '.' Then you need to divide the next character value by 10 before you add it, the one after by 100, and so on.

So taking your example 12.80

'1' - '0' = 1
'2' is waiting
1 x 10 = 10
'2' - '0' = 2
10 + 2 = 12
'.' is waiting
stop multiplying by 10
'8' is waiting
'8' - '0' = 8
8 / 10 = 0.8
12 + 0.8 = 12.8
'0' is waiting
'0' - '0' = 0
0 / 100 = 0.00
12.8 + 0.00 = 12.80
no more characters, finished.

All this is very, very elementary programming. You need to read a book like Kernighan & Ritchie if you want to learn to program in C or C++.

leandro.garcao's picture

Re: xbee with arduino

Good day friend, below is the schedule at the receiver. Please help. The problem is that it is printing every other line digit by digit. The first line prints 1, the second 2 ... need to join in just a number, for example the number 12.80.

int incomingByte;
int i;

void setup() {
  // initialize serial communication:
  Serial.begin(9600);

}

void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    i = incomingByte - 48;  //conversion to decimal

    Serial.print(i);
    Serial.println();
    delay(1000);
  }
}

Robert Wall's picture

Re: xbee with arduino

Read again what I wrote on Mon, 27/10/2014 at 13:42.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.