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