Trinket M0 computer vs powerbank behavior

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mechno
 
Posts: 12
Joined: Wed Apr 11, 2018 4:22 pm

Trinket M0 computer vs powerbank behavior

Post by mechno »

I just got my Trinket M0 yesterday (ORDER #2532518-4434103766) and I noticed a behavior I can’t explain. When connected to my computer (15” retina macbook) the default code loads and does what you’d expect;
  • RGB LED shifts through the color wheel
    Power LED is lit
    other LED activates on capacitive touch detection


However when I connect the Trinket M0 to an external USB power pack, I get
  • RGB LED is lit with purple static color
    power LED is lit
    Capacitive touch triggers no action
It seems like the Trinket is not correctly moving through its boot sequence unless it's connected to a host computer.
Is there some correction that I need to make?
Thanks!

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Trinket M0 computer vs powerbank behavior

Post by mikeysklar »

@mechno,

It sounds like you have some additional hardware connected to your Trinket with the captouch and colorwheel. Can you post a photo of what all is connected?

Do you think it might be a current limitation with the USB power pack? Smaller units are limited to 700mA which could be an issue if you are running a dozen or more NeoPixels.

User avatar
mechno
 
Posts: 12
Joined: Wed Apr 11, 2018 4:22 pm

Re: Trinket M0 computer vs powerbank behavior

Post by mechno »

Thanks for the reply!
This is a stock Trinket M0 with unmodified demo code. My comment "shifts through the color wheel" might have been unclear. I meant to say that the on-board RGB LED changes colors.
This behavior does not seem to be current availability related; I've yet to find any power source that has the default code run on boot.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Trinket M0 computer vs powerbank behavior

Post by mikeysklar »

@mechno,

This sounds as though the example code is running correctly when plugged into a non-host USB source. The internal code is not running when plugged into your host power source. We provide some example code that I believe is loaded on the stock Trinket M0 that drives the DotStar:

https://learn.adafruit.com/adafruit-tri ... al-rgb-led

Code: Select all

"""CircuitPython Essentials Internal RGB LED red, green, blue example"""
import time
import board

# For Trinket M0, Gemma M0, ItsyBitsy M0 Express, and ItsyBitsy M4 Express
import adafruit_dotstar
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
# For Feather M0 Express, Metro M0 Express, Metro M4 Express, Circuit Playground Express, QT Py M0
# import neopixel
# led = neopixel.NeoPixel(board.NEOPIXEL, 1)

led.brightness = 0.3

while True:
    led[0] = (255, 0, 0)
    time.sleep(0.5)
    led[0] = (0, 255, 0)
    time.sleep(0.5)
    led[0] = (0, 0, 255)
    time.sleep(0.5)


User avatar
mechno
 
Posts: 12
Joined: Wed Apr 11, 2018 4:22 pm

Re: Trinket M0 computer vs powerbank behavior

Post by mechno »

Thank you for your reply. I'm, unfortunately, still confused...
What I've noticed is that the "main.py" file will be processed if the Trinket M0 is connected to a data usb port (is this what you meant by "is in host mode"?) but in any situation where the Trinket M0 is getting power only, the code does not execute.

If I insert the USB connector into my mac or pc slowly so that the Trinket M0's power pins make a connection before its data pins, it does not run main.py. If i insert it normally, it does run.

The code that was included follows.

Code: Select all

# Trinket IO demo
# Welcome to CircuitPython 3.1.1 :)

import board
from digitalio import DigitalInOut, Direction, Pull
from analogio import AnalogOut, AnalogIn
import touchio
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
import adafruit_dotstar as dotstar
import time
import neopixel

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

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

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

# Analog output on D1
aout = AnalogOut(board.D1)

# Digital input with pullup on D2
button = DigitalInOut(board.D2)
button.direction = Direction.INPUT
button.pull = Pull.UP

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

# NeoPixel strip (of 16 LEDs) connected on D4
NUMPIXELS = 16
neopixels = neopixel.NeoPixel(board.D4, 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))

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

  # set analog output to 0-3.3V (0-65535 in increments)
  aout.value = i * 256

  # Read analog voltage on D0
  print("D0: %0.2f" % getVoltage(analog1in))

  # use D3 as capacitive touch to turn on internal LED
  if touch.value:
      print("D3 touched!")
  led.value = touch.value

  if not button.value:
      print("Button on D2 pressed!")
      # optional! uncomment below & save to have it sent a keypress
      #kbd.press(Keycode.A)
      #kbd.release_all()

  i = (i+1) % 256  # run from 0 to 255
  #time.sleep(0.01) # make bigger to slow down

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Trinket M0 computer vs powerbank behavior

Post by mikeysklar »

It sounds like this Trinket M0 might have shipped with an older release of CircuitPython and Bootloader. Can you upgrade both of those to current releases as there is nothing in the default code you provided that would prevent USB power from running main.py.

; CircuitPython 6.2.0
; Bootloader v3.13.0
https://circuitpython.org/board/trinket_m0/

User avatar
mechno
 
Posts: 12
Joined: Wed Apr 11, 2018 4:22 pm

Re: Trinket M0 computer vs powerbank behavior

Post by mechno »

Thank you! I'll update the bootloader tonight and report back in!

User avatar
mechno
 
Posts: 12
Joined: Wed Apr 11, 2018 4:22 pm

Re: Trinket M0 computer vs powerbank behavior

Post by mechno »

OK! I think that I figured out what was wrong!
Forgive me for being so bold, but I believe that there's a fault in the sample code that is included.

Code: Select all

# Used if we do HID output, see below
kbd = Keyboard()
Commenting out the "kbd = Keyboard()" line, the Trinket M0 runs its demo script just fine!

User avatar
venarez
 
Posts: 3
Joined: Mon May 03, 2021 12:45 pm

Re: Trinket M0 computer vs powerbank behavior

Post by venarez »

mechno wrote:OK! I think that I figured out what was wrong!
Forgive me for being so bold, but I believe that there's a fault in the sample code that is included.

Code: Select all

# Used if we do HID output, see below
kbd = Keyboard()
Commenting out the "kbd = Keyboard()" line, the Trinket M0 runs its demo script just fine!
Thank you, I was having the same issue, commented out the kbd row and now it cycles through as expected when plugged into external power. So weird how that's causing the issue, wonder if it's a conflict somewhere?

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”