Skip to content

Instantly share code, notes, and snippets.

@netmaniac
Created November 18, 2015 12:07
Show Gist options
  • Save netmaniac/dfd7eb4f884d58346480 to your computer and use it in GitHub Desktop.
Save netmaniac/dfd7eb4f884d58346480 to your computer and use it in GitHub Desktop.
//https://github.com/nettigo/RadioNRF24
#include <SPI.h>
#include <RadioNRF24.h>
#define BUFF_SIZE 40
struct Payload {
byte id;
unsigned long data;
} payload;
#define LED 1
void lightOn(unsigned tme = 1000) {
digitalWrite(LED, LOW);
delay(tme);
digitalWrite(LED, HIGH);
delay(tme);
}
void setup() {
Serial.begin(19200);
payload.id = 66;
payload.data = 99;
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
Serial.println(F("Before begin"));
byte address[3] = {0, 0, 1};
RadioNRF24.begin(address, 100, 8, 7);
for (byte i = 0; i < 5; i++) {
lightOn(100);
}
}
byte pongAddr[3] = {1, 0, 1};
byte received[BUFF_SIZE];
unsigned long last_send = 0;
void loop() {
// put your main code here, to run repeatedly:
//if (digitalRead(BUTTON) == LOW) {
if (millis() - last_send > 2000 + random(1000)) {
last_send = millis();
RadioNRF24.write(pongAddr, payload);
int ret = RadioNRF24.flush();
Serial.print("Debug: ");
Serial.println(ret);
delay(5);
}
// lightOn();
//}
int cnt = RadioNRF24.available();
if (cnt) {
Serial.print(F("avail: "));
Serial.println(cnt, DEC);
RadioNRF24.read(received);
for (int i = 0; i < cnt; i++) {
Serial.print(i);
Serial.print(F(" -> "));
Serial.print(received[i]);
Serial.print(F(", "));
}
Serial.println();
}
}
//Uses Radio libary for tinyBrd in 1.0 version (Radio object not RadioNRF24 yet)
#include <SPI.h>
#include <Radio.h>
#define BUFF_SIZE 40
TinyDebugSerial debug = TinyDebugSerial();
struct Payload {
byte id;
byte data;
} payload;
#define LED 1
void lightOn(unsigned tme = 1000) {
digitalWrite(LED, LOW);
delay(tme);
digitalWrite(LED, HIGH);
delay(tme);
}
void setup() {
debug.begin(9600);
payload.id = 66;
payload.data = 99;
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
byte address[3] = {1, 0, 1};
Radio.begin(address, 100);
for (byte i = 0; i < 5; i++) {
lightOn(100);
}
debug.println(F("GO!"));
}
byte pongAddr[3] = {0, 0, 1};
byte received[BUFF_SIZE];
unsigned long last_send = 0;
void loop() {
// put your main code here, to run repeatedly:
//if (digitalRead(BUTTON) == LOW) {
if (millis() - last_send > 2000 + random(1000)) {
last_send = millis();
Radio.write(pongAddr, payload);
int ret = Radio.flush();
debug.print("Debug: ");
debug.println(ret);
delay(5);
}
// lightOn();
//}
int cnt = Radio.available();
if (cnt) {
debug.print(F("avail: "));
debug.println(cnt, DEC);
debug.print(F("Recvd: "));
Radio.read(received);
for (int i = 0; i < cnt; i++ ) {
debug.print(i, DEC);
debug.print(F("-> "));
debug.print(received[i], DEC);
debug.print(F(", "));
}
debug.println();
}
}
@netmaniac
Copy link
Author

Arduino.ino - sends data to tinyBrd and listens for incoming data
tinybrd.ind - sends data to Arduino and listens for incoming data
Received bytes are displayed on Serial. On tinyBrd serial is software only, one direction on D0...
http://starter-kit.nettigo.eu/2015/using-tinybrd-library-on-arduino-to-connect-via-nrf24l01/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment