ItsyBitsy M4 Trigger Bootloader Mode via USB

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
garberw
 
Posts: 130
Joined: Thu Feb 17, 2022 2:25 pm

ItsyBitsy M4 Trigger Bootloader Mode via USB

Post by garberw »

someone already asked this
viewtopic.php?t=198135
but I could not get it working.
#!/usr/bin/env python
import serial
import sys
def reset_serial_port(fname_port):
with serial.Serial() as fptr:
fptr.baudrate = 1200
fptr.port = fname_port
fptr.open()
fptr.close()
fptr.baudrate = 9600
fptr.open()
for line in fptr:
print(line)

if __name__ == "__main__":
fname_port = sys.argv[1]
reset_serial_port(fname_port)

any help please?
I am trying to capture the output on setup() for arduino for ItsyBitsyM4 in the console without using arduino ide.

User avatar
garberw
 
Posts: 130
Joined: Thu Feb 17, 2022 2:25 pm

Re: ItsyBitsy M4 Trigger Bootloader Mode via USB

Post by garberw »

I tried using
Serial.begin(9600);
while (!Serial);
at the beginning of the setup() function; that works the first time you connect to the serial port from the desktop computer;
$ cat /dev/ttyACM0
shows the boot up and the beginning of the setup function; but the next time you run the cat command it has already booted and has been continuously running; What I am trying to find is a way to trigger the bootloader and call the setup() function by sending a command over the serial port; I read that setting rts and dtr on the serial port for certain arduinos such as the "due" would triger the bootloader but this does not appear to work for the itsy bitsy; is there any way to do this? could I read the serial port from the arduino within the loop() function and if it reads a certain input sequence just call the setup() function or can setup() only be called at boot time? I saw that one sure fire way to do this is to send a signal to the "reset" pin; not sure how to do this; or to use a relay and physically shut the power off to the usb port (power source);

User avatar
garberw
 
Posts: 130
Joined: Thu Feb 17, 2022 2:25 pm

Re: ItsyBitsy M4 Trigger Bootloader Mode via USB

Post by garberw »

I am confused as to what "trigger the bootloader" means. What I am trying to do is to have a predictable way to reset the arduino WHEN NEEDED and capture the output of the setup function, for example by

$ cat /dev/ttyACM0 | tee arduino_output.log

If the first statement in setup() is:

Serial.begin(9600);
while (!Serial);

then you upload you will capture the output of setup
the first time you run the above "cat" command
but it will not go back to setup() again;
if you close the port then the second time you open the port
it does not call setup() again; it will still be running loop();
the Adafruit metro mini and arduino uno would call setup() both times;

Note normally the behavior of "always continuing to run loop() even when serial port is opened and closed repeatedly" is desirable but not when debugging.

You can get what I want by using the "while (!Serial)" statement but it only works for one shot after uploading.

Here is a good video on relay resetting arduions etc.:
https://www.youtube.com/watch?v=hT24hOTrbEI

User avatar
garberw
 
Posts: 130
Joined: Thu Feb 17, 2022 2:25 pm

Re: ItsyBitsy M4 Trigger Bootloader Mode via USB

Post by garberw »

since the itsy bitsy is hooked up to a raspberry pi, the following two python scripts will reset and enter the bootloader respectively. To enter the bootloader pull the reset pin on the arduino to zero twice within 0.5 seconds (start high; low; high; low; high; leave on high). To do a regular reset, just pull the reset pin low for longer than 0.5 seconds then back to high. The point is that this can be done remotely since the raspi has wifi and does not crash so often e.g. if you flash it with a program with an error.
enter-bootloader-g.py
(522 Bytes) Downloaded 3 times
reset-g.py
(427 Bytes) Downloaded 3 times

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

Return to “Itsy Bitsy Boards”