Showing posts with label BMP180. Show all posts
Showing posts with label BMP180. Show all posts

Sunday, July 23, 2017

18650 Li-Ion battery powered Wemos D1 with Wemos Battery Shield - DONE 48 days achieved

>>> For the version with a solar panel attached see this post <<<

Wemos has developed a series of shields for the Wemos D1 :

  • DHT Shield
  • Battery Shield
  • Matrix LED Shield
  • Buzzer Shield
  • Dual Base
  • SHT30 Shield
  • WS2812B RGB Shield
  • ProtoBoard Shield
  • 1-Button Shield
  • Micro SD Card Shield
  • Relay Shield
  • DC Power Shield
  • Tripler Base
  • Motor Shield
  • OLED Shield

The good thing is that you can stack them on top of another.

Let's take a look for now to the Battery Shield that is now on version 1.2.0 and it has a retired version 1.1.0

Get the schematics from here version 1.1.0 and 1.2.0 to see the differences. An immediate visual difference is the inductor on the V1.1.0 is much higher than the one on V1.2.0 but is not all.

Battery Shield V1.1.0


Since I didn't found yet the version 1.2.0, I used the V1.1.0 from here. and the Wemos D1 mini from here. I've also added an BMP180 pressure and temperature sensor.

Characteristics:

  • Charging Voltage: max: 10V, recommend: 5V
  • Charging Current: max: 1A
  • Lithium Battery voltage: 3.3-4.2V
  • Boost Power Supply: 5V(max: 1A)

 Connections between the Wemos D1 mini and Battery shield:

D1 mini Shield
5V         5V(max: 1A) Power Supply
GND GND
A0           Vbat f the jumper J2 is closed.


Now for the battery. Since I didn't find a decent LiIon flat battery on a good price I had to improvise and I've dismounted a EUR 5 Innergie 2600mA power bank.


Original Power Bank

I have disassembled the power bank and I've get the battery from it.

Samsung 18650 Li-Ion battery. Nice !!!

Then I've added the battery to this EUR 1 battery holder from tinytronics.nl.

Battery is charging 


I've connected the Battery Shield's miniUSB to 5V to charge the battery and the red LED start to light. When the battery was charged the LED red turned off and LED green turned ON signaling that the charging is done.  After I've removed the USB cable from the Battery Shield the green LED turned off not to consume from battery. At this moment I've added the BMP180 and flash the firmware.


BE AWARE OF SHORTING THE BATTERY WIRES. ALWAYS DOUBLE CHECK THEM..

This is happening when the battery is shorted. Don't try it at home. This was done so you not have to try it.

Melted wires and battery holder.



To log the battery level I've used again the good service offered by the thingspeak.com and log
the A0 value, a computed voltage which is not accurate at this time since I didn't had a voltmeter with me to do it.

#include <ESP8266WiFi.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>

Adafruit_BMP085 bmp;

unsigned int raw=0;
float volt=0.0;
String apiKey = "YOUR_THINGSPEAK_API_KEY";

void setup() {
  Serial.begin(115200);
  if (!bmp.begin()) {
    Serial.println(F("Could not find a valid BMP180 sensor, check wiring!"));
  }
  Serial.println(F("\n"));
  const char* ssid     = "WIFI_SSID";
  const char* password = "WIFI_PASSWORD";
  const char* host = "api.thingspeak.com";

  pinMode(A0, INPUT);
  raw = analogRead(A0);
  volt=raw/1023.0;
  volt=volt*4.2;

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
     delay(500);
  }
  Serial.println(F("Connected to WiFi"));
  String v=String(volt);// change float into string
  // make TCP connections
  WiFiClient client;
  if (client.connect(host,80))  // "184.106.153.149" or api.thingspeak.com
  {
      String postStr = apiKey;
      postStr +="&field1=";
      postStr += String(v);
      postStr +="&field2=";
      postStr += String(raw);
      postStr +="&field3=";
      postStr += String(bmp.readPressure()/100);
      postStr +="&field4=";
      postStr += String(bmp.readTemperature());
      postStr +="&field5=";
      postStr += String(bmp.readAltitude());      
      postStr += "\r\n\r\n";
      
      client.print("POST /update HTTP/1.1\n");
      client.print("Host: api.thingspeak.com\n");
      client.print("Connection: close\n");
      client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
      client.print("Content-Type: application/x-www-form-urlencoded\n");
      client.print("Content-Length: ");
      client.print(postStr.length());
      client.print("\n\n");
      client.print(postStr);    
  }
  client.stop(); 
  Serial.println(F("Sleep......")); 
  ESP.deepSleep( 10 * 60 * 1000000 ); //10 minutes  
}

void loop() {

}


