Starting SH1106 OLED-based console at boot?

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Starting SH1106 OLED-based console at boot?

Post by istanbulls » Fri May 29, 2020 3:43 am

How do I run SH1106 Oled at startup?
OS: Ubuntu 20.04 LTS (Linux kernel 5.7)
The path to the ".py" extension I want to run: /home/odroid/luma.examples/examples

It should be an easy method but I don't know sorry :)

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Tue Jun 02, 2020 9:49 pm

Isn't there a way to start the oled screen with boot?

User avatar
mad_ady
Posts: 8155
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, C4, N1, N2, H2, Go, Go Advance
Location: Bucharest, Romania
Has thanked: 568 times
Been thanked: 404 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by mad_ady » Tue Jun 02, 2020 11:27 pm

Try adding it to /etc/rc.local.

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Wed Jun 03, 2020 1:37 am

@mad_ady
Thanks for the answer,

I tried this, but it failed.:)
Last edited by istanbulls on Wed Jun 03, 2020 5:46 pm, edited 2 times in total.

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Wed Jun 03, 2020 1:55 am

I made a few hours trial sample with Python.
I am curious about your opinion.
Which watch do you think was better?
Is this?
WhatsApp Image 2020-06-02 at 19.43.33(2).jpeg
WhatsApp Image 2020-06-02 at 19.43.33(2).jpeg (92.72 KiB) Viewed 1497 times
Is this?
WhatsApp Image 2020-06-02 at 19.43.33(1).jpeg
WhatsApp Image 2020-06-02 at 19.43.33(1).jpeg (92.29 KiB) Viewed 1497 times
Attachments
WhatsApp Image 2020-06-02 at 20.05.48.jpeg
WhatsApp Image 2020-06-02 at 20.05.48.jpeg (112.94 KiB) Viewed 1496 times
WhatsApp Image 2020-06-02 at 20.05.13.jpeg
WhatsApp Image 2020-06-02 at 20.05.13.jpeg (90.83 KiB) Viewed 1496 times
These users thanked the author istanbulls for the post:
Luke.go (Wed Jun 03, 2020 2:16 pm)

User avatar
odroid
Site Admin
Posts: 34642
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 824 times
Been thanked: 712 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by odroid » Wed Jun 03, 2020 10:53 am

Very nice 7-segment fonts rendering.
I love the first one.

BTW, is it 0.96inch? or 1.3inch display?

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Wed Jun 03, 2020 5:18 pm

Thank you for your idea,

1.3inch display

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Wed Jun 03, 2020 5:51 pm

mad_ady wrote:
Tue Jun 02, 2020 11:27 pm
Try adding it to /etc/rc.local.
sudo nano /etc/rc.local

Code: Select all

python3 alp-clk.py
I tried this way but I failed.

User avatar
mad_ady
Posts: 8155
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, C4, N1, N2, H2, Go, Go Advance
Location: Bucharest, Romania
Has thanked: 568 times
Been thanked: 404 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by mad_ady » Wed Jun 03, 2020 8:36 pm

/etc/rc.local needs to be marked as executable, must begin with #!/bin/bash ad should contaim full paths to pythonm and your script and should end with exit 0

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Wed Jun 03, 2020 9:41 pm

It works when I enter the code "$ bash -x /etc/rc.local" from the terminal.

I changed the code again as you described, the result is the same, negative.
/etc/rc.local

Code: Select all

#!/bin/bash
python3 /home/odroid/alp-clk.py 
exit 0

User avatar
mad_ady
Posts: 8155
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, C4, N1, N2, H2, Go, Go Advance
Location: Bucharest, Romania
Has thanked: 568 times
Been thanked: 404 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by mad_ady » Wed Jun 03, 2020 10:16 pm

Try with

Code: Select all

#!/bin/bash
date > /tmp/runtime.log
/usr/bin/python3 /home/odroid/alp-clk.py >/tmp/display.log 2>&1
exit 0
If it complains about something you should see it in /tmp/display.log. If /rc.local is run you should see a date in /tmp/runtime.log.

User avatar
tobetter
Posts: 5211
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 176 times
Been thanked: 546 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by tobetter » Wed Jun 03, 2020 10:29 pm

@istanbulls, can you run this command systemctl status rc-local.service and check if it says if the service is active?

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Wed Jun 03, 2020 11:12 pm

mad_ady wrote:
Wed Jun 03, 2020 10:16 pm
Try with

Code: Select all

#!/bin/bash
date > /tmp/runtime.log
/usr/bin/python3 /home/odroid/alp-clk.py >/tmp/display.log 2>&1
exit 0
If it complains about something you should see it in /tmp/display.log. If /rc.local is run you should see a date in /tmp/runtime.log.
after reboot the system
/tmp/ no runtime.log
/tmp/ no display.log

when running "bash -x /etc/rc.local" from the terminal:
oled works
/tmp/ yes runtime.log & no error message
/tmp/ yes display.log & have date and time information

result: "oled" does not work with system startup, works when running "bash -x /etc/rc.local" code with terminal.

I am very grateful for your help, I am a rookie and I know that I have exhausted you. embarrassed and sorry

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Wed Jun 03, 2020 11:15 pm

tobetter wrote:
Wed Jun 03, 2020 10:29 pm
@istanbulls, can you run this command systemctl status rc-local.service and check if it says if the service is active?

Code: Select all

Warning: The unit file, source configuration file or drop-ins of rc-local.servi>
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor prese>
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: inactive (dead)
       Docs: man:systemd-rc-local-generator(8)
lines 1-7/7 (END)

User avatar
tobetter
Posts: 5211
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 176 times
Been thanked: 546 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by tobetter » Wed Jun 03, 2020 11:17 pm

