Showing posts with label GPIO. Show all posts
Showing posts with label GPIO. Show all posts

Thursday, 27 December 2012

Adafruit LCD and Keypad Kit

I purchased one of these this week and having played with it for a few days I have to say it is a great addition to the Raspberry Pi. It is the "Adafruit RGB Negative 16x2 LCD+Keypad Kit for Raspberry Pi" available from the Adafruit website here for $25 plus postage.  Which compared to the price of the Pi seems expensive, but this seems to be an issue with all accessories, as the Pi is just so cheap. For me the extra functionality this add on brings seemed well worth the money.

As its name implies it comes in a kit form which you have to solder together yourself.  I had not done any soldering before, but the Adafruit website claims "Assembly is easy, even if you've never soldered before and the kit can be completed in 30 minutes." and I can attest that I assembled it with no problems although I think it took me more like two to three hours than the 30 minutes (I assume that is the estimated time for someone more experienced at soldering).  The kit basically consists of a circuit board which is identical in size to the Pi and assembly involves soldering all of the components onto that board.

Once completed you have a unit which sits on top of your Pi connecting to the GPIO pins on the top left corner and resting on the ethernet port on the bottom right corner.  (When the model A is released early next year I guess that Adafruit will have to add some more parts to the kit to make up the height difference for the missing ethernet port).  You get a two row text display with sixteen characters on each line and a back light which you can change the color of for the whole display via code.  There are also five input buttons in the bottom left arranged in a directional pad configuration with a select button to the one side.

 
These look like they will be great for all sorts of projects, removing the need for a full keyboard, but in combination with the screen offering a full range of interaction with your projects.  My only slight criticism (and indeed my only criticism about the whole product at all) is I think these would have been better in the bottom right corner where the board is supported by the ethernet port.  Where they are, it feels if you pressed the buttons too hard it could dislodge the board from the Pi.  But to be fair I know nothing about circuit board design and me saying "can't you just move that bit over there?" about something which might be in fact quite difficult, could well be a rather unhelpful comment.  Maybe this could be a 3D printing project for someone to build some sort of support for that corner?
 
In the bottom right of the board is a small potentiometer which once you have your board assembled and running you use to adjust the contrast (using a small screwdriver) to get the display nice and clear (apparently each LCD screen is slightly different, hence the need to manually set this.)
 
Once you have the board assembled and connected to your Pi it is time to get some code running on it.  There is some sample code to get you started on the Adafruit website here.  I found it did not work for me first time and I had a panicked moment of thinking my soldering job was not up to scratch.  But after a quick Google of the error message I found it was in fact something I could fix from the software side of things.  In fact just re-reading the instructions as I write this, I realise I missed the very first instruction:  "edit /etc/modules (sudo nano /etc/modules) and add: i2c-bcm2708 i2c-dev to the end of the file. Then save and reboot to enable the hardware I2C driver.". So if it doesn't work first try for you, try what I did not bother to do and recheck that you followed all of the instructions!  After that try a Google search on your error message and then an inspection of your solder work.
 
My first actual useful project with it was to get my Pi to display its IP address when it boots up.  Great for being able to remotely connect into it without connecting a keyboard or monitor.  When I have time I will write up a full step by step guide on how to get this working.


Tuesday, 24 July 2012

First Look at the GPIO Pins

One of the things that excites me about the Pi, is the ability to use the GPIO pins to control external devices.  Now I don't have much of an electronics background so this is all going to be pretty new to me.  I thought a good place to start was the article in the second edition of MagPi (the Raspberry Pi magazine which is an excellent read and I think compulsory reading if you are interested in the Pi).

Back in 2011 when I first got interested in the Pi project I thought I'd try and learn some basic electronics and so bought these from Amazon*:


Checking the components list I found my electronic kit had everything I needed.  All I needed now was a way to connect to the header pins on my Raspberry Pi.  According to the article I needed female to male jumper wires.  Now this was Sunday evening and I didn't want to order them off the internet and have to wait for them to arrive.  I wanted to start playing right then!  So I thought I'd go down to Radio Shack (a mere 5 minute walk from my house) and see if they had them...

Well, following my Radio Shack visit I have two pieces of advice for you.  Firstly if you want the sales assistants to leave you alone in Radio Shack then hang out in the electrical components section.  I'm sure if I had been looking at mobile phones I would have had multiple people ask if they could help me, as it was I got a pointer to the area of the store I needed as I walked in and then while I searched through draws of components for a good twenty minutes, nobody asked me if they could help.  Next time I'm in there looking at phones and someone asks if they can help me, I'm going to make sure I have a nasty electronics question ready for them.

But anyhow after twenty minutes of searching I couldn't find any jumper wires, so instead settled on these which I figured I could attach to the ends of wires I already had and then attach to the pins:


Which brings me to my second piece of Radio Shack advice: These are NOT the right parts!  As it happens I have managed to use them to hack a solution out of, which will do for now, but it's not one I'd recommend so I'm not going to go into the details of it here.  When I have a more permanent solution I will let you know.

 


I hooked up the circuit, following the digram from the magazine and fired up the RasPi.  Nothing went pop and there was no black smoke so all good so far.  Then I pressed the button and still no black smoke, but the faint shining of the LED; looks like I got it right!


Next step was to get was to install the GPIO drivers.  Now I hadn't yet connected my Pi to the internet, but no problem I just took my USB pen drive from my Pi and used my notebook to download the required file to the pen drive before returning it to the Pi. Then followed all the instructions without problem, until:

sudo python setup.py install

At which point I get an error message about not being able to download a requirement.  Looks like my Pi needs the net after all.  So I do actually have a network cable, the only issue with it is the length.  So the router gets pulled out from behind the sofa and into the middle of the room and then moving the Pi away from the monitor a bit gets the whole thing to reach.  Plugging the cable in makes some new lights light up on the Pi and then rerunning the command above works.

Next step is to create my Python program.  I manage to create the text file using the right click menu then using open with, I find my OS has a python editor pre-installed, nice!

I type in the code carefully as per the magazine, go to run it and get:

"Unexpected Indent"

What!?!  Python cares about how I lay out my code?  Python reads whitespace? Surely not?  But yes, indeed Python does care about indentations. Interesting...  I do see why this could be a good thing to enforce a standard coding style, but it worries me that there is code that I cannot see.  But removing one of the tabs from the line "<tab><tab>if mybutton == False:" fixed the problem and I had a working program which I was controlling with an external switch.

This is something I have been interested in doing for many years and have never even come close with any of my previous computers.  With the Raspberry Pi, I have a working prototype in a single evening.  Impressive stuff!