Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Arduino Wireless Communication Tutorial
- * Example 1 - Receiver Code
- *
- * by Dejan Nedelkovski, www.HowToMechatronics.com
- *
- * Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
- */
- #include <SPI.h>
- #include <nRF24L01.h>
- #include <RF24.h>
- #define PAYLOAD_LEN 32
- #define MESSAGE_KEY 12345
- typedef enum {
- SENSOR_TEMP = 0,
- SENSOR_PRESS
- } sensor_type_t;
- typedef struct {
- int key;
- sensor_type_t type;
- int val;
- } sensor_data_t;
- RF24 radio(9, 10); // CE, CSN
- const byte address[6] = "00001";
- void setup() {
- Serial.begin(9600);
- radio.begin();
- radio.openReadingPipe(0, address);
- radio.setPALevel(RF24_PA_MIN);
- radio.startListening();
- }
- void loop() {
- if (radio.available()) {
- char data[PAYLOAD_LEN] = {0};
- radio.read(data, PAYLOAD_LEN);
- sensor_data_t *msg = (sensor_data_t *)data;
- Serial.println("MESSAGE RECEIVED!\n");
- if (msg->key == MESSAGE_KEY)
- Serial.println(" KEY MATCH!\n");
- Serial.println(msg->key);
- Serial.println(msg->type);
- Serial.println(msg->val);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement