Does ESP8266 has softuart module
-
- Posts: 363
- Joined: Sun Apr 17, 2016 1:55 pm
Does ESP8266 has softuart module
Does ESP8266's micropython has softuart module? Becasue I need more uart.
Re: Does ESP8266 has softuart module
No, it does not have a software UART. Implementing that in Python would possible, if 2400 Baud (or less) is sufficient. Anything faster has to be implemented in the firmware.
Re: Does ESP8266 has softuart module
The ESP8266 has a 2nd hardware UART, but it is TX only.
-
- Posts: 363
- Joined: Sun Apr 17, 2016 1:55 pm
Re: Does ESP8266 has softuart module
I hvae write a soft uart module today, it can works, but it can't receive a lot of continuous data.Roberthh wrote:No, it does not have a software UART. Implementing that in Python would possible, if 2400 Baud (or less) is sufficient. Anything faster has to be implemented in the firmware.
Re: Does ESP8266 has softuart module
That sounds very interesting. Are you willing to share this code with the community?I hvae write a soft uart module today, it can works, but it can't receive a lot of continuous data.
- JonHylands
- Posts: 69
- Joined: Sun Dec 29, 2013 1:33 am
Re: Does ESP8266 has softuart module
I would be interested in this also. I need to connect to a GPS, running at 9600 baud.shaoziyang wrote: I hvae write a soft uart module today, it can works, but it can't receive a lot of continuous data.
-
- Posts: 363
- Joined: Sun Apr 17, 2016 1:55 pm
Re: Does ESP8266 has softuart module
It is work fine with 1200bps, I have not test it for other baudrate, it maybe need to adjust self.bitdelay value.Roberthh wrote:That sounds very interesting. Are you willing to share this code with the community?I hvae write a soft uart module today, it can works, but it can't receive a lot of continuous data.
And in receive mode, it will loss data if receive continuous data.
Code: Select all
import time
import machine
from machine import Pin
class SOFTUART(object):
def __init__(self, tx, rx, baud = 1200):
self.tx = tx
self.rx = rx
self.tx.init(Pin.OUT)
self.rx.init(Pin.IN)
self.baud(baud)
self.timeout = False
def baud(self, baud):
self.bitdelay = 1000000 // baud - 200
def dt(self, dt=''):
if dt=='':
return self.bitdelay
else:
self.bitdelay = dt
def putc(self, dat):
self.tx(0)
time.sleep_us(self.bitdelay)
for i in range(8):
self.tx(dat%2)
dat = dat >> 1
time.sleep_us(self.bitdelay)
self.tx(1)
time.sleep_us(self.bitdelay)
def puts(self, str, cr=1):
for i in range(len(str)):
time.sleep_ms(1)
self.putc(ord(str[i]))
if cr > 0:
time.sleep_ms(1)
self.putc(0x0D)
def put(self, buf):
for i in range(len(buf)):
time.sleep_ms(1)
self.putc(buf[i])
def timeout(self):
return self.timeout
def getc(self, timeout=20):
t = 0
self.timeout = False
while self.rx():
time.sleep_us(20)
t = t + 1
if t < timeout*5:
pass
else:
self.timeout = True
return -1
time.sleep_us(self.bitdelay + self.bitdelay//8)
dat = 0
for i in range(8):
dat = dat >> 1
if self.rx():
dat = dat | 0x80
time.sleep_us(self.bitdelay)
time.sleep_us(self.bitdelay)
return dat
def get(self, num=0):
dat=bytearray(0)
while True:
t = self.getc()
if self.timeout:
return dat
else:
dat.append(t)
if num > 0:
if num > 1:
num = num - 1
else:
return dat
-
- Posts: 363
- Joined: Sun Apr 17, 2016 1:55 pm
Re: Does ESP8266 has softuart module
please see above, I have only test 1200bps.JonHylands wrote:I would be interested in this also. I need to connect to a GPS, running at 9600 baud.shaoziyang wrote: I hvae write a soft uart module today, it can works, but it can't receive a lot of continuous data.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Does ESP8266 has softuart module
See also http://forum.micropython.org/viewtopic.php?f=16&t=2204. I haven't tested it but it looks very promising.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.