controlling relay HELP!!!!!
-
im trying to control a relay using the m5stickc plus2 on g26
This is my code:
from M5 import * # Correct import for M5StickC in UIFlow 2.0
import timeSet GPIO pin for relay control (changed to GPIO 26)
RELAY_PIN = 26 # GPIO 26 for relay control
Initialize the relay pin as an output
relay_pin = M5.Pin(RELAY_PIN, M5.Pin.OUT) # Correct way to initialize the pin
Function to turn on relay
def turn_on_relay():
relay_pin.value(1) # Set relay pin to HIGH (turn on)Function to turn off relay
def turn_off_relay():
relay_pin.value(0) # Set relay pin to LOW (turn off)Main loop
while True:
try:
# Check if button A is pressed
if buttonA.isPressed():
turn_on_relay() # Turn on relay when button A is pressed
lcd.fill(0) # Clear the screen
lcd.text(50, 50, "Relay ON", color=lcd.WHITE, font=FONT_Default)
else:
turn_off_relay() # Turn off relay when button A is not pressed
lcd.fill(0) # Clear the screen
lcd.text(50, 50, "Relay OFF", color=lcd.WHITE, font=FONT_Default)time.sleep(0.1) # Small delay to avoid overwhelming the system except Exception as e: lcd.fill(0) # Clear the screen on error lcd.text(50, 50, f"Error: {e}", color=lcd.WHITE, font=FONT_Default) time.sleep(2) # Wait for a moment before trying again
this is the error im getting on uiflow2.0
Connected to Serial Port!
MicroPython v1.24.0-dirty on 2024-12-20; M5STACK StickC PLUS2 with ESP32(SPIRAM)
Type "help()" for more information.E (287120) i2c: i2c driver install error
E (287136) time: The current date/time in Shanghai is: Wed Jan 1 02:35:08 2025
E (287246) wifi:NAN WiFi stop
E (287248) transport_base: poll_read select error 113, errno = Software caused connection abort, fd = 54
E (287249) mqtt_client: Poll read error: 119, aborting connection
[INFO] Syncing resources...
[INFO] WiFi connected!
Traceback (most recent call last):
File "main.py", line 6, in <module>
NameError: name 'M5' isn't defined
MicroPython v1.24.0-dirty on 2024-12-20; M5STACK StickC PLUS2 with ESP32(SPIRAM)
Type "help()" for more information. -
Hello @EagleFPV
please have a look at the example I've just created in UIFlow2 Project Zone called: M5StickCPlus2_GPIO26_On_Off_UIFlow2.2.0
Thanks
Felix -
@felmue hola he visto que ayuda mucho a la comunidad.
¿Podria ayudarme a saber porque me sale este error?
estoy intentando conectar mi m5 tough a mi wifi pero me sale el siguiente error
E (328421) wifi:NAN WiFi stop
este es mi codigo
import networkwlan = network.WLAN(network.STA_IF)
wlan.active(True)Borra configuraciones anteriores
wlan.disconnect()
wlan.active(False)
wlan.active(True)
wlan.connect("TRC2021", "UoU@%0r3t6QON6ua")
if wlan.isconnected():
print("Conectado a WiFi con IP:", wlan.ifconfig()[0])
else:
print("No se pudo conectar a WiFi") -
Hello @sat-informatica
below code works for me:
import network wlan = network.WLAN(network.STA_IF) wlan.connect('SSID', 'Password') label0.setText(str('Connecting...')) while not (wlan.isconnected()): pass label0.setText(str('Connected'))
Thanks
Felix -
@felmue
Hello, I'm going to tell you everything I know and have tried so far.
I'm experiencing an issue with my M5 Hard devices. A few months ago, I purchased a couple of M5 Hard units for an MQTT data transmission project. I developed it in UIFlow 2, and everything worked perfectly.Recently, I bought more M5 Hard devices to expand the project, but now I’m facing a problem: when I install the firmware and try to connect them to WiFi, they won’t connect. I have tried the following without success:
Reinstalling the USB drivers on my computer.
Resetting the device to factory settings.
Reinstalling the firmware.
Trying different WiFi networks.
Temporarily disabling the firewall and antivirus.
Using different firmware versions.
Checking the router configuration and connection parameters.
Despite all these attempts, I still cannot connect them to WiFi. I’m getting the following error:arduino
Copiar
Editar
E (328401) wifi: sta is connecting, return error
Traceback (most recent call last):
File "<stdin>", line 19, in <module>
File "<stdin>", line 12, in setup
OSError: Wifi Internal Error
Additionally, I’m also getting this error:nginx
Copiar
Editar
E (328338) i2c: i2c driver install error
I don’t believe this is a network issue (firewall, antivirus, etc.) because, as I mentioned earlier, I have successfully programmed and connected other devices without any issues.I would really appreciate any suggestions or help.