-GUIDO-
23-05-2016, 18:51
ciao
Dal 2013 ho controllato il mio marino da 200l con arduino , beneficiando anche del prezioso aiuto di chi popola questo forum ho potuto creare quello che mi serviva.
Display 20x4, rtc, ds18b20 (2),a display stampavo data e ora, temperatura vasca con pulsante per accedere a nuova pagina dove visualizzavo min e max di plafo e vasca, led di allarme in caso di temperature troppo elevate o basse, sfruttando l'ottima libreria di Nico79 controllavo la plafo led (autocostruita).
Ora per causa di qualche problemino di vista sono passato a display 128x64 st7920 che mi permette di stampare mooolto piu in grande cio che è bene vedere anche solo se si passa lontano dall'acquario-:33
Per ora ho un po tradotto cio che era il codice con display 20x4 ma mi sono inpantanato perche la libreria u8g non lavora esattamente come una liquidCrystal: Stampo ora e data, temperatura vasca in grande #21 min e max a display in tempo reale.
Problemi:
- non ho ancora capito come posso fare un lcd.clear premendo un pulsante con sta u8g #19
mi servirebbe per accedere a nuova pagina con stato dei 2 relè e ventola che vorrei gestire
- sempre per il suddetto scopo vorrei usare Alarm.alarmRepeat() (e rispettiva libreria) che mi darebbe opportunità
di temporizzare gli eventi.
- non mi riesce di far funzionare la mitica libreria di Nico79
direi che dopo sta compilation di lacune posto il codice che è meglio...
// Aggiungo librerie
#include "U8glib.h"
#include <SPI.h>
#include <Wire.h>
#include "RTClib.h"
#include <OneWire.h>
#include <DallasTemperature.h>
float massimaAcqua = -50; // dichiaro la variabile "massima"
float minimaAcqua = 65; //dichiaro la variabile "minima"
float massimaPlafo =-50; // dichiaro la variabile "massima interna"
float minimaPlafo = 65; //dichiaro la variabile "minima interna"
float temperature;
char temperatureString[4] = "-";
char massimaAcquaString[5] = "-";
char minimaAcquaString[5] = "-";
char massimaPlafoString[5] = "-";
char minimaPlafoString[5] = "-";
int P1 = A0; // assegno pin pulsante
int P2 = A1; // assegno pin pulsante
int P3 = A2; // assegno pin pulsante
int P4 = A3; // assegno pin pulsante
int pinLed[] = {2,3,5,6};
int bottone[] = {A0, A1, A2, A3};
int statoLed= 0;
// Include the OneWire library
#define ONE_WIRE_BUS 32 //assegno pin dati (sensori temperatura) Pin 32
// Setup OneWire bus
OneWire oneWire(ONE_WIRE_BUS);
// Setup DallasTemperature per lavorare con OneWire bus
DallasTemperature sensors(&oneWire);
DeviceAddress sensAcqua = { 0x28, 0xFF, 0x72, 0x61, 0x00, 0x16, 0x03, 0x1D};
DeviceAddress sensPlafo = { 0x28, 0x29, 0x6A, 0x84, 0x04, 0x00, 0x00, 0xDB };
// setup u8g
U8GLIB_ST7920_128X64_1X u8g(18, 16, 17);
// Setup RTC
RTC_DS1307 RTC;
char monthString[37]= {"GenFebMarAprMagGiuLugAgoSetOttNovDic"};
int monthIndex[122] ={0,3,6,9,12,15,18,21,24,27,30,33};
String thisMonth = "";
String thisTime = "";
String thisDay="";
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
// u8g.setFont(u8g_font_profont15);
u8g.setFont(u8g_font_helvB08);
//
//***** RTC **********
DateTime now = RTC.now();
// display date at bottom of screen
thisDay = String(now.day(), DEC) + "/";
thisMonth="";
for (int i=0; i<=2; i++){
thisMonth += monthString[monthIndex[now.month()-1]+i];
}
thisDay=thisDay + thisMonth + "/";
thisDay=thisDay + String(now.year() , DEC);
const char* newDay = (const char*) thisDay.c_str();
u8g.drawStr(60,11, newDay);
// *********************
// display time in digital format
thisTime="";
thisTime=String(now.hour()) + ".";
if (now.minute() < 10){ thisTime=thisTime + "0";} // add leading zero if required
thisTime=thisTime + String(now.minute()) + ".";
if (now.second() < 10){ thisTime=thisTime + "0";} // add leading zero if required
thisTime=thisTime + String(now.second());
const char* newTime = (const char*) thisTime.c_str();
u8g.setFont(u8g_font_helvB08);
u8g.drawStr(2,11, newTime);
//stampo temperatura acqua grande
u8g.setFont(u8g_font_6x10);
u8g.drawStr( 2, 25, "temp Acqua");
if (temperature == -127) {
u8g.setFont(u8g_font_7x14);
u8g.drawStr( 12, 43, "errore");
}else {
u8g.setFont(u8g_font_ncenB18);
u8g.drawStr( 2, 50, temperatureString);
u8g.drawStr(55,50,"°");
}
//PLAFO//
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 70, 23, "-ACQUA"); //da rivedere... dovrebbe essere "plafo"
u8g.drawStr( 70, 30, "max");
u8g.setFont(u8g_font_courB08);
if (temperature == -127) {
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 100, 30, "errore");
}else {
u8g.drawStr( 100, 30, massimaPlafoString);
}
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 70, 39, "min");
u8g.setFont(u8g_font_courB08);
if (temperature == -127) {
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 100, 39, "errore");
}else {
u8g.drawStr( 100, 39, minimaPlafoString);
}
//imposto condizione che restituisce valore "massima e minima"
if (temperature > massimaPlafo)
massimaPlafo = temperature;
if (temperature < minimaPlafo)
minimaPlafo = temperature;
temperature = sensors.getTempC(sensPlafo);
//ACQUA//
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 70, 47, "-PLAFO"); // da rivedere... dovrebbe essere "acqua"
u8g.drawStr( 70, 54, "max");
u8g.setFont(u8g_font_courB08);
if (temperature == -127) {
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 100, 54, "errore");
}else {
u8g.drawStr( 100, 54, massimaAcquaString);
}
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 70, 64, "min");
u8g.setFont(u8g_font_courB08);
if (temperature == -127) {
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 100, 64, "errore");
}else {
u8g.drawStr( 100, 64, minimaAcquaString);
}
//imposto condizione che restituisce valore "massima e minima"
if (temperature > massimaAcqua)
massimaAcqua = temperature;
if (temperature < minimaAcqua)
minimaAcqua = temperature;
temperature = sensors.getTempC(sensAcqua);
u8g.setFont(u8g_font_timB12);
u8g.drawStr( 2,64,"menu");
u8g.setFont(u8g_font_4x6);
u8g.drawStr( 44,59,"tasto");
u8g.drawStr( 44,64,"verde");
}
void setup(void) {
{
for(int indice = 0; indice < 4; indice++)
{
pinMode(pinLed[indice], OUTPUT);
pinMode(bottone[indice], INPUT);
}
}
Serial.begin(9600);
// If you want to set the aref to something other than 5v
analogReference(EXTERNAL);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop() {
// picture loop
u8g.firstPage();
do {
u8g.drawHLine(0, 13, 128);// disegno linea orizzontale
u8g.drawHLine(0, 15, 128);// disegno linea orizzontale
u8g.drawLine(65, 15, 65, 64);//disegno linea verticale
draw();
} while( u8g.nextPage() );
{
for(int indice = 0; indice < 4; indice++)
{
int leggiBottone=digitalRead(bottone[indice]);
if (leggiBottone == 1)
{
if (statoLed == 0)
{
statoLed=120;
analogWrite(pinLed[indice], statoLed);
delay(1000);
} else {
statoLed=0;
analogWrite(pinLed[indice], statoLed);
delay(1000);
}
}
}
}
// Update the sensor readings
sensors.requestTemperatures();
dtostrf(temperature, 2, 1, temperatureString);
//PLAFO
//leggo temperature
dtostrf(massimaPlafo, 2, 1, massimaPlafoString);
dtostrf(minimaPlafo, 2, 1, minimaPlafoString);
//ACQUA
// Read Temperature
dtostrf(massimaAcqua, 2, 1, massimaAcquaString);
dtostrf(minimaAcqua, 2, 1, minimaAcquaString);
// rebuild the picture after some delay
delay(100);
}
Per ora nel codice ho inserito l'accensione della plafo in manuale tramite pulsanti visti i problemi sopra citati
aggiungo foto display, temperatura acqua da errore perche non ho sonda attiva per ora #19
per ultimo...uso arduino mega.
Questo è quanto #13
http://s33.postimg.cc/k7fa4cl57/display_128x64.jpg (http://postimg.cc/image/k7fa4cl57/)
Dal 2013 ho controllato il mio marino da 200l con arduino , beneficiando anche del prezioso aiuto di chi popola questo forum ho potuto creare quello che mi serviva.
Display 20x4, rtc, ds18b20 (2),a display stampavo data e ora, temperatura vasca con pulsante per accedere a nuova pagina dove visualizzavo min e max di plafo e vasca, led di allarme in caso di temperature troppo elevate o basse, sfruttando l'ottima libreria di Nico79 controllavo la plafo led (autocostruita).
Ora per causa di qualche problemino di vista sono passato a display 128x64 st7920 che mi permette di stampare mooolto piu in grande cio che è bene vedere anche solo se si passa lontano dall'acquario-:33
Per ora ho un po tradotto cio che era il codice con display 20x4 ma mi sono inpantanato perche la libreria u8g non lavora esattamente come una liquidCrystal: Stampo ora e data, temperatura vasca in grande #21 min e max a display in tempo reale.
Problemi:
- non ho ancora capito come posso fare un lcd.clear premendo un pulsante con sta u8g #19
mi servirebbe per accedere a nuova pagina con stato dei 2 relè e ventola che vorrei gestire
- sempre per il suddetto scopo vorrei usare Alarm.alarmRepeat() (e rispettiva libreria) che mi darebbe opportunità
di temporizzare gli eventi.
- non mi riesce di far funzionare la mitica libreria di Nico79
direi che dopo sta compilation di lacune posto il codice che è meglio...
// Aggiungo librerie
#include "U8glib.h"
#include <SPI.h>
#include <Wire.h>
#include "RTClib.h"
#include <OneWire.h>
#include <DallasTemperature.h>
float massimaAcqua = -50; // dichiaro la variabile "massima"
float minimaAcqua = 65; //dichiaro la variabile "minima"
float massimaPlafo =-50; // dichiaro la variabile "massima interna"
float minimaPlafo = 65; //dichiaro la variabile "minima interna"
float temperature;
char temperatureString[4] = "-";
char massimaAcquaString[5] = "-";
char minimaAcquaString[5] = "-";
char massimaPlafoString[5] = "-";
char minimaPlafoString[5] = "-";
int P1 = A0; // assegno pin pulsante
int P2 = A1; // assegno pin pulsante
int P3 = A2; // assegno pin pulsante
int P4 = A3; // assegno pin pulsante
int pinLed[] = {2,3,5,6};
int bottone[] = {A0, A1, A2, A3};
int statoLed= 0;
// Include the OneWire library
#define ONE_WIRE_BUS 32 //assegno pin dati (sensori temperatura) Pin 32
// Setup OneWire bus
OneWire oneWire(ONE_WIRE_BUS);
// Setup DallasTemperature per lavorare con OneWire bus
DallasTemperature sensors(&oneWire);
DeviceAddress sensAcqua = { 0x28, 0xFF, 0x72, 0x61, 0x00, 0x16, 0x03, 0x1D};
DeviceAddress sensPlafo = { 0x28, 0x29, 0x6A, 0x84, 0x04, 0x00, 0x00, 0xDB };
// setup u8g
U8GLIB_ST7920_128X64_1X u8g(18, 16, 17);
// Setup RTC
RTC_DS1307 RTC;
char monthString[37]= {"GenFebMarAprMagGiuLugAgoSetOttNovDic"};
int monthIndex[122] ={0,3,6,9,12,15,18,21,24,27,30,33};
String thisMonth = "";
String thisTime = "";
String thisDay="";
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
// u8g.setFont(u8g_font_profont15);
u8g.setFont(u8g_font_helvB08);
//
//***** RTC **********
DateTime now = RTC.now();
// display date at bottom of screen
thisDay = String(now.day(), DEC) + "/";
thisMonth="";
for (int i=0; i<=2; i++){
thisMonth += monthString[monthIndex[now.month()-1]+i];
}
thisDay=thisDay + thisMonth + "/";
thisDay=thisDay + String(now.year() , DEC);
const char* newDay = (const char*) thisDay.c_str();
u8g.drawStr(60,11, newDay);
// *********************
// display time in digital format
thisTime="";
thisTime=String(now.hour()) + ".";
if (now.minute() < 10){ thisTime=thisTime + "0";} // add leading zero if required
thisTime=thisTime + String(now.minute()) + ".";
if (now.second() < 10){ thisTime=thisTime + "0";} // add leading zero if required
thisTime=thisTime + String(now.second());
const char* newTime = (const char*) thisTime.c_str();
u8g.setFont(u8g_font_helvB08);
u8g.drawStr(2,11, newTime);
//stampo temperatura acqua grande
u8g.setFont(u8g_font_6x10);
u8g.drawStr( 2, 25, "temp Acqua");
if (temperature == -127) {
u8g.setFont(u8g_font_7x14);
u8g.drawStr( 12, 43, "errore");
}else {
u8g.setFont(u8g_font_ncenB18);
u8g.drawStr( 2, 50, temperatureString);
u8g.drawStr(55,50,"°");
}
//PLAFO//
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 70, 23, "-ACQUA"); //da rivedere... dovrebbe essere "plafo"
u8g.drawStr( 70, 30, "max");
u8g.setFont(u8g_font_courB08);
if (temperature == -127) {
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 100, 30, "errore");
}else {
u8g.drawStr( 100, 30, massimaPlafoString);
}
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 70, 39, "min");
u8g.setFont(u8g_font_courB08);
if (temperature == -127) {
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 100, 39, "errore");
}else {
u8g.drawStr( 100, 39, minimaPlafoString);
}
//imposto condizione che restituisce valore "massima e minima"
if (temperature > massimaPlafo)
massimaPlafo = temperature;
if (temperature < minimaPlafo)
minimaPlafo = temperature;
temperature = sensors.getTempC(sensPlafo);
//ACQUA//
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 70, 47, "-PLAFO"); // da rivedere... dovrebbe essere "acqua"
u8g.drawStr( 70, 54, "max");
u8g.setFont(u8g_font_courB08);
if (temperature == -127) {
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 100, 54, "errore");
}else {
u8g.drawStr( 100, 54, massimaAcquaString);
}
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 70, 64, "min");
u8g.setFont(u8g_font_courB08);
if (temperature == -127) {
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 100, 64, "errore");
}else {
u8g.drawStr( 100, 64, minimaAcquaString);
}
//imposto condizione che restituisce valore "massima e minima"
if (temperature > massimaAcqua)
massimaAcqua = temperature;
if (temperature < minimaAcqua)
minimaAcqua = temperature;
temperature = sensors.getTempC(sensAcqua);
u8g.setFont(u8g_font_timB12);
u8g.drawStr( 2,64,"menu");
u8g.setFont(u8g_font_4x6);
u8g.drawStr( 44,59,"tasto");
u8g.drawStr( 44,64,"verde");
}
void setup(void) {
{
for(int indice = 0; indice < 4; indice++)
{
pinMode(pinLed[indice], OUTPUT);
pinMode(bottone[indice], INPUT);
}
}
Serial.begin(9600);
// If you want to set the aref to something other than 5v
analogReference(EXTERNAL);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop() {
// picture loop
u8g.firstPage();
do {
u8g.drawHLine(0, 13, 128);// disegno linea orizzontale
u8g.drawHLine(0, 15, 128);// disegno linea orizzontale
u8g.drawLine(65, 15, 65, 64);//disegno linea verticale
draw();
} while( u8g.nextPage() );
{
for(int indice = 0; indice < 4; indice++)
{
int leggiBottone=digitalRead(bottone[indice]);
if (leggiBottone == 1)
{
if (statoLed == 0)
{
statoLed=120;
analogWrite(pinLed[indice], statoLed);
delay(1000);
} else {
statoLed=0;
analogWrite(pinLed[indice], statoLed);
delay(1000);
}
}
}
}
// Update the sensor readings
sensors.requestTemperatures();
dtostrf(temperature, 2, 1, temperatureString);
//PLAFO
//leggo temperature
dtostrf(massimaPlafo, 2, 1, massimaPlafoString);
dtostrf(minimaPlafo, 2, 1, minimaPlafoString);
//ACQUA
// Read Temperature
dtostrf(massimaAcqua, 2, 1, massimaAcquaString);
dtostrf(minimaAcqua, 2, 1, minimaAcquaString);
// rebuild the picture after some delay
delay(100);
}
Per ora nel codice ho inserito l'accensione della plafo in manuale tramite pulsanti visti i problemi sopra citati
aggiungo foto display, temperatura acqua da errore perche non ho sonda attiva per ora #19
per ultimo...uso arduino mega.
Questo è quanto #13
http://s33.postimg.cc/k7fa4cl57/display_128x64.jpg (http://postimg.cc/image/k7fa4cl57/)