#Gemma m0 memory error

1 messages ยท Page 1 of 1 (latest)

honest tendon
#

I guess I'm running into ram issues?

#

This is the code I'm trying to run:

import adafruit_dotstar as dotstar
import board

dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.1)
pulse = Pulse(dot, speed=0.1, color=(0, 255, 0), period=3)
pulse.animate()
honest tendon
#

Could this be due to the import being inline within the function and not at the top?

coarse ibex
#

The animation library is designed to be used with LED strips. That's a lot of overhead to pulse 1 LED. There are other ways to do it without involving large libraries.

honest tendon
#

I am having trouble writing basic pulse code.

#

Figured the library would be easier

coarse ibex
honest tendon
#

Thanks. That looks like just an analog out. I'm trying to work with the onboard RGB led to create a heartbeat like pulse effect.

coarse ibex
#

the onboard LED is just board.LED though that might not be the RGB LED.

honest tendon
#

I wasn't able to find a pulse/fade through those docs. Been looking at stuff all day, going in circles now ๐Ÿ˜„

#

Might be able to rev-eng the pulse code in the library though

coarse ibex
#

ah the RGB led uses 2 pins. board.APA102_MOSI and board.APA102_SCK. one is data the other is clock.

honest tendon
#

yep, i got the rgb led to rotate colors

#

but, writing nice fade/pulse code isn't trivial for me

coarse ibex
honest tendon
#

Nope, haven't seen this one

coarse ibex
#

the amount of time between operations can be slowed down by using time.sleep(0.01) in seconds.

#

time.sleep(5) would pause for 5 seconds and would be very noticeable but a pause of 0.5 might slow it down to a smoother slow speed.

honest tendon
#

My code is here, I've gotten the capacitive touch etc working.

coarse ibex
#

you'd want the pause inside the while true loop since that's what is looping.

#

something like py if mode == MODE_RGB_WHEEL: time.sleep(0.5) dot[0] = wheel(i)

honest tendon
#

Sure but what I guess i'm missing is what the fade algorithm should be like

#

Hi ,
This video is to show you how to make a simple heat beating effect LED heart.

โ—พ Circuit diagram - https://drive.google.com/file/d/1htFdoxIDvBjw2zZqzsxn_aJPW6iYL6j5/view?usp=drivesdk

โ—พ Resistors - https://amzn.to/3Afk6yh
โ—พ Transistors - https://amzn.to/3XKyyIO
โ—พ IC - https://amzn.to/3AMLgN5
โ—พ PCB - https://amzn.to/3EbR1Vp
โ—พ LED - h...

โ–ถ Play video
coarse ibex
#

ok that's a for in range loop that goes from 0 brightness to 255 where 255 is maximum brightness, then resets to 0 and loops infinitely.

honest tendon
#

It's not really though.

#

It's more like start at 255, fade down to 100, jump back to 255?

#

what I want to control is how fast it pulses down

#

Which I can do with time.sleep?

coarse ibex
#

the brightness is set with the argument brightness=next_brightness_val

honest tendon
#

does brightness internally change the rgb values?

#

what's the difference between using brightness=1 vs [255,0,0]

coarse ibex
#

do you want to keep the touch control for speed or brightness? i might have to whip out a gemma m0 and try this.

honest tendon
#

ideally both

#

A0 can be speed

coarse ibex
#

no the colors are R,G,B [0,0,0] to [255,255,255]

#

they start off at all 0's

honest tendon
#

A1 mode
A2 brightness

coarse ibex
#

so to only change the red you'll only want to change the first value for R in [R,G,B]

honest tendon
#

right

coarse ibex
#

and leave the others at 0

honest tendon
#

for my pulse effect i can ignore brightness correct?

coarse ibex
#

for that script it seems that brightness is equated to the color value where 0 is off (no brightness) and 255 is full brightness (per color).

honest tendon
#

correct. assume brightness constant at 0.1

coarse ibex
#

brightness isn't a constant, it's a variable that does change from 0-255

#

[255,0,0] is full red

honest tendon
#

if i set
dot = [255,0,0]
then change brigthness to 0.1

what is the value of dot?

#

it's not [255,0,0] anymore right?

#

it's [25, 0, 0]?

coarse ibex
#

oh you're correct, i didn't realize dot.brightness was an argument. i've never used the onboard RGB LED.

#

interesting. i'm sure there's documentation on it.

honest tendon
#

right, makes sense

#

So for pulse function you can ignore brightness

honest tendon
#

alternatively just use brightness since it's a single color pulse

coarse ibex
#

you are correct there is a separate parameter just for brightness.

#

i suppose you could just set the color to 255,0,0 and then put brightness in a for i in range(0.0, 1.0): dot.brightness = i

honest tendon
#

except tha twould loop once right

#

so 0, 100 / 100

coarse ibex
#

if it's a while true loop it should loop infinitely.

honest tendon
#

what are the values of i in your example?

