Main Site Documentation

nRF24L01 2.4Ghz Wireless on Panda or Domino


#1

Hi guys!

I have bought a few of these modules:
http://iteadstudio.com/store/index.php?main_page=product_info&cPath=7&products_id=53

There is a arduino library available on that page.
http://iteadstudio.com/application-note/nrf24l01-wireless-module-with-arduino/

I’m trying to get that library translated to C# code, but I’m not that good in reading C++ code :slight_smile:

I hope someone can help!

This is one of the thinks I dont get:


private byte SPI_Read(byte reg)
{
      byte reg_val;
      SPI_PORT&=~CSN; // CSN low, initialize SPI communication...
      SPI_RW(reg); // Select register to read from..
      reg_val = SPI_RW(0); // ..then read register value
      SPI_PORT|=CSN; // CSN high, terminate SPI communication
      
      return (reg_val); // return register value
}


#2

This should help http://www.microframeworkprojects.com/index.php?title=SimpleWireless


#3

Gus your the best! Thanks! I am wirelessly transmitting and receiving data now! how cool!


#4

I have the code working on my two panda’s but I can’t seem to get the two send more than one bite to each other! So the sample works ok… it sends 1…2…3…4…etc… but if I try to change the code (by put a higher payload value) it won’t receive anything anymore…

Can anyone point me in the right direction?


#5

We need to see the code.


#6

Never used those myself but I know the code I pointed out is too old and probably needs some fixes.


#7

Initialization:

NRF24L01.Initialize();

                    // Set adresses
                    NRF24L01.RX_Adress = new byte[] { 0xEE, 0xDD, 0xCC, 0xBB, 0xAA };
                    NRF24L01.TX_Adress = new byte[] { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE };

                    // Initialize nRF24L01
                    NRF24L01.Configure();

                    // Event handler for OnTransmit
                    NRF24L01.OnTransmit += new NRF24L01.OnTransmitHandler(NRF24L01_OnTransmit);

                    // Send first byte, next bytes are send with the OnTransmit handler
                    NRF24L01.SendByte(Counter);

                    // Keep updating screen
                    while (true)
                    {
                        
                        Thread.Sleep(200);
                    }

On transmit handler:

 /// <summary>
            /// Event handler for OnTransmit
            /// </summary>
            /// <param name="succes"></param>
            /// <param name="status"></param>
            void NRF24L01_OnTransmit(bool succes, byte status)
            {
                // See if transmit was succesfull
                if (succes)
                {
                    // If succes increase counter and send next byte
                    if (Counter == 100) { Counter = 1; } else { Counter++; }
                    NRF24L01.SendByte(Counter);
                    Debug.Print("Send data: " + Counter.ToString());
                    Thread.Sleep(1000);
                }
                else
                {
                    // If error decrease counter and try send next byte
                    if (Counter == 1) { Counter = 1; } else { Counter--; }
                    NRF24L01.SendByte(Counter);
                    Debug.Print("Send data failed: " + NRF24L01.ByteToHex(status));
                    Thread.Sleep(1000);
                }

            }

Sendbyte methode:

/// <summary>
    /// Send 1 byte to TX_Adress
    /// </summary>
    /// <param name="b">byte to send</param>
    public static void SendByte(byte b)
    {
        // Chip enable low
        NRF24L01.DisableRXTX();

        // Setup, CRC enabled, Power Up, TRX
        NRF24L01.SendCommand(NRF24L01Commands.W_REGISTER, NRF24L01Registers.CONFIG, new byte[] { (byte)((1 << NRF24L01Mnemonics.EN_CRC) | (1 << NRF24L01Mnemonics.PWR_UP)) });

        // Send payload
        NRF24L01.SendCommand(NRF24L01Commands.W_TX_PAYLOAD, 0x00, new byte[] { b });

        // Pulse for CE -> starts the transmission.
        NRF24L01.EnableRXTX();

    }

But as Gus pointed out I used this code: http://www.microframeworkprojects.com/index.php?title=SimpleWireless

