Ancora una scheda con Arduino ATmega328. Questa volta la integriamo su di una scheda 70x90 e con l'utilizzo di un modulo ricetrasmettitore nRF24L01. Il tutto è stato predisposto per funzionare sul Bus 7090 e potersi collegare al Display TFT, alimentandosi dalla scheda PSU.
Scheda 70x90 con modulo PCB Arduino Nano 328 + nRF24L01
Il ricetrasmettitore nRF24L01 è un modulo molto popolare, da collegare alla porta SPI di Arduino o altri microcontrollori, con ottime caratteristiche di connessione dati fino alla velocità di 2Mbps in banda ISM (2,4 GHz). Esso consente di ricevere i dati dai nostri sensori e comandare i nostri attuatori, con un architettura di rete Punto-Punto oppure Punto-Multipunto. Il modulo RF è molto versatile e si presta nelle varie versioni disponibili per collegamenti dati da poche decine di metri ad alcune centinai di metri.
Test di integrazione con Display TFT, Modulo PSU e Bus 7090
Le librerie software per l'IDE Arduino sono ben fatte e documentate. L'integrazione di un microcontrollore con una rete di sensori/attuatori non risulterà difficile.
Ecco un semplice software di ricezione dati testato con l'IDE Arduino 1.8.19.
/*
READ THIS BEFORE USE:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
////////////////////////////////////////////////////
// SYSTEM-24
// nRF24L01+ Receiver v.1.0 last update 07/03/2024
// Periferal:
// nRF24L01+
////////////////////////////////////////////////////
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//objects
RF24 radio(7, 8); // CE, CSN
//globals
const byte addressOfSlave [][6] = {"SLV01", "SLV02"}; //Setting the Slave TX Pipe Address
const byte addressOfMaster [][6] = {"MST01", "MST02"}; //Setting the Master RX Pipe Address
String nrf_message = ""; //message received fron NRF24L01
char rx_text[32]; //nRF24L01 rx buffer
int line_count = 0; //display line counter
//system setup
void setup() {
Serial.begin(9600);
//time to reset dispay TFT
delay(5000);
//nRF24L01+
radio.begin(); //start communication
radio.setPALevel(RF24_PA_HIGH); //set it as minimum or maximum depending on the distance between the transmitter and receiver.
radio.setDataRate(RF24_250KBPS); //minimum
radio.openReadingPipe(1, addressOfMaster[0]); //Slave rx
radio.startListening(); //This sets the module as receiver
Serial.println("$Ready for listening!");
delay(200);
line_count++;
//delete nRF input buffer
if(radio.available()) {
radio.read(&rx_text, sizeof(rx_text)); //read data
}
} //setup
//application loop
void loop() {
//check nRF24 radio
if(radio.available()) {
radio.read(&rx_text, sizeof(rx_text)); //reading data
nrf_message = String(rx_text);
Serial.print("$");
Serial.println(nrf_message);
line_count++;
//manage the TFT text page
if (line_count > 14) {
Serial.print("$%CLEAR%\r\n");
delay(500);
line_count = 0;
}
}
} //loop
* - * - * - *
Il trasmettitore, invece utilizza questo codice per trasmettere i dati di alcuni sensori. (Abbinare correttamente ricevitore e trasmettitore per un funzionamento ottimale)
* - * - * - *
/*
READ THIS BEFORE USE:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* SYSTEM-24 Package */
/* nRF24L01+ Remote Transmitter with DHT, LDR, 18B20 - v.1.5 last update 09/03/2024 */
/* Transmit format 0x:yyyy... */
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <DHT.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define DHTPIN 6 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
#define ONE_WIRE_BUS 4 //pin D4
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
RF24 radio(7, 8); // CE, CSN (ex 9, 10)
DHT dht(DHTPIN, DHTTYPE);
const byte address [][6] = {"MST01", "SLV01"}; //Setting the two addresses. One for transmitting and one for receiving
char pck_signal[32];
int led_pin = 3;
char str[4];
void setup() {
//ldr
pinMode(5, OUTPUT); //ldr power
digitalWrite(5,HIGH); //power on LDR
//serial
Serial.begin(9600);
//radio
radio.begin();
radio.openWritingPipe(address[0]); //Setting the address where we will send the data
radio.openReadingPipe(1, address[1]); //Setting the address where we will receive the data
radio.setPALevel(RF24_PA_HIGH); //You can set this as minimum or maximum depending on the distance between the transmitter and receiver.
radio.setDataRate(RF24_250KBPS); //minimum
//DHT
dht.begin();
digitalWrite(5,HIGH); //power on LDR
Serial.println("Remote DHT, LDR, 18B20");
//DS18B20
sensors.begin(); // IC Default 9 bit
}
void loop() {
String temp = "";
float t;
float h;
// DHT11 - Read temperature as Celsius (the default)
t = dht.readTemperature();
temp = "00"; //node '0'
temp.concat(":");
temp.concat(String(t,1));
temp.toCharArray(pck_signal,temp.length());
//DHT11 - Read humidity
h = dht.readHumidity();
temp.concat(",");
temp.concat(String(h,1));
temp.toCharArray(pck_signal,temp.length());
//LDR
temp.concat(",");
sprintf(str, "%04d", 1023 - analogRead(A7));
temp.concat(str);
temp.toCharArray(pck_signal,temp.length());
//DS18B20
sensors.requestTemperatures(); // Send the command to get temperatures
temp.concat(",");
temp.concat(String(sensors.getTempCByIndex(0),1)); //Index 0
temp.concat(0x00);
temp.toCharArray(pck_signal,temp.length());
//transmit packet
Serial.println(pck_signal);
radio.write(&pck_signal, sizeof(pck_signal));
//loop every second
delay(1000);
} //loop
Buon lavoro di interconnessione dati. A presto.