Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Itsy Bitsy M0 Express: after upgrade, demo fails
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Itsy Bitsy M0 Express: after upgrade, demo fails

by scruss on Thu Jul 16, 2020 6:59 pm

Just wondering if I'm doing the upgrade process correctly, as I seem to have this problem with a few CiruitPython devices:
  1. Connect Itsy Bitsy M0 Express via USB. CIRCUITPY drive appears, as expected.
  2. Double-click Reset button, and ITSYBOOT drive appears
  3. Drag downloaded CircuitPython 6.0.0-alpha.1 UF2 for the Itsy Bitsy M0 onto the ITSYBOOT window. ITSYBOOT drive is replaced by CIRCUITPY drive, as expected.
  4. Download and extract library bundle adafruit-circuitpython-bundle-6.x-mpy-20200715.zip
  5. Copy across downloaded adafruit_bus_device, adafruit_hid, adafruit_motor and adafruit_waveform folders, and adafruit_dotstar.mpy and neopixel.mpy files into Itsy Bitsy M0 Express's lib folder.
  6. reboot Itsy Bitsy M0 Express.
In Mu's serial monitor, I see the following error when I soft-reboot with Ctrl-D:
Code: Select all | TOGGLE FULL SIZE
File "main.py", line 54, in <module>
TypeError: function takes 2 positional arguments but 1 were given


Here are the CIRCUITPY drive contents:
Code: Select all | TOGGLE FULL SIZE
ls -R


    Directory: D:\


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
da----       2018-01-30     17:29                lib
da----       2018-01-30     17:29                .fseventsd
da----       2018-02-01     22:04                Windows 7 Drivers
-a----       2016-09-01     16:43             98 boot_out.txt
-a----       2017-08-21     14:55              0 .metadata_never_index
-a----       2017-08-21     14:55              0 .Trashes
-a----       2017-10-24     13:26          78444 laugh.wav
-a----       2018-01-30     15:18           3685 main.py
-a----       2018-01-30     15:23           2822 README.txt
-a----       2017-10-24     13:26          96620 rimshot.wav


    Directory: D:\lib


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
da----       2018-01-30     17:29                adafruit_bus_device
da----       2018-01-30     17:29                adafruit_hid
da----       2018-01-30     17:29                adafruit_motor
da----       2018-01-30     17:29                adafruit_waveform
-a----       2020-07-16     18:16           2473 adafruit_dotstar.mpy
-a----       2020-07-16     18:16           1891 neopixel.mpy


    Directory: D:\lib\adafruit_bus_device


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       2020-07-16     18:16           1274 spi_device.mpy
-a----       2020-07-16     18:16              0 __init__.py
-a----       2020-07-16     18:16           2225 i2c_device.mpy


    Directory: D:\lib\adafruit_hid


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       2020-07-16     18:16           2561 gamepad.mpy
-a----       2020-07-16     18:16            441 __init__.mpy
-a----       2020-07-16     18:16            482 consumer_control_code.mpy
-a----       2020-07-16     18:16           1041 consumer_control.mpy
-a----       2020-07-16     18:16           1605 mouse.mpy
-a----       2020-07-16     18:16           1305 keyboard_layout_us.mpy
-a----       2020-07-16     18:16           2176 keycode.mpy
-a----       2020-07-16     18:16           1957 keyboard.mpy


    Directory: D:\lib\adafruit_motor


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       2020-07-16     18:16           2797 servo.mpy
-a----       2020-07-16     18:16              0 __init__.py
-a----       2020-07-16     18:16           1277 motor.mpy
-a----       2020-07-16     18:16           2129 stepper.mpy




Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       2020-07-16     18:16            347 square.mpy
-a----       2020-07-16     18:16              0 __init__.py
-a----       2020-07-16     18:16            426 sine.mpy


    Directory: D:\.fseventsd


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       2017-08-21     14:55              0 no_log


    Directory: D:\Windows 7 Drivers


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       2017-12-29     19:23          13010 adafruit_usbser.cat
-a----       2017-12-09     14:26          10795 Adafruit_usbser.inf

Is there a UF2 that just puts the latest and greatest of everything shipped as stock onto your hardware? That would be ideal, thanks.

scruss
 
Posts: 8
Joined: Thu Jul 05, 2012 10:54 pm

Re: Itsy Bitsy M0 Express: after upgrade, demo fails

by dherrada on Fri Jul 17, 2020 2:29 pm

Can you paste your code.py?

dherrada
 
Posts: 95
Joined: Thu Jan 04, 2018 4:59 pm

Re: Itsy Bitsy M0 Express: after upgrade, demo fails

by scruss on Fri Jul 17, 2020 7:15 pm

