linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Uniker 320x240 TFT w/Case

Thu May 05, 2016 9:32 pm

IMG_0531.jpg
IMG_0531.jpg (51.83 KiB) Viewed 10372 times
hey folks... just put together a little RPi3 package w/a TFT display and case... case is machined aluminum and is very nice! quite sturdy, and the kit includes a little thin-plexi 'window' to protect the display! (can't believe i didn't get my grubby thumbprint on either the display or the window during the install (four brass standoffs, four hex bolts, and an included Allen wrench! btw, the RPi3 wifi worked fine being inside the metal case!)

thought i'd post my initial impressions and some tips and tricks i've come up with so far...

the included screen is 320x240, 64K colors - no touch! however, an IR LED is included and a hole is drilled in the case... no real documentation on the IR function, but i seemed to get it going with:

dtoverlay=lirc-rpi,gpio_in_pin=26

in /boot/config.txt, which enabled /dev/lirc0 (i don't really use a remote w/my RPi3s, but this may be fun to explore later on)

i was easily able to get the TFT up and running (via a simple cmdline.txt edit) in console and X11 mode (toggling by using raspi-config), so this works very well for me..... (i'll be exploring a bit larger VGA fonts and a bit smaller X desktop; right now i'm using the console mode)

no simultaneous display via HDMI (AFAIK), but changing /usr/share/X11/xorg.conf.d/99-fbturbo.conf

from:

Option "fbdev" "/dev/fb1" #enable TFT

to

Option "fbdev" "/dev/fb0" #disable TFT

can toggle the display! oh, and thanks to a poster here on the forums, i was able to disable console blanking by appending:

consoleblank=0

to the end of /boot/cmdline.txt - wonderful!

if you don't like the default screen orientation (with the power/hdmi/auto pointing towards you), you can rotate the display upon booting by using one of four different rotation values in /boot/config.txt, e.g.:

dtoverlay=pitft28-resistive,rotate=0,speed=48000000,fps=30
dtoverlay=pitft28-resistive,rotate=90,speed=48000000,fps=30
dtoverlay=pitft28-resistive,rotate=180,speed=48000000,fps=30
dtoverlay=pitft28-resistive,rotate=270,speed=48000000,fps=30

(i prefer to have the power lead pointing up with my RPi3 standing on a side with no connectors)

after an early breakfast, i eventually came up with a bit of somewhat-useful 'button-press' code for the GPIOs associated with the six brass buttons on the case (four in the front and two on the side; one button doesn't want to 'debounce'?) by modifying an example keyboard python script... my basic approach:

1. set user 'pi' to be auto-logged in at the console (using raspi-config
2. made a shell script named 'menu' in /usr/local/bin containing:
sudo python /home/pi/Downloads/uniker_menu.py
3. created a .bash_login in pi's home directory, containing:
/usr/local/bin/menu
4. created a few handy scripts under /usr/local/bin to launch clients, with names such as thtop, twatch and tconky:
tput clear ; timeout --foreground 30 htop ; tput clear
watch 'dmesg | tail -13' &
tput clear ; /usr/bin/conky -c /home/pi/.conkyrc_console &
5. in uniker_menu.py, used the python os.system call to launch an app when the requisite button is depressed, e.g.:
...
if (not enter) and (not GPIO.input(4)):
os.system("cmatrix&")
...
6. by default, the display shows cmatrix - cool display!

the four brass buttons at the front of the case mapped to:
X - GPIO 5 (i set this one to reboot my RPi3)
down triangle - GPIO 24 (i set this one to launch conky)
square - GPIO 22 (i set this one to launch htop)
circle - GPIO 23 ... haven't decided yet; i might use something like:

timeout --foreground 30 watch 'dmesg | tail -20'

so i can check USB device recognition/initialization by the kernel....

the trigon (left arrow) on the side mapped to GPIO 4 (i set this one to launch cmatrix)
the trigon (right arrow) on the side near the power input mapped to GPIO 17 (i set this one to shutdown the system)

btw, my conky at the console presents a lot of info and is readable at the 8x8 size:

date, time
current weather
MAC address
wlan0 IP address with strength %
down/up traffic
CPU frequency, scaling
CPU temp in C & F
CPU usage bar meter/%
RAM usage amount/total
swap usage
SD card usage/capacity
read/write speeds

i initially use the timeout command to be able to select another command after seeing the desired info... but then decided to just use the background operator (&) on the os.system calls in my uniker_menu.py script, and issue a kill-process command to kill all apps before launching the desired app... otherwise, button presses are ignored when a command is running!

i'm not a python programmer, but i'm learning a lot with playing around with this TFT!

i hope this helps someone who is contemplating a purchase or has purchased this case and screen - one of the best accessories in my stable of RPi goodies!

willie
on the tiny display but sunny, warm and 85F Gulf of Mexico
Attachments
tft.jpg
tft.jpg (55.06 KiB) Viewed 10544 times
Last edited by linux_author on Fri May 13, 2016 2:21 pm, edited 2 times in total.

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: Uniker 320x240 TFT w/Case

Tue May 10, 2016 2:44 pm

hey folks... thought i'd update my efforts on configuring this case/tft - most of the work has been done on making the six exterior buttons useful...

i set up the two side buttons to shutdown or toggle the backlight on or off, and four front buttons to run eye candy (game of life and analog clock), provide system and network monitoring, and finally, kernel output messaging... i'm not a python programmer, but i'm rapidly beginning to appreciate the ease of the scripting, editing, and debugging with python..

here's the code:

Code: Select all

""" uniker_menu.py 
based on rpi-2.2TFT-kbrd.py by ukonline2000 2015.12.08
GPIO Keyboard driver for Raspberry Pi 2.2TFT for use with 5 Buttons
needs uinput kernel module (add uninput to /etc/modules)
needs python-uinput (git clone https://github.com/tuomasjjrasanen/python-uinput)
needs python RPi.GPIO (from http://pypi.python.org/pypi/RPi.GPIO/)

this script loops through a selection of button presses, killing all 
previous instances of commands, launched in the background, to allow
access to button-press events... you should craft your own shell scripts to
run commands... the clockywock analog clock is the startup app

note that this program is meant for the display in console mode, not an 
X11 desktop

(add 'consoleblank=0 to the end of /boot/cmdline.txt to disable blanking!)

have a lot of fun - [email protected] 2016.05.07

"""

import uinput
import time
import RPi.GPIO as GPIO
import os

GPIO.setmode(GPIO.BCM)
# program case buttons
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Circle Button for GPIO23
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Square Button for GPIO22
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Trigon Button for GPIO24
GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)  #X Button for GPIO5
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)  #R (side) Button for GPIO4
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)  #Trigon (power) Button for GPIO4

events = (uinput.KEY_C, uinput.KEY_Q, uinput.KEY_UP, uinput.KEY_DOWN, uinput.KEY_LEFT, uinput.KEY_RIGHT, uinput.KEY_ENTER, uinput.KEY_LEFTCTRL)

device = uinput.Device(events)

trigon = False
circle = False
square = False
up = False
X = False
shutdown = False
backlight = 1 # assume on at startup
clockon = 1

os.system("/usr/local/bin/clockywock&") # default startup

while True:

# launch app via circle button
  if (not circle) and (not GPIO.input(23)):  # circle button pressed
    circle = True
    os.system("/usr/local/bin/tkill")
    if clockon == 1:
     os.system("/usr/local/bin/clockywock&") 
     clockon = 0
    elif clockon == 0:
     os.system("/usr/local/bin/game&") 
     clockon = 1
    device.emit(uinput.KEY_Q, 1) # Press circle key
  if circle and GPIO.input(23):  # circle button released
    circle = False
    device.emit(uinput.KEY_Q, 0) # Release circle key

# launch app via square button
  if (not square) and (not GPIO.input(22)):  # square button pressed
    square = True
    os.system("/usr/local/bin/tkill")
    os.system("/usr/local/bin/conkconsole") # conky
    device.emit(uinput.KEY_RIGHT, 1) # Press square key
  if square and GPIO.input(22):  # square button released
    square = False
    device.emit(uinput.KEY_RIGHT, 0) # square Right key

# launch app via up button
  if (not up) and (not GPIO.input(24)):  # Up button pressed
    up = True
    os.system("/usr/local/bin/tkill")
    os.system("/usr/local/bin/tatop") # atop monitor
    device.emit(uinput.KEY_UP, 1) # Press Up key
  if up and GPIO.input(24):  # Up button released
    up = False
    device.emit(uinput.KEY_UP, 0) # Release Up key

# launch app via X button
  if (not X) and (not GPIO.input(5)):  # X button pressed
    X = True
    os.system("/usr/local/bin/tkill")
    os.system("/usr/local/bin/twatch") # watch dmesg output
    device.emit(uinput.KEY_DOWN, 1) # Press X key
  if X and GPIO.input(5):  # X button released
    X = False
    device.emit(uinput.KEY_DOWN, 0) # Release X key

# shutdown via Trigon button near power
  if (not shutdown) and (not GPIO.input(17)):  # trigon button pressed
    shutdown = True
    os.system("/usr/local/bin/tkill")
    os.system("/usr/local/bin/sd") # shutdown
    device.emit(uinput.KEY_RIGHT, 1) # Press power button
  if shutdown and GPIO.input(17):  # power button released
    shutdown = False
    device.emit(uinput.KEY_RIGHT, 0)

# launch app via trigon button
# in this instance, toggle backlight on/off
# gpio -g mode 27 in (bliton)
# gpio -g mode 27 out (blitoff)
  if (not trigon) and (not GPIO.input(4)): # trigon button pressed
    trigon = True
    if backlight == 1:
     os.system("/usr/local/bin/blitoff") # backlight off
     backlight = 0
    elif backlight == 0:
     os.system("/usr/local/bin/bliton") # backlight on
     backlight = 1

    device.emit(uinput.KEY_ENTER, 1) 
  if trigon and GPIO.input(4):  # trigon button released
    trigon = False
    device.emit(uinput.KEY_ENTER, 0) # release button needed

  time.sleep(.04)

i first thought that just having six buttons available on the case could be a limitation, but now realize that iterative toggling allows many more commands to be used... what's the limit on client toggling toleration? i don't know, but for now only two buttons toggle: the eye_candy (circle) button, which cycles the game of life and an analog clock, and the backlight for an on/off status...

btw, despite setting consoleblank=0 in /boot/cmdline.txt, if the backlight is toggled off for too long the console is never returned... if the backlight is toggle off for a short period (say 5 minutes or so), then the console output is displayed again... perhaps this is a driver issue?

my basic approach to 'menuing' in the script is:

declare, set defaults
launch default command
loop parse input
if button pressed
kill all associated menu commands
launch command into background associated with button (this frees up button input - is there a better way?)
release button

i'm having fun with this little case and display... reminds me of my days with a Palm Pilot and little keyboard (except now a bluetooth keyboard and a RPi3!)...

willie
on the humid Gulf of Mexico
Attachments
IMG_0525.jpg
IMG_0525.jpg (59.35 KiB) Viewed 10406 times
uniker.jpg
uniker.jpg (55.1 KiB) Viewed 10442 times

Rafael4096
Posts: 2
Joined: Thu May 26, 2016 12:11 am

Re: Uniker 320x240 TFT w/Case

Thu May 26, 2016 2:55 am

Total ignoramous here....sorry to step on your thread!
I cannot find a noob image that will get the uniker 2.2" screen running. All links I find are dead. How did you ever get the screen to work? Just got one and an rpi 3 from amazon. Works great with hdmi. Cannot get anywhere with tft.

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: Uniker 320x240 TFT w/Case

Thu May 26, 2016 11:11 am

1. use raspi-config to make your unit boot to console mode with auto-login

sudo raspi-config

2. use the nano text editor

sudo nano /boot/cmdline.txt

to make sure your /boot/cmdline.txt contains (at the end):

fbcon=map:10 fbcon=font:VGA8x8 rootwait consoleblank=0

3. use the nano editor

sudo nano /boot/config.txt

to make sure your /boot/config.txt contains (at the end):

dtparam=i2c_arm=on,spi=on
dtoverlay=pitft28-resistive,rotate=270,speed=48000000,fps=30

4. use the nano editor

sudo nano /usr/share/X11/xorg.conf.d/99-fbturbo.conf

to make sure /usr/share/X11/xorg.conf.d/99-fbturbo.conf contains:

Section "Device"
Identifier "Allwinner A10/A13 FBDEV"
Driver "fbturbo"
Option "fbdev" "/dev/fb1"
Option "SwapbuffersWait" "true"
EndSection


5. reboot and enjoy

sudo reboot

if you want to switch back to using HDMI, use:

Option "fbdev" "/dev/fb0"

in /usr/share/X11/xorg.conf.d/99-fbturbo.conf

the 2.2"TFT is a *tiny* screen, but i have found it useful when running the conky command in console mode:

/usr/bin/conky -c /home/pi/.conkyrc_console &

this lets me get the day, date, time, current weather, wlan0 IP info, CPU frequency and temperature, CPU load, RAM usage, and SD card capacity and usage - very handy!

the only real practical font is VGA8x8, but you can try others by modifying the fbcon=font:<name> entry in /boot/cmdline.txt... perhaps one of these (not all are available for our Raspbian kernel):

VGA8x16
7x14
10x18
VGA8x8
MINI4x6
RomanLarge
SUN8x16
SUN12x22
ProFont6x11
Acorn8x8
PEARL8x8

hope this helps...

willie

p.s. the fbi command is very nice to turn your little TFT into a slideshow viewer:

/usr/bin/fbi --noverbose -t 3 -l /home/pi/Documents/pics.txt

this does a never-ending loop of 3-second showing of 320x240 pictures listed in the file 'pics.txt'

this is the Python line i use in my menu script:

subprocess.call(["/usr/bin/fbi","--noverbose","-t","3","-1","-l","/home/pi/Documents/pics.txt"])

(in this case i only do the slideshow once due to the '-1' option)

each line in the file 'pics.txt' contains the pathname to a slide, such as:

/home/pi/Pictures/100_0094.jpg

(i extracted and resized all my pics to 320x240 from the Photos.app on my OS X 10.10.5 Macbook Air, then schlepped 'em over to my Pi via sftp)

Rafael4096
Posts: 2
Joined: Thu May 26, 2016 12:11 am

Re: Uniker 320x240 TFT w/Case

Fri May 27, 2016 3:07 am

Thank you so very much, linux_author!
I am going to go back to my original setup and follow your guide! I need the experience. I actually got the screen working tonight......found an image on adafruit. Funny......everywhere else I looked.......the image links were no longer valid.
Much respect for taking the time helping a beginner! Have not touched linux for about 25+ years.......not kidding. Feeling over my head..... but enjoying it. :)

bigbadbob
Posts: 7
Joined: Fri Feb 06, 2015 11:23 am

Re: Uniker 320x240 TFT w/Case

Thu Jun 02, 2016 11:30 am

Thanks for your writeup. It helped me a lot.
I got the screen to show console at boot and also auto login. good stuff.
I wrote a simple script to use the buttons and it works ok for most things but when I turn the backlight off and back on the screen is blank white.
Thinking this was an error in my script somewhere, I tried yours, again it works for most things so thanks for that. :-)
But the display is often still blank white after turning backlight back on, not always and not time dependent so I don't think it's the BLANKTIME=0 or poweroff=0 problem.
It's more like the screen is being told to go blank by something running in the background, I run weewx among others.
The screen is even sometimes blank white at boot.
If you've come across this I'd be interested to hear more.
BBB.
P.S. I'm not running xwindows, nor sending anything other than console to the screen. no clockywok at startup.
Last edited by bigbadbob on Thu Jun 02, 2016 12:17 pm, edited 1 time in total.

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: Uniker 320x240 TFT w/Case

