0

I was using an Arduino Leonardo (in the form of an RPI hat) to control a single DC motor via a motor controller. I have it wired to set Phase and Enable to control motor speed and direction, and I read sensors on the motor's encoder to directly measure motor speed.

I triple checked all my wiring, and a test program I wrote to spin the motor at half-speed seemed to work just fine. Then it suddenly stopped working. Now, when I plug the Leonardo into my machine, the ttyACM0 device does not appear, and I seem to have no way to communicate with it anymore.

I've noticed that when I press the reset button, the Leonardo's status light flashes for a few seconds and ttyACM0 does momentarily appear. But as soon as the flashing stops, ttyACM0 disappears again. I tried upload a new sketch when the device reappears, but I get a "broken pipe" error.

What's going on here? Did I somehow fry my Leonardo, or is it possible I just screwed up the serial port? How do I fix it?

Edit: For the host, I've tried Ubuntu 14 running on a Raspberry Pi 2 and a generic 64bit laptop.

Edit: My setup() is simply:

void count_pan_changes(){
    /*
    CW  => 11,00,11,00,...
    CCW => 10,01,10,01,...
    */
    int a = digitalRead(MOTOR_ENCODER_A_PIN);
    int b = digitalRead(MOTOR_ENCODER_B_PIN);
    int direction = (a == b) ? +1 : -1;
    motor_controller.record_direction(direction);
}

void setup(){
    attachInterrupt(digitalPinToInterrupt(MOTOR_ENCODER_A_PIN), count_pan_changes, CHANGE);
}

Edit: I'm not sure why, but when I disconnected the Leonardo from it's 5V UBEC power supply and powered it directly from my laptop via USB, then ttyACM0 suddenly came back. However, when I reconnect it to its own power supply, I again have problems connecting to it. The first upload and serial terminal seem to work, but as soon as I disconnect, further uploads/serial connections seem to fail with a "broken pipe" error. I'm powering it via a UBEC by connecting the 5V and Gnd lines to one of the Leonardo's GVS headers (i.e. it's not going in through any onboard regulator on the Arduino or RPi). Should this work? The motor is behind a separate UBEC.

Edit: Now power cycling isn't even fixing it. I tried erasing the contents using:

avrdude -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -e

as explained here. This keeps /dev/ttyACM0 from disappearing, but if I try and upload a sketch using ano upload, I still get the error:

IOError: [Errno 32] Broken pipe
4
  • Can you describe your host environment?
    – dlu
    Jan 13, 2016 at 2:35
  • If you watch dmesg -w on the Linux machine (I assume you're working on some flavor of Linux) you'll see kernel messages from the USB sub-system. While doing that try resetting the Leonardo and watch the messages. They may give you some clues.
    – dlu
    Jan 13, 2016 at 5:25
  • Does the setup() contain "while (!Serial);" to give the Serial startup time? Jan 13, 2016 at 6:36
  • @MikaelPatel, No. I posted my setup() code.
    – Cerin
    Jan 13, 2016 at 17:10

2 Answers 2

1

Since your code does not open the serial port, it is entirely expected that the serial port will appear briefly on reset, and then disappear. Initially it appears as the bootloader looks for a new sketch, and disappears because your code does not open Serial.

If you time it correctly you should be able to upload a new sketch after pressing Reset. You need to press Reset fairly precisely after the IDE announces that is uploading. You only have a window of a second or so.

0

I think this might be a bug in Arturo. This is how I was able to fix my Leonardo:

  1. Fix disappearing /dev/ttyACM0 by pressing reset to temporarily bring it back, then erase all content with:

    avrdude -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -e

    Now /dev/ttyACM0 stays there, but trying to upload my sketch throws a broken pipe error.

  2. Upload a blank sketch using the Arduino IDE.

Then I could upload my sketches normally.

Your Answer

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

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