Reliably kick Arduino Micro to bootloader - arduino

I have a Arduino Micro connected via usb to my pc, showing up as /dev/arduino.
Now when I want to program it (it currently has the default bootloader from Arduino) I have to boot it into the bootloader. AFAIK this can be done by either resetting the chip or talking to it using the baudrate 1200.
For this I have a script like
#!/usr/bin/env python
import serial
s = serial.Serial(
port="/dev/arduino",
baudrate=1200,
bytesize=serial.EIGHTBITS,
stopbits=serial.STOPBITS_ONE,
parity=serial.PARITY_NONE)
s.isOpen()
s.close()
The problem is, that the script as well as the reset pin do not work reliably. Also cutting the power source from the device usually does not kick it into bootloader.
How can I reliably put my Arduino Micro into bootloader? Preferably over USB.

The Python script you posted really should work. You did not say what your evidence is for why it is not working so I can only guess what might be the problem. My guess would be that you need to add a delay after closing the port because it will take some time for the computer to detect the bootloader, enumerate it, and create the serial ports for it. A delay of one or two seconds ought to be enough.
Another guess would be that the code you are running on your Arduino Micro interferes with USB interface. For example, you might have an interrupt service routine that runs for a long time or you might be disabling interrupts in your mainline code for a long time. If you don't let the Arduino's USB interrupts run promptly, they cannot do their job reliably.

the magic isn't within the arduino IDE but instead on the avrdude sequence.
you can install another avrdude on your system, or use the same one which comes with arduino, but you can make a reset simulating a small signature read with avrdude (avrdude -c arduino -p m328p -P com1)...
but to be completely honest, the real trick is on the arduino's reset circuit. the reset pin is connected to serial DTR via a capacitor (and sometimes rts), so each time avrdude switch the serial configuration to program via rs232 it produce a small pulse on DTR (about 50ms it seems) which causes a reset on the microcontroller. i think you can use s.setDTR(True); time.sleep(0.05); s.setDTR(False) to generate a small pulse to reset your arduino within python...
good luck

Related

Is it possible to factory reset an arduino from hardware to remove bad user code?

I was troubleshooting why Serial1 was always throwing undefined errors in sketches I was trying to run when I found a solution posted online for a slightly different board that suggested this line:
HardwareSerial Serial1(2);
I uploaded it and now the Arduino doesn't show up in the IDE, did I remap it's serial communications? Why is this possible!
Is there any hardware factory reset option available on these boards? Did I just brick my device?
edit: It seems the STM32Cube programmer app can be used to communicate with the device but I'm not sure where to get the original firmware to flash. https://imgur.com/a/LbiHenf
Assuming from the tag in your question, I guess you have an STM32 – (BluePill) Development Board (STM32F103C8).
If you think that your board is not handling serial communication properly then you might consider burning bootloader to your board. This will reset the complete configuration of your board.
There are many ways in which you can burn bootloader to your board.
Using another Arduino board like Uno / Nano / Mega
Using an FTDI USB to TTL Serial Adapter.
You might want to go through tutorials list below:
Getting Started with STM32 using Arduino IDE: Blinking LED
Programming STM32F103C8 Board using USB Port

Arduino mega entry point address