Thu Jun 02, 2016 12:02 pm

dunno if this can help:

https://github.com/notro/fbtft/wiki/Boot-console

or

this:

viewtopic.php?f=91&t=57552

i noticed that if i boot up, then allow a console app (such as vtclock) to run, the little TFT doesn't blank

but if i boot up, use the buttons and screens, then turn the backlight off then on again, the screen will blank after a period of time...

so, my philosophy with this bug [feature] is to approach it like my doctor said:

"Hey, doc, my shoulder really hurts when I do this."

"Well son, then don't do that."

:-)

willie
on the tiny computing Gulf of Mexico

bigbadbob
Posts: 7
Joined: Fri Feb 06, 2015 11:23 am

Re: Uniker 320x240 TFT w/Case

Thu Jun 02, 2016 12:57 pm

Thanks for Your quick reply Willie. :-)
That's re-assuring to hear that you suffer from this "feature" too and it's not just me. I think I understand more now.
Ideally I want the display to show syslog messages so I can keep an eye on what the pi is doing without having to ssh in. but I've had trouble getting it to do that.

From what you've experienced it sounds like I need to run a console app to display the syslog messages.
I'm guessing the screen doesn't show anything after backlight=On because nothing has happened, I need to tell it to do something, it won't go back to showing the [email protected] $ prompt because I've run the button script. albeit in the background.

