Overwritten sketches

I am new with arduino.
I downloaded sketches, but it turns out there's a bug somewhere. I had chatgpt.com review the sketch, and indeed, there's a bug. Question: If I download this rewritten sketch, will the previous sketch simply be overwritten?
Thanks Rene from Holland

Welcome to the forum

Whenever you upload a sketch to the Arduino it overwrites the one previously written to it

Does that answer your question ?

I am a new user.
I have 12 sketches, do I have to download them one by one?
Thanks rene FROM holland

I have merged your two topics as the both ask the same question in a different way

You can only upload and run one sketch at a time but that single sketch could do multiple things

If the old sketch is overwritten, will the sketch with the error also be gone?

Do you mean from the internet to your computer?

The upload process is as follows

  • The IDE compiles the code
  • If there are no compilation errors reported the code is uploaded to the board, overwriting anything previously uploaded
  • If compilation fails and errors are reported then the code is not uploaded to the board

NOTE that just because the code compiles with no errors and is uploaded it does not mean that it does what you want or expect, just that it is valid code

SUMMARY
If code compiles with no errors then it will be uploaded and will replace any code previously uploaded otherwise it will not be uploaded and the previous code uploaded will remail on the board

If you post a full sketch that you are having problems with, using code tags when you do, we can give you more help

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

It is also helpful to post full error messages in code tags as it makes it easier to scroll through them and copy them for examination

Thanks ..

Unfortunately, I have to check all 12 downloaded sketches because after 5 minutes, the Arduino crashes like crazy. Apparently, there's still a bug somewhere. I'll have them copied one by one.
One more question... does Arduino IDE also work on a Chromebook?

Rene

Why do you have 12 Sketches that does the same thing but only one crashes?

We may be dealing with a terminology confusion.
When you load a sketch onto am Arduino, it's called uploading

When you copy a program from the internet, it's normally called downloading

So which are you talking about, uploading or downloading?

Are these sketches that you have downloaded from somewhere or sketches that you have uploaded to the Arduino after compiling them with no errors ?

Sorry, but I know nothing about Chromebooks but if it helps there is an online Arduino IDE

Uploaden.. from the pc to arduino

Then @UKHeliBob's responses explains what happens.

Hi @rene51 !

It might be a good idea to post

  • further information regarding the (12) sketches you mentioned, e.g. links to the weppage(s) where you found them.
  • which board you use (brand/type?)
  • which IDE Version you use

You should be aware that everytime you upload a sketch to the Arduino all previous code is replaced by the latest upload.

Please post also the sketch where chatGPT identified a bug.
Make sure that you post the sketch inside code-tags, do not use screenshots!
You find those tags in the Editor menu
image

If you press the button <code> you will see two tags recreated by dots. Replace the text between both tags (here: "Paste your code here!") by the sketch:

image

It finally should look similar to this example:

/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://docs.arduino.cc/hardware/

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  https://docs.arduino.cc/built-in-examples/basics/Blink/
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);                      // wait for a second
}

Good luck!
ec2021

Chatgpt does not know how to program. Chatgpt samples internet sketches to create lines of code that look like a sketch. You must know how to program to make corrections to the bad chatgpt lines of code.

To see and work with some good sketches, use your IDE in: FILE >> EXAMPLES >> BUILT-IN EXAMPLES >>

Hi, @rene51
Welcome to the forum.

Please tell us what you project is?
Please post your code?

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

So far you have come to us with a problem and told chatGPT more about your project than the forum.

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

I'll now briefly describe the project. It's a haunted castle where doors open and close, lights flash, turn on and off, clocks chime, a crib moves, books in the bookcase move, and you hear scary sounds and music play. And you see ghosts appear... Photos and sketches will follow. But there's an error somewhere in the sketches...which causes the Arduino to crash, sometimes after 2 minutes, sometimes after 15 minutes...sketches play randomly... Perhaps you can help, because the sketches were written by a friend, who is no longer able to help. RENE

As has previously been pointed out the Arduino can only run one sketch at a time so referring to sketches makes no sense

How many sketches have you got and how are you uploading them

