I try to send serial data RPM to XBee series1 and then from XBee to another XBee wirelessly in API with Escapes Mode. I think I have to send the data Frame.But not very sure. Any help?
Following is the code to read RPM and send to XBee?
#include <XBee.h>
#include <SoftwareSerial.h>
/* Serial communication with Xbee.
On Arduino pin 9 is Rx connect to Xbee Tx,
pin 8 is Txconnect to Xbee Rx*/
SoftwareSerial xbeeSerial(9, 8); // RX, TX
XBee xbee = XBee();
int pin = 7; //7
float rpm;
float duration;
float y;
unsigned long val,time;
float rps;
float read_rpm;
uint8_t start_data[] = { 0x7E, 0x00, 0x50, 0x01, 0x01, 0xff, 0xff,0x00, 0x05, 0x00,0x01,0x03, 0x84, 0x00 };
void setup()
{
Serial.begin(9600);
pinMode(pin, INPUT);
Serial.println("I am ready to send some RPM!");
xbeeSerial.begin(9600);
time = millis();
}
void loop()
{
void loop()// run over and over
{
val = pulseIn(pin, LOW,70000000);
duration=(float)val/1000000.00;
rps= 1.00/duration;
rpm=60.00*rps;
/* Sending float to Xbee
Float is 4 byte size*/
serialFloatPrint(rpm);
int floatToInt = (int)rpm;
/* To send INT to XBEE
Int is 2 byte size*/
xbeeSerial.write(highByte(floatToInt));
xbeeSerial.write(lowByte(floatToInt));
Serial.write(0x03);
delay(2000);
}
void serialFloatPrint(float f) {
byte * b = (byte *) &f;
//xbeeSerial.print("f:");
xbeeSerial.print(b[0]);
xbeeSerial.print(b[1]);
xbeeSerial.print(b[2]);
xbeeSerial.print(b[3]);
/* DEBUG */
Serial.println();
Serial.print(b[0],BIN);
Serial.print(b[1], BIN);
Serial.print(b[2], BIN);
Serial.println(b[3], BIN);
//*/
}
}