scotty101
Posts: 2291
Joined: Fri Jun 08, 2012 6:03 pm

Python Tkinter GPIO User Interface

Wed Apr 24, 2013 9:04 am

Hi

I've written a tkinter based GUI for viewing the state of GPIO pins, setting the output high/low and setting the pin as an input or output.

The code is pretty basic (and lacking comments) at the moment but its has proved invaluable for debugging Raspberry Pi projects. Only requirement is the RPi.GPIO module.

[18 Feb 2015 Edit] - Source code now on GitHub https://github.com/scotty3785/python/bl ... UI/gpio.py

Image

Hope someone finds it useful
Last edited by scotty101 on Tue Dec 06, 2016 11:58 am, edited 4 times in total.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Python Tkinter GPIO User Interface

Wed Apr 24, 2013 9:59 am

Looks very useful code base :)
Ta
Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

scotty101
Posts: 2291
Joined: Fri Jun 08, 2012 6:03 pm

Re: Python Tkinter GPIO User Interface

Wed Apr 24, 2013 7:06 pm

Revision 0.2

I've updated the code to add a simulated LED widget to show the current state of the GPIO pin.

[18 Feb 2015 Edit] - Source code now on GitHub https://github.com/scotty3785/python/bl ... UI/gpio.py

Changes
  • Added LED Widget to show the current state of the LED
  • There is actually some comments in the code
  • Ability to invert the state of inputs if there is a pull up resistor in the circuit
  • Runs GPIO "clean up" when the window is closed.
Last edited by scotty101 on Wed Feb 18, 2015 9:15 pm, edited 2 times in total.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

paully323
Posts: 1
Joined: Fri Apr 26, 2013 10:23 pm

Re: Python Tkinter GPIO User Interface

Fri Apr 26, 2013 10:30 pm

Where can I download the code?

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Python Tkinter GPIO User Interface

Sat Apr 27, 2013 7:07 am

paully323 wrote:Where can I download the code?
Click on New Code in the previous post - it's a link.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

Spong23
Posts: 20
Joined: Wed Sep 19, 2012 2:42 pm

Re: Python Tkinter GPIO User Interface

Wed May 15, 2013 2:56 pm

Thanks very much scotty101 this is a really useful piece of software.
I'm an experienced electronics engineer and want to use the RPi as a host controller for a data acquisition/process control system and have learnt the basics of python. The next step was to try to use tkinter to create a simple visual diagnostic/control panel but after considerable time thinking how to do it and getting nowhere I came across this thread.
I'm much obliged to you,many thanks and well done.

scotty101
Posts: 2291
Joined: Fri Jun 08, 2012 6:03 pm

Re: Python Tkinter GPIO User Interface

Thu Jun 27, 2013 1:45 pm

Very welcome. It has become invaluable for debugging my own projects.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

LloydSeaton
Posts: 5
Joined: Sun May 19, 2013 7:52 am

Re: Python Tkinter GPIO User Interface

Sat Jul 27, 2013 2:23 am

Greatly appreciative of your contribution as I'm completely new to Python and Tkinter but was able to hack a usable/useful derivative from your program to help in testing some of my PCBs of the piCocktails series. Thank you very much indeed! The following is a link to my derivative program on Google Drive in case somebody wants to download and try it:
https://docs.google.com/file/d/0B7RZGwt ... sp=sharing

LloydSeaton
Posts: 5
Joined: Sun May 19, 2013 7:52 am

Re: Python Tkinter GPIO User Interface

Thu Aug 01, 2013 10:17 am

I've improved on my previously posted program for examining/changing RasPi GPIO ports and posted it for public access as follows:
https://docs.google.com/file/d/0B7RZGwt ... sp=sharing
Main difference is that you can now control all of the GPIO ports but they remain passive until called upon to change.

spoolboyy
Posts: 23
Joined: Sat Mar 03, 2012 10:13 pm

Re: Python Tkinter GPIO User Interface

Thu Aug 01, 2013 5:08 pm

Thanks, what a great little app! This will make an excellent debugger tool.

- A

scotty101
Posts: 2291
Joined: Fri Jun 08, 2012 6:03 pm

Re: Python Tkinter GPIO User Interface

Tue Aug 13, 2013 2:46 pm

LloydSeaton, Great updates. I had added some Pull Up/Down capability too.
I like the passive mode and will add that to my version too.
I'm very pleased to see my 1hour code "hack" being used by people.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

scotty101
Posts: 2291
Joined: Fri Jun 08, 2012 6:03 pm

Re: Python Tkinter GPIO User Interface

Wed Feb 25, 2015 7:30 pm

Image

Source code now on GitHub https://github.com/scotty3785/python/bl ... UI/gpio.py

The latest version has some new features
  • Supports the 3 different GPIO revisions and will autodetect to display the correct version.
  • Shows (and disables) the GPIO pins currently assigned in an alternate function e.g. SPI
Attachments
2015-02-25-192503_690x476_scrot.png
2015-02-25-192503_690x476_scrot.png (34.62 KiB) Viewed 16387 times
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

User avatar
RogerW
Posts: 255
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: Python Tkinter GPIO User Interface

Thu Feb 26, 2015 4:58 pm

A very nice piece of work and useful!

Roger Woollett

kcranley
Posts: 16
Joined: Fri Jan 20, 2012 10:33 am

Re: Python Tkinter GPIO User Interface

Wed Apr 01, 2015 10:29 am

This looks like an extremely useful GUI. It would be nice to do something similar for the Raspberry Pi Camera (control settings, take pictures etc).
Good work!

scotty101
Posts: 2291
Joined: Fri Jun 08, 2012 6:03 pm

Re: Python Tkinter GPIO User Interface

Wed Apr 01, 2015 12:07 pm

Buy me a camera and I'll do it :D
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

SinewaveMan
Posts: 12
Joined: Sun Jul 19, 2015 5:17 am

Re: Python Tkinter GPIO User Interface

Sat Aug 01, 2015 10:25 am

Thank you scotty101 for this very useful application. I am new to Rpi and Python but have a few years with VBA. I am busy planning some time lapse photographic control apps and will use your inspirational "invention".

I do have two questions and don't know if this is the right place, but here goes:

1) During operation of your application, after a mouse click, the cursor (little arrow) disappears until I move the mouse. Is this something to do with the imported Tkinter, or can it be corrected in the Python code? Or is it maybe something to do with my USB drivers (I'm using a cable USB mouse).

So now I have found that it is NOT a problem with Tkinter or the USB drivers. In the topic "mouse pointer disappears" it is suggested to change the name of /usr/share/icons/Adwaita. This fixes the disappearing problem, but I don't know if this could cause other problems.

2) This is more to do with general Python operation, but where does Python find the "import" files? Namely Tkinter or tkinter.
Last edited by SinewaveMan on Sat Aug 01, 2015 5:35 pm, edited 1 time in total.

scotty101
Posts: 2291
Joined: Fri Jun 08, 2012 6:03 pm

Re: Python Tkinter GPIO User Interface

Sat Aug 01, 2015 5:31 pm

1. Does this happen with all python tkinter GUIs?

2. Try this to find out where they are installed http://stackoverflow.com/questions/2697 ... le-sources
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

SinewaveMan
Posts: 12
Joined: Sun Jul 19, 2015 5:17 am

Re: Python Tkinter GPIO User Interface

Sat Aug 01, 2015 5:42 pm

scotty101 wrote:1. Does this happen with all python tkinter GUIs?
[/url]
I guess probably "yes". But see my "edit" above. It is evidently a "bug" in the raspbian code because it happens in many other places too. For example while using Chromium browser the cursor often disappears when I click on some text. Then it re-appears when I move the mouse. BTW: I love your tkinter - will be studying the usage in depth!

Co Termors
Posts: 12
Joined: Fri Mar 25, 2016 10:58 am

Re: Python Tkinter GPIO User Interface

Fri Mar 25, 2016 12:00 pm

Scotty101 and Lloys Seaton,

We thank you so much for your wonderful GPIO programs. They go a long way to setting up a Relay Control program we're trying to develop to possibly control a model railroad setup.

We're both rookies at Python. Thanks to your program we are now able to activate all four relays and read all four inputs using GPIO 17,18,27 and 22 for outputs, and GPIO 23,24,25 and 4, for inputs. We were able to modify the program labels to show Relays and Inputs, and control the Relays via Menu clicks, and alter the LED in response to Inputs.

Our next step has been a total failure so far under either of your wonderful Tkinter GPIO programs. We want to activate each of the relays, automatically via the program as a result of an input on one of the four input ports, without having to click on the menu. Something like the fan automatically coming on in the cooling system of a car, when the engine gets too hot).

The variety of errors we've managed to trigger is impressive and usually 4 or 5 of them at once, varying from 'the GPIO port has not been set' to complaints about global variables not set, but nothing has ever started the fan. We've tried to adapt 6 or 7 different programs out there, all to no avail.

We've been able to do this quite successfully in Python, but have hit a brick wall within the Tkinter menu system.

Can either of you suggest a way to do this? Your help would be greatly appreciated.

Co Termors

Return to “Python”

Who is online

Users browsing this forum: No registered users and 16 guests