Saturday, January 31, 2015

BMP180 code

Here is the code for running the BMP180 pressure sensor:

>>> import Adafruit_BMP.BMP085 as BMP085
>>> sensor = BMP085.BMP085()
>>> sensor.read_temperature()
24.3
>>> sensor.read_pressure()
102543L
>>> print 'Pressure = {0:0.2f} Pa'.format(sensor.read_pressure())
Pressure = 102543.00 Pa
>>> sensor.read_altitude()
-99.8422490470797
>>> sensor.read_sealevel_pressure()
102542.0

Finding time in Python

In order to properly record the data, I need a timestamp. I found a few minutes this afternoon where I could research it a little. I found two methods:

Using datetime:
>>> from datetime import datetime
>>> current_time = datetime.now()
>>> current_time
datetime.datetime(2015, 1, 31, 15, 35, 14, 21154)

Simple. But there is one slight problem. I'm sure there's a way to do it, but how do you extract just the day, hour, our minute, without any of the other variables?

I would research this more, and probably will, except that I found another solution.
Using time:
>>> from time import strftime,gmtime
>>> strftime("%Y-%m-%d %H:%M:%S", gmtime())
'2015-01-31 20:41:22'
>>> strftime("%Y-%m-%d %H:%M:%S")
'2015-01-31 15:41:26'

In my opinion, this second option is easier. Yes, you need to know date and time codes and formats for Linux, but I've dealt with those for a while, so it shouldn't be an issue for me. For a reference, the codes are found by looking up "man date" in a terminal window in Linux.

In addition to already knowing the date codes, this method also make it possible to set my own preferences in how each timestamp is recorded.

BMP180 setup

I have finally soldered my BMP180 to the pins and hooked it up to the circuit board. I am in the process of mounting the pi and the circuit board to the platform, so expect pictures soon.

In setting up the bmp180, I followed the directions at: https://learn.adafruit.com/using-the-bmp085-with-raspberry-pi

I had everything working up to where I could run simpletest.py. It didn't work at first, so I changed every code that referenced "BMP085" to "BMP180". That didn't work either. 

I looked at the procedure and found my problem. On the overview, it instructs to set up the I2C following the directions on: https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c

I thought I had done that for my DHT Temperature Sensor, but when I followed the procedure, it all went smoothly, but the "BMP180" setting didn't work in the simpletest.py program.  I switched it back to "BMP085", and it worked fine.

Bottom line: follow the procedures exactly, and even though you are using a BMP180, leave the code referencing a BMP085, and it will work. Apparently, according to the website, the 180 is the same thing as a 085, but updated. So, the code for the 085 is still the same.

I'll work on getting the exact code needed for using the BMP180 written up here in the next day or two.

Next on the agenda:
  1. Mount the Pi and the Circuitboard on the platform
  2. Test how much sunlight affects the DHT22. If it's a significant amount, then I'll need to rig an insulator to block the sun, but allow the air to reach the sensor.

Saturday, January 24, 2015

DHT22 Temperature sensor

I got my DHT22 sensor the other day, and finally had time to test it out today. Here are the results of this test.

Run Beginning Temperature Beginning DHT22 Final Temperature Final DHT22
With 10kOhm Resistor 23C 22.6C -16C -15.9C

So, the temperature sensor is really good.  I think it will be perfectly satisfactory as far as calibration goes. However, there is a problem that I have noticed. That has to do with response time.  

To go from 9.3C to -1.8C, it took about 13 minutes.  
To go from -1.8C to 17.1C, it took about 15 minutes.

Now, I was doing this test with extreme changes in temperature (Counter to Freezer, and vice-versa). I'll have to wait until the tethered test in order to see if it will actually work, or if this will cause a problem.  That test will be in a couple of weeks, after I get the pressure sensor working, which is my next task.

Friday, January 9, 2015

Temperature Sensor Update

I did a calibration test for my DHT11 yesterday, and found a few problems.  I placed the room-temperature RPi and a room-temperature thermometer in the freezer, and recorded the temperatures before I put them in, and again after a few minutes.

I ran the test in 3 scenarios, one with the sensor connected directly to the RPi GPIO, one connected through the breadboard, and one with a 10k Ohm resistor included, as directed in the how-to file <https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/wiring>. Here are the results:

Run Beginning Temperature Beginning DHT11 Final Temperature Final DHT11
Connected directly to GPIO 25C 29C -11C 1C
Connected through breadboard 25C 22C -13C 1C
With 10kOhm Resistor 24C 22C -15C 1C

So, the beginning temperatures were much closer with the breadboard than without. Then, as was pointed out to me, the resistor helps the RPi as a failsafe.

The problem is now obviously with the final temperature.  I looked at the details on the DHT11, and found that it only has a range of 0C to 50C.  I'm not sure if I'll get negative temperatures or not, but I'd rather be safe. So, I ordered a couple of DHT22 sensors. The DHT22 has a range of -40C to 80C.  Here are the specs on the DHT22:
http://www.adafruit.com/product/385

In addition, I also ordered the BMP180 Pressure sensor. By the end of next week, I should have all the measurement sensors I need.  Here are the specs on the BMP180:
http://www.adafruit.com/products/1603

The biggest task for me now is to find out how to release the balloons.

Sunday, January 4, 2015

Ice Crystals

I was cleaning out the freezer a little the other day and saw these beautiful ice crystals. How could I resist?