Go Down

Topic: SoftwareSerial dropping bytes when Arduino doing nRF24L01 radio.write() (Read 755 times) previous topic - next topic

Stanley

I've wrote a code to read in serial data ( GPS NMEA data in my case ) and send it across to the other nRF24L01 radio using the same code as a receiver and display them on serial monitor or have GPS s/w read those NMEA data...

As the max bytes for the GPS is less than 90 bytes, I've chopped up the data to three packets as the nRF24L01 can only take 32Bytes max...

With minor packet drops and such, I'm able to get my code running ( merged back the packets ) but when I compared the raw data to the ones I'm receiving, I notice there are lots of dropped bytes when I was in the sendPackets() functions. I was able to get a GPS location lock but not able to see all the birds and their signals...

When I commented out this sendPackets() function, I do not get any dropped bytes...

When I made another sketch with all the nRF24L01 codes deleted, I was able to open a GPS s/w to get all the birds and location fixed..

Is this a SoftwareSerial issue or I need a method to buffer those incoming bytes while Arduino is busy sending out those packets to the nRF24L01 ??

Any ideas/suggestions are welcome...

Thanks

Below is the link to my full source code...
http://pastebin.com/0bDuGESY
nRF24L01+ UNO Adapter for Sale :-
http://arduino-for-beginners.blogspot.com/p/nrf-adapter-for-sale.html

UncleUnvoid

I have something maybe similar, reading a basic serial out of an imp. It gets all the individual bytes, but stops adding it to a string at random places, when I try to add them all back up.

Los garillas a l'arriba siempre cakaras a los de la bajo. (or so)

pylon

I don't understand where exactly your problem is but the SoftwareSerial class is designed in a way that it doesn't coexist very well with other stuff that relies on interrupts or other response in a timely manner. This is because during the transmission or reception of a byte all interrupts are disabled and the processor is blocked completely. You've chosen a baudrate of 9600 which means that receiving one byte blocks the processor completely for about 1ms.

If you want to get your project reliable use the hardware serial for the GPS connection and if really necessary, use the SoftwareSerial for debugging output because then you can control, when the interruption happens. This has the drawback that you need a USB2Serial adapter for the connection to the PC but that's necessary only during debugging. Alternatively you may choose a Mega2560 (4 hardware serials) or a Leonardo (USB debugging without using the hardware serial).

Stanley

Quote

If you want to get your project reliable use the hardware serial for the GPS connection and if really necessary, use the SoftwareSerial for debugging output because then you can control, when the interruption happens. This has the drawback that you need a USB2Serial adapter for the connection to the PC but that's necessary only during debugging. Alternatively you may choose a Mega2560 (4 hardware serials) or a Leonardo (USB debugging without using the hardware serial).


Thanks for the suggestions, I swapped GPS to use h/w serial and plug in a USB-Serial for debugging purpose/serial monitor

I also tweak the nRF24L01 settings for non-blocking radio.write and everything seems to be working... I can use a GPS s/w to open the serial monitor on the receiving end and get valid GPS data..

Below is the updated working code, not optimize yet but it is working...
http://pastebin.com/EVMge54h
nRF24L01+ UNO Adapter for Sale :-
http://arduino-for-beginners.blogspot.com/p/nrf-adapter-for-sale.html

Go Up