[Tutorial] How to get your NanoHatOLED to work

For those of us that were all excited about getting their NanoPi with the NanoHatOLED screen … http://www.friendlyarm.com/index.php?route=product/product&product_id=189
Neo2.jpg
… but had the sad feelings when you could not get the OLED screen to work using DietPi then I have some good news!

Here are the steps I used to get it up and running (everything works!)

Step 0: Make sure you only log into the DietPi using a non-Root account (eg. dietpi:dietpi)

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: Execute the following code

sudo apt-get install libfreetype6-dev libjpeg-dev

Step 3: Execute the following code

sudo pip install --upgrade ssd1306

Step 4: Execute the following code (system will reboot at the end)

git clone https://github.com/friendlyarm/NanoHatOLED.git && cd NanoHatOLED && sudo -H ./install.sh

Once the system reboots you should see the FriendlyElec logo flash up and then everything should just work!


HOWEVER …

After running mine 24x7 for about a month I discovered that my little OLED screen had developed a nasty case of “screen burn” :open_mouth:
This inspired me to do a little hacking and make a few fixes.

Executing the following code will do two things:

  1. Replace the default script with one that turns off the screen after five(ish) minutes (as soon as you click a button it will turn back on for another five minutes).
  2. Replaces the boot image with a muuuch better one. dietpi logo
wget -O NanoHatOLED.zip http://dietpi.com/phpbb/download/file.php?id=1033 && sudo unzip -o NanoHatOLED.zip -d NanoHatOLED/BakeBit/Software/Python

Reboot and all should be good with the world.
NanoHatOLED.zip (5.59 KB)

That’s pretty cool! Btw just a quick question - would this work with a NanoPi-NEO2? I should be receiving one very soon and would want to use this OLED … and with DietPi.

It will indeed work with the Neo2! (I’m using the 1st gen Neo2, looks like you will be using the 3rd gen with the silver case)

If you want to use my custom script that will avoid screen burn I’ve uploaded a new version that has a few changes

  • retains the FriendlyElec logo on bootup (shows the DietPi logo after)
  • turns off the screen after two minutes (old version was set to five minutes)
  • has a better way of working out the IP (makes sure it grabs eth0 and not tun0 when using a VPN)
  • uses 0% CPU when it has turned the screen off (the old script would use between 2-5%)
wget -O NanoHatOLED.zip http://dietpi.com/phpbb/download/file.php?id=1101 && sudo unzip -o NanoHatOLED.zip -d NanoHatOLED/BakeBit/Software/Python

Reboot after installing :slight_smile:
NanoHatOLED v2.zip (5.74 KB)

Thanks for the nice work.

It was working fine on my previous installation. I had to reinstall dietpi … and now the display does not turn off. :frowning:

found the error. Now it’s working perfect.

thank you . works great . i love the small thing

Hi,

Have bought a NanoPi NEO2 LTS. Managed to get the NanoHatOLED working using instructions above.
However after a while having to reboot, the OLED display went all black. Did complete DietPi re-install and it worked till I installed other software (Pi-Hole in casu), now it has stopped working again.

Have re-run install.sh a couple of times but that does not help…

Does someone knows why it won’t work anymore?

Running latest update (v6.20.5).

Thanks,

Maarten

Solution found !

The service did not start

After “systemctl enable rc-local.service”, “systemctl daemon-reload” and “systemctl start rc-local” the display has been activated again.

maarten
Ah jep, please note the following:
rc.local is an outdated/obsolete feature that is disabled on fresh Debian images by default and DietPi just follows that. It is however still implemented via compatibility systemd unit and can be enabled as you did.

But nowadays one should create a systemd unit directly to start custom scripts on boot.

Another possibility is to place the custom script into /var/lib/dietpi/postboot.d/my_script.sh. Name can be chosen, only .sh ending required.
This is our own compatibility implementation that has the same effect and is used by some optional DietPi features as well.

But either way of course works :wink:.

Thanks Micha! I have no knowledge of Linux, just found out by trial and error.

As per your advice I have put a script in /var/lib/dietpi/postboot.d/

Just wondering, will these scripts remain when updating to new version?

maarten
Jep those are update persistent.

great! Thanks Micha !

Hello,

I had to recompile the kernel and then installed DietPi over it. Now it shows “Linux DietPi 4.19.25-sunxi64 #5.76 SMP” under uname.
I can’t make NanoHatOLED work.

When I try “systemctl enable rc-local.service” I get this message :

dietpi@DietPi:~$ sudo systemctl enable rc-local.service
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:

  1. A unit may be statically enabled by being symlinked from another unit’s
    .wants/ or .requires/ directory.
  2. A unit’s purpose may be to act as a helper for some other unit which has
    a requirement dependency on it.
  3. A unit may be started when needed via activation (socket, path, timer,
    D-Bus, udev, scripted systemctl call, …).
  4. In case of template units, the unit is meant to be enabled with some
    instance name specified.

Any ideas?

Thanks

rc-local system has changed in Debian, conflicting some old DietPi leftover. Please check for solution: https://github.com/MichaIng/DietPi/issues/2566

Thanks for the info Micha.

Not working. Did the install, than rebooted…

But even trying to run manually it’s not working.

But … the ./NanoHatOLED is showing under htop however nothing shows at the display.

Same here, worked like a charm up until recently. Now it is not working anymore. Black screen.
However htop shows the deamon is runnning…

i2c not working here …


sudo i2cdetect -y 0
Error: Could not open file /dev/i2c-0' or /dev/i2c/0’: No such file or directory

how can I enable it ?

After several reboots it seems to work again. However, NanoHatOLED display starts working not immediately after (re)boot but it takes a delay…

it’s finally working fine.

Just updated from 6.19.7 to 6.24.1 and everything is working for me, I’m assuming the more recent versions of DietPi have a workaround in place for whatever gremlins were affecting people.