• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Esp32 uart(0) (dedicated to REPL)

Q&A Forum › Category: ESP32 › Esp32 uart(0) (dedicated to REPL)
0 Vote Up Vote Down
Yi Jie Mun asked 6 years ago

Now, I am dealing with the MQTT which publishes data of “ON” or “OFF” to Adafruit.io feeds and got an error.

What I expected from the program, the on/off buttons will; switches every second on the adafruit.io dashboard.

image of ON/OFF buttons
What I saw on the other forum provided ways to solve the problem:

  1. unassigned UART0 from the REPL
  2. blocking stdin to read the line which related UART.

This is my code:

from MQTT import MQTTClient
from machine import Pin
import machine
import time
import Main2
from machine import UART
import os
uart = UART(0, 115200)
os.dupterm(uart)
def sub_cb(topic, msg):
print(msg)
wlan = Main2.get_connection()
if wlan is None:
print("Could not initialize the network connection.")
while True:
pass
client = MQTTClient("Id(i think this random)", "io.adafruit.com",user="Myaccountid", password=
"AIO-key", port=1881)
client.set_callback(sub_cb)
client.connect()
client.subscribe(topic="Myaccountid∕feeds∕afeed")
while True:
print("Sending ON")
client.publish(topic="Myaccountid∕feeds∕afeed", msg="ON")
time.sleep(2)
print("Sending OFF")
client.publish(topic="Myaccountid∕feeds∕afeed", msg="OFF")
time.sleep(2)

Shell result:

Traceback (most recent call last):
File "<stdin>", line 14, in <module>
ValueError: UART(0) is disabled (dedicated to REPL)
These are libraries link of MQTT,Main2(for connecting WIFI).
  1. Main2: github.com/tayfunulu/WiFiManager/blob/master/wifimgr.py
  2. MQTT: github.com/pycom/pycom-libraries/blob/master/examples/mqtt/mqtt.py
Question Tags: Adafruit.io, ESP32, UART(0)
3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi.
Why do you need to import UART? If you comment that line what happens?
Regards,
Sara

0 Vote Up Vote Down
Yi Jie Mun answered 6 years ago
from machine import UART
import os
uart = UART(0, 115200)
os.dupterm(uart)

I want to import UART for setting the esp32 in UART(0) with a baudrate at 115200 to access REPL

to create a serial communication way (i think it is a only way, is it ?)for the esp32 to communicate with adafruit.io.

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi.
I’m sorry for taking so long to get back to you.
I’ve never tried adafruit io with micropython.
But I’ve found this example: https://github.com/miketeachman/micropython-adafruit-mqtt-esp8266/blob/master/publishAdafruit.py
And it doesn’t use uart. It is compatible with the ESP32 and ESP8266.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.