istanbulls wrote:
Wed Jun 03, 2020 11:15 pm
tobetter wrote:
Wed Jun 03, 2020 10:29 pm
@istanbulls, can you run this command systemctl status rc-local.service and check if it says if the service is active?

Code: Select all

Warning: The unit file, source configuration file or drop-ins of rc-local.servi>
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor prese>
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: inactive (dead)
       Docs: man:systemd-rc-local-generator(8)
lines 1-7/7 (END)
It's worth to try, IMO.
https://www.linuxbabe.com/linux-server/ ... th-systemd

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Wed Jun 03, 2020 11:46 pm

tobetter wrote:
Wed Jun 03, 2020 11:17 pm
istanbulls wrote:
Wed Jun 03, 2020 11:15 pm
tobetter wrote:
Wed Jun 03, 2020 10:29 pm
@istanbulls, can you run this command systemctl status rc-local.service and check if it says if the service is active?

Code: Select all

Warning: The unit file, source configuration file or drop-ins of rc-local.servi>
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor prese>
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: inactive (dead)
       Docs: man:systemd-rc-local-generator(8)
lines 1-7/7 (END)
It's worth to try, IMO.
https://www.linuxbabe.com/linux-server/ ... th-systemd
Thanks :)

Code: Select all

Warning: The unit file, source configuration file or drop-ins of rc-local.servi>
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor pres>
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: active (exited) since Wed 2020-06-03 17:33:27 +03; 5min ago
    Process: 2721 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

Haz 03 17:33:27 ubuntu systemd[1]: Starting /etc/rc.local Compatibility...
Haz 03 17:33:27 ubuntu systemd[1]: Started /etc/rc.local Compatibility.
lines 1-10/10 (END)
but "oled" system did not start with reboot :oops:
keep trying ! :D

User avatar
mad_ady
Posts: 8155
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, C4, N1, N2, H2, Go, Go Advance
Location: Bucharest, Romania
Has thanked: 568 times
Been thanked: 404 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by mad_ady » Wed Jun 03, 2020 11:54 pm

Do you have anything in the log files?

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Wed Jun 03, 2020 11:58 pm

sudo nano /etc/rc.local

Code: Select all

#!/bin/bash
/usr/bin/python3 /home/odroid/alp-clk.py
exit 0
#!/bin/bash
exit 0

I changed the code again.
Now everything is perfect.
Thank you very much for all your help.
These users thanked the author istanbulls for the post:
odroid (Thu Jun 04, 2020 8:47 am)

User avatar
odroid
Site Admin
Posts: 34642
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 824 times
Been thanked: 712 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by odroid » Thu Jun 04, 2020 8:48 am

Glad to hear that finally. :D

If you don't mind, please share the Python code.
I want to add an OLED digital clock to my poor C4 board.

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Thu Jun 04, 2020 5:40 pm

odroid wrote:
Thu Jun 04, 2020 8:48 am
Glad to hear that finally. :D

If you don't mind, please share the Python code.
I want to add an OLED digital clock to my poor C4 board.
I would like to share with pleasure.

I made the codes by combining many examples.
python and software do not know at all. I used trial and error method. so bad codes might be too much :) but it will work.

User avatar
odroid
Site Admin
Posts: 34642
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 824 times
Been thanked: 712 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by odroid » Thu Jun 04, 2020 5:50 pm

Great!
Let's try polishing the codes together once you release it. :D

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Thu Jun 04, 2020 6:23 pm

This uses Luma drivers. To get them installed, follow their instructions:
https://github.com/rm-hull/luma.examples
https://luma-oled.readthedocs.io/en/latest/index.html

You need to put the DSEG7Modern-Bold.ttf font I use into the examples/fonts folder:
https://github.com/urish/ng2-simon/blob ... n-Bold.ttf


Example script for sh1106 1.3inc oled

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2014-18 Richard Hull and contributors
# See LICENSE.rst for details.
# PYTHON_ARGCOMPLETE_OK

"""
An analog clockface with date & time.

"""



from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import ssd1306, ssd1325, ssd1331, sh1106
from time import sleep
from PIL import ImageFont, ImageDraw, Image
import time
import datetime

serial = i2c(port=1, address=0x3C)
device = sh1106(serial, rotate=0)

def main():
    today_last_time = "Unknown"
    while True:
        now = datetime.datetime.now()
        today_date = now.strftime("%d %b %y")
        today_time = now.strftime("%H:%M")
        if today_time != today_last_time:
            today_last_time = today_time
            with canvas(device) as draw:
                  font = ImageFont.truetype('./home/odroid/luma.examples/examples/fonts/DSEG7Modern-Bold.ttf',36)
                  draw.text((-2, 27), today_time, font=font, fill=1)
                  font = ImageFont.truetype('./home/odroid/luma.examples/examples/fonts/DSEG7Modern-Bold.ttf',20)
                  draw.text((10, 0), today_date, font=font, fill=1)
        time.sleep(0.1)


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        pass
For the ssd1306 oled screen, you must change the code device = sh1106 (serial, rotate = 0) to device = ssd1306 (serial, rotate = 0) this change should be sufficient.

(I don't have ssd1306 oled screen, I haven't tried!)
Last edited by istanbulls on Thu Jun 04, 2020 7:28 pm, edited 1 time in total.

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Thu Jun 04, 2020 6:52 pm

The new project I want to do:

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2014-18 Richard Hull and contributors
# See LICENSE.rst for details.
# PYTHON_ARGCOMPLETE_OK

