Mini Metro Sporatic Execution

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
carl_e
 
Posts: 3
Joined: Wed Dec 22, 2021 3:24 pm

Mini Metro Sporatic Execution

Post by carl_e »

I recently purchased three different Adafruit Metro Mini 328s (Product Code 2590) and am having a very bizarre problem that I would love some help with.

I've currently uploaded the following program to all three of the Metros:

Code: Select all

int BUTTON = 2;

void setup() {
  pinMode(BUTTON, INPUT);
  Serial.begin(9600);
}

void loop() {
  if(digitalRead(BUTTON)==HIGH){
    Serial.println('D');
    delay(10);
  }
}
After uploading the code, and without pressing anything on my breadboard, the top LED starts flashing (I assume indicating that it is transmitting) and it starts printing "D" to the serial console repeatedly. Assuming I had a short in my breadboard, I removed the metro from the breadboard and reset it, only to find the same exact thing occur again. Thinking I must have just soldered the headers wrong somehow, I tried with the second, and then third Metro, only to find the same thing. When a program is uploaded and the board is moved/touched it immediately starts printing "D" to the serial console as if a button were pressed. This is despite the fact that this occurs without even being mounted in a breadboard and with no external connections whatsoever. I've tried two different USB cables as well as touching it with my fingers, the sleeve of my sweater, and even the page of a book, but they will all either initiate the program to print "D" to the serial console, or to stop the printing depending on the angle that the Metro was touched. Please help, as I am absolutely baffled. Surely I can't have shorted all three boards in the same way to cause the same error, right?

User avatar
carl_e
 
Posts: 3
Joined: Wed Dec 22, 2021 3:24 pm

Re: Mini Metro Sporatic Execution

Post by carl_e »

Ok, I just tried with two different Arduino Unos and its doing the same thing, which suggests it has to be something with the program rather than the board, but I have no idea what could be causing it? Any one have any ideas?

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: Mini Metro Sporatic Execution

Post by adafruit_support_bill »

How is your button wired? Do you have a pullup or pulldown resistor? Otherwise the input will be 'floating' when the button is not pressed and the results of a digitalRead will be random.

The simplest way is to wire the switch between the digital pin and GND. Then use the internal pullup resistors:

https://docs.arduino.cc/learn/microcont ... gital-pins

Code: Select all

  pinMode(BUTTON, INPUT_PULLUP);
  

User avatar
carl_e
 
Posts: 3
Joined: Wed Dec 22, 2021 3:24 pm

Re: Mini Metro Sporatic Execution

Post by carl_e »

My breadboard has a pull up resistor, but I just tried using the internal pull up and am getting the same results (ie even when it is plugged in via the USB-C port to my computer's USB-A port and is not connected to anything else, it instantly starts printing "D" to the serial console.)

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: Mini Metro Sporatic Execution

Post by adafruit_support_bill »

If you have a pullup (internal or external) then you need to reverse your logic. The button will read HIGH until you press it. Then it will read LOW.

Locked
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”