Ok that’s this library in the registry:
If you use lib_deps = nrf24/RF24@^1.4.8
in your platformio.ini the library will be installed automatically. Delete the manual installed library inside the lib
folder
That’s wrong. It must be board = atmega328pb
So here is everyhing you need:
platformio.ini
:
[env:atmega328pb]
platform = atmelavr
board = atmega328pb
framework = arduino
lib_deps = nrf24/RF24@^1.4.8
main.cpp
:
#include <Arduino.h>
#include <RF24.h>
#define LUCI 4
#define BELL 5
#define FARI 6
#define GANCIO 7
#define CE_PIN 8
#define CSN_PIN 9
#define H_POT A6
#define V_POT A7
byte aux = 0;
int h_pot = 0;
int v_pot = 0;
struct dataStruct
{
char direzione;
byte speed;
byte sterzo;
byte Tool;
} dataTosend;
RF24 radio(CE_PIN, CSN_PIN); // Creo radio e definisco i pin
const uint64_t pipeOut = 0xE8E8F0F0E1LL; // indirizzo dello slave
void setup()
{
pinMode(LUCI, INPUT_PULLUP);
pinMode(FARI, INPUT_PULLUP);
pinMode(BELL, INPUT_PULLUP);
pinMode(GANCIO, INPUT_PULLUP);
Serial.begin(9600);
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS); // la più performante
radio.setPALevel(RF24_PA_MIN);
// radio.setPALevel(RF24_PA_MAX); // non usare con il piccolo
radio.openWritingPipe(pipeOut); // il primo indirizzo della matrice
}
void loop()
{
v_pot = analogRead(V_POT); // VRX
// h_pot = analogRead(H_POT); // VRY
// Avanti indietro altrimenti ferma
if (v_pot >= 550)
{
dataTosend.direzione = 'A'; // AVANTI
dataTosend.speed = (byte)map(v_pot, 550, 1023, 1, 255); // velocità
}
else if (v_pot <= 450)
{
dataTosend.direzione = 'I'; // INDIETRO
dataTosend.speed = (byte)map(v_pot, 450, 0, 1, 255); // velocità
}
else
{
dataTosend.direzione = 'S'; // STOP
dataTosend.speed = 0x00; // Speed
}
// Se non è un dataTosend.servo modificare
h_pot = analogRead(H_POT); // VRY
// alza e abbassa pala altrimenti pozizione di riposo
if (h_pot >= 550)
{ // ALZA LA PALA
dataTosend.sterzo = (byte)map(h_pot, 550, 1023, 89, 0); // da definire
}
else if (h_pot <= 450)
{
dataTosend.sterzo = (byte)map(h_pot, 450, 0, 91, 180); // da definire
}
else
{
dataTosend.sterzo = (byte)90; // posizione di riposo da definire
}
// tool fari lampeggiator & C
aux = 0x00;
if (digitalRead(LUCI) == 0)
{
aux = aux | 0x10;
}
if (digitalRead(FARI) == 0)
{
aux = aux | 0x20;
}
if (digitalRead(BELL) == 0)
{
aux = aux | 0x40;
}
if (digitalRead(GANCIO) == 0)
{
aux = aux | 0x80;
}
dataTosend.Tool = aux;
radio.write(&dataTosend, sizeof(dataTosend));
/*
//per debug
Serial.print(dataTosend.direzione);
Serial.print(" ");
Serial.print(dataTosend.speed);
Serial.print(" ");
Serial.print(dataTosend.sterzo);
Serial.print(" ");
Serial.println(dataTosend.Tool);
delay(1000);
*/
}
result:
Processing atmega328pb (platform: atmelavr; board: atmega328pb; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/atmega328pb.html
PLATFORM: Atmel AVR (4.0.1) > ATmega328PB
HARDWARE: ATMEGA328PB 16MHz, 2KB RAM, 32KB Flash
PACKAGES:
- framework-arduino-avr-minicore @ 2.1.3
- toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 9 compatible libraries
Scanning dependencies...
Dependency Graph
|-- RF24 @ 1.4.8
Building in release mode
Checking size .pio\build\atmega328pb\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [= ] 10.8% (used 221 bytes from 2048 bytes)
Flash: [= ] 12.5% (used 4042 bytes from 32256 bytes)
================================================================================= [SUCCESS] Took 1.23 seconds =================================================================================