cubecell and IIC sensors powered by Vext issue

 

http://community.heltec.cn/t/cubecell-vext-with-i2c-sensors/886/2

Testing on IIC sensor such as BME280/BMP280 and DH1750, and controlled by Vext, it seems there is a problem on IIC bus when power back the Vext.

The dirty solution is to add     Wire.begin(); and Wire.end();

so my structure is like this:(power related in red, IIC in green, sensors in blue)

  pinMode(Vext, OUTPUT);

  digitalWrite(Vext, LOW);

  delay(200);

 Wire.begin();

  if (!bme280.init()) {

    Serial.println("bme280 error!");

  }

  delay(100);

  temperature = bme280.getTemperature();

  pressure =  bme280.getPressure() / 100;

  humidity = bme280.getHumidity();

  if(lightMeter.begin()){

  Serial.println(F("BH1750 inited"));

  }

delay(100);// critical to get reading, but the first reading is always 0

  float lux = lightMeter.readLightLevel(true);

    Serial.print("Light: ");

  Serial.print(lux);

  Serial.println(" lx");

  Wire.end();

    digitalWrite(Vext, HIGH);// turn off the Vext

It still get me a strange behave on DH1750, no matter what delay I added(tested 5sec), the first reading after reset is always 0




留言

這個網誌中的熱門文章

GeoSetter how to add geotag on to pictures, and export to google earth as kmz

VESC hall sensor table and use it to add hall sensors to RC sensorless motor, then nake it work with RC sensored ESC

Meshtastic 03 adding GPS on TTGO lora32 V2