[Tutorial] How to get your NanoHatOLED to work

I tried to install this NanoHatOLED on my NanoPi Neo Air (DietPi v6.25.3) but I’m stuck somewhere.
I used python3.5 instead of python2.7, had to change some lines in bakebit but the Service ./NanoHatOLED is running so I think the program itself works.

But now my OLED screen stays black and I’ve got these lines in my dmesg:

i2c i2c-0: mv64xxx: I2C bus locked, block: 1, time_left: 0

i2cdetect works but does not find anything, it just fills my dmesg log with the message above… my friend google can’t help or I’m just not familiar enough with this i2c stuff…

Does anybody know how to solve this? Or could this be caused by python3.5?

thank you!

edit: this error seems to be on another level. not even the pre built friendlyarm-oled image works…

What does your output of

sudo i2cdetect -y 0

look like?

This is what mine looks like (NanoPi NEO2)
i2c.png

i2cdetect -y 0

and

i2cdetect -y 1

only show “–” and scanning takes ages.

i2cdetect -y 2

is fast but empty as well.

i2cdetect -y 3

shows this:

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

there is this camera module attached in the neo air device tree. I can’t find it in sun8i-h3-nanopi-neo.dts

sun8i-h3-nanopi-neo-air.dts

	                i2c@01c2b400 {
                        compatible = "allwinner,sun6i-a31-i2c";
                        reg = <0x1c2b400 0x400>;
                        interrupts = <0x0 0x8 0x4>;
                        clocks = <0x4 0x3d>;
                        resets = <0x4 0x30>;
                        pinctrl-names = "default";
                        pinctrl-0 = <0x2e>;
                        status = "okay";
                        #address-cells = <0x1>;
                        #size-cells = <0x0>;
                        linux,phandle = <0x7c>;
                        phandle = <0x7c>;

                        camera@3c {
                                compatible = "ovti,ov5640";
                                reg = <0x3c>;
                                clocks = <0x2f>;
                                clock-names = "xclk";
                                reset-gpios = <0x14 0x4 0xe 0x1>;
                                powerdown-gpios = <0x14 0x4 0xf 0x0>;
                                AVDD-supply = <0x30>;
                                DOVDD-supply = <0x31>;
                                DVDD-supply = <0x32>;
                                linux,phandle = <0x7d>;
                                phandle = <0x7d>;

                                port {

                                        endpoint {
                                                remote-endpoint = <0x33>;
                                                bus-width = <0x8>;
                                                data-shift = <0x2>;
                                                hsync-active = <0x1>;
                                                vsync-active = <0x0>;
                                                data-active = <0x1>;
                                                pclk-sample = <0x1>;
                                                linux,phandle = <0x35>;
                                                phandle = <0x35>;
                                        };
                                };

The errors appear with and without the NanoHat connected.
Also when pressing the buttons, only k1 creates a log entry in /tmp/nanohat-oled.log
I think there is something wrong with my hardware… first attempt at I2C, already looks like a failing one :thinking:

edit: deleted everything related to the camera from my device tree but all i got was another error in my messages… at least it booted…

edit2, if I add “bias-pull-up;” to all i2c devices (there is such an entry at i2c2) the scans run fast but every address is empty and my oled stays black… hmm but it did something, at least my buttons are all working now…

I need to get better in soldering… everything solved, hardware related not software.

Glad you managed to work out all the kinks :slight_smile:

On a side note I’m kinda flattered my little script modification is getting popular, I even spotted it out in the wild (only version 1 of the script though … they really should update)
http://www.wlanpi.com/

Your script is amazing to start with.
I already modified it to change between hotspot and wifi client by pressing some buttons.
After modifying some lines in main.c and some .py files NanoHatOLED now works with python 3.5 too.

Edit: why did you put so much delay in your script → time.sleep(x) ?

also some ideas:

Return to Home-Screen when Screen Off and K1 pressed (prevent accidental shutdown if page_index==4

if page_index==0 and pageSleepCountdown==0:

Prevent b’ and \n on the lines CPU: MEM: Disk:

str(CPU, encoding='utf-8', errors='ignore')

Get IP address in one line

cmd = "ip a | grep wlan0 | grep inet | awk '{print $2}' | rev | cut -c4- | rev"
IPAddress = subprocess.check_output(cmd, shell = True )

The command “sudo pip install --upgrade ssd1306” no longer works. If you have this issue, substitute the following:

sudo pip install --upgrade luma.oled

Then run the other commands as listed in the tutorial.

Hi All,

Have made a lean and clean install for NanoHatOLED (Python 3). Have made minor changes to the script adapted by Phillski (screen time-out to 30s, changed font size of details screen to make optimal use of max screen size, and changes to make script Python3 compatible).

Furthermore I have modified the install script to install all needed packages (dependencies) and Python modules.

installation instructions:

Step 1: Make sure the following components have been installed using the DietPi Software configuration tool
=> 130 Python Pip
=> 16 Build Essentials
=> 17 Git

Step 2: download attached NanoHatOLED.tar.gz and copy NanoHatOLED.tar.gz to installation folder (e.g. /home)
cd /home
sudo tar -pxvzf NanoHatOLED.tar.gz
cd NanoHatOLED
sudo ./install.sh

Maarten
NanoHatOLED.tar.gz (423 KB)

Thanks for your script …

Thanks for modifications but didn’t work on my NanopiNeo2, neither with
DietPi_NanoPiNEO2-ARMv8-Stretch nor DietPi_NanoPiNEO2-ARMv8-Buster.

On the other side, the script with your modifications it works on my board but
with another …bian distro. I just followed your step 2 and everything was allright.

In DietPi, after I followed your installation instructions, htop show me that .NanoHatOLED is running but the OLED is black.

Have any ideea what could be wrong on my Dietpi settings?

Thanks for your time

Hi Guys,

sorry to jump in but, I have just spent most of this afternoon trying to get the OLED display to work on this great little Neo2Black… to avail.
Having gone through multiple forums and tutorials, this thread IS the most recent and comprehensive concerning what we are trying to do : get DietPI to work on the Neo2Black with an OLED display.

My ultimate goal is to get DietPI + UFW + PiHole + Unbound running on this brilliant piece of engineering.

I have tried multiple times an still no OLED.
@maarten : the new install.sh doesn’t throw any errors, unlike the previous one that I boiled down to a Python 2.7 error.
I have the eMMC module with an μSD to eMMC adapter.
From a fresh eMMC flash (DietPi_NanoPiNEO2Black-ARMv8-Buster.img)
copy NanoHatOLED.tar.gz to /home folder via cp
ssh into dietpi
run dietpi-config
install 130 + 16 + 17
run ./install.sh
Still no OLED.

I’m bummed about this and have called it quits for today, and any help would be appreciated for another bash at it.
Steve

PS : The FriendlARM.img works fine with OLED BTW, but I would much MUCH prefer DietPI ;.)

The install.sh expects rc.local to be present and enabled. Please try this before running install.sh:

>> /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…:

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
/usr/local/bin/oled-start

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:

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?

why not use a systemd service?

[Unit]
Description=NanoHAT OLED

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/oled-start

[Install]
WantedBy=multi-user.target

and oled-start:

#!/bin/sh
cd /root/NanoHatOLED
./NanoHatOLED

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

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 ./install.sh

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

root@DietPi:~# sudo nano oled.service

copy buesche’s code to oled.service

[Unit]

Description=NanoHAT OLED

#[Service]
#Type=oneshot
#RemainAfterExit=yes
#ExecStart=/usr/local/bin/oled-start

#[Install]
#WantedBy=multi-user.target

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
abled)
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
S)
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
akebit_nanohat_oled.py 2>&1 | tee /tmp/nanoled-python.log
├─991 python3 bakebit_nanohat_oled.py
└─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 ;.)

Yeah a systemd unit is the obvious solution on systemd-driven systems indeed. It is not what the original install.sh does, so just take care to not double things.

rc.local on modern Debian/DietPi is btw as well started via systemd unit :wink:: 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 :frowning:.
Does i2cdetect btw show expected output, so that I2C is really enabled?

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 :


red stuff is obviously not good news :.(

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

PS : No OLED output whatsoever, not a blink !

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

=> 16 Build Essentials
=> 17 Git

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

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

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 !
NanoHatOLED.tar.gz (410 KB)

@ dornt, FrogPI

try following and re-install NanoHatOLED:

MichaIng commented on 25 Feb
@maartenlangeveld
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:

docker_optimizations=off

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.
https://www.reddit.com/r/pihole/comments/f9ztfs/just_wanted_to_show_you_my_little_pihole_machine/
https://imgur.com/a/1BLo01B

I’ve mostly been trying to modify the bakebit_nanohat_oled.py 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.

I know this is an old thread, but I am hoping someone can help me. Has anyone been able to get this OLED hat to work on DietPi 8.4 with Python3. If so, what are the steps.

Thank you kindly.