Page 4 of 4

Re: [Tutorial] How to get your NanoHatOLED to work

Posted: Sun Mar 29, 2020 7:39 pm
by MichaIng
The expects rc.local to be present and enabled. Please try this before running

Code: Select all

>> /etc/rc.local
grep 'exit 0' /etc/rc.local ||  sed -i -e '$aexit 0' /etc/rc.local
chmod +x /etc/rc.local
Oh, and the script adds the OLED start command not very failsafe...:

Code: Select all

2020-03-29 19:31:28 root@micha:/tmp# cat test

exit 0

2020-03-29 19:31:31 root@micha:/tmp# sed -i -e '$i \/usr/local/bin/oled-start\n' test
2020-03-29 19:31:40 root@micha:/tmp# cat test

exit 0

If there is a newline after the exit 0, it is never executed...

So please verify that /usr/local/bin/oled-start is present before exit 0:

Code: Select all

cat /etc/rc.local
Also since the source code has not been updated the last 3 years the question is if it's still compatible with newest Python, i.e. Python3?

Re: [Tutorial] How to get your NanoHatOLED to work

Posted: Sun Mar 29, 2020 9:29 pm
by buesche
why not use a systemd service?

Code: Select all

Description=NanoHAT OLED


and oled-start:

Code: Select all

cd /root/NanoHatOLED
The OLED screens does work with python3 (at least on my nanopi neo air with dietpi on it).

Re: [Tutorial] How to get your NanoHatOLED to work

Posted: Mon Mar 30, 2020 12:43 pm
by FrogPI
Greetings !
Yet another bash at getting this OLED to work. Things "seem" to be moving forward, hopefully.
Being new to Linux (30 years of Windoze and 10 of Apples) code seems quite daunting at first, but thanks to the Interweb, it looks as if I am getting somewhere.
I couldn't get my head around MichaIng's post and couldn't figure it out, but then from "buesche" post I chased info on the systemd service thingy, and found some information on the Raspberry website I quote :
"NOTE: on Jessie, Stretch and Buster (which use systemd), rc.local has drawbacks: not all programs will run reliably, because not all services may be available when rc.local runs.
See systemd for another way to have a command or program run when Raspberry Pi boots."

