TX node:


RX node:IMG_20151230_163812832

Basic idea:

Arduino on the TX node reads analog joysticks which have value between 0-1023 (10 bits) and reads the switches.

nRF transmits data to the reciever. Total payload of 5 bytes.

5 bytes are

10 bits of throttle- reading from joystick, value b/w 0-1023, mapping it to 0-1000(add 1000 on the recieivng end gives value b/w 1000 to 2000).
9 bits of yaw- reading from the joystick..again value b/w 0 to 1024..mapped to -180 to 180..which is 8 bits + 1 bit for sign.
6 bits for pitch and roll each- reading from joysticks..mapping it to -30 to 30 in my case..6 bits + 1 bit for sign.
and extra 9 bits for other things like changing modes..turning on led’s and stuff.
in total 5=(10+9+6+6+9)/8=5 bytes

so transmitter transmits 5 * 8 bits packets..via enhanced shockburst..which is a protocol embedded in nRF’s hardware..transmitter switches automatically to reciever mode after transmitting data to recieve acknowledgement packet from reciever and if not recieved then retransmits the data..so its all automatic..one doesn’t needs to implement it..its already there in the hardware..we just have to configure it, looks something like this-


if you’re wondering where have I configured the payload size..then it has to be configured on the RX node only, here-


Once TX node transmits data..it switches to recieving mode..waits for acknowledgement..if it recieves the acknowledgement from the RX node then switches back into transmit mode..and tx interrupt is triggered which reads new value from joysticks and switches..and then again transmits waits for acknowledgement and then again interrupt.

There are in total 3 interrupt..

TX interrupt- data has been transmitted..via RF channel

RX interrupt- new data to recieve..via RF channel

MAX RT- maximum retransmissions

the way I have programmed it..if data is successfully transmitted. ISR for tx interrupt is update_tx_buffer() which reads joysticks switches..arrange them into 5 * 8 bits packets.

if new data is recieved..it is directed to ISR..get_data() function in which microcontroller sends an instruction to read the recieved data.

and max_rt() funtion is executed if max_rt interrupt is triggered..which just tells the user data send fail.

All three interrupt are triggered via IRQ pin..one has to check the status register to know which of the three interrupt has triggered and direct it to sutable ISR..something like this-


So what now..!?

RX node has the 5 packets of 8 bits each..what I did is send it to the host microcontroller(which is running the PID loops and IMU and stuff) via I squared C.

what I could have done was..4 * 10 bits for joystick data all four would have value b/w 0-1000 1 byte for the switches..total payload would add up to 48 bits or 6 bytes..and then reciever would have to use servo library to write pwm signals for the 4 channels and 1’s and 0’s for the rest..and host microcontroller would then read these channels using pinchange interrupts and digitalRead.

so I squared C between RX node and host uC made thing simple for me..as a lot less interrupts are involved. You can find the code in wire library..master reader and slave sender.

one can get the code on https://tachymoron.wordpress.com/project-type/nrf-pickle/