Arduino sketch just vanished.

I'm not sure this counts as a question, as I don't think there's a solution to it. Might count as a rant, but definitely should be considered a warning. Maybe the moral is "keep your software updated."

This issue took place in the IDE version 1.6.12. The Arduino in question probably doesn't matter, as I think this is a software / OS issue, but for the record, this is the Vilros kit (an UNO coupled to a small breadboard). Because I'm currently on a slow Internet connection, the past couple times I've opened the IDE I've disregarded the "there is a new version available" message. I'm simply not in a position to upgrade until the bandwidth-throttling is relaxed in a few days.

The project I'm working on is intended to suss out issues I've had using an AD5220 digital potentiometer to "turn up" / "turn down" the frequency of a digital clock used to generate CLK signals for various digital projects. The details probably aren't important, but the gist of it is that I used two momentary pushbutton controls (like large tact switches, included with the Vilros kit) to bring two I / O pins, normally pulled up, LOW. On each iteration of the main loop, the Arduino checks each pin, and if either is has been grounded by its button, the controller generates a pulse to send to the CLK pin of the dpot; also, depending on which pin is LOW, it sends the appropriate SEL signal to tell the dpot which way to "turn." I have a simple LED / series resistor combo tied to the "wiper" pin of the dpot to serve as an indicator of whether the dpot is working correctly. The LED starts of at "mid" brightness, and depending on which button I press, should gradually brighten or dim accordingly.

The "turn up" functionality worked as expected, but as soon as the "up" button was released, the LED began to dim, as if the "down" button were being held down. To confirm that the Arduino was constantly detecting a "down" press, I opened a serial window and had the main loop print out the current button state. And there's where the trouble began.

The board was connected to COM5. The first time I ran with the serial window open, I got the expected result, but the window quickly filled with text, making the program's progress essentially unreadable. I disconnected the board briefly to update the code with a numeric indicator that could be more easily visually tracked in the debug window. I reconnected the board and attempted to upload the code, and the IDE couldn't find the board. There was nothing on COM5, as far as the IDE was concerned (although Windows Device Manager definitely still saw it).

After several attempts to upload the code, I saved it and closed the IDE, falling back on the time-honored "reset" approach. When I reopened the IDE, the sketch was gone.

Completely.

It wasn't on the Recently Used menu. I used the ordinary Open menu and couldn't find it either. (I don't save my sketches in the default location; I have a Microcontroller/Arduino subfolder in my Source Code folder, with additional subfolders for each board / kit and then for various projects. The corresponding folder for this project wasn't even there.)

The whole project disappeared.

I did a system-wide search for .ino files and found dozens, but none with a file creation date in this year.

The sketch was definitely previously on disk, as I opened it earlier today from the project I'd saved yesterday.

I don't suppose anybody has any idea why this would happen? It's like the IDE took the code down with it when I closed it earlier.

Byff:
I don't suppose anybody has any idea why this would happen?

I'll take a wild guess and say "newbie " confusion over what is and what should be.

Without any code , drawings, details hard to say where you went wrong.
Reason why you should start on simple arrangements and work your way up perhaps.

I don't suppose anybody has any idea why this would happen? It's like the IDE took the code down with it when I closed it earlier.

Highly doubt it. Deleting all the files and the directory that contains them would be a multi-step process for the IDE, it’s more likely you you did a drag-and-hose. Did you look in the recycle bin?

I'll take a wild guess and say "newbie " confusion over what is and what should be.
<<

You're assuming I'm a "newbie" and that I'm "confused." I've been doing Arduino projects for six or seven years now. The problem isn't with the Arduino, my sketch, or the circuit. It's evidently some kind of weird bug involving the IDE and possibly the OS.

Your condescension is noted and appreciated, though, bluejets.

Did you look in the recycle bin?
<<

Yep. Nothing there.

I guess it's not that big a deal. The code was simple enough that I can retype it in maybe five minutes. The real irritant is the loss of the detailed comments I included, a full description of the circuit. Something I've started adding to sketches so that I can readily recreate previous projects.

However, I want to put this out there as a warning about a rather bizarre behavior.

I guess in future I'll let the IDE save to the default location, then back up the sketches to my custom folder.

I guess its possible that your 3 year old version of the IDE did have a bug ..............................

I did a system-wide search for .ino files and found dozens, but none with a file creation date in this year.

