Arduino weather station wireless con NRF24L01+PA+LNA+dht11+bmp180+mq135+HC-05 con doppio display oled 0,96" arduino nano+mega


Ci siamo!!Dopo aver smanettato con i sensori e i display (vedi articoli precedenti)
è arrivato il momento di realizzare una stazione meteo wireless aggiungendo ai progetti realizzati precedentemente i moduli NFR24L01 con arduino nano come postazione trasmittente dei dati ambientali ed arduino mega con dual display come  stazione ricevente.

Il modulo NRF24L01 è un chip prodotto dall’azienda Nordic Semiconductor ed è in grado di trasmettere dati in modo bidirezionale.

La trasmissione avviene attraverso onde radio a 2,4Ghz ISM,scambiando dati fino ad un centinaio di metri.

Specifiche tecniche del modulo NRF24L01+pa+lna

  • Tensione operativa: 1.9V~3.6V
  • Modalità di risparmio energetico: consumo 1μA
  • Antenna: 2.4GHZ 
  • Velocità operativa (max): 2Mbps
  • Regolatore di tensione: integrato
  • Altre funzioni: comunicazione Multi-point a 125 canali, salto di frequenza, anti-interferenza, modulazione GFSK
  • Rilevamento errori CRC







Nel mio circuito ho utilizzato i moduli NRF24L01+PA+LNA dotati di antennina,inoltre ho preferito utilizzare degli adattatori (vedi foto)per poterli alimentare direttamente a 5V dato che questi modulini soffrono un pochino se alimentati a 3,3V(esistono  vari articoli su google che descrivono questi problemi con relative soluzioni).

NRF24L01 con l'adattatore 5V

Per quanto riguarda i collegamenti dei pin del modulino NRF24L01 con l'adattatore ad arduino mega e nano  ho seguito le seguenti istruzioni.

Arduino mega- adattatore+NRF24L01
5V-VCC
GND-GND
8-CSN
7-CE
52-SCK
51-MOSI
50-MISO

Arduino nano - adttatore+NRF24L01
5V-VCC
GND-GND
8-CSN
7-CE
13-SCK
11-MOSI
12-MISO

ATTENZIONE NON COLLEGARE DIRETTAMENTE IL MODULO NRF24L01 Al pin  5 VOLT DI ARDUINO MA USATE L'ADATTATORE di ALIMENTAZIONE MOSTRATO IN FOTO.



Nei miei articoli precedenti trovate gli schemi elettrici e sketch dei progetti con sensori ,display e bluetooth,quindi se li avete visti saprete sicuramente a questo punto collegare i vari sensori (dht11,bmp180,mq135) e display (oled ssd1306,sh1106) utilizzati in questo progetto.Ribadisco che sono alle primissime armi con arduino e tutto quello che pubblico in questi articoli è stato  testato personalmente.Vi consiglio sempre di prestare attenzione ai collegamenti per evitare di danneggiare i vari componenti.

Materiali per questo progetto:
  • arduino mega 2560 x1
  • arduino nano x1
  • NRF24l01+PA+LNA x2
  • adattatore 5volt per NRF24l01 x2
  • hc-05 x1
  • mq135 x1
  • dht11 x1
  • bmp180 x1
  • breadboard x2
  • cavi dupont
  • oled display ssd1306 da 0,96" x2

Una volta caricati gli sketch tx su arduino nano con i vari sensori e lo sketch rx su arduino mega collegato ai due display,inizieremo a visualizzare dopo una schermata iniziale i vari dati sui due display,inoltre tramite il modulo bluetooth hc-05 sarà possibile visualizzarli anche su smartphone.

codice tx da caricare su  arduino nano:

/* Stazione trasmissione dati wireless con bluetooth HC-05 e NFR24L01,
con rilevamento di temperatura e umidità (DHT11),pressione e altitudine (BMP180),
gas CO,CO2,NH4 (MQ-135).*/

//includo le librerie 
#include <RF24_config.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>
#include  <SPI.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <DHT.h>
#include <MQUnifiedsensor.h>
#include  <Adafruit_Sensor.h>

#define DHTTYPE DHT11   // DHT 11 
#define DHTPIN 2// Set DHT pin2
#define placa "Arduino Nano"
#define Voltage_Resolution 5
#define pin A0 //Analog input 0 of your arduino
#define type "MQ-135" //MQ135
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
#define RatioMQ135CleanAir 3.6//RS / R0 = 3.6 ppm 

//Dichiaro il  Sensore mq135
MQUnifiedsensor MQ135(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);

//creo un nome al sensore barometrico
Adafruit_BMP085 BMP180;

// Initialize DHT sensor for normal 16mhz Arduino:
DHT dht = DHT(DHTPIN, DHTTYPE);

//NRF24L01
const int pinCE = 7;
const int pinCSN = 8;
RF24 radio(pinCE, pinCSN);
byte addresses[][6] = {"0"};

// Single radio pipe address for the 2 nodes to communicate.
const uint64_t pipe = 0xE8E8F0F0E1LL;
struct package
{
  float temperature ;
  float pressure;
  float humidity ;
  float Altitude;
  float CO2;
  float CO;
  float NH4;
  float Acetona;
};
typedef struct package Package;
Package data;

void setup()
{
  //inizializzo la seriale
  Serial.begin(9600);
  //inizializzo la radio
  radio.begin();
  radio.setChannel(115);
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate( RF24_250KBPS ) ;
  radio.openWritingPipe( addresses[0]);

  delay(1000);

  // Setup sensor:
  dht.begin();
  BMP180.begin();

  //Set math model to calculate the PPM concentration and the value of constants
  MQ135.setRegressionMethod(1); //_PPM =  a*ratio^b

  /*****************************  MQ Init ********************************************/
  //Remarks: Configure the pin of arduino as input.
  /************************************************************************************/
  MQ135.init();

  float calcR0 = 0;
  for (int i = 1; i <= 10; i ++)
  {
    MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin
    calcR0 += MQ135.calibrate(RatioMQ135CleanAir);
  }
  MQ135.setR0(calcR0 / 10);
}

void loop()

{
  // Read the humidity in %:
  float h = dht.readHumidity();
  // Read the temperature as Celsius:
  float t = dht.readTemperature();
  // Read the temperature as Fahrenheit:
  float f = dht.readTemperature(true);

  // Compute heat index in Fahrenheit (default):
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius:
  float hic = dht.computeHeatIndex(t, h, false);

  MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin

  MQ135.setA(605.18); MQ135.setB(-3.937); // Configurate the ecuation values to get CO concentration
  float CO = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup

  MQ135.setA(77.255); MQ135.setB(-3.18); // Configurate the ecuation values to get Alcohol concentration
  float Alcohol = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup

  MQ135.setA(110.47); MQ135.setB(-2.862); // Configurate the ecuation values to get CO2 concentration
  float CO2 = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup

  MQ135.setA(44.947); MQ135.setB(-3.445); // Configurate the ecuation values to get Tolueno concentration
  float Toluene = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup

  MQ135.setA(102.2 ); MQ135.setB(-2.473); // Configurate the ecuation values to get NH4 concentration
  float NH4 = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup

  MQ135.setA(34.668); MQ135.setB(-3.369); // Configurate the ecuation values to get Acetona concentration
  float Acetona = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup

  //scrivo sul seriale:
  Serial.println("*****************");
  Serial.println("lettura dati DHT11,BMP180");
  Serial.println("");

 //pressione atmosferica
  Serial.print("Pressione atmosferica = ");
  Serial.print(BMP180.readPressure()/100);
  Serial.println(" mbar");

  //altitudine
  Serial.print("Altitudine = ");
  Serial.print(BMP180.readAltitude());
  Serial.println(" metri");

  //pressione atmosferica dal livello del mare
  Serial.print("Pressione dal livello del mare (calcolata) = ");
  Serial.print(BMP180.readSealevelPressure()/100);
  Serial.println(" mbar");

  //altitudine reale
  Serial.print("Altitudine reale = ");
  Serial.print(BMP180.readAltitude(101500));
  Serial.println(" metri");

  //scrivo sul seriale i dati di Temperatura e umidità
  Serial.print(F("Umidità: "));
  Serial.print(h);
  Serial.println(F(" %"));
  Serial.print("Temperatura: " );
  Serial.print(t);
  Serial.println(F(" °C"));

  //scrivo sul seriale i dati del sensore MQ135
  Serial.println("******Lettura valori sensore MQ135******");
  Serial.println(" ");

  Serial.print("Monossido di carbonio CO= ");
  Serial.print(CO);
  Serial.println(" PPM");

  Serial.print("Alcohol= ");
  Serial.print(Alcohol);
  Serial.println(" PPM");

  Serial.print("Anidride carbonica CO2= ");
  Serial.print(CO2);
  Serial.println(" PPM");

  Serial.print("Toluene= ");
  Serial.print(Toluene);
  Serial.println(" PPM");

  Serial.print("Ammonio NH4+= ");
  Serial.print(NH4);
  Serial.println(" PPM");

  Serial.print("Acetone= ");
  Serial.print(Acetona);
  Serial.println(" PPM");
  Serial.println("");

  readSensor();
  radio.write(&data, sizeof(data));
}
void readSensor()
{
  data.humidity = dht.readHumidity();
  data.temperature = dht.readTemperature();
  data.pressure = (BMP180.readPressure() / 100);
  data.Altitude= (BMP180.readAltitude());
  data.CO2 = MQ135.readSensor(); MQ135.setA(110.47); MQ135.setB(-2.862);
  data.CO = MQ135.readSensor(); MQ135.setA(605.18); MQ135.setB(-3.937);
  data.NH4 = MQ135.readSensor(); MQ135.setA(102.2 ); MQ135.setB(-2.473);
  data.Acetona =MQ135.readSensor();MQ135.setA(34.668); MQ135.setB(-3.369);
}


 Questo invece lo sketch rx da caricare sull arduino mega con i display:


