first commit

This commit is contained in:
Jérôme Delacotte
2025-03-06 11:15:32 +01:00
commit 7b30d6e298
5276 changed files with 2108927 additions and 0 deletions

View File

@@ -0,0 +1,400 @@
/////////////////////
// Domoticz Classe
/////////////////////
const uint16_t port = 81;
const char * host = "192.168.1.3"; // ip or dns
#include "Modules.h"
Modules modules;
#include "Ecran.h"
Ecran * ecran;
#include "Graph.h"
Graph * graph;
#include "Mesure.h"
Ecran e;
#define NB_MESURES 15
#define SLEEP_DELAY 2000 //interval envoi des données
Mesure mesures[NB_MESURES];
// domoticz
String macID = "";
unsigned long milli;
// SOLAIRE
//#include <SoftwareSerial.h>
#include <ESP8266WiFiMulti.h>
ESP8266WiFiMulti WiFiMulti;
#include "math.h"
const int analogIn = A0;
int mVperAmp = 185; // 185 pour 5A, use 100 for 20A Module and 66 for 30A Module
int RawValue= 0;
int ACSoffset = 2500;
double mp_offset = 0.040;
double Voltage = 0;
double Amps = 0;
double max_amps = 0;
double max_watt = 0;
double sum_watt = 0;
String start_time = "";
long time_from_start = 0;
int lectures = 0;
double sum_amps = 0;
double sum_watts = 0;
String IDX_U = "1085"; //idx du capteur virtuels tension
String IDX_I = "1086"; //idx du capteur virtuels intensite
String IDX_W = "1087"; //idx du cap
///////////////////////////// TIME
#include <NTPClient.h>
#include <WiFiUdp.h>
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
// Variables to save date and time
String formattedDate;
String dayStamp;
String timeStamp;
void setup()
{
Serial.begin(9600);
WiFi.setSleepMode(WIFI_NONE_SLEEP);
pinMode(D0, WAKEUP_PULLUP);
/* sda scl */
Wire.pins(SDA, SCL);
Wire.begin(SDA, SCL);
// Conversion d'objet en pointeur
ecran = &e;
delay(500);
// We start by connecting to a WiFi network
WiFi.mode(WIFI_STA);
WiFiMulti.addAP("Livebox-37cc", "8A6060920A8A86896F770F2C47");
Serial.println();
Serial.println();
Serial.print("Wait for WiFi... ");
while(WiFiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(500);
///////////////////////////
// macID = domo.generateKey();
// ecran->LcdString(0, 0, domo._domoticz);
// ecran->LcdChar(0, 10, "ID : ");
// ecran->LcdString(40, 10, macID);
// ecran->u8g2->sendBuffer();
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH);
milli = millis();
for (int i =0; i < NB_MESURES; i++){
mesures[i] = Mesure();
}
time_from_start = millis();
// Initialize a NTPClient to get time
timeClient.begin();
// Set offset time in seconds to adjust for your timezone, for example:
// GMT +1 = 3600
// GMT +8 = 28800
// GMT -1 = -3600
// GMT 0 = 0
timeClient.setTimeOffset(3600);
getTime();
// start_time = getTime();
// if (start_time.length() >=5) {
// String h = start_time.substring(0,2);
// String m = start_time.substring(2,2);
// Serial.println("Time=" + start_time+ " " + h + " " + m);
// }
}
void loop()
{
// SOLAIRE
ecran->LcdClear();
int i = 0;
RawValue = 0;
// Somme du courant alternatif pendant 20 ms ==> 50hz
// Détermination du max et max pour hauteur de crete
int vmin = 1024;
int vmax = 0;
int max_bcl = 200;
for (i = 0; i < max_bcl; i++) {
int value = analogRead(analogIn);
if (value >= 0) {
RawValue += value;
vmax = max(value,vmax);
vmin = min(value,vmin);
} else {
i--;
}
delay(1);
}
RawValue = RawValue / max_bcl;
lectures ++;
Serial.print("rawValue = " );
Serial.print(RawValue);
Serial.print(" min = " );
Serial.print(vmin);
Serial.print(" max = " );
Serial.print(vmax);
// Tension continue
// why 40 ?
// Voltage = (RawValue / 1023.0) * 5000; // Gets you mV
// Amps = ((Voltage - ACSoffset) / mVperAmp);
// La valeur maxi * racine carrée de 2 pour obtenir la tension "réelle"
// La tension efficace pour l'effet Hall étant réduite d'un facteur 0,707
// Voltage = ((vmax - vmin) / 430.0) * 5000;
// branchement 5V 0.341 sinon 0.171 et pas de multilplication voltage * 2
Voltage = (vmax - vmin -28); //1.4142;
Amps = max(1.05 * (Voltage / mVperAmp) /*- 0.341*/, 0.0);
sum_amps += Amps;
//Amps = max(5.5 * (vmax - vmin) / 473.0 -0.0580, 0.0); // <= pour le bruit
max_amps = max(max_amps, Amps);
max_watt = max(max_watt, Amps * 220);
double watt = Amps * 220;
int watth = (int) (Amps * 220 * 3600 / (millis() - milli) );
// Serial.print(" Raw Value = " ); // shows pre-scaled value
// Serial.print(RawValue);
Serial.print("\t mV = "); // shows the voltage measured
Serial.print(Voltage,3); // the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("\t Amps = "); // shows the voltage measured
Serial.print(Amps,3); // the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("\t Watt = "); // shows the voltage measured
Serial.print(Amps * 220,3);
Serial.print("\t WattH = "); // shows the voltage measured
Serial.print(watth);
Serial.println(millis() - milli);
ecran->drawRect(1, 1, LCD_X -1, LCD_Y -1);
// ecran->drawJauge(10, 24, LCD_X -10, 34, i, "Jauge");
ecran->LcdString(0, 5, "T: " + String(Voltage));
ecran->LcdString(0,12, "A: " + String(Amps) + " " + max_amps);
ecran->LcdString(0,19, "W: " + String(Amps * 220) + " " + max_watt);
ecran->drawJauge(10, 30, LCD_X -10, 40, 100 * (watt / 600), "Watt");
ecran->u8g2->sendBuffer();
//domo.envoieDomoticz(IDX_U,String((vmax - vmin))); // tension
if (lectures == NB_MESURES) {
Serial.println("Envoi domoticz..." + String(sum_amps / lectures) + " " + String(sum_amps * 220 / lectures) );
ecran->LcdString(2,35, "Envoi Domo");
envoieDomoticz(IDX_I,String(sum_amps / lectures)); // intensite
envoieDomoticz(IDX_W,String(sum_amps * 220 / lectures)+ ";" +String(watth)); // puissance
Serial.println("Envoi domoticz effectué.");
delay(100);
milli = millis();
long seconds = (milli - time_from_start) / 1000;
int hours = seconds / 3600;
int minutes = (seconds - hours * 3600) / 60;
Serial.println("Envoi domoticz... " + String(hours) + ":" + String(minutes) + " " + seconds);
lectures = 0;
sum_amps = 0;
sum_watts = 0;
}
//Serial.println("Pause de "+String(SLEEP_DELAY_IN_SECONDS)+" secondes...");
// ecran->LcdClear();
// Graph g (ecran, 0, 0, 84, 48) ;
// g.title = "Production";
// g.axe_x = "t";
// g.axe_y = "W";
// g.drawGraph();
// ecran->drawRect(1, 1, LCD_X -1, LCD_Y -1);
//ecran->u8g2->drawLine(5, y1 - 1, 5, y1 -1);
delay(SLEEP_DELAY);
// Dark
// while (isDark()) {
// sleep(30);
// }
}
String getTime()
{
while(!timeClient.update()) {
timeClient.forceUpdate();
}
// The formattedDate comes with the following format:
// 2018-05-28T16:00:13Z
// We need to extract date and time
formattedDate = timeClient.getFormattedTime();
Serial.println(formattedDate);
// Extract date
int splitT = formattedDate.indexOf("T");
dayStamp = formattedDate.substring(0, splitT);
Serial.print("DATE: ");
Serial.println(dayStamp);
// Extract time
timeStamp = formattedDate.substring(splitT+1, formattedDate.length()-1);
Serial.print("HOUR: ");
Serial.println(timeStamp);
}
void envoieDomoticz(String IDX, String Svalue) {
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
Serial.println("wait 5 sec...");
delay(5000);
return;
}
// This will send the request to the server
client.print("GET /json.htm?type=command&param=udevice&idx="+IDX+"&nvalue=0&svalue=" + Svalue);
client.println(" HTTP/1.1");
client.println("Host: 192.168.1.3:81");
client.println("User-Agent: Arduino-ethernet");
client.println("Connection: close");
client.println();
//read back one line from server
String line = client.readStringUntil('\r');
Serial.println("----------------------------------------------");
Serial.println(line);
Serial.println("----------------------------------------------");
//Serial.println("closing connection");
client.stop();
delay(500);
}
void sleep(int sleepTime)
{
Serial.print("Go to sleep ");
Serial.println(sleepTime);
delay(20);
ESP.deepSleep(sleepTime * 1000000L); // Infini
//sleepWifi();
delay(200);
}
boolean isDark()
{
String separator = ",";
int nb = 0;
WiFiClient client;
if (client.connect(host, port)) {
Serial.println("Connected to domoticz");
client.print("GET /json.htm?type=command&param=getuservariable&idx=6");
client.println(" HTTP/1.1");
client.println("Host: 192.168.1.3:81");
client.println("User-Agent: Arduino-ethernet");
client.println("Connection: close");
client.println();
// Read the first line of the request
boolean ret = false;
while (1) {
String req = client.readStringUntil('\n');
if (req.indexOf("Value") != -1) {
if (req.indexOf("True") != -1) {
ret = true;
}
break;
}
if (req == "" || nb > 500) {
break;
}
nb++;
}
client.stop();
delay(100);
return ret;
}
}
String getVariableValue(String idx)
{
String separator = ",";
int nb = 0;
WiFiClient client;
if (client.connect(host, port)) {
Serial.println("Connected to domoticz");
client.print("GET /json.htm?type=command&param=getuservariable&idx=" + idx);
client.println(" HTTP/1.1");
client.println("Host: 192.168.1.3:81");
client.println("User-Agent: Arduino-ethernet");
client.println("Connection: close");
client.println();
// Read the first line of the request
String ret = "";
while (1) {
String req = client.readStringUntil('\n');
if (req.indexOf("Value") != -1) {
ret = req.substring(req.indexOf("Value"));
Serial.println("Idx=" + idx + " Value " + ret);
break;
}
if (req == "" || nb > 500) {
break;
}
nb++;
}
client.stop();
delay(100);
return ret;
}
}

