Grand Central unexpected digital read behavior on select pin

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
mckelvan
 
Posts: 3
Joined: Tue Jun 22, 2021 8:56 am

Grand Central unexpected digital read behavior on select pin

Post by mckelvan »

Thanks in advance for any help offered. I am new to all of this.

I wrote a script below to read digital signals from my new Adafruit Grand Central, and once it is working these signals will be translated to MIDI signals so I can add MIDI USB output to my acoustic piano. My first step was debugging using the Serial Monitor to make sure all the digital and analog pins do what I expect, which is to turn from HIGH to LOW if I connect them to ground.

The issues I am having:
1. pin 13 is stuck on LOW whether connected to ground or not
2. Instead of analog pins A0-A15 being labeled 54-70 (expected behavior), I am getting A0-A3 being accessible in my script as pins 62-66, A8-A15 as 54-61, and it appears A4-A7 (62-66?) don't change from HIGH to LOW no matter what I do. Therefore I am unable to change the state from HIGH to LOW on A4-A7 using this script, and the Analog pin assignments seem...weird.

Are my issues the fault of the board, my script, the Arduino IDE (using the version 1.8.15 tarball directly in Debian), or the board manager (I followed instructions at https://learn.adafruit.com/adafruit-ard ... ot-6-x-ide)?

Thanks, and sorry if I am posting any of this incorrectly.

Code: Select all

#if 0
//  Final script will use this library to turn microcontroller into MIDI USB device.
//  Script assumes use of Arduino Due or Adafruit Grand Central
//  When debugging using the Serial Monitor, pin 13 is always LOW, 67-70 are labeled "A0-A3", 62-66 (A4-A7?) don't go to LOW at all, 54-61 are labeled A8-A15. 
    #include <MIDIUSB.h>
#endif

//  KEY_QTY starts at 0, ie "3" would mean 4 total keys.
//  For final script this will be = 70.
const byte KEY_QTY = 68;

//  Temporary and allows for easier Serial debugging
const byte PIN_OFFSET = 2;

//Initializing
byte key_states[KEY_QTY]; //  using an array for comparing MIDI states comes from https://www.instructables.com/Building-an-Arduino-MIDI-Controller/
byte key_state;

void setup() {
    Serial.begin(9600);  //  This line for debugging, not final script.
    for (byte i = 0; i <= KEY_QTY; i++) {
        byte pin = i + PIN_OFFSET;
        pinMode(pin, INPUT_PULLUP);
    }
}

void loop() {
    for (byte i = 0; i <= KEY_QTY; i++) {
        delay(200);  //  This will be 1 or 2 for final script. 200 is handier for Serial debugging.
        byte pin = i + PIN_OFFSET;
        byte key_state = digitalRead(pin);
        //  The following Serial.print lines for debugging, not final script.
        Serial.print(key_state);
        Serial.print("\t");
        Serial.print(pin);
        Serial.print("\n");
        #if 0
        //  This block for final script
            if (key_state != key_states[i]) {
                key_states[i] = key_state;
                byte pitch = i+25;
                if (key_state == LOW) {
                    key_pressed(note);
                } else {
                    key_released(note);
                }
            }
        #endif
    }
}

#if 0
//  This block for final script. Sends MIDI signal to PC.
    void key_pressed(byte note) {
        MidiUSB.sendMIDI({0x09, 0x90, pitch, 64});
        MidiUSB.flush();
    }
    void key_released(byte note) {
        MidiUSB.sendMIDI({0x08, 0x80, pitch, 0});
        MidiUSB.flush();
    }
#endif

User avatar
mckelvan
 
Posts: 3
Joined: Tue Jun 22, 2021 8:56 am

Re: Grand Central unexpected digital read behavior on select

Post by mckelvan »

I see I am supposed to include error messages, order #, pics, and other stuff. In this case the board looks fine and the only connection is an Adafruit jumper cable connecting ground to various digital and analog pins to the headers included with the board. There are no error messages when uploading or running the script. Serial output is as expected, ie
1 2
1 3
1 4
...
0 13 (since 13 is stuck on LOW)
...
1 70
...

I purchased the item a couple weeks ago and the order number is 2584193-5680648423.
Hopefully that's everything needed, but let me know if I should post anything else.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Grand Central unexpected digital read behavior on select

Post by adafruit_support_carter »

1. pin 13 is stuck on LOW whether connected to ground or not
Pin 13 has an LED attached to it which is likely pulling the pin to GND through the LED.
2. Instead of analog pins A0-A15 being labeled 54-70 (expected behavior), I am getting A0-A3 being accessible in my script as pins 62-66, A8-A15 as 54-61, and it appears A4-A7 (62-66?) don't change from HIGH to LOW no matter what I do. Therefore I am unable to change the state from HIGH to LOW on A4-A7 using this script, and the Analog pin assignments seem...weird.
Not sure what the question is here. The analog pins should be as indicated using Ax syntax. If you want to address them using integers (like digital io pins), then take a look at the definitions in the variants file here:
https://github.com/adafruit/ArduinoCore ... iant.h#L96

A0-A7 = 67-74
A8-A15 = 54-61

User avatar
mckelvan
 
Posts: 3
Joined: Tue Jun 22, 2021 8:56 am

Re: Grand Central unexpected digital read behavior on select

Post by mckelvan »

Thank you for the response. Do I need to do anything to close the topic?

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Grand Central unexpected digital read behavior on select

Post by adafruit_support_carter »

Nope, nothing needed to close a topic. Is that info what you were after?

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

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