/* Stazione ricevente dati wireless con bluetooth HC-05 e NFR24L01,
  con rilevamento di temperatura e umidità (DHT11),pressione e altitudine (BMP180),
  gas CO,CO2,NH4 (MQ-135).*/

//librerie
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <Adafruit_GFX.h>
#include <Wire.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1

Adafruit_SSD1306 display1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// trans package
struct package
{
  float temperature ;
  float pressure;
  float humidity;
  float Altitude;
  float CO2;
  float CO;
  float NH4;
  float Acetona;
};

// radio
const int pinCE = 7;
const int pinCSN = 8;
RF24 radio(pinCE, pinCSN);
byte address[][6] = {"0"};
const uint64_t pipe = 0xE8E8F0F0E1LL;
typedef struct package Package;
Package data;

//schermata iniziale logo segnale radio
const unsigned char PROGMEM arduino [] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x1C, 0x00, 0x00, 0x70, 0x04, 0x80, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x02, 0x80, 0x64, 0x00, 0x00, 0x4C, 0x02, 0x80, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x05, 0x80, 0xD8, 0x00, 0x00, 0x32, 0x03, 0x40, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x05, 0x01, 0x10, 0x00, 0x00, 0x19, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x0A, 0x01, 0x60, 0x00, 0x00, 0x05, 0x80, 0xA0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x0A, 0x02, 0x40, 0x00, 0x00, 0x04, 0x80, 0x90, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x14, 0x04, 0x80, 0x00, 0x00, 0x02, 0x40, 0x50, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x14, 0x01, 0x00, 0x50, 0x1C, 0x01, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x10, 0x0A, 0x01, 0x90, 0x13, 0x00, 0xA0, 0x38, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x28, 0x0A, 0x02, 0x60, 0x0C, 0x80, 0xA0, 0x28, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x28, 0x14, 0x04, 0x80, 0x02, 0x40, 0x50, 0x28, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x30, 0x14, 0x05, 0x00, 0x01, 0x40, 0x50, 0x14, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x50, 0x18, 0x08, 0x00, 0x00, 0x20, 0x38, 0x14, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x0A, 0x00, 0x00, 0xA0, 0x28, 0x14, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x14, 0x01, 0x00, 0x50, 0x28, 0x14, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x14, 0x06, 0xC0, 0x50, 0x28, 0x14, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x14, 0x08, 0x20, 0x50, 0x28, 0x14, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x14, 0x08, 0x20, 0x50, 0x28, 0x14, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x14, 0x08, 0x20, 0x50, 0x28, 0x14, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x14, 0x08, 0x20, 0x50, 0x28, 0x14, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x14, 0x06, 0xC0, 0x50, 0x28, 0x14, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x14, 0x01, 0x00, 0x50, 0x28, 0x14, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x0A, 0x00, 0x00, 0xA0, 0x28, 0x14, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x50, 0x18, 0x08, 0x00, 0x00, 0xA0, 0x38, 0x14, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x30, 0x14, 0x05, 0x00, 0x01, 0x60, 0x50, 0x14, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x28, 0x14, 0x04, 0x80, 0x02, 0x40, 0x50, 0x28, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x28, 0x0A, 0x02, 0x60, 0x0C, 0x80, 0xA0, 0x28, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x38, 0x0A, 0x01, 0xB0, 0x19, 0x00, 0xA0, 0x38, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x14, 0x01, 0x00, 0xD0, 0x16, 0x01, 0x20, 0x50, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x14, 0x05, 0x80, 0x20, 0x08, 0x03, 0x40, 0x50, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x12, 0x02, 0x40, 0x00, 0x00, 0x02, 0x80, 0xD0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x0A, 0x03, 0x40, 0x00, 0x00, 0x05, 0x80, 0xA0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x05, 0x01, 0x30, 0x00, 0x00, 0x09, 0x01, 0x60, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x05, 0x80, 0x98, 0x00, 0x00, 0x32, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x02, 0x80, 0x64, 0x00, 0x00, 0x4C, 0x02, 0xC0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x1C, 0x00, 0x00, 0x70, 0x04, 0x80, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

