Address signal throught RF

Hi everyone !

I would like to know how to transfert, throught RF, a signal shaped like:

1.2.255;

Thanks in advance

Danakil

The simplest way is using a pair of xbee modules.

Well, I only have Rf transmitter and receiver… then let’s do the hard way ! XD

So you have some unknown RF transmitter, and some unknown RF receiver? You want to transmit numbers from one to the other?

What kind of input does the transmitter take?

I've got a pair of APC220, the parameters are setted by TTL/UART (4,5PIN)

Google says that the interface is via TTL UART so you can just decide on a message format, write the message at the sending side and read+decode it at the receiving side.

It would have saved me some time if you'd posted a link to the specs for your tranceivers, by the way.

Yep I badly readed the post from majenko, and answered off-topic... Sorry :disappointed_relieved:

So ok, I am going to have a look at what TTL/UART is

Cheers

Well, I now know what is TTL/UART, but how to encode my data ?

They say that “the UART hardware generates a start bit, shifts the required number of data bits out to the line, generates and appends the parity bit (if used), and appends the stop bits.” (http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter
So I don’t need to care about… XD

So just tell me if I am wrong:

// Master sketch:

#include <Wire.h>

byte* data[3];

void setup()
{
  Wire.begin();
}

void loop()
{
data = [1; 2; 255]
  Wire.beginTransmission();
                              
  Wire.write(data);            
  Wire.endTransmission();
}

Few questions are remaining: - is the wire library good to use ?

  • how do call a particulary slave (for example, slave2) ?
  • how to send the (.) or (/) with the data ? [1/2/255]

For UART/TTL:

Serial.print("1.2.255;");

The Serial device (RX and TX pins) is a UART/TTL interface. It is also (on the Uno) the same interface used to communicate with the computer.

I am a bit surpised of the answer, so easy ! XD

and to send my address and rencode it:

// TX

byte* data[3] = [1; 2; 255]

Serial.print(data[0]); Serial.print('/'); Serial.print(data[1]); Serial.print('/'); Serial.print(data[2]); Serial.println('.');

/************************************************************/
//RX

long getSerialdata()
{
  byte* serialdata[3] = 0;
  while (inbyte != '.')
  {
    inbyte = Serial.read(); 
    for (i=0; i<3; i++){
         if (inbyte > 0 && inbyte != '/')
         {
          serialdata[i] = inbyte;
         }
    }
  }
inbyte = 0;
return serialdata[];
}

You're using your while wrong.

You should start with a read, then do the while, and end the while with the next read. Or shorten it so you do the read in the while condition:

while ((inbyte = Serial.read()) != ".")
{
  //...
}

However, you need to ensure that the data is there first before you read it. Serial.read() will return -1 if there are no characters to read - it won't block. You should use the Serial.available() function to determine if there is any characters there to read.

http://hacking.majenko.co.uk/reading-serial-on-the-arduino

You are totally right, I didn t mention it because it was in the loop
So to make sure, it will run :

void loop(){
    unsigned long currentMillis = millis();

  while ((Serial.available() < 6) && (currentMillis - previousMillis > interval)){             // If you havent get your 6 datas in INTERVAL time.....
        
                         // Wait or do something
            delay(50);
           }

  if (Serial.available() >=6){
           getserialdata();
           delay(50);
  }
}

long getSerialdata()
{
  byte* serialdata[3] = 0;
  inbyte = Serial.read();                 // <= indeed here is much better !
  while (inbyte != '.')
  {
    for (i=0; i<3; i++){
         if (inbyte > 0 && inbyte != '/')
         {
          serialdata[i] = inbyte;
         }
    }
  }
inbyte = 0;
return serialdata[];
}

Almost, but you're now not doing a read inside the while loop to update inbyte. That should be the last thing you do in the while loop.

Really ? the subroutine IF won't run ? it won't update the array serialdata[] ? I'm lost....

  inbyte = Serial.read();                 // <= indeed here is much better !
  while (inbyte != '.')
  {
    for (i=0; i<3; i++){
         if (inbyte > 0 && inbyte != '/')
         {
          serialdata[i] = inbyte;
         }
    }
  }

Where in either of those loops does inbyte change?

You want to read up to a “.” character… try this:

inbyte = Serial.read();
while (inbyte != ".") {
   serialdata[i++] = inbyte;
   inbyte = Serial.read();
}

You want to only take numbers out of it, modify it to:

inbyte = Serial.read();
while (inbyte != ".") {
   if (inbyte >= '0' && inbyte <= '9') {
      serialdata[i++] = inbyte;
   }
   inbyte = Serial.read();
}

Note the ‘’ around the numbers - you’re comparing the character representation of the numbers, not the numbers.

Yep i understand, it seems clear now for serialdata[i++]

but the ‘around the number’ is a bit mysterious,

My Tx send in binary :
{1/2/255.} => {00000001 00101111 00000010 00101111 11111111 00101110 }
DEC 1 / 2 / 255 .

On the Rx side, because I defined inbyte as an integer, it should uncode it in DEC, right ?
but if I define inbyte as a CHAR, I would get: NULL / SOH / nothing .

BUT you wrote that if the representation of inbyte in CHAR is between 0 and 9 {with (’)} it means I guess that if the representation of INBYTE is a number then get it.

my question is: shouldn’t we write :

if (inbyte >= '0' && inbyte <= '255') {

I mean the range of numbers inbyte should be ?

If you are sending the string "1/2/255" then the numbers are '1' '2' '2' '5' and '5' as characters, not as numbers. The actual data would be: 49,47,50,47,50,50,55

If you send the bytes 1,47,2,47,255 then the numbers are 1, 2 and 255 as numbers.

Unicode is just a human representation of data. ASCII is more common and simpler.

Be careful when working with numbers. If you send them as part of a string, then they will be ASCII characters. If you send them as raw bytes, they will be numbers. Be sure you're working with the right concept.

I got it ! I am working with character because I used Serial.print() . I would have number with Serial.write() ! I am stupid :grin:

but in this case, I don't know how many bytes I would get, for example:

{1/ 2/ 255 .} => {49,47,50,47,50,53,53, 46} => 8 bytes {1/ 2/ 12 .} => {49, 47, 50, 47, 49, 50, 46} => 7 bytes

So I may need to use something as your example (readline())on your website.

Anyway, thank you a lot for your help, you made my day ! I've learned many many things !