Erase and reset my arduino - arduino

By some reason, I wrote the code below and upload it into my arduino, and obviously, I forget a delay function in loop method.
So, every time I pin the arduino into my computer, the simulated keyboard is always input something and can not stop.
I want to erase or reset my arduino, but how can I work it?
Type of board is Leonardo Micro Mini.
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
Keyboard.print("Hello.");
}

I think the problem here is that it's difficult for you to upload, for instance, the BareMinimum example because of the Arduino printing "Hello." on your keyboard.
Is this right? If so, I see three possible solutions.
unplug the arduino, load the BareMinimum example, push the "Load" button and, when the compilation starts, plug the arduino back. It should start printing "Hello" but, in the end, it should load the sketch on the leonardo.
keep the reset button pressed; hit the load button in the IDE, then, as soon as the IDE says "loading" (after the compilation) release the switch. An alternative is to just press the reset button at the right moment, but I think that keeping it pressed is less annoying
use a programmer (or even another arduino - google for Arduino as ISP for more infos) to load the bootloader again on the leonardo
Bye

Related

how can I send signal to computer

greetings to each of you. I need your help. I am working on a project. I need that when a > is greater than 5, the arduino sends a signal to the computer and starts playing the video on the computer. my computer operation system is Windows11. I want play video on windows media player or anything. everytime my computer is open and video on media player ready to play. I don't know how to do it. first I connected the servo motor, the servo motor rotated 70 degrees and hit the computer's "space" key. now I want to develop it further. When it enters the "if" period, it will send a signal and start playing the video automatically.
You don't need to think so complicated. With Java, C# or Python, you can code scripts where you can read values and take actions over the serial port. For Arduino side use Serial.begin(9600); in the setup() and write your code in loop as:
while (a > 5 )
{
Serial.println(1);
}
While your a greater than 5 we send 1 value to serial port. Now I will continue to explain over python.
import serial
ser = serial.Serial('COM5')
ser.flushInput()
while True:
try:
ser_bytes = ser.readline()
decoded_bytes = float(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
print(decoded_bytes)
except:
print("Keyboard Interrupt")
break
You do your test and write your code in try section.

Is there a way to rescue my processor from a reset deadlock

I have a board with an XMC1400 MCU on it. It is a custom board with LEDs and buttons and so on.
So I accidentally add a '''XMC_SCU_RESET_AssertMasterReset()''' line at the beginning of the code... This function cause xmc to reset but it doesn't just reset the program counter, it also clears everything and ends the debug connection. And since it happens so quickly I cannot reconnect before it resets again. For the one who doesn't know, when you load a program to the xmc, it gets written to the flash, and once it's loaded it will always run with power up.
I know in some boards there are some pins used to clear to board when shorted but there is no such a thing in this one.
There are however several bootstrap loaders(can and uart). But they are disabled by a flash parameter called BMI. I don't have much hope but is there a way to rescue this processor?
Thanks!

Run non blocking steppers with serial communication on arduino

I want to drive up to 10 stepper motors at the same. All with a constant but individual speed. Meanwhile other calculations and data transfer is to be done.
All Steppers have their own driver with dir/step pin. I use AccelStepper for non blocking functions to run the steppers. It is very important that the steppers run as smooth as possible.
First I simply put the runSpeed function for every stepper in the main loop, resulting in stuttering when data was written to the serial by the arduino. I now use Timer5 of the Mega to run a function that does nothing but call all runSpeed functions every 200 µs or so. This works very good with the steppers and the rest of the code except for the serial communication. I want to send commands to the arduino but with the interrupt being active some bytes never reach the arduino. Right now I am sending a notification byte that data will be transfered, the arduino answers and stops the interrupt, receives the command and starts the interrupt again. Works like a charm except for the 0.5 s stepper pause inbetween. This is to be solved.
Now I thought about the following:
1. Making the interrupt adoptable. Means: Track alls steps on every motor and calculate when a motor has to do the next step. Make the timer interrupt at exactly that time. Of course the interrupt has to be adjusted after every step of any motor. My fear is that the time demand for the calculations would be quite high, if not too high, so that the arduino gets stuck in interrupts and does not execute other code anymore.
2. Using a second arduino which only runs the steppers in the loop so the timing is no problem and serial data can be received. However, if I want that arduino to confirm the new settings to the main arduino, then I will get short pauses again... Solution would be to switch to interrupts when sending data, else use the main loop (sending data with interrupt works, receiving has the issue).
This is my idea of how to do it. But before I put all the effort in it, I wanted to discuss this with you and ask you, if you have another, better solution that for me.
I attached an exemplary code which with which the arduino cannot receive longer texts without missing bytes.
#include "AccelStepper.h"
#include "TimerFive.h"
AccelStepper m1(AccelStepper::DRIVER, 24, 25);
AccelStepper m2(AccelStepper::DRIVER, 26, 27);
AccelStepper m3(AccelStepper::DRIVER, 28, 29);
void setup() {
m1.setMaxSpeed(1000);
m2.setMaxSpeed(1000);
m3.setMaxSpeed(1000);
m1.setSpeed(50);
m2.setSpeed(70);
m3.setSpeed(90);
Timer5.initialize(250);
Timer5.attachInterrupt(run);
}
void run() {
m1.runSpeed();
m2.runSpeed();
m3.runSpeed();
}
void loop() {} {
//some calculations...
if (Serial.available() > 0) Serial.println(Serial.readString());
delay(1000);
}

Tone is not playing on Arduino Uno

I am trying to make a bot that follows a line with IR sensors and I also have a IR sensor to prevent collisions. In the if statement that stops movement, I also have it play a tone, but the problem is the tone doesn't play. I know that the if statement is being executed as the servos do stop as intended and resume after the object is removed. Also the speaker setup is confirmed working as other code with tones are working fine. I did hear it beep a few times when I was troubleshooting which is strange.
Here is the statement with the issue;
if (irDetect == 0) // Object detected
{
servoLeft.writeMicroseconds(1500); // Stop left servo
servoRight.writeMicroseconds(1500); // Stop right servo
tone(5, 4000, 100);
delay(100);
}
I cannot figure out the problem so any help is appreciated.
Tone and the ir library you are using are both using timer2. So you have a timer conflict. Both can't simultaneously have control over timer2. You'll either need to find a new library for one function or the other or modify one to use a different timer.

Display time with push button interrupt Arduino

I need to write a code that contains an interval loop but contains a push button interrupt that displays RTC values when activated. I have found a way to individually do each task i.e change pushbutton state, loop in intervals, display RTC value but I cannot seem to combine them and create a working. If someone can provide links or an explanation on how to accomplish this I would be so grateful.
If you do not use delay(interval); in your main loop, you can run as many tasks in parallel as you want. Understand the BlinkWithoutDelay sample, and try to extend it to two leds blinking independently. Or read a button while blinking.
And push button and interrupt does not go together well, BTW.
You even might add a small delay(2); to slow down polling the button pin.
This is usually fine for the other parallel running tasks and implements a very simple debounce mechanism.

Resources