From the date of purchase NanoPi NEO2 with NanoHat OLED display it's only been about two weeks, all the time computer was turned on and lay on the windowsill. On the display at this time was showed the 1st screen with the current time, i.e. it would seem, not such a static picture. But it turned out that this is enough to start to burn out OLED-display. It is noticeable on the 3rd screen, where menu items are highlighted. On the top item Yes can be clearly read Mar 2019, and on the bottom item No shows the clock elements.

In order not to completely ruin the display – it was necessary to implement a sleep timer, in order to automatically turn off the display after a certain time. As it turned out, this idea visited not only me, and the script for controlling the display has already been finalized. Here is the original changes, and here small discussion.

The only thing that I did not like in these improvements – after the display fell asleep, pressing any key not just awakens the display, but awakens the display and immediately performs the action that is assigned to the button. In my opinion this is wrong, so I slightly changed the script to the first press of any button just turned on the display.

--- bakebit_nanohat_oled.py.orig    2018-10-11 11:08:29.000000000 +0300
+++ bakebit_nanohat_oled.py 2019-03-14 12:40:19.083354599 +0300
@@ -45,6 +45,8 @@
 import signal
 import os
 import socket
+import fcntl
+import struct

 global width
 width=128
@@ -57,6 +59,10 @@
 pageIndex=0
 global showPageIndicator
 showPageIndicator=False
+global pageSleep
+pageSleep=120
+global pageSleepCountdown
+pageSleepCountdown=pageSleep

 oled.init()  #initialze SEEED OLED display
 oled.setNormalDisplay()      #Set display to normal mode (i.e non-inverse mode)
@@ -83,6 +89,14 @@
 global lock
 lock = threading.Lock()

+def get_ip_address(ifname):
+    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+    return socket.inet_ntoa(fcntl.ioctl(
+        s.fileno(),
+        0x8915,  # SIOCGIFADDR
+        struct.pack('256s', ifname[:15])
+    )[20:24])
+
 def get_ip():
     s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     try:
@@ -111,6 +125,7 @@
     global width
     global height
     global lock
+    global pageSleepCountdown

     lock.acquire()
     is_drawing = drawing
@@ -120,6 +135,16 @@
     if is_drawing:
         return

+    # if the countdown is zero we should be sleeping (blank the display to reduce screenburn)
+    if pageSleepCountdown == 1:
+        oled.clearDisplay()
+        pageSleepCountdown = 0
+
+    if pageSleepCountdown == 0:
+        return
+
+    pageSleepCountdown = pageSleepCountdown - 1
+
     lock.acquire()
     drawing = True
     lock.release()
@@ -149,12 +174,15 @@
     elif page_index==1:
         # Draw some shapes.
         # First define some constants to allow easy resizing of shapes.
-        padding = 2
+        padding = 0
         top = padding
         bottom = height-padding
         # Move left to right keeping track of the current x position for drawing shapes.
         x = 0
-   IPAddress = get_ip()
+        try:
+            IPAddress = get_ip_address('eth0')
+        except:
+            IPAddress = get_ip()
         cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %.2f\", $(NF-2)}'"
         CPU = subprocess.check_output(cmd, shell = True )
         cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%sMB %.2f%%\", $3,$2,$3*100/$2 }'"
@@ -218,6 +246,15 @@

 def receive_signal(signum, stack):
     global pageIndex
+    global pageSleepCountdown
+    global pageSleep
+
+    # check if screen is black then just return from sleep without signal processing
+    if pageSleepCountdown == 0:
+        pageSleepCountdown = pageSleep # user pressed a button, reset the sleep counter
+        return
+    else:
+        pageSleepCountdown = pageSleep

     lock.acquire()
     page_index = pageIndex

As you can see from the diff, the script not only adds the functionality of the screen saver, but also improves the definition of IP-address. Because the original script in some conditions may show the IP-address is not a network card, but any other interface, such as VPN-connection interface tun0.

These changes can be manually made to the file /root/NanoHatOLED/BakeBit/Software/Python/bakebit_nanohat_oled.py or you can copy them to .diff file and apply the patch to the original script:

wakko@NanoPi-NEO2:~$ nano -w ~/sleep.diff
... insert here the contents of the patch ...
wakko@NanoPi-NEO2:~$ patch -b ~/NanoHatOLED/BakeBit/Software/Python/bakebit_nanohat_oled.py < ~/sleep.diff
patching file ~/NanoHatOLED/BakeBit/Software/Python/bakebit_nanohat_oled.py

Then restart the computer and no longer worry that the display can quickly burn out.


Next Post Previous Post