PB D'ASSOCIATION HUMIDITE SUR DS18B20 + SHT31D
Publié : 23 déc. 2019, 16:27
Bonjour,
Je suis tout débutant dans l'environnement ARDUINO et DOMOTICZ, j'y suis venu pour me faire une balance de ruche étant donné le prix prohibitif de ces dernières.
J'arrive à peu prés a faire ce que je veux mise à part quelques détails gênants :
Pour résumé le projet :
Arduino pro mini
HX711 + 1 cellule de charge
DS18B20 fixé sur la cellule de charge pour une éventuelle compensation du poids en fonction de la température de la cellule
DS18B20 pour la température à l'intérieure de la ruche, sur un deuxiéme pin de l'arduino, afin d'eventuellement en mettre quelques uns en série
SHT31D pour la température et l'humidité dans la ruche ou au dessus dans la hausse
Tout les capteurs répondent ça pas de problème, par contre il est associé la mesure d’humidité du SHT31D également au DS18B20. cela est gênant dans le sens ou je compte utiliser le mode plan et il est impossible de dissocier les 2 affichages.
le problème a déjà été abordé dans ce post viewtopic.php?f=20&t=1286 mais clear l'EEprom n'a rien changé pour moi.
Le problème est aussi abordé sur ce post https://forum.mysensors.org/topic/5132/ ... domoticz/4 et il est question de grouper les capteurs d'un même nœud, mais il n'est pas expliqué la façon de faire.
le "#" indique a priori les groupe, je pense que j'ai un problème dans ma façon de déclarer pour avoir tout les capteur sur le meme groupe "#1".,
illstration :

Merci d'avance,
ci-après un max d'info :
Détail du Node :

Dispositifs :

Log Domoticz :

Log Mysensors :
Mon code :
Je suis tout débutant dans l'environnement ARDUINO et DOMOTICZ, j'y suis venu pour me faire une balance de ruche étant donné le prix prohibitif de ces dernières.
J'arrive à peu prés a faire ce que je veux mise à part quelques détails gênants :
Pour résumé le projet :
Arduino pro mini
HX711 + 1 cellule de charge
DS18B20 fixé sur la cellule de charge pour une éventuelle compensation du poids en fonction de la température de la cellule
DS18B20 pour la température à l'intérieure de la ruche, sur un deuxiéme pin de l'arduino, afin d'eventuellement en mettre quelques uns en série
SHT31D pour la température et l'humidité dans la ruche ou au dessus dans la hausse
Tout les capteurs répondent ça pas de problème, par contre il est associé la mesure d’humidité du SHT31D également au DS18B20. cela est gênant dans le sens ou je compte utiliser le mode plan et il est impossible de dissocier les 2 affichages.
le problème a déjà été abordé dans ce post viewtopic.php?f=20&t=1286 mais clear l'EEprom n'a rien changé pour moi.
Le problème est aussi abordé sur ce post https://forum.mysensors.org/topic/5132/ ... domoticz/4 et il est question de grouper les capteurs d'un même nœud, mais il n'est pas expliqué la façon de faire.
le "#" indique a priori les groupe, je pense que j'ai un problème dans ma façon de déclarer pour avoir tout les capteur sur le meme groupe "#1".,
illstration :

Merci d'avance,
ci-après un max d'info :
Détail du Node :

Dispositifs :

Log Domoticz :

