|To Sextant or not: That is the question...|
|Build Your Own Cheap Wireless AIS Receiver|
|Handheld Marine VHF Radio Reviews|
|Best 4 Marine Binoculars|
Raspberry Pi is an amazing tiny little computer that we really love. It is quite powerful, runs a fully functional Linux distribution and has GPIO connections to integrate with external devices and sensors. In this tutorial, we are going to explain how to add a BME280 temperature, humidity and pressure sensor to a Raspberry Pi.
We will use the sensor from sensord, an extensible open source sensor daemon. We will also demonstrate how to receive temperature, pressure and humidity readings from a mobile app (both iOS and Android), that is also open source.
While this whole set-up is primarily intended for marine enthusiasts who have their boats, this tutorial is also directly relevant to those who only have a Raspberry Pi and want to add some mobile app controlled mini weather station capability. Just keep reading!
First some background. BME280 is an integrated environmental sensor developed by Bosch. It combines temperature, pressure and humidity sensors and it is very affordable. You can buy it for less than $10! And it supports I2C and SPI buses, which are both supported by Raspberry Pi. This really makes it ideal for creating a mini weather station. Using the BME280 directly is a little difficult so you will need a module that makes it easier to integrate. Modules are trivial to connect to Raspberry Pi as you will see soon.
There are various modules made, we would like to highlight the one made by Adafruit and Diymall. In this tutorial, we used the Diymall version but you can technically use any others with minor changes to configuration. If you want to stick to this tutorial one-to-one, try the Diymall.
Once you have the BME280 module, you need to connect it to your Raspberry Pi, either via I2C or SPI bus. In this tutorial, we will use the I2C bus. Note that DIY module only supports I2C, while Adafruit one can be used for I2C or SPI.You will need a breadboard and you may need to do some soldering. If you are a bit careful in ensuring contacts, you may be good without soldering as well. If you don't have a breadboard or want to bypass it, you can use jumper cables like these.
In the above diagram, all you need is pins 1 (3.3V Power), 3 (I2C1 SDA), 5 (I2C1 SCL) and 9 (GND). You need to connect these pins to VIN, SDA, SCL and GND pins of the Diymall BME module respectively. You need to make sure Raspberry Pi is turned off while doing this!
Once the wiring is complete, you need to enable I2C on Raspbian, which is disabled by default. There are a few different ways to do this and this Adafruit article explains this very well. Enable I2C by using one of the methods explained there, reboot your Raspberry Pi for the changes to take effect and continue.
Now is the time to install the necessary libraries. We will need the Adafruit GPIO Python library, let's get it first:
sudo apt-get update sudo apt-get install build-essential python-pip python-dev python-smbus git git clone https://github.com/adafruit/Adafruit_Python_GPIO.git cd Adafruit_Python_GPIO sudo python setup.py install
Now, we need our sensord and its dependencies, let's get and run it:
sudo pip install tornado git clone https://github.com/itemir/rpi_boat_utils cd rpi_boat_utils/sensord sudo ./sensord &
If you have the Diymall BME280 sensor and everything up to this point was right, this should just start running the daemon in the background. If you have a different BME280 sensor, you may need to update plugins/BME280.py file and modify BME280_I2CADDR setting. For Adafruit BME280 breakout board, this value should be 0x77. If you are struggling, do the following and check the value you see there.
i2cdetect -y 1
If the daemon is running without giving any errors, you may pretty much be done already. What this daemon does is to take readings from the BME280 sensor every 5 seconds via the BME280 plugin and makes it available over the network using the Signal K protocol. Signal K is an open, marine specific protocol but in this case, it doesn't really matter for you if you are just building a mini weather station. All it will do for you is to transfer readings between the sensor and the mobile app.
You do not need to own a boat or any other expensive marine instruments or software. All you need is some software that can read and understand Signal K protocol. There is also an open source mobile app that can use Signal K. It supports marine specific instruments but it also supports the temperature, pressure and humidity readings that we need.
When you run the app, whether on iOS or Android, it will try to find a Signal K server on the network automatically for a few seconds. It will not find it as we don't advertise the service (we will come to that later). You can simply provide the IP address manually for now. That will be the IP address of your Raspberry Pi and make sure that your mobile device is on the same network as the Raspberry Pi. sensord uses port 1923 so, you need to enter the address as <ip_address_of_raspberry_pi>:1923 (e.g. 192.168.1.124:1923). Do not change the path, default path is good.
When the app opens, Panel and AIS tabs will be empty, that is normal as you don't have any marine instruments that are communicating over Signal K. Switch to Sensors tab and you will see gauges for temperature, pressure and humidity. The wifi icon on the right upper corner indicates whether the mobile app is connected to sensord Signal K server. If it is green, you should be receiving updates every 5 seconds. If it is red, it means there is some problem with the connection. Make sure the IP address you entered is correct, port number is 1923, sensord is running on the Raspberry Pi and network connectivity is good. Remember, mobile device needs to be on the same network as the Raspberry Pi, you cannot be on 4G/LTE.
Signal K Mobile app is designed with sailors and mariners in mind. If you only use it as a weather app, additional screens may feel cumbersome or unnecessary. If that is the case, there is another good news. Signal K Mobile is open source and its source code is available on GitHub. With a little bit of effort, you can tweak it and create your own mobile app with the exact look and feel that you want! Hint: Start by editing app/pages/tabs/tabs.html to remove some of the tabs there. Enjoy!