oledterm
oledterm copied to clipboard
Unable to access %s
Hi Im keen to use this with my Orange Pi Zero setup. Luma.oled is installed and working, and can display all the luma.examples. I'm using an SSD1306 controller OLED display connected via the i2c bus. When I run the following command from the oledterm directory:
sudo python3 oledterm.py --display ssd1306 --interface i2c --rotate 2
it blows up as follows:
File "oledterm.py", line 55 print "Unable to access %s, try running as root?" % (VIRTUAL_TERMINAL_DEVICE,)
Any clues what might be wrong?
Peter
Correction, I'm using a 1.3" OLED with an SH1106 controller.
I discovered this issue was because your code is written for Python 2. I ran it through 2to3 to convert to Python 3 but now when I run:
python3 oledterm.py --i2c-port 0 --display sh1106
I get:
Traceback (most recent call last): File "oledterm.py", line 113, in main() File "oledterm.py", line 100, in main term.putch(char) File "/usr/local/lib/python3.7/dist-packages/luma/core/virtual.py", line 327, in putch w = self.font.getsize(char)[0] File "/usr/local/lib/python3.7/dist-packages/PIL/ImageFont.py", line 262, in getsize size, offset = self.font.getsize(text, False, direction, features, language) TypeError: expected string
Some junk appears on the screen for a few seconds while the above prints, then it goes blank.
Any thoughts?
Perhaps this is an orphan project......
bump
Hi peterbmckinley,
I have the same Problem like you and i think, i slowly get it work.
I did a convert with 2to3, so the code can run thrue python3, because luma.oled ONLY runs now in Python3.
like you said it runs in trouble in line 100 term.putch(char) with the reason unexpected type, needed string.
So i tried to get it work, what would be nicer than a REAL RETRO PI with OLED Terminal ;-)
for char in data:
if '\r' in chr(char):
term.carriage_return()
elif chr(10) in chr(char):
#term.newline()
# no scroll, no flush
term.carriage_return()
x = 0
term._cy += term._ch
elif '\b' in chr(char):
term.backspace()
x =- 1
elif '\t' in chr(char):
term.tab()
else:
term.putch(chr(char))
So now the Oled (SSH1106) shows up with number per line.
😳
On Sat, 22 Aug 2020, 18:39 Krizzel87, [email protected] wrote:
So i tried to get it work, what would be nicer than a REAL RETRO PI with OLED Terminal ;-)
for char in data: if '\r' in chr(char): term.carriage_return() elif chr(10) in chr(char): #term.newline() # no scroll, no flush term.carriage_return() x = 0 term._cy += term._ch elif '\b' in chr(char): term.backspace() x =- 1 elif '\t' in chr(char): term.tab() else: term.putch(chr(char)) So now the Oled (SSH1106) shows up with number per line.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/satoshinm/oledterm/issues/4#issuecomment-678669905, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFONLDIUXX25QLX75FPJ5HTSB77GZANCNFSM4PADFK5Q .
oh and you need to edit the go.sh
insert this
#!/bin/sh -x
python3 oledterm.py --display sh1106 --interface i2c --rotate 0
hope you have installed python libs etc
the only thing I need to learn is how data = subprocess.check_output(["screendump"])
is getting the data
Good luck! I can't help you with that, but good work 🤞😊
here is the full new python 3 code
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# based on:
# Copyright (c) 2014-17 Richard Hull and contributors
# See LICENSE.rst for details.
# PYTHON_ARGCOMPLETE_OK
import os
import time
import sys
import subprocess
from luma.core import cmdline
from luma.core.virtual import terminal
from PIL import ImageFont
VIRTUAL_TERMINAL_DEVICE = "/dev/vcsa"
ROWS = 9
COLS = 31
# based on demo_opts.py
from luma.core import cmdline, error
def get_device(actual_args=None):
"""
Create device from command-line arguments and return it.
"""
if actual_args is None:
actual_args = sys.argv[1:]
parser = cmdline.create_parser(description='luma.examples arguments')
args = parser.parse_args(actual_args)
if args.config:
# load config from file
config = cmdline.load_config(args.config)
args = parser.parse_args(config + actual_args)
# create device
try:
device = cmdline.create_device(args)
except error.Error as e:
parser.error(e)
#print(display_settings(args))
return device
# based on luma.examples terminal
def make_font(name, size):
font_path = os.path.abspath(os.path.join(
os.path.dirname(__file__), 'fonts', name))
return ImageFont.truetype(font_path, size)
def main():
if not os.access(VIRTUAL_TERMINAL_DEVICE, os.R_OK):
print(("Unable to access %s, try running as root?" % (VIRTUAL_TERMINAL_DEVICE,)))
raise SystemExit
fontname = "tiny.ttf"
size = 6
font = make_font(fontname, size) if fontname else None
term = terminal(device, font, animate=False)
term.clear()
for i in range(0, ROWS):
term.puts(str(i) * COLS)
term.flush()
#time.sleep(1)
while True:
# Get terminal text; despite man page, `screendump` differs from reading vcs dev
#data = file(VIRTUAL_TERMINAL_DEVICE).read()
data = subprocess.check_output(["screendump"])
#print [data]
# Clear, but don't flush to avoid flashing
#term.clear()
term._cx, term._cy = (0, 0)
#term._canvas.rectangle(term._device.bounding_box, fill=term.bgcolor)
term._canvas.rectangle(term._device.bounding_box, fill="black")
# puts() flushes on newline(), so reimplement it ourselves
#term.puts(data)
for char in data:
if '\r' in chr(char):
term.carriage_return()
elif chr(10) in chr(char):
#term.newline()
# no scroll, no flush
term.carriage_return()
x = 0
term._cy += term._ch
elif '\b' in chr(char):
term.backspace()
x =- 1
elif '\t' in chr(char):
term.tab()
else:
term.putch(chr(char))
term.flush()
time.sleep(0.01)
#print "refresh"
#print data
if __name__ == "__main__":
os.system("stty --file=/dev/console rows %d" % (ROWS,))
os.system("stty --file=/dev/console cols %d" % (COLS,))
try:
device = get_device()
main()
except KeyboardInterrupt:
pass
but you can test it!
is luma.oled installed to your python3 and running succesfull? did you start i2c interface etc=?
Now I have Holiday and want to make a cool pi Server. Learnd python with google^^ and i can read and understand. It was horrible the problem seems to be the change from python2 to python3 wit how Chars and Strings were used.
To run on boot, add to /etc/rc.local:
sudo python3 /home/pi/oledterm/oledterm.py --display sh1106 --interface i2c --rotate 0 &
is luma.oled installed to your python3 and running succesfull? did you start i2c interface etc=?
Now I have Holiday and want to make a cool pi Server. Learnd python with google^^ and i can read and understand. It was horrible the problem seems to be the change from python2 to python3 wit how Chars and Strings were used.
See OP: "Luma.oled is installed and working, and can display all the luma.examples"
Yes the change from Python 2 to Python 3 is a huge problem for the inexperienced
but i thing the auto boot will only work when you are the ONLY user on your pi and only log in once.
https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/
I test it with pi 4 latest raspian OS and SH1106. now it Work. Only issue --rotate 1 und 3 does not work correctly.
Fantastic! I'll be home soon and will test it. Im using Orange Pi Zero but hopefully it will work too.
On Sat, 22 Aug 2020, 19:53 Krizzel87, [email protected] wrote:
I test it with pi 4 latest raspian OS and SH1106. now it Work. Only issue --rotate 1 und 3 does not work correctly.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/satoshinm/oledterm/issues/4#issuecomment-678678005, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFONLDKDZGQWAPHS2RSVG6LSCAH2TANCNFSM4PADFK5Q .
I fail the hole evening, because i Booted to Desktop and not to CLI, it can be changed in raspi-config
.
To test you can start it sudo sh go.sh
and then switch via Ctrl Alt F1 to CLI. Have Fun! The front is very tiny, but you can change Size and Type in oledterm.py in Line 58
fontname = "tiny.ttf"
size = 6
but then you need to resize in line 17, to resize Display
ROWS = 9
COLS = 31
Until Screen looks like this at programm start
000000000000
111111111111
222222222222
333333333333
Not like this
000000001111
111122222222
333333334444
444455555555
Have Fun
It works! Thank you :)
Hi Krizzel87, I've re-opened this issue as I can't get it to autorun at boot.
Adding python3 oledterm/oledterm.py --i2c-port 0 --display sh1106 to /etc/rc.local fails with a Compatibility error.
I tried adding python3 oledterm/oledterm.py --i2c-port 0 --display sh1106 to ~/.profile, which I've used to automatically run other scripts (my Orange Pi Zero is set to automatically login the root account) but the output seems to get stuck in a loop, it's like the oled is trying to display 2 or more processes.
Have you had any success getting oledterm to run automatically at boot?
Okay.
I created a new go.sh with
#!/bin/sh -x
sudo python3 oledterm.py --display sh1106 --interface i2c --rotate 0
Edit /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
sudo python3 /home/pi/oledterm3/oledterm.py --display sh1106 --interface i2c --rotate 0 &
exit 0
I'm getting this during boot:
[ 33.402269] rc.local[1148]: python3: can't open file 'oledterm/oledterm.py': [Errno 2] No such file or directory
The path I added in /etc/rc.local works fine:
python3 oledterm/oledterm.py --i2c-port 0 --display sh1106
Any idea why it fails to execute during runtime?
You need to Start the script with sudo
SUDO PYTHON3 /home/pi/oledterm/oledterm.py --d sh1106
And you need to use absolute Adress of the oledterm.py
exactly the same
[ 33.826075] rc.local[1166]: python3: can't open file 'oledterm/oledterm.py': [Errno 2] No such file or directory
Here is the complete /etc/rc.local file:
#!/bin/sh -e
rc.local
This script is executed at the end of each multiuser runlevel.
Make sure that the script will "exit 0" on success or any other
value on error.
In order to enable or disable this script just change the execution
bits.
By default this script does nothing.
sudo python3 oledterm/oledterm.py --i2c-port 0 --display sh1106 &
exit 0
You need to Start the script with sudo
SUDO PYTHON3 /home/pi/oledterm/oledterm.py --d sh1106
And you need to use absolute Adress of the oledterm.py
It is the absolute path. It works when I paste it into a Command Prompt
no idea why the formatting is all messed up, sorry about that. #new problems
Hmm... okay. I is that Problem i had last evening, to auto Boot the script via rc.local
I solved it with sudo raspi-config Boot options Boot to Cli with auto login
I'm getting this during boot:
[ 33.402269] rc.local[1148]: python3: can't open file 'oledterm/oledterm.py': [Errno 2] No such file or directory
The path I added in /etc/rc.local works fine:
python3 oledterm/oledterm.py --i2c-port 0 --display sh1106
Any idea why it fails to execute during runtime?
You did not used the absolute Adresse
sudo python3 /home/pi/oledterm/oledterm.py --i2c-port 0 --display sh1106
Here i correct it for you
Absolute Adresse always begin with /xxx/yyy/fite.date
When you use oledterm/oledterm.py --i2c-port 0 --display sh1106
as User it must be saved in your HOME
so editing /etc/rc.local only works with users, not root?
The script rc.local is done durring local loginprogress.
Sudo is to make you root that means
Root is path / Userpath is /home/pi/
So if you write
Oledterm/oledterm.py
It Will not executed, but if you put this code to rc.local
Sudo python3 /home/pi/oledterm/oledterm.py --display sh1106 --interface i2c &
It will run
Getting anything to run automatically has always been a nightmare in Linux, because developers write code to make things happen, and Administrators write code to prevent anything happening
by the way I dont have pi anything, im not using a raspberry pi
Sry plz add
Sudo python3 /home/pi/oledterm/oledterm.py --display sh1106 --interface i2c &
To rc.local
Ok now it's working.
Oledterm doesn't like running under the root account, and my root account was set to autologon. I disabled all that and set oledterm up under the user account (which I had named "admin").
For me the absolute path is:
sudo python3 /home/admin/oledterm/oledterm.py --i2c-port 0 --display sh1106 &
:+1:
Hi Krizzel87, I'm having problems with rendering and random scrolling. When you modified the script to use Python 3, did you use satoshinm's original script, or the oledterm.py which fixes printing to terminal?
You have it ALMOST useable, congratulations on that! But did you use the code listed under " Fix printing to terminal output which causes it to be displayed ad nauseum" on the main oledterm github page?
https://github.com/satoshinm/oledterm/commit/b8b7f89b08d59ddeac146176982de720033fbd14
I debug that with print(data)
But this is raw bytes
So if you want to see output print(str(data))
On my Pi 4 it Works now fine, starts At Boot, before Login in
After you log in, does it display ok?
On mine its flashing and scrolling, its hard to get to the prompt. It looks like satoshinm provided a fix for that
When flashing and popping like an old TV, the program may be started 2 times? Or you startet wrong drivers. I uploaded the wrorking code on https://github.com/Krizzel87/Oledterm_SH1106
Plz check your code, look at rc.local
Check if pi boots to CLI automaticly
Please upload a photo of your oled display immediately after you log in. Thanks!
On mine its hard to use, I only get to the prompt when I press enter many times. Plz upload a photo. Thanks
Oh sry you have an ssd1306
So you need to change the go.sh
sudo phython3 /home/pi/oledterm/oledterm.py --display ssd1306 --interface i2c
Tty this in Cmd
This flashing and popping is because ssd1306 vs sh1106 ist the registersize and mich more
Thats the login screen. Can you go ahead and log in and show me the NEXT screen
On Sun, 23 Aug 2020, 23:48 Krizzel87, [email protected] wrote:
Oh sry you have an ssd1306 So you need to change the go.sh --display ssd1306 --interface i2c
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/satoshinm/oledterm/issues/4#issuecomment-678834716, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFONLDODDXPBGWSPDZ5PHB3SCGMEJANCNFSM4PADFK5Q .
Plz one Moment i try to test it with Kali, and Ubuntu , so pi4 is in Setup
I have SSD1306 and also SH1106, its the same problem for both (after editing for the correct display)
This is SSD1306
It Work now for you? No sh1106 ist not the Same SSD1306 both are oled 1.3 inch. Try to play with arduino to see Differenz. Ssd1306 is better
If your TFT run you of screen all the time correct the in oled.py
rows= 9
Try 8 or 7
Let me know when you get it working after login.
Good luck!
It Work
I dont have issues
Can you upload a photo of your oled screen AFTER you log in. As requested before. Mine is fine up to the login screen, but after I log in its unusable.
On Mon, 24 Aug 2020, 00:47 Krizzel87, [email protected] wrote:
It Work
I dont have issues
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/satoshinm/oledterm/issues/4#issuecomment-678841161, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFONLDKXVXBIO54PTFD4K3TSCGTAJANCNFSM4PADFK5Q .
Also, can I check you changed THIS oledterm.py file and NOT satoshinm's original oledterm.py file? Please confirm
This is SH1106
It Work now for you? No sh1106 ist not the Same SSD1306 both are oled 1.3 inch. Try to play with arduino to see Differenz. Ssd1306 is better
No. see videos.
By the way 0.91" and 0.96" oled displays are always SSD1306 controller. 1.3" oled display is ALMOST always SH1106 controller. They CAN be SSD1306 controller, but this is very rare.
So if you upload a video of your display AFTER YOU LOG IN, and its ok, then I know the problem is with Orange Pi Zero and it can't be fixed. So can you please upload a new video, AFTER log in.
You are lucky! Good work Krizzel87 👍😁
Any idea why its unstable for me? I can't use it.
Would you consider getting an Orange Pi Zero and fixing it for me? As you know its not possible to make a commercial product from a Raspberry Pi, because the Compute module is too expensive.
May be the Resolution is wrong.
Oledterm.py try to play with COLS = 24 and ROWS = 7 . I would try
VIRTUAL_TERMINAL_DEVICE = "/dev/vcsa"
ROWS = 9
COLS = 31
Or try Other fonts in def main or size.
fontname = "tiny.ttf"
size = 6
I know the resolution for both the 0.96" SSD1306 and the 1.3" SSH1106 is 128x64, but surely yours is the same?
I haven't changed the defaults.
But I'll try it later today. What settings did you use to make it stable?
On Mon, 24 Aug 2020, 11:39 Krizzel87, [email protected] wrote:
May be the Resolution is wrong.
Oledterm.py try to play with COLS = 24 and ROWS = 7 . I would try
VIRTUAL_TERMINAL_DEVICE = "/dev/vcsa" ROWS = 9 COLS = 31
Or try Other fonts in def main
fontname = "tiny.ttf" size = 6
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/satoshinm/oledterm/issues/4#issuecomment-679051367, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFONLDI6HFB2HGMKCC2FJNLSCI7PHANCNFSM4PADFK5Q .
I prefer tiny.ttf, but the are more cool fonts.i use size 6 to 12. But always have to fit COLS and ROWS .
On your screen it you truely have to much ROWS try 7
Given that yours works and you are using the same resolution display (128x64), please post your CURRENT values for SIZE, ROWS & COLUMNS
I will match your values and re-test. Hopefully that will fix my problem.
On Mon, 24 Aug 2020, 11:52 Krizzel87, [email protected] wrote:
I prefer tiny.ttf, but the are more cool fonts.i use size 6 to 12. But always have to fit COLS and ROWS
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/satoshinm/oledterm/issues/4#issuecomment-679056291, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFONLDOWYSBQIB5AAEJVQETSCJA5NANCNFSM4PADFK5Q .
Maybe your Problem is that the fontscrip doesnt fit to terminal size and thats why it is shifted? Try to typ clear
after logged in
And see if it will Happen again. I valve rows 9 cols 31 Font tiny.ttf size 6
I haven't changed it from the default "Tiny ttf".
If you could post your own settings for size, rows and columns for a working system using the same screen it would be very helpful.
I haven't changed my settings from the default. (size 6, 9 rows and 31 columns I think from memory)
Thanks in advance. Peter
On Mon, 24 Aug 2020, 12:55 Krizzel87, [email protected] wrote:
Maybe your Problem is that the fontscrip doesnt fit to terminal size and thats why it is shifted? Try to typ clear after logged in
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/satoshinm/oledterm/issues/4#issuecomment-679081819, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFONLDLROQQL7SUWBXYEYLTSCJIKBANCNFSM4PADFK5Q .
I Gott it to Work like yours. It shiftig away all the time
You can fix it, I have much confidence in you 😁
Did you use the code from the later commit, that claims to fix this problem? I sent a screenshot
On Mon, 24 Aug 2020, 13:08 Krizzel87, [email protected] wrote:
I Gott it to Work like yours. It shiftig away all the time
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/satoshinm/oledterm/issues/4#issuecomment-679087708, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFONLDJHDQR5XHVZEKPV2DTSCJJ5RANCNFSM4PADFK5Q .
Shifting oled. Connected hdmi to see terminal
Fixed oled
Hdmi output
It happend during change virtual Terminal2 with cntl Alt F2 . When i go black to virtual terminal 1 it will work.
Dont know how to change Resolution of Terminals. But how ever the issue is there.
Log in and typ in Bash stty rows 7
and stty col 24
It will change the size off terminal play around to find best valvues
Good work. I'll try it later today when I get home.
Peter
On Mon, 24 Aug 2020, 14:02 Krizzel87, [email protected] wrote:
Log in and typ in Bash stty rows 7 and stty col 24
It will change the size off terminal play around to find best valvues
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/satoshinm/oledterm/issues/4#issuecomment-679112518, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFONLDI73H2YU4MHOBRP5DTSCJQG7ANCNFSM4PADFK5Q .
Ok I opened T2 with ctrl-alt-F2, but when I went back to T1 (ctrl-alt-F1) the problem is the exactly the same as shown in my videos. 🙄
I know Richard Hull is looking at doing a complete clean-room rebuild of oledterm, with a view to adding to his luma.examples repo. If you can't fix it maybe he can, or maybe you can fix it together.
Check issue #120 on oled.examples Github page.
https://github.com/rm-hull/luma.examples/issues/120#issuecomment-671255581
Hope this helps
Its good that you're seeing the same issue, so we know it isn't platform specific
Also, can I check you changed THIS oledterm.py file and NOT satoshinm's original oledterm.py file? Please confirm
sorry to be a bore, but can you confirm you modified THIS version of satoshinm's code, and NOT the original?
Satoshinm claims to have fixed our exact problem in this commit. Please advise
Cool never read it before! i used original oledterm. And than run it my self thrue 2to3 and begann to debug it. Test the code with PI 2 B+ . But the load is too much. So my project is dead. Try to edit refresh time from 0.01 to 0.05 but is cpu load over 70%.
The code works with no Problems.
Might be worth enabling some virtual RAM by creating additional swap file? In my example 384MB.
dd if=/dev/zero of=/root/myswapfile bs=1M count=384 chmod 600 /root/myswapfile mkswap /root/myswapfile swapon /root/myswapfile nano /etc/fstab and add the line: /root/myswapfile swap swap defaults 0 swapon -s
I had to do that just to install luma.oled, or the process gets killed from lack of memory.