Go Down

Topic: Programming for voltage readout through Arduino leonardo and Xbee series 1 (Read 1 time) previous topic - next topic

PaulS

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.

33chen

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.

Code: [Select]
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

PaulS

If, instead of:
Code: [Select]
                 Serial.print(myData, DEC);
you used
Code: [Select]
                 Serial.println(myData, DEC);
the output would be useful.

33chen

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

PaulS

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.

Go Up