Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access %s #4

Open
peterbmckinley opened this issue Jul 18, 2020 · 76 comments
Open

Unable to access %s #4

peterbmckinley opened this issue Jul 18, 2020 · 76 comments

Comments

@peterbmckinley
Copy link

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

@peterbmckinley
Copy link
Author

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......

@peterbmckinley
Copy link
Author

bump

@Krizzel87
Copy link

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.

@Krizzel87
Copy link

Krizzel87 commented Aug 22, 2020

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.

@peterbmckinley
Copy link
Author

peterbmckinley commented Aug 22, 2020 via email

@Krizzel87
Copy link

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

@Krizzel87
Copy link

the only thing I need to learn is how data = subprocess.check_output(["screendump"]) is getting the data

@peterbmckinley
Copy link
Author

Good luck! I can't help you with that, but good work 🤞😊

@Krizzel87
Copy link

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

@Krizzel87
Copy link

but you can test it!

@Krizzel87
Copy link

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.

@Krizzel87
Copy link

Krizzel87 commented Aug 22, 2020

To run on boot, add to /etc/rc.local:

sudo python3 /home/pi/oledterm/oledterm.py --display sh1106 --interface i2c --rotate 0 &

@peterbmckinley
Copy link
Author

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

@Krizzel87
Copy link

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/

@Krizzel87
Copy link

I test it with pi 4 latest raspian OS and SH1106.
now it Work. Only issue --rotate 1 und 3 does not work correctly.

@peterbmckinley
Copy link
Author

peterbmckinley commented Aug 22, 2020 via email

@Krizzel87
Copy link

Krizzel87 commented Aug 22, 2020

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

@peterbmckinley
Copy link
Author

It works! Thank you :)

@peterbmckinley
Copy link
Author

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?

@Krizzel87
Copy link

Krizzel87 commented Aug 23, 2020

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

@peterbmckinley
Copy link
Author

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?

@Krizzel87
Copy link

Krizzel87 commented Aug 23, 2020

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

@peterbmckinley
Copy link
Author

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

@peterbmckinley
Copy link
Author

no idea why the formatting is all messed up, sorry about that. #new problems

@Krizzel87
Copy link

Krizzel87 commented Aug 23, 2020

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

@Krizzel87
Copy link

Krizzel87 commented Aug 23, 2020

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

@peterbmckinley
Copy link
Author

so editing /etc/rc.local only works with users, not root?

@Krizzel87
Copy link

Krizzel87 commented Aug 23, 2020

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

@peterbmckinley
Copy link
Author

peterbmckinley commented Aug 23, 2020

I have SSD1306 and also SH1106, its the same problem for both (after editing for the correct display)

ezgif com-video-to-gif

This is SSD1306

@Krizzel87
Copy link

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

@Krizzel87
Copy link

If your TFT run you of screen all the time correct the in oled.py

rows= 9

Try 8 or 7

@peterbmckinley
Copy link
Author

Let me know when you get it working after login.

Good luck!

@Krizzel87
Copy link

It Work

I dont have issues

@peterbmckinley
Copy link
Author

peterbmckinley commented Aug 23, 2020 via email

@peterbmckinley
Copy link
Author

fix_oled
Also, can I check you changed THIS oledterm.py file and NOT satoshinm's original oledterm.py file? Please confirm

@peterbmckinley
Copy link
Author

SH1106

This is SH1106

@peterbmckinley
Copy link
Author

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.

@peterbmckinley
Copy link
Author

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.

@Krizzel87
Copy link

20200824_023314_3.gif

20200824_023314_2.gif

20200824_023314_1.gif

@peterbmckinley
Copy link
Author

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.

@Krizzel87
Copy link

Krizzel87 commented Aug 24, 2020

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

@peterbmckinley
Copy link
Author

peterbmckinley commented Aug 24, 2020 via email

@Krizzel87
Copy link

Krizzel87 commented Aug 24, 2020

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

@peterbmckinley
Copy link
Author

peterbmckinley commented Aug 24, 2020 via email

@Krizzel87
Copy link

Krizzel87 commented Aug 24, 2020

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

@peterbmckinley
Copy link
Author

peterbmckinley commented Aug 24, 2020 via email

@Krizzel87
Copy link

I Gott it to Work like yours.
It shiftig away all the time

@peterbmckinley
Copy link
Author

peterbmckinley commented Aug 24, 2020 via email

@Krizzel87
Copy link

Krizzel87 commented Aug 24, 2020

20200824_142432_1.gif
Shifting oled. Connected hdmi to see terminal
20200824_142456.jpg

Fixed oled

20200824_142522_1.gif

Hdmi output
20200824_142616.jpg

@Krizzel87
Copy link

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.

@Krizzel87
Copy link

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

@peterbmckinley
Copy link
Author

peterbmckinley commented Aug 24, 2020 via email

@peterbmckinley
Copy link
Author

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.

rm-hull/luma.examples#120 (comment)

Hope this helps

@peterbmckinley
Copy link
Author

Its good that you're seeing the same issue, so we know it isn't platform specific

@peterbmckinley
Copy link
Author

fix_oled
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

@Krizzel87
Copy link

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.

@peterbmckinley
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants