Go Down

Topic: rfbeewireless with analog sensors doesn't give any values (Read 725 times) previous topic - next topic

gundorf

hi all,
I want to use a gyro sensor into a rfbee- to track motion and accelerations. I have another rfbee connected in my pc through uartsbee to receive values.

I use the rfbeewireless code wich I found here http://tronixstuff.wordpress.com/2012/03/19/rf-wireless-data-with-the-seeedstudio-rfbee/

This example works fine, I receive the array of 'ABCD' on my pc, so the communication is ok.

now I try to transmitdata() my sensors values, but the terminal console is still blank...(the "ok" appears and then nothing). although the slave rfbee (connected to the pc) receives datas from the master (the tx led blinks every 1000ms when I put on the master rfbee)
I suspected a problem of datas type (maybe confuse with int-byte)...
here's the loop where I trie to send values of the analog sensors:

int sensor1 =3;
int sensor2=4;
int val1=analogRead(sensor1);
int val2=analogRead(sensor2);
byte testData[4] = {val1,val2};

void sendTestData()
{
  // send the four bytes of data in the byte testData[] from address 1 to address 2
  transmitData(testData,4,1,2);
  delay(1000);
}

any help would be appreciated, thanks !!
g.

gundorf

I think the problem point is here:

int val1=analogRead(sensor1);
int val2=analogRead(sensor2);
byte testData[4] = {val1,val2};

void sendTestData()
{
  // send the four bytes of data in the byte testData[] from address 1 to address 2
  transmitData(testData,4,1,2);
  delay(1000);
}

How could I transform an int like 153 into a byte of array ? wich would send 1,5,3 in the transmitdata function ?
I think this might solve, (I hope so !) the issue.
thanks
g.

GoForSmoke

I know someone who just connects Xbee to Arduino and uses SoftSerial to communicate. He gets to use the print commands.

OTOH, sprintf() will let you fill a char or byte array with formatted text.
http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

gundorf

#3
Nov 14, 2012, 04:31 pm Last Edit: Nov 14, 2012, 04:32 pm by gundorf Reason: 1
here's a little debug sketch: my int value must be put in an array, and then I have to recover this int sensor value, from the array,
I fail to do that.
Code: [Select]

//debug rfbee data sendind and receiving;
void setup()
{
  Serial.begin(9600);
}


void loop()
{
  envoi_capteur();
  delay(100);
  reception_capteur();
  delay(5000);
  Serial.println();
}
  ///////////  ///////////  ///////////  ///////////  ///////////  ///////////  ///////////  MASTER RFBEE   ///////////  ///////////  ///////////  ///////////  ///////////  ///////////  ///////////   
void envoi_capteur()
{
  byte val = random(255);//simulate my sensor
  byte val1= random(255);
  byte txData = {'val'}; //array to send to rf transmission

  //transmitData((byte*) txData, 3, 1,2);//data transmission (data, length, rfbee src, fbee dst)
Serial.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>TX>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
Serial.println();
Serial.println("transmit message[0]:       ");
Serial.print(txData);

}
///////////  ///////////  ///////////  ///////////  ///////////  ///////////  ///////////   SLAVE RFBEE   ///////////  ///////////  ///////////  ///////////  ///////////  ///////////  /////////// 
void reception_capteur()
{ Serial.println();
Serial.println();
  Serial.println();
  //result= receiveData(rxData, &len, &srcAddress, &Address, (byte *)&rssi, &lqi); this is the function wich receive rfdata on the rx rfbee, connected to my pc.   
  byte rxData;
  Serial.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<RX<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
  Serial.println();
  Serial.println("How could I recover the VAL (values of sensor) from the rxData array ????");//This is where I'm stuck
}


stupid silly problem, but I'm really stuck :=)

PaulS

Code: [Select]
  byte txData = {'val'}; //array to send to rf transmission
So, txData is a multicharacter constant. Is that what you really want?

gundorf

oups, no sorry it's a mistake- this is a sensor value, an int-

GoForSmoke

int    sprintf (char *__s, const char *__fmt,...)
sprintf returns NULL (0) on error

pseudocode:

int A = 153;
byte buffer[8]; // big enough even number to hold "-65536" and terminating \0

if ( sprintf( buffer, "%d", A ) == 0 )
{
  Serial.println( "format conversion error" );
  exit;
}
else
{
  // buffer now has "153\0", strlen( buffer ) returns 3
}



Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

gundorf

great !! thanks a lot.
I'll post the final solution- rfbee 's message' forums are though to find.
cheers

Go Up