Wednesday, April 1, 2015

63. A Python GUI to control the Pi 2B's GPIO Pins

32,000 page views!!
What do you think of my new Pi2B with its Pibow Coupé Flotilla case from Pimoroni - I think it's even snazzier than the Pi B+ in its red Pibow Coupé case! 

This is just a quick description of a means of making a Graphical User Interface (GUI) using Python (with tkinter, a  Python library for drawing graphics) to show and control the status of the GPIO ports on the Raspberry Pi.

Here's a screenshot, taken on the Pi using the scrot program's command:

scrot -cd 10 -u captureKC.jpg


This is showing that I have selected GPIO pins 23, 24 and 25 as outputs, and when I click on the respective tick-boxes to send these Outputs to High or Low, the RGB LED anodes are activated through the three 330 resistors (Ideally 3 different values of resistors should have been used to get pure white when all are on).

The link to information about scrot is here:
http://www.raspberrypi-spy.co.uk/2013/10/how-to-take-screenshots-on-the-raspberry-pi/

I have temporarily (only temporarily, I hope) lost the ability to run the Pi headless, (and I can't connect to WinSCP  to transfer files from the Pi to the PC!!), so I had to use scrot to capture the window on the Pi, and I exported this file to the PC using a memory stick!

I should probably at this point explain what the above command does:  -cd 10 gives a 10 second countdown before the image is captured, to allow time to put the focus on the correct window, and -u tells it to capture the current active window, rather than the whole screen.  The file captureKC.jpg is written to the current directory of the Pi, in this case, the Home Folder, where my program is.

The reason for the 10 second delay is to allow time for me to leave the current active window (the LXTerminal) and click on the window I wanted to image.

The Python GUI was written by scotty101 and the code is shown below:


You can see that scotty101 intends to put more functionality on this code. Thanks Scotty!

Here is a picture of the very simple connections to the Pi:
You can just see the 330 resistors on the mini breadboard connecting the RGB LED's three anodes to the Cyntech B+ 40-way Paddle Board (previously described in my Post 55 at http://smokespark.blogspot.co.uk/2014/10/55-exploring-pis-gpio-ports.html).  The RGB LED (with all three colours illuminated, as indicated in the screen-shot above) has been covered with a light diffuser (Draft Guinness widget - much better than a table tennis ball).

What I would like to do with this is to develop it to include GUI control of the RasPi Camera.  That would be really coooool !



No comments:

Post a Comment