I apologize in advance for the long post - I am trying to include as much info as possible. I tried using the </> to put the code text in the correct format (with colored text) to no avail. Also thank you in advance for any help/thoughts/insights/questions/funny stories/etc.
I am trying to make a simple remote control using the nRF24L01 with the ezButton library. What I am trying to do is send a code to the receiver to turn on an LED when a button is pressed and then turn it off when the button is released. My thinking here is that this will keep the battery-operated transmitter from having to continuously send the code to turn the LED off, draining the battery.
I am using a macbook pro OS10.14.3, Arduino IDE 1.8.16
The transmitter is a Nano-knockoff with a current bootloader.
The receiver is a Nano-knockoff with an old bootloader.
The "Hello World" example without modifications works fine.
When I add the ezButton library and an associated button to the transmitter, the program fails to compile. (Error messages below, points that caught my eye are in bold). The button is SPST NO on pin 7, with a 1k pulldown resistor.
Questions:
Is this a correct approach to this program?
Is there another library that includes the "on press" and "on release" functions that do not interfere with the compiling?
The transmit and receiver codes directly from the examples:
//**************************************************
//RF24 TRANSMITTER FOR NANO
/* Arduino Wireless Communication Tutorial
* Example 1 - Transmitter Code
* by Dejan Nedelkovski, www.HowToMechatronics.com
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
const char text[] = "Hello World";
radio.write(&text, sizeof(text));
delay(2000);
}
// RF24 RECEIVER FOR NANO
/* 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>
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 text[32] = "";
radio.read(&text, sizeof(text));
Serial.println(text);
}
}
//**************************************************
This is the above transmitter code with the ezButton library and associated code:
//**************************************************
//RF24 TRANSMITTER FOR NANO
/* Arduino Wireless Communication Tutorial
* Example 1 - Transmitter Code
* by Dejan Nedelkovski, www.HowToMechatronics.com
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <ezButton.h> //version 1.0.3
ezButton button(7) //the pin the button is attached to
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
void setup()
{ radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop()
{ button.loop();
if (button.isPressed())
{const char text[] = "Hello World";
radio.write(&text, sizeof(text));
}
delay(2000);
}
//**************************************************
And the compiling errors that come back:
Arduino: 1.8.16 (Mac OS X), Board: "Arduino Nano, ATmega328P"
/Applications/Arduino.app/Contents/Java/arduino-builder -dump-prefs -logger=machine -hardware /Applications/Arduino.app/Contents/Java/hardware -hardware /Users/davidmisner/Library/Arduino15/packages -hardware /Arduino/hardware -tools /Applications/Arduino.app/Contents/Java/tools-builder -tools /Applications/Arduino.app/Contents/Java/hardware/tools/avr -tools /Users/davidmisner/Library/Arduino15/packages -built-in-libraries /Applications/Arduino.app/Contents/Java/libraries -libraries /Arduino/libraries -fqbn=arduino:avr:nano:cpu=atmega328 -vid-pid=1A86_7523 -ide-version=10816 -build-path /var/folders/1m/yvxgl13j0h9896gkp_221vw40000gp/T/arduino_build_948385 -warnings=all -build-cache /var/folders/1m/yvxgl13j0h9896gkp_221vw40000gp/T/arduino_cache_153418 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.arduinoOTA.path=/Users/davidmisner/Library/Arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/Users/davidmisner/Library/Arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -verbose /Arduino/RF24_TransmitterWithezButton/RF24_TransmitterWithezButton.ino
/Applications/Arduino.app/Contents/Java/arduino-builder -compile -logger=machine -hardware /Applications/Arduino.app/Contents/Java/hardware -hardware /Users/davidmisner/Library/Arduino15/packages -hardware /Arduino/hardware -tools /Applications/Arduino.app/Contents/Java/tools-builder -tools /Applications/Arduino.app/Contents/Java/hardware/tools/avr -tools /Users/davidmisner/Library/Arduino15/packages -built-in-libraries /Applications/Arduino.app/Contents/Java/libraries -libraries /Arduino/libraries -fqbn=arduino:avr:nano:cpu=atmega328 -vid-pid=1A86_7523 -ide-version=10816 -build-path /var/folders/1m/yvxgl13j0h9896gkp_221vw40000gp/T/arduino_build_948385 -warnings=all -build-cache /var/folders/1m/yvxgl13j0h9896gkp_221vw40000gp/T/arduino_cache_153418 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.arduinoOTA.path=/Users/davidmisner/Library/Arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/Users/davidmisner/Library/Arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -verbose /Arduino/RF24_TransmitterWithezButton/RF24_TransmitterWithezButton.ino
Using board 'nano' from platform in folder: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr
Using core 'arduino' from platform in folder: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr
**Warning: Board breadboard:avr:atmega328bb doesn't define a 'build.board' preference. Auto-set to: AVR_ATMEGA328BB**
Detecting libraries used...
/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/eightanaloginputs /var/folders/1m/yvxgl13j0h9896gkp_221vw40000gp/T/arduino_build_948385/sketch/RF24_TransmitterWithezButton.ino.cpp -o /dev/null
**Alternatives for ezButton.h: [ezButton@1.0.3]**
**ResolveLibrary(ezButton.h)**
** -> candidates: [ezButton@1.0.3]**
/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/eightanaloginputs -I/Arduino/libraries/ezButton/src /var/folders/1m/yvxgl13j0h9896gkp_221vw40000gp/T/arduino_build_948385/sketch/RF24_TransmitterWithezButton.ino.cpp -o /dev/null
Alternatives for SPI.h: [SPI@1.0]
ResolveLibrary(SPI.h)
-> candidates: [SPI@1.0]
/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/eightanaloginputs -I/Arduino/libraries/ezButton/src -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src /var/folders/1m/yvxgl13j0h9896gkp_221vw40000gp/T/arduino_build_948385/sketch/RF24_TransmitterWithezButton.ino.cpp -o /dev/null
Alternatives for nRF24L01.h: [RF24@1.3.4]
ResolveLibrary(nRF24L01.h)
-> candidates: [RF24@1.3.4]
/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/eightanaloginputs -I/Arduino/libraries/ezButton/src -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src -I/Arduino/libraries/RF24 /var/folders/1m/yvxgl13j0h9896gkp_221vw40000gp/T/arduino_build_948385/sketch/RF24_TransmitterWithezButton.ino.cpp -o /dev/null
/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/eightanaloginputs -I/Arduino/libraries/ezButton/src -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src -I/Arduino/libraries/RF24 /Arduino/libraries/ezButton/src/Button.cpp -o /dev/null
/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/eightanaloginputs -I/Arduino/libraries/ezButton/src -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src -I/Arduino/libraries/RF24 /Arduino/libraries/ezButton/src/ezButton.cpp -o /dev/null
/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/eightanaloginputs -I/Arduino/libraries/ezButton/src -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src -I/Arduino/libraries/RF24 /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.cpp -o /dev/null
/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/eightanaloginputs -I/Arduino/libraries/ezButton/src -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src -I/Arduino/libraries/RF24 -I/Arduino/libraries/RF24/utility /Arduino/libraries/RF24/RF24.cpp -o /dev/null
Generating function prototypes...
/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/eightanaloginputs -I/Arduino/libraries/ezButton/src -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src -I/Arduino/libraries/RF24 /var/folders/1m/yvxgl13j0h9896gkp_221vw40000gp/T/arduino_build_948385/sketch/RF24_TransmitterWithezButton.ino.cpp -o /var/folders/1m/yvxgl13j0h9896gkp_221vw40000gp/T/arduino_build_948385/preproc/ctags_target_for_gcc_minus_e.cpp
/Applications/Arduino.app/Contents/Java/tools-builder/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /var/folders/1m/yvxgl13j0h9896gkp_221vw40000gp/T/arduino_build_948385/preproc/ctags_target_for_gcc_minus_e.cpp
Compiling sketch...
/Users/davidmisner/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/eightanaloginputs -I/Arduino/libraries/ezButton/src -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src -I/Arduino/libraries/RF24 /var/folders/1m/yvxgl13j0h9896gkp_221vw40000gp/T/arduino_build_948385/sketch/RF24_TransmitterWithezButton.ino.cpp -o /var/folders/1m/yvxgl13j0h9896gkp_221vw40000gp/T/arduino_build_948385/sketch/RF24_TransmitterWithezButton.ino.cpp.o
In file included from /Arduino/RF24_TransmitterWithezButton/RF24_TransmitterWithezButton.ino:11:0:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:72:1: error: expected ',' or ';' before 'class'
class SPISettings {
^~~~~
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:178:39: error: **'SPISettings' has not been declared**
inline static void beginTransaction(SPISettings settings) {
^~~~~~~~~~~
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h: In static member function 'static void SPIClass::beginTransaction(int)':
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:203:21: error: request for member 'spcr' in 'settings', which is of non-class type 'int'
SPCR = settings.spcr;
^~~~
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:204:21: error: request for member 'spsr' in 'settings', which is of non-class type 'int'
SPSR = settings.spsr;
^~~~
Using library ezButton at version 1.0.3 in folder: /Arduino/libraries/ezButton
Using library SPI at version 1.0 in folder: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI
Using library RF24 at version 1.3.4 in folder: /Arduino/libraries/RF24
exit status 1
Error compiling for board Arduino Nano.