"""
Showcase viewport and hotspot functionality.

Loosely based on poster_demo by @bjerrep
https://github.com/bjerrep/ssd1306/blob/master/examples/poster_demo.py

Needs psutil (+ dependencies) installed::
  $ sudo apt-get install python-dev
  $ sudo pip install psutil
"""

import psutil
from luma.core.virtual import viewport, snapshot
from hotspot import memory, cpu_load, clock, network
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import sh1106

# rev.1 users set port=0
# substitute spi(device=0, port=0) below if using that interface
serial = i2c(port=1, address=0x3C)

# substitute ssd1331(...) or sh1106(...) below if using that device
device = sh1106(serial)


def position(max):
    forwards = range(0, max)
    backwards = range(max, 0, -1)
    while True:
        for x in forwards:
            yield x
        for x in backwards:
            yield x


def pause_every(interval, generator):
    try:
        while True:
            x = next(generator)
            if x % interval == 0:
                for _ in range(66):
                    yield x
            else:
                yield x
    except StopIteration:
        pass


def intersect(a, b):
    return list(set(a) & set(b))


def first(iterable, default=None):
    if iterable:
        for item in iterable:
            return item
    return default


def main():
    if device.rotate in (1, 1):
        # Horizontal
        widget_width = device.width // 1
        widget_height = device.height
    else:
        # Vertical
        widget_width = device.width
        widget_height = device.height // 1

    # Either function or subclass
    #  cpuload = hotspot(widget_width, widget_height, cpu_load.render)
    #  cpuload = cpu_load.CPU_Load(widget_width, widget_height, interval=1.0)
    cpuload = snapshot(widget_width, widget_height, cpu_load.render, interval=0.5)
    clk = snapshot(widget_width, widget_height, clock.render, interval=0.5)


   
    widgets = [clk, cpuload]

    if device.rotate in (1, 1):
        virtual = viewport(device, width=widget_width * len(widgets), height=widget_height)
        for i, widget in enumerate(widgets):
            virtual.add_hotspot(widget, (i * widget_width, 0))

        for x in pause_every(widget_width, position(widget_width * (len(widgets) - 1))):
            virtual.set_position((x, 0))

    else:
        virtual = viewport(device, width=widget_width, height=widget_height * len(widgets))
        for i, widget in enumerate(widgets):
            virtual.add_hotspot(widget, (0, i * widget_height))

        for y in pause_every(widget_height, position(widget_height * (len(widgets) - 1))):
            virtual.set_position((0, y))
            
            


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        pass
I want to replace the analog clock with the digital clock I made. :D ;)

User avatar
odroid
Site Admin
Posts: 34642
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 824 times
Been thanked: 712 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by odroid » Thu Jun 04, 2020 6:57 pm

Great!
We will receive a couple of 0.96inch(SSD1306) OLED modules early next week and we will test the codes.

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Thu Jun 04, 2020 7:14 pm

Note:
Odroid N2 has replaced the HTPC I have used in my living room for years.
I don't remember when I last opened my computer.
I use the N2 plugged into the TV for my internet browser, my movies, music and all my needs.
I am 3-4 meters away from the TV, so I am interested in what I can see on the screen at a distance of 3-4 meters. The changes I made on the oled screen are in this direction.
I plan to remove or change the shapes that I cannot see at 3-4 meters.
These users thanked the author istanbulls for the post:
odroid (Thu Jun 04, 2020 7:17 pm)

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Thu Jun 04, 2020 7:20 pm

odroid wrote:
Thu Jun 04, 2020 6:57 pm
Great!
We will receive a couple of 0.96inch(SSD1306) OLED modules early next week and we will test the codes.
For 0.96inch (SSD1306) OLED, you need to change device = sh1106 (serial, rotate = 0) or run it with python3 xxxx.py --display ssd1306 code but you already know it :)
Last edited by istanbulls on Fri Jun 05, 2020 10:53 am, edited 1 time in total.

User avatar
odroid
Site Admin
Posts: 34642
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 824 times
Been thanked: 712 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by odroid » Thu Jun 04, 2020 7:22 pm

Thank you for letting us know.
These users thanked the author odroid for the post:
istanbulls (Thu Jun 04, 2020 7:37 pm)

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Fri Jun 05, 2020 10:51 am

New oled example
CUP Load & Digital clock
I will share the codes tomorrow, I must sleep now.

YouTube

User avatar
odroid
Site Admin
Posts: 34642
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 824 times
Been thanked: 712 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by odroid » Fri Jun 05, 2020 11:28 am

Very neat CPU load visualization. :o
Good night!

rpineau
Posts: 36
Joined: Sun Sep 30, 2018 12:19 pm
languages_spoken: english
ODROIDs: XU4
Has thanked: 1 time
Been thanked: 3 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by rpineau » Fri Jun 05, 2020 11:52 am

This might be of interest : https://github.com/rpineau/libSSD1306
Supports I2c and SPI screens (I forked it and added some code to work on the SSH1106 and also with SPI screens).
The original project is in C++ and the current code uses standard linux ioctl for I2C and SPI. The SPI version uses wiringPi to toggle the D/C pin on SPI screen (switch between data and command mode).
The default is the SSD1306 mode, but if you pass an extra parameter set to true it switches to SSD1106 mode;
See the constructor for I2C :

Code: Select all

    OledI2C(
        const std::string& device,
        uint8_t address,
        bool bIsSSH1106 = false);
Regards,
Rodolphe
These users thanked the author rpineau for the post (total 2):
odroid (Fri Jun 05, 2020 1:55 pm) • istanbulls (Fri Jun 05, 2020 5:46 pm)

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Starting SH1106 OLED-based console at boot?

Post by istanbulls » Fri Jun 05, 2020 9:45 pm

This uses Luma drivers. To get them installed, follow their instructions:
https://github.com/rm-hull/luma.examples
https://luma-oled.readthedocs.io/en/latest/index.html

You need to put the DSEG7Modern-Bold.ttf font I use into the examples/fonts folder:
https://github.com/urish/ng2-simon/blob ... n-Bold.ttf

Digital clock with 7-segment fonts & CPU Load (updated carousel)
Example script for sh1106 1.3inc oled

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2014-18 Richard Hull and contributors
# See LICENSE.rst for details.
# PYTHON_ARGCOMPLETE_OK

"""
Showcase viewport and hotspot functionality.

Loosely based on poster_demo by @bjerrep
https://github.com/bjerrep/ssd1306/blob/master/examples/poster_demo.py

Needs psutil (+ dependencies) installed::
  $ sudo apt-get install python-dev
  $ sudo pip install psutil
"""

import psutil
from luma.core.interface.serial import i2c
from demo_opts import get_device
from luma.core.virtual import viewport, snapshot
from luma.oled.device import ssd1306, ssd1325, ssd1331, sh1106
from hotspot import memory, cpu_load, clock


# rev.1 users set port=0
# substitute spi(device=0, port=0) below if using that interface
serial = i2c(port=1, address=0x3C)

# substitute ssd1331(...) or sh1106(...) below if using that device
device = sh1106(serial, rotate=0)

def position(max):
    forwards = range(0, max)
    backwards = range(max, 0, -1)
    while True:
        for x in forwards:
            yield x
        for x in backwards:
            yield x


def pause_every(interval, generator):
    try:
        while True:
            x = next(generator)
            if x % interval == 0:
                for _ in range(66):
                    yield x
            else:
                yield x
    except StopIteration:
        pass


def intersect(a, b):
    return list(set(a) & set(b))


def first(iterable, default=None):
    if iterable:
        for item in iterable:
            return item
    return default


def main():
    if device.rotate in (1, 1):
        # Horizontal
        widget_width = device.width // 1
        widget_height = device.height
    else:
        # Vertical
        widget_width = device.width
        widget_height = device.height // 1

    # Either function or subclass
    #  cpuload = hotspot(widget_width, widget_height, cpu_load.render)
    #  cpuload = cpu_load.CPU_Load(widget_width, widget_height, interval=1.0)
    #  utime = snapshot(widget_width, widget_height, uptime.render, interval=1.0)
    #  mem = snapshot(widget_width, widget_height, memory.render, interval=2.0)
    #  dsk = snapshot(widget_width, widget_height, disk.render, interval=2.0)
    cpuload = snapshot(widget_width, widget_height, cpu_load.render, interval=0.5)
    clk = snapshot(widget_width, widget_height, clock.render, interval=1.0)

    #  network_ifs = psutil.net_if_stats().keys()
    #  wlan = first(intersect(network_ifs, ["wlan0", "wl0"]), "wlan0")
    #  eth = first(intersect(network_ifs, ["eth0", "en0"]), "eth0")
    #  lo = first(intersect(network_ifs, ["lo", "lo0"]), "lo")

    #  net_wlan = snapshot(widget_width, widget_height, network.stats(wlan), interval=2.0)
    #  net_eth = snapshot(widget_width, widget_height, network.stats(eth), interval=2.0)
    #  net_lo = snapshot(widget_width, widget_height, network.stats(lo), interval=2.0)

    widgets = [cpuload, clk]


    if device.rotate in (1, 1):
        virtual = viewport(device, width=widget_width * len(widgets), height=widget_height)
        for i, widget in enumerate(widgets):
            virtual.add_hotspot(widget, (i * widget_width, 0))

        for x in pause_every(widget_width, position(widget_width * (len(widgets) - 1))):
            virtual.set_position((x, 0))

    else:
        virtual = viewport(device, width=widget_width, height=widget_height * len(widgets))
        for i, widget in enumerate(widgets):
            virtual.add_hotspot(widget, (0, i * widget_height))

        for y in pause_every(widget_height, position(widget_height * (len(widgets) - 1))):
            virtual.set_position((0, y))


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        pass
You should replace the contents of clock.py in examples/hotspot/ with this code.

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2014-18 Richard Hull and contributors
# See LICENSE.rst for details.

import math
import time
import datetime

from hotspot.common import title_text, tiny_font, ImageFont


def digital(draw, width, height):
    
    now = datetime.datetime.now()
    today_date = now.strftime("%d %b %y")
    today_time = now.strftime("%H:%M")

    
    font = ImageFont.truetype('./home/odroid/luma.examples/examples/fonts/DSEG7Modern-Bold.ttf', 36)
    draw.text((-2, 27), today_time, font=font, fill=1)
    font = ImageFont.truetype('./home/odroid/luma.examples/examples/fonts/DSEG7Modern-Bold.ttf', 20)
    draw.text((4, 0), today_date, font=font, fill=1)
                


def render(draw, width, height):
    clock = digital if height >= 64 else analog
    clock(draw, width, height)
YouTube
Attachments
WhatsApp Image 2020-06-05 at 15.42.20.jpeg
WhatsApp Image 2020-06-05 at 15.42.20.jpeg (14.03 KiB) Viewed 1288 times
WhatsApp Image 2020-06-05 at 15.41.48.jpeg
WhatsApp Image 2020-06-05 at 15.41.48.jpeg (15.03 KiB) Viewed 1288 times
WhatsApp Image 2020-06-05 at 15.41.18.jpeg
WhatsApp Image 2020-06-05 at 15.41.18.jpeg (15.8 KiB) Viewed 1288 times
Last edited by istanbulls on Tue Jun 09, 2020 5:44 pm, edited 1 time in total.

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Oled Screen Examples For N2

Post by istanbulls » Mon Jun 08, 2020 9:31 pm

!!This is a rookie project!!
I made the codes by combining many examples.
Python and software do not know at all. I used the trial and error method
So there may be bad codes and excess codes, but it will work.

I am making projects according to the sh1106 oled screen I am about to use, but it can be used by changing a few codes for other ssd1306 screens.

Sorry for my bad English, also thanks to google translator endlessly ... :)




This uses Luma drivers. To get them installed, follow their instructions:
https://github.com/rm-hull/luma.examples
https://luma-oled.readthedocs.io/en/latest/index.html

You need to put the DSEG7Modern-Bold.ttf font I use into the examples/fonts folder:
https://github.com/urish/ng2-simon/blob ... n-Bold.ttf


Histogram Temperature Example:

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2019 Richard Hull and contributors
# See LICENSE.rst for details.
# PYTHON_ARGCOMPLETE_OK

import os
import multiprocessing
import time
import psutil
from datetime import datetime

from demo_opts import get_device
from luma.core.render import canvas
from luma.oled.device import sh1106
from luma.core.interface.serial import i2c
from PIL import ImageFont

serial = i2c(port=1, address=0x3C)
device = sh1106(serial, rotate=0)

# Longer refresh rate the more history is shown
# If you set this to e.x. 30 sec you will get about 25 minutes of history on the graph
REFRESH_INTERVAL = 1

# FlipFlop blink variable
blnk = 1


def init_histogram():
    # HistogramSettings
    histogramResolution = 100
    histogramTime = []
    histogramData = []
    x = 106
    # Filling up the arrays for the histogram
    for pix in range(0, histogramResolution):
        x -= 2
        if x > 2:
            histogramTime.append(x)

    for timeLen in range(1, len(histogramTime)):
        histogramData.append(64)

    return histogramData, histogramTime


def main(device, histogramData, histogramTime):
    # Importing some global vars
    global blnk

    # Vars:
    # Getting system uptime
#     sysUptime = datetime.now() - datetime.fromtimestamp(psutil.boot_time())


    # Temp bar
    maxBarHeight = 60
    minBarHeight = 7
    try:
        with open("/sys/class/thermal/thermal_zone0/temp", "r") as temp:
            tmpCel = int(temp.read()[:2])
            tmpPercent = (tmpCel / 55) * 100

            height = (((100 - tmpPercent) * (maxBarHeight - minBarHeight)) / 100) + minBarHeight
    except:
        tmpCel = 0
        height = 0


    # Starting the canvas for the screen
    with canvas(device, dither=True) as draw:
        # Print
        # Drawing the outlines and legends:
        # Main Outline



        # CPU Temperature
        if height > minBarHeight:
            draw.rectangle((1, height, 128, maxBarHeight), fill="white")
            draw.rectangle((1, height, 128, height + 49), fill="black")
            font = ImageFont.truetype('./home/odroid/luma.examples/examples/fonts/DSEG7Modern-Bold.ttf', 46)
            draw.text((19, 13), str(tmpCel), font=font, fill="white")
            font = ImageFont.truetype('./home/odroid/luma.examples/examples/fonts/DSEG7Modern-Bold.ttf', 29)
            draw.text((99, 0), 'o', font=font, fill="white")
            
        else:
            draw.rectangle((1, minBarHeight, 128, maxBarHeight), outline="black")
            if blnk == 1:
                draw.rectangle((1, minBarHeight, 128, maxBarHeight), fill="white")
                draw.rectangle((1, minBarHeight, 128, minBarHeight + 60), fill="black")
                
                font = ImageFont.truetype('./home/odroid/luma.examples/examples/fonts/DSEG7Modern-Bold.ttf', 46)
                draw.text((19, 13), str(tmpCel), font=font, fill="white")
                font = ImageFont.truetype('./home/odroid/luma.examples/examples/fonts/DSEG7Modern-Bold.ttf', 29)
                draw.text((99, 0), 'o', font=font, fill="white")
                blnk = 0
            else:
                draw.rectangle((1, minBarHeight, 128, minBarHeight + 60), fill="white", outline="black")
                
                font = ImageFont.truetype('./home/odroid/luma.examples/examples/fonts/DSEG7Modern-Bold.ttf', 46)
                draw.text((19, 13), str(tmpCel), font=font, fill="black")
                font = ImageFont.truetype('./home/odroid/luma.examples/examples/fonts/DSEG7Modern-Bold.ttf', 26)
                draw.text((99, 0), 'o', font=font, fill="black")
                blnk = 1


if __name__ == "__main__":
    histogramData, histogramTime = init_histogram()
    while True:
        main(device, histogramData, histogramTime)
        time.sleep(REFRESH_INTERVAL)
YouTube
Attachments
WhatsApp Image 2020-06-08 at 15.15.02.jpeg
WhatsApp Image 2020-06-08 at 15.15.02.jpeg (164.21 KiB) Viewed 1143 times
These users thanked the author istanbulls for the post (total 3):
rooted (Mon Jun 08, 2020 10:18 pm) • jgmdev (Tue Jun 09, 2020 12:48 am) • Chris Oi (Tue Jun 09, 2020 2:20 am)

User avatar
rooted
Posts: 7752
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 721 times
Been thanked: 209 times
Contact:

Re: Oled Screen Examples For N2

Post by rooted » Mon Jun 08, 2020 10:18 pm

It's not a rookie project, learning from and adapting examples is what they are for.

Nice job.
These users thanked the author rooted for the post:
istanbulls (Mon Jun 08, 2020 10:35 pm)

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Oled Screen Examples For N2

