| Característica | Arduino UNO | Raspberry Pi 4 |
|---|---|---|
| Tipo | Microcontrolador — sem SO | Computador de placa única — Linux completo |
| CPU | ATmega328P 8-bit 16 MHz | Cortex-A72 64-bit 1.8 GHz (quad-core) |
| RAM | 2 KB SRAM | 2 / 4 / 8 GB LPDDR4 |
| Entradas analógicas | 6 × ADC 10-bit integrado | Nenhuma — precisa de ADC externo (ex: MCP3008) |
| GPIO | 14 digitais (6 PWM) + 6 analógicos | 40 pinos (26 GPIO usáveis) |
| Ideal para | Leitura de sensores, PWM, tempo real | Processamento, IA, rede, câmara, logging CSV |
| Consumo | ~50 mA | ~600 mA (RPi 4) |
| Tensão GPIO | 5V tolerante | 3.3V apenas — não tolera 5V nos GPIO! |
GPIO.setmode(GPIO.BCM) ou GPIO.setmode(GPIO.BOARD).| Função | Pino físico | BCM | Uso típico com Kit B 37 |
|---|---|---|---|
| 3.3V | 1, 17 | — | Alimentação de módulos 3.3V |
| 5V | 2, 4 | — | Alimentação de módulos 5V (cuidado com GPIO!) |
| GND | 6, 9, 14, 20, 25, 30, 34, 39 | — | Massa de todos os módulos |
| GPIO (entrada/saída) | 3,5,7,8,10,11,12,13,15,16,18,19,21,22,23,24,26,27,28,29,31,32,33,35,36,37,38,40 | 2–27 | Sensores e atuadores digitais |
| SDA (I²C) | 3 | GPIO2 | Display OLED, sensores I²C |
| SCL (I²C) | 5 | GPIO3 | Display OLED, sensores I²C |
| MOSI/MISO/SCLK (SPI) | 19/21/23 | GPIO10/9/11 | ADC externo MCP3008 |
Vai a raspberrypi.com/software e descarrega o Raspberry Pi Imager. Seleciona Raspberry Pi OS (64-bit) com Desktop.
Ao primeiro arranque, define localização (Portugal), teclado (PT), palavra-passe e rede WiFi.
Vai a Preferências → Raspberry Pi Configuration → Interfaces. Ativa: SSH, I²C, SPI (para ADC externo).
Abre o terminal e executa: sudo apt update && sudo apt upgrade -y
Normalmente já instalada. Para verificar: python3 -c 'import RPi.GPIO; print(RPi.GPIO.VERSION)'
import RPi.GPIO as GPIO
import time
# Configuração inicial
GPIO.setmode(GPIO.BCM) # Usar numeração BCM (GPIO17, etc.)
GPIO.setwarnings(False) # Suprimir avisos de pinos já em uso
# Configurar pinos
GPIO.setup(17, GPIO.OUT) # Pino GPIO17 como saída (LED)
GPIO.setup(27, GPIO.IN, # Pino GPIO27 como entrada
pull_up_down=GPIO.PUD_UP) # com pull-up interno
# Ler e escrever
GPIO.output(17, GPIO.HIGH) # Liga (3.3V no pino)
GPIO.output(17, GPIO.LOW) # Desliga (0V no pino)
estado = GPIO.input(27) # Lê HIGH ou LOW
# PWM (frequência em Hz, duty cycle 0–100%)
pwm = GPIO.PWM(18, 1000) # GPIO18, 1kHz
pwm.start(50) # 50% duty cycle
pwm.ChangeDutyCycle(75) # Altera para 75%
pwm.stop()
# Limpeza final — SEMPRE no fim do programa
GPIO.cleanup()#!/usr/bin/env python3
# LED Pisca no Raspberry Pi — equivalente ao Blink do Arduino
import RPi.GPIO as GPIO
import time
LED_PIN = 17 # GPIO17 → pino físico 11
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_PIN, GPIO.OUT)
try:
while True:
GPIO.output(LED_PIN, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(LED_PIN, GPIO.LOW)
time.sleep(0.5)
except KeyboardInterrupt:
GPIO.cleanup() # Ctrl+C → limpa os pinos
print("GPIO limpo. Programa terminado.")python3 led_pisca_pi.py no terminal. Para parar, pressiona Ctrl+C — o bloco except KeyboardInterrupt garante que os GPIO ficam limpos. Sempre inclui GPIO.cleanup() no final dos scripts.