🛠 Broches, ADC 13 bits, DAC 12 bits et PWM : dompter les E/S de la Teensy 3.2

Teensy 3.2 · debutant · Schéma : IMG-teensy-32-debutant-2-teensy32-broches-analogique-pwm.svg — Teensy 3.2 sur breadboard : potentiomètre 10 kΩ sur A2, bouton sur la broche 5, LED + 330 Ω sur la broche 6 (PWM), doigt posé sur la broche 0 (touche capacitive) et sortie DAC A14 reliée à un oscilloscope.

Objectives

Master the Teensy 3.2 I/O like a pro: 34 I/O pins, with 24 easily accessible on a compact breadboard, 21 analog inputs distributed across 2 converters, a true 12-bit DAC on A14, 12 touch pins (touchRead), and 12 PWM pins divided into 3 timer groups with independent frequencies. You will wire a potentiometer, a button, and a PWM LED, and read everything in a single sketch with DAC output.

Hardware

Architecture points to know

Complete code

// Potentiometre (A2) -> LED PWM (broche 6) + vraie sortie DAC (A14)
// + bouton (broche 5) + touche capacitive (broche 0).
const int POT = A2, BTN = 5, LEDPWM = 6, DAC = A14, TOUCH = 0;

void setup {
  Serial.begin(9600);
  pinMode(BTN, INPUT_PULLUP);          // jamais INPUT_PULLUP sur la broche 13 !
  pinMode(LEDPWM, OUTPUT);
  analogWriteFrequency(LEDPWM, 20000); // 20 kHz sur le groupe FTM0
  analogWriteResolution(12);           // resolution 12 bits pour le DAC A14
}

void loop {
  int v = analogRead(POT);             // 0..1023 par defaut (10 bits)
  analogWrite(LEDPWM, map(v, 0, 1023, 0, 255));
  analogWrite(DAC, map(v, 0, 1023, 0, 4095)); // veritable DAC 12 bits
  Serial.printf("pot=%d touche=%d bouton=%d\n",
                v, touchRead(TOUCH), digitalRead(BTN));
  delay(50);
}

Expected verification

The Serial Monitor displays the potentiometer value (0–1023) and a touch value that jumps when you place your finger on pin 0 (touchRead). The oscilloscope on A14 shows a continuous voltage that follows the potentiometer — a true analog output, not a filtered PWM. On pin 6, the PWM runs at 20 kHz (inaudible on a buzzer, clean for an LED driver). The LED follows the potentiometer.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials