maanantai 28. toukokuuta 2018

Home temperature meter by Adafruit Feather HUZZAH ESP8266 and TPL5110

I have a hobby project to collect information about the temperature and humidity of my home. For the prototyping I selected an Adafruit Feather HUZZAH ESP8266 board with integrated wifi.

For temperature measuring I selected a popular and cheap DHT22 sensor. The DHT22 contains temperature and humidity meter in a same package and it is packed to the plastic box that can be attached to the wall. The sensor is preatty cheap - price is about 10€. Adafruit provides ready to use Arduino library and tutorials to use the DHT22 sensor so taking sensors to use is relatively easy.


Summary

On my project the most difficult part was to manage the Feather board power consumption (actually the ESP8266 chip is the issue). This is an issue especially on battery powered setups since the board will run only couple weeks by the batteries. The TPL5110 breakout is an useful extension to solve this issue especially if the setup can be switch off periodically. 

The Feather board itself works well and I didn't have any issues with the board.

The DHT22 sensors works well expect the issues to power up the circuit. I didn't find any good solution to solve that issue and ended up to manually hook the wires to get the sensors work.

In future I will replace the prototyping board with more solid solution. The prototyping board may cause some issues since it is very easy to accidentally loose the wires.

I have created a simple dashboard to the Adafruit IO cloud.

The project


The setup contains Adafruit Huzzah board, four accu-batteries and two DHT22 sensors. Setup is assembled to the prototyping board.

On my home, the one DHT22 is placed in the living room and second is in the air conditioning pipe where fresh air flows into the room. Measurements are collected and sent to the cloud over the wifi in every 10 minutes.

My aim was to create a battery powered setup. I noticed immediately that the power consumption of the Feather board is relative high. For that reason I ended up to try couple different setups. First setup was using DeepSleep mode of the board to restrict the idle power consumption. That didn't give enough battery life so I made a second version that was using an additional TPL5110 circuit to control the power.



Version 1 with ESP8266 DeepSleep mode

The first version of the setup was using the Feather ESP8266 board DeepSleep mode to save the power. In a DeepSleep mode the Feather will shut down all functions expect the real time clock. On my project the Feather was put into the DeepSleep between the measurements. Practically the Feather was awake about 10 seconds that was required to send the data to the cloud and after that it was shut down to the DeepSleep for 10 minutes.

The DeepSleep mode is activated from the program code by simple command: ESP.deepSleep(milliseconds). After the given time, the board wakes up. Note that the wake up will reset the board.

The reliability of this setup was very good during the couple months when it was in use. Only issue was battery life that was about 10 days with the four accu-batteries.

I measured power consumption of the Feather. The board takes about 100mA current when connected to the Wifi. In the DeepSleep mode consumption is still 7mA. The DeepSleep consumption is the problem since it will eat the batteries empty even nothing is happening.

Charging accu-batteries in every 10 days was a bit frustrating so I started to search a better solution.

The version 1 circuit is very simple. Instead of the picture, I have four AA batteries.


Version 2 with Adafruit TPL5110 Power timer breakout

The second version of the setup was using the Adafruit TPL5110 breakout to control the power.

Adafruit site says: "TPL5110 will take care of turning your project on/off using a built in timer that can vary from once every 100ms up to once every two hours. Basically, the TPL will turn on periodically, adjustable by potentiometer or resistor, and turn on your project's power. It will then wait until a signal is received from the project to tell the TPL that it can safely turn off the power."

The circuit:
  • Power to the Feather is wired though the TPL breakout
  • The Feather GPIO pin 5 is connected to the TPL "done pin"

1) After the Feather has sent data to the cloud it will switch the power OFF by rising the GPIO pin to HIGH. 2) The TPL will wait the time amount that is defined by the build in potentiometer. 3) After the time has passed the TPL will switch the power ON.

The TPL itself consumes very little power so the Idle power consumption is much less compared to the version 1.

I noticed that the Feather GPIO pins 4 and 5 are the only pins that can be used to control the TPL5110. Every other GPIO pin has a strange feature: there happen a small voltage peak when the power is switch ON to the Feather board. That peak is just enough to trigger the TPL to cut the power immediately OFF and the setup never start up properly. The voltage peak cannot be controlled from the program code so it must be related to the board build-in boot sequence.

The reliability of this setup has been excellent. The setup run 45 days before the accu-batteries were empty. That is 35 days more than without the TPL5110 brakeout.

Stability of the DHT22


After the first tests I realized that the DHT22 sensor is quite unstable. Often the sensor value can not be read after the power is switch on to the board. It doesn't matter whether the board is powered from the USB or battery. After some googleing I found that the issue is well known and reported on the discussion forums and blogs.

I found that quite often the sensor starts to work after manually loosing the sensor power wire and then instantly plugging it back. This must be done while the board is powered and reading the sensor.

I also tried to take the sensor power straight from the board IO pin. That way I was able to control the sensor power from the code by switching the IO pin HIGH and LOW. This also didn't give any real help.

My conclusion is that the sensor just is unstable. If the first reading is fine after the power is switch ON, then the sensor will probably work without any issues as long as the board is powered. If the first reading does't success, then it will not repair itself without actions. With the TPL5110 the sensors seems to work better.

Update 12.12.2018:

I changed the power interval of the setup from 10 mins to 20 mins. After that the battery life increased to tree months that is a preatty good result.


sunnuntai 30. kesäkuuta 2013

IOIO Cyclocomputer - enhanced version


I had some issues with my first proto of cyclocomputer that I covered in previous post. Briefly, sensor signals and IOIO board electricity start failing when driving on rough road. That happened since I used very basic wire connectors without any locking mechanism. Now I have made some improvements to get hardware work better. I created so called shield that is attached over IOIO board and solder all wires directly to it. That solved connector issues since there is no separate connectors anymore. Shield is still removable and IOIO board can be easily removed if needed. I also improved Android user interface to have more professional look.

IOIO board and custom made shield where sensors are connected.

Shield attached to IOIO board.

Standard speedometer sensor to measure cadence. Magnet is attached to crank.

Standard speedometer sensor to measure speed.

Android user interface.

I try to hide wires and succeeded quite well.


sunnuntai 9. kesäkuuta 2013

IOIO cyclocomputer - mounted to bike


I got my cyclocomputer proto mounted to bike that I mentioned in previous post. Briefly, computer is running on Android phone and IOIO board is used to connect phone to sensors. Sensors are ordinary speedometer sensors that normal out of the stock bike speedometers are using. It means that there is no need to use GPS to measure speed since speed data is measured by physical sensors.

On my proto I'm using two separate sensors to measure wheel rotation and cadence speed. For clarification, cadence means how fast foot pedals are rolling around (rolls per minute). Using collected data I can calculate speed, travel distance, average speed, cadence, gear ration etc. Calculated values are displayed on Android phone that is mounted to bike handlebar.


Bike mounting

Android device can be connected to IOIO board by two ways: using USB cable or wireless bluetooth. Unfortunately my old phone (HTC Desire HD) is not capable to open bluetooth connection to IOIO so I'm forced to use not so fancy USB cable. Anyway, connection is working and that only matters. IOIO board itself including 9V battery is packed to saddle bag. I have faced some issues with sensor connectors on shaking bike because connectors are simple pins on board without any locking mechanism. I have to consider to purchase better connectors if I would like to have more permanent solution ... and maybe  something else than masking tape on wiring :)


Some words about application code

Controlling IOIO board from software code is relatively simple. Only challenge I faced was to figure out how to measure two separate sensors simultaneously. To measure very short signals such as rolling wheel I had to use IOIO method called input.waitForValue(bool). Problem is that waitForValue() freeces the program execution until desired value appears (magnet passes sensor) so it is impossible to measure two separate signals simultaneously. When program is waiting signal from rolling wheel it cannot capture signal from cadence sensor. I solved this issue by creating own thread for both sensors and got code running correctly. Rest of the application is mostly calculating values and displaying them on screen. Total count of lines containing comments is about 350.

Example of thread to measure sensor value:

Summary

Overall project was succesful and didn't take too much time to implement - thanks to IOIO board that is easy to develop. After few rides the biggest issue is loose connectors. When driving on rough road the sensor signals and board electricity start to fail. Connectors have to be build carefully to get hardware work without issues. Currently I'm using basic harvin connectors to connect wires to IOIO board and they are not tight enought to work on moving bike. In future I will make some improvements to get hardware to work better.




torstai 9. toukokuuta 2013

Android IOIO - Analog Input


IOIO board is capable to measure voltage levels from I/O pins. Simplest example to demostrate analog input is to attach potentiometer to IOIO. IOIO will detect potentiometer rotation angle as different voltage levels. Voltage levels are measured by Android application as absolute voltage or relative value from 0 to 1.

In this demostration potentiometer rotation angle is presented by numbers (scale 0-1) and using visual bar. Circuit is simple and no additional components is needed expect the potentiometer itself.

Program code of activity:

sunnuntai 5. toukokuuta 2013

Bicycle computer with IOIO-OTG



Some time ago I got an idea to create Android based bicycle computer. Computer should include functions such as speed, drive distance, drive time, GPS etc. To get dream come true I had to find solution how to attach bicycle computer wheel sensor to Android phone. I have done some electronic stuff at many many years ago so I have basic knowledge how to do trick on hardware level. After some googling I found solution that should solve the problem: Android develoment board called IOIO-OTG.

IOIO is a simple circuit board that contains tens of I/O ports those can be controlled by Android device. Basicly I/O ports can be used for example as a Digital I/O, PWM output or Analog input etc. It means that IOIO is capable to measure and drive many kind of electronic signals and attached devices. IOIO board is controlled from Android application using special API that contains all needed tools to access board functions. Bicycle computer sensor is simple on/off switch that conducts electricity or not depending the position of the wheel. Regarding that fact, IOIO board should be capable to measure rolling wheel.

First impressions of IOIO board


I ordered IOIO board direcly from manufacturer, Sparkfun Electronics. Price was 39 dollars. Order process was simple and board arrived to Finland after two weeks. Controlling board from Android application is suprisingly easy. API is well documented and it contains high level functions to all hardware level controls. IOIO board can be attached to Android device using USB or Bluetooth. To use wireless bluetooth connection, additional BT dongle have to be attached to board USB port. IOIO onboard IC processor handles communication with bluetooth dongle and Java API contains needed BT logic.

Basic circuit: battery, IOIO and phone

Bicycle computer proto


For proto I borrow wheel sensor from my old bicycle computer. I cut wires and attached new contacts so that sensor could be plug to IOIO. Circuit is very simple and doesn't need any extra components. Connection to Android phone is using USB because I don't currently have suitable bluetooth dongle. Program code to measure sensor signals contains only couple effective lines. IOIO is programmed by extending BaseIOIOLooper class that provides all the needed logic. Following code snippet is originally from IOIO sample app that I have modified.




Calculate method does the needed calculation to have speed, travel distance, average speed and ride time. Calculate is called every time when wheel sensor triggers the signal that is once per full turn of wheel. Wheel circuit is 2,11 meters so distance is increased by wheel circuit at every function call. Other values are calculated at the same way.


Summary


There is a good wiki available from IOIO main developer: https://github.com/ytai/ioio/wiki
Board can be ordered from manufacturer: https://www.sparkfun.com/products/11343