Part of the reason I bought a 3D Printer was to add some polish and portability to Raspberry Pi and Arduino projects, my favorite of those projects has been the 3D Printed Touch Pi battery powered Raspberry Pi case with Adafruit 3.5” PiTFT Touchscreen.

After building a Raspberry Pi laptop with a Motorola LapDock I have been looking for a reasonable way to make the Pi more portable. Even when it worked the LapDock based laptop was a loosely connected horror of strange cables and adaptors and Konami code like startup sequences.

I also saw the Pi-Top laptop, but it costs more than my ChromeBook 2 did and is huge. I have the small keyboard and mouse in the original Pi-Top kit and really just wanted a way to do simple tasks like opening the desktop, restarting, shutting down or setting up wifi without having to use the keyboard at all.

For about a hundred bucks the Touch Pi is a really nice way to have a neatly contained battery powered portable raspbery pi with touchscreen. Wanting to learn a little bit of python I took a few different projects and cobbled together a menu for my Touch Pi to handle many common tasks, as well as displaying the hostname and IP address to make it easier to connect to the Touch Pi remotely.

Touch Pi Menu

You can find the code for the menu here Simple PiTFT TouchPi Menu System.

After using my new menu for a few days I found the awesome PiFi project and added a WiFi Settings button that runs the PiFi python script. My only issue with the Touch Pi at this point was that it would shut down without warning when running on the battery.

I read a bit a about setting up some sort of battery indicator using the PowerBoost and it looked annoying, so I soldered half a female jumper wire to the LBO - Low Battery Output pin on my PowerBoost and plugged it into pin 21 (Bottom Right Pin) of the GPIO on my B+. The documentation of the LBO pin appears to be cut off in adafruit’s docs, but it does say the pin defaults to high. One of my favorite things about the pi and adafruit products, is that the little bit of documentation available is really all I needed to know to get started.

Touch Pi LBO GPIO Wiring

To see how the LBO pin behaved I wrote a small python script and saved it on my pi. I then ran it from a SSH session on my desktop so that I could see the output from just before the battery died. When running the following script I would see 6-9 Pin Low prints before the pi powered off (60-80 seconds before powerdown)

import RPi.GPIO
import time
RPi.GPIO.setmode (RPi.GPIO.BCM)

RPi.GPIO.setup(21, RPi.GPIO.IN, pull_up_down=RPi.GPIO.PUD_UP)

while True:
  if RPi.GPIO.input(21) == RPi.GPIO.LOW:
      print ("Pin Low")
      time.sleep(10)

  if RPi.GPIO.input(21) == RPi.GPIO.HIGH:
      now = time.strftime("%c")
      print ("Pin High " + now )
      time.sleep(60)

The LBO pin returned High when my touch pi battery switch was turned off and the unit was being powered from the regular micro usb power port, and while the switch was turned on an the battery had enough power for the pi. The LBO input switched to low when the battery was only able to power the Pi for about another 60 seconds. This would be perfect for setting up automated shutdown in the menu. I put together a bit of python code that runs in the menu’s while loop

# LBO Pin from Powerboost setup before while loop
RPi.GPIO.setmode (RPi.GPIO.BCM)
RPi.GPIO.setup(21, RPi.GPIO.IN, pull_up_down=RPi.GPIO.PUD_UP)


# Inside loop
if RPi.GPIO.input(21) == RPi.GPIO.LOW:
    screen.fill(black)
    font=pygame.font.Font(None,48)
    label=font.render("Battery Low, Shutting down", 1, (white))
    screen.blit(label,(20,120))
    pygame.display.flip()
    time.sleep(10)
    pygame.quit()
    shutdown()
    sys.exit()

I ran the battery out on my Touch Pi, and then charged it for about 20 minutes and started it up. A few minutes starting up I saw the following:

Touch Pi Low Battery shutdown screen

I ran the battery out a few times with the actual shutdown function line commented out, and it showed the low battery screen moments before the pi abruptly powered off every time.

I am sure my approach here is not great for battery life, but I don’t know anything about writing battery efficient python code at this point.

Don't have a 3D Printer?

Get a printed touch pi case for your project in the project store



Just completed a simple touch menu for Raspberry Pi projects using the 3.5” Adafruit PiTFT 480x320 touch screen.

Runs as a python script in the framebuffer without needing a desktop environment.

I have made a model b+ Touch Pi 3D printed case for my screen and raspberry pi, and with a battery and PowerBoost 500c charger it makes a great base for raspberry pi projects.

I wanted a way to do common tasks like going to the desktop, rebooting and shutting down without needing to use a keyboard. I also wanted the screen to display the current IP address to make it easier to ssh into the device.

Touch Pi Menu

You can get the source code from github.

Featured on the adafruit blog for pi day:



These are notes for myself on the crouton setup for my chromebook

1. Enter Developer Mode

Hold Power+ESC+Refresh, then let go of the power, when the OS verification warning screen appears enter Ctrl-D

2. Setup Crouton

Follow the instructions here to download the latest version of https://goo.gl/fd3zc.

Open a chrome terminal tab using CTRL+ALT+T and then open a shell

shell

Figure out what version of linux you want to run here https://github.com/dnschneid/crouton

Install the crouton extension in chromeos from here https://goo.gl/OVQOEt

3. Setup a chroot

I have been running Ubuntu Unity, Gnome 3 and enlightenment using an Ubuntu Trusty Tahr release.

sudo sh ~/Downloads/crouton -t keyboard,extension,unity -r trusty -n unitytrusty
sudo sh ~/Downloads/crouton -t keyboard,extension,gnome -r trusty -n gnometrusty
sudo sh ~/Downloads/crouton -t keyboard,xiwi,e17 -r trusty -n enlightenment

After the instalation is complete you will set up your unix username and password for the chroot in the terminal.

Once the chroot is done installing and you have set up your user you launch your chroot using:

sudo startunity
sudo startgnome

Crouton Command Cheat Sheet

4. Setup Lightweight Desktop

Click the dash icon in the top left corner and search for terminal, use xterm to install software using aptitude

sudo apt-get install terminator vlc git xarchiver

Install Google Chrome

sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb

Download Cura from http://software.ultimaker.com/

cd Downloads
sudo dpkg -i cura_15.02.1-debian_amd64.deb

Download and install Github Atom

cd Downloads
wget https://github.com/atom/atom/releases/download/v1.0.0/atom-amd64.deb
sudo dpkg -i atom-amd64.deb

##5. Update Keyboard to match ChromeOS

xmodmap -e "keycode 94 shift = backslash bar"
xmodmap -e "keycode 51 shift = numbersign asciitilde"
xmodmap -e  "keycode 11 shift = 2 quotedbl"
xmodmap -e "keycode 48 shift = apostrophe at"

xmodmap -e "keycode 22 shift = BackSpace Delete"
xmodmap -e "keycode 133 = Caps_Lock"

* Optional - Install Non Free Software that makes things easier and better looking

sudo apt-get install ttf-mscorefonts-installer

sudo apt-get install ubuntu-restricted-extras

Issues

  • The keyboard command used when installing the chroot don’t do anything
  • The chrome extension with chroot chrome window functionality is not working

Notes

You can copy and paste in the shell with Ctrl+Shift+C and Ctrl+Shift+V.