drumminhands
Member
Hello,
I'm using a 10 slot rotary switch and breakout board from SparkFun. https://learn.sparkfun.com/tutorials/rotary-switch-potentiometer-hookup-guide
I've wired it up and tested resistance. All wiring and soldering working well.
I have a teensy 4.0. I plug the CCW to ground on the teensy, W to port 17 (aka A3), and CW to 5v. I simplified the code from Sparkfun (see below) to simply report the slot to the serial terminal. The problem is, I'm getting very inconsistent results:
Position 1: val = 0
Position 2: val = 1
Position 3: val = 3
Position 4: val = 4
Position 5: val = 6
Position 6: val = 8
Position 7: val = 9
Position 8: val = 9
Position 9: val = 9
Position 10: val = 9
But, if I plug into an Arduino Uno, using the same CCW to ground, W to A3, and CW to 5v, it works perfectly.
Position 1: val = 0
Position 2: val = 1
Position 3: val = 2
Position 4: val = 3
Position 5: val = 4
Position 6: val = 5
Position 7: val = 6
Position 8: val = 7
Position 9: val = 8
Position 10: val = 9
What is the difference between analog input ports on the Teensy 4.0 vs Arduino Uno?
Thanks.
I'm using a 10 slot rotary switch and breakout board from SparkFun. https://learn.sparkfun.com/tutorials/rotary-switch-potentiometer-hookup-guide
I've wired it up and tested resistance. All wiring and soldering working well.
I have a teensy 4.0. I plug the CCW to ground on the teensy, W to port 17 (aka A3), and CW to 5v. I simplified the code from Sparkfun (see below) to simply report the slot to the serial terminal. The problem is, I'm getting very inconsistent results:
Position 1: val = 0
Position 2: val = 1
Position 3: val = 3
Position 4: val = 4
Position 5: val = 6
Position 6: val = 8
Position 7: val = 9
Position 8: val = 9
Position 9: val = 9
Position 10: val = 9
But, if I plug into an Arduino Uno, using the same CCW to ground, W to A3, and CW to 5v, it works perfectly.
Position 1: val = 0
Position 2: val = 1
Position 3: val = 2
Position 4: val = 3
Position 5: val = 4
Position 6: val = 5
Position 7: val = 6
Position 8: val = 7
Position 9: val = 8
Position 10: val = 9
What is the difference between analog input ports on the Teensy 4.0 vs Arduino Uno?
Thanks.
Code:
/* Test rotary switch
// modified from https://github.com/sparkfun/Rotary_Switch_Potentiometer
Demonstrates using the Rotary Switch Potentiometer breakout board
with a microcontroller, to build a 10 position selector switch.
The Rotary Switch Potentiometer is a breakout board that adds 9 resistors to a
10 position rotary switch, to make a custom-taper, stepped potentiometer. This
example uses 9 10KOhm resistors, and connects the rotary switch potentiometer
to an analog input.
The Rotary Switch Potentiometer board was populated with 10K resistors in
every position. It was connected to the RedBoard as follows:
RedBoard pin : Rotary Switch Potentiometer Pin
----------------------------------------------
GND : CCW
A3 aka 17 : W
5V : CW
*/
#define BAUDRATE 115200
#define ROTARY_PIN 3 //A3, analog 3, aka pin 17 on Teensy 4.0
void setup() {
Serial.begin(BAUDRATE);
Serial.println("Begin Test Rotary Switch");
}
void loop() {
uint16_t input;
uint16_t val;
// read the ADC
input = analogRead(ROTARY_PIN);
// Translate ADC value from 0-1023 to 0-9.
// This implements the proportion
// input/1023 = val/9.
// One "step" of the pot is about 113 ADC counts.
// We're adding 65 (1/2 of 113) to the input value, so that the
// input is in the middle of the window, rather than right at the edge, so values
// are stable and solid.
val = (input+56)*9/1023;
Serial.println(val);
}