#

isn't it just 0,1

#
        j = 0
        dot[0] = [0, 255, 0]
        for j in range(0, 100):
            jk = j / 100
            dot.brightness = jk

this is causing some crazy flickering ha

#

it's turning off and on on each set.

honest tendon
#
heartbeat_min = 30
while True:
    if mode == MODE_RGB_WHEEL:
        dot[0] = wheel(i)
        # dot.show()
    elif mode == MODE_HEARTBEAT:
        j = 255 - i
        if j < heartbeat_min:
            dot[0] = [0, heartbeat_min, 0]
        else:
            dot[0] = [0, j, 0]

this kinda works, but would be better with the pulse library ๐Ÿ˜„

coarse ibex
#

i loaded up my gemma m0 to help test but it's not recognizing the dotstar library for some reason.

#

what version of circuit python are you using?

honest tendon
#

9

#

You should only need dotstar & pixelbuf

#

my gemma came with cp v5, updated it to v9

coarse ibex
#

do you have a boot_out.txt file? what version date is it?

#

i'm having some weird issues here.

honest tendon
#

Adafruit CircuitPython 9.0.5 on 2024-05-22; Adafruit Gemma M0 with samd21e18
Board ID:gemma_m0
UID:A1B2E6594E34315020312E43112A15FF

coarse ibex
#

yeah the latest is from May and I don't think it's working right. I couldn't get it to work with the dotstar library at all.

honest tendon
#

You tried the latest library right?

coarse ibex
#

this is the simpletest example for the dotstar ```py

SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries

SPDX-License-Identifier: MIT

import time
import random
import board
import adafruit_dotstar as dotstar

On-board DotStar for boards including Gemma, Trinket, and ItsyBitsy

dots = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)

Using a DotStar Digital LED Strip with 30 LEDs connected to hardware SPI

dots = dotstar.DotStar(board.SCK, board.MOSI, 30, brightness=0.2)

Using a DotStar Digital LED Strip with 30 LEDs connected to digital pins

dots = dotstar.DotStar(board.D6, board.D5, 30, brightness=0.2)

HELPERS

a random color 0 -> 192

def random_color():
return random.randrange(0, 7) * 32

MAIN LOOP

n_dots = len(dots)
while True:
# Fill each dot with a random color
for dot in range(n_dots):
dots[dot] = (random_color(), random_color(), random_color())

time.sleep(0.25)
#

yes the mpy and the py bundle neither work for me

honest tendon
#

intresting

#

should work with v9 uf2 & v9 mpy

#

Thanks for trying and helping out. I'm somewhat satisfied with the result ๐Ÿ˜„

#

I might look into the Pulse animation library and see why it's hogging so much memory to light up one pixel

coarse ibex
#

i've brought it up to the devs, someone will look into it. i can't even replicate your setup with the identical board. :/

#

yes it should. what it should do and what it's doing are 2 different things. ๐Ÿ˜ฆ

honest tendon
#

hw is never reproducible

coarse ibex
#

the samd21 is one of the lowest end cpu's. the only thing lower is an arduino uno or there about. there's very little ram so it doesn't take much to hit a memory limit error.

#

i do love the gemma m0's for how small and compact they are though. i have many of them and this is the first time i've ever encountered this type of issue.

honest tendon
#

how would you go about adding BLE to an m0, trying to keep it's form factor small as well

#

alternatively I was looking at an esp32c3 which has ble

coarse ibex
#

it's almost like the UF2 is from a beta state where mpy files weren't accepted and only py libraries were. it's asking for the .py specifically and even when i put it in /lib it still says module not found. it's so weird.

honest tendon
#

ah i think that's a compiliation error

#

i had the error too and it was because i aws mising the pip package

coarse ibex
#

right but why is yours working with the same exact build date and mine isn't. ๐Ÿ˜ฆ

honest tendon
#

I had to install the pip package and it worked

coarse ibex
#

pip? on a microcontroller?

honest tendon
#

No, i was seeing the uC log .py error

coarse ibex
#

i don't use circup i drag and drop

honest tendon
#

so i insatlled it via ide

#

and it worked

#

not entirely sure how i got through it tbh

coarse ibex
#

that's ok, someone will have to look into it. it's a weird issue i've never seen before. usually the build dates are from like last night or today... so seeing it from May might be a clue that the UF2 hasn't been building properly via github actions since May. just a guess.

#

hmm maybe i could try a nightly build but that's not really the point i guess. someone else will run into the same issue so it's best i report it.

honest tendon
#

Makes sense, thanks again!

coarse ibex
#

sorry i couldn't be more help. yeah May was the last stable release it's all beta versions since then.

honest tendon
#

You were helpful enough to get me thinking to write a custom pulse function, and that gets the job done

#

You could run & modify my code on an dotstar I guess, doesn't have to be m0

coarse ibex
#

glad you know enough coding to take it and run with it. good stuff.