-2

Currently I'm stuck sending data from one xbee series1 to another xbee series1 (both are connected to an Arduino unor3). Here is the program for sending data.

#include <eHealth.h>

#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1); // RX, TX

float temperature;

char xbeedata[4];

// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(9600);  
}

// the loop routine runs over and over again forever:
void loop() {
  temperature = eHealth.getTemperature();


  memcpy(xbeedata, &temperature, 4);    // send data


  Serial.print("Temperature (ºC): ");       
  Serial.print(temperature, 2);  
  Serial.println(""); 

 delay(1000);   // wait for a second 
}

the program for the receiving end is

 #include <eHealth.h>

#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1); // RX, TX

float temperature;

char *xbeedata[4];

// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(9600);  
}

// the loop routine runs over and over again forever:
void loop() {
  temperature = eHealth.getTemperature();

  memcpy(&temperature, xbeedata, 4);    // receive data


  Serial.print("Temperature (ºC): ");       
  Serial.print(temperature, 2);  
  Serial.println(""); 

  delay(1000);  // wait for a second 
}

Am I lacking things? I'm supposed to send the float like this float temperature->byte array ->xbee(send) -> xbee(receive) -> byte array -> float temperature -> display on serial monitor. I'm currently using the Arduino IDE.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Is `Serial` a serial port connected to the XBee, or is that your console? Where is the code that sends the 4 bytes from one XBee to the other? What is working so far? Can you send strings of text from one Arduino to the other? Sending the 4 bytes of a float isn't very portable -- different platforms may store their floating point numbers in different formats and not necessarily IEEE 754. – tomlogic Aug 26 '14 at 23:21

1 Answers1

0

Try to multiply your float value for 100 and save it into a int variable, then you can convert int to string like String(Yourintvariable) and convert to char array to send it to the serial, note that serial convert automatically chars to byte. I hope I have helped.

best regards

Rui Oliveira
  • 13
  • 1
  • 5