Wrangling the GPIO Port
Hickmat 100000QA3T Comments (3) Visits (6699)
Sooo what I really got my Raspberry PI for was to play with sensing and controlling, which in the case of the PI means getting to grips with the GPIO (General Purpose Input / Output ) port on the PI. For those who are not familar with the layout of the PI here is a picture of a real Pi along with nice overview schematic...
So the GPIO (for the less technical) is the spiky hedghog on the top left of the board :-) (basd on the orientation of the picture above). So having located it I needed to construct a break-out board to do the following:
A word of caution... I not an electronics expert everything I've done has been based on materials I have found on the Web. What I am about to describe is what worked for me. I suggest you review some other materials as well to ensure you are comfortable with what you are doing or you may fry your PI - so to speak.
There are a numerous Blogs / Wikis explaining how to create a break-out board but the approach I took was to rummage through Maplin and find a set of connectors that would allow me to connect the GPIO pins to a bread-board. For simplicity I made sure that the pins were connects to the termnial strip with number that corresponded to the actual GPIO pin number as shown on the PI's PCB. The follow picture shows the configuration I am using:
Once I had access to the physical pins I needed to look for a way to drive them from the PI. As this was a simple set up test I decided to use the very neat gpio-admin tool from Quick2Wire. This can be found here. This tool allows the GPIO pins to be exported as files within the PI's file system which allows pins to be set easily by echo'ing 0 or 1 to the file representing the exported pin. So the next step was to create a basic circuit to allow an LED to be driven. The following shows the set up I used:
So with the circuit built and and gpio-admin installed it was just a case of testing it... So using SSH I signed onto my PI and executed the following steps.
That's it you can now control something via the PI. If you want to sense you can use the gpio-admin tool and in step 2 set the direction to in rather than out (you will also have to create a loop to poll the value from the mapped file).
In the following articles I'll build on this basic model and create a java based interface layer to allow me to control the pin via MQTT. But that's going to take a bit longer to write up :-)