buzzing mindfulness bracelet code plus some new functions

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
bozzaglia
 
Posts: 90
Joined: Mon Aug 01, 2022 6:14 am

Re: buzzing mindfulness bracelet code plus some new functions

Post by bozzaglia »

Here is a snapshot. Sorry I didn’t try it earlier
Attachments
1E449521-0ABC-4840-82D6-4C0A5A22896E.jpeg
1E449521-0ABC-4840-82D6-4C0A5A22896E.jpeg (718.98 KiB) Viewed 101 times

User avatar
dastels
 
Posts: 11053
Joined: Tue Oct 20, 2015 3:22 pm

Re: buzzing mindfulness bracelet code plus some new functions

Post by dastels »

OK. You need to put the debouncer module in your CIRCUITPY/lib directory. You'll find it in the bundle: adafruit_debouncer.mpy.

Dave

User avatar
bozzaglia
 
Posts: 90
Joined: Mon Aug 01, 2022 6:14 am

Re: buzzing mindfulness bracelet code plus some new functions

Post by bozzaglia »

Ok! I’m looking for the bundle you pointed on your website but I am having a hard time finding it. Could you please send the link?

User avatar
bozzaglia
 
Posts: 90
Joined: Mon Aug 01, 2022 6:14 am

Re: buzzing mindfulness bracelet code plus some new functions

Post by bozzaglia »

I think I got it here:
https://github.com/adafruit/Adafruit_Ci ... g/20220817
I downloaded the circuitpython 7.x bundle at this link and found the file in the lib directory.
Do I have the right one?

User avatar
bozzaglia
 
Posts: 90
Joined: Mon Aug 01, 2022 6:14 am

Re: buzzing mindfulness bracelet code plus some new functions

Post by bozzaglia »

ok, I got this message on the REPL
Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info. I'm going to look at the link

User avatar
dastels
 
Posts: 11053
Joined: Tue Oct 20, 2015 3:22 pm

Re: buzzing mindfulness bracelet code plus some new functions

Post by dastels »

Grab the bundle from here: https://circuitpython.org/libraries. You want the one that matches the version of CircuitPython you are using: 7.x or 8.x.

It sounds like you have a mismatch between CP and the library bundle. It's all covered at https://learn.adafruit.com/welcome-to-circuitpython.

Dave

User avatar
bozzaglia
 
Posts: 90
Joined: Mon Aug 01, 2022 6:14 am

Re: buzzing mindfulness bracelet code plus some new functions

Post by bozzaglia »

I tried downloading the 8.x version, since the 7.x was apparently incompatible. The bundle name is "adafruit-circuitpython-bundle-8.x-mpy-20220817.zip".
I pasted the adafruit_debouncer.mpy file in the lib folder. Got the same incompatible message in the REPL. And now the gemma led cycles solid red - solid green - blinking green.
I attach the screenshot of my CIRCUITPY/lib folder
Attachments
screenshot.png
screenshot.png (25.08 KiB) Viewed 87 times

User avatar
bozzaglia
 
Posts: 90
Joined: Mon Aug 01, 2022 6:14 am

Re: buzzing mindfulness bracelet code plus some new functions

Post by bozzaglia »

I started reading at the link but didn’t find a way to understand what version of circuit python is on my board.

User avatar
dastels
 
Posts: 11053
Joined: Tue Oct 20, 2015 3:22 pm

Re: buzzing mindfulness bracelet code plus some new functions

Post by dastels »

If you connect to the REPL and CTRL-C to break out of the program it will tell you what version is running.

Or you could put a known version of CircuitPython onto the board. See https://learn.adafruit.com/welcome-to-c ... cuitpython.

If you are running some 7.whatever.whatever version of CircuitPython, you MUST ,use a version 7 library bundle. I suggest using the latest version 7 of CircuitPython from https://circuitpython.org/board/gemma_m0/ and the library bundle from https://circuitpython.org/libraries. Copy just what you need from the bundle's lib directory to CIRCUITPY/lib.

I suggest you delete everything from CIRCUITPY/lib, empty trash, and tyhen copy over what you need.

Dave

User avatar
bozzaglia
 
Posts: 90
Joined: Mon Aug 01, 2022 6:14 am

Re: buzzing mindfulness bracelet code plus some new functions

Post by bozzaglia »

