Forget Brexit – the hot topic this year in the UK is…you guessed it, the weather. Truth be told, it’s been a somewhat freakish summer. After all, temperatures soared just above tepid and there wasn’t as much as a drop of snow. But what we call a heatwave here in blighty has got us all clambering for news of what Nature has in store for us on the weather front.

With this in mind, we thought we’d show you how to be the first to know with this nifty little weather station using our old friend Raspberry Pi – plus a couple of cheap Xinabox parts and ten minutes of your precious time.

If you’re new to the wonders of XinaBox, you’re in for a treat. These clever little square modules are fab for clipping together super-fast prototypes for all sorts of circuit stuff.

The SW01 module sports a magical Bosch BME280 digital sensor that gives accurate readings for temperature, humidity and air pressure. Since XinaBox modules use I2C to interface together, and the BME280 is an I2C device, we can use existing Python BME280 libraries to drive the sensor from our Raspberry Pi. How cute is that?

We’ll be using Richard Hull’s Python module for this little project (there’s also an Adafruit module you could use).

OK, fingers nice and warm? Let’s do this…

Install the XinaBox modules

Start by fitting the BR01 Rasperry Pi bridge onto the GPIO pins furthest away from the USB sockets on your Pi:



We’d normally use the MD01 spacer (in this case it’s the MD03) to make sure our sensor isn’t reading the temperature directly above the Broadcom processor (woops). As you regular Pi guys out there know, the processor can get toasty even when it isn’t doing all that much:



In fact, we used a quick shell script to find the processor temperature. And even doing zip, the processor was pushing a tropical 45°C. So using the spacer to move the sensor away from this heat source should pretty much mitigate any distorted readings.

Right, time for Setup.

Setup your Pi

The first thing we need to do is make sure the I2C kernel driver is enabled on our Raspberry Pi. So simply run dmesg or lsmod from the command line in a terminal:



In this pic they’re all present and correct. But, if you don’t see any I2C kernel modules listed, here’s how to enable them:

In your terminal type:

$ sudo raspi-config

Then use the arrow key to move down to ‘Advanced Options’ and hit <Enter>:



Still with us? Good. We now need to move down to ‘Interfacing Options’ and <Enter>:



Then select P5 I2C:



And we get:



Select <Yes> which should produce:



Now hit the <OK> which takes us back to the main menu. Use the right arrow key to get to <Finish>:




Now reboot and check dmesg or lsmod again. And those pesky little kernel modules should now be well and truly loaded.

Install Python librarires

The next thing we need to do is install some tools and an essential pre-requisite Python library:



Now we’ve installed the I2C tools, we can check our weather sensor is visible on the bus…



…and lo and behold, there it is at address 0x76! Phew.

Now we can install our Python module:

$ sudo pip install RPi.bme280

Want to use Python 3? You’ll need to use pip3:

$ sudo pip3 install RPi.bme280

The code

Now it’s time to get our programming head on as we start to write our Python Program.

Let’s kick off with a really rough n’ ready program, just to check our hardware is behaving properly. Open the text editor or use Geany to enter a test script:


import smbus2
import bme280

bus = smbus2.SMBus(1)

bme280.load_calibration_params(bus, 0x76)

print(bme280.sample(bus, 0x76))


We can save this as

Open a terminal and run the script from the command line:



Way to go!  Our hardware has produced a sensible output, so we know all’s working as it should.

Now we can go on and do something useful, like logging our readings over time into a file. For this we’ll need a slightly more complicated Python script:


import time
import smbus2
import bme280

bus = smbus2.SMBus(1)
address = 0x76

calibration_params = bme280.load_calibration_params(bus, address)
layout = '{0:5d}:  {1},  {2:0.3f} deg C,  {3:0.2f} hPa,  {4:0.2f} %'
counter = 1

while True:
    data = bme280.sample(bus, address, calibration_params)
    with open("sample.log","a+") as f:
        f.write(layout.format(counter, data.timestamp, data.temperature, data.pressure, data.humidity) + "n")
    counter += 1


Not a lot happens in the terminal when we save and run this. But our output is appended to a file on each loop:



We’ve used a 5-second interval between each loop so we can extract some quick data output, but for real-world logging you’d probably choose an interval of something like 5 to 15 minutes between entries. The log file ends up looking something like this:



So there we are – next time there’s any wild weather around you’ll be the first to spread the news.

Just thinking about this project, it really struck us how incredibly fast the XinaBox x-chips make it to test out any lightbulb moments you may have. You don’t even need to be an electronics nut – you just need to know the functionality you want. Then you can clip these functions together in seconds and get straight to programming. Which is pretty perfect for super-quick prototyping or makeshift measurement instruments you can take apart and re-use for other purposes when you’re done.

There are over 80 x-chips covering a host of different processor, sensor and communications functions. And more are being added all the time. So we’re excited by the prospect of being able to build and deploy just about any kind of IoT or autonomous embedded system you care to imagine. All of which means the future’s looking bright (see what we did there?).



Like what you read? Why not show your appreciation by giving some love.

From a quick tap to smashing that love button and show how much you enjoyed this project.


Our website uses cookies and similar technologies to provide you with a better service while searching or placing an order, for analytical purposes and to personalise our advertising. You can change your cookie settings by reading our cookie policy. Otherwise, we’ll assume you’re OK with our use of cookies.