4
\$\begingroup\$

I tried to make custom library for my Leonardo to work as a native gamepad, but as it turns out, it isn't as easy as it looks. After i got some code of core arduino and imported it, everything uploaded fine but then Windows stopped recognizing Arduino itself (It is now listed as a Composite USB Device).

Now is there any way to wipe arduino back to its factory settings without need of an external programmer or without need for rewriting arduino drivers? Thanks in advance.

\$\endgroup\$
1

2 Answers 2

4
\$\begingroup\$

The boot loader of the Arduino does not immediately run your application code. Rather it looks at the serial port for semaphore sequence sent by Avrdude. which in turn is started by the Arduino's IDE upload process after compile. Where Avrdude opening the serial port will cause a reset of the Arduino, as to catch the boot loader when sending the semaphore. This above process should work. Regardless of your application code.

immediately after power up or reset of the leo, you should see in your device manager a COMM Port briefly for about 5 seconds and then disappear being replaced with your Game interface. This will do the same for the IDE when uploading.

If this does not occur, it is possible that you may have blanked the boot loader and the application is running directly. Note when programing application by the ISP will blank the boot loader.

It is possible that your IDE's machine, avrdude and the leo's timing is just off and misses. You could attempt to manually reset the leo just after compile and as avrdude starts. In the IDE preferences you can turn on the verbose for both compile and upload to better see when to hit the leo's reset.

This was the way of the old Bluetooth's Arduino's that did not have the DTR of the Serial port tied to the ATmega's reset. Where with the leo, a remote reset is triggered by the serial port opening and closing at 1200 baud. Where here it may be possible that with an application of Game controller the USB CDC virtual serial port cannot be opened at 1200 baud. Hence as above stated, may just need to time the reset.

\$\endgroup\$
1
\$\begingroup\$

I have a similar issue with a Leonardo: Dumping too much data at once to Serial.print(), it seems I broke my programmer. As a result, my sketch still starts but I can't update/upload it anymore.

Problem

  • Given my sketch is started
  • When I upload any sketch
  • Then the build fails as the Serial connection is broken
Global variables use 149 bytes (5%) of dynamic memory, leaving 2411 bytes for local variables. Maximum is 2560 bytes.
Forcing reset using 1200bps open/close on port /dev/ttyACM0
PORTS {/dev/ttyACM0, /dev/ttyS4, } / {/dev/ttyS4, } => {}
PORTS {/dev/ttyS4, } / {/dev/ttyS4, } => {}
...
PORTS {/dev/ttyS4, } / {/dev/ttyS4, } => {}
Couldn't find a Board on the selected port. Check that you have the correct port selected.  If it is correct, try pressing the board's reset button after initiating the upload.
  • Given the arduino is starting (double press reset)
  • When I upload any sketch
  • Then the build fails with the following error
Connecting to programmer: .
Found programmer: Id = "Frames:"; type = e
    Software Version = F.r; Hardware Version = a.m
avrdude: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?

As yo can see the id is "Frames:" and if you concatenate the software version, hardware version and type, you get "F.r_a.m_e", which is what I printed to Serial.

Breaking sketch

Here is the piece of code I think broke:

template <typename T, typename... Types>
void printLine(T first, Types... other) {
  Serial.print(first);
  printLine(other...) ;
}

String byteToString(int value) {
  String out;
  for (int i = 7; i >= 0; i--) {
      bool b = bitRead(value, i);
      out += b ? '1' : '0';
  }

  return out;
}


...


    printLine("Frames: ");
    for (int i = 0; i < 16; i++) {
      printLine(
        // printf("%04d", i),
        i,
        " => "
            ,byteToString(leftFrame[0][i])
        ,",",byteToString(leftFrame[1][i])
        ,",",byteToString(leftFrame[2][i])
        ,",",byteToString(leftFrame[3][i])
        ,",",byteToString(leftFrame[4][i])
        ,",",byteToString(leftFrame[5][i])
        ,",",byteToString(leftFrame[6][i])
        ,",",byteToString(leftFrame[7][i])
        ,":"
            ,byteToString(rightFrame[0][i])
        ,",",byteToString(rightFrame[1][i])
        ,",",byteToString(rightFrame[2][i])
        ,",",byteToString(rightFrame[3][i])
        ,",",byteToString(rightFrame[4][i])
        ,",",byteToString(rightFrame[5][i])
        ,",",byteToString(rightFrame[6][i])
        ,",",byteToString(rightFrame[7][i])
      );
    }

The funny part here is the fact that the Leonardo seems to have written in itself when I asked him to write "outside" (Serial).

Tries

Working solution

Finally, I bought this USBtinyISP and burned my bootloader in 20 seconds without any wiring to do or complicated post to read

enter image description here

Some other resources

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.