The deal is that up to yesterday my Leonardo-clone was behaving perfectly, with the assistance of a DHT11 and a two-colour OLED advising me of the temperature and humidity in my room.
I wanted to add another sensor and spent some time messing around with wires and pins (I'm pretty confident I didn't wire-up things in a damaging way) but couldn't get it to work as the Arduino IDE couldn't find the serial port (previously COM7). I've tried different USB cables (which I knew "worked" - the IDE sees my 'ordinary' Arduino on COM10) and connected to a PC-USB rather than through a USB-hub but without success: when only the Leonardo is connected "Port" under "Tools" is greyed-out in the IDE. So when I try to run "blink" I get red messages about Couldn't find board on selected port (of course there is no selected port ...).
On connecting and disconnecting the Leonardo the PC generates the usual USB-device connected bippedy-boo sound (Windows 10) and the Leonardo's green ON and yellow L LEDs come on. If I press reset the L LED waxes and wanes for a few seconds then goes off and the yellow RX LED comes on and stays on.
I haven't been able to find anything on the forum nor via web-wide searching - I really wish it wasn't called Leonardo as I spend a lot of time clicking on links which are about a Mr Da Vinci.
Due to the USB stack running on the same microcontroller as your sketch with this board, it is possible for code in your sketch to break the USB functionality.
Fortunately, the upload code (bootloader) is stored in a separate section of memory and can not be broken by the sketch code.
The only tricky thing is that the bootloader has to be activated at just the right time during the upload. Normally this is done by some special code that runs in the background of your sketch code recognizing a 1200 baud connection as the signal to reset the microcontroller and start the bootloader. However, in your current situation, that system won't work so you'll need to manually reset the board to activate the bootloader.
You need to get the timing right. If you press the reset button too early, the bootloader will have already timed out by the time the upload starts. The tricky thing is that when you press the "Upload" button in the Arduino IDE, it first compiles your sketch before starting the actual upload. So you need to wait until after the compilation finishes before pressing the reset button.
Select Sketch > Upload from the Arduino IDE's menus.
Watch the black console window at the bottom of the Arduino IDE window until you see something like this:
Sketch uses 444 bytes (1%) of program storage space. Maximum is 30720 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables.
Maximum is 2048 bytes.
Immediately press and release the reset button on the Arduino board.
After that, the sketch should upload successfully. If the problem persists after a successful upload, you know there is something in your sketch that is breaking the USB functionality. You can verify this by uploading the File > New sketch, after which the board should be recognized by your computer and you should be able to upload normally. If the problem is in your sketch, you will need to find out what it is in your sketch breaking the USB code. Now that you know how to recover your board, that should be manageable.
Adding the "arduino" keyword to your searches should eliminate those results.
Thanks - not just for the recipe but also the explanation, although it does beg a question about why this sort of thing is necessary at all.
I have the hand-eye co-ordination of a geriatric snail so it took me a few times but I think I have done it. The Leonardo seems to be on COM12 now, not that I mind - the same number as the mighty Wolfgang Overath, one of the best mid-fielders of all time, so it's in good company.
I did include Arduino when searching but I just got flooded with Arduino-centric pages - even when I had "Leonardo" as must-include.
It is just an unavoidable characteristic of the boards that have native USB. If you want to avoid it, use one of the Arduino boards that have a separate USB chip, such as the Uno, classic Nano, Mega, or Pro Mini. Your sketch can never break USB on those boards because the sketch is running on a completely separate chip.
The situation is improved a bit with the newer native USB boards such as the MKR line and the Nano 33 IoT in that you can put the board into a persistent bootloader mode by pressing the reset button twice. That means that you don't need to worry about timing the reset. But the USB can be broken by the sketch just as easily on those boards, it's just that it's a little easier to recover them from that state.
I think it was Einstein who said something about stupidity being doing the same thing again and expecting different results.
I got the Leonardo working with the DHT11 / OLED fine again, added the BMP180 via Wire and the same thing as above happened. I don't know whether I've "lost the knack" or something's gone seriously wrong but I've been trying for about an hour to press the reset button on the Leonardo at the right moment without success.
(a) Tools / Port is now greyed-out for my Arduino Uno (previously on COM4) and my ESP8266 (previously on COM3) as well
(b) there are no sounds when a USB device is plugged in or unplugged - not just the boards but also flash-drives and a kindle.
I tried uninstalling the IDE, powering everything off (inc the separately-powered USB-hub) and reinstalling / restarting everything but that hasn't helped (even though I used an uninstaller there seemed to be lots of "arduino memory" left over eg it loaded the Additional Boards Manager for the 8266). The fact that non-Arduino USB devices aren't working properly makes me think this is a Windows / PC issue. But advice welcome
Incidentally, should pressing the reset button on the Leonardo remove the program from memory? When I plug the DHT11 and OLED back in, the last-successfully-loaded program still runs.
No. The program is written to non-volatile memory when you upload it to the Leonardo. It will run any time you power the board, regardless of whether it is connected to the computer.
The way you remove a program from the memory of the Arduino board is by uploading a new one.
I'm glad to hear it!
There are electrical protection devices on the USB ports of the computer. A bad circuit connected to an Arduino board can trigger that protection, which will cut off the USB port. I don't know the exact details of how it works, but the common type of resettable "PTC fuse" works by temperature, so it is possible that it can take a little time to cool off before it will reset.
I recommend carefully evaluating the circuitry connected to your Arduino board to make sure it is not drawing excessive amounts of current (especially via a short circuit). Also check carefully that the board is not sitting on a conductive surface (i.e., a metal tabletop) or in contact with any sort of conductive debris (e.g., cut off bits of wire, coins).
Thanks. The environment the Leonardo is in is fairly clutter-free and although I'm using a USB hub I only have one or two devices in use at any one time. But I'll look into and keep an eye on the electrical aspects.