Skip to content

Instantly share code, notes, and snippets.

@kjiwa
Last active August 29, 2015 14:27
Show Gist options
  • Save kjiwa/196b5117c0175a00e017 to your computer and use it in GitHub Desktop.
Save kjiwa/196b5117c0175a00e017 to your computer and use it in GitHub Desktop.
/**
* An Arduino program that listens for messages on an RF radio and prints them
* on the serial console.
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/**
* The pipe number to use when receiving messages from transmittors.
*/
#ifndef RECEIVER_PIPE_NO
#define RECEIVER_PIPE_NO 1
#endif
/**
* The pipe address to use when receiving messages. Addresses are 40-bit values
* (0x0000000000000000 - 0x000000ffffffffff).
*/
#ifndef RECEIVER_PIPE_ADDR
#define RECEIVER_PIPE_ADDR 0x0000000000000000
#endif
/**
* A message containing sensor readings. The structure is:
*
* 0: A number uniquely identifying the device.
* 1: The temperature in Kelvin.
*/
static int msg[2];
/**
* A handle to the Bluetooth transceiver. The transceiver requires a 3.3V supply
* voltage and is connected in the following way:
*
* CE: 9
* CSN: 10
* MOSI: 11
* MISO: 12
* SCK: 13
*/
static RF24 radio(9, 10);
void setup() {
Serial.begin(115200);
/* Initialize the RF radio. */
radio.begin();
radio.openReadingPipe(RECEIVER_PIPE_NO, RECEIVER_PIPE_ADDR);
radio.startListening();
}
void loop() {
if (!radio.available()) {
return;
}
if (!radio.read(&msg, sizeof(msg))) {
Serial.println("Error reading payload.");
return;
}
Serial.print("ID: ");
Serial.println(msg[0]);
Serial.print("Temperature: ");
Serial.println(msg[1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment