1

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);
  //*/
}
}
  • 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 examples – Martynas Oct 28 '14 at 11:47
  • Please use the code tag. – Werner Kvalem Vesterås Oct 28 '14 at 13:40
  • @werner, where is the code tag? – zalt Oct 28 '14 at 23:23
  • couldn't find the example what I want. I tried the following. Though can't recevive any serial data. – zalt Oct 29 '14 at 7:04
  • I got stucked with this. Any help? – zalt Oct 29 '14 at 7:10
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.