is it better like this?
aDm1N
@aDm1N
Best posts made by aDm1N
Latest posts made by aDm1N
-
RE: Was läuft falsch?What's wrong?
Danke schon mal für die Hilfe.
Thank you in advance for the help.Ich bin jetzt so weit das alle Daten gesendet werden, bis auf die ds18b20. Ich habe die Verkabelung überprüft, kann jedoch keinen Fehler finden. Bin ich Blind? Sieht jemand eventuell einen Fehler in dem Sketch?
I am now so far that all data is sent, except for the ds18b20. I have checked the cabling but can not find a fault. Am I blind? Does anyone see an error in the sketch?
#include <MySensor.h> //ds18b20 & DHT #include <DHT.h> #include <DallasTemperature.h> #include <OneWire.h> // #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) #define CHILD_ID_MOISTURE1 0 #define CHILD_ID_MOISTURE2 1 #define CHILD_ID_MOISTURE3 2 #define CHILD_ID_MOISTURE4 3 //#define CHILD_ID_BATTERY 1 #define SENSOR_ANALOG_PIN 0 #define SENSOR_ANALOG_PIN1 1 #define SENSOR_ANALOG_PIN2 2 #define SENSOR_ANALOG_PIN3 3 #define SENSOR_POWER_PIN 8 //#define SLEEP_TIME 600000 // Sleep time between reads (in milliseconds) (=10 MINUTES) #define STABILIZATION_TIME 300 // Let the sensor stabilize before reading //#define BATTERY_FULL 3700 // 3,700 millivolts //#define BATTERY_ZERO 1700 // 1,700 millivolts //ds18b20 & DHT #define MAX_ATTACHED_DS18B20 6 #define ONE_WIRE_BUS 6 #define DHT1_DATA_PIN 7 #define CHILD_ID_DHT1HUM 6 #define CHILD_ID_DHT1TEMP 7 #define SENSOR_TEMP_OFFSET 0 // Sleep time between sensor updates (in milliseconds) // Must be >1000ms for DHT22 and >2000ms for DHT11 static const uint64_t UPDATE_INTERVAL = 3000; unsigned long SLEEP_TIME = 30000; boolean receivedConfig = false; boolean metric = true; int numSensors=0; OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. MyMessage msgDallas(0,V_TEMP); MyMessage msg6DHT1Temp(CHILD_ID_DHT1TEMP,V_TEMP); MyMessage msg7DHT1Hum(CHILD_ID_DHT1HUM,V_HUM); DHT dht; // MySensor gw; MyMessage msg1(CHILD_ID_MOISTURE1, V_HUM); MyMessage msg2(CHILD_ID_MOISTURE2, V_HUM); MyMessage msg3(CHILD_ID_MOISTURE3, V_HUM); MyMessage msg4(CHILD_ID_MOISTURE4, V_HUM); //MyMessage voltage_msg(CHILD_ID_BATTERY, V_VOLTAGE); int lastsoilValue1 = 0; int lastsoilValue2 = 0; int lastsoilValue3 = 0; int lastsoilValue4 = 0; //ds18b20 & DHT void before() { // Startup up the OneWire library sensors.begin(); } // void setup() { gw.begin(); gw.sendSketchInfo("Bodenfeuchte_Temperatur_Hum", "1.0"); //ds18b20 & DHT // requestTemperatures() will not block current thread sensors.setWaitForConversion(true); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Present all sensors to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) gw.present(i, S_TEMP); gw.present(CHILD_ID_DHT1TEMP,S_TEMP); gw.present(CHILD_ID_DHT1HUM,S_HUM); metric = gw.getConfig().isMetric; // pinMode(SENSOR_POWER_PIN, OUTPUT); gw.present(CHILD_ID_MOISTURE1, S_HUM); gw.present(CHILD_ID_MOISTURE2, S_HUM); gw.present(CHILD_ID_MOISTURE3, S_HUM); gw.present(CHILD_ID_MOISTURE4, S_HUM); delay(250); //gw.present(CHILD_ID_BATTERY, S_CUSTOM); } void loop() { //ds18b20 & DHT // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time and sleep until conversion completed int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) gw.sleep(conversionTime); // Read temperatures and send them to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; // Send in the new temperature gw.send(msgDallas.setSensor(i).set(temperature,1)); //#ifdef MY_DEBUG Serial.print("Dallas"); Serial.print(i); Serial.print(" :"); Serial.println(temperature); //#endif gw.wait(200); // sleep(SLEEP_TIME); } dht.setup(DHT1_DATA_PIN); // set data pin of DHT1 sensor if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) { Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!"); } // Sleep for the time of the minimum sampling period to give the sensor time to power up // (otherwise, timeout errors might occure for the first reading) gw.sleep(dht.getMinimumSamplingPeriod()); // Force reading sensor, so it works also after sleep() // dht.readSensor(false); // Get temperature from DHT library float dht1temperature = dht.getTemperature(); if (isnan(dht1temperature)) { Serial.println("Failed reading temperature from DHT!"); } else if (!metric) { dht1temperature = dht.toFahrenheit(dht1temperature); } dht1temperature += SENSOR_TEMP_OFFSET; gw.send(msg6DHT1Temp.set(dht1temperature, 1)); //#ifdef MY_DEBUG Serial.print("DHT1TEMP: "); Serial.println(dht1temperature); //#endif gw.sleep(UPDATE_INTERVAL); // Get humidity from DHT library float dht1humidity = dht.getHumidity(); if (isnan(dht1humidity)) { Serial.println("Failed reading humidity from DHT"); } else { gw.send(msg7DHT1Hum.set(dht1humidity, 1)); //#ifdef MY_DEBUG Serial.print("DHT1HUM: "); Serial.println(dht1humidity); //#endif } // Sleep for a while to save energy gw.sleep(UPDATE_INTERVAL); //gw.wait(300); //DHT Ende digitalWrite(SENSOR_POWER_PIN, HIGH); // Power on the sensors //gw.wait(500); gw.sleep(STABILIZATION_TIME); //stabilization before mesuring int moistureLevel = (1023 - analogRead(SENSOR_ANALOG_PIN)) / 10.23; // read moisture of the first sensor if (moistureLevel != lastsoilValue1) { //test if moisture is different than before gw.send(msg1.set(moistureLevel)); //send to controller moisture level of sensor 1 lastsoilValue1 = moistureLevel; gw.wait(200); } int moistureLevel1 = (1023 - analogRead(SENSOR_ANALOG_PIN1)) / 10.23; // read moisture of the second sensor if (moistureLevel1 != lastsoilValue2) { //test if moisture is different than before gw.send(msg2.set(moistureLevel1)); //send to controller moisture level of sensor 2 lastsoilValue2 = moistureLevel1; gw.wait(200); } int moistureLevel2 = (1023 - analogRead(SENSOR_ANALOG_PIN2)) / 10.23; // read moisture of the third sensor if (moistureLevel2 != lastsoilValue3) { //test if moisture is different than before gw.send(msg3.set(moistureLevel2)); //send to controller moisture level of sensor 3 lastsoilValue3 = moistureLevel2; gw.wait(200); } int moistureLevel3 = (1023 - analogRead(SENSOR_ANALOG_PIN3)) / 10.23; // read moisture of fourth sensor if (moistureLevel3 != lastsoilValue4) { //test if moisture is different than before gw.send(msg4.set(moistureLevel3)); //send to controller moisture level of sensor 4 lastsoilValue3 = moistureLevel3; gw.wait(200); } //debugging comment it when dont use Serial.print("first plant :"); Serial.println(moistureLevel); Serial.print("second plant :"); Serial.println(moistureLevel1); Serial.print("third plant :"); Serial.println(moistureLevel2); Serial.print("fourth plant :"); Serial.println(moistureLevel3); digitalWrite(SENSOR_POWER_PIN, LOW); //spower off sensors //long voltage = readVcc(); //gw.send(voltage_msg.set(voltage / 1000.0, 3)); // redVcc returns millivolts and set wants volts and how many decimals (3 in our case) //gw.sendBatteryLevel(round((voltage - BATTERY_ZERO) * 100.0 / (BATTERY_FULL - BATTERY_ZERO))); gw.sleep(SLEEP_TIME); } /*long readVcc() { // From http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/ // Read 1.1V reference against AVcc // set the reference to Vcc and the measurement to the internal 1.1V reference #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) ADMUX = _BV(MUX5) | _BV(MUX0); #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) ADMUX = _BV(MUX3) | _BV(MUX2); #else ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #endif delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Start conversion while (bit_is_set(ADCSRA, ADSC)); // measuring uint8_t low = ADCL; // must read ADCL first - it then locks ADCH uint8_t high = ADCH; // unlocks both long result = (high << 8) | low; result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 return result; // Vcc in millivolts }*/```
send: 6-6-1-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
send: 6-6-1-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.4
send: 6-6-1-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:1
read: 0-1-6 s=255,c=3,t=15,pt=6,l=2,sg=0:0100
read: 0-1-6 s=255,c=3,t=6,pt=0,l=1,sg=0:M
sensor started, id=6, parent=1, distance=2
send: 6-6-1-0 s=255,c=3,t=11,pt=0,l=25,sg=0,st=ok:Bodenfeuchte_Temperatur_H
send: 6-6-1-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
send: 6-6-1-0 s=7,c=0,t=6,pt=0,l=0,sg=0,st=ok:
send: 6-6-1-0 s=6,c=0,t=7,pt=0,l=0,sg=0,st=ok:
send: 6-6-1-0 s=0,c=0,t=7,pt=0,l=0,sg=0,st=ok:
send: 6-6-1-0 s=1,c=0,t=7,pt=0,l=0,sg=0,st=ok:
send: 6-6-1-0 s=2,c=0,t=7,pt=0,l=0,sg=0,st=fail:
send: 6-6-1-0 s=3,c=0,t=7,pt=0,l=0,sg=0,st=ok:
send: 6-6-1-0 s=7,c=1,t=0,pt=7,l=5,sg=0,st=ok:18.3
DHT1TEMP: 18.30
send: 6-6-1-0 s=6,c=1,t=1,pt=7,l=5,sg=0,st=ok:25.0
DHT1HUM: 25.00
first plant :0
second plant :0
third plant :0
fourth plant :0 -
Was läuft falsch?What's wrong?
Hallo
HelloIch habe diesen Sketch :
i have this sketch :#include <SPI.h> #include <MySensor.h> //ds18b20 & DHT #include <DHT.h> #include <DallasTemperature.h> #include <OneWire.h> // #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) #define CHILD_ID_MOISTURE1 0 #define CHILD_ID_MOISTURE2 1 #define CHILD_ID_MOISTURE3 2 #define CHILD_ID_MOISTURE4 3 //#define CHILD_ID_BATTERY 1 #define SENSOR_ANALOG_PIN 0 #define SENSOR_ANALOG_PIN1 1 #define SENSOR_ANALOG_PIN2 2 #define SENSOR_ANALOG_PIN3 3 #define SENSOR_POWER_PIN 8 //#define SLEEP_TIME 600000 // Sleep time between reads (in milliseconds) (=10 MINUTES) #define STABILIZATION_TIME 500 // Let the sensor stabilize before reading //#define BATTERY_FULL 3700 // 3,700 millivolts //#define BATTERY_ZERO 1700 // 1,700 millivolts //ds18b20 & DHT #define MAX_ATTACHED_DS18B20 10 #define ONE_WIRE_BUS 6 #define DHT1_DATA_PIN 7 #define CHILD_ID_DHT1HUM 6 #define CHILD_ID_DHT1TEMP 7 #define SENSOR_TEMP_OFFSET 0 // Sleep time between sensor updates (in milliseconds) // Must be >1000ms for DHT22 and >2000ms for DHT11 static const uint64_t UPDATE_INTERVAL = 3000; unsigned long SLEEP_TIME = 30000; boolean receivedConfig = false; boolean metric = true; int numSensors=0; OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. MyMessage msgDallas(0,V_TEMP); MyMessage msg6DHT1Temp(CHILD_ID_DHT1TEMP,V_TEMP); MyMessage msg7DHT1Hum(CHILD_ID_DHT1HUM,V_HUM); DHT dht; // MySensor gw; MyMessage msg1(CHILD_ID_MOISTURE1, V_HUM); MyMessage msg2(CHILD_ID_MOISTURE2, V_HUM); MyMessage msg3(CHILD_ID_MOISTURE3, V_HUM); MyMessage msg4(CHILD_ID_MOISTURE4, V_HUM); //MyMessage voltage_msg(CHILD_ID_BATTERY, V_VOLTAGE); int lastsoilValue1 = 0; int lastsoilValue2 = 0; int lastsoilValue3 = 0; int lastsoilValue4 = 0; //ds18b20 & DHT void before() { // Startup up the OneWire library sensors.begin(); } // void setup() { gw.begin(); //ds18b20 & DHT // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Present all sensors to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) gw.present(i, S_TEMP); gw.present(CHILD_ID_DHT1TEMP,S_TEMP); gw.present(CHILD_ID_DHT1HUM,S_HUM); metric = gw.getConfig().isMetric; // pinMode(SENSOR_POWER_PIN, OUTPUT); gw.sendSketchInfo("Bodenfeuchte, Temperatur und Temp-Hum w bat", "1.0"); gw.present(CHILD_ID_MOISTURE1, S_HUM); gw.present(CHILD_ID_MOISTURE2, S_HUM); gw.present(CHILD_ID_MOISTURE3, S_HUM); gw.present(CHILD_ID_MOISTURE4, S_HUM); //delay(250); //gw.present(CHILD_ID_BATTERY, S_CUSTOM); } void loop() { //ds18b20 & DHT // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time and sleep until conversion completed int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) gw.sleep(conversionTime); // Read temperatures and send them to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; // Send in the new temperature gw.send(msgDallas.setSensor(i).set(temperature,1)); #ifdef MY_DEBUG Serial.print("Dallas"); Serial.print(i); Serial.print(" :"); Serial.println(temperature); #endif // sleep(SLEEP_TIME); } dht.setup(DHT1_DATA_PIN); // set data pin of DHT1 sensor if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) { Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!"); } // Sleep for the time of the minimum sampling period to give the sensor time to power up // (otherwise, timeout errors might occure for the first reading) gw.sleep(dht.getMinimumSamplingPeriod()); // Force reading sensor, so it works also after sleep() //dht.readSensor(true); // Get temperature from DHT library float dht1temperature = dht.getTemperature(); if (isnan(dht1temperature)) { Serial.println("Failed reading temperature from DHT!"); } else if (!metric) { dht1temperature = dht.toFahrenheit(dht1temperature); } dht1temperature += SENSOR_TEMP_OFFSET; gw.send(msg6DHT1Temp.set(dht1temperature, 1)); #ifdef MY_DEBUG Serial.print("DHT1TEMP: "); Serial.println(dht1temperature); #endif gw.sleep(UPDATE_INTERVAL); // Get humidity from DHT library float dht1humidity = dht.getHumidity(); if (isnan(dht1humidity)) { Serial.println("Failed reading humidity from DHT"); } else { gw.send(msg7DHT1Hum.set(dht1humidity, 1)); #ifdef MY_DEBUG Serial.print("DHT1HUM: "); Serial.println(dht1humidity); #endif } // Sleep for a while to save energy gw.sleep(UPDATE_INTERVAL); //DHT Ende digitalWrite(SENSOR_POWER_PIN, HIGH); // Power on the sensors gw.sleep(STABILIZATION_TIME); //stabilization before mesuring int moistureLevel = (1023 - analogRead(SENSOR_ANALOG_PIN)) / 10.23; // read moisture of the first sensor if (moistureLevel != lastsoilValue1) { //test if moisture is different than before gw.send(msg1.set(moistureLevel)); //send to controller moisture level of sensor 1 lastsoilValue1 = moistureLevel; } int moistureLevel1 = (1023 - analogRead(SENSOR_ANALOG_PIN1)) / 10.23; // read moisture of the second sensor if (moistureLevel1 != lastsoilValue2) { //test if moisture is different than before gw.send(msg2.set(moistureLevel1)); //send to controller moisture level of sensor 2 lastsoilValue2 = moistureLevel1; } int moistureLevel2 = (1023 - analogRead(SENSOR_ANALOG_PIN2)) / 10.23; // read moisture of the third sensor if (moistureLevel2 != lastsoilValue3) { //test if moisture is different than before gw.send(msg3.set(moistureLevel2)); //send to controller moisture level of sensor 3 lastsoilValue3 = moistureLevel2; } int moistureLevel3 = (1023 - analogRead(SENSOR_ANALOG_PIN3)) / 10.23; // read moisture of fourth sensor if (moistureLevel3 != lastsoilValue4) { //test if moisture is different than before gw.send(msg4.set(moistureLevel3)); //send to controller moisture level of sensor 4 lastsoilValue3 = moistureLevel3; } //debugging comment it when dont use Serial.print("first plant :"); Serial.println(moistureLevel); Serial.print("second plant :"); Serial.println(moistureLevel1); Serial.print("third plant :"); Serial.println(moistureLevel2); Serial.print("fourth plant :"); Serial.println(moistureLevel3); digitalWrite(SENSOR_POWER_PIN, LOW); //spower off sensors //long voltage = readVcc(); //gw.send(voltage_msg.set(voltage / 1000.0, 3)); // redVcc returns millivolts and set wants volts and how many decimals (3 in our case) //gw.sendBatteryLevel(round((voltage - BATTERY_ZERO) * 100.0 / (BATTERY_FULL - BATTERY_ZERO))); gw.sleep(SLEEP_TIME); } /*long readVcc() { // From http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/ // Read 1.1V reference against AVcc // set the reference to Vcc and the measurement to the internal 1.1V reference #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) ADMUX = _BV(MUX5) | _BV(MUX0); #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) ADMUX = _BV(MUX3) | _BV(MUX2); #else ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #endif delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Start conversion while (bit_is_set(ADCSRA, ADSC)); // measuring uint8_t low = ADCL; // must read ADCL first - it then locks ADCH uint8_t high = ADCH; // unlocks both long result = (high << 8) | low; result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 return result; // Vcc in millivolts }*/
Das ist die ausgabe des Seriellen Monitor :
This is the serial monitor:send: 6-6-1-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0 send: 6-6-1-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=fail:1.5.4 send: 6-6-1-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:1 sensor started, id=6, parent=1, distance=2 send: 6-6-1-0 s=7,c=0,t=6,pt=0,l=0,sg=0,st=ok: send: 6-6-1-0 s=6,c=0,t=7,pt=0,l=0,sg=0,st=ok: send: 6-6-1-0 s=255,c=3,t=11,pt=0,l=25,sg=0,st=ok:Bodenfeuchte, Temperatur send: 6-6-1-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0 send: 6-6-1-0 s=0,c=0,t=7,pt=0,l=0,sg=0,st=ok: send: 6-6-1-0 s=1,c=0,t=7,pt=0,l=0,sg=0,st=ok: send: 6-6-1-0 s=2,c=0,t=7,pt=0,l=0,sg=0,st=fail: send: 6-6-1-0 s=3,c=0,t=7,pt=0,l=0,sg=0,st=ok: send: 6-6-1-0 s=7,c=1,t=0,pt=7,l=5,sg=0,st=ok:18.8 send: 6-6-1-0 s=6,c=1,t=1,pt=7,l=5,sg=0,st=ok:25.2 send: 6-6-1-0 s=0,c=1,t=1,pt=2,l=2,sg=0,st=fail:86 send: 6-6-1-0 s=1,c=1,t=1,pt=2,l=2,sg=0,st=fail:86 send: 6-6-1-0 s=2,c=1,t=1,pt=2,l=2,sg=0,st=fail:86 send: 6-6-1-0 s=3,c=1,t=1,pt=2,l=2,sg=0,st=fail:86 first plant :86 second plant :86 third plant :86 fourth plant :86
Das ist der Verdrarungsplan dazu :
This is the wiring : -
RE: 12v Solar battery monitor
Hallo
Mein Englisch ist nicht so gut.
Ich habe versucht das Projekt nach zu bauen. Den Button brauche ich (denke ich) nicht, dafür habe ich das script jedoch um 2 weitere current und voltage Sensoren erweitert. Das Ziel ist 3 mal Current und 3 mal Volt als Ergebnis zu bekommen. Ich habe 30A Sensoren und einen 30A Laderegler. Dazwischen sind jeweils 30A Sicherungen.
Leider kommt in Domoticz aber nur ein mal Volt und 2 mal Current an. Leider habe ich auch nicht wirklich viel Ahnung vom Programmieren. Könnte hier mal jemand über den Sketch gucken um zu sehen ob ich einen Fehler darin habe?/*Sketch for a MySensor node to monitor a 12v battery with a solar panel for charging * The node monitors battery voltage,current into and out of the battery, ambient temperature and battery temperature. * 2 x DS18b20 dallas temperature ic's their data pins connected to arduino digital pin 3 * 1 x ACS712 current sensor module connected to arduino analog pin A4 * 1 x 25v voltage sensor module connected to arduino analog pin A0 * 1 x nRF24L01+ 2.4ghz tranceiver connected as per the MySensors web site. * 1 x LED connected via a 330 ohm resistor to pin 6 * 1 x push button connected to pin 5 */ #include <MySensor.h> #include <SPI.h> #include <OneWire.h> #include <DallasTemperature.h> #define ONE_WIRE_BUS 3 // Ds18b20 data wire is connected to digital pin 3 on the Arduino #define ID_S_TEMPA 0 // First temp device #define ID_S_TEMPB 1 // second temp device #define ID_S_MULTIMETERV1 3 // Multimeter device for voltage measurement #define ID_S_MULTIMETERC1 4 // Multimeter device for positive current measurement #define ID_S_MULTIMETERC11 5 // Multimeter device for negative current measurement #define ID_S_MULTIMETERV2 3 // Multimeter device for voltage measurement #define ID_S_MULTIMETERC2 4 // Multimeter device for positive current measurement #define ID_S_MULTIMETERC12 5 // Multimeter device for negative current measurement #define ID_S_MULTIMETERV3 6 // Multimeter device for voltage measurement #define ID_S_MULTIMETERC3 7 // Multimeter device for positive current measurement #define ID_S_MULTIMETERC13 8 #define NUM_SAMPLES 10 // number of analog voltage samples to take per reading int ledPin = 6; // the pin for the LED int buttonPin = 5; // the input pin for offset pushbutton int buttonState = 0; // variable for reading the pin status unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) int lastmilli1 = 25000; // set to an arbitary number outside of expected current sensor range to ensure a change when first run int lastmilli2 = 25000; // set to an arbitary number outside of expected current sensor range to ensure a change when first run int lastmilli3 = 25000; // set to an arbitary number outside of expected current sensor range to ensure a change when first run float sensitivity = 66 ; //change this to 185 for ACS712-5 or to 100 for ACS712-20A or to 66 for ACS712-30A int VQ = 0; //Placeholder for quiescent voltage calculations int ACSPin1 = A4; // Analog pin number the ACS712 data pin connects to int ACSPin2 = A5; // Analog pin number the ACS712 data pin connects to int ACSPin3 = A3; // Analog pin number the ACS712 data pin connects to float lastTemperature[2]; //Array to hold the last temp readings sent to gateway, only send new data if different int sum = 0; // sum of voltage samples taken unsigned char sample_count = 0; // current sample number int lastVoltage1 = 30000; // set to an arbitary number outside of expected voltage sensor range to ensure a change when first run int lastVoltage2 = 30000; // set to an arbitary number outside of expected voltage sensor range to ensure a change when first run int lastVoltage3 = 30000; // set to an arbitary number outside of expected voltage sensor range to ensure a change when first run int voltagePin1 = A0; // analog pin voltage sensor or voltage divider is connected to int voltagePin2 = A1; // analog pin voltage sensor or voltage divider is connected to int voltagePin3 = A2; // analog pin voltage sensor or voltage divider is connected to int voltSense1Max = 25000; // set to the maximum input voltage in millivolts of your voltage divider input int voltSense2Max = 25000; // set to the maximum input voltage in millivolts of your voltage divider input int voltSense3Max = 25000; // set to the maximum input voltage in millivolts of your voltage divider input OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature. MySensor gw; // ------ Initialize messages ------- MyMessage msg(0,V_TEMP); MyMessage msg_S_MULTIMETERv1(ID_S_MULTIMETERV1,V_VOLTAGE); MyMessage msg_S_MULTIMETERc1(ID_S_MULTIMETERC1,V_CURRENT); MyMessage msg_S_MULTIMETERc11(ID_S_MULTIMETERC11,V_CURRENT); MyMessage msg_S_MULTIMETERv2(ID_S_MULTIMETERV2,V_VOLTAGE); MyMessage msg_S_MULTIMETERc2(ID_S_MULTIMETERC2,V_CURRENT); MyMessage msg_S_MULTIMETERc12(ID_S_MULTIMETERC12,V_CURRENT); MyMessage msg_S_MULTIMETERv3(ID_S_MULTIMETERV3,V_VOLTAGE); MyMessage msg_S_MULTIMETERc3(ID_S_MULTIMETERC3,V_CURRENT); MyMessage msg_S_MULTIMETERc13(ID_S_MULTIMETERC13,V_CURRENT); void setup() { sensors.begin(); // Start up the onewire library gw.begin(); // Startup and initialize MySensors library. Set callback for incoming messages. gw.sendSketchInfo("Battery Status Sensor", "1"); // Send the sketch version information to the gateway and Controller // ------ Present all sensors to controller ------ gw.present(ID_S_TEMPA, S_TEMP); gw.present(ID_S_TEMPB, S_TEMP); gw.present(ID_S_MULTIMETERV1,V_VOLTAGE); gw.present(ID_S_MULTIMETERC1,V_CURRENT); gw.present(ID_S_MULTIMETERC11,V_CURRENT); gw.present(ID_S_MULTIMETERV2,V_VOLTAGE); gw.present(ID_S_MULTIMETERC2,V_CURRENT); gw.present(ID_S_MULTIMETERC12,V_CURRENT); gw.present(ID_S_MULTIMETERV3,V_VOLTAGE); gw.present(ID_S_MULTIMETERC3,V_CURRENT); gw.present(ID_S_MULTIMETERC13,V_CURRENT); pinMode(buttonPin, INPUT_PULLUP); // Set buttonPin as input and turn on internal pull up resistor pinMode(ledPin, OUTPUT); // Set ledPin as output digitalWrite(ledPin, LOW); // Make sure ledPin is off // ------ load offset for current sensor int validCheck = gw.loadState(0); if (validCheck == 120){ // check to see if valid data exists VQ = gw.loadState(1); // Load count offset into VQ // Serial.print(" positive VQ offset loaded..."); Serial.println(VQ); } else if (validCheck == 125) { VQ = -abs(gw.loadState(1)); // Serial.print(" negative VQ offset loaded..."); Serial.println(VQ); } else { // Serial.println("VQ offset not set"); } delay(500); } void loop() { buttonState = digitalRead(buttonPin); //Serial.print("buttonstate..."); Serial.println(buttonState); if (buttonState == LOW) { VQ = determineVQ(ACSPin1); //Returns the offset count needed to show zero with no load if (VQ >= 0 && VQ < 255) { //check for valid data. VQ is positive number gw.saveState(0, 120); // Store 120 value in eeprom position 0. use this to check for valid data at boot gw.saveState(1, VQ); // Store offset count in eeprom. in case of re-boot } else if (VQ < 0 && VQ > -255) { // VQ is a negative number. negatives cannot be stored in eeprom gw.saveState(0, 125); // Store 125 value in eeprom position 0. use this to check for valid data at boot gw.saveState(1, abs(VQ)); // convert VQ to positive and Store offset count in eeprom. in case of re-boot } } // ------------------ Start voltage 1 readings -------------------- sample_count = 0; sum = 0; while (sample_count < NUM_SAMPLES) { // take a number of voltage samples sum += analogRead(voltagePin1); sample_count++; delay(10); } //Serial.print("sum count..."); Serial.println((sum / NUM_SAMPLES)); // print the count result. will be between 0 and 1023 int voltage1I = map(sum/NUM_SAMPLES,0,1023,0,voltSense1Max); // map the reading and get our result in millivolts //Serial.print("mapped volts..."); Serial.println(voltageI / 1000.0, 1); // convert millivolts back to volts and print. the 1 at the end determines how many decimal places to show if ( voltage1I != lastVoltage1) { // check if we have a new value. only send data if it is different gw.send(msg_S_MULTIMETERv1.set(voltage1I / 1000.0, 1)); // voltagel is in millivolts so we divide by 1000 to convert back to volts and // send voltage message to gateway with 1 decimal place lastVoltage1 = voltage1I; // copy the current voltage reading for testing on the next loop } //--------------------Start Current 1 readings--------------------------------- int milli1 = readCurrent(ACSPin1); // take a reading from the ACS712 and send to the readcurrent function //Serial.print("Milliamps..."); Serial.println(milli); // print the value (in milliamps) returned if ( milli1 != lastmilli1) // check if value has changed { if ( milli1 > 0) // Battery is charging { gw.send(msg_S_MULTIMETERc1.set(milli1/1000.0, 1)); // Send new data to charging amp device gw.send(msg_S_MULTIMETERc11.set(0)); // set the dis-charging amp device to zero lastmilli1 = milli1; } else if (milli1 < 0) // Battery is discharging { gw.send(msg_S_MULTIMETERc1.set(0)); // set the charging amp device to zero gw.send(msg_S_MULTIMETERc11.set(abs(milli1)/1000.0, 1)); // use abs(milli) to Send a positive number to dis-charging amp device lastmilli1 = milli1; } else // No current flowing, set both to zero { gw.send(msg_S_MULTIMETERc1.set(0)); gw.send(msg_S_MULTIMETERc11.set(0)); lastmilli1 = milli1; } } //----------------------Teperature readings start------------------------ Serial.println(" Requesting temperatures..."); // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // call sensors.requestTemperatures() to issue a global temperature request to all devices on the bus // ------- query conversion time and sleep until conversion completed ------ int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); gw.sleep(conversionTime); for (int i=0; i<2; i++) { // Serial.print("Temperature for Device: ");Serial.print(i);Serial.print(" is: "); // Serial.println(sensors.getTempCByIndex(i)); // Why "byIndex"? // You can have more than one IC on the same bus. // 0 refers to the first IC on the wire float temperature = static_cast<float>(static_cast<int>((sensors.getTempCByIndex(i)) * 10.)) / 10.; // Fetch and round temperature to one decimal in celcius if (lastTemperature[i] != temperature) // check for a changed temperature reading { gw.send(msg.setSensor(i).set(temperature,1)); // Send in the new temperature lastTemperature[i]=temperature; // Save new temperatures for next compare } } // ------------------ Start 2 voltage readings -------------------- sample_count = 0; sum = 0; while (sample_count < NUM_SAMPLES) { // take a number of voltage samples sum += analogRead(voltagePin2); sample_count++; delay(10); } //Serial.print("sum count..."); Serial.println((sum / NUM_SAMPLES)); // print the count result. will be between 0 and 1023 int voltage2I = map(sum/NUM_SAMPLES,0,1023,0,voltSense2Max); // map the reading and get our result in millivolts //Serial.print("mapped volts..."); Serial.println(voltageI / 1000.0, 1); // convert millivolts back to volts and print. the 1 at the end determines how many decimal places to show if ( voltage2I != lastVoltage2) { // check if we have a new value. only send data if it is different gw.send(msg_S_MULTIMETERv2.set(voltage2I / 1000.0, 1)); // voltagel is in millivolts so we divide by 1000 to convert back to volts and // send voltage message to gateway with 1 decimal place lastVoltage2 = voltage2I; // copy the current voltage reading for testing on the next loop } //--------------------Start Current 2 readings--------------------------------- int milli2 = readCurrent(ACSPin2); // take a reading from the ACS712 and send to the readcurrent function //Serial.print("Milliamps..."); Serial.println(milli); // print the value (in milliamps) returned if ( milli2 != lastmilli2) // check if value has changed { if ( milli2 > 0) // Battery is charging { gw.send(msg_S_MULTIMETERc2.set(milli2/1000.0, 1)); // Send new data to charging amp device gw.send(msg_S_MULTIMETERc12.set(0)); // set the dis-charging amp device to zero lastmilli2 = milli2; } else if (milli1 < 0) // Battery is discharging { gw.send(msg_S_MULTIMETERc2.set(0)); // set the charging amp device to zero gw.send(msg_S_MULTIMETERc12.set(abs(milli2)/1000.0, 1)); // use abs(milli) to Send a positive number to dis-charging amp device lastmilli2 = milli2; } else // No current flowing, set both to zero { gw.send(msg_S_MULTIMETERc2.set(0)); gw.send(msg_S_MULTIMETERc12.set(0)); lastmilli2 = milli2; } } // ------------------ Start voltage 3 readings -------------------- sample_count = 0; sum = 0; while (sample_count < NUM_SAMPLES) { // take a number of voltage samples sum += analogRead(voltagePin3); sample_count++; delay(10); } //Serial.print("sum count..."); Serial.println((sum / NUM_SAMPLES)); // print the count result. will be between 0 and 1023 int voltage3I = map(sum/NUM_SAMPLES,0,1023,0,voltSense3Max); // map the reading and get our result in millivolts //Serial.print("mapped volts..."); Serial.println(voltageI / 1000.0, 1); // convert millivolts back to volts and print. the 1 at the end determines how many decimal places to show if ( voltage3I != lastVoltage3) { // check if we have a new value. only send data if it is different gw.send(msg_S_MULTIMETERv3.set(voltage3I / 1000.0, 1)); // voltagel is in millivolts so we divide by 1000 to convert back to volts and // send voltage message to gateway with 1 decimal place lastVoltage3 = voltage3I; // copy the current voltage reading for testing on the next loop } //--------------------Start Current 3 readings--------------------------------- int milli3 = readCurrent(ACSPin3); // take a reading from the ACS712 and send to the readcurrent function //Serial.print("Milliamps..."); Serial.println(milli); // print the value (in milliamps) returned if ( milli3 != lastmilli3) // check if value has changed { if ( milli3 > 0) // Battery is charging { gw.send(msg_S_MULTIMETERc3.set(milli3/1000.0, 1)); // Send new data to charging amp device gw.send(msg_S_MULTIMETERc13.set(0)); // set the dis-charging amp device to zero lastmilli3 = milli3; } else if (milli3 < 0) // Battery is discharging { gw.send(msg_S_MULTIMETERc3.set(0)); // set the charging amp device to zero gw.send(msg_S_MULTIMETERc13.set(abs(milli3)/1000.0, 1)); // use abs(milli) to Send a positive number to dis-charging amp device lastmilli3 = milli3; } else // No current flowing, set both to zero { gw.send(msg_S_MULTIMETERc3.set(0)); gw.send(msg_S_MULTIMETERc13.set(0)); lastmilli3 = milli3; } } gw.sleep(SLEEP_TIME); } /*-------------- Function to get the offset required for ACS712 to show zero with no current flowing -----------------*/ int determineVQ(int PIN) { digitalWrite(ledPin, HIGH); // Turn on LED to indicate offset being calculated delay(500); // Delay to hold LED on digitalWrite(ledPin, LOW); // Turn off LED delay(150); // Delay to let readings stabilise // Serial.print("estimating avg. quiscent voltage:"); long acsCount = 0; for (int i=0; i<5000; i++) //read 5000 samples to stabilise value { acsCount += analogRead(PIN); // read the count value between 0 and 1023 and add it to acsCount delay(1); } acsCount /= 5000; // acsCount now eaquals the average of the 5000 readings taken // Serial.print(map(acsCount, 0, 1023, 0, 5000));Serial.println(" mV"); //Print the avg in millivolts // Serial.print("acsCount:");Serial.println(acsCount); //Print the actual count value return int(acsCount - 512); // return the count difference. 512 is the count for 2.5v which is what the reading should be with no current flow } /*--------------- Function to read current flowing ------------------*/ int readCurrent(int PIN) { int count = 0; for (int i=0; i<5; i++) //read 5 analog count samples to stabilise value { count += analogRead(PIN) - VQ; //subtract the offset count VQ to improve accuracy delay(1); // Serial.print("raw count..."); Serial.println(count); } /* Notes on the conversion below * .00488 is the volt value per count of the arduino adc. The analog pin measures from 0 to 5 volt and then assigns the result to * a count from 0 to 1023, thats 1024 counts including zero. If we devide 5v by 1024 we get .oo488 volts for each count. * * The (count/5) just gets us the average of our 5 count samples. * * So after the first part of the equation (.00488 * (count/5) is complete we have converted our count reading into volts. * * The ACS712 can measure current flow in both directions so it outputs a voltage of 2.5v as it's center point (when no current is flowing). * To allow for this offset we must subtract the 2.5v to center our voltage reading. * * Thats what the next part does (.00488 * (count/5)) - 2.5) After this is complete we are left with either a negative or positive voltage * reading or a reading of zero for no current flow. * * NOTE: While the ACS712 is a 5v device it does not use the full 0 to 5v for it's output. The datasheet shows the 20A version has a sensitivity of * 100mv per amp, so if we multiply 100mv by 20 we get 2v. That means the 20A ACS712 has an output range from .5v to 4.5v. * * So to convert our reading in volts to a reading in amps we need to add the last part ((.00488 * (count/5)) - 2.5)/(sensitivity/1000). * The variable sensitivity is defined at the begining of the sketch and holds the ACS712 sensitvity amount, it is stored in millivolts. * That is 66mv for the 30amp, 100mv for the 20amp and 185mv for the 5amp. As sensitivity is in millivolts we need to devide it by 1000 * to convert it back to volts so we can use it in the equation. * * Now we have our Amps value stored in the float amps. Integers are much easier to work with when checking for zero so we multiply by 1000 * to convert it to milliamps and return it as an integer. */ //Serial.print("VQ = ..."); Serial.println(VQ); //Serial.print("current count..."); Serial.println(count/5); //Serial.print("map milliamps..."); Serial.println(map((count/5), 102, 922, -20000, 20000)); float amps = ((.00488 * (count/5)) - 2.5) / (sensitivity/1000); // Serial.print("float amps..."); Serial.println(amps, 1); return int (amps * 1000); // convert to milliamps and return as an integer } Insert Code Here
English:
Hello
My English is not that good.
I tried to build the project. The button I need (I think) not, but I have extended the script, however, by 2 more current and voltage sensors. The goal is to get 3 times Current and 3 times Volt as a result. I have 30A sensors and a 30A charger. In between are 30A fuses.
Unfortunately in Domoticz but only one time Volt and 2 times Current. Unfortunately I have not really much idea of the programming. Could someone here over the sketch look around to see if I have a mistake in it?do i