Onboard A button is flaky/floating on A-Star 32U4 Prime LV

Hi,

I have a classroom of students who are using the A-Star 32U4 LV. As I’m trying to start with the most basic information about programming the uc via the Arduino IDE, I’m running into a strange situation.

Given just this minimal code (I’ve tried several variations - I’ve just simplified to the bare minimum for this post)…

[code]void setup() {
pinMode(13,OUTPUT);
pinMode(14, INPUT_PULLUP);
}

void loop() {
digitalWrite(13, digitalRead(14) );
}[/code]

The LED goes on when the board is placed on a table, when a hand is waved near the button, etc. The Button library example seems to work, but I think this goes beyond debouncing since it’s flaky before a button is even pressed. The schematic shows that we should be using a pullup on this pin, which I’m doing above, but the behavior is the same with INPUT as the pinMode. The boards are all plugged into laptops via USB for power. The same flaky behavior happens with all students.

Am I missing something obvious here? I haven’t had a chance to try this with a breadboarded switch with an actual pullup resistor, but I’m trying to make this work since it’s one of the reasons I got this board for the class… to allow them to focus on programming by using the onboard hardware (buttons/leds/buzzer) before starting to deal with wiring things up on a bboard.

Thanks for any help,
Rob

Hello, Rob.

You say that “the LED goes on” unexpectedly, but based on your code, the LED should be on by default (and off only while button A is held down). Is this not the behavior you are observing?

- Ben

Hi, Rob.

Are you working with the microSD version of the A-Star Prime, and do you have the CS jumper installed? If so, that would explain the flaky readings you are getting from pin 14: it doubles as the MISO line, and when CS is low, that line is driven by the microSD level shifting circuit. When no card is inserted, the output of that level shifter can be undefined and result in inconsistent readings on pin 14.

When you aren’t using the microSD card, you should remove that jumper so CS is not shorted low; this should allow Button A to be read properly. (If you’re worried about losing the shorting block, one solution is to move or rotate it so it only sits on one of the pins.)

- Kevin

Yes, Ben, sorry… the led goes on AND off unexpectedly. The behavior is erratic.

I will check the CS jumper - thanks Kevin.

Rob

I didn’t realize that the jumper you were talking about is only on boards with the SD card slot. We don’t have that model so that’s not the issue. I’m still not sure what the problem is, and today I had the students switch to button C which didn’t seem to respond at all (for any one of the students) with the same code above. Again, it works fine with the astar32u4 library’s button functions. Again, is there something obvious that I’m missing? I can’t see any reason - in the schematics or the code - why this shouldn’t work.

Thanks for any help,
Rob

That is strange that the library examples work but your code doesn’t. I tried your exact program on a few A-Stars here and it seemed to work fine on all of them. We’d like to try to figure out what’s going on:

  • Do you have anything other than a USB cable connected to the A-Stars?
  • Do you have “Pololu A-Star 32U4” selected as the board type in the Arduino IDE?
  • What version of the Arduino IDE are you using?
  • Could you try using a multimeter to measure the voltage on pin 14 when Button A is pressed and not pressed(and the pullup is enabled)? The easiest way to access it is on the column of pins next to the LCD connector (the pin is labeled “DB4 = 14” on the back). You can try this for Button C/pin 17 too.

If it’s easy for you to get a video of the problem occurring, that might be helpful for troubleshooting too.

- Kevin