Im trying to transmit RF using a nRF905 transceiver but I don’t understand the code, Could someone please help?

hi guys

Im currently trying to use a nRF905 transceiver and the nRF905 Radio Library for Arduino (4.0) to transmit some bits (as per below) on the 433mhz frequency but Im having a hard time understanding the code, Ive never done something like this before and arduino language is still quite new to me.

I'm currently trying to use this code (also is below) as my reference but i don’t understand a-lot of it (such as BUF_LEN, CONF_LEN, i know what TX is but i don’t know what the address is and quite a lot of other stuff), if someone could please explain what these mean and maybe write out a bit of example code that explains everything that would be helpful. Thanks

bits I'm trying to transmit:

0000000010000001100000101000001110000100100001011000011010000111100010001001100010101000101110001100100011011000111010001111100100101001001110010101100101101001011110011001101010011011100111011001111010011111101010101110101101101011111011011110111011111111

Reference code Im using:


  #include <NRF905.h>
    #include <SPI.h>
    
    #define BUF_LEN          32
    #define CONF_LEN         10
    
    #define NRF905_CSN       10
    
    unsigned char tx_buf[BUF_LEN]= "RDIoT TX CNT:  \r\n";
    unsigned char read_config_buf[CONF_LEN];
    
    byte tx_address[4]= {0xcc,0xcc,0xcc,0xcc};
    
    void setup()
    {
        unsigned char i;
        
        pinMode(NRF905_CSN,OUTPUT); //to make sure SPI works
        
        nrf905=NRF905(NRF905_CSN);
        
        nrf905.init();
    
    
        /**
            default configuration, need to specify frequency
            choose Z-Wave frequency band, support :
            US		908.42Mhz
            EUROPE		868.42MHz
            AFRICA		868.42MHz
            CHINA		868.42MHz
            HK		919.82MHz
            JAPAN		853.42MHz
            AUSTRALIA	921.42MHz
            NEW_ZEALAND	921.42MHz
            BRASIL		921.42MHz
            RUSSIA		896MHz
        */
        nrf905.write_config(US);
    	
    	
        nrf905.read_config(read_config_buf);
    
        Serial.begin(9600);
    
        for(i=0; i<10; i++)
        {
            Serial.print(read_config_buf[i],HEX);
            Serial.print(' ');
        }
        
        tx_buf[12] = '0';
    }
    
    void loop()
    {
        /** transmit data packet with default TX Address */
        nrf905.TX(tx_buf);
        
        /** transmit data packet with specified TX Address */
    //    nrf905.TX(tx_buf, tx_address);
        
        // NOTE: TX_Address and RX_Address must be the same
        
        /** Count Sending times */
        tx_buf[12]++;
        if(tx_buf[12] == 0x3A){
          tx_buf[12] = '0';
        }
        delay(50);
    }

You might find this Arduino reference page helpful;

store those bits as bytes into an array (as per the previous reference) and that's what you need to send.

which NRF905.h library are you using? can you provide a link?

And it might be worthwhile if you explain what you are trying to do by transmitting that string of binary.

Just a question regarding arrays is the number contained within the [ ] eg [6] the size of the elements in the array? Like if the elements are 1,2,3 then the square brackets will be [3]?

Is this how I would do the array? :
int bytes[number of bytes] = {0000000010000001100000101000001110000100100001011000011010000111100010001001100010101000101110001100100011011000111010001111100100101001001110010101100101101001011110011001101010011011100111011001111010011111101010101110101101101011111011011110111011111111};

Also here’s the library nRF905 Radio Library - Arduino Reference

And what does buf_len and things mean?

I’m trying to open my garage, I know it would be better to just record the code my garage uses but I thought doing it this way would be more fun

Do you know for sure if someone else has been able to use an nRF905 to operate your specific garage remote ?

if you want to send text, you coud do

char message[] = "0000000010000001100000101000001110000100100001011000011010000111100010001001100010101000101110001100100011011000111010001111100100101001001110010101100101101001011110011001101010011011100111011001111010011111101010101110101101101011111011011110111011111111";

if you want to send bytes, you need to group those bits into bytes

byte message[] = {
  0b00000000,
  0b10000001,
  0b10000010,
  0b10000011,  
  0b10000100,
   ...
  0b11101110,
  0b11111111,
};

the size of the array is automatically calculated by the compiler and you can get it with sizeof message (as the content is on a byte).

in the case of a string of text (first case) the size will include an extra byte which is a trailing null char the compiler add to denote the end of the cString in memory.

Ok this makes sense, thanks. Just 2 more questions what does the 0b mean at the start of the byte and why do I need to group the bits into bytes?

edit: i just realised im dumb, of courses it needs to be in bytes if thats the variable type

No I haven’t seen anyone do this with my garage

0b denotes that the data that follows is in binary (0s and 1s)
0x denotes that the data that follows is in Hexadecimal

0b00001111 for example is the same as 0x0F and is the same as 15 in decimal

it's just a convenient way to type a number depending on what you have

ok thanks

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.