Better understanding Qt Py SAMD21 Analog vs Digital pinouts

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
swooby
 
Posts: 67
Joined: Wed Jun 19, 2019 4:09 pm

Better understanding Qt Py SAMD21 Analog vs Digital pinouts

Post by swooby »

I am looking at to better understand the datasheet for the ATSAMD21:
https://www.mouser.com/datasheet/2/268/ ... 580554.pdf

The Qt Py SAMD21 appears to use the ATSAMD21E18A-U model.
That 256KB model is hard [for me] to find, so I am using what I hope is only a 128KB difference model ATSAMD21E17D-AU.
I hope there is not a huge difference between the "A-U" and "D-AU".

I am trying to understand in the pinout image how the Qt Py SAMD21 uses different pins that are designated in the datasheet as green for analog and blue for digital.
From Page 24 of the datasheet:
ATSAMDExxA/B/D datasheet pinout
ATSAMDExxA/B/D datasheet pinout
Screenshot 2021-11-24 175525.jpg (73.77 KiB) Viewed 574 times
For example, in this keypad demo (https://learn.adafruit.com/deluxe-4x4-n ... d?view=all) they are controlling the columns using Qt Py SAMD21 pins SCL, TX, RX, and SCK, with SDA sending the neopixel data.
qt py SAMD21 controlling  1x4 neokey rows and columns
qt py SAMD21 controlling 1x4 neokey rows and columns
Screenshot 2021-11-24 175508.jpg (74.88 KiB) Viewed 574 times
Those pins resolve to the SAMD21's respective pins of PA17, PA06, PA07, and PA11, with PA16 sending the neopixel data.
Qt Py PCB pins controlling neokey columns
Qt Py PCB pins controlling neokey columns
Screenshot 2021-11-24 175956.jpg (163.74 KiB) Viewed 574 times
In the first image, PA06 and PA07 are Analog, and PA11 and PA17 are Digital, and PA16 sending the neopixel data is also Digital.

Is it OK to mix and match Analog and Digital pins like that for the columns?

Must the neopixel pin be Digital, or could is also be any of the Analog pins?

Or maybe I am reading the datasheet pinouts all wrong or having some other brain fart.

Any help in understanding how to use the Qt Py SAMD21 pinouts and/or SAMD21 in general would be greatly appreciated.
My project is in relation to this thread, viewtopic.php?f=19&t=184476#p899657, in an attempt to cleanup the trace routes for the keypad columns on a 1x4 or larger keypad.

Thanks, and Happy Thanksgiving! Gobble Gobble!

User avatar
swooby
 
Posts: 67
Joined: Wed Jun 19, 2019 4:09 pm

Re: Better understanding Qt Py SAMD21 Analog vs Digital pino

Post by swooby »

Basically, in the project's (https://learn.adafruit.com/deluxe-4x4-n ... d?view=all) code [by John Park]:
Screenshot 2021-11-24 185852.jpg
Screenshot 2021-11-24 185852.jpg (37.77 KiB) Viewed 570 times
A0, A1, A2, A3, A6, and A7 all show up in the SAMD21 datasheet as Analog pins PA02, PA03, PA04, PA05, PA06, and PA07 respectively.
A8 (SCK?) and SCL show in the SAMD21 datasheet as Digital pins PA11 and PA17 respecively.
Screenshot 2021-11-24 190954.jpg
Screenshot 2021-11-24 190954.jpg (197.21 KiB) Viewed 569 times
XxX Snap Apart Keypad Wiring.png
XxX Snap Apart Keypad Wiring.png (903.92 KiB) Viewed 569 times
Does it really not matter in this use case if there is a mix of datasheet spec'ed Analog and Digital pins used for the rows and/or columns, or is there some magic that `Adafruit_Keypad` is doing to initialize those pins?

User avatar
swooby
 
Posts: 67
Joined: Wed Jun 19, 2019 4:09 pm

Re: Better understanding Qt Py SAMD21 Analog vs Digital pino

Post by swooby »

I see a bit more detail about the pinouts here that may answer my question(s):
https://learn.adafruit.com/adafruit-qt- ... -3073174-3

It looks like a lot of the pins can be dual Analog or Digital purposed.

And it looks like Adafruit_Keypad initializes the rows as digital:
https://github.com/adafruit/Adafruit_Ke ... d.cpp#L116

Code: Select all

void Adafruit_Keypad::begin() {
  _keystates = (volatile byte *)malloc(_numRows * _numCols);
  memset((void *)_keystates, 0, _numRows * _numCols);

  for (int i = 0; i < _numCols; i++) {
    pinMode(_col[i], OUTPUT);
    digitalWrite(_col[i], HIGH);
  }

  for (int i = 0; i < _numRows; i++) {
    pinMode(_row[i], INPUT_PULLUP);
  }
}

User avatar
westfw
 
Posts: 2008
Joined: Fri Apr 27, 2007 1:01 pm

Re: Better understanding Qt Py SAMD21 Analog vs Digital pino

Post by westfw »

Any of the "analog" pins on a SAMD21 can be used as a digital pin instead (and perhaps other functions.)
See the "I/O Multiplexing and Considerations" section of the data sheet.
And/or this spreadsheet: https://docs.google.com/spreadsheets/d/ ... sp=sharing
(QT Py isn't on there, though.)

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

Return to “Microcontrollers”