Tutorial: Part 2 -Building a Solar Powered Raspberry Pi Weather Station – GroveWeatherPi

Tutorial: Part 2 -Building a Solar Powered Raspberry Pi WeatherGroveWeatherPi Station – GroveWeatherPi

The Raspberry Pi is a fabulous device to on which to build your projects.    The GroveWeatherPi project is designed to show the capabilities of this computer while remaining accessible to a diverse Maker community.

GroveWeatherPi is a Solar Powered Raspberry Pi WiFi connected weather station designed for Makers by SwitchDoc Labs ( www.switchdoc.com). This is a great system to build and tinker with. All of it is modifiable and all source code is included.

This tutorial for building your own Solar Powered Weather Station based on the Raspberry Pi consists of 14 parts.

[include-page id=”gdplinks”]

The GroveWeatherPi is heavily based on Grove I2C Sensors.

What is an I2C Bus and What is On the Bus?

An I2C bus is often used to communicate with chips or sensors that are on the same board or located physically close to the CPU.  It stands for standard Inter-IC device bus.   I2C was first developed by Phillips (now NXP Semiconductors).  To get around licensing issues, often the bus will be called TWI (Two Wire Interface).  SMBus, developed by Intel, is a subset of I2C that defines the protocols more strictly.  Modern I2C systems take policies and rules from SMBus sometimes supporting both with minimal reconfiguration needed.  The Raspberry Pi is one of these devices.

I2C provides good support for slow, close peripheral devices that only need be addressed occasionally.  For example, a temperate measuring device will generally only change very slowly and so is a good candidate for the use of I2C, where a camera will generate lots of data quickly and potentially changes often.

I2C uses only two bi-directional open-drain lines (open-drain means the device can pull a level down to ground, but can not pull the line up to Vdd.  Hence the name open-drain.  Thus a requirement of I2C bus is that both lines are pulled up to Vdd.   This is an important area and not properly pulling up the lines is the first and most common mistake you make when you first use an I2C bus.  More on pullup resistors later in the next section.  The two lines are SDA (Serial Data Line) and the SCL (Serial Clock Line).  There are two types of devices you can connect to an I2C bus.  They are Master devices and Slave devices.  Typically, you have one Master device (The Raspberry Pi in our case) and multiple Slave devices, each with their individual 7 bit address ().

When used on the Raspberry Pi, the Raspberry Pi acts as the Master and all other devices are connected as Slaves.

Figure6

The I2C protocol uses three types of messages:

  • Single message where a master writes data to a slave;
  • Single message where a master reads data from a slave;
  • Combined messages, where a master issues at least two reads and/or writes to one or more slaves.

Lucky for us, most of the complexity of dealing with the I2C bus is hidden by drivers and libraries from the user.

Pullups on the I2C Bus

One import thing to consider on your I2C bus are pullup resistors.  The Raspberry Pi has 1.8K ohm (1k8) resistors already attached to the SDA and SCL lines, so you really shouldn’t need any additional pullup resistors.  However, you do need to look at your I2C boards to find out if they have pullup resistors.  If you have too many devices on the I2C bus with their own pullups, your bus will stop working.  The rule of thumb from Phillips is not to let the total pullup resistors in parallel be less than 1K (1k0) ohms.   The GroveWeatherPi has build in pullup resistors on all the I2C buses.

The I2C Bus on Weather Pi

At SwitchDoc Labs, we love data. And we love I2C devices. We like to gather the data using lots of I2C devices on our computers and projects. Project Curacao has a total of 12, GroveWeatherPi has 11 devices and SunRover (a solar powered rover under development at SwitchDoc – you will see it in 2017) will have over 20 and will require one I2C bus just for controlling the motors. We are always running into conflicts with addressing on the I2C device. Since there are no standards, sometimes multiple devices will have the same address, such as 0x70 and you are just out of luck in running both of them on the same I2C bus without a lot of jimmy rigging.

To get around this addressing problem (and our conflict with an INA3221 on SunAirPlus and the Inside Humidity Sensor) we added an I2C Bus Multiplexer to the design which allows us to have many more I2C devices on the bus, irregardless of addressing conflicts. Here is our current list of I2C devices in GroveWeatherPi including which I2C bus the devices is on in the GroveWeatherPi design:

I2CBus

Note that GroveWeatherPi only uses Bus 0, Bus 1 and Bus 2.

Here is what the I2C bus looks like on the Raspberry Pi after assembling the GroveWeatherPi project. This is the output from the example code with the I2C 4 Channel Mux (hence there are 4 independent busses shown for the I2C bus).

I2C Mux
4 Channel Grove I2C Mux
Test SDL_Pi_TCA9545 Version 1.0 - SwitchDoc Labs

Sample uses 0x73
Program Started at:2016-08-03 21:50:40

-----------BUS 0-------------------
tca9545 control register B3-B0 = 0x1
ignore Interrupts if INT3' - INT0' not connected
tca9545 control register Interrupts = 0x0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- -- 
40: 40 -- -- -- -- -- -- -- 48 -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- 
70: -- -- -- 73 -- -- -- 77                         

-----------------------------------

-----------BUS 1-------------------
tca9545 control register B3-B0 = 0x2
ignore Interrupts if INT3' - INT0' not connected
tca9545 control register Interrupts = 0x0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          03 -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- 73 -- -- -- --                         

-----------------------------------

-----------BUS 2-------------------
tca9545 control register B3-B0 = 0x4
ignore Interrupts if INT3' - INT0' not connected
tca9545 control register Interrupts = 0x0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- 48 -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- 73 -- -- -- --                         

-----------------------------------

-----------BUS 3-------------------
tca9545 control register B3-B0 = 0x8
ignore Interrupts if INT3' - INT0' not connected
tca9545 control register Interrupts = 0x0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- 73 -- -- -- --