im trying to read data from arduino via Xbee Api mode (xbee pro s2b). i dont know how to program in processing at all. like make a graph or just display the data. please anybody help me. is there a tutorial that can help me with an explanation?? or anybody willing to give a little program??
my code in arduino :
#include "XBee.h"
/*
This example is for Series 2 XBee
Sends a ZB TX request with the value of analogRead(pin5) and checks the status response for success
*/// create the XBee object
XBee xbee = XBee();// we are going to send two floats of 4 bytes each
uint8_t payload[4] = { 0, 0, 0, 0};// union to convery float to byte string
union u_tag {
uint8_t b[4];
float fval;
} u;// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x406F4973);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();int statusLed = 13;
int errorLed = 13;void flashLed(int pin, int times, int wait) {
for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(wait);
digitalWrite(pin, LOW);if (i + 1 < times) {
delay(wait);
}
}
}void setup() {
pinMode(statusLed, OUTPUT);
pinMode(errorLed, OUTPUT);
xbee.begin(9600);
}void loop() {
float h = 1.034; //for example i send float = 1.034
{u.fval = h;
for (int i=0;i<4;i++){
payload_=u.b*;_
_ }*_* xbee.send(zbTx);*
* // flash TX indicator*
* flashLed(statusLed, 1, 100);** // after sending a tx request, we expect a status response*
* // wait up to half second for the status response*
* if (xbee.readPacket(500)) {*
* // got a response!** // should be a znet tx status *
* if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
_ xbee.getResponse().getZBTxStatusResponse(txStatus);*_* // get the delivery status, the fifth byte*
* if (txStatus.getDeliveryStatus() == SUCCESS) {*
* // success. time to celebrate*
* flashLed(statusLed, 5, 50);*
* } else {*
* // the remote XBee did not receive our packet. is it powered on?*
* flashLed(errorLed, 3, 500);*
* }*
* }*
* } else if (xbee.getResponse().isError()) {*
* //nss.print("Error reading packet. Error code: "); *
* //nss.println(xbee.getResponse().getErrorCode());*
* } else {*
* // local XBee did not provide a timely TX Status Response -- should not happen*
* flashLed(errorLed, 2, 50);*
* }*
* }*
* delay(1000);*
}
[/quote]
i convert float to byte string
// union to convery float to byte string
union u_tag {
* uint8_t b[4];
_ float fval;
} u;
then
float h = 1.034 u.fval = h;
for (int i=0;i<4;i++){
payload=u.b;*
i wanna show the data in PC and i use processing but i dont know at all.
please anybody help me to convert back from byte string to float and show in processing.
Thanks in advance._