I have a program that run well the first time but when I upload it again the port is not found. So I start the bootloader (double click in reset button) and the program upload without problem but when I tried to upload again the same failure.
This is the ouput screen with the error:
Sketch uses 33404 bytes (12%) of program storage space. Maximum is 262144 bytes.
Global variables use 3372 bytes (10%) of dynamic memory, leaving 29396 bytes for local variables. Maximum is 32768 bytes.
Performing 1200-bps touch reset on serial port COM5
Waiting for upload port...
No upload port found, using COM5 as fallback
No device found on COM5
"..\packages\arduino\tools\bossac\1.7.0-arduino3/bossac.exe" -i -d --port=COM5 -U true -i -e -w -v "…Local\arduino\sketches\01C13766CA96C28CD895C9FD76BD10C6/Watering_System_V1_0_PRUEBA.ino.bin" -R
Failed uploading: uploading error: exit status 1
Does the same problem happen when you use a simple sketch like blink? After a successful upload of blink you should be able to upload the blink sketch numerous times without problems without double tap.
If you can upload blink a number of times without double tap of the reset, your problem is caused by your sketch.
They should not. Note that the "Blink" sketch also contains delays.
If you post your full sketch, the forum helpers can take a look and see if we can spot anything that might cause the problem.
I'll provide instructions you can follow to do that:
Select Tools > Auto Format from the Arduino IDE menus. ⓘ This is done to make the code easier for us to read.
Select Edit > Copy for Forum (Markdown) from the Arduino IDE menus.
Open a reply here on this forum topic by clicking the "Reply" button.
Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
This will paste the sketch to the post composer.
Move the cursor outside of the code block markup before you add any additional text to your reply.
Repeat the above process if your sketch has multiple tabs.
Click the "Reply" button to publish the post.
When your code requires a library that's not included with the Arduino IDE please post a link to where you downloaded that library from, or if you installed it using Library Manager then say so and state the full name of the library.
Part of the code that you upload is the core. One of the functionalities provided by that is the reaction on the software reset issued by the IDE (the 1200-bps touch) and the USB detection when you connect the board.
One of the reasons why those functionalities can fail is that your sketch manages to overwrite variables used by these functionalities. As a result those functionalities break. A common reason is writing outside boundaries of an array, there might be others.
Another reason can be a long-running interrupt routine preventing USB interrupt functionality from being honoured.
PS
I'm not familiar with your board but familiar with 32U4 based boards where the same issue can happen.
This is the code what it does is : check the soil humidity and if its lower than threshold start a water pump and check again if the umidity it’s ok stop if not try three times to reach the value.
This is the code:
#define DEBUG true
#define HUM_SENSOR A0
#define PUMP_PIN 1
#define TIME_WATERING 5 * 1000 // Initial WATERING TIME
#define THRESHOLD_HUM 50 //bellow this value start watering
#define TIME_CHECK_HUMIDITY 5 * 1000 // minutes to check humidity after watering
bool watering_active = false;
int time_activated;
int start_time = 0;
bool start_Watering = false;
//To control watering proccess
float factor = 0;
int pass = 0;
// Define the interval in milliseconds (7 days)
//const unsigned long weekInterval = 7UL * 24UL * 60UL * 60UL * 1000UL;
const unsigned long weekInterval = 5UL * 60UL * 1000UL;
// Use unsigned long to store the last time the sensor was checked.
// Initialized to 0 to make sure it runs the check on the first loop.
unsigned long lastCheckMillis = 0;
void setup() {
// put your setup code here, to run once:
pinMode(HUM_SENSOR, INPUT);
pinMode(PUMP_PIN, OUTPUT);
digitalWrite(PUMP_PIN, LOW);
Serial.begin(9600);
while (!Serial);
start_Watering = true;
//clearSerial();
}
void watering(float factor) {
unsigned long currentMillis = millis();
unsigned long start = currentMillis;
Serial.println("Maximum Pumping: " + String(TIME_WATERING * factor));
digitalWrite(PUMP_PIN, HIGH);
//while ((currentMillis - start) < TIME_WATERING * factor) {
// currentMillis = millis();
//}
delay(TIME_WATERING * factor);
digitalWrite(PUMP_PIN, LOW);
Serial.println("Time pumping: " + String((millis() - start)));
return;
}
void clearSerial() {
for (int i = 0; i < 50; i++) {
Serial.println();
}
}
void loop() {
// put your main code here, to run repeatedly:
// Get the current time
unsigned long currentMillis = millis();
int sample = analogRead(HUM_SENSOR);
int humidity = map(sample, 245, 700, 100, 0);
Serial.println("Humidity %: " + String(humidity) + " ----- Start_watering: " + String(start_Watering));
if (start_Watering) {
if (humidity < THRESHOLD_HUM) {
factor = (1 - pass * .25);
pass++;
Serial.println("Start Watering . . . Pass: " + String(pass));
watering(factor);
Serial.println("Watering Finish . . . Humidity %: " + String(humidity));
if (pass > 4 || humidity >= THRESHOLD_HUM) {
pass = 0;
start_Watering = false;
}
//Wait to Stabilize the humidity and check again
delay(TIME_CHECK_HUMIDITY);
lastCheckMillis = millis();
}
}
Serial.println("Time:" + String((currentMillis - lastCheckMillis) / 1000));
// Check if the interval has passed since the last check
if (currentMillis - lastCheckMillis >= weekInterval) {
// Save the current time as the last check time
lastCheckMillis = currentMillis;
start_Watering = true;
Serial.println("Restart . . .");
}
}
I don't see anything problematic in that code, and it doesn't cause any problem when I run it on my MKR WiFi 1010 board.
Does the problem still occur if you disconnect all external circuitry from the MKR WiFi 1010 board and run the sketch on just the board by itself? I'm thinking that the pump might be subjecting the board to electrical conditions outside its rated capabilities, and thus putting the board into a non-functional state. Although less likely, this could also be caused by the sensor connected to the board.
You are Right. Problem was the circuitry connected to MKR1010. Without it works prefect. I have to check the relay module that I bought to control the pump.
You are welcome. Identifying the cause of the problem is great progress towards a solution!
If you aren't able to determine exactly what it is about the external circuitry that is causing the problem, you are welcome to share details about the circuit here on Arduino Forum. The forum helpers may be able to identify the problem with the circuit and suggest how to solve it.
Here is a image of the circuit I used with the MKR. I found that something was wrong with this because when I connected it to MKR the LOW signal in any pin was around 1V but when I disconnected it everything was ok. FInally after several trys I bricked the MKR and now is like in bootloader (slow blinking led) but the PC doesn’t reconigze the port!!