ds2438 stuff, vesense+ and - swapped

This commit is contained in:
Empire 2021-02-04 23:52:54 +01:00
parent 6b64fa50a4
commit 268fe0fdc0
6 changed files with 14139 additions and 13932 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,7 @@
#define DS2438_TEMPERATURE_DELAY 10
#define DS2438_VOLTAGE_CONVERSION_DELAY 8
#define DEFAULT_PAGE0 uint8_t[8] { \
#define DEFAULT_PAGE0(var) uint8_t var[8] { \
0b00001011 /* X, ADB=0, NVB=0, TB=0, AD=1, EE=0, CA=1, IAD=1 */, \
0, /* Temperatur */ \
0, /* Temperatur */ \

View File

@ -46,6 +46,8 @@ void DS2438::begin(){
if (validAddress(searchDeviceAddress)) {
if (validFamily(searchDeviceAddress)) {
memcpy(_address,searchDeviceAddress,8);
//DEFAULT_PAGE0(defaultConfig);
//writePage(0, defaultConfig);
deviceFound = true;
}
}
@ -84,9 +86,26 @@ void DS2438::update() {
return;
}
if (!readPage(0, data)){
Serial.println("Error reading zero page ds2438 channel a");
return;
}
Serial.print(data[0],16);
Serial.print(" ");
Serial.print(data[1],16);
Serial.print(" ");
Serial.print(data[2],16);
Serial.print(" ");
Serial.print(data[3],16);
Serial.print(" ");
Serial.print(data[4],16);
Serial.print(" ");
Serial.print(data[5],16);
Serial.print(" ");
Serial.print(data[6],16);
Serial.print(" ");
Serial.println(data[7],16);
if (doTemperature) {
_temperature = (double)(((((int16_t)data[2]) << 8) | (data[1] & 0x0ff)) >> 3) * 0.03125;
@ -116,17 +135,63 @@ void DS2438::update() {
int16_t upperByte = ((int16_t)data[6]) << 8;
int16_t lowerByte = data[5];
int16_t fullByte = (upperByte | lowerByte);
_current = ((float)fullByte) / (4096.0f * _currentShunt);
int16_t fullByte = (int16_t)(upperByte | lowerByte);
float fullByteb = fullByte;
_current = (fullByteb) / ((4096.0f * _currentShunt));
_error = false;
Serial.print(data[0],16);
Serial.print(" ");
Serial.print(data[1],16);
Serial.print(" ");
Serial.print(data[2],16);
Serial.print(" ");
Serial.print(data[3],16);
Serial.print(" ");
Serial.print(data[4],16);
Serial.print(" ");
Serial.print(data[5],16);
Serial.print(" ");
Serial.print(data[6],16);
Serial.print(" ");
Serial.println(data[7],16);
Serial.println("-");
if (!readPage(7, data)){
if (readPage(7, data)){
PageSeven_t *pSeven = (PageSeven_t *) data;
int16_t CCA = pSeven->CCA0 | ((int16_t) pSeven->CCA1) << 8;
int16_t DCA = pSeven->DCA0 | ((int16_t) pSeven->DCA1) << 8;
Serial.printf("DCA: %d. CCA: %d\n", DCA, CCA);
}
if (readPage(1, data)){
PageOne_t *pSeven = (PageOne_t *) data;
Serial.print(data[0],16);
Serial.print(" ");
Serial.print(data[1],16);
Serial.print(" ");
Serial.print(data[2],16);
Serial.print(" ");
Serial.print(data[3],16);
Serial.print(" ");
Serial.print(data[4],16);
Serial.print(" ");
Serial.print(data[5],16);
Serial.print(" ");
Serial.print(data[6],16);
Serial.print(" ");
Serial.println(data[7],16);
Serial.println(pSeven->ICA);
float Ah = pSeven->ICA / (2048.0f * _currentShunt);
Serial.println(Ah);
Serial.println("=");
}
}
double DS2438::getTemperature() {

View File

@ -54,6 +54,8 @@ void print_wakeup_reason(){
}
}
bool whatever = true;
void setAll2Off() {
digitalWrite(OUTPUT_PUMP0, LOW);
digitalWrite(OUTPUT_PUMP1, LOW);
@ -82,7 +84,7 @@ void setup() {
setAll2Off();
Serial.begin(115200);
Serial.begin(9600);
//Increment boot number and print it every reboot
++bootCount;
@ -93,7 +95,7 @@ void setup() {
print_wakeup_reason();
/* activate power pump and pump 0 */
digitalWrite(OUTPUT_PUMP, HIGH);
digitalWrite(OUTPUT_SENSOR, HIGH);
delay(1);
@ -110,7 +112,10 @@ void setup() {
Serial.println("Temp/10");
}
void loop() {
void loop() {
whatever = !whatever;
digitalWrite(OUTPUT_PUMP, whatever?HIGH:LOW);
delay(2000);
digitalWrite(OUTPUT_PUMP0, HIGH);
for(int j=0; j < 5 && temp.getDeviceCount() == 0; j++) {
@ -121,7 +126,7 @@ void loop() {
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();
}

BIN
sheets/DS2438.pdf Normal file

Binary file not shown.