I am working on a fresh arduino mega rev3 device.
I want to understand how it works and i need to disassemble flash memory dump.
I have seen that bootloader starts at address 0x3E000
What i want to know now is where does the main program starts in memory.
Thanks
Where the bootloader starts (if it's used) depends on fuse settings. If you have compact bootloader, you can use smaller BOOTSZ. If you're using ICSP header for uploading user program, you don't even need bootloader at all.
Anyway, program starts at 0x0000 on this chip.

Arduino bootloader sequence

I have put together a Bareduino which is an ATmega328 on a breadboard. I have a transceiver chip (MAX233) connected to it and to my serial port adapter on my laptop. I haven't been able to upload any sketches yet. What is the bootloader sequence? Does the Arduiono send out a character first or does the IDE? What is it looking for?
I have a manual reset button. The ATmega328 comes with a bootloader and a program already in it to blink an LED on D13 (chip pin 19). The LED is blinking on and off at one second intervals so it appears to be running. I have ordered an FTDI board, but I scrounged up a MAX233 and thought I would give it a try. Sorry, not a coding question, but I am interested in learning about the bootloader sequence.
On bootlup, the Arduino waits for a signal from the IDE, if it doesn't get one, it runs the local program. Are you getting timeouts? Are you selecting the right com port and board type? depending on the boot loader installed on your chip, try duemilanove or uno. do you have the capacitor for auto reset installed?
see http://www.instructables.com/id/The-Embedded-Arduino-building-an-Arduino-into-a-p/

Leonardo: Gets detected in Device Manager but then gets disconnected

An Arduino Leonardo gets detected in Device Manager, but then it gets disconnected.
So, this is what I am doing. Connecting Arduino Leonardo to my laptop. It gets detected in Device Manager (I have updated the driver as well). However, I soon hear a beep and the Leonardo gets uninstalled. If I push the 'Reset' button it gets detected again. However, after a few seconds it gets disconnected again. The Device Manager displays the message
Currently, this hardware device is not connected to the computer. (Code 45)
Note: It was working fine a couple of weeks ago. I am using Windows 7.
It looks like a problem with the soft-reset of the Arduino Leonardo, normally when you connect the Arduino Leonardo, it appears in Device Manager like Ard...bootloader (COMX), for a few seconds and then the Arduino Leonardo appears on a different COM port.
I know, in your case, after that it just disappears.
Try to select that port in the Arduino IDE, and then you have to try to load some sketch, like blink.ino. Press the reset button at the same time, and then when the sketch is beginning to be uploaded, release the reset button. That works for me.
I had exactly the same problem. After pushing Reset my Arduino Micro first got detected normally. Here's the corresponding excerpt from my /var/log/syslog (without the timestamps, etc.):
usb 6-1: new full-speed USB device number 56 using uhci_hcd
usb 6-1: New USB device found, idVendor=2341, idProduct=0037
usb 6-1: New USB device strings: Mfr=2, Product=1, SerialNumber=0
usb 6-1: Product: Arduino Micro
usb 6-1: Manufacturer: Arduino LLC
cdc_acm 6-1:1.0: ttyACM3: USB ACM device
But only a few seconds later it got disconnected:
usb 6-1: USB disconnect, device number 56
After a long search I found how you can recover from this fatal situation:
Connect your Arduino via a USB cable.
Open the Arduino IDE and load the "Blink" example.
Open a shell and enter: tail -f /var/log/syslog. This is for observing which /dev/tty port the Arduino gets associated with.
Now you must be fast: Reset the Arduino, see what /dev/tty port it gets and choose that port in the IDE under menu Tools → Serial Port. You must do this before the Arduino disconnects again or else the correct menu point won't be accessible. You probably need one or two tries before you get it. That was the hard part.
Press "Reset" again on the Arduino, and immediately after, press the Upload button in the Arduino IDE.
Your Arduino should start the blink program shortly after the Upload and is "healed".
After some more investigation I found the reason for the whole misery: In some forgotten source code of some forgotten file there was a main() function (I had written that one for some tests under Linux/g++ some weeks before). The compiler now preferred to use that main() instead of the standard main() from the IDE environment.
The result is that the USB gets disconnected, probably because the original main() does some initialisation which now was missing.
Make sure that nothing, rather than the USB cable, is connected to the Arduino and try again. If the problem persist, try to replace the cable and test it on a different USB port.
Try also to read the post Windows Not recognizing Uno. If you can see the Arduino in the Device Manager for few seconds, try to reinstall the drivers. The drivers are in the Arduino IDE folder.
You may know about those ICSP "mystery" pins.
Take an Arduino Uno and add the needed "Arduino as Programmer" code to it, wire the Leonardo to the Arduino Uno and now you can program the Leonardo - but you'll nuke the Leonardo's bootloader.
In the IDE, go to "file" and move the mouse to "upload using Arduino as programmer" and have your fun. If you resort to this method, do not buy a LilyPad USB as it has the exact same 32U4 chip like a Leonardo and doesn't have the ICSP pins. That is, unless you can solder the pins into the six holes!

How to send/receive serial communication

How can I send a string via serial communications from Java or Python? I have a very little arduino program that will recieve a CSV string of ints that each control different relays (I adapted it from their example).
I just got an Arduino, and I am trying to use it to open and close a relay remotely. I have it opening and closing the relay, no problem. But I really have no idea where to start as far as using serial communication.
I have a bluetooth dongle that I can connect to, but once I do that I'm lost.
Also, this is my first time using serial communications AND my first time using an Arduino. So I'm sorry if I am completely off on some of the things I am asking. All I know is what I've learned from Google.
Thank you very much
You can use any Java or Python serial port classes and methods. There is however one thing you need to be aware of.
The newer arduino's have a feature known as AutoReset. This works by connecting the DTR signal from the serial port to the Reset line on the chip using a capacitor or such. The IDE uses this to reset the board to activate the bootloader and initiate uploading code to the arduino. The serial monitor in the IDE is aware of this and does not toggle the DTR line when comunicating with the device (except when it initially connects).
There is are several ways to defeat this feature and you can read about them here.
As for actually comunicating with the device, there are several tutorials about serial communication in both Java and Python.
Pyserial includes the option to not use the DTR lines when opening a port.
Here is a website explaining how to use RXTX (a Java library) to comunicate with an Arduino
Best of luck.

Resources