Obviously this is a learning curve for me, so this is what I did, please correct if I am doing things wrong (I'm all ears from the pros) :

From a fresh eMMC flash (DietPi_NanoPiNEO2Black-ARMv8-Buster.img)
copy NanoHatOLED.tar.gz to /home folder via cp (from another machine onto the eMMC)
ssh into dietpi
run dietpi-config
install 130 + 16 + 17

root@DietPi:~# python --version
Python 2.7.16

root@DietPi:~# cd /etc
root@DietPi:~# ls
# an rc.local file is present

root@DietPi:~# cd /home
root@DietPi:~# cd NanoHatOLED
root@DietPi:~# run ./

root@DietPi:~# python --version
Python 2.7.16
#still same Python version 2.7.16 and has not been updated via

root@DietPi:~# sudo nano oled.service

# copy buesche's code to oled.service

# [Unit]
# Description=NanoHAT OLED



root@DietPi:~# sudo cp oled.service /etc/systemd/system/oled.service
root@DietPi:~# sudo reboot

# after reboot

root@DietPi:~# sudo systemctl start oled.service
root@DietPi:~# sudo systemctl status oled.service

● oled.service - NanoHAT OLED
Loaded: loaded (/etc/systemd/system/oled.service; disabled; vendor preset: en
Active: active (exited) since Mon 2020-03-30 11:11:34 BST; 15s ago
Process: 982 ExecStart=/usr/local/bin/oled-start (code=exited, status=0/SUCCES
Main PID: 982 (code=exited, status=0/SUCCESS)
Tasks: 5 (limit: 1023)
Memory: 17.9M
CGroup: /system.slice/oled.service
├─985 ./NanoHatOLED
├─988 sh -c cd /home/NanoHatOLED/BakeBit/Software/Python && python3 b 2>&1 | tee /tmp/nanoled-python.log
├─991 python3
└─992 tee /tmp/nanoled-python.log

Mar 30 11:11:34 DietPi systemd[1]: Starting NanoHAT OLED...
Mar 30 11:11:34 DietPi systemd[1]: Started NanoHAT OLED.

# The service seems to be starting without any problems, and HTOP shows a NanoHatOLED service runnning, but still no OLED , Grrrr !
Screen Shot 2020-03-30 at 12.33.55.png
Any ideas would be greatly appreciated, in NOOB language if possible ;.)

Re: [Tutorial] How to get your NanoHatOLED to work

Posted: Mon Mar 30, 2020 3:58 pm
by MichaIng
Yeah a systemd unit is the obvious solution on systemd-driven systems indeed. It is not what the original does, so just take care to not double things.

rc.local on modern Debian/DietPi is btw as well started via systemd unit ;): systemctl status rc-local
But it requires the rc.local file to be executable, which is not the case by default.

Okay, so we have the script started now but it does not lead to any OLED output :(.
Does i2cdetect btw show expected output, so that I2C is really enabled?

Re: [Tutorial] How to get your NanoHatOLED to work

Posted: Mon Mar 30, 2020 5:55 pm
by FrogPI
Hi MichaIng

thanks for your prompt reply.
Sorry for my ignorance, but how can I check that systemd & rc.local are not being doubled up, as you say ?

Here is the output of :
Screen Shot 2020-03-30 at 17.36.06.png
red stuff is obviously not good news :.(

An i2c detect shows :
Screen Shot 2020-03-30 at 17.48.59.png
Screen Shot 2020-03-30 at 17.48.59.png (13.41 KiB) Viewed 2201 times
I'll be very honest, I am a tad out of my league here, and any help is greatly appreciated, cheers.

Re: [Tutorial] How to get your NanoHatOLED to work

Posted: Mon Mar 30, 2020 5:56 pm
by FrogPI
PS : No OLED output whatsoever, not a blink !

Re: [Tutorial] How to get your NanoHatOLED to work

Posted: Tue Apr 07, 2020 7:32 pm
by Aldoszx
It is working for me, but slightly modified in order to put the startup script on /var/lib/dietpi/postboot.d/

Install instructions:

1. Enable i2c (add to armbianEnv.txt): overlays=i2c0 usbhost1 usbhost2

2. Make sure the following components have been installed using the DietPi Software configuration tool

<Software Additional> => 16 Build Essentials
<Software Additional> => 17 Git

3. Download attached NanoHatOLED.tar.gz and copy archive to installation folder (e.g. /home)

cd /home
tar -pxvzf NanoHatOLED.tar.gz
cd NanoHatOLED

That is all !
Now it should work.

Later edit:
the script installs Python 3.7, python-pip, etc

Later later edit:
I forgot to mention, I am using maarten's package for Python 3 !
Thanks maarten !
I've also modified the installer in order to use systemd, based on oled.script proposed by buesche.
I am using it on Armbian and it is working fine !

Re: [Tutorial] How to get your NanoHatOLED to work

Posted: Thu Apr 16, 2020 2:30 am
by maarten
@ dornt, FrogPI

try following and re-install NanoHatOLED:

MichaIng commented on 25 Feb
Many thanks for testing. Could you please try to edit /boot/armbianEnv.txt and add:
i2c0 to the overlays line, so it should look like this:

overlays=usbhost1 usbhost2 i2c0
There is also an i2c1 overlay available, not sure which one uses which pins.
And if you don't use Docker, add the following as new line as well, which should lead to minor performance enhancements:


Re: [Tutorial] How to get your NanoHatOLED to work

Posted: Sun May 10, 2020 4:34 am
by Fatguy5150
Hi everybody. Thanks for the great posts. I got a new NanoPi Neo2 Black and have been struggling to make the OLED work. Aldoszx your instructions/script work perfectly and I get to run dietpi like I want!

I was also able to get this to work using Ubuntu; showing the pi-hole stats and updating the shutdown screen to the pi-hole disable for 15mins option, but can’t seem to get them to work here on dietpi. ... e_machine/

I’ve mostly been trying to modify the file but to no avail. Any ideas on how to access the pi-hole stats/disable options?

Hardware: NanoPi Neo2 Black
OS: DietPi_NanoPiNEOBlack-ARMv8-Buster (beta)

Thanks again for the awesome posts, it's really cool to get this thing working.