Seeking help on BigSeg7x4

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
eaderigt
 
Posts: 26
Joined: Sun Oct 02, 2022 2:00 am

Seeking help on BigSeg7x4

Post by eaderigt »

Dear all,

I have set my Raspberry PI up with a BigSeg7x4 display. And I use it to show 3 values that switch a) power usage b) temperature c) wind direction.

In order to switch from one value to the other I use display.fill(0) to clean the display before showing the next one.

It runs fine and can run perfectly for days. Though at some point (sometimes after hours - sometimes after days) my code crashes and I get the error message like below.
It seems to crash on the display.fill(0) line.
>>> %Run knmi_power6.py
Traceback (most recent call last):
File "/home/erik/meter/knmi_power6.py", line 88, in <module>
display.fill(0)
File "/home/erik/.local/lib/python3.9/site-packages/adafruit_ht16k33/ht16k33.py", line 141, in fill
self.show()
File "/home/erik/.local/lib/python3.9/site-packages/adafruit_ht16k33/ht16k33.py", line 128, in show
i2c_dev.write(buffer)
File "/usr/local/lib/python3.9/dist-packages/adafruit_bus_device/i2c_device.py", line 101, in write
self.i2c.writeto(self.device_address, buf, start=start, end=end)
File "/usr/local/lib/python3.9/dist-packages/busio.py", line 174, in writeto
return self._i2c.writeto(address, memoryview(buffer)[start:end], stop=stop)
File "/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 52, in writeto
self._i2c_bus.write_bytes(address, buffer[start:end])
File "/usr/local/lib/python3.9/dist-packages/Adafruit_PureIO/smbus.py", line 314, in write_bytes
self._device.write(buf)
OSError: [Errno 121] Remote I/O error
>>>
This is the Code I use:

Code: Select all

import requests
import re
import serial
import time
import board
from adafruit_ht16k33 import segments

custom_chars = {}
custom_chars["z"] = 0b01100011 #gradenteken
custom_chars["g"] = 0b00111001
custom_chars["y"] = 0b00001111 #rechtshaak
custom_chars["x"] = 0b00111001 #linkshaak
custom_chars["w"] = 0b00001110 #rechtsonder
custom_chars["v"] = 0b00111000 #linksonder
custom_chars["u"] = 0b00000111 #rechtsboven
custom_chars["m"] = 0b00110001 #linksboven
custom_chars["n"] = 0b00000001 #boven
custom_chars["q"] = 0b00001000 #onder
custom_chars["k"] = 0b00001001 #onder en boven

i2c = board.I2C()
#display = segments.BigSeg7x4(i2c)
display = segments.BigSeg7x4(i2c, char_dict=custom_chars)
display.brightness = 0.1
 
# Seriele poort confguratie
ser = serial.Serial()

# DSMR 4.0/4.2 > 115200 8N1:
ser.baudrate = 115200
ser.bytesize = serial.EIGHTBITS
ser.parity = serial.PARITY_NONE
ser.stopbits = serial.STOPBITS_ONE
 
ser.xonxoff = 0
ser.rtscts = 0
ser.timeout = 12
ser.port = "/dev/ttyUSB0"
ser.close()

erik_temp = 99
erik_dir = 99

teller = 199

while True:
    teller = teller + 1
    if teller == 200:
    
        res2 = requests.get('https://weerlive.nl/api/json-data-10min.php?key=BANNED&locatie=52.34838940753904,4.906978197204979')
        data2 = res2.json()

        erik_temp = data2['liveweer'][0]['temp']
        erik_dir = int(data2['liveweer'][0]['windrgr'])
            
        teller = 0
    if 23 <= erik_dir < 68: #noordoost
        erik_dir2 = '__nu'
    elif 68 <= erik_dir < 113: #oost
        erik_dir2 = '__ky'
    elif 113 <= erik_dir <= 158: #zuidoost
        erik_dir2 = '__qw'
    elif 158 <= erik_dir < 203: #zuid
        erik_dir2 = 'vqqw'
    elif 203 <= erik_dir < 248: #zuidwest
        erik_dir2 = 'vq__'
    elif 248 <= erik_dir < 293: #west
        erik_dir2 = 'xk__'
    elif 293 <= erik_dir < 338: #noordwest
        erik_dir2 = 'mn__'
    else:
        erik_dir2 = 'mnnu' #noord
    
    ser.open()
    checksum_found = False

    #start BANNED inlees loop
    while not checksum_found:
        BANNED_line = ser.readline() # Lees een seriele lijn in.
        #print (type(BANNED_line))
    # check of het de elec regel is
        if re.match(b'(?=1-0:1.7.0)', BANNED_line):
            #check of de regel volledig is
            #print (BANNED_line)
            if re.search(b'(?=\(..\....\*kW\))', BANNED_line):
                elec1 = (BANNED_line[10:16]).decode()
                elec2 = int(float(elec1) * 1000)
                display.fill(0)
                time.sleep(0.01)
                display.print (str(elec2))
                time.sleep(1.6)
                display.fill(0)
                time.sleep(0.01)
                display.print (str(int(float(erik_temp))) + "zc")
                time.sleep(1.6)
                display.fill(0)
                time.sleep(0.01)
                display.print (str(erik_dir2))
                time.sleep(1.2)
            else:
                pass
                
    # Check wanneer het uitroepteken ontvangen wordt (einde BANNED inlees loop)
        if re.match(b'(?=!)', BANNED_line):
            checksum_found = True

    ser.close()  
