Programming for voltage readout through Arduino leonardo and Xbee series 1

Hello.

Could someone tell me how to receive data from XBee series 1 on Arduino Leonardo ? (Sorry I may aslo put this topic on arduino project section)
I can receive any data from my xbee transmitter which is connected with a potentiometer, and totally get lost... Any correction on my code would be sincerely appreciated.

My enviroments.

two Xbees are well configured using X-CTU software (from digiKey) and has been tested without using leonardo. Right now I have my xbee receiver connected to leonardo through xbee shield. I would like to use a code to achieve voltage readout from my potentiometer which is connected with my xbee transimtter. Potentiometer voltage signal sends to DIO pin in xbee transmitter. 3.3V DC power is supplied to both Xbee trasmitter and potentiomter. And 3.3V pin and RES on my xbee transmitter has been wired together.

I followed the advice from this thread ( http://arduino.cc/forum/index.php/topic,114936.0.html). physically connect a 100uF capacitor (monolithic type, no polarity issue involved) the 3.3v pin and RES on my xbee receiver (which is what they call the shield's xbee) and run a IDE code looking like below:

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  while(!Serial){}; //required for the Leonardo
  
}

void loop() {
  while(Serial.available()>0){ 
    Serial1.write(Serial.read());// input from Serial to Serial1
  }
  while(Serial1.available()>0){
    Serial.write(Serial1.read()); //input from Serial1 to Serial
  }

  // read the input pin:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (3.3 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);
     delay(1);
 }

Let me know what I should do next. Thanks a lot.

Any suggestions would be appreciated!Thank you.

Any suggestions would be appreciated!Thank you.

Somehow, I doubt that the suggestion that you have some patience is going to be appreciated. Bumping a thread after 4 hours is silly.

Let me know what I should do next.

That really depends on what you want to do. What is it you want to do?

Why are you echoing everything that the transmitter receives? If there is any reason for the sender to be sending the data, you should be reading it and doing something about it. Those first 6 lines in loop() are fine for determining that the XBee is configured properly. Once you know that they are, delete them.

Paul,

Thanks alot. As a newbie here, I will definitely take your advice to be a little more patient.

What I try to do right now is to try read out voltage signal from my potentiometer. As mentioned previously, my pot is attached to a Xbee transmitter. I want to use the xbee communication system and arduino leonardo to readout the voltage. If I can make it work, what I want to do next is to use the xbee and arduino system to achieve remote mouse control.

Just make sure if I did it right:

  1. Do I need to physically connect or solder a 100uF capacitor between 3.3V and RES at the Shield's Xbee (Xbee receiver)?

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  while(!Serial){}; //required for the Leonardo
  
}

void loop() {
  while(Serial.available()>0){ 
    Serial1.write(Serial.read());// input from Serial to Serial1
  }

  // read the input pin:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (3.3 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);
     delay(1);
 }

Thank you.

Ji

Hi Paul,

Just want to update what I have done. I removed the capacitor from the Xbee receiver (on Xbee shield) and switch the Xbee shield from Dline back to UART. And run the following code. I start to receive some thing from my serial monitor on IDE software. But apparently that is not voltage value.

int incomingByte = 0;   // for incoming serial data
 
void setup() {
         Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
         Serial1.begin(9600);
         while(!Serial){
           ;
       }
       }
 
void loop() {
 
   while(Serial1.available()>0){
    Serial.write(Serial1.read()); //input from Serial1 to Serial
  }
        // send data only when you receive data:
         if (Serial.available() > 0) {
                 // read the incoming byte:
                 incomingByte = Serial.read();
   float voltage = incomingByte*(3.3/1023);
                // say what you got:
                 //Serial.print("I received: ");
                 //Serial.println(incomingByte, DEC);
                 Serial.println(voltage);
         }
 }

What I receive from serial monitor can be seen in attachment. Do I need to parse the data from serial read.

If the sender is sending ASCII data, why are you using Serial.write() to echo it back out? Serial.write() is for sending binary data.

More importantly, though, why are you printing unidentified stuff to the Serial port? Everything printed to the serial port should have some kind of identification associated with it, so you can KNOW what was printed.

It looks, though, like the baud rate of the serial monitor does not match the baud rate of the sketch, or the two XBees are not using the same baud rate.

Paul,