View File

@@ -0,0 +1,202 @@
#include "Ecran.h"
Ecran::Ecran()
{
Serial.println("--------------------------------------");
Serial.println("Init Ecran");
// ECRAN
LcdInitialise();
// LcdClear();
// LcdChar(0, 0, "Starting");
//
// FIN ECRAN
}
// ECRAN Methodes
void Ecran::LcdCharacter(char character)
{
LcdWrite(LCD_D, 0x00);
for (int index = 0; index < 5; index++)
{
LcdWrite(LCD_D, ASCII[character - 0x20][index]);
}
LcdWrite(LCD_D, 0x00);
}
void Ecran::LcdClear(void)
{
u8g2->clearBuffer();
// for (int index = 0; index < LCD_X * LCD_Y / 8; index++)
// {
// LcdWrite(LCD_D, 0x00);
// }
}
void Ecran::LcdInitialise(void)
{
static U8G2_PCD8544_84X48_F_4W_SW_SPI u(U8G2_R0,
/* clock=*/ PIN_SCLK,
/* data=*/ PIN_SDIN,
/* cs=*/ PIN_SCE,
/* dc=*/ PIN_DC,
/* reset=*/ PIN_RESET); // Nokia 5110 Display
u8g2 = &u;
u8g2->begin();
u8g2->setFont(u8g2_font_6x10_tf);
u8g2->setFontRefHeightExtendedText();
u8g2->setDrawColor(1);
u8g2->setFontPosTop();
u8g2->setFontDirection(0);
setContrast(contrast);
}
void Ecran::LcdChar(int x, int y, char *characters)
{
u8g2->drawStr(x, y, characters);
}
void Ecran::LcdString(int x, int y, String s)
{
char cs[s.length() + 1];
s.toCharArray(cs, s.length() + 1);
LcdChar(x, y, cs);
}
void Ecran::LcdWrite(byte dc, byte data)
{
digitalWrite(PIN_DC, dc);
digitalWrite(PIN_SCE, LOW);
shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
digitalWrite(PIN_SCE, HIGH);
}
void Ecran::setContrast(byte contrast)
{
//analogWrite(PIN_LCD, contrast);
}
//This takes a large array of bits and sends them to the LCD
void Ecran::LcdBitmap(int x, int y, char my_array[])
{
for (int index = 0 ; index < (x * y / 8) ; index++)
{
LcdWrite(LCD_DATA, my_array[index]);
}
}
//void Ecran::printInfos()
//{
// // ECRAN
// LcdClear();
// float fractionC;
//
// fractionC = temperature - ((int)temperature);
//
// gotoXY(0,0);
// LcdString("TEMP ");
// itoa(temperature,strBuffer,10);
// LcdString(strBuffer);
// itoa(fractionC,strBuffer,10);
// LcdString(".");
// LcdString(strBuffer);
// LcdString("C ");
//
// fractionC = pression - ((int) pression);
//
// gotoXY(0,10);
// LcdString("Pres ");
// itoa(pression,strBuffer,10);
// LcdString(strBuffer);
// itoa(fractionC,strBuffer,10);
// LcdString(".");
// LcdString(strBuffer);
// LcdString("hp");
//
// fractionC = lux - ((int) lux);
//
// gotoXY(0,20);
// LcdString("Lum ");
// itoa(lux,strBuffer,10);
// LcdString(strBuffer);
// itoa(fractionC,strBuffer,10);
// LcdString(".");
// LcdString(strBuffer);
// LcdString("Lux ");
// // FIN ECRAN
//}
void Ecran::intro()
{
int a = 0;
u8g2->clearBuffer();
u8g2->setFontDirection(0);
LcdChar(0, 0, "Starting");
u8g2->drawStr(30+a,31, " 0");
u8g2->setFontDirection(1);
u8g2->drawStr(30,31+a, " 90");
u8g2->setFontDirection(2);
u8g2->drawStr(30-a,31, " 180");
u8g2->setFontDirection(3);
u8g2->drawStr(30,31-a, " 270");
u8g2->sendBuffer();
delay(2000);
const uint8_t frame_size = 24;
u8g2->clearBuffer();
u8g2->drawBox(0, frame_size * 0.5, frame_size * 5, frame_size);
u8g2->drawStr(frame_size * 0.5, 50, "Black");
u8g2->drawStr(frame_size * 2, 50, "White");
u8g2->drawStr(frame_size * 3.5, 50, "XOR");
u8g2->setBitmapMode(false /* solid */);
u8g2->drawStr(0, 0, "Solid bitmap");
u8g2->sendBuffer();
delay(2000);
u8g2->clearBuffer();
u8g2->setDrawColor(0);// Black
u8g2->drawXBMP(frame_size * 0.5, 24, cross_width, cross_height, cross_bits);
u8g2->setDrawColor(1); // White
u8g2->drawXBMP(frame_size * 2, 24, cross_width, cross_height, cross_bits);
u8g2->setDrawColor(2); // XOR
u8g2->drawXBMP(frame_size * 3.5, 24, cross_width, cross_height, cross_bits);
u8g2->sendBuffer();
delay(2000);
}
void Ecran::drawRect(int x0, int y0, int x1, int y1)
{
u8g2->drawLine(x0, y0, x1, y0);
u8g2->drawLine(x1, y0, x1, y1);
u8g2->drawLine(x1, y1, x0, y1);
u8g2->drawLine(x0, y1, x0, y0);
// u8g2->drawLine(LCD_X / 2, 1, LCD_X / 2, LCD_Y -1);
}
void Ecran::drawJauge(int x0, int y0, int x1, int y1, int val, String text)
{
drawRect(x0, y0, x1, y1);
if (val > 100) {
val = x1;
}
u8g2->drawBox(x0, y0, ((x1 - x0) * val) / 100, y1 - y0);
if (text != "") {
LcdString(x0, y0, text);
}
// u8g2->drawLine(LCD_X / 2, 1, LCD_X / 2, LCD_Y -1);
}
void Ecran::drawFace(int x0, int y0, int x1, int y1, int x2, int y2)
{
u8g2->drawLine(x0, y0, x1, y1);
u8g2->drawLine(x1, y1, x2, y2);
u8g2->drawLine(x2, y2, x0, y0);
}