For connecting the BMP180 to Wemos D1 mini see this post. 

The Wemos will enter in sleep mode and every 10 minutes will wake and log the data to cloud.

Don't forget to connect the RST pin to D0 to activate the deep sleep.

The 5V to 3V3 on the Wemos is always  powers so there is some energy lost on it but is ok.

After one day the graph is looking like this:




Total cost: EUR 14.

[ EDIT 1 ] 5 days later after 700 measurements the graph is:

I am considering adding a solar panel to charge the battery during the day.

5 days later
[ EDIT 2 ] I've measured battery's voltage today and the deviation is 0.5V. So I need to add 0.5V over the calculated value. Voltage measured on battery after 5 days is 4.11 V.

I don't find the any information if the shield module will stop providing voltage to Wemos D1 if the battery voltage drop under the 3.6 V or will dry the 18650 battery, but my guess is that will stop at 3.6 V.

[ EDIT 3 ] After 9 days the battery has 4.06 V

9 days later



[ EDIT 4 ] After 11 days the battery has 4.03 V
11 days 

[ EDIT 5 ] After 13 days the battery has 4.00 V. For one day the router decided to take a break. It looks like the battery still have 0.4 V left and it is enough for the rest of the month. I predict that the module can run 30 days without problems with only one charge. Discharging rate is is pretty linear and I hope it will stay linear.

13 days later
[ EDIT 6 ] After 16 days - 3.943 V


[ EDIT 7 ] After 30 days - 3.8 V



The second interruption was deliberate ( I had to travel ).

Conclusion:

After 4160 records logged with a single charge of one 18650 battery there is still some power left
for at least one week. In conclusion you can use the WeMos D1 ,  Wemos Battery Shield and one 18650 to get and log data at 10 minutes interval with a single charge for more then one month.

[ EDIT 8 ] After  2 hours charge the module is ready for another month of working. I've added a trigger to be notified via twitter when the voltage is bellow 3.7 V to charge it again.

Ready for a new month

[EDIT 9] I have now  38 days with one charge. Remember, every 10 minutes is measuring the temperature and post it on thingspeak.com then is entering again is deep sleep

38 days with one charge

[Edit 10] I have now 48 days with one charge. In the last days I've notice that the value for the battery voltage is quite flat comparing it with the previous values. I am sure that today I will receive a tweet that the voltage have dropped under 3.65V.


48 days with one charge


>>> For the version with a solar panel attached see this post <<<

Thursday, December 1, 2016

BMP280 and ESP8266

The BMP280 is the next generation sensor from Bosch and follows its predecessors BMP085 - BMP180. Price for it is now under $2 with free shipping.




Key parameters

  •  Pressure range 300 … 1100 hPa (equiv. to +9000…-500 m above/below sea level)
  •  Package 8-pin LGA metal-lid
  • Footprint : 2.0 × 2.5 mm², height: 0.95 mm
  •  Relative accuracy ±0.12 hPa, equiv. to ±1 m
  •  (950 … 1050hPa @25°C)
  •  Absolute accuracy typ. ±1 hPa  (950 ...1050 hPa, 0 ...+40 °C)
  •  Temperature coefficient offset 1.5 Pa/K, equiv. to 12.6 cm/K  (25 ... 40°C @900hPa)
  •  Digital interfaces I²C (up to 3.4 MHz) SPI (3 and 4 wire, up to 10 MHz)
  •  Current consumption 2.7µA @ 1 Hz sampling rate
  •  Temperature range -40 … +85 °C


Typical applications

  • Enhancement of GPS navigation
  •  (e.g. time-to-first-fix improvement, dead-reckoning, slope detection)
  •  Indoor navigation (floor detection, elevator detection)
  •  Outdoor navigation, leisure and sports applications
  •  Weather forecast
  •  Health care applications (e.g. spirometry)
  •  Vertical velocity indication (e.g. rise/sink speed)









For connecting the BMP280 to ESP8266 the following pins need to be connected: 


BMP280
NodeMCU / WeMos D1 mini
Other ESP8266
VCC
3V3

GND
GND

SCL
D1
GPIO 5
SDA
D2
GPIO 4
CSB
3V3

SDO
3V3




The BMP280 supports the I²C and SPI digital interfaces; it acts as a slave for both protocols. 

The I²C interface supports the Standard, Fast and High Speed modes. 

The SPI interface supports both SPI mode ‘00’ (CPOL = CPHA = ‘0’) and mode ‘11’ (CPOL = CPHA = ‘1’) in 4- wire and 3-wire configuration. The following transactions are supported: Single byte write  multiple byte write (using pairs of register addresses and register data) single byte read multiple byte read (using a single register address which is auto-incremented) 


