Lesson 2: Check hardware
- Connect hardware
- Test hardware
In order to be able to do some things we need to connect hardware. In short we’ll be using the following pins on the GPIO header of the Raspberry Pi as follows:
Be carefull with the names and numbers. There are different numbering schemes. We use the BCM scheme here.
In order to avoid connectivity and wiring errors I’ll use a shield that has all the wiring on it. It’s called a IoT shield and the specs are on github.
We do some basic testing with Node RED.
In order to create the test setup it is important to notice that switches function as input devices. LED’s function as output devices.
Let’s wire them together. In the Node RED interface click on all the triangles on the left side until the majority of them are closed. It should look similar to this:
Drag an input node and an output node into the editor. Connect them using a virtual wire.
Double click on the input node and select the corresponding pin (GPIO5, pin 29). Change the resistor setting into ‘pulldown’. Finally enter a name, ‘Switch 1’. Click on ‘Done’ when ready.
Do the same with the output. Select Pin 31 (GPIO6), set type to ‘Digital output’ and name to LED 1. Click ‘Done’ when ready.
Finally activate the flow by clicking on ‘Deploy’ in the upper right corner.
Press the switch. If all goes well de LED will light up when the switch is pressed.
The status of both the switch and the LED is shown as well:
This can be repeated for all connected switches and LED’s.
If you want you can test all sensors easily with a few lines of python.
First you need to install some software. Open a terminal and enter the following commands:
sudo pip install Adafruit_DHT git clone https://github.com/mverleun/IoT-Devices
This will install and download the required files. Next step is to launch the python scripts. Enter the following commands in the terminal to get them running:
cd ~/IoT-Devices/Python ./LEDs-and-switches.py ./Light-sensor.py
What if things go wrong? LED’s only work if the are connected properly. If not try to reverse the pins. Also make sure that you use the proper wiring scheme. There are several scheme’s and if you use the wrong one you’ll be connecting to the wrong pins.
Make sure that you are not running multiple programs at the same time. What if one program tries to turn a switch on while the other wants to turn it off?