re:-https://github.com/notro/fbtft/wiki/Boot-console
My driver is compiled into the kernel, might be better as a module. hmmm, food for thought.
I was a bit confused about whether or not I needed to load the module. now I understand there are two methods. :)

re:- viewtopic.php?f=91&t=57552
I'm running raspian and text console so have set BLANK_TIME=0 and POWERDOWN_TIME=0
I'm not running x11 so havn't set @xset s noblank, @xset s off or @xset -dpms.
Thanks again Willie.

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: Uniker 320x240 TFT w/Case

Thu Jun 02, 2016 2:01 pm

bigbadbob wrote: Ideally I want the display to show syslog messages so I can keep an eye on what the pi is doing without having to ssh in. but I've had trouble getting it to do that.
my approach to this using the python buttons is to first craft the desired output in a shell script under /usr/local/bin, then to have the script run in the background (which returns control to the loop of the buttons) when a desired button is depressed... by using iteration logic in the python script, one could potentially have dozens of different output screens from various commands appear on the TFT by repeatedly depressing a single button (note i only toggle two buttons in my script; i'm a python n00b)

:-)

something like this might work for you? i'd first create a script named watchsys, make it executable, then copy it to /usr/local/bin:

Code: Select all

echo "/usr/bin/watch -n 1 '/usr/bin/tail -5 /var/log/syslog'" >watchsys ; chmod +x watchsys ; sudo mv watchsys /usr/local/bin
i like one-second updates on my time or dmesg output and only use 5 lines of output due to the 40-character limit on the small TFT, which wraps long output lines... my conky console output is nicely formatted though

