📺 Infravermelhos (IR)
Receber e descodificar sinais IR de um comando remoto. Controlar saídas GPIO sem fios. Instalar e configurar LIRC no Raspberry Pi OS.
Instalar LIRC
Terminal
sudo apt install lirc -y # Editar /boot/config.txt — adicionar linha: # dtoverlay=gpio-ir,gpio_pin=17 sudo nano /boot/config.txt
Circuito
VS1838B OUT → GPIO 17
VS1838B VCC → 3.3V
VS1838B GND → GND
Exercício — Ler teclas do comando
Python · ir_receber.py
import subprocess, time print("A aguardar sinal IR... (Ctrl+C para parar)") while True: try: # Usar irw para ler eventos LIRC proc = subprocess.Popen( ['irw'], stdout=subprocess.PIPE) for linha in proc.stdout: print(f"Recebido: {linha.decode().strip()}") except KeyboardInterrupt: break