FastLED 3.9.15
Loading...
Searching...
No Matches
TeensyAudioInput.h
Go to the documentation of this file.
1// Teensy I2S Audio Input Implementation
2// Compatible with: Teensy 3.x and 4.x
3// Supported Microphones: INMP441, ICS43432, SPH0645LM4H-B, ICS43434
4
5#pragma once
6
7// Keep fbuild's library scanner aware of PJRC Audio sources for Teensy.
8#include <Audio.h>
9
11
12// ============================================================================
13// TEENSY CONFIGURATION
14// ============================================================================
15//
16// IMPORTANT: Teensy uses FIXED hardware pins that cannot be changed.
17// Pin assignments vary by board - see wiring diagrams below.
18//
19// ============================================================================
20// WIRING FOR INMP441 MICROPHONE → Teensy
21// ============================================================================
22//
23// --- Teensy 3.x (I2S1 only) ---
24// INMP441 Pin → Teensy Pin
25// SCK (BCLK) → Pin 9 (I2S1 Bit Clock)
26// WS (LRCLK) → Pin 23 (I2S1 Word Select)
27// SD (Data) → Pin 13 (I2S1 Data In)
28// L/R Select → GND (Left channel) or 3.3V (Right channel)
29// VDD → 3.3V
30// GND → GND
31// Note: MCLK (Pin 11) is automatically generated by Teensy Audio Library
32//
33// --- Teensy 4.x (I2S1) ---
34// INMP441 Pin → Teensy Pin
35// SCK (BCLK) → Pin 21 (I2S1 Bit Clock)
36// WS (LRCLK) → Pin 20 (I2S1 Word Select)
37// SD (Data) → Pin 8 (I2S1 Data In)
38// L/R Select → GND (Left channel) or 3.3V (Right channel)
39// VDD → 3.3V
40// GND → GND
41// Note: MCLK (Pin 23) is automatically generated by Teensy Audio Library
42//
43// --- Teensy 4.x (I2S2) ---
44// INMP441 Pin → Teensy Pin
45// SCK (BCLK) → Pin 4 (I2S2 Bit Clock)
46// WS (LRCLK) → Pin 3 (I2S2 Word Select)
47// SD (Data) → Pin 5 (I2S2 Data In)
48// L/R Select → GND (Left channel) or 3.3V (Right channel)
49// VDD → 3.3V
50// GND → GND
51// Note: MCLK (Pin 33) is automatically generated by Teensy Audio Library
52//
53// ============================================================================
54// MICROPHONE CONFIGURATION
55// ============================================================================
56// For the INMP441:
57// - Connect L/R pin to 3.3V to capture Right channel
58// - Connect L/R pin to GND to capture Left channel
59// - Single microphone: Connect L/R to 3.3V (Right is more common)
60//
61// ============================================================================
62// REQUIREMENTS
63// ============================================================================
64// - Teensy Audio Library (install via Arduino Library Manager)
65// - FastLED library
66//
67// ============================================================================
68
69// Select I2S Port (I2S1 is available on all Teensy 3.x and 4.x)
70// I2S2 is only available on Teensy 4.x
71#define USE_I2S_PORT fl::audio::TeensyI2S::I2SPort::I2S1
72
73// Select audio channel (Left or Right)
74// Match this to your INMP441 L/R pin connection
75#define AUDIO_CHANNEL fl::audio::AudioChannel::Right
76
77// Sample rate (Teensy Audio Library uses 44100 Hz)
78#define SAMPLE_RATE 44100
79
80// Platform-specific initialization delay (Teensy needs less startup time)
81#define PLATFORM_INIT_DELAY_MS 2000
82
83// Platform name for serial output
84#define PLATFORM_NAME "Teensy I2S Audio FastLED Example"
85
86// Create platform-specific Config
90
91// Print platform-specific setup information
92inline void printPlatformInfo() {
93#if defined(FL_IS_TEENSY_3X)
94 Serial.println("Detected: Teensy 3.x");
95 Serial.println("I2S1 pins: BCLK=9, MCLK=11, RX=13, LRCLK=23");
96#elif defined(FL_IS_TEENSY_40)
97 Serial.println("Detected: Teensy 4.0");
98 Serial.println("I2S1 pins: BCLK=21, MCLK=23, RX=8, LRCLK=20");
99 Serial.println("I2S2 pins: BCLK=4, MCLK=33, RX=5, LRCLK=3");
100#elif defined(FL_IS_TEENSY_41)
101 Serial.println("Detected: Teensy 4.1");
102 Serial.println("I2S1 pins: BCLK=21, MCLK=23, RX=8, LRCLK=20");
103 Serial.println("I2S2 pins: BCLK=4, MCLK=33, RX=5, LRCLK=3");
104#else
105 Serial.println("Detected: Teensy (model unknown)");
106#endif
107 Serial.print("Using I2S Port: ");
108 Serial.println(USE_I2S_PORT == fl::audio::TeensyI2S::I2SPort::I2S1 ? "I2S1" : "I2S2");
109 Serial.print("Channel: ");
110 Serial.println(AUDIO_CHANNEL == fl::audio::AudioChannel::Right ? "Right" : "Left");
111 Serial.print("Sample Rate: ");
112 Serial.println(SAMPLE_RATE);
113
114 Serial.println();
115 Serial.println("Troubleshooting:");
116 Serial.println("1. Install Teensy Audio Library from Arduino Library Manager");
117 Serial.println("2. Verify microphone wiring matches pin assignments above");
118 Serial.println("3. Check that microphone has 3.3V power and ground connections");
119}
fl::audio::Config createAudioConfig()
void printPlatformInfo()
#define AUDIO_CHANNEL
#define USE_I2S_PORT
#define SAMPLE_RATE
static Config CreateTeensyI2S(TeensyI2S::I2SPort port=TeensyI2S::I2SPort::I2S1, AudioChannel channel=AudioChannel::Right, u16 sample_rate=AUDIO_DEFAULT_SAMPLE_RATE, u8 bit_resolution=AUDIO_DEFAULT_BIT_RESOLUTION, MicProfile profile=MicProfile::GenericMEMS) FL_NOEXCEPT
Definition input.h:191
#define Serial
Definition serial.h:304