#include <DHT.h> //Call DHT22 library
//The data of the DHT22 sensor is printed in digital form
#include "LiquidCrystal_I2C.h" //Call the I2C module library
#include <stm32l0xx_hal.h>
#define DHT_PORT 2 //Read data from DHT22 at pin D2 on the STM32 circuit.
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
#define flashAddress 0x08020000 //Declare the values of LCD
DHT dht(DHT_PORT, DHT22);
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
int choice = 0;
void setup() {
lcd.init();
lcd.backlight();
dht.begin(); //Start DHT sensor
}
void loop() {
float humid = dht.readHumidity(); //Read humidity
float temp = dht.readTemperature(); //Read temperature
printLcd(humid, temp);
delay(2000);
}
void printSerial(float humid, float temp) {
Serial.print("Humid: "); Serial.println(humid);
Serial.print("Temp: "); Serial.println(temp);
}
void printLcd(float humid, float temp) {
lcd.setCursor(0, 0);
lcd.print("Humid: ");
lcd.print(humid);
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temp);
//Export temperature and humidity values
}
void writeIntToFlash(int value) {
HAL_FLASH_Unlock();
// Function to write an integer to Flash memory
FLASH_EraseInitTypeDef FlashEraseInit;
uint32_t SectorError = 0;
HAL_FLASHEx_Erase(&FlashEraseInit, &SectorError);
// Erase the sector before writing
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, flashAddress, (uint64_t)value);
// Write the integer to Flash memory
HAL_FLASH_Lock();
// Lock the Flash memory after writing
}
int readIntFromFlash() {
return *(__IO int*)flashAddress;
// Function to read an integer from Flash memory
}
Loading
st-nucleo-l031k6
st-nucleo-l031k6