So apparently the IDE also did a system wide search of your PC, and deleted every .ino file it found. You would imagine that would take a while ................

So apparently the IDE also did a system wide search of your PC, and deleted every .ino file it found. You would imagine that would take a while ................
<<

There would only have been a handful, from the past few days. This is not the PC I do most of my microcontroller coding on. But yes. Every sketch that was auto-saved with a jul_whatever filename is gone, along with the one with the customized file name from earlier today.

Interestingly, the same problem connecting to the board just happened, and I think it has to do with attempting to upload the program while the serial monitor window is open. The IDE just lost the connection to COM5, although Device Manager shows it still up and running. It was at this point that I closed the IDE before. I have copied the code, and will save it in a text file, and watch the save folder to see what happens when I close it this time.

In case there's any question about whether the code might have been involved, I'll paste in what I have retyped from memory. I suppose I could also upload a photo of the circuit if needed.

/*

 PROBLEM:  
 To build a voltage divider around an AD5220 digital pot, in order 
 to provide control voltages for a 555-based PWM generator.  The 
 first phase of the project entails using tact switches as 
 "up" and "down" buttons to control the dpot and thereby 
 vary the pulse width of the output pulses.  Once this is 
 working satisfactorily, the buttons will be replaced by 
 digital signals from a control source, either discrete logic 
 or a microcontroller.

 ISSUE:  
 The dpot is not functioning as expected.  Either the chip 
 is defective (unlikely, since I've tried a few different ones), 
 or the 555 timer's otuput is not a properly square pulse (a 
 known factor in operating the D5220).  I've included a 
 debouncing circuit in order to compensate (a trusty old 14490
 hex debouncer, with each signal routed through twice to re-
 invert the logic levels), but even that didn't produce the 
 desired result.

 So I'm setting up an Arduino project to see what happens if 
 I can get what I would presume are perfectly-formed pulses to 
 the dpot.

 CIRCUIT DESCRIPTION:
 Two pushbutton controls (like large tact switches) and the dpot 
 are arranged vertically on the breadboard.  One leg of each 
 button is tied to ground.  The other is tied, through pull-up 
 (1K) resistors, to +V (5V).  Each of these HIGH tie points are 
 connected to digital I/O pins on the Arduino board.  The 
 theory of operation is that, once the pinmode of these pins 
 (12 and 13) is set to INPUT, they will be pulled HIGH until 
 the button is pressed, grounding the pin and pulling the signal 
 LOW.  The loop function will poll for this state change.  Due 
 to the nature of the circuit, in which the buttons will be 
 pressed continuously for several seconds during testing, it 
 seems unnecessary to include debouncing, but this can be 
 added later if it seems necessary.

 The dpot is connected to the Arduino through two more I/O pins, 
 11 and 8.  11 is used to send pulses to the CLK input (pin 1) of 
 the chip.  DPOT pin 2, the SEL sensor, will receive a HIGH or LOW 
 from Arduino pin 8, instructing it whether to turn "down" or "up" 
 (as determined by the specific button being pressed).  The dpot 
 is powered via pin 8 to +V and pin 4 to GND, with pin 7, CS (chip 
 select) being held LOW by being tied directly to GND.  Dpot pin 
 3, "A", is tied to +V; pin 6, "B," is left disconnected, so that 
 all the current through the resistor comes through "wiper," pin 
 5.  This output is routed to a green LED, which connects to GND 
 through a 3.3K series resistor.

 The breadboard's rails are connected via jumper wires to the 5V 
 and GND headers in the POWER section of the UNO board.

 If this experiment produces the desired result, then on to 
 Phase II, which will more closely model the circuit under test.  
 In that iteration, the Arduino will continuously generate pulses, 
 and a button press will simply close the route between the pulses 
 and the CLK pin on the AD5220, with the SEL pin being set 
 appropriately.
 
 */

//  Arduino I / O pins:
const int UP_BUTTON = 13;
const int DN_BUTTON = 12;
const int CLK = 11;
const int SEL = 8;

//  for better visual tracking in debug window:
int up_clicks = 0;  
int dn_clicks = 0;

void setup() {
  pinMode(UP_BUTTON, INPUT);
  pinMode(DN_BUTTON, INPUT);
  pinMode(CLK, OUTPUT);
  pinMode(SEL, OUTPUT);

  Serial.begin(9600);
}