Post by istanbulls » Mon Jun 08, 2020 10:26 pm

@rooted
I accept this as a nice compliment :) Thanks.
And I'm a curious real rookie :D

Chris Oi
Posts: 55
Joined: Tue Aug 04, 2015 5:56 pm
languages_spoken: German, English
ODROIDs: Odroid XU4
Odroid N2
Has thanked: 16 times
Been thanked: 15 times
Contact:

Re: Oled Screen Examples For N2

Post by Chris Oi » Tue Jun 09, 2020 2:23 am

May I ask if this also works on coreELEC?
I would like to use a display for my project aswell :D

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Oled Screen Examples For N2

Post by istanbulls » Tue Jun 09, 2020 2:42 am

Chris Oi wrote:
Tue Jun 09, 2020 2:23 am
May I ask if this also works on coreELEC?
I would like to use a display for my project aswell :D
It doesn't work with coreelec, I don't know how to add-on.
These users thanked the author istanbulls for the post:
Chris Oi (Tue Jun 09, 2020 2:59 am)

User avatar
rooted
Posts: 7752
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 721 times
Been thanked: 209 times
Contact:

Re: Oled Screen Examples For N2

Post by rooted » Tue Jun 09, 2020 8:31 am

Chris Oi wrote:May I ask if this also works on coreELEC?
I would like to use a display for my project aswell :D
You can see my thread for something that does work in CoreELEC.

viewtopic.php?p=290917#p290917
These users thanked the author rooted for the post:
Chris Oi (Tue Jun 09, 2020 6:39 pm)

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Oled Screen Examples For N2

Post by istanbulls » Tue Jun 09, 2020 5:39 pm

rooted wrote:
Tue Jun 09, 2020 8:31 am
Chris Oi wrote:May I ask if this also works on coreELEC?
I would like to use a display for my project aswell :D
You can see my thread for something that does work in CoreELEC.

viewtopic.php?p=290917#p290917
I saw and used it in the Coreelec forum, I didn't know it was your project. :)
It works great, you inspired me. You brought me a new hobby, thank you :)

User avatar
rooted
Posts: 7752
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 721 times
Been thanked: 209 times
Contact:

Re: Oled Screen Examples For N2

Post by rooted » Wed Jun 10, 2020 5:55 am

istanbulls wrote:
rooted wrote:
Tue Jun 09, 2020 8:31 am
Chris Oi wrote:May I ask if this also works on coreELEC?
I would like to use a display for my project aswell :D
You can see my thread for something that does work in CoreELEC.

viewtopic.php?p=290917#p290917
I saw and used it in the Coreelec forum, I didn't know it was your project. :)
It works great, you inspired me. You brought me a new hobby, thank you :)
It's not my project, I was just linking it instead of typing it out again.

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Oled Screen Examples For N2

Post by istanbulls » Thu Jun 11, 2020 6:58 pm

This uses Luma drivers. To get them installed, follow their instructions:
https://github.com/rm-hull/luma.examples
https://luma-oled.readthedocs.io/en/latest/index.html

You need to put the DSEG7Modern-Bold.ttf and digital-7-mono.ttf font I use into the examples/fonts folder:
https://github.com/urish/ng2-simon/blob ... n-Bold.ttf
https://github.com/ndt-project/ndt/blob ... 7-mono.ttf

7-segment digital fonts, Clock, CPU, Temp, Ram alternating display. Example script for sh1106 1.3inc oled

Code: Select all

import os
import psutil
import time
import platform
from luma.core.interface.serial import i2c
from luma.oled.device import sh1106
from luma.core.render import canvas
from PIL import ImageFont
from datetime import datetime

serial = i2c(port=1, address=0x3C)
device = sh1106(serial, rotate=0)

global width
width=128
global height
height=64

global line1
line1=9
global col1
col1=-1
global line2
line2=9
global col2
col2=16
global col3
col3=1
global line3
line3=1
global line5
line5=1
global line6
line6=1


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)


font11 = make_font("./home/odroid/luma.examples/examples/fonts/digital-7.mono.ttf", 58)
font10 = make_font("./home/odroid/luma.examples/examples/fonts/DSEG7Modern-Bold.ttf", 39)
 
def bytes2human(n):
    """
    >>> bytes2human(10000)
    '9K'
    >>> bytes2human(100001221)
    '95M'
    """
    symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
    prefix = {}
    for i, s in enumerate(symbols):
        prefix[s] = 1 << (i + 1) * 10
    for s in reversed(symbols):
        if n >= prefix[s]:
            value = int(float(n) / prefix[s])
            return '%s%s' % (value, s)
    return "%sB" % n
  
def cpu_usage():
    # load average, uptime
    av1, av2, av3 = os.getloadavg()
    return "%s" \
        % (av1)
 
def cpu_temperature():
    # load average, uptime
    tempC = ((int(open('/sys/devices/virtual/thermal/thermal_zone0/temp').read()[:2])))
    return "%s'C" \
        % (str(tempC))

 
def mem_usage():
    usage = psutil.virtual_memory()
    return "%.0f %%" \
        % ((usage.percent))
  

def stats():
    global looper
    with canvas(device) as draw:
        if looper==1:
            draw.text((col2, line2), cpu_temperature(),  font=font11, fill=255)
            looper=2
        elif looper==2:
            draw.text((col2, line1), cpu_usage(),  font=font11, fill=255)
            looper=3
        elif looper==3:
            draw.text((col2, line2), mem_usage(),  font=font11, fill=255)
            looper=4       
        else:
            uptime = datetime.now() - datetime.fromtimestamp(psutil.boot_time())
            draw.text((col1, line1),str(datetime.now().strftime('%H:%M')), font=font11, fill=255)
            looper=1
        #oled.drawImage(image)
    
