Reading DHT sensor data and SOC with the battery shield

I have a Photon running with the Particle battery shield attached.
Reading the SOC (state-of-charge) of the LiPo threw the shield works totally fine.

When trying to read values from a DHT11 sensor module - a three pin one with a resistor build in - the humidity/temperature values as well as the SOC measurements are garbage (NAN or 255).

The wiring is pretty simple:

  • DHT VCC is attached to Particle D0
  • DHT DATA is attached to Particle D1
  • DHT GND is attached to Particle GND

Removing the VCC wire to the DHT results in correct battery gauge values.
Also not initializing I2C via lipo.begin() leads to correct DHT measurements.

How can I read both SOC and DHT values at the same time? Thanks

#include <Adafruit_DHT.h>
#include <SparkFunMAX17043.h>

const int DHT_POWER = D0;
const int DHT_DATA = D1;    

DHT dht(DHT_DATA, DHT11);

void setupSerial() {
    Serial.begin(9600);
}

void setupDHT() {
    pinMode(DHT_POWER, OUTPUT);
    digitalWrite(DHT_POWER, HIGH);

    pinMode(DHT_DATA, INPUT);
}

void setupLipo() {
    lipo.begin();
}

void setup() {
    setupSerial();
    setupDHT();
    setupLipo();
}

void printMeasurements() {
    Serial.printlnf("humidity: %.2f", dht.getHumidity());
    Serial.printlnf("temperature: %.2f", dht.getTempCelcius());

    lipo.quickStart();  // restarts the MAX17043 chip to get more accurate results for SOC
    Serial.printlnf("battery charge: %.2f", lipo.getSOC());
}

void loop() {
  printMeasurements();
  delay(1000);
}

D0 and D1 are the I2C lines used to communicate with the fuelgauge on the battery shield and can’t be changed.
But you can put the DHT sensor on other pins as it doesn’t use I2C but a proprietory protocol.

2 Likes

Thanks a lot!
The setup works fine using for example D6 and D7.