Connecting an Arduino to a Raspberry PI using I2C

Some time ago I created a weather station using a Raspberry PI and an off the shelf weather station, connecting the two via USB.

However, for some time not I’ve been meaning to create a weather station from scratch – i.e. one or more Raspberry PI’s which connect to the network (via Ethernet or WiFi) and directly monitor the sensors directly.

Now the problem here is that some sensors are analog – for example the leaf, soil and UV sensors I have generate an analog signal so we need an ADC (Analogue to Digital Converter) which the Raspberry PI doesn’t have.

So we have two possible solutions:

  1. Add a Raspberry PI compatible ADC
  2. Use an Arduino

With the parts I have available, the Arduino won, not just on available ADC channels but also with the additional digital ports available.

Now how to connect it to the PI? Well the easiest way is to use USB, however the PI only has two USB ports (one for the Model A) and as I’m intending to use Model A’s for the final station I need that for WiFi (there won’t be room or power for hubs) so USB is out.

There’s RS232 which both support, however the PI runs on 3v3 whilst the Arduino (UNO) is 5v so I need to add a level converter between the two. It also limits me to just one arduino and I might need to use more than one so another solution is needed.

Continue reading “Connecting an Arduino to a Raspberry PI using I2C”

Setting up a Weather WebCam on Linux

Weather webcams are always popular and it is easy and free to set one up yourself.  This article will show how to setup a simple USB webcam to produce still images and serve them on a local apache webserver.

Continue reading “Setting up a Weather WebCam on Linux”

Installing a USB Weather Station on a Raspberry PI part 2

In the first article I covered how to install a weather station on a Raspberry PI. In the second part I’ll cover how to get it to upload data on an hourly basis to a website using FTP.

Getting the station to run hourly

First we need to get the station to run hourly. To do this I created a script called weatherupload which I placed under /usr/local/bin

pi@kell: ~$ sudo vi /usr/local/bin/weatherupload

Enter the following:

#!/bin/bash
cd /usr/local/weather
python Hourly.py -vvv data

Once saved make it executable and then edit the main crontab:

pi@kell: ~$ sudo chmod +x /usr/local/bin/weatherupload
pi@kell: ~$ sudo vi /etc/crontab

At the end of the file you need to add the following:

0 * * * * root /usr/local/bin/weatherupload

Save it and now every hour it will now run.

Note: I’ve placed it there and not under /etc/cron.hourly because

  1. cron.hourly runs once an hour, but not necessarily at the top of the hour. I a later article when I add twitter you want the tweet to be close to 0m rather than at a random time.
  2. I’ve found in the past that using crontab -e doesn’t always work, even for root but in the core crontab it just works

Uploading to a website

First to generate the graphs pywws uses gnuplot so we need to install it:

pi@kell: ~/sudo apt-get install gnuplot

Next we need to add some details to the stations weather.ini file. At the top theres a section called paths. Make sure those point to the relevant templates and graph_templates directories in your pywws install.
Next under the hourly section you should see a pair of lines:

plot = []
text = []

You need to add the plots and pages that need to be generated:

plot = ['7days.png.xml', '24hrs.png.xml', 'rose_24hrs.png.xml', 'rose_7days_nights.png.xml']
text = ['current.html', '24hrs.html', '6hrs.html', '7days.html', 'feed_hourly.xml', 'allmonths.html']

Finally theres the ftp section which needs configuring with the remote ftp server (your web host will give you these):

[ftp]
secure = False
site = ftp.example.com
local site = False
user = myaccount@example.com
directory = /weather/
password = mypassword

That’s about it. Now when you run the hourly script it will generate some simple pages & images to your website.

You can see an example of this over at maidstoneweather.com – although the uploaded templates only form part of that site.

%d bloggers like this: