Reading MatrixPortal's UP/DOWN buttons in Arduino

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
tahunus
 
Posts: 33
Joined: Fri Aug 20, 2021 4:24 pm

Reading MatrixPortal's UP/DOWN buttons in Arduino

Post by tahunus »

I've found several entries in the forum on reading the MatrixPortal's UP/DOWN buttons in CircuitPython, but none on how to read them using Arduino (C++).

The MatrixPortal's pinout, and its learning guide, have these buttons mapped to Arduino Pins 2 & 3, adding "...The up and down buttons do not have any pull-up resistors connected to them and pressing either of them pulls the input low.."

Using a simple code (below), and reading them as analogRead in case there was an issue with bouncing or something, shows them always LOW, regardless of pressing them or not.

What am I missing?

Thanks!!

Code: Select all

#include <Adafruit_Protomatter.h>
uint8_t addrPins[] = {17, 18, 19, 20};
uint8_t rgbPins[]  = {7, 8, 9, 10, 11, 12};
uint8_t clockPin   = 14;
uint8_t latchPin   = 15;
uint8_t oePin      = 16;
Adafruit_Protomatter matrix(32, 6, 1, rgbPins, sizeof(addrPins), addrPins, clockPin, latchPin, oePin, true);

void setup() {
  Serial.begin(115200); 
  ProtomatterStatus status = matrix.begin();
  pinMode(2, INPUT);  //placing these before or after the matrix initialization makes no difference
  pinMode(3, INPUT);
}

void loop() {
  Serial.print(analogRead(2)); 
  Serial.print(",");
  Serial.println(analogRead(3)); 
}
Sample run (Note: when using digitalRead instead of analogRead, all readings are 0's):

Code: Select all

18:19:17.524 -> 77,74
18:19:17.524 -> 91,73
18:19:17.524 -> 80,73
18:19:17.524 -> 77,72
18:19:17.524 -> 77,68
18:19:17.524 -> 70,91
18:19:17.524 -> 90,78
18:19:17.524 -> 82,76
18:19:17.524 -> 79,74
18:19:17.524 -> 89,73
18:19:17.524 -> 81,72
18:19:17.524 -> 79,72
18:19:17.524 -> 77,68
18:19:17.524 -> 56,69
18:19:17.524 -> 66,69
18:19:17.524 -> 73,70
18:19:17.524 -> 87,72
18:19:17.524 -> 79,72
18:19:17.524 -> 77,71
18:19:17.524 -> 78,71
18:19:17.524 -> 51,84
18:19:17.524 -> 67,76
18:19:17.524 -> 74,93
18:19:17.524 -> 92,80
18:19:17.524 -> 96,78
18:19:17.524 -> 85,75
18:19:17.524 -> 79,72
18:19:17.524 -> 77,73
18:19:17.524 -> 53,67
18:19:17.524 -> 66,70
18:19:17.524 -> 72,71
18:19:17.524 -> 74,72
18:19:17.524 -> 89,73
18:19:17.524 -> 81,72

User avatar
dastels
 
Posts: 15653
Joined: Tue Oct 20, 2015 3:22 pm

Re: Reading MatrixPortal's UP/DOWN buttons in Arduino

Post by dastels »

You need to enable the pullup resistors on the button inputs, i.e. set the pinMode to INPUT_PULLUP. Also, read them using digitalRead().

Using the Bounce2 library https://github.com/thomasfredericks/Bounce2 with the button will probably be quite useful. It will debounce them as well as let you detect pressed/released event rather than just is-pressed/is-not-pressed state (though it will give you that as well).

Dave

User avatar
tahunus
 
Posts: 33
Joined: Fri Aug 20, 2021 4:24 pm

Re: Reading MatrixPortal's UP/DOWN buttons in Arduino

Post by tahunus »

Wasn't expecting a response so fast! Thanks! This solved it. And the debouncing library is a very cool addition.

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

Return to “Itsy Bitsy Boards”