0

Disable USB connection in boot.py for Trinket M0
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Disable USB connection in boot.py for Trinket M0

by dbayrock on Wed Feb 13, 2019 12:58 am

Hi there!

Short story. My application with the Trinket M0 is to simulate a F1 keypress as a USB Keyboard when the computer it is attached to hangs at boot (just after BIOS and before loading any OS) waiting for the user to press F1.

OK. Enclosed is my Fritzing file, boot.py, code.py, and output from boot.out.txt

boot.py
Code: Select all | TOGGLE FULL SIZE
import board
from digitalio import DigitalInOut, Direction, Pull
switch = DigitalInOut(board.D2)
switch.direction = Direction.INPUT
switch.pull = Pull.UP


code.py
Code: Select all | TOGGLE FULL SIZE
# CircuitPython IO demo #1 - General Purpose I/O
import time
import board
from digitalio import DigitalInOut, Direction, Pull

from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode

# Set the Red onboard LED as an indicator
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

#Set Keyboard
kbd = Keyboard()
layout = KeyboardLayoutUS(kbd)


# For Gemma M0, Trinket M0, Metro M0 Express, ItsyBitsy M0 Express, Itsy M4 Express
switch = DigitalInOut(board.D2)
# switch = DigitalInOut(board.D5) # For Feather M0 Express, Feather M4 Express
# switch = DigitalInOut(board.D7) # For Circuit Playground Express

switch.direction = Direction.INPUT
switch.pull = Pull.UP

while True:
    # We could also do "led.value = not switch.value"!
    if switch.value:
        led.value = False
    else:
        led.value = True
       
        # Wite USB Keyboard
        # Type 'abc' followed by Enter (a newline).
        #layout.write('abc\n')
        #layout.write(4)
        #kbd.send(Keycode.F)
       
    time.sleep(0.1) # debounce delay


boot_out.txt
Code: Select all | TOGGLE FULL SIZE
Adafruit CircuitPython 3.1.2 on 2019-01-07; Adafruit Trinket M0 with samd21e18
boot.py output:



So my thinking is that I can use the MOBO's internal +5V SPKR connection "beep" at BIOS boot to send a signal via the LN35 to the Trinket to start a timer and eventually press F1 after x seconds.

On my Fritzing, I just have the USB connection as the +5V signal for the time being.

So I set Trinket M0 Pin 2 high and connecting to ground thru Pin 5 and 6 on the LN35 works. For now I have coded the RED LED in code.py on the M0 to turn on when the circuit completes (just an indicator).

Everything with hardware works and I smell no burning silicon :>>>

Now the problem.

1. If the computer is fully booted into the OS and I reset the M0, all is well and the LED turns on. Disconnecting/Reconnecting +5V to Pin 1 on LN35 works as expected.

2. If I disconnect the M0, poweroff the computer, and reconnect the M0, the LED does not turn on. If I then reset the trinket, the LED still does not come on. I would expect that the LED would be on at any time that the USB (power) is connected but this is not the case.

Looking thru the forums thoroughly, the M0 manual, and CircuitPython docs, I am thinking it has something to do with how the M0 senses an active USB connection on bootup and not just power. But this is where I get lost.

So is there a way for boot.py to disable USB check/reset that comes after boot.py? What am I missing?

Sincerely,

Dennis
Attachments
Untitled Sketch 2_bb.png
Untitled Sketch 2_bb.png (235.61 KiB) Viewed 43 times

dbayrock
 
Posts: 7
Joined: Mon Feb 27, 2017 1:08 pm

Please be positive and constructive with your questions and comments.