Playing with RFM22 lib

Post Reply
User avatar
Loosi
Posts: 63
Joined: Sat Aug 20, 2011 8:31 pm
Location: Germany (HSK)
Contact:

Playing with RFM22 lib

Post by Loosi »

Hey all!

Can someone explain me how to convert a int to uint8_t ?
I´am trying to send the A0-A5 ports to a other arduino via RFM22 but the rfm22.send() command needs a uint8_t input and i get a int from analogRead() :-(

Greetings
Daniel

User avatar
Rob
Posts: 77
Joined: Sun Apr 03, 2011 4:40 pm

Re: Playing with RFM22 lib

Post by Rob »

the_char = ((char) (the_int/4))

send the_char


or

the_char1 = (((char) the_int & 0xff00)>>4)
the_char2 = ((char) the_int & 0x00ff)


send the_char1
send the_char2

User avatar
Loosi
Posts: 63
Joined: Sat Aug 20, 2011 8:31 pm
Location: Germany (HSK)
Contact:

Re: Playing with RFM22 lib

Post by Loosi »

Hmm, tried some stuff but i cant get it working :-(

Currently it looks like

Code: Select all

 //uint8_t data[] = "Hello World!"; //<- this is the original what is working
uint8_t data[4] = (((char) analogRead(A0) & 0xff00)>>4); //<- dont work :-(
   
rf22.send(data, sizeof(data));

the error is

Code: Select all

error: array must be initialized with a brace-enclosed initializer

User avatar
Rob
Posts: 77
Joined: Sun Apr 03, 2011 4:40 pm

Re: Playing with RFM22 lib

Post by Rob »

a simple explanation:



uint8_t data[4];
uint16_t analog_data;



analog_data = analogRead(A0) ;

data[0] = analog_data
data[1] = analog_data>>8&0xff;

analog_data = analogRead(A0) ;

data[2] = analog_data
data[3] = analog_data>>8&0xff;


rf22.send(data, sizeof(data));

User avatar
Rob
Posts: 77
Joined: Sun Apr 03, 2011 4:40 pm

Re: Playing with RFM22 lib

Post by Rob »

your question was: Can someone explain me how to convert a int to uint8_t ?


uint8_t data;


data = ((char) (analogRead(A0)/4));

rf22.send(data, data);

User avatar
Loosi
Posts: 63
Joined: Sat Aug 20, 2011 8:31 pm
Location: Germany (HSK)
Contact:

Re: Playing with RFM22 lib

Post by Loosi »

thanks :) got it working with this:

Code: Select all

  int ADC0 = analogRead(A0);
  rf22.send((uint8_t*)&ADC0, sizeof(ADC0));

Post Reply