Log Mysensors :
Code : Tout sélectionner
__ __ ____
| \/ |_ _/ ___| ___ _ __ ___ ___ _ __ ___
| |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
| | | | |_| |___| | __/ | | \__ \ _ | | \__ \
|_| |_|\__, |____/ \___|_| |_|___/\___/|_| |___/
|___/ 2.3.1
16 MCO:BGN:INIT NODE,CP=RNNNA---,REL=255,VER=2.3.1
26 MCO:BGN:BFR
MYSENSORS SHT31D Temperature Humidity sensor: Start SHT31
OK
40 TSM:INIT
43 TSF:WUR:MS=0
49 TSM:INIT:TSP OK
51 TSF:SID:OK,ID=87
53 TSM:FPAR
90 TSF:MSG:SEND,87-87-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
204 TSF:MSG:READ,0-0-87,s=255,c=3,t=8,pt=1,l=1,sg=0:0
210 TSF:MSG:FPAR OK,ID=0,D=1
2099 TSM:FPAR:OK
2099 TSM:ID
2101 TSM:ID:OK
2103 TSM:UPL
2107 TSF:MSG:SEND,87-87-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
2117 TSF:MSG:READ,0-0-87,s=255,c=3,t=25,pt=1,l=1,sg=0:1
2123 TSF:MSG:PONG RECV,HP=1
2127 TSM:UPL:OK
2129 TSM:READY:ID=87,PAR=0,DIS=1
2134 TSF:MSG:SEND,87-87-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
2142 TSF:MSG:READ,0-0-87,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
2150 TSF:MSG:SEND,87-87-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.1
2160 TSF:MSG:SEND,87-87-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
2174 TSF:MSG:READ,0-0-87,s=255,c=3,t=6,pt=0,l=1,sg=0:M
2183 TSF:MSG:SEND,87-87-0-0,s=255,c=3,t=11,pt=0,l=10,sg=0,ft=0,st=OK:BEECONNECT
2193 TSF:MSG:SEND,87-87-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0
2203 TSF:MSG:SEND,87-87-0-0,s=0,c=0,t=12,pt=0,l=0,sg=0,ft=0,st=OK:
2211 TSF:MSG:SEND,87-87-0-0,s=1,c=0,t=12,pt=0,l=0,sg=0,ft=0,st=OK:
2222 TSF:MSG:SEND,87-87-0-0,s=2,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
2230 TSF:MSG:SEND,87-87-0-0,s=3,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
2238 TSF:MSG:SEND,87-87-0-0,s=4,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
2248 TSF:MSG:SEND,87-87-0-0,s=5,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
2254 MCO:REG:REQ
2258 TSF:MSG:SEND,87-87-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
2267 TSF:MSG:READ,0-0-87,s=255,c=3,t=27,pt=1,l=1,sg=0:1
2273 MCO:PIM:NODE REG=1
2275 MCO:BGN:STP
2539 MCO:BGN:INIT OK,TSP=1
Weight: 1.23
Temp out: 18.81
Temp in: 20.19
2916 TSF:MSG:SEND,87-87-0-0,s=2,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:21.2
2926 TSF:MSG:SEND,87-87-0-0,s=3,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:49.8
transmitted temperature OK: 21.17°C
transmitted humidity OK: 49.75%
2949 TSF:MSG:SEND,87-87-0-0,s=0,c=1,t=12,pt=7,l=5,sg=0,ft=0,st=OK:1.2
2959 TSF:MSG:SEND,87-87-0-0,s=1,c=1,t=12,pt=7,l=5,sg=0,ft=0,st=OK:1.2
2967 TSF:MSG:SEND,87-87-0-0,s=4,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:20.2
2977 TSF:MSG:SEND,87-87-0-0,s=5,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:18.8
2985 MCO:SLP:MS=5000,SMS=0,I1=255,M1=255,I2=255,M2=255
2992 TSF:TDI:TSL
2994 MCO:SLP:WUP=-1
2996 TSF:TRI:TSB
ADC: 916
VCC: 3.968
0 : 4.20 | 100
1 : 4.10 | 96
2 : 4.00 | 92
3 : 3.96 | 89
3012 TSF:MSG:SEND,87-87-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:89
transmitted battery level OK: 89%
Weight: 4.23
Temp out: 18.75
Temp in: 20.31
3395 TSF:MSG:SEND,87-87-0-0,s=2,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:21.1
3405 TSF:MSG:SEND,87-87-0-0,s=3,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:49.7
transmitted temperature OK: 21.11°C
transmitted humidity OK: 49.69%
3428 TSF:MSG:SEND,87-87-0-0,s=0,c=1,t=12,pt=7,l=5,sg=0,ft=0,st=OK:4.2
3436 TSF:MSG:SEND,87-87-0-0,s=1,c=1,t=12,pt=7,l=5,sg=0,ft=0,st=OK:3.0
3446 TSF:MSG:SEND,87-87-0-0,s=4,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:20.3
3457 TSF:MSG:SEND,87-87-0-0,s=5,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:18.8
3465 MCO:SLP:MS=5000,SMS=0,I1=255,M1=255,I2=255,M2=255
3471 TSF:TDI:TSL
Code : Tout sélectionner
#define MY_DEBUG
#define MY_RADIO_NRF24
#include <SPI.h>
#include <MySensors.h>
#include "HX711.h"
#include <Adafruit_SHT31.h>
Adafruit_SHT31 sht31 = Adafruit_SHT31();
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS_1 4
#define ONE_WIRE_BUS_2 3
OneWire oneWire_out(ONE_WIRE_BUS_1);
OneWire oneWire_in(ONE_WIRE_BUS_2);
DallasTemperature sensor_out(&oneWire_out);
DallasTemperature sensor_in(&oneWire_in);
const int LOADCELL_DOUT_PIN = 7;
const int LOADCELL_SCK_PIN = 8;
float calibration_factor = 22;
//float manual_tare = 9500;
float calibration_temperature = 20;
float l;
HX711 scale;
unsigned long SLEEP_TIME = 5000;
#define VREF 1.099
struct batteryCapacity
{
float voltage;
int capacity;
};
const batteryCapacity remainingCapacity[] = {
4.20, 100,
4.10, 96,
4.00, 92,
3.96, 89,
3.92, 85,
3.89, 81,
3.86, 77,
3.83, 73,
3.80, 69,
3.77, 65,
3.75, 62,
3.72, 58,
3.70, 55,
3.66, 51,
3.62, 47,
3.58, 43,
3.55, 40,
3.51, 35,
3.48, 32,
3.44, 26,
3.40, 24,
3.37, 20,
3.35, 17,
3.27, 13,
3.20, 9,
3.1, 6,
3.00, 3,
};
const int ncell = sizeof(remainingCapacity) / sizeof(struct batteryCapacity);
#define CHILD_ID_WEIGHT 0
#define CHILD_ID_WEIGHT 1
#define CHILD_ID_TEMP 2
#define CHILD_ID_HUM 3
#define CHILD_ID_TEMP 4
#define CHILD_ID_TEMP 5
// boolean receivedConfig = false;
// boolean metric = true;
MyMessage msgWeight(0, V_WEIGHT);
MyMessage msgWeight_delta(1, V_WEIGHT);
MyMessage msgTemp_sht31(2, V_TEMP);
MyMessage msgHum(3, V_HUM);
MyMessage msgTemp_in(4, V_TEMP);
MyMessage msgTemp_out(5, V_TEMP);
void before()
{
int mode_1;
(mode_1, 1);
Serial.print("MYSENSORS SHT31D Temperature Humidity sensor: ");
// Startup up the SHT31 library
Serial.println(F("Start SHT31"));
if (!sht31.begin(0x44)) {
Serial.println(F("Couldn't find SHT31"));
}
Serial.println("OK");
}
void setup()
{
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.tare();
sensor_out.begin();
sensor_in.begin();
}
void presentation() {
sendSketchInfo("BEECONNECT", "1.0");
present(0, S_WEIGHT);
present(1, S_WEIGHT);
present(2, S_TEMP);
present(3, S_HUM);
present(4, S_TEMP);
present(5, S_TEMP);
}
unsigned int getBatteryCapacity(void)
{
// float voltage = (1023 * VREF) / analogReadReference();
analogReference(INTERNAL);
analogRead(0);
delay(1);
unsigned int adc = analogRead(0);
#ifdef MY_DEBUG
Serial.print("ADC: ");
Serial.println(adc);
#endif
float voltage = adc * VREF / 1023 / 0.248;
#ifdef MY_DEBUG
Serial.print("VCC: ");
Serial.println(voltage, 3);
#endif
for (int i = 0 ; i < ncell ; i++){
#ifdef MY_DEBUG
Serial.print(i);
Serial.print(" : ");
Serial.print(remainingCapacity[i].voltage);
Serial.print(" | ");
Serial.println(remainingCapacity[i].capacity);
#endif
if (voltage > remainingCapacity[i].voltage) {
return remainingCapacity[i].capacity;
}
}
return 0;
}
void readSHT31D(void)
{
static float lastTemperature;
float t2 = sht31.readTemperature();
float h = sht31.readHumidity();
#if COMPARE_TEMP == 1
if (lastTemperature != temperature && !isnan(temperature)) {
#else
if (!isnan(t2)) {
#endif
// Send in the new temperature
send(msgTemp_sht31.set(4).set(t2, 1));
send(msgHum.set(5).set(h, 1));
// Save new temperatures for next compare
lastTemperature = t2;
Serial.print("transmitted temperature OK: ");
Serial.print(t2, 2);
Serial.println("°C");
Serial.print("transmitted humidity OK: ");
Serial.print(h, 2);
Serial.println("%");
delay(10);
}
}
void loop()
{
sensor_out.requestTemperatures();
float t = sensor_out.getTempCByIndex(0);
//float c = 1+(calibration_temperature-sensor_out.getTempCByIndex(0))*0.0021; // Compensation température coeff a déterminer
delay(10);
sensor_in.requestTemperatures();
float i = sensor_in.getTempCByIndex(0);
delay(10);
scale.set_scale(calibration_factor);
//float w = scale.get_units(20)*c; // température compensée
float w = scale.get_units(20); // température non compensée (pour l'étalonnage et la détermination du coeff)
if (isnan(w)) {
Serial.println("Failed to read from HX711 sensor!");
return; }
float d = w - l;
Serial.print("Weight: ");
Serial.println(w);
Serial.print("Temp out: ");
Serial.println(t);
Serial.print("Temp in: ");
Serial.println(i);
delay(10);
readSHT31D();
send(msgWeight.set(w, 1));
send(msgWeight_delta.set(d, 1));
send(msgTemp_in.set(i, 1));
send(msgTemp_out.set(t, 1));
l = w;
scale.power_down();
sleep(SLEEP_TIME);
scale.power_up();
int batteryLevel = getBatteryCapacity();
sendBatteryLevel(batteryLevel);
Serial.print("transmitted battery level OK: ");
Serial.print(batteryLevel);
Serial.println("%");
}