it is a bit of challenge to maximize small-screen output... my next project is a 128x64 ssd1306 OLED - talk about a tiny screen! but it will be fun to pair it with a Pi Zero... i'll post my project pics and code under this forum when i get it somewhat hashed out...

have a lot of fun and hth,

willie
on the rapidly warming Gulf of Mexico
Last edited by linux_author on Thu Jun 02, 2016 7:15 pm, edited 1 time in total.

bigbadbob
Posts: 7
Joined: Fri Feb 06, 2015 11:23 am

Re: Uniker 320x240 TFT w/Case

Thu Jun 02, 2016 2:46 pm

Yay, you know what I'm thinking Willie.
I'm a n00b to this stuff too, I'm better at hardware, haha.
I did think about using Conky but don't want the overhead of running x11 just for a few lines of text so your idea looks great.
I only need a few lines to check (for example) when weewx last sent an update to wunderground (my weather station)
I'll have a try. 8-)
Bob.
On the slowly warming Isle of Skye.

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: Uniker 320x240 TFT w/Case

Thu Jun 02, 2016 5:25 pm

bigbadbob wrote: I did think about using Conky but don't want the overhead of running x11 just for a few lines of text so your idea looks great.
fyi: i use conky in its 'console' mode! (works great with no X session!):

Code: Select all