Thanks a lot. Feel grateful to you for always providing constructive suggestion technically and morally. As you pointed out, the voltage singal I would like to deliver from one-to one Xbee communication system should be ASCII type data, I modified my code.

int myData = 0;   // for incoming serial data
 
void setup() {
         Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
         Serial1.begin(9600);
         while(!Serial){
           ;
       }
       }
 
void loop() {
 
   while(Serial1.available()>0){
    myData = Serial.print(Serial1.read()); //input from Serial1 to Serial
  }
        // send data only when you receive data:
         if (Serial.available() > 0) {
                 // read the incoming byte:
                // incomingByte = Serial.parseFloat();
   // float voltage =incomingByte*3.3;
                // say what you got:
                 //Serial.print("I received: ");
                 Serial.print(myData, DEC);
                // Serial.println(incomingByte);
         }
 }

The readout from serial monitor pop up window is
1260101311852520120325525312601013118525201200100155

If, instead of:

                 Serial.print(myData, DEC);

you used

                 Serial.println(myData, DEC);

the output would be useful.

Just made a change as you recommened. The seria monitor shows the following. It looks a little familiar to me. I once used a matlab code to parse out the actual data information. But in arduino code, do I still need to parse? Essentially, i want to use the voltage signal to achieve remote control of PC mouse.

3
82
178
126
0
10
131
18
52
44
0
1
2
0
3
255
5
126

What is providing the voltage that the sender is measuring?

How is that voltage going to be useful for moving a mouse?

The output you are showing does not make sense. The values should be the ASCII codes for the numbers in the float being sent, so most of them should be in the range 48 to 57, with 10, 13 and the value for the decimal point in there, too.

What is providing the voltage that the sender is measuring?

The potentiometer is providing the voltage that the xbee sender is measuring. The voltage signal goes to the Pin DIO0 on the Xbee sender.

How is that voltage going to be useful for moving a mouse?

I once did a little project that follows the example on the arduino website. By phyiscally connecting a potentiometer signal line to pin A0 on Arduino leonardo board. I can achieve the mouse control by controlling the voltage of potentiometer. I try to see if I can do it remotely by sending the voltage through the xbee wireless system to still control the mouse.

The output you are showing does not make sense. The values should be the ASCII codes for the numbers in the float being sent, so most of them should be in the range 48 to 57, with 10, 13 and the value for the decimal point in there, too.

Should I use analogread() or any other syntax to make the serial data back to ASCII codes?

The voltage signal goes to the Pin DIO0 on the Xbee sender.

But, the Arduino doesn't know anything about stuff attached to the XBee. If you are not going to use an Arduino on the sending end, you need to use API mode and Andrew Rapp's XBee library on the receiver.

Hi Paul,

It would be a difficult process for me to grasp API in a short time. The reason i didnt group leonardo with the sender side of Xbee is because I want to have the sender size as simple and small in terms of volume as possible. I have read some API informtion on Xbee manual and not quite understand so far. What I need to do is only to have some way to convert the serial data to voltage value (recognized by Leonardo) and then control the mouse.

Any good example similar to my case rings your bell? Thanks.

What I need to do is only to have some way to convert the serial data to voltage value (recognized by Leonardo) and then control the mouse.

The sender code you showed initially was for an Arduino. The Arduino is reading data from an analog pin, converting that to a voltage value, and sending the value as a string.

Now, you say that the sensor is connected to the XBee's digital pin, not the Arduino. So, what the Arduino is reading is noise. Surely, you don't want to move your mouse based on noise.

It's time for you to post a schematic showing what is connected to what on the sending end.

If the analog sensor is really connected to a digital pin on the XBee, then there is no way in hell you are going to get or send good data from it.

If the sensor is connected to an analog pin on the XBee, AND the XBee is configured to read and send that pin's data, then on the receiver you must use API mode, no matter how hard it is, because API mode is the ONLY way that the XBee sends digital and analog pin data that it reads.

The reason I connect 5v pin of my xbee sender to 3.3v power supply, is , that it seems that 5v DC supply to my Xbee sender doest give me correct readout from my Xbee receiver. Attached is schematic detail of my project and pictures of my sender and receiving side.

schematic drawing and picture of my project .pdf (294 KB)

Paul,

Attached is my schematic drawing. Any similar example you think I can follow for the API configuration. Thanks