thank you ,
Erik

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Seeking help on BigSeg7x4

Post by mikeysklar »

The only slightly related issue I see looks resolved. display.fill() would fail when display.auto_write was not set to True.

You could try adding some try/except logic to catch the error and continue.

Code: Select all

  try:
    display.fill(0)
  except OSError as error:
    print(error)
    print("can't stop me now")
Finally, how is your wiring and soldering? Anything unstable?

User avatar
eaderigt
 
Posts: 26
Joined: Sun Oct 02, 2022 2:00 am

Re: Seeking help on BigSeg7x4

Post by eaderigt »

hello mikey,

Thank you. I have the code now running including your suggestion. And will report here if it not crashing on the display.fill(0) lines.

Soldering and wiring has been strong and during the set up I spent time taking away all weak spots in the wiring and soldering.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Seeking help on BigSeg7x4

Post by mikeysklar »

Keep a REPL console open if possible. This will print out the errors should they still be occurring.

User avatar
eaderigt
 
Posts: 26
Joined: Sun Oct 02, 2022 2:00 am

Re: Seeking help on BigSeg7x4

Post by eaderigt »

I have that.

It is running smoothly. I will report here once it crashes or when it runs for a full week.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Seeking help on BigSeg7x4

Post by mikeysklar »

Cool. Still running. Thanks for the update.

User avatar
eaderigt
 
Posts: 26
Joined: Sun Oct 02, 2022 2:00 am

Re: Seeking help on BigSeg7x4

Post by eaderigt »

hi mike,

OK. Cool. you did it. It is still running at the moment.

But we did pass the crucial moment without crashing.
Screenshot 2023-03-15 at 08.02.01.png
Screenshot 2023-03-15 at 08.02.01.png (623.98 KiB) Viewed 208 times
I want to thank you a lot! because this had been bothering me for weeks/months.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Seeking help on BigSeg7x4

Post by mikeysklar »

Yes! I love it when these simple work arounds avoid a crash. Thank you for the follow up and the screenshot.

User avatar
eaderigt
 
Posts: 26
Joined: Sun Oct 02, 2022 2:00 am

Re: Seeking help on BigSeg7x4

Post by eaderigt »

hi Mike,
Quick update for your information. My code crashed once but unfortunately I did not get the message from the shell.
It is certainly more stable than it used to be.
Example screenshot is from that last 48 hours and we see it hit the crucial point twice.

I am waiting now to see if it crashes again. I am close to 99% certain it crashed on something else than the display fill.
Screenshot 2023-03-21 at 07.13.01.png
Screenshot 2023-03-21 at 07.13.01.png (200.83 KiB) Viewed 176 times

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Seeking help on BigSeg7x4

Post by mikeysklar »

I'm glad it is more delayed, but that error message does look the same as the one that was triggered by display.fill(0).

There is something you can try and it is not an elegant solution or even a fix. One thing that can happen on occasion with i2c devices is they fall off the i2c bus. You might be able to scan for them and get them back on the bus.

You could add this bit of scan logic to the error condition and see if the device can recover. Place the imports as the top of the file.

Code: Select all

import os
from time import sleep

os.system('i2cdetect -y 1')
sleep(0.1)
os.system('i2cdetect -y 1')

User avatar
eaderigt
 
Posts: 26
Joined: Sun Oct 02, 2022 2:00 am

Re: Seeking help on BigSeg7x4

Post by eaderigt »

thanks mike,

it has now been running for the past 4/5 days without ny messages in the shell. So that is good.

Still I will work on your suggestion - to see if it helps for more stability.

Will continue to inform here.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Seeking help on BigSeg7x4

Post by mikeysklar »

That is good progress @ 5days and running.

Did you add the i2cdetect or is this running without it?

Thank you for the update.

User avatar
eaderigt
 
Posts: 26
Joined: Sun Oct 02, 2022 2:00 am

Re: Seeking help on BigSeg7x4

Post by eaderigt »

currently still without it and still running.

Nice empty shell
Screenshot 2023-03-27 at 06.45.04.png
Screenshot 2023-03-27 at 06.45.04.png (88.93 KiB) Viewed 154 times

User avatar
eaderigt
 
Posts: 26
Joined: Sun Oct 02, 2022 2:00 am

Re: Seeking help on BigSeg7x4

Post by eaderigt »

hello Mike,
code has been running now for about 12 days without any crashes or shell updates.
that length it has never reached before I implemented you solution.

So that is cool.
In the case it would crash again - then I will go back and make alternations on your other suggestions.

Again - thanks

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Seeking help on BigSeg7x4

Post by mikeysklar »

Thank you for the update. 12 day and counting++.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”