OK! I did everything you suggested:
  • installed the most recent 7.x Circuitpython (did all the "Gemmaboot" process as described). The version previously on the board was 5.0.0.
  • Downloaded the 7.x bundle at the link you sent me.
  • Wiped the CIRCUITPY/lib folder (it contained a folder named "adafruit_hid" and two files: "adafruit_dotstar.mpy" and "neopixel.mpy"
  • Emptied trash
  • Pasted in the CIRCUIPY/lib folder the same folder and files from the 7.x bundle.
  • Pasted the adafruit_debouncer.mpy file from the 7.x bundle
  • Pasted again the file BOOT.PY in the CIRCUITPY directory (took it from the downloaded folder "circuitpython_logger_boot / 7.x)
  • I also made sure that my button works by running a simple plotting code
After I did this I saved the CODE.PY file and got an error message in the REPL with the following:

File "code.py", line 5, in <module>
File "adafruit_debouncer.py", line 32, in <module>
ImportError: no module named 'adafruit_ticks'

So I found a file named "adafruit_ticks.mpy" in the 7.x bundle and pasted it in the CIRCUITPY/lib folder (NOTE: that file wasn't there before!)

I reloaded the code and the REPL this time didn't write anything at all. I did it twice to make sure.

The board led blinked a couple of times (don't remember the color) and then the led switched off and remained off. After some 10-15 minutes the buzzer went off once and right away the led turned to flashing red and nothing else happened.

Did I do something wrong? Help :-O

User avatar
dastels
 
Posts: 11053
Joined: Tue Oct 20, 2015 3:22 pm

Re: buzzing mindfulness bracelet code plus some new functions

Post by dastels »

And nothing was output on the REPL?

Dave

User avatar
bozzaglia
 
Posts: 90
Joined: Mon Aug 01, 2022 6:14 am

Re: buzzing mindfulness bracelet code plus some new functions

Post by bozzaglia »

I just tried it again (erased the code I used to test the button and saved my code) and got this on the REPL (I translated from italian):

Code stopped by auto-reload. Reloading soon.
soft reboot
code.py output:
Traceback (most recent call last):
File "code.py", line 28, in <module>
AttributeError: object 'DigitalInOut' doesn't have the attribute 'fell'

It never gave this message before... Could I have lost some pieces of code in the cut and paste process? I checked and doesn't seem so...

User avatar
dastels
 
Posts: 11053
Joined: Tue Oct 20, 2015 3:22 pm

Re: buzzing mindfulness bracelet code plus some new functions

Post by dastels »

OK. The Debouncer has the fell property, not the DigitalInOut.

Please post your current code.

Dave

User avatar
bozzaglia
 
Posts: 90
Joined: Mon Aug 01, 2022 6:14 am

Re: buzzing mindfulness bracelet code plus some new functions

Post by bozzaglia »

Here it is... now when I save it the REPL prints just this:

Code stopped by auto-reload. Reloading soon.
soft reboot
L'auto-reload è attivo. Salva i file su USB per eseguirli o entra nel REPL per disabilitarlo.
code.py output:


And the led on the gemma goes off and stays like that...


Code: Select all

import time
import board
import random
from digitalio import DigitalInOut, Direction, Pull
from adafruit_debouncer import Button

pulsante = DigitalInOut(board.D2)
pulsante.direction = Direction.INPUT
pulsante.pull = Pull.UP
vibrating_disc = DigitalInOut(board.D1)
vibrating_disc.direction = Direction.OUTPUT
switch = Button(pulsante)

on_time = 4     # Vibration motor run time, in seconds
interval = random.randint(1, 1800)
delta = (1800 - interval)

start_time = time.monotonic()  
while True:
    switch.update()
    timer = time.monotonic() - start_time  # timer è t tra start_time e time.monotonic

    if timer >= interval and timer <= (interval + on_time):  # avvia il motore
        vibrating_disc.value = True

    elif timer >= (interval + on_time) and timer <= (interval + on_time + delta):
        vibrating_disc.value = False
        if pulsante.fell:
            file1 = open("mindfulness_log.txt", "a")
            file1.writelines("interval, ok")
            file1.close()
        elif pulsante.short_count == 2:
            file1 = open("mindfulness_log.txt", "a")
            file1.writelines("interval, no")
            file1.close()

    elif timer > (interval + on_time + delta):
        start_time = time.monotonic()  
        interval = random.randint(1, 1800)  
        delta = (1800 - interval)

User avatar
bozzaglia
 
Posts: 90
Joined: Mon Aug 01, 2022 6:14 am

Re: buzzing mindfulness bracelet code plus some new functions

Post by bozzaglia »

After a little while the buzzer goes off (like it would normally do with the random buzzing) and the led starts blinking red.

The REPL prints
Traceback (chiamata più recente per ultima):
File "code.py", riga 28, in <module>
AttributeError: l'oggetto 'DigitalInOut' non ha l'attributo 'fell'
Caricamento codice pronto.
Press any key to enter the REPL. Use CTRL-D to reload.


I push the button (which should create the file "mindfulness_log" and start appending my feedback, and nothing happens on the CIRCUITPY drive

BTW if I check the code on MU I get the green thumbs up

Post Reply
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”