def main():
    global looper
    looper = 0
    while True:
        stats()
        if looper==0:
            time.sleep(10)
        else:
            time.sleep(5)
  
  
if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        pass


https://youtu.be/3zk-ccw2XzM
Attachments
WhatsApp Image 2020-06-11 at 12.46.48.jpeg
WhatsApp Image 2020-06-11 at 12.46.48.jpeg (147.88 KiB) Viewed 935 times
These users thanked the author istanbulls for the post:
odroid (Thu Jun 11, 2020 7:23 pm)

User avatar
mad_ady
Posts: 8155
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, C4, N1, N2, H2, Go, Go Advance
Location: Bucharest, Romania
Has thanked: 568 times
Been thanked: 404 times
Contact:

Re: Oled Screen Examples For N2

Post by mad_ady » Thu Jun 11, 2020 7:39 pm

Offtopic, but @istanbulls have you removed the cutout from the case to put the wires through? I too have a bunch of wires going out from the N2 to various sensors, and I find it difficult to slide the case in/out with the jumper cables attached (somethimes I need to access the emmc). Perhaps for the next case revision HK could consider uniting the GPIO cutout with the end of the case, so that one can slide the top case in/out without removing the GPIO pins. It would affect structural integrity only when the cutout for GPIO pins has been removed.
These users thanked the author mad_ady for the post:
istanbulls (Thu Jun 11, 2020 7:44 pm)

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Oled Screen Examples For N2

Post by istanbulls » Thu Jun 11, 2020 8:01 pm

@mad_ady

Because of this problem, I used it for 1 year without a case.
Now I installed eMMC Android and now I am trying not to move eMMC :)
You made a very accurate reproof.

Oled is not fixed for now because I am still playing with it. I'm thinking of fixing it somewhere when I'm done, but I have no idea yet, I will find a creative solution.
Attachments
WhatsApp Image 2020-06-11 at 13.59.25.jpeg
WhatsApp Image 2020-06-11 at 13.59.25.jpeg (225.45 KiB) Viewed 869 times

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Oled Screen Examples For N2

Post by istanbulls » Thu Jun 11, 2020 8:20 pm

As I described in the picture, 2-3 mm excess can be cut.
Attachments
WhatsApp Image 2020-06-11 at 14.17.41.jpeg
WhatsApp Image 2020-06-11 at 14.17.41.jpeg (99.9 KiB) Viewed 867 times

User avatar
rooted
Posts: 7752
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 721 times
Been thanked: 209 times
Contact:

Re: Oled Screen Examples For N2

Post by rooted » Thu Jun 11, 2020 9:05 pm

mad_ady wrote:Offtopic, but @istanbulls have you removed the cutout from the case to put the wires through? I too have a bunch of wires going out from the N2 to various sensors, and I find it difficult to slide the case in/out with the jumper cables attached (somethimes I need to access the emmc). Perhaps for the next case revision HK could consider uniting the GPIO cutout with the end of the case, so that one can slide the top case in/out without removing the GPIO pins. It would affect structural integrity only when the cutout for GPIO pins has been removed.
Don't you have a 3D printer?

User avatar
mad_ady
Posts: 8155
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, C4, N1, N2, H2, Go, Go Advance
Location: Bucharest, Romania
Has thanked: 568 times
Been thanked: 404 times
Contact:

Re: Oled Screen Examples For N2

Post by mad_ady » Thu Jun 11, 2020 9:58 pm

No, I have too many kids :)) No room for a 3d printer
These users thanked the author mad_ady for the post:
istanbulls (Thu Jun 11, 2020 10:06 pm)

User avatar
rooted
Posts: 7752
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 721 times
Been thanked: 209 times
Contact:

Re: Oled Screen Examples For N2

Post by rooted » Fri Jun 12, 2020 5:02 am

mad_ady wrote:No, I have too many kids :)) No room for a 3d printer
You can never have too many Image
These users thanked the author rooted for the post (total 2):
istanbulls (Fri Jun 12, 2020 6:02 am) • mad_ady (Fri Jun 12, 2020 2:53 pm)

neal
Posts: 225
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: Korean, English
Has thanked: 5 times
Been thanked: 16 times
Contact:

Re: Oled Screen Examples For N2

Post by neal » Sat Jun 13, 2020 12:49 pm

Thank you for sharing your code @istanbulls.
I just put @istanbulls's code into my C4 and have some changed it to work ssd1306 oled.
In my case, DSEG7Modern-Bold.ttf didn't work out. so I downloaded v0.46 DSEG fonts via this command and applied and worked.

Code: Select all

wget https://github.com/keshikan/DSEG/releases/download/v0.46/fonts-DSEG_v046.zip
SSD1306_luma_C4.jpg
SSD1306_luma_C4.jpg (167.26 KiB) Viewed 758 times

Code: Select all

root@odroid:~/luma.examples/examples# uname -a
Linux odroid 4.9.218-25 #1 SMP PREEMPT Mon Jun 8 13:54:52 UTC 2020 aarch64 aarch64 aarch64 GNU/Linux
root@odroid:~/luma.examples/examples# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04 LTS"
root@odroid:~#
root@odroid:~# cat -n /etc/rc.local
     1  #!/bin/bash
     2
     3  if [ -f /aafirstboot ]; then /aafirstboot start ; fi
     4
     5
     6  if [ -f /aafirstboot ]; then /aafirstboot start ; fi
     7
     8  # exit 0
     9
    10  if [ -f /root/luma.examples/examples/alp-clk.py ]; then /usr/bin/python3 /root/luma.examples/examples/alp-clk.py& start ; fi
    11
    12  exit 0
