Interfacing a MikroElektronika SHT1x Click Board with a Raspberry Pi

By , August 24, 2014 5:02 pm

Overview

After the success of my previous MikroElektronika GPS Click, and Thumbstick Click board blog posts, I thought I'd write up a tutorial on reading temperature and humidity with a MikroE SHT1x Click board and a Raspberry Pi. This blog post includes a python script that reads the SHT1x Click board data using I2C and displays the temperature, humidity, and dew point results from the sensor.

Raspberry PI Interfacing Notes

Raspberry Pi and SHT1x Click Board

The SHT1X Click board is connected to a Raspberry Pi using the MikroE Pi Click Shield. This shield connects to the Raspberry PI GPIO header pins and lets you attach MikroBus format Click boards.

If you don't have a Pi Click Shield or a SHT1x Click board, you can get one from the MikroElektronika Webstore, or from Digikey, or Farnell.

Pi Click Shield

The SHT1x Click board uses an I2C based Sensiron SHT11 module for reading the temperature and humidity. The temperature sensor measures a range of -40°C to +100°C in half degree increments. The board is powered on 3.3 Volts from the GPIO header on the Raspberry PI.

For more details on the sensor, take a look at the SHT1x PDF datasheet:

Sensirion_Humidity_SHT1x_Datasheet_V5.pdf

SHT1x Click

The SHT1X board connects to the Raspberry Pi using the following connections:

  • MikroBus I2C SDA = RPI Pin 3
  • MikroBus I2C SCL = RPI Pin 5

Download the Library

You can download my ACH-SHT1x-Click-RPi-Demo.zip example from the Libstock site:

http://www.libstock.com/projects/view/1084/ach-sht1x-click-rpi-demo

Admin Privileges Required

Scripts that use the GPIO and I2C hardware interfaces need to be run with sudo since GPIO reading requires admin privileges on Linux.

That means you need to run the sht1x_click.py demo python script using:

Driver Setup and Installation

Step 1. Download the Library

Step 2. Expand the file in the Raspbian File Manager using the right click "Expand Here" contextual menu item.

Step 3. Install the rpiSht1x library using:

Step 4. To verify the library is installed correctly check if the SHT1x module is listed in the python interactive help section:

To quit the python interactive session type:

Step 5. Now, let's run the sht1x_click.py script from the terminal:

If the script runs correctly you will be presented with the following output in the terminal:

sht1x_click.py Script

You can quit the python script by pressing the Control+D hotkey.


SHT1X Click Board Demo Ported by Andrew Hazelden

Based upon the code and library from the pypi.python.org website:
https://pypi.python.org/pypi/rpiSht1x/1.2

rpiSht1x Created by Luca Nobili (lunobili):
https://bitbucket.org/lunobili/rpisht1x

flattr this!

Interfacing a MikroElektronika Thumbstick Click with a Raspberry Pi

By , August 22, 2014 5:01 pm

Overview

I thought it would be interesting to look at the process of interfacing a MikroBus format "Click" board to a Raspberry Pi. The MikroElektronika Thumbstick Click board provides 2 analog joystick x/y axis input channels via an onboard SPI MCP3204 IC, and a center joystick button via GPIO input. I've put together a simple python script for this blog post that reads the Thumbstick Click board data using the open source webiopi library on Raspbian Linux.

Raspberry PI Interfacing Notes

Raspberry Pi and Thumbstick Click Board

The Thumbstick Click board is connected to a Raspberry Pi using the MikroE Pi Click Shield. This shield connects to the Raspberry PI GPIO header pins and lets you attach MikroBus format Click boards.

If you don't have a Pi Click Shield, or a Thumbstick Click board you can get one from the MikroElektronika Webstore, or from Digikey, or Farnell.

Pi Click Shield

The Thumbstick Click board uses an SPI based MCP3204 module for reading the joystick axes. The ADC0 channel is used for the y-axis and the ADC1 channel is used for the x-axis. The board is powered on 3.3 Volts from the GPIO header on the Raspberry PI.

Thumbstick Click

The joystick "center click" button is read using the GPIO input 17 on the Raspberry Pi and has an inverted logic state where the button clicked=0, and the button unclicked=1.

If you take the rubber joystick cap off the thumbstick you can see the mechanical push button that responds to the clicking motion.

Thumbstick Click Button

Download the Library

You can download my ACH-Thumbstick-Click-RPi-Demo.zip example from the Libstock site:

http://www.libstock.com/projects/view/1078/ach-thumbstick-click-rpi-demo

Admin Privileges Required

Scripts that use the GPIO and SPI hardware interfaces need to be run with sudo since GPIO reading requires admin privileges on Linux.

That means you need to run the thumbstick.py demo python script using:

Driver Setup and Installation

Step 1. Let's enable SPI on the Pi using the following terminal command: ( Tip from the projects.drogon.net blog)

Then check the SPI module is active with:

You should now see the following module listed:

Step 2. Install webiopi so it is easy to use SPI inputs from python scripts.

You can download the free webiopi library from:
http://sourceforge.net/projects/webiopi/files

Then you need to Un-gzip the file "WebIOPi-0.7.0.tar.gz". You can do that by right clicking on the file and using the "Extract Here" tool on Raspbian.

Run the webiopi setup program with:

It is a good idea to setup a webiopi username and password for the integrated server module:

Note: The webiopi generated password file is stored in:
/etc/webiopi/passwd

Step 3. Edit the webiopi config file with:

Scroll down to line 96 in the webiopi "config" file and add the following code:

This tells the webiopi software that the Thumbstick Click board uses the MCP3204 SPI based chip for ADC input.

Step 4. Run the thumbstick.py demo script using:

If the script runs correctly you will be presented with the following output in the terminal:

Thumbstick.py Script

You can quit the python script by pressing the Control+D hotkey.

Using the Webiopi WebGUI

As an optional step, you can start the webiopi server module for http based SPI and GPIO access.

Webiopi Webgui

Note: You need to set up the webiopi password in step 3 if you want to use the webserver module.

The webiopi server module creates an http hosted webgui page that updates on your pi. After you start the server module you can access it using either:

http://localhost:8000

or

http://<write your raspberry pi ip address here>:8000

You can start webiopi's webserver module with ONE of the following options:

Start webiopi from a terminal session with:

To start webiopi in the background:

To start webiopi at boot:

Webiopi GPIO Header

Webiopi GPIO Header

You can use the webGUI to read the current GPIO pin state from a web browser. This is interesting as you can see the input and output mapping and see the binary state of each of the GPIO pins.

Webiopi Device Monitor

Webiopi Device Monitor

You can also watch the live values on the Thumbstick's 2 ADC channels (Joystick X & Y Axis) using the webiopi "Device Monitor" webpage.

flattr this!