Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

How to programmatically type into a TFT display?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

How to programmatically type into a TFT display?

by furusato on Mon Aug 24, 2020 2:28 am

Hi, I've been successfully using a variety of your TFT displays (135x240, 1.3" 240x240, 1.54" 240x240, 2" 320x240, 2.8" 320x240), generally as a terminal input on my Raspberry Pi based robot using a tiny, radio-connected Rapoo keyboard. Works like a charm when I don't want to ssh into the robot.

What I'm wondering is this: I typically type 'top' or 'htop' and display a monitor on the screen. In order to do this I need to type this on my remote keyboard.

I realise this might be more of a Linux question, but how do I programmatically type something that shows up on the TFT screen? I'd like to do this in Python, e.g.,
Code: Select all | TOGGLE FULL SIZE
os.system('htop)


I'm guessing I need to somehow connect to its tty input or some such thing...

Thanks!

furusato
 
Posts: 15
Joined: Tue Nov 05, 2019 7:42 pm

Re: How to programmatically type into a TFT display?

by mikeysklar on Mon Aug 24, 2020 7:06 pm

Hello furusato,

If you want htop to startup on your TFT when the system boots you can add the following command to the last line of the /etc/rc.local file:

Code: Select all | TOGGLE FULL SIZE
htop


This is assuming the TFT is the primary display on yoru Pi and you are booting into console mode (setable via raspi-config).

BTW I love the look of the Rapoo keyboards and mice. I had not seen those before.

mikeysklar
 
Posts: 2073
Joined: Mon Aug 01, 2016 8:10 pm

Re: How to programmatically type into a TFT display?

by furusato on Tue Aug 25, 2020 4:33 am

Hi,

That kinda sorts out what I'm after, though not quite. Yes, running htop or top on startup is my goal, but ideally I'd like to be able to do that via python, programmatically.

So if my robot operating system (written in python) needs to at some point write to the screen, I'd be able to do that. That would include things like top, but could be other things too. That was where I was going with "os.system('command')". I'm specifically not thinking graphics-to-screen, but output of a terminal, so I guess what I'm asking for is how to (via python) locate the tty that the screen represents, and be able to write to that tty. Basically programmatically do the typing I'm currently doing from the external keyboard.

But for now I'll go ahead and use the rc.local approach you suggested, thanks very much!

----
And yes, the Rapoo keyboards are relatively cheap and work pretty well. The one I have has a built-in trackpad on the right side of the keyboard so I don't even need a mouse (though the reaction is pretty slow). I actually have some really old folding bluetooth keyboards for the Palm Pilot (remember those?) such as the Think Outside Stowaway Universal Bluetooth Keyboard" and once paired they work really well since many of them have almost full-size keys. I think these can be found on eBay for next to nothing.

furusato
 
Posts: 15
Joined: Tue Nov 05, 2019 7:42 pm

Re: How to programmatically type into a TFT display?

by furusato on Tue Aug 25, 2020 5:04 am

Hmm, actually on trying that it doesn't quite work. My Pi is set to open automatically into a console, and after booting up the TFT properly displays a command prompt.

My rc.local must have been modified by the TFT installer script and currently ends with

Code: Select all | TOGGLE FULL SIZE
sudo sh -c "TERM=linux setterm -blank 0 >/dev/tty0"
exit 0

The comment states the script must end with an "exit 0" on success or any other value on error, so it's clear that last line must remain. I tried putting both "htop" and "htop &" just before the "exit 0" as well as before the penultimate line, and while the htop gets displayed (briefly), it gets run off the screen by the motd and the command prompt, i.e., htop runs, but then gets scrolled offscreen.

Hmm. But the contents of the rc.local script suggests that the TFT might actually be "/dev/tty0" so I might have a go at python-scripting something that writes to that...

furusato
 
Posts: 15
Joined: Tue Nov 05, 2019 7:42 pm

Re: How to programmatically type into a TFT display?

by furusato on Tue Aug 25, 2020 5:09 am

Success! My Python script is as follows:

Code: Select all | TOGGLE FULL SIZE
#!/usr/bin/env python3
 
import os

os.system("sudo sh -c 'htop >/dev/tty0'")

When executed it starts htop on the TFT display!

furusato
 
Posts: 15
Joined: Tue Nov 05, 2019 7:42 pm

Re: How to programmatically type into a TFT display?

by mikeysklar on Tue Aug 25, 2020 4:39 pm

Congrats. Sounds like you got your ideal setup. Thanks for sharing your script.

mikeysklar
 
Posts: 2073
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.