Issue with analogRead() on the Teensy 4.1 Board

Hello everyone,

I am right now working with the Teensy 4.1 and reading the output voltage from the Force sensor (Burster 8417) which is amplified by Futek IAA100 Amplifier.

I tried troubleshooting the issue but couldn't fix it and stuck with this.

I cross verified the voltage across the Analog pin and the ground, it is within the acceptable range (0-3.3V). Also, when there is force applied the voltage deviates on the multimeter. But I cannot actually print the values using the serial.print(). When i tried to print the raw analog values between 0-1023, there was also no change.

I have paste the debug code I am using right now and then attached the code which I am using for the system.

const int analogPin = A2; // Analog input pin

void setup() {
Serial.begin(9600);
analogReadResolution(10);
}

void loop() {
int adcValue = analogRead(analogPin);
Serial.println(adcValue);
delay(100);
}
 

Attachments

  • ChannelC.ino
    6 KB · Views: 25
Yeah, i am aware about the pin numbers. I did check it using the Pinout diagram of 4.1. I did check using a different Analog pin A16, thinking that the problem was with the A2 i was using. But it was not the actual issue
 
[ EDIT: for future readers that may find this particular post, this guess is incorrect . . . see @h4yn0nnym0u5e explanation below ]

You have this line in your posted sketch:

const int pinForceC = A2 ;

That line is probably not doing what you think it is. The "A2" is probably being interpreted as 0xA2, which is equivalent to decimal 162.

Try this instead for that line:

const int pinForceC = 16 ; // pin 16 = analog input A2

Hope that helps . . .

Mark J Culross
KD5RXT
 
Last edited:
You have this line in your posted sketch:

const int pinForceC = A2 ;

That line is probably not doing what you think it is. The "A2" is probably being interpreted as 0xA2, which is equivalent to decimal 162.
This would appear not to be the case - C will not magically add a 0x for you, you'd just get a compilation error. A2 is defined in teensy4/pins_arduino.h:
C++:
#define PIN_A2  (16)
// ... followed a few lines later by:
static const uint8_t A2 = PIN_A2;
Unless you're using Teensyduino 1.59 (you haven't said which revision you're on...), you should probably set the pin mode for A2, as the Teensy 4.1 has a "pin keeper" function by default which can interfere with analogue inputs:
C++:
pinMode(A2, INPUT_DISABLE);
From 1.59 this is done automatically inside analogRead(), if you didn't do it in your code.
 
Back
Top