Powering an SI7021 sensor from a digital pin

Hi all,

I am trying to use an SI7012 I2C sensor in a low power pro mini based sensor node. I am running into troubles trying to power the SI 7021 from a pro mini's digital pin (to save power while sleeping).

If I power the SI7021 from Vcc, the max current I measure is 1.09 mA; the datasheet states 4mA max during startup. And yet I fried two pins on the pro mini (#5 & #6) trying to use them to power the sensor; by that I mean that if I run a dummy sketch that sets pins 5 to 9 to output high, all pins are at 3.3V except the 2 ones I have used to power the sensor which are at 1.41V only.

I will write down the schematics, but as a general question is there any safety measures to take when powering a sensor directly from a digital pin? I could use a transistor of course, but a) I'd rather understand why I should and b) if the setup kills digital pins I guess it may kill the transistor just the same?

Franck

I will write down the schematics, but as a general question is there any safety measures to take when powering a sensor directly from a digital pin?

There is. Don’t. It’s really that simple.

Use the pin to control the gate on a transistor. Transistors need very little current to open or close the gate.

and b) if the setup kills digital pins I guess it may kill the transistor just the same?

You probably killed the digital pin by pulling too much current. 40mA is the maximum recommended. Your measurements seem to indicate that you are drawing less than that, but you haven’t said exactly how you measured the current, so I tend to think that “incorrectly” is the answer.

PaulS: There is. Don't. It's really that simple.

Use the pin to control the gate on a transistor. Transistors need very little current to open or close the gate. You probably killed the digital pin by pulling too much current. 40mA is the maximum recommended. Your measurements seem to indicate that you are drawing less than that, but you haven't said exactly how you measured the current, so I tend to think that "incorrectly" is the answer.

Hmmm, ok. I measured with my digital multimeter that has a "Max" function, there is a delay(1000) right after setting the pin to high to power the sensor, and I have let it go through about 20 cycles.

Also the datasheet claims 4mA absolute max... but sure, I can live with a transistor :)

Franck

Is the sensor on a breakout board? Does the board contain anything other than a bypass capacitor and two pull-up resistors for the I2C bus?

johnwasser:
Is the sensor on a breakout board? Does the board contain anything other than a bypass capacitor and two pull-up resistors for the I2C bus?

Well, good question, what I have is this module:
https://www.ebay.com/itm/New-HTU21D-GY-21-HTU-Temperature-Humidity-Sensor-Breakout-Board-Module-Hot-/271731131299

I found it looking for SI7021, but now I am confused since printed on the board I find SI7021, GY-21, SHT21, and HTU21 :slight_smile:
The SI7021 library gets temperature & humidity just fine though.

Here are the schematics of my circuit, I have an RTC module on the I2C bus along with the sensor:

VMCSensor_schem.png

Franck

