Trinket MO project: Guardian Sword

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
cannonlaw66
 
Posts: 5
Joined: Mon Nov 22, 2021 10:02 pm

Trinket MO project: Guardian Sword

Post by cannonlaw66 »

Hello there, this is my first time posting in the forums, but I am having an issue with using a Trinket MO board to run a string of neopixels.

https://learn.adafruit.com/breath-of-th ... ython-code


I am following this guide, and have followed each step to the best of my knowledge, but when the code is run, the neopixel strip does not light up. I am getting the single green blink on the board itself to say the code has run, but that is all. Same results whether powering over USB or battery with the backpack. At first I thought I had maybe messed up the first board by using a poorly tinned soldering iron and left heat on the board for too long. So to continue troubleshooting I went ahead and ordered a new board and backpack to be sure. Same issue, so I assume that is not it.

Have run the code through Mu onto the board as-is from the guide and Serial is giving me:


Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
main.py output:

Code stopped by auto-reload.
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
main.py output:


Any help you could provide would be greatly appreciated. Thank you.
Attachments
20211123_095656.jpg
20211123_095656.jpg (864.49 KiB) Viewed 525 times

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

Re: Trinket MO project: Guardian Sword

Post by dastels »

Can you post the output when you get into the repl? The CircuitPython build version and board?

Dave

User avatar
cannonlaw66
 
Posts: 5
Joined: Mon Nov 22, 2021 10:02 pm

Re: Trinket MO project: Guardian Sword

Post by cannonlaw66 »

dastels wrote:Can you post the output when you get into the repl? The CircuitPython build version and board?

Dave
Thanks for the response. It appears I am running build version 7 on Trinket MO.

adafruit-circuitpython-trinket_m0-en_US-7.0.0.uf2

Attached is the response I get from the REPL.

In my first comment, I said the green light was flashing once for "code ran". I realized it was running an empty code.py file and not the main.py that the main script is in. The green light is no longer blinking when I save the file.
Attachments
Screenshot 2021-11-23 164724.png
Screenshot 2021-11-23 164724.png (10.1 KiB) Viewed 516 times

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

Re: Trinket MO project: Guardian Sword

Post by dastels »

You can only have one of main.py or code.py. I can never remember the search order it uses, but it takes the first one it finds and ignores the other.

Can you try something simple, maybe blink? It will continuously blink the "13" LED next to the USB connector. Put this in either code.py or main.py (and as I said, get rid of the other).

Code: Select all

import board
import digitalio
import time

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = True
    time.sleep(0.5)
    led.value = False
    time.sleep(0.5)
Dave

User avatar
cannonlaw66
 
Posts: 5
Joined: Mon Nov 22, 2021 10:02 pm

Re: Trinket MO project: Guardian Sword

Post by cannonlaw66 »

Thanks Dave.

Runs blink program as main.py, with code.py removed.

Same output on REPL.

Was also able to run Trinket IO "rainbow" demo than came on the board:

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.2)

# 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
dastels
 
Posts: 15820
Joined: Tue Oct 20, 2015 3:22 pm

Re: Trinket MO project: Guardian Sword

Post by dastels »

So it worked with the connected neopixels? Well, 16 of them?

Dave

User avatar
cannonlaw66
 
Posts: 5
Joined: Mon Nov 22, 2021 10:02 pm

Re: Trinket MO project: Guardian Sword

Post by cannonlaw66 »

Ah, sorry, no it did not.

On the imbedded neopixel on the board, it ran the color wheel, but that was it.

I have a string of 92 neopixels connected to 4, but nothing.

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

Re: Trinket MO project: Guardian Sword

Post by dastels »

OK. It runs, but nothing on the NeoPixels?

Check the voltage on the neopixels to make sure they're getting powered. Make sure that the Trinket is connected to the input end of the strip.

Dave

User avatar
cannonlaw66
 
Posts: 5
Joined: Mon Nov 22, 2021 10:02 pm

Re: Trinket MO project: Guardian Sword

Post by cannonlaw66 »

I'm not sure what you did Dave, but after plugging in the battery and hitting the switch, it's working. Did that 50 times before to no avail, but now it appears to be fine.

Thank you very much for your help. The not-knowing-what-fixed-it will bother me later, but for now I'm just glad it is working in time to finish assembly for my son's birthday.


Thanks again from a fellow Dave, and if I figure out what it was later, I will try to post the solve.

Cheers

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

Re: Trinket MO project: Guardian Sword

Post by dastels »

I'm just that good. ;)

Seriously, though. It could be a loose connection or a sketchy solder joint.

Dave

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

Return to “Trinket ATTiny, Trinket M0”