BMP180 and Raspberry Pi

Update: I found this gave incorrect readings, see this post for the method I used to correct problems with height measurements.

The I2C pins on my Raspberry Pi for the Weather Ballon project were tied up with a Real Time Clock. However, this stopped working after a week and so I decided to add the BMP 180 atmospheric pressure sensor. This would not only give the pressure but would provide an air temperature reading that the onboard thermometer in the radio could be compared against. There does not seem to be too much information on the Internet about using this sensor on the Pi and using Python, so I went over to the Adafruit site and followed their instructions.

I added the the library but as soon as I tried to run the script in IDLE it showed an error. When I tried the Adafruit example it worked perfectly as long as I ran the script directly. If I loaded into IDLE and tried to run it would not work. So, I made the alterations to my weather balloon script and saved the file. I shut down VNC and opened up connection via SSH. I use Serverauditor on my iPad, and once it was running I used the following commands:

Cd /home/pi/Weather_Balloon

Sudo Python

Once the programme was running I could monitor the output from the slave on my iPad.

I made some alterations to the main control panel software running on my laptop and now the local pressure, sea level pressure and height (measured on the balloon) are shown. I am hoping to be able to show how pressure decreases with height above sea level.


Tilt Switch and Vibration Sensor for Arduino


A tilt switch acts just like a simple push button. The picture above shows an example connected to digital pins 6 and 7. The brass tube contains a small ball that moves as the sensor moves. Like a switch or push button this ball completes a circuit. Move the sensor and the ball moves breaking the circuit.

This particular sensor is ‘off’ when pointing up and ‘on’ when horizontal or pointing down. This sensor detects vibration so the even when pointing up any vibration will turn the sensor ‘on’.

As it’s just a switch any simple sketch that uses a push button can be used. The sensor has two  leads, connect one to earth and the other to a digital pin. This digital pin needs to be kept HIGH, using a resistor to +5 volts. As the sensor is activated it takes the digital pin LOW.

The code below uses two simple tricks to keep the connections to a minimum. The input is Digital pin 7, so Digital pin 6 is made an OUTPUT and this pin is then set to LOW to provide 0v or ground. So how do we get rid of the need to use a resistor to keep inn 7 HIGH? The Arduino has pullup resisistors that can be switched on, so when defining pin 7 this resistor is switched on using pinMode(inPin, INPUT_PULLUP).

This simple circuit switches the onboard LED off and on. You can also see its operation as a vibration sensor

// Tilt sensor and Vibration a Detector

int ledPin = 13;
int inPin = 7;
int earthPin = 6;
int valueTilt = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inPin, INPUT_PULLUP);
pinMode(earthPin, OUTPUT);
digitalWrite(earthPin, LOW);


void loop() {
valueTilt = digitalRead(inPin); // read the state of the tilt switch
digitalWrite(ledPin, valueTilt);

Ublox NEO6MVC GPS unit and Raspberry. Pi

I have an Adafruit Ultimate GPS, which cost me around £35. I did not want to risk this on my Weather Balloon and so looked for a cheaper alternative. I didn’t need a number of features on the Ultimate GPS, I just needed to get a height and location. The Ublox NEO6 can be had on eBay for about £8 and so I sent for one. It arrived in about two weeks, which is good comming from Hong Kong. The board is about the same size as the Ultimate GPS, but the ceramic antenna was bigger. I needed to solder a four pin header and I used a spot of hot glue to hold the antenna to the board.

The device is 3volts, so it needs a logic level shifter if I was going to use it with a USB FTDI adaptors. Hobbytronics sell an I2C bidirectional logic level shifter here for £3. The advantage of this board is that it has a 3.3 volt 250 mA regulator that will supply the Ublox GPS.

The logic level shifter has a 5 volt side and a 3 volt side and it is very important that you connect it the right way round. The 3 volt pin is an output pin and if you accidentally connect 5 volts to the 3 volt pin you will destroy the regulator. Connect the 5 volt pin to 5 volts on the USB adaptor and Gnd on the USB to GND on the logic level shifter. Tx and Rx on the USB adaptor are connected to SDA and SCL on the 5 volt side (it doesn’t matter which way round). 

Now for the 3 volt side of the logic shifter board. Connect the 3 volts and Gnd to the Ublox GPS board. The Ublox can use either 5 volts or 3 volts as a power supply. Tx from the USB adaptor needs to connect to the Rx on the Ublox board (and Rx to Tx) so if you connected the Tx from the USB adaptor to the 5 volt SDA pin then connect the 3 volt SDA pin to the Ublox Rx pin. Connect Rx from the USB board to Ublox Tx through the SCL pins.

Once it’s all connected up plug USB adaptor into a USB socket on the Raspberry Pi. Install GPSD as shown here. The same setup can also be plugged into an Arduino without any alteration.

The Ublox GPS performed just as well as the more expensive Adafruit Ultimate GPS and acquired a lock in about the same time. Accuracy seemed to be within 2 metres in an urban location. I feel this little unit is amazing value for money.

Raspberry Pi and a real time clock

One of the problems with using the Raspberry Pi with WiFi using an access point, as I am doing with my weather balloon project, is that without Internet access the Raspberry Pi has no clock. The answer is to use a real time clock and there is an excellent one designed to plug straight onto the GPIO pins. The same device is available from a number of sources on eBay and prices range from about £1.50 post paid from China, to about £7 in the UK. I managed to find a UK source that was selling them at less than £4 post paid.

The device itself is tiny, on the underside is a backup cell and the RTC is mounted on the top. This RTC is an upgrade on the usual DS1307. The DS3231 has improved temperature stability and will operate at both 3 volts and 5 volts. It can be used on either the Raspberry Pi or the Arduino. DS1307 libraries can be used with no problems.

Setting up the Raspberry Pi took some time and was a little complicated, I found the best source was  here at the Pi Hut. I found it easier to follow than the Adafruit tutorial, although you need to follow the Adafruit tutorial on setting up i2c on the Raspberry Pi. It took me about half an hour to set everything up, and now I will be able to time stamp images from my weather balloon project.