So I have an HTU21d, and it is apparently hardware and software compatible with the SI7021 according to this page: [http://www.kandrsmith.org/RJS/Misc/Hygrometers/calib_many.html[/url>

Franck](http://www.kandrsmith.org/RJS/Misc/Hygrometers/calib_many.html)

That breakout board appears to have a voltage regulator and level shifter, probably to make it 5V compatible.

It turns out that could use some help using a transistor to switch the sensor on and off… I am using this schematic:

… and I can’t get readings from the sensor. If I replace the sensor with a led + 220ohms resistor the circuit works as expected, my control pin lights the led on and off.

If I measure the voltage between Vcc and the transistor’s collector (that feeds the GND side of the sensor), I get a stable 3.3V when the control pin (4) is high, but readings between 1 and 3V when the control pin is down. I have tried adding a 220ohm resistor in series with the sensor, same result.

The transistor is a pn2222a, the sensor is the htu21d module mentioned above in the thread… any hint appreciated!

Thanks,
Franck

Solved my problem, the readings at the collector are actually not all over the place but slowly decreasing, I guess a capacitor of the sensor module is simply discharging. And I can get sensor readings after figuring out the right sequence of Wire begin/end and delays to allow the sensor & I2C to wake up.

Franck

So the system works, but each of the SDA and SCL lines draw 0.66 mA while the pro mini is sleeping. I have tried all the pin mode combinations on A4 & A5 with no success. The culprit is probably the level shifting on the module:

"we spun up a breakout board that includes the Filtered version (the white bit of plastic which is a PTFE filter to keep the sensor clean), a 3.3V regulator and I2C level shifting circuitry."

Short of hacking the module it looks like I will need something to disconnect the I2C bus. Apparently an ADuM1250 would work, but the hardware a bit expensive: http://www.analog.com/media/en/technical-documentation/application-notes/AN_913.pdf

Any better solution to use this module in a low power pro mini node?

Franck

I have tried all the pin mode combinations on A4 & A5 with no success.

pinMode() does not affect the analog nature of the pins. pinMode() has no affect on the digital nature of the pins when you use them for I2C.

Going to sleep does not necessarily disable the A2D converter. Going to sleep does not necessarily disable the I2C hardware.

You posted in the Programming section, where one of the requirements is to POST YOUR CODE. Why haven't you? Why should anyone try to help you when YOU can't follow simple rules?

PaulS:
pinMode() does not affect the analog nature of the pins.
pinMode() has no affect on the digital nature of the pins when you use them for I2C.

Going to sleep does not necessarily disable the A2D converter.
Going to sleep does not necessarily disable the I2C hardware.

You posted in the Programming section, where one of the requirements is to POST YOUR CODE. Why haven’t you? Why should anyone try to help you when YOU can’t follow simple rules?

I could swear I had posted this in the “Project Guidance” section, so my mistake (do you get notified if a thread gets moved by a mod?).
That being said if you read my post I don’t have any programming question. If I hook things up like I described I measure “x” mA, and if I pull the SDA cable I read “x-0.66” mA.

I am wondering what kind of circuitry/component/module I could use to programmatically isolate the SDA & SCL lines from the pro mini.

Here is the code if you need it (schematics above, RTC & SD Card are not hooked up):

#include <SI7021.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <LowPower.h>
#define CTRL_PIN 4

void setup() {
  MCUSR = 0;
  wdt_enable(WDTO_8S);
  Serial.begin(9600);
  Serial.println("#### Reset");

  for (uint8_t i = 0; i <= A5; i++) {
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }
  pinMode(CTRL_PIN, OUTPUT);
}

void loop() {
  digitalWrite(CTRL_PIN, HIGH);
  delay(250);
  SI7021 sensor;
  sensor.begin();
  int rawTemp = sensor.getCelsiusHundredths();
  Serial.print("Temp: "); Serial.println(rawTemp); Serial.flush();
  Wire.end();
  digitalWrite(CTRL_PIN, LOW);

  wdt_disable();
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
  wdt_enable(WDTO_4S);

}

Sleep current is 1.31mA, if I unplug either SDA or SCL while in sleep that drops to 0.65mA, and it drops to uAs if I unplug both.

Franck

Edit: and the libraries:

I really don't understand the LowPower library. It claims that PowerDown() is the lowest current consumption mode, but it leaves the I2C circuit active. It has an idle() method that takes an argument to turn the I2C circuit off. That method calls power_twi_disable() which doesn't seem to be defined anywhere.

I had actually missed some pin settings combinations... so here is what works me, but be aware that it goes against the excellent recommendations by Nick Gammon (https://www.gammon.com.au/forum/?id=11497) so use at your own risk.

I get back down to 4.5uA while sleeping by enabling the pullups on the A4 & A5 analog pins (after calling Wire.end() or clearing TWEN in TWCR otherwise this may well have no effect):

    Wire.end();
    digitalWrite(CTRL_PIN, LOW) // power off the sensor
    digitalWrite(SDA, 1);
    digitalWrite(SCL, 1);

    LowPower.powerDown(_sleepTime, ADC_OFF, BOD_OFF);


    digitalWrite(CTRL_PIN, HIGH) // if you powered off your sensor
    Wire.begin();
    delay(250); // let I2C stabilize

Franck

PaulS:
I really don’t understand the LowPower library. It claims that PowerDown() is the lowest current consumption mode, but it leaves the I2C circuit active. It has an idle() method that takes an argument to turn the I2C circuit off. That method calls power_twi_disable() which doesn’t seem to be defined anywhere.

In power.h:
#define power_twi_disable() (PRR |= (uint8_t)(1 << PRTWI))

According to the datasheet:
“Bit 7 – PRTWI0: Power Reduction TWI0
Writing a logic one to this bit shuts down the TWI 0 by stopping the clock to the module.”

… so I don’t know, I will test it but I suspect it won’t set the pins in the right state and my little module will still draw current if I only use that.

Franck

[Edit]: I confirmed that power_twi_disable() in itself doesn’t help with the sleep current. Maybe it helps when used in addition to enabling the pullups on SDA & SCL, but if so that’s in the 1uA range.