🛠 Entrées analogiques du Teensy 4.1 : 18 broches, 2 ADC, 0-3,3 V fixes et zéro DAC
Objectives
Master the Teensy 4.1 analog capabilities: 18 inputs distributed across 2 ADCs, default resolution of 10 bits, voltage range fixed at 0-3.3 V. Three documented disappointments to know before wiring: analogReference has no effect, the hardware 12-bit resolution is not practically usable ("only about 10 bits are usable due to noise," product page), and the board has no DAC — unlike the Teensy 3.5/3.6, analog audio output goes through I2S, the MQS pin, or a PT8211 kit. As compensation, 4 analog comparators are embedded.
Hardware
- 1 Teensy 4.1 + micro-USB data cable
- 1 10 kΩ potentiometer (3.3 V / A0 / GND) — never 5 V on the pin!
- Optional: a resistor and an LDR for a light-dependent voltage divider
Key Facts
- By default,
analogReadreturns 0..1023; the hardware range is exactly 0 to 3.3 V, with no selectable external reference. - Analog pins do not tolerate 5 V: a voltage divider is mandatory upstream of a 5 V signal.
- There is no PGA or capacitive sensing embedded (absent from technical specs).
- EEPROM writes abruptly pause execution from flash: if you log analog measurements with
EEPROM.update, expect micro-interruptions in timing.
Complete Code
const uint8_t AIN = 14; // A0 sur Teensy
void setup {
Serial.begin(9600);
while (!Serial && millis < 3000); // laisser monter l'USB série
analogReadResolution(10); // 10 bits : ce qui sert vraiment
}
void loop {
long somme = 0;
for (int i = 0; i < 64; i++) somme += analogRead(AIN);
int moyenne = somme / 64; // suréchantillonnage anti-bruit
float volts = moyenne * 3.3f / 1023.0f;
Serial.printf("A0 = %d (%.3f V)\n", moyenne, volts);
delay(250);
}
Expected Verification
When turning the potentiometer, the displayed voltage smoothly follows 0.000 → 3.300 V. Averaging over 64 samples stabilizes the last two digits: this is the counterpart to the noise floor documented by PJRC. To go further (precise triggering, hardware oversampling), Pedro Pereira's third-party ADC library is the community reference, but the 10 useful bits remain the physical ceiling.
Common Errors
- Calling
analogReference(INTERNAL)or others: the function exists for Arduino compatibility but does nothing on the 4.1 — the range is hardware-fixed. - Aiming for 4096 with
analogReadResolution(12)and being surprised by noise: 12-bit resolution is there on paper, not in practice. - Powering a sensor with 5 V and injecting its output directly: level shifting is mandatory.
- Comparing with a Teensy 3.6 looking for
analogWriteDAC: the true 12-bit analog output is gone; for audio, see the Audio/I2S tutorial.
Other tutorials for this board
- Premiers pas sur le Teensy 4.1 : Teensyduino, Teensy Loader et premier Blink
- GPIO et PWM sur le Teensy 4.1 : 55 broches en 3,3 V, ni 5 V tolérées ni traîne
- Logger sur carte SD via le port SDIO natif du Teensy 4.1
- Serveur web embarqué : l'Ethernet natif 10/100 du Teensy 4.1 (DP83825)
- Boîte à rythmes USB MIDI : classes MIDI, MIDIx16 et port hôte USBHost_t36
- Ingénierie mémoire du Teensy 4.1 : TCM, DMAMEM, EXTMEM, flash QSPI et EEPROM
Code examples for this board
clignotante.inoArduinotouche-capacitive.inoArduinoanalogique-12-bits.inoArduinomidi-piano.inoArduinopwm-respiration.inoArduinoservo-angle.inoArduino