A21 A22 pins on Teensy 3.6

Status
Not open for further replies.

rfresh737

Well-known member
I'm trying to add a 4-way joystick with a push in switch to my Teensy 3.6 project.

I have it wired following the tutorial here: https://www.brainy-bits.com/arduino-joystick-tutorial/

However, I'm using one of my MCP23017 pins for the switch and that is working fine.

The X axis I had connected to A21 and the Y axis I had connected to A22 but neither joystick movement showed any changes in the serial monitor of the X or Y values. They didn't change much at all.

The following code worked fine on a separate bread board with a Teensy 3.2 on it. I connected X to A0 and Y to A1.

Code:
// Arduino pin numbers
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output

void setup() {
  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);
  Serial.begin(115200);
}

void loop() {
  Serial.print("Switch:  ");
  Serial.print(digitalRead(SW_pin));
  Serial.print("\n");
  Serial.print("X-axis: ");
  Serial.print(analogRead(X_pin));
  Serial.print("\n");
  Serial.print("Y-axis: ");
  Serial.println(analogRead(Y_pin));
  Serial.print("\n\n");
  delay(1000);
}

Then I connected the joystick to my main project bread board with a Teensy 3.6 using the same code as above except I initially connected to A21 and A22 but, as stated at the top, joystick movement didn't change the X Y values very much.

I already was using Teensy 3.6 pins D14 and D15 as digital pins. I removed those wires and connected my X and Y axis to those pins as analog A0 (D14) and A1 (D15). The X axis responded fine and I could see a large swing in the X axis high and low values. The Y axis values had full swing on the high value (going up to 1023) but when I pushed the Y axis the other direction towards the low values, the low values did show up, but the serial display slowed down...showing the low Y axis values about once every 3 secs. Normally I was seeing both X axis values and the high end Y axis values about 10 lines in the serial monitor every second. But the low end Y axis value is only showing about once every 3 to 4 seconds.

So I have two issues:

1. I don't know why the Y axis low side value slow down the whole system.

2. I'd like to make use of the A21 and A22 pins but they don't seem to work, so I must be doing something wrong there. I'm looking at the top side of the 3.6 pins diagram for reference as I can't get to the pins on the bottom side.

The first attachment shows the normal high Y axis speed display.

The second attachment shows the low end of the Y axis displaying the value 4 about every three seconds in the monitor.

Thanks for any help.
 

Attachments

  • Y Axis NormalSpeed.png
    Y Axis NormalSpeed.png
    2.5 KB · Views: 73
  • Y Axis Slow.png
    Y Axis Slow.png
    2.1 KB · Views: 68
  • Teensy 3.6.png
    Teensy 3.6.png
    540.7 KB · Views: 115
Interesting I think there is some confusion with the DAC pins.

Correct me if I'm wrong but I believe the suffix A means analog but in this case the DAC means digital to analog converters in plain English it's output pins only, honestly didn't even look at the source code you provided just doing a quick guess :confused:.
 
Code:
// Arduino pin numbers
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output

Instead of using 0/1 for analog pins, use A0 or A1. The Teensy header files define the appropriate mapping from analog pin number to digital. So to use A20 and A21, change this to:

Code:
// Arduino pin numbers
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = A20; // analog pin connected to X output
const int Y_pin = A21; // analog pin connected to Y output

Note, A20 and A21 are analog only pins. You cannot use them as digital pins (i.e. for digitalRead or digitalWrite). They are the two DAC (digital to analog output), so typically you would use these two specific pins for putting out sounds (you would need to connect the pins to an amplifier).
 
@Chris O.

So you're saying I cannot use the A21 and A22 as Analog input pins. That would seem correct since I never got a good response value from either of them (the X or the Y axis pins).

So it's looking like I'm going to have to stay with using my current wiring on the 3.6 A0 and A1 pins.

Now, to figure out why I'm getting a big slow down when I push the joystick towards the low Y axis values. All the other axis values (both high and low X axis and high Y axis values) are responding very quickly and with the values expected.
 
@Michael

'A21' and 'A22' worked fine. Thanks.

If the value is between 0-9, analogRead interpolates to mean analog pins A0..A9. Under the Teensy A0 is 14, and A9 is 23. So if you put 21 or 22 there, the function will use A7 or A8.

A21 is 66 and A22 is 67. Above A9, the analog pins are not numbered in order, so you really have to use 'A<x>'.
 
Status
Not open for further replies.
Back
Top