from machine import Pin,SPI,I2C,SoftI2C,ADC,Timer,SDCard
import time
import framebuf
import os
import ssd1306
from wifi import WIFI
from mqtt import MQTT
PINO_LED_VERMELHO = Pin(3,Pin.OUT)
PINO_BTN = Pin(45,Pin.IN,Pin.PULL_UP)
PINOS_I2C = I2C(sda=Pin(14),scl=Pin(21))
PINO_RELAY = Pin(48,Pin.OUT)
PINO_ANALOGICO = ADC(Pin(1))
PINO_ANALOGICO.atten(ADC.ATTN_11DB)
PINO_ANALOGICO.width(ADC.WIDTH_12BIT)
# PINOS_I2C = SoftI2C(sda=Pin(14),scl=Pin(21))
PIXELS_X_OLED = 128
PIXELS_Y_OLED = 64
DISPLAY_OLED = ssd1306.SSD1306_I2C(PIXELS_X_OLED,PIXELS_Y_OLED,PINOS_I2C)
# NOME_REDE = "IFCE Alunos"
# SENHA_REDE = ""
NOME_REDE = "Wokwi-GUEST"
SENHA_REDE = ""
wifi = WIFI(NOME_REDE,SENHA_REDE)
wifi.conectar_rede()
MQTT_CLIENT_ID = "ESP"
MQTT_BROKER = "broker.emqx.io"
MQTT_USER=None
MQTT_PASSWORD=None
mqtt = MQTT(MQTT_BROKER)
mqtt.conectar_mqtt()
timer = Timer(0)
def manipular_led(PINO,value:int):
PINO.value(value)
def acender_led(tempo_segundos:int=1):
manipular_led(PINO_LED_VERMELHO,1)
print(f"valor pino: {PINO_LED_VERMELHO.value()}")
print("o barulho ai")
time.sleep(tempo_segundos)
manipular_led(PINO_LED_VERMELHO,0)
print(f"valor pino: {PINO_LED_VERMELHO.value()}")
print("sem barulho")
time.sleep(tempo_segundos)
def texto_oled(texto:str,posicao_x:int=0,posicao_y:int=0):
DISPLAY_OLED.fill(0)
DISPLAY_OLED.text(texto,posicao_x,posicao_y,1)
DISPLAY_OLED.show()
def imagem_oled():
# img_buffer = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xff\xff\xff\xf0\x00\x00\x0f\xe0\x00\x00\x00\x00\x00\x00\x00\x01\xff\xff\xff\xf0\x00\x00\x0f\xe0\x00\x00\x00\x00\x00\x00\x00\x1f\xff\xff\xff\xff\x00\x00\x0f\xe0\x00\x00\x00\x00\x00\x00\x00\x1f\xff\xff\xff\xff\x00\x00\x0f\xe0\x00\x00\x00\x00\x00\x00\x00\x1f\xff\xff\xff\xff\x00\x00\x0f\xe0\x00\x00\x00\x00\x00\x00\x00\x1f\xff\xff\xff\xff\xff\xff\xef\xff\x0f\xfd\xff\xef\xf8\x7f\xc0\x1f\xfe?\xff\xff\xff\xff\xff\xff\x9f\xff\xff\xff\xfd\xff\xf0\x1f\xfe\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x1f\xfe\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x1f\xfe\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x1f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x1f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x1f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x1f\xff\xff\xff\xff\xfb\xfb\xff\xef\xff\xff\xfe\xff\x7f\xff\xf8\x1f\xff\xff\xff\xff\xfb\xfb\xff\xef\xff\xff\xfc\xfe\x03\xff\xf8\x1f\xff\xff\xff\xff\xfb\xfb\xff\xef\xff\xff\xfc\xff\x7f\xff\xf8\x1f\xff\xff\xff\xff\xfb\xfb\xff\xff\xff\xff\xfc\xff\xff\xff\xf8\x1f\xff\xff\xff\xff\xfb\xfb\xff\xff\xff\xff\xfc\xff\xff\xff\xf8\x1f\xfe\x7f\xff\xff\xfb\xfb\xff\xff\xff\xff\xfc\x7f\xff\xff\xf8\x1f\xfe\x7f\xff\xff\xfb\xfb\xff\xff\xff\xff\xfc\x7f\xff\xff\xf8\x1f\xfe\x7f\xff\xff\xfb\xfb\xff\xff\xff\xff\xfc\x7f\xff\xff\xf8\x1f\xfe?\xff\xff\xfb\xfb\xff\xff\xff\xff\xfc?\xff\xff\xf8\x1f\xff\xff\xff\xff\xfb\xfb\xff\xff\xbf\xff\xfc?\xff\xff\xf8\x1f\xff\xff\xff\xff\xfb\xfb\xff\xff\x7f\xff\xfc\x0f\xf8\xff\xf8\x1f\xff\xff\xff\xff\x00\x00\x00\x00|\x00\x00\x00\x00\x00\x00\x0f\xff\xff\xff\xff\xe0\x00\x00\x00|\x00\x00\x00\x00\x00\x00\x01\xff\xff\xff\xf3\xe0\x00\x00\x00|\x01\xff\xbf\xdf\x00\x00\x01\xff\xff\xff\xf3\xe0\x00\x00\x00|\x01\xff\xff\xff\xc0\x00\x01\xff\xff\xff\xf3\xe0?\x01\xfc\x7f\xe1\xff\xff\xff\xc0\x00\x01\xff\xff\xff\xf7\xfe\xff\xc7\xff\x7f\xf9\xff\xff\xff\xc0\x00\x00\x1f\xff\xff\x07\xff\xff\xe7\xff\x7f\xfd\xff\xff\xff\xc0\x00\x00\x1f\xff\xff\x07\xff\xff\xef\xff\xff\xfd\xff\xff\xff\xc0\x00\x00\x1f\xff\xff\x07\xff\xff\xef\xff\xff\xfd\xff\xff\xff\xf0\x00\x00\x1f\xff\xff\x03\xe3\xff\xff\xff\xff\xfd\xff\xff\xff\xf0\x00\x00\x0f\xff\xff\x03\xe3\xf3\xff\xdf\xfe\xfd\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x03\xe3\xff\xff\x8f\xfc}\xef\xff\xff\xf0\x00\x00\x00\x00\x00\x03\xe3\xff\xff\x8f\xfc}\xef\xff\xff\xf0\x00\x00\x00\x00\x00\x03\xe3\xff\xff\x80|}\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x03\xe3\xff\xff\x80|}\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x03\xe3\xff\xff\x8f\xfc}\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x03\xe3\xe3\xef\x8f\xfc}\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x03\xf3\xf3\xef\xdf\xfc}\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x03\xff\xff\xef\xff\xfc}\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x03\xff\xff\xef\xff\xfc}\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x03\xff\xff\xef\xff\xfc}\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x01\xff\xff\xe7\xff|}\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x01\xfe\xff\xc3\xff|}\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xff\xff\xff\xf8\x00')
img_buffer = bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x0f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x07\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff?\xf0\x03\xff\xff\xff\xff\xff\xe0\x7f\xef\xff\xff\xff\xff\xfe\x1f\xf1\xe3\xff\xdc\xff\xff\xe0\x00?\xc7\xff\xbf\x83\xff\xfe\x1f\xf3\xe3\xff\x88\x7f\xff\xc0\x00?\xc7\xff\x1f\x00\x7f\xfe\x1f\xe3\xe3\xff\x88\xf7\xff\xc0\x0f\x7f\xc7\xfe\x1f\x00?\xfe\x0f\xe3\xe3\xff\x08\xe3\xff\xc0?\xff\xc3\xf8\x1f\x18\x1f\xfe\x0f\xe3\xe3\xff\x18\xe3\xff\xc4\x0f\xff\x81\xf0\x1f\x1f\x0f\xfe\x07\xe3\xe3\xff\x18\xe3\xff\xc7\x01\xff\x80\xc0\x1f\x1f\x87\xfe\x07\xe3\xe3\xfe\x18\xe3\xff\xc7\x80\xff\x88\x83\x1f\x1f\xc7\xfcC\xe3\xc3\xf8\x00\x01\xff\xc7\xf0\x7f\x88\x07\x1f\x1f\xc7\xfcc\xe0\x07\xf0\x00\x00\xff\xc7\xfc\xff\x8c\x1f\x1f\x1f\x87\xfcc\xe0\x07\xf8\x00\x01\xff\xc7\xff\xff\x8c\x7f\x1f\x00\x0f\xfcc\xe0\x0f\xfe\x1f\xe3\xff\xc7\xff\xff\x8c?\x1f\x00\x07\xfcq\xe0\x7f\xfe?\xe3\xff\xc0\x01\xff\x8e?\x1f\x00\x03\xf8\xf1\xe0?\xfe?\xe3\xff\xc0\x00\xff\x8e?\x1f\x1f\xc1\xf8\x01\xe2?\xfe?\xe3\xff\xc0\x01\xff\x8f\x7f\x1f\x1f\xf0\xf8\x01\xe3\x1f\xfe?\xe3\xff\xc7\xff\xff\x8f\xff\x1f\x1f\xf8\xf8\x01\xe3\x0f\xf0\x00\x00?\xc7\xff\xff\x8f\xff\x1f\x1f\xf8\xf8\xf0\xe3\x8f\xe0\x00\x00\x1f\xc7\xff\xff\x8f\xff\x1f\x1f\xf8\xf0\xf8\xe3\x87\xf0\x00\x00?\xc7\xff\xff\x8f\xff\x1f\x1f\xf8\xf1\xf8\xe3\xc7\xfe<c\xff\xc7\xff\xff\x8f\xff\x1f\x1f\xf8\xf1\xf8\xe3\xc3\xfe<c\xff\xc7\xff\xff\x8f\xff\x1f\x1f\xf0\xf1\xf8\xe3\xe3\xfe<c\xff\xc7\xff\xff\x8f\xff\x1f\x1f\xc0\xf1\xf8\xe3\xf7\xfe<w\xff\xe0\x00\x1f\xc7\xff\x1f\x0e\x01\xf1\xf8\xe3\xff\xff|\x7f\xff\xe0\x00\x0f\xc7\xff\x1f\x80\x07\xf1\xf8\xf7\xff\xff\xfe\xff\xff\xf0\x00\x1f\xef\xff\xbf\x80\x1f\xfb\xfd\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xd0\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf9\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x07\xf0\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x03\xf0\xff\xff\xc3\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x07\xf0\x7f\xff\x80\x0f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\xff\xf0?\xff\xc0\x03\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf1\xff\xf0?\xff\xf0\x00\xff\xbf\xff\xff\xff\xff\xff\xff\xff\xe3\xff\xf0\x1f\xff\xff\x80\x7f\x0f\xff\xff\xff\xff\xff\xff\xff\xe3\xff\xf1\x1f\xff\xff\x8c\xff\x00\xff\xff\xff\xf7\xf9\xff\xff\xe3\xff\xf1\x0f\xff\xff\x8f\xff\x00\x1f\xff\xff\xe3\xf0\xff\xff\xc7\xff\xf1\x8f\xff\xff\x8f\xff\x10\x0f\xfe\x07\xe3\xf0\xff\xff\xc7\xff\xe3\x8f\xff\xff\x8f\xff\x1e\x07\xf0\x03\xe3\xf0\xff\xff\xc7\xff\xe3\xc7\xff\xff\x8f\xff\x1f\xef\xe0\x07\xe3\xf0\xff\xff\xc7\xff\xe3\xc7\xff\xff\x8f\xff\x1f\xff\xe1\xff\xe3\xf0\xff\xff\x8f\xff\xe3\xc7\xff\xff\x8f\xff\x1f\xff\xc7\xff\xe3\xf8\xff\xff\x8f\xff\xe0\x03\xff\xff\x8f\xff\x10\x00\xc7\xff\xe3\xf8\xff\xff\x8f\xff\xe0\x03\xff\xff\x8f\xff\x00\x00G\xff\xe0\x00\xff\xff\x8f\xff\xc0\x03\xff\xff\x8f\xff\x10\x00\xc7\xff\xe0\x00\xff\xff\x8f\xff\xc7\xe3\xff\xff\x8f\xff\x1f\xff\xc7\xff\xe0\x00\xff\xff\x8f\xff\xc7\xe3\xff\xff\x8f\xff\x1f\xff\xc7\xff\xc3\xf8\xff\xff\x8f\xff\xc7\xe1\xff\xff\x8f\xff\x1f\xff\xc7\xff\xc3\xf8\xff\xff\x87\xff\x8f\xf1\xff\xff\x8f\xff\x1f\xfb\xe3\xff\xc3\xf8\xff\xff\xc3\xe7\x8f\xf1\xff\xff\x8f\xff\x00\x01\xe3\xff\xc3\xf8\xff\xff\xe0\x03\x8f\xf1\xff\xff\xdf\xff\x80\x01\xe1\xff\xc3\xf8\xff\xff\xf0\x07\x8f\xf1\xff\xff\xff\xff\xe0\x03\xf0\xf7\xc7\xf0\xff\xff\xf8\x0f\xdf\xfb\xff\xff\xff\xff\xff\xff\xf8\x03\xef\xf1\xff\xff')
print(len(img_buffer) == (PIXELS_X_OLED * PIXELS_Y_OLED) // 8)
img = framebuf.FrameBuffer(img_buffer,PIXELS_X_OLED,PIXELS_Y_OLED,framebuf.MONO_HLSB)
# img = framebuf.FrameBuffer(img_buffer,PIXELS_X_OLED,PIXELS_Y_OLED,framebuf.MONO_VLSB)
DISPLAY_OLED.fill(0)
DISPLAY_OLED.blit(img,0,0)
DISPLAY_OLED.show()
def endereco_oled():
print(f"endereço do display oled: {hex(PINOS_I2C.scan()[0])}\n")
def mudar_estado_relay(timer=None):
estado_relay = PINO_RELAY.value()
PINO_RELAY.value(not estado_relay)
def irq_handler(pin):
timer.init(mode=Timer.ONE_SHOT,period=300,callback=mudar_estado_relay)
PINO_BTN.irq(trigger=Pin.IRQ_FALLING,handler=irq_handler)
endereco_oled()
mqtt.sub(b"painel/tirar-foto")
while True:
# print(f"valor pino btn {PINO_BTN.value()}")
# time.sleep(2)
# acender_led(tempo_segundos=2)
# texto_oled("texto")
# time.sleep(3)
# texto_oled("outro texto")
# time.sleep(3)
# imagem_oled()
# time.sleep(5)
if not wifi.esta_conectado():
wifi.conectar_rede()
print("ta indo")
mqtt.check()
if mqtt.msg:
print("chegou")
topico = mqtt.topico.decode()
msg = mqtt.msg.decode()
if msg == "foto":
camera = b"fds"
mqtt.pub(b"painel/receber-foto",camera)
mqtt.msg = None
time.sleep(2.5)Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1
IO35 - Optacoplador(Entrada)
Observação:
IO36 - Optacoplador(Entrada)
IO41 -Pino Livre
IO42 -Pino Livre
IO43 - TX
IO44 - RX