PoTroll
successeur de
PoTrollDoucheV3 (fork lcd puis universelle en cours)
version avec
- afficheur LCD 16x2, connexion I2C, pas d'interface de commande
- programmation température par usb
- repris le 20170101, sur Vostro LcdKeyD?
- àsuire: PotrollDoucheLcdKey
20160410
- la mesure prend moins de 300 ms
- écran Lcd dispo seulement au démarrage (reset pour le faire réapparaitre)
- 4 digits possible
20160408
porté sur
ArduinoproMini sur breadboard rouge
- mémorise réglages
- programmer réglages par l'interface série de debug
20160407
consigne fixe!
prise CH2 A
affichage 4digits si connecté
sonde
Ds18B20 étanche sur câble
était branché par prolific noir intégré dans usb A mâle! (noir rouge vert jaune) (BSOD fréquent)
mis usb pwr noir rouge
conso: moins de 1 mA en veille, donc si 400 mAh (batôn 9900 mAh) on doit durer 400 heures, plus d'une semaine
chantier: C:\Users\adminpo\Desktop\ARDUINO\arduino-1.6.7\examples\po\
PoTrollDoucheV4?
réflexion sur afficheur!
le
Led4Digits5pins n'est pas convenable (nécessite en rafraichissement permanent)
plus simple avec
Led4digitsClock4pins
ressorti
ArduinoLcd16x2 (6 mA , mais 25 mA avec rétro-éclairage)
voir ce que coute LcdKeypadShield 1.5 €
testé branchement alimentation sur pin 2 et extinction à la fin du sursis, reboot pour le revoir
voir ce que donne 8 chiffres + clavier
Display8digits8Keys8Leds
20160407-1300 mis en décharge sur
PowerBankGoldLed : semble tenir
bilan20160408
commande
Rf433 Hs
Ok conso écran sur pin D
câblage proto était:
montage sur mini breadboard rouge
colonne de gauche,
bas: Grnd par male-male orange
hautVcc par male male vert
Rf433:
Lcd inchangé
Ds18B20:
noir -prolongé MM noir Grnd
rouge prolongé MM noir Vcc
marron prolongé MM jaune: D11
Connexions: de bas en haut: Noir rouge, vert, blanc, deux pins externes non connectées
#define DEEPSLEEP true
#define PRECISION 100.
#include <DS18B20.h>
#include <RCSwitch.h>
#include <Sleep_n0m1.h>
#include <Wire.h> // Include Wire.h to control I2C
#include <LiquidCrystal_I2C.h> //Download & include the code library can be downloaded below
#include <DISPLAY4.h>
#include <EEPROM.h>
/* map eprom
* 0-11: ON
* 12 23: OFF
* 24-25 1/100 deg
* */
// display
#define SCK 7
#define RCK 5
#define DIO 6
Sleep sleep;
unsigned long sleepTime; //how long you want the arduino to sleep
RCSwitch mySwitch = RCSwitch();
// testé le 20120213 aveccapteur reçu ce jour
// http://antiguide.free.fr/wiki/wakka.php?wiki=ArduinoDs18B20
/*ReadDS18B20
ver: 6 Jly 2010
THIS IS A FIRST DRAFT.... WORKS, but scheduled for overhaul.
Simple, simple test of reading DS18B20
connected to nuelectronics.com datalogging shield.
See...
http://sheepdogguides.com/arduino/ar3ne1tt.htm
... for explanation of this code.
Code lightly adapted from code from nuelectronics.com*/
#define PWR_PIN 13
#define LCD_PWR_PIN 2
#define TEMP_PIN 11 //See Note 1, sheepdogguides..ar3ne1tt.htm
#define TEMP_PWR_PIN 12 //See Note 1, sheepdogguides..ar3ne1tt.htm
#define RF433_PIN 10
long Tcritique=0;
//#define ON "00FF00FF000F"
#define OFF "00FF00FF0000"
char on[12]={'0','0','F','F','0','0','F','F','0','0','0','F'};
char off[12]={'0','0','F','F','0','0','F','F','0','0','0','0'};
char shown[12];
DS18B20 ds;
DISPLAY4 display;
long awake;
enum keypad {k_up,k_down, k_left, k_right,k_enter};
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE); // Initialize LCD Display at address 0x27
long SURSIS=60000;
long sursis=SURSIS;
bool menu=false;
int colonne=3;
int COLONNES=6;
int line=0;
int detail=-1;
int DETAILS=12;
void powerlcd(bool onoff){
Serial.print("power lcd ");Serial.println(onoff);
pinMode(LCD_PWR_PIN,OUTPUT);
if (onoff) {
digitalWrite(LCD_PWR_PIN,HIGH);
} else {
digitalWrite(LCD_PWR_PIN,LOW);
}
}
bool lcdon=true;
void setup() {
powerlcd(true);
Serial.begin(115200);
delay(1000);
pinMode(13,OUTPUT);
sleepTime =60000;
lcd.begin (16,2);
awake=millis();
Serial.print("Douche... : ");
lcd.print("Douche... : ");
Tcritique=getconsigne();
Serial.print("temperature choisie: ");
Serial.println(Tcritique);
mySwitch.enableTransmit(RF433_PIN); // pin emetteur
mySwitch.setRepeatTransmit(4); // increase # of frames will slow process!
plug(true);delay(2000);
plug(false);delay(2000);
digitalWrite(TEMP_PIN, LOW);
pinMode(TEMP_PIN, INPUT_PULLUP); // sets the digital pin as INPUT_PULLUP (logic 1)
digitalWrite(TEMP_PWR_PIN,LOW);
pinMode(TEMP_PWR_PIN, OUTPUT); // sets the digital pin as INPUT_PULLUP (logic 1)
digitalWrite(TEMP_PWR_PIN,HIGH);
pinMode(PWR_PIN, OUTPUT); // sets the digital pin as INPUT_PULLUP (logic 1)
digitalWrite(PWR_PIN,HIGH);
Serial.print(TEMP_PIN);
Serial.print("\n");
ds.begin(TEMP_PIN);
sleep.idleMode();
sleep_mode();
wdt_disable();
// vider buffer
while (Serial.available()>0) int xx=Serial.read();
dump(0);
dump(1);
dump(2);
sursis=SURSIS;
menu=true;
go();
}
long getconsigne(){
long l=0;
for (int i=0;i<5;i++ ){
if (i!=2){
l=l*10;
l=l+EEPROM.read(24+i)-'0';
}
}
return l;
}
void raz(){
for (int i=0;i<12;i++){
EEPROM.write(i,on[i]);
delay(100);
if (EEPROM.read(i)!=on[i]) Serial.println("ereur ecriture");
EEPROM.write(i+12,off[i]);
EEPROM.write(i+24,' ');
delay(100);
}
EEPROM.write(24,'2');
EEPROM.write(25,'7');
EEPROM.write(26,'.');
EEPROM.write(27,'5');
EEPROM.write(28,'5');
Serial.println("stored");
}
void plug(bool on){
Serial.print("demande la prise en etat ");Serial.println(on);
int ad;
if (on) ad=0;else ad=12;
long l=0;
for (int i=0;i<12;i++) {
l=l*4;
if ((char) EEPROM.read(ad+i)== (char) 'F') l=l+1;
}
if (lcdon) {
lcd.setCursor(11,0);
if (on) lcd.print("On ");
else lcd.print("Off");
}
/* affichage cmd
*
mySwitch.send(l,12);
lcd.setCursor(0,0); // Move cursor to 0
lcd.print(l);
*/
}
void act(float x){
if (!lcdon) return;
lcd.setBacklight(HIGH); //Set Back light turn On
lcd.setCursor(0,1); // Move cursor to 0
lcd.print("1 ");
lcd.setCursor(0,1); // Move cursor to 0
lcd.print(x);
}
void th(float x){
if (menu) return;
if (!lcdon) return;
lcd.setBacklight(HIGH); //Set Back light turn On
lcd.setCursor(0,0); // Move cursor to 0
lcd.print("2 ");
lcd.setCursor(0,0); // Move cursor to 0
lcd.print(x);
}
bool cmdav(){
bool ya=Serial.available()>0;
return ya;
}
void titre(char *t){
if (!lcdon) return;
lcd.setCursor(0,0); // Move cursor to 0
lcd.print("3 ");
lcd.setCursor(0,0); // Move cursor to 0
lcd.print(t);
}
void show(int what){
if (!lcdon) return;
for (int i=0;i<12;i++){
lcd.setCursor(i,1);
shown[i]=EEPROM.read(12*what+i);
lcd.print(shown[i]);
}
}
void dump(int what){
for (int i=0;i<12;i++){
Serial.print((char) EEPROM.read(12*what+i)) ;
}
Serial.println();
}
void change(char sens,int index,int onoff){
char old=shown[index];
if (onoff<2){
if (old='0' && sens=='+') shown[index]='F';
if (old='F' && sens=='+') shown[index]='1';
if (old='F' && sens=='-') shown[index]='0';
if (old='1' && sens=='-') shown[index]='F';
} else{
if (old>='0' && old<'9' && sens=='+') shown[index]=shown[index]+1;
if (old>='1' && old<='9' && sens=='-') shown[index]=shown[index]-1;
}
EEPROM.write(index+12*onoff,shown[index]);
show(onoff);
}
void go(){
lcd.setCursor(14,0);
lcd.print(" ");
lcd.setCursor(0,0);
if (menu) lcd.print("Menu <- -> ");
lcd.setCursor(0,1);
lcd.print(" ");
// powerlcd(false);
}
void docmd (){
char key= Serial.read();
if (key<' ')return;
menu=true;
sursis=SURSIS;
Serial.println((int) key);
keypad btn;
switch (key){
case 'd' : {
btn=k_right;
break;
}
case 's' : {
btn=k_left;
break;
}
case 'e' : {
btn=k_up;
break;
}
case 'x' : {
btn=k_down;
break;
}
case 'm' : {
btn=k_enter;
break;
}
}
switch (btn) {
case k_right: {
if (line==0 && colonne<COLONNES)colonne=colonne+1;
if (line==1 && detail<DETAILS)detail=detail+1;
Serial.print ("now colonne=");Serial.print(colonne);Serial.print(" detail:");Serial.println(detail);
break;
}
case k_left: {
if (line==0 && colonne>0)colonne=colonne-1;
if (line==1 && detail>0)detail=detail-1;
Serial.print ("now colonne=");Serial.print(colonne);Serial.print(" detail:");Serial.println(detail);
break;
}
case k_up: {
if (line==1) change('+',detail,colonne);;
break;
}
case k_down: {
if (line==1) change('-',detail,colonne);
break;
}
case k_enter: {
Serial.println("enter");
if (colonne==5) {
menu=false;
powerlcd(false);
go();
return;
}
if (colonne==3) {
plug(true);
go();
return;
}
if (colonne==4) {
plug(false);
go();
return;
}
if (colonne==6) {
raz();
go();
return;
}
// effacer ?
Serial.println("ENTER");
lcd.setCursor(15,line); // Move cursor to 0
lcd.print(" ");
line=1-line;
// if line=1 mise à jour
if (line==1 ){
show(colonne);
detail=0;
}
}
break;
}
switch (colonne) {
case 0:{
titre ("On");
break;
}
case 1:{
titre ("Off");
break;
}
case 2:{
titre ("Temperature");
break;
}
case 3:{
titre ("Test ON");
break;
}
case 4:{
titre ("Test OFF");
break;
}
case 5:{
titre ("Go");
break;
}
case 6:{
titre ("RAZ.");
break;
}
}
}
long blink=0;
bool vu=false;
bool ok=false;
int prev=-1;
void loop(){
delay(500);
// Serial.print("loop ");
// Serial.println(millis());
if (cmdav()) {
// Serial.println("cmd av");
docmd();return;}
if (menu){
//Serial.println("menu en cours");
if (millis()>sursis+SURSIS) {
menu=false;
Serial.println("FIN DE MENU TIMEOUT");
lcd.setCursor(15,0);
lcd.print(" ");
lcd.setCursor(15,1);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("6 ");
lcd.setCursor(0,0);
lcd.print(Tcritique/100);
}
if (millis()>blink+500){
lcd.setCursor(15,line); // Move cursor to 0
blink=millis();
vu=!vu;
if (vu && menu) lcd.print('?');
else lcd.print(' ');
if (line==1 && detail>-1) {
if (prev!=-1) {
lcd.setCursor(prev,line);
lcd.print(shown[prev]);
}
lcd.setCursor(detail,line);
if (vu && menu) lcd.print('?');
else lcd.print(shown[detail]);
prev=detail;
}
}
//Serial.println("rteturn");
return;
}
// if (menu) Serial.println("fin de lmenu");
// menu=false;
// Serial.print("not menu");
if (lcdon) lcd.setCursor(0,10); // Move cursor to 0
int TReading=ds.read();
if (! ok){
delay(1000);
ok=true;
return;
}
Serial.println("prendre temp");
th(Tcritique/PRECISION);
Serial.print(" raw: ");
Serial.println(TReading);
int SignBit, Whole, Fract, Tc_100;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
// ignore first value
if (ok){
Serial.print("centieme de degre: ");Serial.println(Tc_100);
plug(Tc_100<Tcritique);
act(Tc_100/PRECISION);
display.setint(Tc_100);
display.show(5);
Whole = Tc_100 / 100; // separate off the whole and fractional portions
Fract = Tc_100 % 100;
if (SignBit) // If its negative
{
Serial.print("-");
}
Serial.print(Whole);
Serial.print(".");
if (Fract < 10)
{
Serial.print("0");
}
Serial.print(Fract);
Serial.print("\n");
}
long alive=millis()-awake;
Serial.print("alive during ");Serial.println(alive);
if (alive>sleepTime) alive=0;
if (DEEPSLEEP) Serial.print("deep");
Serial.print("sleep for (ms): ");
Serial.println(sleepTime - alive);
delay(100); //delay to allow serial to fully print before sleep
if (DEEPSLEEP) {
digitalWrite(PWR_PIN,LOW);
lcdon=false;
digitalWrite(LCD_PWR_PIN,LOW);
sleep.pwrDownMode(); //set sleep mode
sleep.sleepDelay(sleepTime); //sleep for: sleepTime
delay(100); ////delays are just for serial print, without serial they can be removed
Serial.println("Awaked... ");
digitalWrite(PWR_PIN,HIGH);
awake=millis();
}
else{
digitalWrite(PWR_PIN,LOW);
long ds=sleepTime;
while (ds>0) {
if (cmdav()) return;
delay(100);
ds=ds-100;
}
digitalWrite(PWR_PIN,HIGH);
}
}