d-bieber / pi_statusdisplay

Small Python status script, which displays informations on a 2.7" OLED
MIT License
8 stars 2 forks source link

pi_statusdisplay and sh1306 i2c device #1

Open bighegi opened 4 years ago

bighegi commented 4 years ago

Hi Dominik, I got luma.oled running on my rpi with an sh1306 i2c oled display.

Running the sample code from the luma.oled project works without a problem.

As I am more an interested user than a coder, I am suffering difficulties getting pi_statusdisplay to work. My assumption is, that you start the main.py to fire everything up. Upon trying this I get:

`$ python3 main.py Version: luma.oled 3.4.0 (luma.core 1.12.0) Display: ssd1306 Interface: i2c Dimensions: 128 x 64

Traceback (most recent call last): File "main.py", line 8, in import oled_control as oled #Modifizierter Display-Treiber File "/root/pi_statusdisplay/oled_control.py", line 284, in font = make_font(STANDARD_FONT, STANDARD_FONT_SIZE) File "/root/pi_statusdisplay/oled_control.py", line 35, in make_font return ImageFont.truetype(font_path, size) File "/usr/local/lib/python3.7/dist-packages/PIL/ImageFont.py", line 642, in truetype return freetype(font) File "/usr/local/lib/python3.7/dist-packages/PIL/ImageFont.py", line 639, in freetype return FreeTypeFont(font, size, index, encoding, layout_engine) File "/usr/local/lib/python3.7/dist-packages/PIL/ImageFont.py", line 188, in init font, size, index, encoding, layout_engine=layout_engine OSError: cannot open resource ` Any help on this is highly appreciated. Cheers,

bighegi.

d-bieber commented 4 years ago

Hi, it looks like you don't have the necessary fonts installed. Simply put the folder 'fonts' in the same folder as the main.py, or change the path to it in der oled_control.py. But I'm afraid this won't be the last issue, because I never made the code compatible to Python3. I would recommend, that you try to make it work with Python2.7.

bighegi commented 4 years ago

Hi Dominik, downgrading to 2.7 and the fonts issue helped a lot.

Now I got

If you got an idea or two, this would surely help. Thanks a lot in advance! Cheers, bighegi.

d-bieber commented 4 years ago

Hi, sorry for the late response. I'm not at home right now, so I can't have a look at my pi. But I try to help you remotely.

The getWeather.py is meant to be called externally via cronjob and edits the weather.wtd. The main.py only reads the weather.wtd. I don't know if the getWeather.py can create the file, so the best would be to create an empty file. The piHole Status is odd. Could you show me the output of your /api.php?status ?

bighegi commented 4 years ago

Hi Dominik, I'm a bit further, thanks to you hints. But not yet fully there.

  1. I did a "touch weather.wtd" and "touch storm.wtd".
  2. I changed the area for the weather warnings to my area.
  3. I tried to put my location in the openweathermap call.
  4. Then ran getWeather.py and afterwards main.py

The good news: The weather-warnings work now :). However I have an issue with the openweathermap. Here's what I tried: LOCATION_ID = '2871034' ## my hometown "Löhne" and later on I found "YOURDATA" not clear to me ... response = url.urlopen('http://api.openweathermap.org/data/2.5/'+ YOURDATA) I tried ... response = url.urlopen('https://api.openweathermap.org/data/2.5/weather?q=L%C3%B6hne,de&appid=[my api key here]') or alternatively ... response = url.urlopen('https://api.openweathermap.org/data/2.5/weather?id=2871034&appid=[my api key here]') ... how is this code supposed to look like? - I'd appreciate an example from you.

Thanks a lot in advance. bighegi.

bighegi commented 4 years ago

... me again, now the pihole.py issues.

When I call "api.php?status" I get: status: "enabled" The "api.php" gives me for the first entries: domains_being_blocked: 970689 dns_queries_today: 1733 ads_blocked_today: 445 ads_percentage_today: 25.678015 ... lines 2-4 is exactly what "__oldPiholeStatus()" reports. I suppose this is an issue with the other way of drawing text in piholeStatus(). I'm not sure whether this is an I2C or an ssd1306 issue ... in theory luma.oled should take care of this. Interesting though, that the percentage-graph works ...

Well, maybe you got another idea here, too? Tnx & good night bighegi.

