nRF24L01 2.4Ghz Wireless on Panda or Domino

Hi guys!

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

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

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
}

This should help microframeworkprojects.com

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

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?

We need to see the code.

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

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: [url]microframeworkprojects.com

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…

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

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…

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.

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?

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.

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…

Hey Ramon,

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

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

Cheers,

Ramon

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

Any progress on the wireless cards?

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

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

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

Hey Ramon,

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