I got it to work in VS2010 and MF4.1 and the demo works. But I can’t get it to send more then one byte…


#8

Can you show please how are you trying to send more than 1 byte


#9

I tried several things:


 /// <summary>
    /// Send 1 byte to TX_Adress
    /// </summary>
    /// <param name="b">byte to send</param>
    public static void SendBytes(byte[] data)
    {
        // Chip enable low
        NRF24L01.DisableRXTX();

        // Setup, CRC enabled, Power Up, TRX
        NRF24L01.SendCommand(NRF24L01Commands.W_REGISTER, NRF24L01Registers.CONFIG, new byte[] { (byte)((1 << NRF24L01Mnemonics.EN_CRC) | (1 << NRF24L01Mnemonics.PWR_UP)) });

        // Send payload
        //NRF24L01.SendCommand(NRF24L01Commands.W_TX_PAYLOAD, 0x00, new byte[] { b });
        for (int i = 0; i < data.Length; i++)
        {
            NRF24L01.SendCommand(NRF24L01Commands.W_TX_PAYLOAD, 0x00, new byte[] { data[i] });
            //Thread.Sleep(10);
        }

        // Pulse for CE -> starts the transmission.
        NRF24L01.EnableRXTX();

    }

And this:

/// <summary>
    /// Send 1 byte to TX_Adress
    /// </summary>
    /// <param name="b">byte to send</param>
    public static void SendBytes(byte[] data)
    {
        // Chip enable low
        NRF24L01.DisableRXTX();

        // Setup, CRC enabled, Power Up, TRX
        NRF24L01.SendCommand(NRF24L01Commands.W_REGISTER, NRF24L01Registers.CONFIG, new byte[] { (byte)((1 << NRF24L01Mnemonics.EN_CRC) | (1 << NRF24L01Mnemonics.PWR_UP)) });

        // Send payload
        
        NRF24L01.SendCommand(NRF24L01Commands.W_TX_PAYLOAD, 0x00, data);
        
        // Pulse for CE -> starts the transmission.
        NRF24L01.EnableRXTX();

    }

On the receiver side there is this line:

// Read payload data
            byte[] payload = NRF24L01.SendCommand(NRF24L01Commands.R_RX_PAYLOAD, 0x00, new byte[1]);

When i change it to for example:

// Read payload data
            byte[] payload = NRF24L01.SendCommand(NRF24L01Commands.R_RX_PAYLOAD, 0x00, new byte[16]);

It stops working…


#10

Ok second form of your SendBytes method looks right,just remember that data should be up to 32 bytes.

On receiving side use R_RX_PL_WID command to determine the size of the payload and allocate accordingly.


#11

Hi Architect! Thank you very much for your help, I’m afraid I don’t really know where to put that command, can you please help me a bit more?


#12

Right before you use the R_RX_PAYLOAD command. R_RX_PL_WID will give you back how many bytes are available for reading, then you should be able to allocate a buffer of the right size. Again I am just guessing here since I don’t have the module and the problem may be somewhere else.

I looked at these modules and I really like them, especially the price.
I am ordering couple of these. I will probably get them in two weeks.

I will be able to mess with them then and help you more if you still have the issues.


#13

Wow thats what I call service! :smiley: I really like the modeules to and the price even better! they work great on the arduinos but I would really like to use them for my FEzzez…


#14

Hey Ramon,

Got my cards today. Will try the code tonight and see if I can solve that issue. :wink:


#15

Damn, great! Shame I’m going on a holliday tomorrow 8) can’t wait to try it out!

Cheers,

Ramon


#16

I’m back! Still in one peace :slight_smile:

Any progress on the wireless cards?


#17

Sorry, Got busy with something else and haven’t tried it yet. Will do in a couple of days.


#18

Ok great! let me know when you have something for me to test!


#19

Sorry for nagging :slight_smile: but did you had the time by any chance?


#20

Hey Ramon,

I did,but one of the transceivers was bad. I’ve ordered the replacement which should be here soon.