root@odroid:~#
root@odroid:~/luma.examples/examples# cat -n alp-clk.py
     1  #!/usr/bin/env python
     2  # -*- coding: utf-8 -*-
     3  # Copyright (c) 2014-18 Richard Hull and contributors
     4  # See LICENSE.rst for details.
     5  # PYTHON_ARGCOMPLETE_OK
     6
     7  """
     8  An analog clockface with date & time.
     9
    10  """
    11
    12
    13
    14  from luma.core.interface.serial import i2c
    15  from luma.core.render import canvas
    16  from luma.oled.device import ssd1306, ssd1325, ssd1331, sh1106
    17  from time import sleep
    18  from PIL import ImageFont, ImageDraw, Image
    19  import time
    20  import datetime
    21
    22  serial = i2c(port=0, address=0x3C)
    23  # device = sh1106(serial, rotate=0)
    24  device = ssd1306(serial, rotate=2)
    25
    26  def main():
    27      today_last_time = "Unknown"
    28      while True:
    29          now = datetime.datetime.now()
    30          today_date = now.strftime("%d %b %y")
    31          today_time = now.strftime("%H:%M")
    32          if today_time != today_last_time:
    33              today_last_time = today_time
    34              with canvas(device) as draw:
    35                    font = ImageFont.truetype('/root/luma.examples/examples/fonts/fonts-DSEG_v046/DSEG7-Modern/DSEG7Modern-Bold.ttf',36)
    36                    # font = ImageFont.truetype('/root/luma.examples/examples/fonts/FreePixel.ttf',36)
    37                    draw.text((0, 27), today_time, font=font, fill=1)
    38                    font = ImageFont.truetype('/root/luma.examples/examples/fonts/fonts-DSEG_v046/DSEG7-Modern/DSEG7Modern-Bold.ttf',20)
    39                    # font = ImageFont.truetype('/root/luma.examples/examples/fonts/FreePixel.ttf',20)
    40                    draw.text((0, 0), today_date, font=font, fill=1)
    41          time.sleep(0.1)
    42
    43
    44  if __name__ == "__main__":
    45      try:
    46          main()
    47      except KeyboardInterrupt:
    48          pass
root@odroid:~/luma.examples/examples#
These users thanked the author neal for the post (total 4):
tobetter (Sat Jun 13, 2020 1:07 pm) • istanbulls (Sat Jun 13, 2020 5:36 pm) • joerg (Sat Jun 13, 2020 7:32 pm) • odroid (Mon Jun 15, 2020 10:46 am)

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Oled Screen Examples For N2

Post by istanbulls » Sat Jun 13, 2020 5:52 pm

@neal
thanks for sharing, i would love to try it when my C4 arrives.

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Oled Screen Examples For N2

Post by istanbulls » Mon Jun 15, 2020 12:07 am

OS: Ubuntu 20.04 - 5.7.0
Oled does not work after the last update.

Code: Select all

             
odroid@ubuntu:~$ i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
odroid@ubuntu:~$ 

Code: Select all

Traceback (most recent call last):
  File "sys_histogram.py", line 20, in <module>
    device = sh1106(serial, rotate=0)
  File "/usr/local/lib/python3.8/dist-packages/luma/oled/device/__init__.py", line 71, in __init__
    self.command(
  File "/usr/local/lib/python3.8/dist-packages/luma/core/device.py", line 39, in command
    self._serial_interface.command(*cmd)
  File "/usr/local/lib/python3.8/dist-packages/luma/core/interface/serial.py", line 84, in command
    self._bus.write_i2c_block_data(self._addr, self._cmd_mode,
  File "/usr/local/lib/python3.8/dist-packages/smbus2/smbus2.py", line 622, in write_i2c_block_data
    ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 6] No such device or address

User avatar
istanbulls
Posts: 238
Joined: Tue May 14, 2019 10:18 pm
languages_spoken: Turkish
ODROIDs: ODROID N2
Has thanked: 119 times
Been thanked: 23 times
Contact:

Re: Oled Screen Examples For N2

Post by istanbulls » Mon Jun 15, 2020 12:37 am

istanbulls wrote:
Mon Jun 15, 2020 12:07 am
OS: Ubuntu 20.04 - 5.7.0
Oled does not work after the last update.

Code: Select all

             
odroid@ubuntu:~$ i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
odroid@ubuntu:~$ 

Code: Select all

Traceback (most recent call last):
  File "sys_histogram.py", line 20, in <module>
    device = sh1106(serial, rotate=0)
  File "/usr/local/lib/python3.8/dist-packages/luma/oled/device/__init__.py", line 71, in __init__
    self.command(
  File "/usr/local/lib/python3.8/dist-packages/luma/core/device.py", line 39, in command
    self._serial_interface.command(*cmd)
  File "/usr/local/lib/python3.8/dist-packages/luma/core/interface/serial.py", line 84, in command
    self._bus.write_i2c_block_data(self._addr, self._cmd_mode,
  File "/usr/local/lib/python3.8/dist-packages/smbus2/smbus2.py", line 622, in write_i2c_block_data
    ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 6] No such device or address
I solved the problem, the Port changed after the update.
It used to be: "serial = i2c (port = 1, address = 0x3C)"

New Port = 0
"serial = i2c (port = 0, address = 0x3C)"
These users thanked the author istanbulls for the post (total 2):
tobetter (Mon Jun 15, 2020 1:31 am) • odroid (Mon Jun 15, 2020 10:46 am)

Post Reply

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 0 guests