current sensorfixes
This commit is contained in:
parent
d4ccab6ea5
commit
653d962cdf
@ -44,13 +44,14 @@ typedef uint8_t DeviceAddress[8];
|
|||||||
|
|
||||||
class DS2438 {
|
class DS2438 {
|
||||||
public:
|
public:
|
||||||
DS2438(OneWire *ow);
|
DS2438(OneWire *ow, float currentShunt);
|
||||||
DS2438(OneWire *ow, uint8_t *address);
|
DS2438(OneWire *ow, uint8_t *address);
|
||||||
|
|
||||||
void begin();
|
void begin();
|
||||||
void update();
|
void update();
|
||||||
double getTemperature();
|
double getTemperature();
|
||||||
float getVoltage(int channel=DS2438_CHA);
|
float getVoltage(int channel=DS2438_CHA);
|
||||||
|
float getCurrent();
|
||||||
boolean isError();
|
boolean isError();
|
||||||
boolean isFound();
|
boolean isFound();
|
||||||
private:
|
private:
|
||||||
@ -64,6 +65,8 @@ class DS2438 {
|
|||||||
double _temperature;
|
double _temperature;
|
||||||
float _voltageA;
|
float _voltageA;
|
||||||
float _voltageB;
|
float _voltageB;
|
||||||
|
float _current;
|
||||||
|
float _currentShunt;
|
||||||
boolean _error;
|
boolean _error;
|
||||||
boolean startConversion(int channel, boolean doTemperature);
|
boolean startConversion(int channel, boolean doTemperature);
|
||||||
boolean selectChannel(int channel);
|
boolean selectChannel(int channel);
|
||||||
|
@ -24,8 +24,9 @@
|
|||||||
|
|
||||||
#define DS2438MODEL 0x26
|
#define DS2438MODEL 0x26
|
||||||
|
|
||||||
DS2438::DS2438(OneWire *ow) {
|
DS2438::DS2438(OneWire *ow, float currentShunt = 1.0f) {
|
||||||
_ow = ow;
|
_ow = ow;
|
||||||
|
_currentShunt = currentShunt;
|
||||||
};
|
};
|
||||||
|
|
||||||
void DS2438::begin(){
|
void DS2438::begin(){
|
||||||
@ -112,6 +113,11 @@ void DS2438::update() {
|
|||||||
}
|
}
|
||||||
_voltageB = (((data[4] << 8) & 0x00300) | (data[3] & 0x0ff)) / 100.0;
|
_voltageB = (((data[4] << 8) & 0x00300) | (data[3] & 0x0ff)) / 100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t upperByte = ((int16_t)data[6]) << 8;
|
||||||
|
int16_t lowerByte = data[5];
|
||||||
|
int16_t fullByte = (upperByte | lowerByte);
|
||||||
|
_current = ((float)fullByte) / (4096.0f * _currentShunt);
|
||||||
_error = false;
|
_error = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,6 +135,10 @@ float DS2438::getVoltage(int channel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float DS2438::getCurrent() {
|
||||||
|
return _current;
|
||||||
|
}
|
||||||
|
|
||||||
boolean DS2438::isError() {
|
boolean DS2438::isError() {
|
||||||
return _error;
|
return _error;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ int secondBootCount = 0;
|
|||||||
|
|
||||||
OneWire oneWire(SENSOR_DS18B20);
|
OneWire oneWire(SENSOR_DS18B20);
|
||||||
DallasTemperature temp(&oneWire);
|
DallasTemperature temp(&oneWire);
|
||||||
DS2438 battery(&oneWire);
|
DS2438 battery(&oneWire,0.1f);
|
||||||
|
|
||||||
|
|
||||||
void print_wakeup_reason(){
|
void print_wakeup_reason(){
|
||||||
@ -100,21 +100,28 @@ void setup() {
|
|||||||
|
|
||||||
temp.begin();
|
temp.begin();
|
||||||
battery.begin();
|
battery.begin();
|
||||||
|
|
||||||
|
Serial.print("Battery");
|
||||||
|
Serial.print("\t");
|
||||||
|
Serial.print("Solar");
|
||||||
|
Serial.print("\t");
|
||||||
|
Serial.print("Bat I");
|
||||||
|
Serial.print("\t");
|
||||||
|
Serial.println("Temp/10");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
delay(200);
|
|
||||||
digitalWrite(OUTPUT_PUMP0, HIGH);
|
digitalWrite(OUTPUT_PUMP0, HIGH);
|
||||||
|
|
||||||
for(int j=0; j < 5 && temp.getDeviceCount() == 0; j++) {
|
for(int j=0; j < 5 && temp.getDeviceCount() == 0; j++) {
|
||||||
delay(10);
|
delay(10);
|
||||||
Serial.println("Reset 1wire temp");
|
// Serial.println("Reset 1wire temp");
|
||||||
temp.begin();
|
temp.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int j=0; j < 5 && (0 == battery.isFound()); j++) {
|
for(int j=0; j < 5 && (0 == battery.isFound()); j++) {
|
||||||
delay(10);
|
delay(10);
|
||||||
Serial.println("Reset 1wire bat");
|
// Serial.println("Reset 1wire bat");
|
||||||
battery.begin();
|
battery.begin();
|
||||||
battery.update();
|
battery.update();
|
||||||
}
|
}
|
||||||
@ -123,5 +130,7 @@ void loop() {
|
|||||||
Serial.print("\t");
|
Serial.print("\t");
|
||||||
Serial.print(battery.getVoltage(1));
|
Serial.print(battery.getVoltage(1));
|
||||||
Serial.print("\t");
|
Serial.print("\t");
|
||||||
Serial.println(battery.getTemperature());
|
Serial.print(battery.getCurrent());
|
||||||
|
Serial.print("\t");
|
||||||
|
Serial.println(battery.getTemperature()/10);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user