Pi screen frame New temperature sensor for Feather controller Julian Rogers Home Home

Development of Pi touch screen supervisor for the Feather and Arduino controller

Under construction

I developed the Python software running on my Raspberry Pi with “Official Touchscreen” to switch between several controllers by selecting the IP address and port with a Tkinter button. Now I wanted to set the Pi up on a shelf in my living room. It occurred to me that it would be nice if the Pi could double as a photo frame while it was not being used to monitor and control things (which is the majority of the time).

When left to itself, the Pi screen goes blank after a period of time and, with the touch screen, it can just be prodded to bring things back to life. There is no built in facility to turn this energy saving feature off or to substitute a slide show type screen saver. However, a trawl through the forums shows that this has been done already.

The blank screen can be turned off by starting a terminal window and doing a bit of editing:

sudo nano /etc/lightdm/lightdm.conf

Then scoll down past the [Set Defaults] section and enter:

# don't sleep the screen!

xserver-command=X -s 0 -dpms

Then F3 to write to disc. Hopefully this will work as it did for me, although, there has been a lot of discussion on the Web over screen blanking across the years. There have been lots of solutions proposed and lots of people saying it just didn't work for them!

(For this, I have to thank the good people posting on


Now for the slide show.  Here I have to thank J.A.McNaughton for his screensaver script which uses the image display software “feh” and “xprintidle” which detects inactivity on the computer. Then follow: http://jamcnaughton.com/2014/09/05/simple-slideshow-screensaver-script-for-ubuntu/

The shell script needs to be made executable to allow it to be run. In File Manager, navigate to the file and right click on it. Left click on “Permissions” and change “Execute” to “Anyone”. (Alternatively, in Terminal use chmod +x screensaver.sh

The only problem is that feh seems to expect Esc to be pressed on the keyboard to exit and the whole point of the set up is that there is no keyboard! Perhaps it is possible to generate an Esc from the touch screen but I don't know how to do it!

A way out is to plug in a circuit which can act like a USB keyboard and simulate the Esc key being pressed. The Adafruit (5v) Trinket can do this, https://learn.adafruit.com/trinket-usb-keyboard/code?view=all#wiring. I have set this up on a bread board with a push button switch and it works perfectly! Note, the Trinket needs to be programmed to run at 16MHz.

I am hoping to mate this with an Adafruit touch sensor (https://learn.adafruit.com/adafruit-capacitive-touch-sensor-breakouts/downloads?view=all) and arrange this so that touching the top of the Pi screen frame will generate the Esc and break out of the slide show. Now I have to buy a very short type A to micro-USB cable. I have found one on eBay about 150mm long which should do the trick.

5 volt Trinket programmed to output a keyboard Esc when the button is pressed.


TrinketKeyboard, generates Esc characters

Adpted from Adafruit Industries example


adapted for adafruit momentary touch switch


//program at 16MHz, programmer is USBtinyISP

#include <TrinketKeyboard.h>

//next 3 variables are to limit the generation of Esc characters to 1 every 7 //seconds

boolean flag = false;   

int count1 = 0;

int count2 = 0;

void setup(){  

  pinMode(0, INPUT);   // the switch is connected to pin 0

  // start USB stuff



void loop(){

  // the poll function must be called at least once every 10 ms

  // or cause a keystroke

  // if it is not, then the computer may think that the device

  // has stopped working, and give errors


  if (digitalRead(0) == HIGH && !flag){

    // send Esc


    // this releases the key (otherwise it is held down!)

    TrinketKeyboard.pressKey(0, 0);

    flag = true;    //no more Esc characters until flag is cleared    



  if(count1 == 20000){

   count1 = 0;



  if(count2 == 100){

   count2 = 0;

   flag = false;



Adafruit momentary touch switch doing a more elegant job than the push button!

This is the program using the Adafruit library to simulate a USB keyboard.

The switch is very sensitive, so much so that putting a piece of perspex on it will trigger it so I am keeping my fingers crossed that I can incorporate it in the Pi’s frame without causing it to be permanently on.

Next, making a frame to conceal the touch switch.

Ultimately, I probably want the screen saver and the Python program to start up automatically on powering up the Pi. For now, however, I want to be able to start everything manually but easily without a keyboard. I write a script to run the Python program by just double clicking on the script file.

I start Terminal then start nano with a new file called f.sh

    sudo nano ./f.sh

Then, once nano starts:


   python3 ./progs/feather_control22a3a.py

Where “feather_control22a3a.py” is my Python program located in a directory called “progs”.

Save the script (F3 to save, CtrlX to exit. Them make the file executable:

sudo chmod +x ./f.sh

Now double clicking on f.sh located in file manager will start the Python program directly (following a request for confirmation). (The screensaver script  should be started first!)