0

Hallowing Circuitpython - small int overflow
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Hallowing Circuitpython - small int overflow

by jcue on Wed Feb 17, 2021 11:59 pm

Hello,

I just installed the latest version of circuitpython (6.1.0) on the HalloWing M0 Express. I keep getting the following error with the stock example that creates a slideshow. I also tried the Magic 9 Ball example which results in the same error :
Code: Select all | TOGGLE FULL SIZE
code.py output:
Traceback (most recent call last):
  File "code.py", line 24, in <module>
  File "adafruit_slideshow.py", line 176, in __init__
OverflowError: small int overflow

jcue
 
Posts: 9
Joined: Sun Jul 27, 2014 6:17 pm

Re: Hallowing Circuitpython - small int overflow

by tannewt on Thu Feb 18, 2021 3:26 pm

What version of adafruit_slideshow do you have? I don't see anything suspicious on that line here: https://github.com/adafruit/Adafruit_Ci ... ow.py#L176

(Try updating the library if it's old.)

tannewt
 
Posts: 2189
Joined: Thu Oct 06, 2016 8:48 pm

Re: Hallowing Circuitpython - small int overflow

by jcue on Thu Feb 18, 2021 3:34 pm

The version that comes with the latest version of circuitpython. It's the default code.py file.

jcue
 
Posts: 9
Joined: Sun Jul 27, 2014 6:17 pm

Re: Hallowing Circuitpython - small int overflow

by tannewt on Thu Feb 18, 2021 3:51 pm

CircuitPython itself doesn't include libraries. Updating CircuitPython preserves the existing libraries on the file system.

Here is a guide on how to do this: https://learn.adafruit.com/welcome-to-c ... -libraries

tannewt
 
Posts: 2189
Joined: Thu Oct 06, 2016 8:48 pm

Re: Hallowing Circuitpython - small int overflow

by jcue on Thu Feb 18, 2021 4:04 pm

Doh! That's most likely my problem. I'll update the libraries and test again. Thanks for the help.

jcue
 
Posts: 9
Joined: Sun Jul 27, 2014 6:17 pm

Re: Hallowing Circuitpython - small int overflow

by jcue on Thu Feb 18, 2021 4:51 pm

I updated the libraries and I continue getting the same error. The example code I am using is for the Magic 9 ball

https://learn.adafruit.com/hallowing-ma ... cuitpython

Code: Select all | TOGGLE FULL SIZE
Adafruit CircuitPython 6.1.0 on 2021-01-21; HalloWing M0 Express with samd21g18
>>> [B
>>>
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.

code.py output:
Traceback (most recent call last):
  File "code.py", line 17, in <module>
OverflowError: small int overflow

Code done running.

jcue
 
Posts: 9
Joined: Sun Jul 27, 2014 6:17 pm

Re: Hallowing Circuitpython - small int overflow

by tannewt on Fri Feb 19, 2021 9:22 pm

Even though you are using example code, please repost it. I want ensure we're looking at the same code.

tannewt
 
Posts: 2189
Joined: Thu Oct 06, 2016 8:48 pm

Re: Hallowing Circuitpython - small int overflow

by jcue on Fri Feb 19, 2021 10:26 pm

Sure no problem. I was able to get the code to work - for some reason it doesn't like the lambda function. I'll post the original code that doesn't work and the codes where a made a few tweaks:

Code: Select all | TOGGLE FULL SIZE
# Magic 9 Ball
# Turn HalloWing face down and then face up to change images at random
# place 128 x 128 pixel 24-bit .bmp images at root level of HalloWing

import time
import os
import random
import board
import displayio
import adafruit_lis3dh

splash = displayio.Group()
board.DISPLAY.show(splash)

SENSITIVITY = 5   # reading in Z direction to trigger, adjustable

images = list(filter(lambda x: x.endswith("bmp"), os.listdir("/")))

i = random.randint(0, (len(images)-1))  # initial image is randomly selected

# Set up accelerometer on I2C bus, 4G range:
ACCEL = adafruit_lis3dh.LIS3DH_I2C(board.I2C(), address=0x18)

ACCEL.range = adafruit_lis3dh.RANGE_4_G

while True:
    shaken = False
    with open(images[i], "rb") as f:
        print("Image load {}".format(images[i]))
        try:
            odb = displayio.OnDiskBitmap(f)
        except ValueError:
            print("Image unsupported {}".format(images[i]))
            del images[i]
            continue
        face = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter())

        splash.append(face)
        # Wait for the image to load.
        try:
            board.DISPLAY.refresh(target_frames_per_second=60)
        except AttributeError:
            board.DISPLAY.wait_for_frame()

        # Fade up the backlight
        for b in range(101):
            board.DISPLAY.brightness = b / 100
            time.sleep(0.01)  # default (0.01)

        # Wait until the board gets shaken
        while not shaken:
            try:
                ACCEL_Z = ACCEL.acceleration[2]  # Read Z axis acceleration
            except OSError:
                pass
            # print(ACCEL_Z)  # uncomment to see the accelerometer z reading
            if ACCEL_Z > SENSITIVITY:
                shaken = True

        # Fade down the backlight
        for b in range(100, 0, -1):
            board.DISPLAY.brightness = b
            time.sleep(0.005)  # default (0.005)

        splash.pop()

        i = random.randint(0, (len(images)-1))  # pick a new random image
        # print("shaken")
        faceup = False
        i %= len(images) - 1


Updated Code:

Code: Select all | TOGGLE FULL SIZE
# Magic 9 Ball
# Turn HalloWing face down and then face up to change images at random
# place 128 x 128 pixel 24-bit .bmp images at root level of HalloWing

import time
import os
import random
import board
import displayio
import adafruit_lis3dh

splash = displayio.Group()
board.DISPLAY.show(splash)

SENSITIVITY = 5   # reading in Z direction to trigger, adjustable
dirName = '/pics'

images = []
files_dir = os.listdir(dirName)
for img in files_dir:
    if img.endswith(".bmp"):

        images.append(dirName + "/" + img)

"""  """
i = random.randint(0, (len(images)-1))  # initial image is randomly selected

# Set up accelerometer on I2C bus, 4G range:
ACCEL = adafruit_lis3dh.LIS3DH_I2C(board.I2C(), address=0x18)

ACCEL.range = adafruit_lis3dh.RANGE_4_G




while True:
    shaken = False
   
    with open(images[i], "rb") as f:
        print("Image load {}".format(images[i]))
        try:
            odb = displayio.OnDiskBitmap(f)
        except ValueError:
            print("Image unsupported {}".format(images[i]))
            del images[i]
            continue
        face = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter())

        splash.append(face)
        # Wait for the image to load.
        try:
            board.DISPLAY.refresh(target_frames_per_second=60)
        except AttributeError:
            board.DISPLAY.wait_for_frame()

        # Fade up the backlight
        for b in range(101):
            board.DISPLAY.brightness = b / 100
            time.sleep(0.01)  # default (0.01)

        # Wait until the board gets shaken
        while not shaken:
            try:
                ACCEL_Z = ACCEL.acceleration[2]  # Read Z axis acceleration
            except OSError:
                pass
            # print(ACCEL_Z)  # uncomment to see the accelerometer z reading
            if ACCEL_Z > SENSITIVITY:
                shaken = True

        # Fade down the backlight
        for b in range(100, 0, 1):
            board.DISPLAY.brightness = b
            time.sleep(0.005)  # default (0.005)

        splash.pop()

        i = random.randint(0, (len(images)-1))  # pick a new random image
        # print("shaken")
        faceup = False
        i %= len(images) - 1

jcue
 
Posts: 9
Joined: Sun Jul 27, 2014 6:17 pm

Re: Hallowing Circuitpython - small int overflow

by tannewt on Sat Feb 20, 2021 8:09 pm

Thanks for the update! I'm glad you got it going. It's a very weird error.

tannewt
 
Posts: 2189
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.