Hi, this is a new product post for OpenSprinkler Pi (OSPi) v1.2. Since its original release, OSPi has become a very popular product. This version is a minor revision. The main change compared to version 1.1 is the addition of a PCF8591T 8-bit A/D D/A converter, which provides four independent 8-bit analog input pins, and one 8-bit analog output pin. The reason this has been added is that Raspberry Pi (RPi)’s GPIO pins do not have built-in ADC capability. In order to interface with analog sensors (such as soil moisture sensor, light sensor etc.), you would need an ADC unit. The addition of the PCF8591T chip allows OSPi to provide on-board analog inputs as well as output. This makes it more convenient for your prototyping need. Other than this, the rest of the circuit is pretty much the same as before, with 24V AC to 5V DC switching regulator (based on LM2596S), DS1307 RTC and backup battery, 74HC595 shift register and triacs. Here are two pictures of the OSPi v1.2 board:
If you Google ‘RPi ADC’ you will find plenty of choices of ADC modules and tutorials on how to get them to work with RPi. Why did I pick PCF8591T? There are several reasons. First, it’s low-cost: volume pricing is just a couple of dollars per piece. Second, it provides four independent A/D channels, and one D/A channel. This means you can use one chip to interface with 4 different analog sensors, and additionally you can get one channel of analog output. According to the datasheet, the analog output is implemented with resistor divider chain, which is sometimes a better choice than PWM. Also, it uses I2C interface, so it doesn’t require any extra GPIO pins from RPi. Overall it’s a very attractive choice. The main downside is that it’s only 8-bit. This means the analog input value is on a resolution of 0 to 255, same with analog output. A lot of the other chips provide at least 10 bits of precision. But I figured that 8-bit is sufficient in many cases, so I settled with this choice.
The chip, together with analog pinouts, are located on the right-hand side of the board:
For convenience, I’ve also provided a separate pair of VCC and GND pinouts for each analog channel. The picture on the left below is an example of plugging in a MCP9700 temperature sensor directly to the pinouts; and the picture on the right below shows an LED (with current limiting resistor) plugged into the analog output channel, to allow programmable control of the LED brightness.
Suppose this gets you interested, the next question is how to program RPi to talk to the ADC chip? Fortunately there are plenty of tutorials online. In particular, I found the following posts very useful:
If you are confused and just want a quick demo. Here is a short tutorial to get you started.
First, run sudo i2cdetect 1 to check if the PCF8591T chip is detected. (Note, if you own RPi rev. 1 you should run sudo i2cdetect 0 instead). You should then see a printout like the following. This shows it has detected two I2C devices, one is at address 0x68 (that’s the DS1307 RTC), and one 0x48 (this is PCF8591T).
Next, you can use the i2cget command to read analog values from a particular channel. For example, run
sudo i2cget -y 1 0x48
repeatedly to sample the analog value from channel 0 (pin A0). To change to channel 1 instead, run
sudo i2cset -y 1 0x48 0x01
and then if you run sudo i2cget -y 1 0x48 that will return sampled value of channel 1, and so on.
To enable analog output, use the i2cset command. For example:
sudo i2cset -y 1 0x48 0x40 0xff
where 0xff is the 8-bit analog output value. You can change it to any value between 0x00 to 0xff to enable 256 grades of values. Since the chip is powered by 3.3V supply, that will translate to an analog output from 0V to 3.3V linearly.
The above use shell commands as an example to interface with the chip. There are also WiringPi and Python code examples which can do the same. When I get time I will write a more complete tutorial. For now, try to explore on your own 🙂
OpenSprinkler Pi v1.2 is immediately available for purchase at Rayshobby Shop, at the same old price.