Go Down

Topic: Sending a number instead of a Byte using RF communication. (Read 599 times) previous topic - next topic

mixania

May 10, 2013, 06:09 pm Last Edit: May 10, 2013, 06:15 pm by mixania Reason: 1
Whats up Arduino forum? Recently I have managed to create a data transmitter out of an Attiny85 and a RF Link Transmiter - 4800bps (434MHz) from SparkFun. The receiver is an Arduino Uno and a RF Link Receiver - 4800bps (434MHz) connected to a computer for Serial Monitoring.  $)
https://www.sparkfun.com/products/10532
https://www.sparkfun.com/products/10534

Since there are very few libraries that support Attiny85, I had to create my own transmitter and receiver code. They are extremely minimalistic, but they work pretty well! Basically the transmitter code consists of a function called byteSend() . What it does is chop up a letter that is typed into it, into bits and send the bits through the transmitter one at a time. For now, I can only send one byte at a time, so in order to create a sentence I have to create many byteSend() functions.The Receiver does the opposite of the transmitter, it collects the the bits and packs them into a byte in order to send them over the Serial Monitor. :smiley-sweat:

Despite the fact that transmitting letters works with my code, I eventually want to transmit temperature readings from the analog pin on the Attiny85. For this I have to convert the analog reading which is an Int, into a byte, so I can send it via the Transmitter. I tried to send one digit ints through the link but I believe they consist of two bytes so that's probably the reason why It didn't work. Here is how I did it. :|

Code: [Select]
int d = 7;
byteSend(d);


Is there a way to convert the int into a byte that the function will be able to send? :smiley-roll:
Thanks guys. :smiley-surprise:

Here is the transmitter code:
Code: [Select]


// Data pin that connects to the transimter's DATA IN pin
int dataPin = 2;
void setup(){
   // Set up the Data pin as an Output
   pinMode(dataPin, OUTPUT);
}

void loop(){
   // Send some bytes continuesly
   byteSend('T');
   byteSend('E');
   byteSend('S');
   byteSend('T');
   byteSend('#');
   delay(10);
}

// Function that will simplify the process of sending a letter
void byteSend (byte inputByte){
    int i;
   
    // Loop that will make the reciever wake up and adjust its amplification
    for(i=0; i<20; i++){
      digitalWrite(dataPin, HIGH);
      delayMicroseconds(50);
      digitalWrite(dataPin, LOW);
      delayMicroseconds(50);
    }
   
   // A 3ms delay in order to synch the transimtter and get ready for data transmition
   digitalWrite(dataPin, HIGH);
   delayMicroseconds(3000);
   digitalWrite(dataPin, LOW);
   delayMicroseconds(500);
   
   // A loop that goes throught all the bits in a byte and transimts accordingly
   for(i=0; i<8; i++){
     
   if (bitRead(inputByte,i)==1) {
     digitalWrite(dataPin, HIGH);
     delayMicroseconds(1000);
   }
   
   if (bitRead(inputByte,i)==0) {
     digitalWrite(dataPin, LOW);
     delayMicroseconds(1000);
}
Arduino Uno R3
Mac OSX Lion

PaulS

Quote
Is there a way to convert the int into a byte that the function will be able to send?

highByte() and lowByte() will get the two bytes that make up the int.

But, why? Is it really hotter than 255 degrees where you are? Normally, the temperature, on some scale, will fit in a byte.

Go Up