Bonjour,
Je vous présente mon projet de mini station météo (un classique) avec un afficheur LCD TFT de 3.6 pouces.
- carte arduino Mega
- Sensor Shield arduino méga V2.0
- LCD TFT 3.6 pouces 400*200 pixels
- Sonde T° et humidité DHT 22 (pour l'intérieur)
- Sonde T° DS18B20 étanche (pour Extérieur)
- Sonde pression BMP 180
- Module RTC DS3231
- Module BT HC-06
- Module SD-Card
Archivage sur une micro-sd , de la T° Ext et de la pression , toutes les 15 min.
Nouvelle boite (boitier pupitre) pour mettre tous les composants :
Archivage de l'heure des T° Ext Maxi et mini.
Affichage des T° Ext, Int et pression sur smartphone Android, via BT.
Pour la suite du projet, je vais travailler sur la gestion du tactile du lcd pour ajouter des informations en plus.
@+
#include <UTFT.h>
#include <DS3232RTC.h> //http://github.com/JChristensen/DS3232RTC
#include <Time.h> //http://www.arduino.cc/playground/Code/Time
#include <Wire.h> //http://arduino.cc/en/Reference/Wire (included with Arduino IDE)
#include <Adafruit_BMP085.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "DHT.h"
#include <SPI.h>
#include <SD.h>
#define DHTPIN 17 // Sonde temperature DHT22
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
UTFT myGLCD(ILI9327,38,39,40,41); // Ecran TFT LCD 3.6 pouces
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
int heures;
int minutes;
int secondes;
int jour_mois;
int Mois;
int annee;
int pression_atm;
int temp_Ext;
float Tmax_Ext = 0;
float Tmin_Ext = 100;
float Tmax_Int = 0;
float Tmin_Int = 100;
static long date_init;
int comp_sd=0;
int Intervalle = 15;
char myData[100];
File myFile;
const int chipSelect = 53; // port SD card
Sd2Card card;
const char* jour_semaine[] = {
" \0",
"Dimanche \0",
"Lundi \0",
"Mardi \0",
"Mercredi \0",
"Jeudi \0",
"Vendredi \0",
"Samedi \0"};
const char* mois[] = {
" \0",
"Jan\0",
"Fev\0",
"Mar\0",
"Apr\0",
"Mai\0",
"Juin\0",
"Juillet\0",
"Aout\0",
"Sep\0",
"Oct\0",
"Nov\0",
"Dec\0"};
Adafruit_BMP085 bmp; // Sonde de pression atmospherique BMP 180
#define ONE_WIRE_BUS 10 // sonde de temperature DS18B20
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup()
{
date_init=millis();
sensors.begin();
dht.begin();
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setColor(255, 255, 255);
myGLCD.fillScr(128, 208, 208);
myGLCD.setBackColor(128, 208, 208);
myGLCD.drawRect(5,5,395,235);
myGLCD.drawLine(5,25,395,25);
myGLCD.drawLine(5,55,395,55);
myGLCD.drawLine(5,115,395,115);
myGLCD.drawLine(5,175,395,175);
myGLCD.drawLine(5,220,395,220);
myGLCD.setFont(SmallFont);
myGLCD.print("Station Meteo Arduino", CENTER, 10);
Serial.begin(9600);
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus() != timeSet)
{
Serial.println("Unable to sync with the RTC");
}
else
{
Serial.println("RTC has set the system time");
}
Serial.print("Initialisation SD card...");
if (!SD.begin(53)) {
Serial.println("Echec Initialisation carte SD ");
myGLCD.print("Echec initialisation carte SD", 150, 222);
return;
}
}
void loop()
{
myGLCD.setFont(SmallFont);
myGLCD.print("Nb ecritures SD: ", 10, 222);
myGLCD.printNumI(comp_sd,140,222);
myGLCD.print("Intervalle en min: ", 200, 222);
myGLCD.printNumI(Intervalle,350,222);
affiche_heure(10,60);
affiche_date(10,30);
pression(190,60);
temperatures_humidite(15,120);
if (millis()>=date_init + (Intervalle*60000))
{
sdcar();
date_init=millis();
}
delay(1000);
}
void affiche_heure(int x, int y)
{
heures=hour();
minutes = minute();
secondes =second();
myGLCD.setFont(SevenSegNumFont);
myGLCD.printNumI(heures, x, y, 2 ,'0');
myGLCD.printNumI(minutes, x+70, y, 2 ,'0');
myGLCD.setFont(BigFont);
myGLCD.printNumI(secondes, x+135, y, 2 ,'0');
}
void affiche_date (int x, int y)
{
jour_mois= day();
annee=year();
myGLCD.setFont(BigFont);
myGLCD.setColor(255,255,0);
myGLCD.print(jour_semaine[weekday()], x, y);
myGLCD.printNumI(jour_mois, x+120, y, 2);
myGLCD.print(mois[month()], x+170, y, 2);
myGLCD.printNumI(annee, x+305, y, 2);
myGLCD.setColor(255, 255, 255);
}
void pression (int x, int y)
{
myGLCD.setFont(SevenSegNumFont);
pression_atm = ((bmp.readPressure()/100)+17);
myGLCD.printNumI(pression_atm,x,y);
myGLCD.setFont(BigFont);
myGLCD.setColor(255, 255, 0);
myGLCD.print("hPa",x+130,y);
myGLCD.setColor(255, 255, 255);
}
void temperatures_humidite (int x, int y)
{
int humidite = dht.readHumidity();
int temp_Int = dht.readTemperature();
// Temperature DS 3231
float c = RTC.temperature() / 4.;
sensors.requestTemperatures();
myGLCD.setFont(SevenSegNumFont);
temp_Ext=int (sensors.getTempCByIndex(0));
myGLCD.printNumI(temp_Ext,x,y,2,1);
myGLCD.setFont(SmallFont);
myGLCD.print("O", x+68, y);
myGLCD.setFont(BigFont);
myGLCD.print("C", x+75, y);
myGLCD.print("Ext", x+65, y+35);
myGLCD.setFont(SevenSegNumFont);
myGLCD.printNumI(temp_Int,x+130,y);
myGLCD.setFont(SmallFont);
myGLCD.print("O", x+195, y);
myGLCD.setFont(BigFont);
myGLCD.print("C", x+205, y);
myGLCD.print("Int", x+195, y+35);
myGLCD.setFont(SevenSegNumFont);
myGLCD.printNumI(humidite,x+280,y);
myGLCD.setFont(BigFont);
myGLCD.print("%", x+350, y);
if (hour()==00 && minute()==00)
{
Tmax_Ext=0;
Tmin_Ext=100;
Tmax_Int=0;
Tmin_Int=100;
}
if (Tmax_Ext<temp_Ext)
{
Tmax_Ext=temp_Ext;
}
if (temp_Ext<Tmin_Ext)
{
Tmin_Ext=temp_Ext;
}
if (Tmax_Int<temp_Int)
{
Tmax_Int=temp_Int;
}
if (temp_Int<Tmin_Int)
{
Tmin_Int=temp_Int;
}
myGLCD.setFont(BigFont);
myGLCD.setColor(255, 255, 255);
myGLCD.print("TMax_Ext:", x, y+60);
myGLCD.printNumI(Tmax_Ext,x+140,y+60);
myGLCD.print("TMin_Ext:", x, y+80);
myGLCD.printNumI(Tmin_Ext,x+140,y+80);
myGLCD.setColor(255, 0, 0);
myGLCD.print("TMax_Int:", x+190, y+60);
myGLCD.printNumI(Tmax_Int,x+330,y+60);
myGLCD.print("TMin_Int:", x+190, y+80);
myGLCD.printNumI(Tmin_Int,x+330,y+80);
myGLCD.setColor(255, 255, 255);
}
void sdcar()
{
heures=hour();
minutes = minute();
secondes =second();
Mois=month();
jour_mois= day();
annee=year();
sensors.requestTemperatures();
temp_Ext=(sensors.getTempCByIndex(0));
pression_atm = int ((bmp.readPressure()/100)+17);
sprintf(myData,"%u/%u/%u %u:%u:%u %u %u", annee,Mois,jour_mois,heures,minutes,secondes,temp_Ext,pression_atm);
myFile = SD.open("Meteo2.txt", FILE_WRITE);
myFile.println(myData);
myFile.close();
myFile = SD.open("Meteo2.txt");
// Lecture du contenu du fichier
if (myFile) {
Serial.println("Meteo2.txt:");
while (myFile.available()) {
Serial.write(myFile.read());
}
// Fermeture fichier
myFile.close();
} else {
Serial.println("erreur ouverture meteo2.txt");
}
comp_sd = comp_sd+1;
}
Station_meteo_TFT_v1.ino (4.99 KB)