void loop() {
  if (digitalRead(UP_BUTTON) == HIGH)
  {
    //  TODO:  debounce?
    digitalWrite(SEL, LOW);
    PulseOut(CLK, 50);
    Serial.println((String)"Up" + ++up_clicks);
  }
  else if (digitalRead(DN_BUTTON) == HIGH)
  {
    //  TODO:  debounce?
    digitalWrite(SEL, HIGH);
    PulseOut(CLK, 50);
    Serial.println((String)"Down" + ++dn_clicks);
  }
}

//  Library function to emulate PicBasic's PULSOUT command
void PulseOut(int Pin, int PulseWidth)
{
  digitalWrite(Pin, HIGH);
  delay(PulseWidth);
  digitalWrite(Pin, LOW);
}

What was the location on your computer where you had the sketches saved to?

Any chance the code was saved off your system into the dreaded cloud (I hate that word), but your search didn't look further than the local storage?

Call me anal, but whenever I get a new part of my sketch working, I copy the entire source code to a USB stick.

I give them serial numbers - "Traffic06" goes to 07 and so on using "save as". May end up with a lot of files but - what else are PCs for?

Or thinking backups, just make them cyclical; after 9 go to 1.

nixie:
Call me anal, but whenever I get a new part of my sketch working, I copy the entire source code to a USB stick.

I will not disagree with your observations.
I am curious if the virtual drice was ueed or a restore operation occurred

On line IDE?

What was the location on your computer where you had the sketches saved to?
<<

I have a Source Code folder on my C: drive, and subfolders for each of the different major types of projects. It was originally saved to the Microcontroller/Arduino/Vilros subfolder.

It's now saved in the default My Documents location, and backed up to that other subfolder.

Any chance the code was saved off your system into the dreaded cloud...
<<

I suppose it's a possibility, but I can't think how.

I copy the entire source code to a USB stick.
<<

I have set up an SVN-based repository on my D: drive, and intend to add all my existing C: source code to it, but have yet to organize it all to my satisfaction. :\

May end up with a lot of files but - what else are PCs for?
<<

Not a bad idea at all, but when I get the SVN repository up and running, it should handle all the versioning for me. That's the theory, anyway.

I'm going to go ahead and update my IDE code today just to try to eliminate any other potential weirdness. The issue with losing COM5 still happens, but it's not insurmountable.

BTW, I found a bug in the code (as posted). The "up" button works fine, but the "down" functionality takes over as soon as "up" is released. Execution is dropping down into the "else if" case even if the down button isn't pressed. The fix was to remove "else" and make the second if statement discrete.

I guess this is no longer an issue, but for those reading, please consider keeping your IDE up to date, and watch for weird results if you attempt to upload code while the serial monitor window is open.

Thanks, all.

Byff:
I guess this is no longer an issue, but for those reading, please consider keeping your IDE up to date, and watch for weird results if you attempt to upload code while the serial monitor window is open.

Well, given that no-one else has reported anything similar, I would hazard a guess that it has nothing to do with keeping the IDE up to date or the serial monitor.

Since the IDE does not (to my knowledge) perform backups, the specific danger is the unintentional sequence of control-A or control-End highlighting the whole code, followed by an Enter or space and a "compile" instruction which writes the (now empty) file to disk. :roll_eyes:

Well, here's the thing. When you save the project, it's not just the sketch file that gets saved. A project folder is also created, and the sketch is saved within that.

The whole thing was gone. All of it. Folder and sketch.

Byff:
Well, here's the thing. When you save the project, it's not just the sketch file that gets saved. A project folder is also created, and the sketch is saved within that.

Sure about that ?

I though a new project folder and project (*.ino) was only creatred when you used the 'save as' option ?

I dont ever recall that just saving the project you are working on creates a new one with a new folder.

So when you use just the 'save' option where is this new folder and project created ?

The ino file has to be in a folder by the same name. You can open an ino file in a folder full of other files, but when you save it, the IDE will automatically create a folder by the same name.

If you compiled the sketch, the IDE first does a save.

Hope this helps.

BTW, I use a free program called "everything" that does lightning fast searches on the PC. I find it to be indispensable. In a couple of seconds I can search my entire hard-disks for ".ino" and sort by date. It's faster than opening File Explorer then drilling down to my target folder.