d-bieber commented 3 years ago

Hey, I'm sorry I didn't answer your messages. Today I updated the script to work in Python3. I also did a bit of refactoring and inline documentation. I hope some things get a lot clearer now. Maybe your first issue with getWeather will be solved. The API response from pihole looks fine to me. But maybe this issue is solved now too with the new version.

If something's not working please don't hesitate to ask again here. I promise I will answer much faster next time ;)

Dominik

bighegi commented 3 years ago

Hi Dominik, ... I'm slowly getting forward, but there are still issues. Just for clarification:

Thx & stay healty bighegi.

d-bieber commented 3 years ago

Hi,

bighegi commented 3 years ago

Hi Dominik, yes, I forgot the python3 ... I uninstalled python-dev but not python-2.7 ... too bad. The good news: The script now runns, but it does not do what it is supposed to do.

It recognizes the the ssd1306, makes the font-test with the 4 lines of text and shows the analog clock for 10 secs. Then the display blanks and after about 2 minutes, it shows the clock for another 10secs. - Which means, none of the other modules are working ;-((.

The fonts dir looks like this:

ls -l fonts insgesamt 9044 -rw-r--r-- 1 root root 49432 Mär 10 19:20 'C&C Red Alert [INET].ttf' -rw-r--r-- 1 root root 11380 Mär 10 19:20 ChiKareGo.ttf -rw-r--r-- 1 root root 8377000 Mär 10 19:20 code2000.ttf -rw-r--r-- 1 root root 85484 Mär 10 19:20 creep.bdf -rw-r--r-- 1 root root 134316 Aug 5 22:23 fa-brands.ttf -rw-r--r-- 1 root root 203980 Aug 5 22:24 fa-solid.ttf -rw-r--r-- 1 root root 165548 Mär 10 19:20 fontawesome-webfont.ttf -rw-r--r-- 1 root root 64880 Mär 10 19:20 FreePixel.ttf -rw-r--r-- 1 root root 23280 Mär 10 19:20 miscfs_.ttf -rw-r--r-- 1 root root 22184 Mär 10 19:20 pixelmix.ttf -rw-r--r-- 1 root root 35656 Mär 10 19:20 ProggyTiny.ttf -rw-r--r-- 1 root root 2847 Mär 10 19:20 'README [INET].txt' -rw-r--r-- 1 root root 6656 Mär 10 19:20 tiny.ttf -rw-r--r-- 1 root root 55580 Mär 10 19:20 Volter__28Goldfish_29.ttf

And the config.ini like this:

cat config.ini [weather] cityid1 = 2871034 cityid2 = 2988507

apikey = [top secret]

Storm ID from dwd.de - Only for Germany (Example ID: Munich)

stormid = 10575800

[pihole] ip = 192.168.2.60

Only for German stations

[timetable] station = Köln Hbf

Next I rememberd, I forgot to run python3 get_weather.py (which creates strom.wtd and weather.wtd). When running python3 main.py I get again only the following output on the console:

python3 main.py Version: luma.oled 3.4.0 (luma.core 1.12.0) Display: ssd1306 Interface: i2c Dimensions: 128 x 64

The only change to the previous tests is, that the analog clock flickers on and off a couple of times ...

And there my creativity ends for today ... Any help is appreciated ... Cheers

Stefan.

d-bieber commented 3 years ago

That's odd. Could you post your crash.log? I only have one idea: Every font in the font folder is owned by root. I think it shouldn't be a problem, but please try in your folder where fonts/ lies: sudo chown -R pi:pi font/ This sets the owner of the folder fonts and every file in it to pi.

bighegi commented 3 years ago

Hi Dominik, I do not have a user "pi" and I am running these tests as root. Therefore access ought to be not the problem, I think. Moreover, fonts is world-executable + -readable and all the fonts are world-readable. The crash.log is empty.

Any other ideas? Thx again

Stefan.

d-bieber commented 3 years ago

Hm, there should at least be something in the crash.log. If there is no exception the problem lies probably deeper but first let's check if the functions are running without an error. First set DEBUG to True and add at the near bottom of the file a print(str(e) in the except from weather() so it should look like this:

...
        try:
            weather()
        except Exception as e:
           print(str(e)
           crashWriter("Weather",e)
        nightMode()
...
bighegi commented 3 years ago

Hi Dominik, thanks for bearing with me. When just setting DEBUG=True, I get the following output

python3 main.py Version: luma.oled 3.4.0 (luma.core 1.12.0) Display: ssd1306 Interface: i2c Dimensions: 128 x 64

Clock Weather Storm piHole Status Timetable PiStatus Clock Weather ^C Stopped by KeyboardInterrupt

Interesting is, than when it writes Weather, the Clock flashes on again for the fraction of a second. Timetable takes >1min. All other modules go through smoothly.

Regarding the extra command, I added a closing bracket: print(str(e)) to make it work, but I get no extra output on the console. As there are no errors or problems (and no entries in crash.log ... I even made it word-writeable ... just in case), I suspect there is a problem with either:

  1. a missing package (e.g. vcgencmd did not provide status data previously, because it was missing - package libraspberrypi-bin needed to be installed)
  2. the fonts, or
  3. with the OLED config / communications (mine is a ssd1306)
  4. some problem with my path

As the luma-test-modules work, 3. seems less likely.

As I had already font-problems with the python2.7-Version (namely: Pihole module, I got only the bar, not the text. This was the only function, where explicitly a font was specified; oldPiholeStatus works fine), but the fonts are there, I assume that maybe I miss some odd python package for processing ttf-fonts or so ...

If there was a python-fonts package missing,I'd expect some error message. Nevertheless, what about:

python3-fonttools ... I shy away from a quick try, as this wants to install 60(!) packages in total due to dependencies.

python3-qtawesome ... I shy away from a quick try, as this wants to install 72(!) packages in total due to dependencies.

As I am currently testing, I have everything in /root/pi_statusdisplay - could this be a problem to font-access?

That's all I got for now. Thanks again. And keep cool in the heat today!

bighegi.

d-bieber commented 3 years ago

Hi,

what os is running on your Raspi? You said you don't have a user named 'pi' so I suspect you have some other type of linux running? I recently formatted my pi and installed the new version of Raspberry Pi OS (former Raspbian). Except from luma.oled I didn't have to download anything else. It's really odd the script is not throwing errors. If it couldn't find some packets or fonts he should throw something. But it's running normally, so that shouldn't be the case. Also really odd is, that timetable takes so long. This means internally my script for scrolling the text is running fine. It just displays nothing. My only idea is, that some of my scripts for printing I wrote in oled_control, are working (or not working) differently on your hardware. But I cant't understand why, as luma should handle everything and even our resolution is the same.

I wrote a absolutely minimum program for you that prints some infos and should show something on the screen. First it prints with my method. After 5 seconds it draws text on the screen like the clock is drawn or the pihole screen. Let me know what you're seeing and what the console says.

import oled_control as oled

from luma.core.render import canvas

import time

device = oled.getDevice()
font = oled.getFont()
print('Lines: ' + str(oled.getHeight()))
print('Line-Width: ' + str(oled.getWidth()))

oled.scPrint('Line1','Line2')

time.sleep(5)

with canvas(device) as draw:
    draw.text((0,30), font=font, text='Canvas Text')

time.sleep(1000000)

Hiding from the heat, working on my display Dominik

bighegi commented 3 years ago

Hi Dominik, ... well I'am running a raspbian buster. BUT originally this was a voyage-mpd installation (http://linux.voyage.hk/voyage-mpd) for raspbian ... but that was discontinued long ago.

In the meantime I added a lot of stuff, including pihole and upgraded all the way to buster. Since I have so much special stuff on this box, I shy away from a new install.

What I suggest is, you do a dpkg --get-selections |egrep python and compare that to my output (I currently have python-2.7 and python-3 in parallel). - Very likely this will show the missing package.

dpkg --get-selections |egrep python dh-python install libpython-dev:armhf install libpython-stdlib:armhf install libpython2-dev:armhf install libpython2-stdlib:armhf install libpython2.7:armhf install libpython2.7-dev:armhf install libpython2.7-minimal:armhf install libpython2.7-stdlib:armhf install libpython3-dev:armhf install libpython3-stdlib:armhf install libpython3.5-minimal:armhf deinstall libpython3.7:armhf install libpython3.7-dev:armhf install libpython3.7-minimal:armhf install libpython3.7-stdlib:armhf install python install python-configparser install python-dev install python-gobject-2 install python-minimal install python-pip install python-pip-whl install python-talloc:armhf install python2 install python2-dev install python2-minimal install python2.7 install python2.7-dev install python2.7-minimal install python3 install python3-dev install python3-distutils install python3-lib2to3 install python3-minimal install python3.5-minimal deinstall python3.7 install python3.7-dev install python3.7-minimal install

I tried your code. Copied it into a file called test.py and run it with python3. - As expected, the display says nothing ;-(. On the console I get:

python3 test.py Version: luma.oled 3.4.0 (luma.core 1.12.0) Display: ssd1306 Interface: i2c Dimensions: 128 x 64

Lines: 6 Line-Width: 21 Traceback (most recent call last): File "test.py", line 22, in ^C time.sleep(1000000) KeyboardInterrupt I hit -C after a few minutes, then changed the value for the final time.sleep :-).

... but the working output with python-2.7 was generated with oled.oPrint() and oled.println(). I tried to modify your sample code accordingly, but I did not get oled.oPrint() to work. oled.println() works fine with python 2.7 and 3:

oled.println(oled.center("Line 1")) oled.println(oled.center("Line 2"))

Any more clues? Thanks again. bighegi.

d-bieber commented 3 years ago

Hi,

here my output from dpkg. There are definitely some differences. Did you install luma.oled accordingly to this manual?

pi@raspberrypi:~ $ dpkg --get-selections | egrep python
dh-python                                       install
libpython-stdlib:armhf                          install
libpython2-stdlib:armhf                         install
libpython2.7-minimal:armhf                      install
libpython2.7-stdlib:armhf                       install
libpython3-dev:armhf                            install
libpython3-stdlib:armhf                         install
libpython3.7:armhf                              install
libpython3.7-dev:armhf                          install
libpython3.7-minimal:armhf                      install
libpython3.7-stdlib:armhf                       install
python                                          install
python-apt-common                               install
python-minimal                                  install
python-pip-whl                                  install
python-rpi.gpio                                 install
python2                                         install
python2-minimal                                 install
python2.7                                       install
python2.7-minimal                               install
python3                                         install
python3-apt                                     install
python3-asn1crypto                              install
python3-certifi                                 install
python3-cffi-backend                            install
python3-chardet                                 install
python3-crypto                                  install
python3-cryptography                            install
python3-dbus                                    install
python3-debconf                                 install
python3-dev                                     install
python3-distutils                               install
python3-entrypoints                             install
python3-gi                                      install
python3-idna                                    install
python3-keyring                                 install
python3-keyrings.alt                            install
python3-lib2to3                                 install
python3-minimal                                 install
python3-pip                                     install
python3-pkg-resources                           install
python3-requests                                install
python3-secretstorage                           install
python3-setuptools                              install
python3-six                                     install
python3-urllib3                                 install
python3-wheel                                   install
python3-xdg                                     install
python3.7                                       install
python3.7-dev                                   install
python3.7-minimal                               install

At least the draw.text should have drawn something on the screen. That's bare code from luma.oled. So my guess is that it's the few missing python3 libs. Still not understanding why no exceptions are thrown. Maybe bad error handling on luma's side?

bighegi commented 3 years ago

Hi Dominik, thanks for your patience with me :). I installed all the missing python packages ... though the crypto stuff is clearly not needed ... whatever ... I did install luma historically following the specified manual in your post. Now I just re-installed and upgraded form 3.4.0 to 3.5.0. ... but this does not change anyting. ;-(.

Then I checked out the latest luma.examples - python3 font_awesome.py works without problems showing the fa pictograms. My suspicion is, that something is wrong with the fonts directory, especially with the two manually downloaded ttf-fonts. Could you please compare name and size to yours?

-rw-r--r-- 1 root root 134316 Aug 5 22:23 fa-brands.ttf -rw-r--r-- 1 root root 203980 Aug 5 22:24 fa-solid.ttf

Copying the fonts dir from the luma examples over mine for the rest of the fonts did not change anything. Or could it have something to do with me having just a 1" ssd1306 (instead of the bigger ssd1325)?

I'm really running out of ideas ... this all feels so wrong. It's probably just a minor tweak which is obviously out in the open ... and I miss it.

Thanks again bighegi.

d-bieber commented 3 years ago

Hey,

no problem. At this point I'm just as curious as you are ;)

Oh no. I really hoped the missing packages were the problem... I just replaced my fonts folder with a fresh download from FontAwesome and the example fonts. Still working for me.

-rw-r--r-- 1 pi pi  134316 Aug  9 21:53  fa-brands.ttf
-rw-r--r-- 1 pi pi  203980 Aug  9 21:53  fa-solid.ttf
-rw-r--r-- 1 pi pi   35656 Aug  9 21:51  ProggyTiny.ttf

Or could it have something to do with me having just a 1" ssd1306 (instead of the bigger ssd1325)?

Well, I never tested it on another display. But the differences should be handled by luma.oled and I tried to write my methods to be broadly usable. Furthermore the resolution is the same on both of our displays. I don't understand, why you can run luma.examples, but not my small script which just use the draw from examples. Did you try to run a few different example files? Maybe there are some issues, too.

Which display exactly do you have? The issue says sh1306, but in your last answer you said ssd1306. The scripts are running with this device description, too. Did you try some other display-configs? For example python3 main.py --display=sh1106 or any of those:

 'ssd1306', 'ssd1309', 'ssd1322', 'ssd1362', 'ssd1322_nhd', 'ssd1325', 'ssd1327', 'ssd1331', 'ssd1351', 'sh1106', 'pcd8544', 'st7735', 'ht1621', 'uc1701x', 'st7567', 'ili9341', 'max7219', 'ws2812')

To rule out my oled_config I modified the little script I sent you yesterday. It now only uses luma directly.

from luma.core.render import canvas
from demo_opts import get_device

import time
import os
from PIL import ImageFont

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)

device = get_device()
font = make_font("ProggyTiny.ttf", 16)

print('Device: ' + str(device))
print('Font: ' + str(font))

with canvas(device) as draw:
    draw.text((0,30), font=font, text='Canvas Text')

time.sleep(10)

Dominik

bighegi commented 3 years ago

Hi Dominik, ... this thing is starting to drive me nuts ...

Your new test script is showing on the OLED ... nothing!

python3 test2.py Version: luma.oled 3.5.0 (luma.core 1.14.1) Display: ssd1306 Interface: i2c Dimensions: 128 x 64

Device: <luma.oled.device.ssd1306 object at 0x75f56b70> Font: <PIL.ImageFont.FreeTypeFont object at 0x75f56a50>

Other things I did:

With PYTHON3: These example-schripts work: 3d_box.py, animated_gif.py, bounce.py, chroma.py, clock.py, colors.py, crawl.py (...cool), demo.py (no dimming though), font_awesome.py, game_of_life.py, greyscale.py, image_composition.py, invaders.py, jetset_willy.py, larson_hue.py, matrix.py, maze.py, perfloop.py, pi_logo.py, runner.py, savepoint.py, scrolling_pixelart.py, sprite_animation.py, starfield.py, terminal.py (though the progress bar does not show, only the percentages), tv_snow.py, welcome.py

These example-scritps do NOT work: carousel.py (fails to import psutil), sevensegment_demo.py (not supported on a ssd1306 device), sys_histogram.py (fails to import psutil), sys_info.py (fails to import psutil), scripts in hotspot dir (fails to import psutil and hotspot module)

BUT... after the installation of "python3-psutil" working: carousel.py, sys_histogram.py, sys_info.py

Not sure: dotmatrixtool.py (says only "HELP" on screen) ... but seems to be working after psutil installation ...

These scripts require dependencies (I have not installed so far): bitstamp_realtime.py (requires pusherclient), bitstamp_ticzker.py (requires requests), picamera_photo.py & picamera_video.py (require picamera), tweet_scroll.py (requires tweepy), video.py (requires pyav), weather.py (requires feedparser)

Effects of the installation of psutils on main.py: I do now get the char-test of all the different chars at startup, then a blank screen and afterwards the clock. The rest remains blank as before ... but the char-test worked only on the old version with python2 so far. So the installation of python3-psutil helped a little ...

But still not getting there ... Tried again your first test.py script ... no outout. The same applies for the second test-script.

Frustrated for the moment after 2 hours of testing, I hope you find another clue ...

Thx & Greetings bighegi.