Abstract2actual
  • Home
  • Blog
  • Gallery
  • Buy stuff
  • Contact
  • About

Programming the Adafruit PiTFT buttons

8/28/2016

0 Comments

 
After installing the Adafruit PiTFT display to my Raspberry-Pi, I wanted to use the buttons on the panel.  I searched high and low for examples of this, but couldn't find what I was looking for.  Ultimately I want to use one switch to port the display back and forth between the HDMI monitor and the TFT display and another switch to switch the wireless from a LAN configuration to an ad-hoc configuration.  I found a nice article that teaches the basics of using switches connected to the GPIO header here. https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/  This was really helpful in developing the script I wound up building.
​
I'm still having trouble figuring out how to call the framebuffer and network using a script, so I chose to takle something a little simpler, just to prove the concept of using the buttons to execute Pi commands.  The TFT has a backlight that can be turned on and off, and there's a program called OctoPiPanel that can pretty easily be called by a script, so these are what I chose to control.  I programmed the third switch to simply output a line of text to the terminal indicating that the switch had been pressed and what state the toggle was in.

I found a reference at https://github.com/jonaslorander/OctoPiPanel that showed me how to run OctoPiPanel.  Once I had it installed I had to get the Octoprint API key and copy it to the OctoPiPanel.cfg file.  Then I had to make OctoPiPanel executable.  From that point, I can launch OctoPiPanel from a command line which I will later tie to one of the switches.

The next step was to create a python script that monitors the buttons.  it uses RPi.GPIO to map the switches.  I added some logic to create a two state state engine, so I can essentially treat each switch as an on-off switch even though they are only momentary.  I mapped one switch to start and stop OctoPiPanel and another switch to toggle the LCD backlight.  Finally, I modified the startup script /etc/rc.local to call my monitoring script.
Now I can toggle the backlight and run OctoPiPanel at the press of a button.

I published my work on GitHub here:  https://github.com/TJEmsley/PiTFT-Button-Monitor
0 Comments



Leave a Reply.

    View my profile on LinkedIn

    TJ Emsley

    Lifetime tinkerer.

    Archives

    October 2022
    January 2021
    November 2020
    October 2020
    September 2020
    February 2018
    January 2018
    January 2017
    October 2016
    August 2016
    July 2016
    June 2016
    May 2015
    April 2015
    March 2015
    February 2015
    December 2014
    October 2014
    August 2014
    July 2014
    May 2014
    April 2014
    March 2014
    November 2013
    October 2013

    Categories

    All
    3d Design
    3d Printing
    Open Source

    RSS Feed




Proudly powered by Weebly