[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 and DietPi is based on Buster Bookworm 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 install

  1. Enable i2c (add to armbianEnv.txt): overlays=i2c0 usbhost1 usbhost2
  2. Download NanoHatOLED.tar.gz and copy it on ~/
  3. apt-get install git build-essential
  4. Add board information on /etc/sys_info. The below is an example of a NanoPi NEO1.4. If you have a different board, find the _platform & _board_id information here ~/NanoHatOLED/BakeBit/WiringNP/wiringPi/boardtype_friendlyelec.c and the _chipid here nano /proc/cpuinfo. For example, NanoPi NEO Air issunxi_platform: Sun8iw7p1. and sunxi_board_id: 2(0). Everything else is kindda irrelevant.

/etc/sys_info

sunxi_platform    : Allwinnersun8iFamily
sunxi_secure      : normal
sunxi_chipid      : 2c21020e786746240000540000000000
sunxi_chiptype    : 00000042
sunxi_batchno     : 1
sunxi_board_id    : 1(0)
  1. tar -pxvzf NanoHatOLED.tar.gz && cd NanoHatOLED && ./install.sh

Troubleshooting:

  • Check that after reboot, the binary ./NanoHatOLED is running inhtop
  • Check you have a nice reading of all IO when executing command gpio readall
  • Check that i2c is enabled by executing command sudo i2cdetect -y 0
  • Finally, check for some errors on the below logs
    /tmp/nanoled-python.log or /tmp/nanohat-oled.log

Notes:

  • No need for those libraries anymore libfreetype6-dev libjpeg-dev luma.oled
  • the flag --break-system-packages is used for the -pip libraries to install them on the system level

How can I upload the source code here?? Please somebody let me know.

*edit1: DietPi is Based on Bookworm.
*edit2: Added PiHole 6.x API integration

??? 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…