void setup() {

  Serial.begin(9600);//inizializzo seriale
  display1.begin( SSD1306_SWITCHCAPVCC, 0x3d);//inizializzo i display con indirizzi diversi
  display2.begin( SSD1306_SWITCHCAPVCC, 0x3c);
  display1.display();
  display2.display();
  delay(1000);//pausa schermata adafruit
  //pulisco e mando la schermata iniziale logo radio sui due display
  display1.clearDisplay();
  display2.clearDisplay();
  display1.setTextSize(1);
  display2.setTextSize(1);
  display1.setCursor(12, 55);
  display2.setCursor(12, 55);
  display1.setTextColor(WHITE, BLACK);
  display2.setTextColor(WHITE, BLACK);
  display1.println("Waiting for signal");
  display1.drawBitmap(0, 0, arduino, 128, 64, WHITE);
  display1.display();
  display2.println("Waiting for signal");
  display2.drawBitmap(0, 0, arduino, 128, 64, WHITE);
  display2.display();
  delay(2000);//pausa  e pulisco i display
  display1.clearDisplay();
  display2.clearDisplay();

  // inizializzo la radio
  radio.begin();
  radio.setChannel(115);
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate( RF24_250KBPS ) ;
  radio.openReadingPipe(1, address[0]);
  radio.startListening();


}

void loop() {



  //leggo i valori ricevuti via radio
  radio.read( &data, sizeof(data) );

  //scrivo sul seriale i valori ricevuti dai sensori
  Serial.print("Dati ricevuti:");
  Serial.println("**********************");
  Serial.print("Temperatura C:");
  Serial.println(data.temperature);
  Serial.print("Umidità %:");
  Serial.println(data.humidity);
  Serial.print("Pressione mBar:");
  Serial.println(data.pressure);
  Serial.print("Anidride carbonica PPM:");
  Serial.println(data.CO2);
  Serial.print("Monossido di carbonio PPM: ");
  Serial.println(data.CO);
  Serial.print("NH4 PPM: ");
  Serial.println(data.NH4);
  Serial.print("Acetone PPM: ");
  Serial.println(data.Acetona);


  //scrivo i dati di DHT11 sul display1


  display1.clearDisplay();
  display1.setTextColor(WHITE);
  display1.setTextSize(1);
  display1.setCursor(0, 0);
  display1.print("  Temperatura ");
  display1.setTextSize(2);
  display1.setCursor(1, 15);

  display1.print( data.temperature );
  display1.print(" ");
  display1.setTextSize(1);
  display1.cp437(true);
  display1.write(167);
  display1.setTextSize(2);
  display1.print("C");

  display1.setTextColor(WHITE);
  display1.setTextSize(1);
  display1.setCursor(20, 35);
  display1.print("Umidita");
  display1.setTextSize(2);
  display1.setCursor(1, 45);
  display1.print( data.humidity );
  display1.print(" %");
  display1.display();

  //scrivo i dati di BMP180 e MQ-135 sul display2
  display2.clearDisplay();
  display2.setTextColor(WHITE);
  display2.setTextSize(1);
  display2.setCursor(0, 0);
  display2.print("Press: ");
  display2.print( data.pressure );
  display2.println(" mBar");


  display2.setTextColor(WHITE);
  display2.setTextSize(1);
  display2.setCursor(0, 10);
  display2.print("ALT: ");
  display2.print( data.Altitude );
  display2.println(" mt");


  display2.setTextSize(1);
  display2.setCursor(0, 20);
  display2.print("NH4: ");
  display2.print( data.NH4 );
  display2.println(" PPM");


  display2.setTextSize(1);
  display2.setCursor(0, 30);
  display2.print("CO2: ");
  display2.print( data.CO2 );
  display2.println(" PPM");

  display2.setTextSize(1);
  display2.setCursor(0, 40);
  display2.print("CO: ");
  display2.print( data.CO );
  display2.println(" PPM");

  display2.setTextSize(1);
  display2.setCursor(0, 50);
  display2.print("Acet: ");
  display2.print( data.Acetona );
  display2.println(" PPM");
  display2.display();
  delay(1000);
}
Nel prossimo progetto aggiungerò dei mini pannelli solari con batteria ricaricabile per rendere autonoma la stazione trasmittente.

Post popolari in questo blog

Arduino nano+Mq135+display oled 0.96" ssd1306 128x64

Arduino+DHT11+BMP180+Oled display i2c sh1106 con schermate che si alternano

Modulo di contatto

Nome

Email *

Messaggio *