-
Notifications
You must be signed in to change notification settings - Fork 0
Testing sketch
Pavel S edited this page May 29, 2021
·
1 revision
Testing sketch for you to test the whole board
#include "mbed.h"
#include "SHTC3.h"
#include "BQ35100.h"
I2C i2c(I2C_SDA, I2C_SCL);
BQ35100 gauge(GAUGE_ENABLE_PIN);
SHTC3 sht;
Wisol wisol(WISOL_TX, WISOL_RX);
int main() {
if (gauge.init(&i2c)) {
debug("Gauge nit OK\n");
} else {
debug("Could not init the gauge\n");
return 0;
}
if (gauge.startGauge()) {
debug("Gauge started\n");
} else {
debug("Could not start the gauge\n");
return 0;
}
if (sht.init(&i2c)) {
debug("SHTC3 init OK\n");
} else {
debug("SHTC3 init failed\n");
return 0;
}
if (!wisol.init()) {
debug("Wisol init failed\n");
return 0;
}
uint8_t data[8];
if (wisol.getId(data)) {
debug("Wisol ID: %02X%02X%02X%02X\n", data[0], data[1], data[2], data[3]);
}
if (wisol.getPac(data)) {
debug("Wisol PAC: %02X%02X%02X%02X%02X%02X%02X%02X\n", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
}
while (1) {
uint16_t data_1, data_2;
int16_t current;
if (sht.read(&data_1, &data_2)) {
float temp = sht.toCelsius(data_1) * 100;
float humidity = sht.toPercentage(data_2) * 100;
// result is actually "°C * 100" and "% * 100"
debug("Temperature: %i*C\nHumidity: %u%%\n", (int16_t)temp, (uint16_t)humidity);
} else {
debug("SHTC3 read failed\n");
}
if (gauge.getVoltage(&data_1)) {
debug("Battery voltage: %umV\n", data_1);
} else {
debug("Failed to read battery voltage\n");
}
if (gauge.getCurrent(¤t)) {
debug("Battery current: %imA\n", current);
} else {
debug("Failed to read battery current\n");
}
if (gauge.getTemperature(&data_1)) {
// result is actually "°C * 100"
debug("Battery temperature: %li*C\n", ((int32_t)data_1 * 10) - 27315);
} else {
debug("Failed to read battery temperature\n");
}
if (gauge.getInternalTemperature(&data_1)) {
// result is actually "°C * 100"
debug("Gauge temperature: %li*C\n", ((int32_t)data_1 * 10) - 27315);
} else {
debug("Failed to read gauge temperature\n");
}
debug("\n");
ThisThread::sleep_for(2s);
}
}
This documentation is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.