Hi,
I've been experimenting with the nRF24L01 transmit/receive modules for Arduino.
This tutorial provides two Arduino projects, one for the transmitter and one for the receiver. It's originally a mail box indicator project where one Arduino sends a bit when the mail box is opened, and the other Arduino receives it and indicate that the mail box is opened.
I'm going to use this as a baseline for my project, which is to indicate that a fridge door has been opened where samples are placed temporarily for pick-up. The laboratory employee will get a notification light, walks down to the fridge, picks up the sample and should then reset the indicator with a button by the fridge.
This is the receiver code in question:
// RECEIVER
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
//#include "printf.h"
#define ledPin 4
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(9,10);
// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = {
0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
void setup(void)
{
pinMode(ledPin, OUTPUT);
Serial.begin(57600);
// printf_begin();
// printf("THIS IS THE RECEIVER");
radio.begin();
// optionally, increase the delay between retries & # of retries
radio.setRetries(15,15);
// optionally, reduce the payload size. seems to
// improve reliability
//radio.setPayloadSize(8);
radio.openReadingPipe(1,pipes[0]);
radio.startListening();
//radio.printDetails(); uncomment to debug
}
void loop(void)
{
unsigned long data_in = getData();
if(data_in == 999){
Serial.println("THE VALUE IS HIGH!");
digitalWrite(ledPin,HIGH);
}
else if(data_in == 111){
Serial.println("THE VALUE IS LOW");
digitalWrite(ledPin, LOW);
}
else if(data_in != 111 || data_in != 999)
Serial.println("UNEXPECTED DATA IN");
}
unsigned long getData(){
delay(50);
unsigned long got_time;
if ( radio.available() ) {
// Dump the payloads until we've gotten everything
bool done = false;
while (!done)
{
// Fetch the payload, and see if this was the last one.
done = radio.read( &got_time, sizeof(unsigned long )); // return true when done
// Spew it
// printf("Got payload %lu...",got_time);
}
}
return(got_time);
}
However, the receiver code does not want to compile. It throws an error:
Arduino: 1.8.15 (Windows 10), Board: "Arduino Micro"
C:\Users\XXXXX\OneDrive - XXXXX\Dokumenter XXXXXX - XXXXXXX\Prosjekter\Kjøleskapssignal lab\Program\RECEIVER\RECEIVER.ino: In function 'long unsigned int getData()':
RECEIVER:66:59: error: void value not ignored as it ought to be
exit status 1
void value not ignored as it ought to be
The transmitter code compiles with no problem:
// TRANSMITTER
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
//#include "printf.h"
#define ledPin 7
#define sensorPin 4
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(9,10);
//
// Topology
//
// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = {
0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
void setup(void)
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
pinMode(sensorPin, INPUT_PULLUP);
Serial.begin(57600);
// printf_begin();
// printf("TRANSMITTER\n");
radio.begin();
// optionally, increase the delay between retries & # of retries
radio.setRetries(15,15);
// optionally, reduce the payload size. seems to
// improve reliability
//radio.setPayloadSize(8);
//
// Open pipes to other nodes for communication
//
// This simple sketch opens two pipes for these two nodes to communicate
// back and forth.
// Open 'our' pipe for writing
// Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)
//if ( role == role_ping_out )
{
radio.openWritingPipe(pipes[0]);
//radio.openReadingPipe(1,pipes[1]);
}
//else
{
//radio.openWritingPipe(pipes[1]);
// radio.openReadingPipe(1,pipes[0]);
}
//
// Start listening
//
// radio.startListening();
//
// Dump the configuration of the rf unit for debugging
//
//radio.printDetails();
}
void loop(void)
{
boolean recived_data;
boolean sensorStat = digitalRead(sensorPin);
if(sensorStat == LOW){ // connection has been made
boolean recived_data;
do{
recived_data = sendData(999);
Serial.println("Data has not been recived");
}while(recived_data == false);
//if(sensorStat == HIGH)
//sendData(111);
}
}
boolean sendData(unsigned long dataToSend){
// Take the time, and send it. This will block until complete
// printf("Now sending %lu...",dataToSend);
bool ok = radio.write( &dataToSend, sizeof(unsigned long ) );
if (ok){
// printf("Message was recived\n"); // confirmed it has been recived
digitalWrite(ledPin, HIGH);
return(true);
}
else{
// printf("failed.\n\r");
digitalWrite(ledPin,LOW);
return false;
}
}
I'm not quite familiar with Arduino programming yet, and my attempts to learn what's wrong have failed. I have been mostly programming industrial PLCs, so this is completely new for me.
It seems like it's trying to get a value out of ( &got_time, sizeof(unsigned long ) but it shouldn't?
The Arduino used is a Micro for both the transmitter and receiver.
Does anyone know what I should do to correct the error? Thanks.