Please post your full sketch(es), using code tags when you do

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

It is also helpful to post full error messages in code tags as it makes it easier to scroll through them and copy them for examination

Hi Rene,

the sad truth is: If you don't post the sketches we will not be able to help you ...

#pragma once

#include "globals.h"
#include "routines.h"

void setup() { /*** INITIALISATIE ***/
/*--------------------------------------------------------------------------------------------*/     
    zolder::dakkapellen::       init_Verlichting      (); // Dakkapel verlichting
/*--------------------------------------------------------------------------------------------*/     
    globals::                   init_Randomizer       (); // Randomize timer
    globals::                   init_Serial           (); // Schakel Seriële poort in
    globals::                   init_I2C              (); // Schakel I2C in
    globals::                   init_LCD              (); // Schakel LCD in
    globals::                   init_Bluetooth        (); // Schakel Bluetooth in
/*--------------------------------------------------------------------------------------------*/     
    Links::                     init_Verlichting      (); // PWM_PCA9685; &0x40 (WIT)
    Links::                     init_Effecten         (); // PWM_PCA9685; &0x50 (WIT)
/*--------------------------------------------------------------------------------------------*/     
    Midden1::                   init_Verlichting      (); // PWM_PCA9685; &0x41 (BLAUW)
    Midden1::                   init_Effecten         (); // PWM_PCA9685 ;&0x51 (BLAUW)
/*--------------------------------------------------------------------------------------------*/     
    Toren::                     init_Verlichting      (); // PWM_PCA9685; &0x42 (ROOD)
    Toren::                     init_Effecten         (); // PWM_PCA9685; &0x52 (ROOD)
/*--------------------------------------------------------------------------------------------*/     
    Midden2::                   init_Verlichting      (); // PWM_PCA9685; &0x43 (GROEN)
    Midden2::                   init_Effecten         (); // PWM_PCA9685; &0x53 (GROEN)
/*--------------------------------------------------------------------------------------------*/     
    Rechts::                    init_Verlichting      (); // PWM_PCA9685; &0x44 (GEEL)
    Rechts::                    init_Effecten         (); // PWM_PCA9685; &0x54 (GEEL)
/*--------------------------------------------------------------------------------------------*/     
    globals::                   init_Relais_5V        (); // Schakel  5 Volt relais in
    globals::                   init_Relais_12V       (); // Schakel 12 Volt relais in
/*--------------------------------------------------------------------------------------------*/     
    globals::                   init_Volume           (); // Audio; Volumeknop
/*--------------------------------------------------------------------------------------------*/     
    globals::                   init_Speaker_Midden1  (); // Audio; Midden1 (Piano)
    globals::                   init_Speaker_Toren    (); // Audio; Toren   (Onweer)
    globals::                   init_Speaker_Midden2  (); // Audio; Midden2 (Badkamer)
/*--------------------------------------------------------------------------------------------*/     
    globals::                   init_Toggle           (); // Audio Status
/*--------------------------------------------------------------------------------------------*/     
} // setup

void loop() { /*** ROUTINES ***/
/*--------------------------------------------------------------------------------------------*/     
    globals::                   GetAudioState         (); // Controleer audio
    globals::                   GetVolumeState        (); // Volumeknop
    globals::                   GetToggleState        (); // Schakelaars
/*--------------------------------------------------------------------------------------------*/
//                                                    ACHTERKANT         BOVEN             BENEDEN     VOORKANT     KLEUR
    routine::                  _Zolder                (); // Zolder      Dakkapellen (Casper)
    routine::                  _Links                 (); // Links       Ouderslaapkamer & Woonkamer   Rechts       (WIT)
    routine::                  _Midden1               (); // Midden_1    Babykamer       & Pianokamer  Midden2      (BLAUW)
    routine::                  _Toren                 (); // Toren       Overloop        & Voyer       Toren        (ROOD)
    routine::                  _Midden2               (); // Midden_2    Badkamer        & Keuken      Midden1      (GROEN) 
    routine::                  _Rechts                (); // Rechts      Kinderkamer     & Kantoor     Links        (GEEL)
} // main loop