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);
//*/
}
}
asked Oct 28, 2014 at 6:50
-
As @TMa showed, download this library and first test the communication without any RPM calculation. When you will be sure you get good messages on another arduino, then add rpm and etc... In Xbee-Arduino library there are examplesMartynas– Martynas2014年10月28日 11:47:30 +00:00Commented Oct 28, 2014 at 11:47
-
Please use the code tag.Werner Kvalem Vesterås– Werner Kvalem Vesterås2014年10月28日 13:40:30 +00:00Commented Oct 28, 2014 at 13:40
-
@werner, where is the code tag?zalt– zalt2014年10月28日 23:23:55 +00:00Commented Oct 28, 2014 at 23:23
-
couldn't find the example what I want. I tried the following. Though can't recevive any serial data.zalt– zalt2014年10月29日 07:04:48 +00:00Commented Oct 29, 2014 at 7:04
-
I got stucked with this. Any help?zalt– zalt2014年10月29日 07:10:56 +00:00Commented Oct 29, 2014 at 7:10
1 Answer 1
You are using it as in non-API mode when data are passed to Xbee wireless transparently. To use Xbee in API mode use e.g. Xbee-Arduino library.
lang-cpp