I understood how the Vext works. After pinMode(Vext, OUTPUT); digitalWrite(Vext, HIGH); we get 3.4 Volts on the pin #6 in the middle of the board. After digitalWrite(Vext, LOW); it is back to 0 V.
The BME280 works fine from the Vext pin. It seems there is enough current for this sensor on this pin.
Now I am trying to use the Vext together with the BME280 and the LowPower_Handler();
BME280 makes measurements once, but then it does not wake up for some reason. And I cannot find a soluton for this. I want that after the wakeup the sensor makes the new measurements.
Here is my code:
#include “BME280.h”
#include <Wire.h>
#include “Arduino.h”
#define timetosleep 15000
#define timetowake 20000
static TimerEvent_t sleep;
static TimerEvent_t wakeup;
uint8_t lowpower = 1;
unsigned long time_now = 0;
BME280 bme280;
void OnSleep()
{
Serial.printf(“into lowpower mode, %d ms later wake up.\r\n”, timetowake);
lowpower = 1;
//timetosleep ms later wake up;
TimerSetValue( &wakeup, timetowake );
TimerStart( &wakeup );
}
void OnWakeup()
{
Serial.printf(“wake up, %d ms later into lowpower mode.\r\n”, timetosleep);
lowpower = 0;
//timetosleep ms later into lowpower mode;
TimerSetValue( &sleep, timetosleep );
TimerStart( &sleep );
}
void setup()
{
Serial.begin(115200);
BoardInitMcu();
Radio.Sleep( );
pinMode(Vext, OUTPUT);
digitalWrite(Vext, HIGH);
if (!bme280.init()) {
Serial.println(“Device error!”);
}
time_now = millis();
while (millis() < time_now + 500) {
}
TimerInit( &sleep, OnSleep );
TimerInit( &wakeup, OnWakeup );
OnWakeup();
}
void loop()
{
if (lowpower) {
digitalWrite(Vext, LOW);
time_now = millis();
while (millis() < time_now + 1000) {
}
//note that LowPower_Handler() run six times the mcu into lowpower mode;
LowPower_Handler();
time_now = millis();
while (millis() < time_now + 1000) {
}
} else {
digitalWrite(Vext, HIGH);
time_now = millis();
while (millis() < time_now + 2000) {
}
float pressure;
//get and print temperatures
Serial.print("Temp: ");
Serial.print(bme280.getTemperature());
Serial.println("C");//The unit for Celsius because original arduino don't support speical symbols
//get and print atmospheric pressure data
Serial.print("Pressure: ");
Serial.print(pressure = bme280.getPressure());
Serial.println("Pa");
//get and print altitude data
Serial.print("Altitude: ");
Serial.print(bme280.calcAltitude(pressure));
Serial.println("m");
//get and print humidity data
Serial.print("Humidity: ");
Serial.print(bme280.getHumidity());
Serial.println("%");
time_now = millis();
while (millis() < time_now + 2000) {
}
}
}