Driver - Nordic nRF24L01+ wireless module driver

Dear Gralin:
Thanks.
myAddress problem is solved.
But the output still shows " “Send failed!”.
I deploy this code on only one Domino. I only insert one board to PC.
I do not deploy the other Domino board, so I didn’t change

myAddress = fez1;
                            _otherBoards = new byte[2][];
                            _otherBoards[0] = fez2;    

So the problem is the hardware connection?

You will get “Send failed” if no ACK was received. If you only want to send and there is no target board you will get this :slight_smile: If you are able to read your own address or channel then your connection between board and module is ok.

Dear Gralin:
It works.
But why it stop when received a packet? Why can’t send and receive continually?

And in the Initialize class, I see

   // Module reset time
            Thread.Sleep(100);

The Initialize only runs in the first time or need Initializing on each sending or receiving ?

Thankis

Initialize is needed only before first use to set up the module.

So what is the result you are getting? You see in console that the second board has received data and nothing more? Are you sure each board has different address and not that both boards have the same program ? (I used different FEZ boards and this way i could use the same program, the address was dependant on the FEZ type)

The FEZA1 Send “Test” string to the FEZA2. and I use the debug to print the string.
I can see the “Test” string in the output window in FEZA2. But it only print the string once.
So the code works, but the data only send once,I don’t know why.
I don’t know how to control the sending period.
Thanks
Send:



        public void Run()
        {
            const byte channel = 10;

            // all addresses need to have the same length
            var fez1 = Encoding.UTF8.GetBytes("FezA1");
            var fez2 = Encoding.UTF8.GetBytes("FezA2");
          

            // here we determine on which device the code is running on
          

                       // case Fez.Domino:
                            _myAddress = fez1;
                            _otherBoards = new byte[2][];
                            _otherBoards[0] = fez2;                                               
                        
            // here we attatch event listener
            _module.OnDataReceived += OnReceive;
            _module.OnTransmitFailed += OnSendFailure;
            _module.OnTransmitSuccess += OnSendSuccess;

            // we nned to call Initialize() and Configure() befeore we start using the module
            _module.Initialize(_spi, _chipSelectPin, _chipEnablePin, _interruptPin);
            _module.Configure(_myAddress, channel);

            // to start receiveing we need to call Enable(), call Disable() to stop/pause
            _module.Enable();
            // example of reading your own address
            var myAddress = _module.GetAddress(AddressSlot.Zero, 5);
            Debug.Print("I am " + new string(Encoding.UTF8.GetChars(myAddress)));
            //_led.Write(true);
            Send();
        }
                     
        private void OnSendSuccess()
        {
            _led.Write(false);
            Debug.Print("send successful");
        }

        private void OnSendFailure()
        {
            Debug.Print("Send failed!");
            Send();
        }

        private void OnReceive(byte[] data)
        {
            Debug.Print("Token = " + data[0] + ", Delay = " + data[1]);
            _lastActivity = DateTime.Now;
            _token = (byte) (data[0] + 1);
            _delay = data[1];
            Send();
        }

        private void Send()
        {
           
            SendTokenToNextBoard();
        }
               
        private void SendTokenToNextBoard()
        {
            _led.Write(true);

            // delay added to see LED blink
            // the _delay value is 0...255
            Thread.Sleep(1000);
            byte[] data = Encoding.UTF8.GetBytes("test");
            _module.SendTo(_otherBoards[0], data);
        }

Receiver:


public void Run()
        {
            const byte channel = 10;

            // all addresses need to have the same length
            var fez1 = Encoding.UTF8.GetBytes("FezA1");
            var fez2 = Encoding.UTF8.GetBytes("FezA2");
          

            // here we determine on which device the code is running on
          

                       // case Fez.Domino:
                            _myAddress = fez2;
                            _otherBoards = new byte[2][];
                            _otherBoards[0] = fez1;                                               
                        
            // here we attatch event listener
            _module.OnDataReceived += OnReceive;
            _module.OnTransmitFailed += OnSendFailure;
            _module.OnTransmitSuccess += OnSendSuccess;

            // we nned to call Initialize() and Configure() befeore we start using the module
            _module.Initialize(_spi, _chipSelectPin, _chipEnablePin, _interruptPin);
            _module.Configure(_myAddress, channel);

            // to start receiveing we need to call Enable(), call Disable() to stop/pause
            _module.Enable();
            // example of reading your own address
            var myAddress = _module.GetAddress(AddressSlot.Zero, 5);
            Debug.Print("I am " + new string(Encoding.UTF8.GetChars(myAddress)));          
            //Send();
        }
                     
        private void OnSendSuccess()
        {
            _led.Write(false);
        }

        private void OnSendFailure()
        {
            Debug.Print("Send failed!");
            //Send();
        }

        private void OnReceive(byte[] data)
        {
            //Debug.Print("Token = " + data[0] + ", Delay = " + data[1]);
            int count = data.Length;
            char[] chars = Encoding.UTF8.GetChars(data);
            string str = new string(chars, 0, count);
            Debug.Print(str);
            //Debug.Print(data[0].ToString());
            //Send();
        }

        private void Send()
        {
           
            SendTokenToNextBoard();
        }
               
        private void SendTokenToNextBoard()
        {
            _led.Write(true);

            // delay added to see LED blink
            // the _delay value is 0...255
            Thread.Sleep(1000);
            byte[] data = Encoding.UTF8.GetBytes("test");
            _module.SendTo(_otherBoards[0], data);
        }

