[Tutorial] How to get your NanoHatOLED to work

Maybe you need to enable i2c manually:

And use 2to3 to convert old python2 script to python3 version.

Hej, so I am trying to redeploy my NanoHatOLED on an Neo2 but @Aldoszx Package did not seem to work right away.
After some digging I found the Error, for the current DietPi 8.7 one has to replace the python3.7 with python3.9

This worked for me

Yes this is somehow expected as in meantime we use Debian Bullseye. There Python 3.9 will be installed.

hello guys.
I share my solution with you:
the bakebit.py can’t run well in python3 but only work with python2.
when you run in python3, it will have “smbus module is not found”, “Mode =01” etc problems.

so, don’t waste time to make it work in python3, just install or keep python2 to run it.
in NanoPi-Neo oled Ubuntu16 ROM. it owns python2.7 and python3.5.4. the default command “python” is python2. if you install python3.10 or python3.11, the command “python” will be going to version python3.10 or python3.11.

way#1,you can use “ln -s /usr/bin/python2.7 /usr/bin/python” to softlink (re-direct) python to python2
way#2, modify vim /usr/bin/oled-start, add a new line after end line “python2 \root\NanoHatOLED/BakeBit/Software/Python/bakebit_128_64_oled.py”

if sys.version_info<(3,0):
p_version=2
else:
p_version=3

if sys.platform == ‘uwp’:
import winrt_smbus as smbus
bus = smbus.SMBus(1)
else:
import smbus
import RPi.GPIO as GPIO
rev = GPIO.RPI_REVISION
if rev == 2 or rev == 3:
bus = smbus.SMBus(0)
else:
bus = smbus.SMBus(0)

Something you definitely should not do as Python 2 is depreciated since nearly 3 years now Sunsetting Python 2 | Python.org

There was definitely enough time for python script maintainers to migrate to Python 3. Staying on python 2 is not a good option.

keep two versions of python on the system.
both python2 and python3.

revise:
NOT “\root\NanoHatOLED/BakeBit/Software/Python/bakebit_128_64_oled.py””
it should be "\root\NanoHatOLED/BakeBit/Software/Python/bakebit_nanohat_oled.py”

It is 2025 2026 and DietPi is based on Buster Bookworm Trixie with kernel 4.x 6.x.

Some modifications were necessary on the latest NanoHatOLED github repository which is already based on Python3.8.

I have removed everything not related to the NanoHatOLED and merged all the modifications from @maarten and @Fatguy5150 described in this forum.

  • DietPi or PiHole Logo on boot
  • 30 Seconds sleep to avoid OLED Burn-in
  • Start-up script on var/lib/dietpi/postboot.d/
  • Latest PiHole 6.x API integration (api.php has been removed)

How-to is found here

??? Nope, DietPi did not support Buster since years

2 Likes

Hi NanoDiet,

Quite interested in your code there. I finally got around to install a small web server on this nanopi neo of mine. Would love to make use of the oled hat. Everything’s running fine on dietpi bookworm, just now looking into getting the hat to work…

For others: Nanopi has now an image based on bookworm with the hat working out of the box. Just go to their wiki (i think) and ownload it. Then get the code in one of the above messages (with the burnout fix) and you’re off to the races.

1 Like