Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

ItsyBitsy nRF52840 user switch and serial REPL
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ItsyBitsy nRF52840 user switch and serial REPL

by nekomatic on Wed Jul 01, 2020 11:36 am

I'm just trying to get started with my ItsyBitsy nRF52840, which I've set up with CircuitPython 5.3.0. To begin with I tried the Dotstar example from the library download:

Code: Select all | TOGGLE FULL SIZE
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)

# 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)

and that works fine - the onboard LED cycles through random colours nicely. Next I wanted to use the onboard user button, which the documentation tells me is D4:

Code: Select all | TOGGLE FULL SIZE
# imports and HELPERS as before

# Read the onboard button
from digitalio import DigitalInOut, Direction, Pull
switch = DigitalInOut(board.D4)
switch.direction = Direction.INPUT
switch.pull = Pull.UP   

# 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())
    while not switch.value:
        time.sleep(0.1) # if button pressed, wait
    time.sleep(0.25)

and that doesn't work - it puts the board into what looks like a continuous reboot/error cycle. If I change D4 to, say, D2 or D7 then it runs fine, but it doesn't read the button. If I add the button code line by line it looks like it's simply the line referring to board.D4 that causes the error.

Meanwhile, I've tried connecting to the REPL using screen as described here - I'm on macOS Catalina - and while I can press Ctrl-C and get a REPL prompt, pressing any key then produces a load of garbage:

Screenshot 2020-07-01 at 15.22.33.png
Screenshot 2020-07-01 at 15.22.33.png (84.99 KiB) Viewed 20 times


Any help with either of these please? I've read the board documentation pages and searched the forum but if the answers are there I didn't see them.

nekomatic
 
Posts: 2
Joined: Wed Jul 01, 2020 11:02 am

Re: ItsyBitsy nRF52840 user switch and serial REPL

by tannewt on Wed Jul 01, 2020 1:12 pm

That is very weird! Please try the latest 5.4.0 beta instead.

There shouldn't be a `board.D4` it looks like it's `board.SWITCH`: https://github.com/adafruit/circuitpyth ... ess/pins.c

I'm on Catalina and have never seen that screen issue.

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

Re: ItsyBitsy nRF52840 user switch and serial REPL

by nekomatic on Sun Jul 05, 2020 5:18 pm

Thanks, that's fixed both issues - SWITCH reads the button and flashing the 5.4.0beta1 firmware seems to get the REPL behaving OK. The BLE keyboard example from here is working nicely too!

nekomatic
 
Posts: 2
Joined: Wed Jul 01, 2020 11:02 am

Re: ItsyBitsy nRF52840 user switch and serial REPL

by tannewt on Mon Jul 06, 2020 1:16 am

Great! Glad it's working.

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

Please be positive and constructive with your questions and comments.