View File

@@ -0,0 +1,160 @@
#ifndef Ecran_h
#define Ecran_h
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
#include "Pins.h"
#define LCD_C LOW
#define LCD_D HIGH
#define LCD_COMMAND 0
#define LCD_X 84
#define LCD_Y 48
//The DC pin tells the LCD if we are sending a command or data
#define LCD_COMMAND 0
#define LCD_DATA 1
static const byte ASCII[][5] =
{
{0x00, 0x00, 0x00, 0x00, 0x00} // 20
,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f backslash
,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c ¥
,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^
,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _
,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `
,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a
,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b
,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c
,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d
,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e
,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f
,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g
,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h
,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i
,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j
,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k
,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l
,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m
,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n
,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o
,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p
,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q
,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r
,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s
,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t
,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u
,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v
,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w
,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x
,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y
,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z
,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {
,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |
,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }
,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ←
,{0x78, 0x46, 0x41, 0x46, 0x78} // 7f →
};
// DEMO
#define cross_width 24
#define cross_height 24
static const unsigned char cross_bits[] U8X8_PROGMEM = {
0x00, 0x18, 0x00, 0x00, 0x24, 0x00, 0x00, 0x24, 0x00, 0x00, 0x42, 0x00,
0x00, 0x42, 0x00, 0x00, 0x42, 0x00, 0x00, 0x81, 0x00, 0x00, 0x81, 0x00,
0xC0, 0x00, 0x03, 0x38, 0x3C, 0x1C, 0x06, 0x42, 0x60, 0x01, 0x42, 0x80,
0x01, 0x42, 0x80, 0x06, 0x42, 0x60, 0x38, 0x3C, 0x1C, 0xC0, 0x00, 0x03,
0x00, 0x81, 0x00, 0x00, 0x81, 0x00, 0x00, 0x42, 0x00, 0x00, 0x42, 0x00,
0x00, 0x42, 0x00, 0x00, 0x24, 0x00, 0x00, 0x24, 0x00, 0x00, 0x18, 0x00, };
class Ecran
{
public:
Ecran();
void drawFace(int x0, int y0, int x1, int y1, int x2, int y2);
void drawRect(int x0, int y0, int x1, int y1);
void drawJauge(int x0, int y0, int x1, int y1, int val, String text);
void intro();
void LcdWrite(byte dc, byte data);
void LcdChar(int x, int y, char *characters);
void LcdString(int x, int y, String s);
void LcdInitialise(void);
void LcdClear(void);
void LcdBitmap(int x, int y,char my_array[]);
void LcdCharacter(char character);
void setContrast(byte contrast);
private:
public:
long contrast = 200;
U8G2_PCD8544_84X48_F_4W_SW_SPI * u8g2;
};
#endif

View File

@@ -0,0 +1,39 @@
#include "Graph.h"
Graph::Graph(Ecran * _ecran, int _x0, int _y0 ,int _x1, int _y1)
{
Serial.println("--------------------------------------");
Serial.println("Init Graph");
x0 = _x0;
x1 = _x1;
y0 = _y0;
y1 = _y1;
ecran = _ecran;
}
void Graph::drawAxes()
{
ecran->LcdString(0, 0, axe_x);
ecran->LcdString(x1-10, y1-10, axe_y);
ecran->u8g2->drawLine(x0 + 5, y1 - 1, x1, y1 -1);
ecran->u8g2->drawLine(x0 + 5, y0 + 5, x0 + 5, y1);
}
void Graph::drawTitle()
{
if (title != "") {
ecran->LcdString(x0 + 20, y0, title);
}
}
void Graph::drawDatas()
{
}
void Graph::drawGraph()
{
drawAxes();
drawTitle();
drawDatas();
ecran->u8g2->sendBuffer();
}

View File

@@ -0,0 +1,19 @@
#ifndef Graph_h
#define Graph_h
#include <Arduino.h>
#include "Ecran.h"
class Graph {
public :
Graph(Ecran * ecran, int x0, int y0 ,int x1, int y1);
void drawAxes();
void drawTitle();
void drawDatas();
void drawGraph();
public :
Ecran * ecran;
int x0, y0,x1, y1;
String title, axe_x, axe_y;
};
#endif

View File

@@ -0,0 +1,7 @@
#include "Mesure.h"
Mesure::Mesure()
{
nb = 0;
somme = 0;
}

View File

@@ -0,0 +1,12 @@
#ifndef Mesure_h
#define Mesure_h
class Mesure {
public :
Mesure();
public :
int nb;
double somme;
};
#endif

View File

@@ -0,0 +1,122 @@
#include "Modules.h"
// int status = WL_IDLE_STATUS; // the Wifi radio's status
//WiFiClient client;
// Dallas
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
Modules::Modules()
{
Serial.println("--------------------------------------");
Serial.println("Init Module");
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW);
pinMode(RELAY_PIN_02, OUTPUT);
digitalWrite(RELAY_PIN_02, LOW);
pinMode(RELAY_PIN_03, OUTPUT);
digitalWrite(RELAY_PIN_03, LOW);
pinMode(RELAY_PIN_03, OUTPUT);
digitalWrite(RELAY_PIN_03, LOW);
}
bool Modules::readTemp()
{
//DS18B20.begin();
Serial.println("--------------------------------------");
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
Serial.print("Température Dallas =");
Serial.println(temp);
if (temp > 0 && temp < 70) {
return true;
}
return false;
}
void Modules::barometre() {
/* See Example: TypeA_WithDIPSwitches */
delay(500);
Serial.print("Barometre: ");
Serial.println(bmp.begin());
// BMP
if (bmp.begin()) {
delay(1000);
temp = bmp.readTemperature();
pressure = bmp.readPressure() / 100.0;
pression = pressure / 101.325;
pression = pression * 0.760 * 100;
// http://en.wikipedia.org/wiki/Atmospheric_pressure#Mean_sea_level_pressure
// Serial.print("Presiure la nivelul marii (calculata) = ");
presiune = bmp.readSealevelPressure(ALTITUDE) / 101.325;
presiune = presiune * 0.760;
Serial.print("Temperature="); Serial.println(temp);
Serial.print("pressure="); Serial.println(pressure);
Serial.print("pression="); Serial.println(pression);
}
else {
Serial.print("Pas de barometre détecté");
}
}
void Modules::sleep(int sleepTime)
{
Serial.print("Go to sleep ");
Serial.println(sleepTime);
delay(20);
ESP.deepSleep(sleepTime * 1000000L); // Infini
//sleepWifi();
delay(200);
}
void Modules::readDht()
{
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
humidity = dht.readHumidity();
// Read temperature as Celsius
temp = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temp) || isnan(f)) {
// Serial.println("Failed to read from DHT sensor!");
return;
} else {
// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, humidity);
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hi);
Serial.println(" *F");
}
}
void Modules::relay(int pin, int value)
{
delay(100);
digitalWrite(pin, value);
delay(100);
}

View File

@@ -0,0 +1,36 @@
#ifndef Modules_h
#define Modules_h
#include <Arduino.h>
#include <Adafruit_BMP085.h>
#include <DallasTemperature.h>
#include "DHT.h"
#include "Pins.h"
// ################# Barometre ####
#define ALTITUDE 19.0 // Altitude of SparkFun's HQ in Boulder, CO. in meters
#define DHTTYPE DHT11 // DHT 11
//SFE_BMP180 pressure;
// #####################
class Modules
{
public:
Modules();
bool readTemp();
void barometre();
void readDht();
void sleep(int sleepTime);
void relay(int pin, int value);
private:
public:
Adafruit_BMP085 bmp;
double humidity = 0;
double temp = 0;
double pression = 0;
double pressure = 0;
double presiune = 0;
int end_filament = 0;
};
#endif

View File

@@ -0,0 +1,26 @@
#ifndef Pins_h
#define Pins_h
#include <Arduino.h>
#define SDA D1
#define SCL D2
#define ONE_WIRE_BUS 5 // DS18B20 pin
#define DHTPIN 11 // what pin we're connected to
#define RELAY_PIN D0
#define RELAY_PIN_02 D1
#define RELAY_PIN_03 D2
#define RELAY_PIN_04 D6
#define BUTTON_PIN 0
// Ecran
#define PIN_RESET D3
#define PIN_SCE D4
#define PIN_DC D8
#define PIN_SDIN D7
#define PIN_SCLK D5
//#define PIN_LCD D6 // backlight
//#define PIN_FADER 1 // analog
//#define PIN_TMP 0 // analog
#endif