tput clear ; /usr/bin/conky -c /home/pi/.conkyrc_console &
willie
on the old-school UNIX Gulf of Mexico

bigbadbob
Posts: 7
Joined: Fri Feb 06, 2015 11:23 am

Re: Uniker 320x240 TFT w/Case

Thu Jun 02, 2016 5:51 pm

Hmmmm....
I created watchsys as suggested, containing

Code: Select all

/usr/bin/watch -1 '/usr/bin/tail -5 /var/log/syslog'
when I run it with

Code: Select all

sudo /usr/local/bin/watchsys
it returns-
/usr/bin/watch: invalid option -- '1'
followed by an options list of which one option is -n so I don't know why it has a problem with -1.
n=1 right? grrrr....

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: Uniker 320x240 TFT w/Case

Thu Jun 02, 2016 7:11 pm

oops! yes, should be:

Code: Select all

watch -n 1 'tail -5 /var/log/syslog'
sorry! [fixed the code in my previous post] oh, and no reason to use 'sudo' to run the script... (sudo was only needed to copy the script to /usr/local/bin - although some Linux distros do have a 'lockdown' on users being able to view syslog and other logs)

willie
on the red-faced Gulf of Mexico

bigbadbob
Posts: 7
Joined: Fri Feb 06, 2015 11:23 am

Re: Uniker 320x240 TFT w/Case

Fri Jun 03, 2016 6:17 pm

Haha, thanks Willie. watchsys script now works from console with keyboard plugged in, I just need to sort my screwups with uniker_menu.py. :D
btw, the Grrrr... wasn't aimed at you, it was just my frustration with code coming out. I'm a hardware man who just uses code when it will do a job for me. :D

edit: can you show me what's in your tkill script. how do I kill any script I've started in uniker_menu without killing anything else?
is there a simple way or do I need to do something like-
if clockon=1 killall /usr/local/bin/clockywok
elif circle=1 kill that one
etc
etc

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: Uniker 320x240 TFT w/Case

Fri Jun 03, 2016 10:38 pm

bigbadbob wrote:can you show me what's in your tkill script. how do I kill any script I've started in uniker_menu without killing anything else?
is there a simple way
i use:

sudo pkill name_of_client

such as:

sudo pkill mpg321
sudo pkill conky
sudo pkill game
sudo pkill aclock
sudo pkill vtclock
sudo pkill htop
sudo pkill watch

hth!

willie on the stinkin' hot Gulf of Mexico

p.s. this is not optimal, btw... it would be much better to record the process number started after depressing a button on the uniker_case/GPIO button - but i'm a clumsy twit and like to bully through the china shop, destroying processes in my wake!

:-)

bigbadbob
Posts: 7
Joined: Fri Feb 06, 2015 11:23 am

Re: Uniker 320x240 TFT w/Case

Sat Jun 04, 2016 8:08 am

:D
Thanks Willie.
so you just kill em whether they're running or not? nof ifs and buts.
sounds like the simple way.
73 de MM0RBZ ;)

Edit: woohoo!!! it works!!! I can now monitor the last 5 lines of syslog just by pushing a button.
I aslo used the x button to exit from it. (just do a sudo pkill watch)
I ended up including a
try.....
except:
GPIO.cleanup()
statement in your uniker script to resolve gpio issues during troubleshooting.
And a word to the wise. when using this case, make sure you ground it. I found my case was floating at 67v ac above ground.
this causes no end of problems and spurious errors when you touch the metal buttons. I had to scrape off some of the anodising to make sure all metal parts were in contact with the ground plane and add a grounding screw through the case.
thanks again for your help Willie.