Connect the CSB pin to GND to have SPI and to VCC(3V3) for I2C.

The 7-bit device address is 111011x. The 6 MSB bits are fixed. The last bit is changeable by SDO value and can be changed during operation. 

Connecting SDO to GND results in slave address 1110110 (0x76), connecting it to VCC results in slave address 1110111 (0x77), which is the same as BMP180’s I²C address. 

The SDO pin cannot be left floating, if left floating, the I²C address will be undefined.

In my setup I've connected CSB and SDO to VCC to have I2C and 0x77 as address.


To run a quick test I've installed the Adafruit Sensor library and Adafruit BMP280 library .

The code to test the BMP280 is the example code from library.

This code assume that the SDA and SCL are connected on GPIO 4 and GPIO 5. If you need to assign new pins to your BMP280 use the Wire.begin(2,0) where the GPIO 2 is connected to SDA and GPIO 0 is connected to  SCL.

Now its time to add some code to read the temperature and pressure, post them to the thingspeak.com and also update the temperature gauge on this blog.



/**********************************************
 * Catalin Batrinu bcatalin@gmail.com 
 * Read temperature and pressure from BMP280
 * and send it to thingspeaks.com
**********************************************/

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <ESP8266WiFi.h>

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11 
#define BMP_CS 10

Adafruit_BMP280 bme; // I2C
// replace with your channel’s thingspeak API key,
String apiKey = "YOUR-API-KEY";
const char* ssid = "YOUR-SSID";
const char* password = "YOUR-ROUTER-PASSWORD";
const char* server = "api.thingspeak.com";
WiFiClient client;


/**************************  
 *   S E T U P
 **************************/
void setup() {
  Serial.begin(9600);
  Serial.println(F("BMP280 test"));
  
  if (!bme.begin()) {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
  WiFi.begin(ssid, password);
  
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");  
}

  /**************************  
 *  L O O P
 **************************/
void loop() {
    Serial.print("T=");
    Serial.print(bme.readTemperature());
    Serial.print(" *C");
    
    Serial.print(" P=");
    Serial.print(bme.readPressure());
    Serial.print(" Pa");

    Serial.print(" A= ");
    Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
    Serial.println(" m");

    if (client.connect(server,80))  // "184.106.153.149" or api.thingspeak.com
    {
        String postStr = apiKey;
        postStr +="&field1=";
        postStr += String(bme.readTemperature());
        postStr +="&field2=";
        postStr += String(bme.readPressure());
        postStr += "\r\n\r\n";
        
        client.print("POST /update HTTP/1.1\n");
        client.print("Host: api.thingspeak.com\n");
        client.print("Connection: close\n");
        client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
        client.print("Content-Type: application/x-www-form-urlencoded\n");
        client.print("Content-Length: ");
        client.print(postStr.length());
        client.print("\n\n");
        client.print(postStr);    
    }
    client.stop(); 
    //every 20 sec   
    delay(20000);
}


Temperature logging


A post about BMP180 attached to a battery shield can be found here.











Friday, November 27, 2015

DHT22 versus BMP180. The winner is ....

For my chronothermostat  project I have evaluated the 5.11USD DHT22 and 2.20 USD BMP180.

I've let them work in parallel for few days and the winner is ..... BMP180.

This is a graph for BMP180.


BMP180



This is a graph for DHT22.
DHT22


As you can see the DHT22 had few unwanted spikes which leads to false triggers.

DHT22 has the advantage of using one pin,  BMP180 is i2c so is using 2 pins, but the temperature has no spikes. 

Both sensors:

  •  are reading the same temperature
  •  both are showing a lower value as my current chronothermostat which is responding more quickly on changing the temperature.

If you know other sensors that are more precise and are more temperature responsive, please let me know.





Tuesday, April 7, 2015

Post man #4

To extend the range ( which seems to be fine for my project at this time) I've ordered some 
19 cm mini PCI U.FL to RP-SMA WiFi Antenna Cable. My plan was to reuse the antenna from NRF240L01P modules but I didn't checked the connectors. 


SMA U.FL wifi antenna cable and antenna from NRF24L01



Murphy's law is applicable also in this case, so as you can guess they don't match. So the new antennas are on their way also.


I've received also the BMP180 sensors ( replace the old BMP085 version). 
  • Pressure sensing range: 300-1100 hPa (9000m to -500m above sea level)
  • Up to 0.03hPa / 0.25m resolution
  • -40 to +85°C operational range, +-2°C temperature accuracy
  • This board/chip uses I2C 7-bit address 0x77


BMP180 sensor bag

The sensor and its board is very small, which is great. 

So I have temperature and humidity from DHT22, pressure from BMP180, I can now predict the weather for my irrigation platform.