
Como funciona
Um Sensirion SEN55 lido por I²C com o conjunto de comandos real: o script inicia a medição escrevendo 0x0021 no endereço 0x69, depois consulta o comando 0x03C4 e desempacota a resposta de 24 bytes em PM2.5 (escala ÷10), umidade (÷100) e temperatura (÷200), exatamente como um firmware de produção. O SEN55 fica no barramento de 5 V porque o ventilador dele é uma carga real; os pinos de dados compartilham o barramento I²C do C3 (SDA=G8, SCL=G9) com o SSD1306 que mostra as leituras da estação uma vez por segundo.
O que está na bancada
- ESP32-C3
- OLED 128×64
- SEN55
Como está ligado
- furo a10→furo B-5
- furo a11→furo B+5
- furo a30→furo B+9
- furo a31→furo B-9
- furo a32→furo a20
- furo a33→furo f11
- furo a34→furo B-9
- furo a40→furo B-9
- furo a41→furo f10
- furo a42→furo g11
- furo a43→furo b20
- ESP32-C3 · gnd→furo e10
- ESP32-C3 · vin→furo e11
- ESP32-C3 · g8→furo e20
- ESP32-C3 · 3v3→furo i10
- ESP32-C3 · g9→furo i11
O código
Este script MicroPython roda na placa emulada a cada inicialização. Edite-o em “Code”.
from machine import I2C, Pin import framebuf, time i = I2C(0, scl=Pin(9), sda=Pin(8), freq=100000) buf = bytearray(1024) fb = framebuf.FrameBuffer(buf, 128, 64, framebuf.MONO_VLSB) for c in b'\xae\xd5\x80\xa8\x3f\xd3\x00\x40\x8d\x14\x20\x00\xa1\xc8\xda\x12\x81\xcf\xd9\xf1\xdb\x40\xa4\xa6\xaf': i.writeto(0x3c, bytes([0, c])) def show(): i.writeto(0x3c, b'\x00\x21\x00\x7f\x22\x00\x07') i.writeto(0x3c, b'\x40' + buf) # Big digits: each pixel of the 8x8 font drawn as a k x k block def big(s, x, y, k): w = 8 * len(s) t = framebuf.FrameBuffer(bytearray(w), w, 8, framebuf.MONO_VLSB) t.text(s, 0, 0, 1) for cx in range(w): for cy in range(8): if t.pixel(cx, cy): fb.fill_rect(x + cx * k, y + cy * k, k, k, 1) # SEN55: CRC-8 (initial 0xff, polynomial 0x31), 20 ms command delay def read_words(command, count): i.writeto(0x69, command) time.sleep_ms(20) d = i.readfrom(0x69, count * 3) words = [] for k in range(count): a, b, checksum = d[k*3:k*3+3] crc = 0xff for value in (a, b): crc ^= value for bit in range(8): crc = ((crc << 1) ^ (0x31 if crc & 0x80 else 0)) & 0xff if crc != checksum: raise ValueError('SEN55 checksum mismatch') words.append((a << 8) | b) return words def signed(value): return value - 65536 if value & 0x8000 else value i.writeto(0x69, b'\x00\x21') time.sleep_ms(50) while True: if not read_words(b'\x02\x02', 1)[0]: time.sleep_ms(200) continue w = read_words(b'\x03\xc4', 8) if w[1] == 0xffff or w[4] in (0x7fff, 0xffff) or w[5] in (0x7fff, 0xffff): time.sleep(1) continue pm, rh, temp = w[1]/10, signed(w[4])/100, signed(w[5])/200 fb.fill(0) fb.text('PM2.5', 0, 0) fb.text('ug/m3', 88, 0) big('%.1f' % pm if pm < 100 else '%d' % pm, 0, 11, 3) fb.text('RH', 0, 37) fb.text('TEMP C', 64, 37) big('%d%%' % round(rh), 0, 48, 2) big('%.1f' % temp, 64, 48, 2) show() print('PM2.5', pm, 'RH', rh, 'T', temp) time.sleep(1)
Experimente
- Selecione o SEN55 e acompanhe a leitura de PM2.5 ao vivo (ambiente simulado). O valor varia sozinho; compare com as leituras no OLED e na serial.
- Dois dispositivos, um barramento: execute I2C(0, scl=Pin(9), sda=Pin(8)).scan() no REPL e encontre 0x3c e 0x69.
- Compare com o projeto do extrator de fumaça, que transforma essas mesmas leituras em controle do ventilador.
- Passe o cursor sobre o pino de alimentação do SEN55: 5 V, não 3V3. O ventilador precisa disso.