fungus666
Posts: 4
Joined: Sat Jun 18, 2016 4:25 am

Re: Uniker 320x240 TFT w/Case

Sat Jun 18, 2016 4:44 am

I tried several modules for GPIO input. python uinput seems to be the best.
couldnt run constant polls for button interrupts and use the menu i liked at the same time.
tried forking and subprocesses. I couldnt kill launched apps adequately.
split the uinput root privilege code and the binary calls.

/usr/bin/local/launcher.sh

Code: Select all

#!/bin/bash
echo "something meaningful"
sudo python unikerinput.py &
python menu.py
I used menu-ncurses.
it puts it in sort of a kiosk mode. it cant be killed by control c, only by selecting exit.
http://curses-menu.readthedocs.io/en/la ... sMenu.html

sudo pip install curses-menu


unikerinput.py

Code: Select all

"""
addendum:

Split button polling to separate python script ran at boot
menu controlled by python menu-curses
assumed rotatation of 270 in xorg config. side buttons become up and down.
x button sends Ctrl+C (order is important)
Havent thought of a use for square and triangle yet. I have a half-assed attempt at kill
Keyboard event can easily be replaced by whatever.
I think any of these will work too.
https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h
"""

import uinput
import time
import RPi.GPIO as GPIO
#import os
#import subprocess
#import signal

GPIO.setmode(GPIO.BCM)
# program case buttons
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Circle Button for GPIO23
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Square Button for GPIO22
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Trigon Button for GPIO24
GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)  #X Button for GPIO5
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)  #R (side) Button for GPIO4
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)  #Trigon (power) Button for GPIO4

events = (uinput.KEY_C, uinput.KEY_UP, uinput.KEY_DOWN, uinput.KEY_ENTER, uinput.KEY_LEFTCTRL)
device = uinput.Device(events)

trigon = False
circle = False
square = False
up = False
X = False
shutdown = False
while True:

# circle button
  if (not circle) and (not GPIO.input(23)):  # circle button pressed
    circle = True
    device.emit(uinput.KEY_ENTER, 1) # Press circle key
  if circle and GPIO.input(23):  # circle button released
    circle = False
    device.emit(uinput.KEY_ENTER, 0) # Release circle key

# square button
  if (not square) and (not GPIO.input(22)):  # square button pressed
    square = True
    device.emit(uinput.KEY_C, 1) # Press square key
  if square and GPIO.input(22):  # square button released
    square = False
    device.emit(uinput.KEY_C, 0) # square Right key

#  fronttriangle button
  if (not up) and (not GPIO.input(24)):  # Up button pressed
    up = True
    device.emit(uinput.KEY_LEFTCTRL, 1) # Press Up key
  if up and GPIO.input(24):  # Up button released
    up = False
    device.emit(uinput.KEY_LEFTCTRL, 0) # Release Up key

#  X button
  if (not X) and (not GPIO.input(5)):  # X button pressed
    X = True
    device.emit_combo([uinput.KEY_LEFTCTRL, uinput.KEY_C]) # Press X key
  if X and GPIO.input(5):  # X button released
    X = False
    device.emit(uinput.KEY_X, 0) # Release X key

# arrow button near power
  if (not shutdown) and (not GPIO.input(17)):  # trigon button pressed
    shutdown = True
    device.emit(uinput.KEY_UP, 1) # Press power button
  if shutdown and GPIO.input(17):  # power button released
    shutdown = False
    device.emit(uinput.KEY_UP, 0)


#  button near SDA pin
# in this instance, toggle backlight on/off
# gpio -g mode 27 in (bliton)
# gpio -g mode 27 out (blitoff)
  if (not trigon) and (not GPIO.input(4)): # trigon button pressed
    trigon = True
    device.emit(uinput.KEY_DOWN, 1)
  if trigon and GPIO.input(4):  # trigon button released
    trigon = False
    device.emit(uinput.KEY_DOWN, 0) # release button needed

  time.sleep(.04)

menu.py

Code: Select all

#import uinput
#import time
#import RPi.GPIO as GPIO
#import os
#import subprocess
#import signal
#import psutil
from cursesmenu import *
from cursesmenu.items import *


menu = CursesMenu("title", "subtitle")

cmatrix_ = CommandItem("run cmatrix", "cmatrix")
conky_ = CommandItem("conky", "conky")
htop_ = CommandItem("htop", "htop")
reboot_ = CommandItem("sudo reboot", "sudo reboot")


menu.append_item(conky_)
menu.append_item(cmatrix_)
menu.append_item(htop_)
menu.append_item(reboot_)

menu.show()
Also,
write a script to swap fbdev0 and fbdev1 in 99turbo,
then reload xorg and launch x11 to the gui.

See Spotify-cli client
https://github.com/fabiofalci/sconsify