Tzu Hsuan,

your code will send only once!

If you want to send lets say every 5 seconds, you need to implement a Timer.

@ Tzu Hsuan: Eric is right, you are sending the data only once. Add Send() call in the OnSendSuccess() method and your sender will send data each 1s. Also if you post your code please trim it to contain only that what is essential.

Thanks: Its work.

Gralin,

Maniacbug has been busy lately: RF24Network for Wireless Sensor Networking | maniacbug

Cool stuff :wink:

Wow very cool indeed…
my only wish is if this was a NETMF Project and with the cerburus this would work great…

I wonder how hard it would be to port his work to NETMF.

Cheers…
Jay.

Wow, that’s very timely. I was just thinking about this Monday Gone :slight_smile: Looks awesome.

I don’t see why we shouldn’t implement this in NET MF as the implementation is not complicated (it’s the concept that needs some time to be digested). It’s a good timing since Errol, ransomhall, GHI and soldermonkey all want to create a gadgeteer module out of this chip (ransomhall is the first one to have a protototype). Maybe we could count on some more help and do this together. I’m not saying we all need to write code. It’s testing and bug reporting that is most wanted.

The board I had fabbed is a simple breakout for the existing nordic module… for those who already have them and want to “gadgeteer-ize” them. BTW, Gralin is being overly humble. It was his idea to make it.

Count me in…
I’ll be happy to contribute…

First we would need prepare a list of hardware, so whoever decided to help will know what to buy… this will allow future help to step in any time…

standing by for instructions.

thanks.

@ Jay Jay, that’s great to hear! I think the first step would be buying a few nordic modules and learning how they work using the driver that already exists. After that we can discuss implementing the network layer. You can wait for Errol to manufacture his all-in-one modules (which look great but i don’t know how long will it take him) or you can buy the nordic modules somewhere online and the gadgeteer breakouts from ransomhall. The driver available on codeplex works for net mf and has a gadgeteer driver project included but no one has yet tested it with gadgeteer ;).

Thanks Gralin,
I went ahead and ordered 4 nRF24L01+ and one of the Long Range ones from IteadStudio .
I do have the DuinoProto board and the extender module which i think would be enough to wire the modules according to the diagram you have up here…

once i get the modules i will set them up and report back here.

@ ransomhall when you get the Gadgeteer module ready please put me down for a couple…

thanks.

Great, let us know if you have any problems. Also report back how the long range version is working out for you. I guess you will be able to test the range with ACK turned off (since you have only one it will be able to send data on long range but the other board won’t be able to send ack back).

@ JayJay - they are ready. well, i need to solder on the IDC, but that won’t take long. Send your mailing info to my alias name at gmail. I’ve got a bunch of other boards I’m mailing out shortly, so will be in “shipping and handling” mode this weekend.

So I’m guessing the long range ones are back in stock. Do they say what “long range” is roughly? I might snag a couple. I’ve a friend interested in doing a person to person outdoor wireless serial data project on the cheap, and these just might be the thing to suit his budget.

Hi ransomhall,
That’s great, I’ll send you an e-mail after this post. as for the long range it does say 800m to 1km in open space…

Cheers

Just an update. My design files went to PCB-Pool on Thursday. They say I will have it by the 22nd. That is if they don’t have issues with my design.

Having 12 green boards made. Other colors aren’t an option. After the design has been validated I will have them made in purple at DorkBot.

Also, my boards will come in two flavours. One with onboard antenna. The other with U.FL connector for external antenna.