ah yes, that might help:
Code: Select all | TOGGLE FULL SIZE
# Itsy Bitsy M0 Express IO demo
# Welcome to CircuitPython 2.2 :)

import board
import gc
import time
from digitalio import DigitalInOut, Direction, Pull
from analogio import AnalogIn
import audioio
import touchio
import pulseio
import neopixel
import adafruit_dotstar
from adafruit_motor import servo

gc.collect()   # make some rooooom
# HID keyboard support
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode

# One pixel connected internally!
dot = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)

# Built in red LED
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

# Analog audio output on A0, using two audio files
audiofiles = ["rimshot.wav", "laugh.wav"]

# Analog input on A1
analog1in = AnalogIn(board.A1)

# Capacitive touch on A2
touch = touchio.TouchIn(board.A2)

# Digital input with pullup on D7, D9, and D10
buttons = []
for p in [board.D7, board.D9, board.D10]:
    button = DigitalInOut(p)
    button.direction = Direction.INPUT
    button.pull = Pull.UP
    buttons.append(button)

# Servo on D12
servo_pwm = pulseio.PWMOut(board.D12, frequency=50)
servo = servo.Servo(servo_pwm)

# NeoPixel strip (of 16 LEDs) connected on D5
NUMPIXELS = 16
neopixels = neopixel.NeoPixel(board.D5, NUMPIXELS, brightness=0.2, auto_write=False)

# Used if we do HID output, see below
kbd = Keyboard()

######################### HELPERS ##############################

# Helper to convert analog input to voltage
def getVoltage(pin):
    return (pin.value * 3.3) / 65536

# Helper to give us a nice color swirl
def wheel(pos):
    # Input a value 0 to 255 to get a color value.
    # The colours are a transition r - g - b - back to r.
    if (pos < 0):
        return [0, 0, 0]
    if (pos > 255):
        return [0, 0, 0]
    if (pos < 85):
        return [int(pos * 3), int(255 - (pos*3)), 0]
    elif (pos < 170):
        pos -= 85
        return [int(255 - pos*3), 0, int(pos*3)]
    else:
        pos -= 170
        return [0, int(pos*3), int(255 - pos*3)]

def play_file(filename):
    print("")
    print("----------------------------------")
    print("playing file "+filename)
    f = open(filename, "rb")
    a = audioio.AudioOut(board.A0, f)
    a.play()
    while a.playing:
        pass
    print("finished")
    print("----------------------------------")
   
######################### MAIN LOOP ##############################

i = 0
while True:
  # spin internal LED around! autoshow is on
  dot[0] = wheel(i & 255)

  # also make the neopixels swirl around
  for p in range(NUMPIXELS):
      idx = int ((p * 256 / NUMPIXELS) + i)
      neopixels[p] = wheel(idx & 255)
  neopixels.show()

  # Read analog voltage on A1
  print("A1: %0.2f" % getVoltage(analog1in), end="\t")

  # use A2 as capacitive touch to turn on internal LED
  print("A2 touch: %d" % touch.raw_value, end="\t")
  if touch.value:
      print("A2 touched!", end ="\t")
  led.value = touch.value

  if not buttons[0].value:
      print("Button D7 pressed!", end ="\t")
      # optional! uncomment below & save to have it sent a keypress
      #kbd.press(Keycode.A)
      #kbd.release_all()

  if not buttons[1].value:
      print("Button D9 pressed!", end ="\t")
      play_file(audiofiles[0])

  if not buttons[2].value:
      print("Button D10 pressed!", end ="\t")
      play_file(audiofiles[1])

  # sweep a servo from 0-180 degrees (map from 0-255)
  servo.angle = i / 255 * 180
 
  i = (i+1) % 256  # run from 0 to 255
  #time.sleep(0.01) # make bigger to slow down

  print("")

I think it's the same as the stock file in the Downloads | Introducing ItsyBitsy M0 Express | Adafruit Learning System

scruss
 
Posts: 8
Joined: Thu Jul 05, 2012 10:54 pm

Re: Itsy Bitsy M0 Express: after upgrade, demo fails

by scruss on Fri Jul 17, 2020 9:30 pm

ah, no matter. Seems that the upgrade doesn't change the main.py file, so it's left incompatible and up to the user to fix. Nice work ...

What you need to do:

Add this line:
Code: Select all | TOGGLE FULL SIZE
import usb_hid


Change the line from:
Code: Select all | TOGGLE FULL SIZE
kbd = Keyboard()

to
Code: Select all | TOGGLE FULL SIZE
kbd = Keyboard(usb_hid.devices)


complete source: https://gist.github.com/scruss/034ba8ba ... 7407ecaffc

scruss
 
Posts: 8
Joined: Thu Jul 05, 2012 10:54 pm

Please be positive and constructive with your questions and comments.