wicd-curses
http://linux.die.net/man/8/wicd-curses

links2
http://linux.die.net/man/1/links2

mutt
http://linux.die.net/man/1/mutt

fortune
http://linux.die.net/man/1/fortune

adom
gameboy
doom

p.s.
If anyone knows the correct minimum_size in conky_no_x11.conf for this screen,
please make it known.


have fun
Image
Last edited by fungus666 on Tue Nov 29, 2016 10:54 pm, edited 4 times in total.

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: Uniker 320x240 TFT w/Case

Sat Jun 18, 2016 10:50 am

i just *knew* someone would come up with something better! when i get a chance, i'm gonna give your menuing approach a run...

thank you *very* much for posting this!

willie
on the cloudy and rainy Gulf of Mexico

Lord Bedfont
Posts: 2
Joined: Fri Aug 19, 2016 3:57 pm

Re: Uniker 320x240 TFT w/Case

Fri Aug 19, 2016 4:04 pm

Hi,

I have the same Uniker display, but having a problem getting Conky to work.

The Pi is running on Console mode, and the screen is working, but Conky always generates the message "Conky: can't open display"

I've created a default conky.conf in my /home/pi/conky directory, so my conky command line is "conky -c /home/pi/conky/conky.conf" and that config file is below:

Code: Select all

# Conky, a system monitor, based on torsmo
#
# Any original torsmo code is licensed under the BSD license
#
# All code written since the fork of torsmo is licensed under the GPL
#
# Please see COPYING for details
#
# Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
# Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

alignment top_right
background no
border_width 0
cpu_avg_samples 2
default_color red
default_outline_color black
default_shade_color black
double_buffer yes
draw_borders no
draw_graph_borders yes
draw_outline no
draw_shades yes
use_xft yes
xftfont DejaVu Sans Mono:size=9
gap_x 10
gap_y 50
minimum_size 200 100
net_avg_samples 2
no_buffers yes
out_to_console no
out_to_stderr no
extra_newline no
own_window yes
own_window_class Conky
own_window_transparent yes
own_window_type override
stippled_borders 0
update_interval 1.0
uppercase no
use_spacer none
show_graph_scale no
show_graph_range no

TEXT
${font DejaVu Sans Mono:style=bold:size=9}SYSTEM $hr
${font}$sysname $kernel $alignr $machine
Host: $alignr $nodename
Uptime: $alignr $uptime
File System: $alignr $fs_type
###Temp: $alignr ${acpitemp}C

${font DejaVu Sans Mono:style=bold:size=9}PROCESSORS $hr
${font}${cpugraph cpu0}
CPU1: ${cpu cpu1}% ${cpubar cpu1}
###CPU2: ${cpu cpu2}% ${cpubar cpu2}

${font DejaVu Sans Mono:style=bold:size=9}MEMORY $hr
${font}RAM ${alignc} $mem/$memmax  $alignr $memperc%
${membar}

${font DejaVu Sans Mono:style=bold:size=9}DISKS $hr
${font}/ $alignc ${fs_used /} / ${fs_size /} $alignr ${fs_used_perc /}%
${fs_bar /}
HOME $alignc ${fs_used /home} / ${fs_size /home} $alignr ${fs_used_perc /home}%
${fs_bar /home}
SWAP $alignc $swap / $swapmax $alignr $swapperc%
$swapbar

${font DejaVu Sans Mono:style=bold:size=9}TOP PROCESSES $hr
${font}${top name 1}$alignr${top cpu 1}%
${top name 2}$alignr${top cpu 2}%
${top name 3}$alignr${top cpu 3}%
${top name 4}$alignr${top cpu 4}%
${top name 5}$alignr${top cpu 5}%

${font DejaVu Sans Mono:style=bold:size=9}NETWORK $hr
${font}IP Address: $alignr ${addr wlan0}
SSID: $alignr ${wireless_essid wlan0}
Connection Quality: $alignr ${wireless_link_qual wlan0}%
${downspeedgraph wlan0}
DLS: ${downspeed wlan0}/s $alignr ${totaldown wlan0}
${upspeedgraph wlan0}
ULS: ${upspeed wlan0}/s $alignr ${totalup wlan0}
I'm sure this is something very simple, but I just can't figure it out.

Help is always much appreciated!

Thanks
Lord_B

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: Uniker 320x240 TFT w/Case

Fri Aug 19, 2016 11:06 pm

here's my console conkyrc:

Code: Select all

# --------------------------------------------------------------------------------------------- #
#
# .conkyrc_console - for the Uniker Raspberry Pi 2.2TFT 
#  (meant to be run at the console using VGA8x8 font)
# --------------------------------------------------------------------------------------------- #
 
