Infrared Transmission & Reception
Infrared (IR) Communication
The Snake V1 features dedicated hardware for high-power infrared transmission and sensitive reception, allowing it to act as a universal remote, signal sniffer, or proximity sensor.
Hardware Specifications
The IR subsystem is built on two primary components:
- Transmitter (TX): Vishay TSAL6400 - A high-efficiency 940 nm infrared emitting diode. It is designed for high radiant power and high speed, capable of handling the high-frequency carrier pulses required for most consumer electronics.
- Receiver (RX): Vishay TSOP38238 - An IR receiver module tuned to a 38 kHz carrier frequency. It includes a photo detector, preamplifier, and internal filter for PCM frequency suppression, outputting a clean digital signal to the STM32.
Infrared Transmission (TX)
To transmit IR signals, the system uses a PWM-modulated carrier frequency (typically 38 kHz). The IR_Transmit interface allows you to send raw pulse-space timings or encoded protocol data (such as NEC, Sony, or RC5).
Usage Example: Sending a Raw Signal
If you have captured a raw signal (a sequence of microsecond durations), you can replay it using the following pattern:
// Example: Sending a simple 38kHz modulated raw burst
// Durations are in microseconds (us)
uint32_t raw_buffer[] = {9000, 4500, 560, 560, 560, 1690};
// snake_ir_send_raw(uint32_t* buffer, uint16_t length, uint16_t carrier_freq_hz)
snake_ir_send_raw(raw_buffer, 6, 38000);
Public Interface
| Function | Description |
| :--- | :--- |
| snake_ir_send_raw(timings, len, freq) | Transmits an array of pulse/space timings at a specific carrier frequency. |
| snake_ir_send_protocol(protocol_type, address, command) | Encodes and sends data using standard protocols (e.g., IR_PROTO_NEC). |
Infrared Reception (RX)
The TSOP38238 receiver simplifies signal processing by stripping the 38 kHz carrier frequency and providing a logic-level signal to the STM32WB35. The firmware uses an Input Capture timer to measure the duration of incoming pulses with microsecond precision.
Usage Example: Reading Incoming Signals
The reception interface is generally asynchronous, utilizing a callback or a polling buffer to retrieve decoded data.
// Initialize IR listening mode
snake_ir_rx_init();
// Check if a packet has been decoded
if (snake_ir_available()) {
ir_packet_t packet = snake_ir_read();
// Output protocol and data
printf("Protocol: %d | Address: 0x%02X | Cmd: 0x%02X\n",
packet.protocol, packet.address, packet.command);
}
Implementation Details
- Carrier Filtering: The receiver hardware automatically filters out IR noise (like sunlight or fluorescent lights) that does not match the 38 kHz modulation.
- Input Capture: The signal is routed to a hardware timer on the STM32. This ensures that timing measurements are not affected by CPU interrupt latency, providing high accuracy for "learning" unknown remote codes.
Configuration and Tuning
While the hardware is optimized for 38 kHz, the transmission carrier can be adjusted in software to support other common frequencies (e.g., 36 kHz, 40 kHz, or 56 kHz) if needed for specific proprietary devices.
Note: The TSOP38238 receiver is hardware-fixed to 38 kHz. While it may still detect signals at 36 kHz or 40 kHz, the range and sensitivity will be significantly reduced. For maximum performance with non-standard frequencies, ensure the Snake V1 is held in close proximity to the source.