This shows you the differences between two versions of the page.
|
digispark:tutorials:pronrf [2014/11/25 11:50] netguy204 |
digispark:tutorials:pronrf [2016/06/09 12:03] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | This page is a work in progress. | ||
| - | Progress on reverse engineering the Pro nRF Shield so far: | ||
| - | |||
| - | Pins: | ||
| - | |||
| - | {{:digispark:tutorials:nrfmodule.jpg?600|}} | ||
| - | |||
| - | Assembled: | ||
| - | |||
| - | {{:digispark:tutorials:evernote-camera-roll-20141125-143604.jpg?600|}} | ||
| - | |||
| - | Stacked Up and Ready to Go: | ||
| - | |||
| - | {{:digispark:tutorials:evernote-camera-roll-20141125-143141.jpg?600|}} | ||
| - | |||
| - | Dependencies: | ||
| - | |||
| - | Use the [[https://github.com/maniacbug/RF24|RF24]] library to control the module. You can [[https://github.com/maniacbug/RF24/archive/master.zip|download the latest version here]]. Copy the contents of the zip to your libraries directory. | ||
| - | |||
| - | Sketches: | ||
| - | |||
| - | You'll need two Digispark Pros with nRF modules to execute these sketches. Select one Digispark to be the sender and load this code: | ||
| - | |||
| - | <code> | ||
| - | #include <SPI.h> | ||
| - | #include "nRF24L01.h" | ||
| - | #include "RF24.h" | ||
| - | |||
| - | RF24 radio(9,12); | ||
| - | const int LED = 1; | ||
| - | |||
| - | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; | ||
| - | |||
| - | // The various roles supported by this sketch | ||
| - | typedef enum { role_ping_out = 1, role_pong_back } role_e; | ||
| - | |||
| - | // The role of the current running sketch | ||
| - | role_e role = role_pong_back; | ||
| - | |||
| - | void setup() { | ||
| - | // put your setup code here, to run once: | ||
| - | pinMode(LED, OUTPUT); | ||
| - | | ||
| - | digitalWrite(LED, LOW); | ||
| - | radio.begin(); | ||
| - | radio.setRetries(15, 15); | ||
| - | radio.openWritingPipe(pipes[1]); | ||
| - | digitalWrite(LED, HIGH); | ||
| - | } | ||
| - | |||
| - | void loop() { | ||
| - | unsigned long value = 2000; | ||
| - | bool ok = radio.write(&value, sizeof(unsigned long)); | ||
| - | | ||
| - | if(ok) { | ||
| - | digitalWrite(LED, LOW); | ||
| - | delay(2000); | ||
| - | digitalWrite(LED, HIGH); | ||
| - | } | ||
| - | } | ||
| - | </code> | ||
| - | |||
| - | The other Digispark should be the receiver. Upload this code: | ||
| - | |||
| - | <code> | ||
| - | #include <SPI.h> | ||
| - | #include "nRF24L01.h" | ||
| - | #include "RF24.h" | ||
| - | |||
| - | RF24 radio(9,12); | ||
| - | const int LED = 1; | ||
| - | |||
| - | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; | ||
| - | |||
| - | // The various roles supported by this sketch | ||
| - | typedef enum { role_ping_out = 1, role_pong_back } role_e; | ||
| - | |||
| - | // The role of the current running sketch | ||
| - | role_e role = role_pong_back; | ||
| - | |||
| - | void setup() { | ||
| - | // put your setup code here, to run once: | ||
| - | pinMode(LED, OUTPUT); | ||
| - | | ||
| - | digitalWrite(LED, LOW); | ||
| - | radio.begin(); | ||
| - | radio.setRetries(15, 15); | ||
| - | radio.openReadingPipe(1, pipes[1]); | ||
| - | radio.startListening(); | ||
| - | digitalWrite(LED, HIGH); | ||
| - | } | ||
| - | |||
| - | void loop() { | ||
| - | if(radio.available()) { | ||
| - | unsigned long value; | ||
| - | bool done = false; | ||
| - | while(!done) { | ||
| - | done = radio.read(&value, sizeof(unsigned long)); | ||
| - | delay(20); | ||
| - | } | ||
| - | | ||
| - | digitalWrite(LED, LOW); | ||
| - | delay(1000); | ||
| - | digitalWrite(LED, HIGH); | ||
| - | } | ||
| - | } | ||
| - | </code> | ||
| - | |||
| - | Now, when both units are powered up the LEDs on both should start blinking. If either is unplugged then the LED on the other will revert to solid on. | ||