Go Down

Topic: xbee simple program code for view processing graph (Read 5375 times) previous topic - next topic

nassery

hi. hello everyone here. i'm newbie in both arduino & xbee. i'm currently searching for information about connection for arduino uno board to xbee module & sample program for transmiting analog signal from arduino uno board to receiving xbee to produce a graph view by processing software. basically for analog read from analog input & view a graph by processing software i'm already done. just about the xbee program only i stuck here. it would be glad & my pleasure if u guys can help me. with all, regards. thank you.

nickgammon

Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nassery

actually i was working with my wireless ecg project...i have done the programming for analog input from the arduino and i have done the programming on how to view the ecg graph using Processing software at the pc..but for now, i'm stuck at the xbee wireless module program because i dont know how to write a program from the arduino through xbee into my pc..i am using arduino uno..i got the program from the internet for xbee but i dont know how to read the program.. this is the sample program i found... but, basically i don't know how to read the program. bcoz i don't have basic programming. hope u can help me. thank you.

Code: [Select]

/**
* Copyright (c) 2009 Andrew Rapp. All rights reserved.
*
* This file is part of XBee-Arduino.
*
* XBee-Arduino is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* XBee-Arduino is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBee-Arduino.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <XBee.h>

/*
This example is for Series 1 XBee
Sends a TX16 or TX64 request with the value of analogRead(pin5) and checks the status response for success
Note: In my testing it took about 15 seconds for the XBee to start reporting success, so I've added a startup delay
*/

XBee xbee = XBee();

unsigned long start = millis();

// allocate two bytes for to hold a 10-bit analog reading
uint8_t payload[] = { 0, 0 };

// with Series 1 you can use either 16-bit or 64-bit addressing

// 16-bit addressing: Enter address of remote XBee, typically the coordinator
Tx16Request tx = Tx16Request(0x1874, payload, sizeof(payload));

// 64-bit addressing: This is the SH + SL address of remote XBee
//XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x4008b490);
// unless you have MY on the receiving radio set to FFFF, this will be received as a RX16 packet
//Tx64Request tx = Tx64Request(addr64, payload, sizeof(payload));

TxStatusResponse txStatus = TxStatusResponse();

int pin5 = 0;

int statusLed = 11;
int errorLed = 12;

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);
  Serial.begin(9600);
  xbee.setSerial(Serial);
}

void loop() {
   
   // start transmitting after a startup delay.  Note: this will rollover to 0 eventually so not best way to handle
    if (millis() - start > 15000) {
      // break down 10-bit reading into two bytes and place in payload
      pin5 = analogRead(5);
      payload[0] = pin5 >> 8 & 0xff;
      payload[1] = pin5 & 0xff;
     
      xbee.send(tx);

      // flash TX indicator
      flashLed(statusLed, 1, 100);
    }
 
    // after sending a tx request, we expect a status response
    // wait up to 5 seconds for the status response
    if (xbee.readPacket(5000)) {
        // got a response!

        // should be a znet tx status           
    if (xbee.getResponse().getApiId() == TX_STATUS_RESPONSE) {
       xbee.getResponse().getZBTxStatusResponse(txStatus);
   
       // get the delivery status, the fifth byte
           if (txStatus.getStatus() == 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());
      // or flash error led
    } else {
      // local XBee did not provide a timely TX Status Response.  Radio is not configured properly or connected
      flashLed(errorLed, 2, 50);
    }
   
    delay(1000);
}

Binu Madola

hai
  if you have a full functioning Xbee module with  a serial port, you can transfer data as using Serial.print(); function.
for eg.if you have a analog value get from your ecg , as
int x=analogRead(pin);///which analog pin you used
Serial.print(x);

nassery


hai
  if you have a full functioning Xbee module with  a serial port, you can transfer data as using Serial.print(); function.
for eg.if you have a analog value get from your ecg , as
int x=analogRead(pin);///which analog pin you used
Serial.print(x);

just serial print function only? just like that? like the program to view the serial monitor? is that so... i try first. i guess juz need to configure the X-CTU only...

Binu Madola

hai,
    What type of BT you are using?
    if you want more serial you must set up a additional softwareserial.
I think you want two one for processing and other for BT.

nassery

i am using xbee as my wireless module..i'm working on programming on how to transmit ecg graph from my arduino to pc via my wireless xbee..

PaulS

Quote
i am using xbee as my wireless module..i'm working on programming on how to transmit ecg graph from my arduino to pc via my wireless xbee..

The XBees, when properly configured, replace a wire. There is NOTHING that changes in the programming from when you used a wire to connect the Arduino to the PC.

What, exactly, is an ecg graph?
The art of getting good answers lies in asking good questions.

nassery

owh...so i just configure the xbees..and then just matching it from transmitter and receiver?...do i need to program it in arduino for xbees?

*ecg graph is ELECTROCARDIOGRAPHY which measure our electrical activity of heart...


PaulS

How is this graph stored/represented on the Arduino? What, exactly, are you sending?

Which XBees are you using? Have you get them talking to each other?

How are they connected to the Arduino/PC?
The art of getting good answers lies in asking good questions.

Go Up