# -------------------- Conky's Run Time Parameters -------------------- #
out_to_ncurses yes
out_to_x no
update_interval 1.0                     # Conky update interval in seconds
total_run_times 0                       # Number of updates before quitting.  Set to zero to run forever.
no_buffers yes                          # Subtract file system buffers from used memory?
cpu_avg_samples 2                       # Number of cpu samples to average. Set to 1 to disable averaging
net_avg_samples 2                       # Number of net samples to average. Set to 1 to disable averaging
 
# -------------------- Conky's General Look & Feel -------------------- #
 
# --- default values --- #
default_color yellow                      # Default color and border color
default_bar_size 0 6            # Specify a default width and height for bars.
default_gauge_size 25 15        # Specify a default width and height for gauges.
#default_gauge_size 25 25        # Specify a default width and height for gauges.
default_graph_size 0 15         # Specify a default width and height for graphs.
default_outline_color green     # Default border and text outline color
default_shade_color yellow      # Default border and text shading color
 
# --- predefined colors - http://www.kgym.jp/freesoft/xrgb.html --- #
color0 FFFFFF                           # white
color1 FFA500                           # orange
color2 B22222                           # firebrick
color3 696969                           # dim gray
color4 D3D3D3                           # light gray
color5 2F4F4F                           # dark slate gray
color6 FFEC8B                           # light golden rod
color7 54FF9F                           # sea green
color8 FF8C69                           # salmon
color9 FFE7BA                           # wheat
 
# --- window layout & options --- #
own_window yes                          # Conky creates its own window instead of using desktop
own_window_type normal          # If own_window is yes, use type normal, desktop, or override
own_window_transparent no      # Use pseudo transparency with own_window?
own_window_colour black          # If own_window_transparent is no, set the background colour
double_buffer yes                       # Use double buffering (reduces flicker)
use_spacer right                        # Adds spaces to stop object from moving
maximum_width 600                       # Maximum width of window in pixels
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
 
# --- window placment --- #
alignment top_right
 
# --- borders, margins, and outlines --- #
draw_graph_borders yes          # Do you want to draw borders around graphs
border_inner_margin 9           # Window's inner border margin (in pixels)
border_outer_margin 5           # Window's outer border margin (in pixels)
gap_x 25                                        # Gap between borders of screen and text (on x-axis)
gap_y 25                                        # Gap between borders of screen and text (on y-axis)
border_width 5                         # Window's border width (in pixels)
 
# --- Text --- #
draw_outline no                         # Do you want ot draw outlines
draw_shades no                          # Do you want to draw shades
draw_borders no                         # Do you want to draw borders around text
uppercase no                            # set to yes if you want all text to be in uppercase
use_xft yes                             # use the X FreeType interface library (anti-aliased font)
xftfont Monospace:size=9:weight=bold    # Xft font to be used
 
# -------------------- Conky's Displayed System Monitoring Parameters -------------------- #
TEXT
# Title / Banner message
${color1}
${alignc 65}${font Arial Black:size=30}${time %A %B %d %H:%M:%S}${font}

# current WX - requires external shell script
#
${color1}Current WX: $color${execi 30 currentwx}$color


# General system information

${color0}MAC Address: $color${execi 99999 cat /sys/class/net/eth0/address }

${color0}wlan0 IP: ${addr wlan0} Signal: ${wireless_link_qual_perc wlan0}%

${color0}Down:$color ${downspeed wlan0}/s ${alignr}${color0}Up:$color ${upspeed wlan0}/s


# CPU information
${color0}Freq: $color$freq MHz ${color0}  Scaling: $color${execi 3 cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor }

${color0}CPU Temperature: $color${execi 30 cputempf }$color

${color0}CPU Usage:$color $cpu% ${color7}${cpubar}

# Ethernet utilization

# Memory and swap space untilization
${color0}RAM Usage: ${color}$mem / $memmax

${color0}Swap Usage: ${color}$swap / $swapmax

# File System utilization
${color0}SD Card:$color ${fs_used /} / ${fs_size /}

${color0}Reads: $color$diskio_read/s${alignr}${color0}Writes: $color$diskio_write/s


nathan6666
Posts: 1
Joined: Wed Dec 17, 2014 2:44 am

Re: Uniker 320x240 TFT w/Case

Fri Sep 16, 2016 3:13 pm

I have been trying to get fungus666's example to work and i can get it to display the same menu he has but its not blue like his. Its black and white like the linux command line. Does anyone have an idea of how to get this to work? I followed linux author's list of steps and it does display fungus666's example just not blue like his.

fungus666
Posts: 4
Joined: Sat Jun 18, 2016 4:25 am

Re: Uniker 320x240 TFT w/Case

Sun Oct 23, 2016 8:41 pm

That's just camera distortion. My console is b+w.

However, I think that's cool.
Try setterm

http://www.tuxradar.com/answers/482

Return to “General discussion”