Skip to content

Instantly share code, notes, and snippets.

@rmtsrc
Last active January 29, 2024 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmtsrc/0564d1b3194c2d6c6a64f58d2647055c to your computer and use it in GitHub Desktop.
Save rmtsrc/0564d1b3194c2d6c6a64f58d2647055c to your computer and use it in GitHub Desktop.
Tingbot display revival

Tingbot display revival

  1. Download & install the Raspberry Pi Imager

  2. Choose Device: Raspberry Pi 3

  3. Choose OS: Raspberry Pi OS (other) > Raspberry Pi OS Lite (Legacy, 64-bit)

  4. Click Next then Edit Settings and set Username/Password or SSH key

  5. If connecting via Wi-Fi enter your routers details otherwise connect an Ethernet cable

  6. Once the Raspberry Pi Imager has finished don't remove the SD card just yet

  7. Check if a new drive called boot is available on your computer (this is the Raspberry Pi's boot drive)

  8. On the drive open up config.txt and change display_auto_detect=1 to:

    dtoverlay=fbtft
    dtparam=spi0-0,ssd1289
    dtparam=speed=48000000,regwidth=0
    dtparam=reset_pin=22,dc_pin=27,led_pin=18
    dtparam=rotate=270,bgr,fps=50
    
    dtoverlay=ads7846
    dtparam=penirq=25,xohms=80,swapxy=1
    
  9. Open cmdline.txt at the end of this 1 line file add a space followed by: fbcon=map:10

  10. Power it up & wait a few minutes for it to boot up

  11. You should hopefully see that the display is now working 🎉

If you only need access to the console then you can stop here.

Tingbot OS could now be installed, but since Tingbot OS is no longer maintained/updated, a Chromium kiosk window can be used instead (to display a dashboard or app like Home Assistant).

Optional Chromium kiosk window

Update system

sudo apt update && \
sudo apt full-upgrade -y && \
sudo apt autoremove -y

Install LXDE desktop environment, Chromium and unclutter (which hides the mouse pointer)

sudo apt install -y rpi-chromium-mods unclutter lxde

If you're using Wi-Fi/Bluetooth, after installing LXDE ensure it still works

sudo connmanctl enable wifi && \
sudo connmanctl enable bluetooth

Add frame buffer for X11 desktop display

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

Section "Device"
  Identifier "myfb"
  Driver "fbdev"
  Option "fbdev" "/dev/fb0"
EndSection

X11 Tingbot touchscreen display calibration file (generated via xcalibrate)

sudo nano /usr/share/X11/xorg.conf.d/99-libinput-ts-calib.conf

Section "InputClass"
    Identifier      "calibration"
    MatchProduct    "ADS7846 Touchscreen"
    Option          "CalibrationMatrix"  "-1.139887904380033 0.0 1.103406570595112 0.0 -1.115188775130766 1.0674508540122458 0.0 0.0 1.0"
EndSection

sudo reboot

Autostart Chromium

nano ~/kiosk.html

Paste in the contents of kiosk.html

mkdir -p ~/.config/lxsession/LXDE
nano ~/.config/lxsession/LXDE/autostart
@xset s off
@xset -dpms
@xset s noblank
@sed -i 's/"exited_cleanly": false/"exited_cleanly": true/' ~/.config/chromium-browser Default/Preferences
@chromium-browser --noerrdialogs --kiosk file:///home/pi/kiosk.html --disable-translate --force-dark-mode

To be able to boot to the desktop

sudo raspi-config

Select

  1. System options
  2. S5 Boot / Auto Login
  3. B4 Desktop Autologin
  4. Reboot Yes

Button mappings

sudo nano /boot/config.txt

# https://github.com/torvalds/linux/blob/v4.12/include/uapi/linux/input-event-codes.h#L64

# left button press (brightness toggle)
# #sudo dtoverlay gpio-key gpio=17 keycode=67 label="KEY_F9" active_low=0
dtoverlay=gpio-key,gpio=17,keycode=67,label="KEY_F9",active_low=0

# midleft button press (back)
# #sudo dtoverlay gpio-key gpio=23 keycode=158 label="KEY_BACK" active_low=0
dtoverlay=gpio-key,gpio=23,keycode=158,label="KEY_BACK",active_low=0

## midright button press (page up)
## #sudo dtoverlay gpio-key gpio=24 keycode=104 label="KEY_PAGEUP" active_low=0
dtoverlay=gpio-key,gpio=24,keycode=104,label="KEY_PAGEUP",active_low=0

# right button press (page down)
# #sudo dtoverlay gpio-key gpio=14 keycode=109 label="KEY_PAGEDOWN" active_low=0
dtoverlay=gpio-key,gpio=14,keycode=109,label="KEY_PAGEDOWN",active_low=0

nano ~/.config/openbox/lxde-rc.xml

Add inside <keyboard> block

<keybind key="F9">
  <action name="Execute">
    <command>bash ~/brightness-toggle.sh</command>
  </action>
</keybind>

WiringPi (for display brightness control)

sudo apt install -y git
git clone https://github.com/WiringPi/WiringPi.git
cd WiringPi
sudo ./build

Copy brightness.py and brightness-toggle.sh to your home folder (~)

chmod +x brightness-toggle.sh

sudo nano /etc/rc.local add before exit 0

/home/pi/brightness-toggle.sh restore-brightness

Thanks

  • @vitorio

References

#!/usr/bin/env bash
home=/home/pi
state_file=$home/.brightness-state
state=$(cat $state_file || 4)
if [ ! -n "$1" ]; then
[[ $state -le 0 ]] && state=4 || state="$(($state-1))"
echo $state >$state_file
fi
if [ "$state" = "0" ]; then
brightness=0
elif [ "$state" = "1" ]; then
brightness=25
elif [ "$state" = "2" ]; then
brightness=50
elif [ "$state" = "3" ]; then
brightness=75
else
brightness=100
fi
python $home/brightness.py $brightness
# Usage `python brightness.py <brightness-level>`
# E.g. Display 100% `python brightness.py 100`
# Display 50% `python brightness.py 50`
# Display off `python brightness.py 0`
# Requires WiringPi to be installed
# https://github.com/WiringPi/WiringPi
import subprocess
import sys
def ensure_backlight_setup():
subprocess.check_call(['gpio', '-g', 'mode', '18', 'pwm'])
subprocess.check_call(['gpio', '-g', 'pwmr', '65536'])
def set_backlight(brightness):
'''
Sets the backlight of the screen to `brightness`. `brightness` is a number from 0 to 100.
'''
ensure_backlight_setup()
if brightness <= 4:
# linear scaling from 0 to 4
value = brightness
else:
# cubic scaling from 4 to 100
value = 65536 * (brightness/100.0)**3
subprocess.check_call(['gpio', '-g', 'pwm', '18', str(value)])
set_backlight(int(sys.argv[1]))
<!DOCTYPE html>
<html>
<body style="margin: 0">
<iframe src="https://example.com" id="kiosk" width="320" height="240" frameborder="0"></iframe>
<script>
setTimeout(
() => document.getElementById("kiosk").contentWindow.focus(),
4000
);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<p id="width"></p>
<p id="height"></p>
<script>
var w = window.innerWidth;
var h = window.innerHeight;
var x = document.getElementById("width");
x.innerText = "Width: " + w;
var y = document.getElementById("height");
y.innerText = "Height: " + h;
</script>
</body>
</html>
@vitorio
Copy link

vitorio commented Jan 5, 2023

You may no longer need to roll the kernel back to get the Tingbot display working: tingbot/tingbot-os#33

@rmtsrc
Copy link
Author

rmtsrc commented Jan 6, 2023

@vitorio thanks for the tip! I've tested this overlay on my Tingbot and it works like charm, so I've updated this guide 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment