0

RuntimeError: Group full with CPB + TFT Gizmo
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RuntimeError: Group full with CPB + TFT Gizmo

by V2man on Sat Feb 08, 2020 5:59 pm

CPB + TFT Gizmo
Adafruit CircuitPython 5.0.0-beta.5 on 2020-02-05;
Adafruit Circuit Playground Bluefruit with nRF52840
02/06/2020 Bundle Version 5.x libraries
How can I display more information on the CPX + TFT Gizmo without running into a group full error?
Is there a better way to do this than what I am doing now?
The code below runs but if I uncomment statements related to text_area6 I get :
File "code.py", line 101, in <module>
File "adafruit_display_text/label.py", line 178, in text
File "adafruit_display_text/label.py", line 123, in _update_text
RuntimeError: Group full

Code: Select all | TOGGLE FULL SIZE
import board
import microcontroller
import analogio
import audiobusio
import busio
import digitalio
import displayio
import math
import array
import terminalio
import adafruit_lis3dh
from time import sleep
from adafruit_display_text import label
# from adafruit_bitmap_font import bitmap_font
from adafruit_gizmo import tft_gizmo
light = analogio.AnalogIn(board.LIGHT)

# Number of samples to read at once.
NUM_SAMPLES = 160
# Remove DC bias before computing RMS.
def normalized_rms(values):
    minbuf = int(mean(values))
    samples_sum = sum(
        float(sample - minbuf) * (sample - minbuf)
        for sample in values
    )
    return math.sqrt(samples_sum / len(values))

def mean(values):
    return sum(values) / len(values)
mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA,
                       sample_rate=16000, bit_depth=16)

# Record an initial sample to calibrate. Assume it's quiet when we start.
samples = array.array('H', [0] * NUM_SAMPLES)
mic.record(samples, len(samples))

if hasattr(board, 'ACCELEROMETER_SCL'):
    i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
    int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
    lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
else:
    i2c = busio.I2C(board.SCL, board.SDA)
    int1 = digitalio.DigitalInOut(board.D6)
    lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
lis3dh.range = adafruit_lis3dh.RANGE_2_G
# displayio.release_displays()
# Create the TFT Gizmo display
display = tft_gizmo.TFT_Gizmo()
font = terminalio.FONT
text_group = displayio.Group(max_size=8, scale=2, x=0, y=0)
space_20 = "                   "
green = 0x00FF00
# Create the text labels
text_area1 = label.Label(font, text=space_20, color=green)
text_area2 = label.Label(font, text=space_20, color=green)
text_area3 = label.Label(font, text=space_20, color=green)
text_area4 = label.Label(font, text=space_20, color=green)
text_area5 = label.Label(font, text=space_20, color=green)
# text_area6 = label.Label(font, text=space_20, color=green)

# Set the locations
text_area1.x = 0
text_area1.y = 20
text_area2.x = 0
text_area2.y = 30
text_area3.x = 0
text_area3.y = 40
text_area4.x = 0
text_area4.y = 50
text_area5.x = 0
text_area5.y = 60
# text_area6.x = 0
# text_area6.y = 70

# append the labels to a group
text_group.append(text_area1)
text_group.append(text_area2)
text_group.append(text_area3)
text_group.append(text_area4)
text_group.append(text_area5)
# text_group.append(text_area6)

display.show(text_group)

while True:
    cpu_temp = microcontroller.cpu.temperature * (9/5) + 32
    cpu_freq = microcontroller.cpu.frequency/1000000
    cpu_volt = microcontroller.cpu.voltage
    intensity = light.value
    mic.record(samples, len(samples))
    magnitude = normalized_rms(samples)
    x, y, z = lis3dh.acceleration
    text_area1.text = "Temp:  %0.1f *F" % cpu_temp
    text_area2.text = "Freq:  %0.1f MHz" % cpu_freq
    text_area3.text = "Volt:  %0.3f V" % cpu_volt
    text_area4.text = "Light: %0.0f " % intensity
    text_area4.text = "Light: %0.0f " % intensity
    text_area5.text = "Sound: %0.0f " % magnitude
    # text_area6.text = "Accl: %0.1f" % x + ",%0.1f" % y + ",%0.1f" % z
    sleep(1)
    pass

V2man
 
Posts: 703
Joined: Mon Dec 03, 2018 12:38 am

Re: RuntimeError: Group full with CPB + TFT Gizmo

by V2man on Sun Feb 09, 2020 1:06 am

This reduces the space needed to display acceleration by 2.
text_area6.text = "Accl: %0.1f" % x + ",%0.1f" % y + ",%0.1f" % z becomes text_area6.text = "Acc:%0.1f" % x + ",%0.1f" % y + ",%0.1f" % z
CPB + TFT Gizmo works now with all text_area6 statements uncommented.

But CPX + TFT Gizmo with the modified code still gives RuntimeError: Group full.

V2man
 
Posts: 703
Joined: Mon Dec 03, 2018 12:38 am

Re: RuntimeError: Group full with CPB + TFT Gizmo

by adafruit_support_carter on Mon Feb 10, 2020 1:55 pm

Can you reproduce it on the CPX with a simple example that only uses your text_area6 code?

adafruit_support_carter
 
Posts: 14475
Joined: Tue Nov 29, 2016 2:45 pm

Re: RuntimeError: Group full with CPB + TFT Gizmo

by V2man on Mon Feb 10, 2020 8:15 pm

@ adafruit_support_carter
I modified text_area6.text = "A:%0.1f" % x + ",%0.1f" % y + ",%0.1f" % z to give me the most space for double digit numbers.
I have tried using text_area5 and text_area6 with all the other text_areas commented out. That works on the CPX + Gizmo.
When I also uncomment one of the others: text_area1, text_area2, text_area3 or text_area4 I get
MemoryError: memory allocation failed, allocating 84 bytes

V2man
 
Posts: 703
Joined: Mon Dec 03, 2018 12:38 am

Re: RuntimeError: Group full with CPB + TFT Gizmo

by adafruit_support_carter on Mon Feb 10, 2020 8:54 pm

Getting the MemoryError is probably due to the limited space available on the CPX. There's really no way around that other than reduce the amount of items you are trying to create or upgrade the hardware - to something like a CP Bluefruit.

Getting the RuntimeError: Group full is probably due to trying to update the Label text with a string that is longer than what it was originally setup for. In your case, this looks like 20 characters max.

There's a Python trick for things like this:
Code: Select all | TOGGLE FULL SIZE
space_20 = "                   "

You can also do:
Code: Select all | TOGGLE FULL SIZE
space_20 = " "*20

adafruit_support_carter
 
Posts: 14475
Joined: Tue Nov 29, 2016 2:45 pm

Re: RuntimeError: Group full with CPB + TFT Gizmo

by V2man on Mon Feb 10, 2020 10:07 pm

@ adafruit_support_carter Thanks for the tip on defining the string variable, space more easily.

V2man
 
Posts: 703
Joined: Mon Dec 03, 2018 12:38 am

Re: RuntimeError: Group full with CPB + TFT Gizmo

by Teedee1 on Thu Feb 13, 2020 9:41 am

Is there a direct convesrion rate to convert the sound output into Decibels and is there a conversion to convert the light output to Lux?

Thanks!!

Teedee1
 
Posts: 8
Joined: Thu Jan 30, 2020 5:45 am

Re: RuntimeError: Group full with CPB + TFT Gizmo

by V2man on Thu Feb 13, 2020 11:55 am

Good question @ Teedee1! I was thinking the same thing. I have these light and sound numbers but they are meaningless. They are just relative numbers. It would be nice to be able to calibrate them to an absolute scale. Might even want to add distance so we could hold the board a some fixed distance from a light or sound source and get an accurate absolute reading in dB or LUX. I don't know the answer. Maybe someone else on this forum can chime in.

V2man
 
Posts: 703
Joined: Mon Dec 03, 2018 12:38 am

Please be positive and constructive with your questions and comments.