Uart communication

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
misisnik
Posts: 5
Joined: Wed Jan 17, 2018 7:29 am

Uart communication

Post by misisnik » Wed Jan 17, 2018 7:40 am

Hello

I have a problem with UART0 communication with my PC from ESP8266.
My main.py code looks like (it should send magnetometer data throw UART)
from machine import Pin, I2C
from lsm303e import LSM303
import time
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
lsm303 = LSM303(i2c)

p2 = Pin(2, Pin.OUT)
#and send the data
from machine import UART

uart = UART(0, 9600)
uart.init(9600, bits=8, parity=None, stop=1)

while 1:
time.sleep(0.001)
uart.write(str(lsm303.mag_read())+'\n')

And when I want to read this data in my PC (I am using cp2100), none of the data had come. UART REPL mode in boot.py is running without problem with this usb to uart converter.

My python code in my PC for reading uart data is:
import serial
import time
ser = serial.Serial('/dev/ttyUSB0', 9600)
while 1:
print(str(ser.readline()))
time.sleep(0.5)

Where is problem? I have not see any :)
THX Mike

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Uart communication

Post by Roberthh » Wed Jan 17, 2018 11:18 am

Since UART0 ist used for REPL, you can on the ESP8266 simple print() what you want to send. No need to use the UART API.

Post Reply