So you want to use the UART...

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
gpson
Posts: 3
Joined: Sun Jul 31, 2016 6:55 am

Re: So you want to use the UART...

Postby gpson » Sun Jul 31, 2016 7:15 am

I have Wemos D1 mini board and GPS module. Connected GPS Rx, Tx to Wemos Tx and Rx and trying the MP code from WebRTL

WHAT I TRIED

import machine
uart = machine.UART(0, 9600)
print( uart.readall() )

and the result is always None

When I connect GPS module over serial cable I see the output in the terminal on 9600 baud

THE QUESTION

is the MP modules not suitable for this task or I did something wrong?

torwag
Posts: 173
Joined: Fri Dec 13, 2013 9:25 am

Re: So you want to use the UART...

Postby torwag » Sun Jul 31, 2016 7:42 am

Hi,
first of all, check the voltage levels. Does the GPS module use 3.3V logic. The esp8266 works only with 3.3V, you might damage the chip applying 5V to the GPIOs. It was reported that it can scope with 5V but it is far out it's specs. Better to use level shifters in that case. Just to make sure, the GPS module uses TTL logic levels? That is logic 0 is around 0V and logic 1 around 3.3V (or 5V). There is also differential logic using negative and positive voltages.
Did you connect Rx to Tx and vice versa?
Hope that this gives a starting point.

gpson
Posts: 3
Joined: Sun Jul 31, 2016 6:55 am

Re: So you want to use the UART...

Postby gpson » Sun Jul 31, 2016 8:10 am

@torwag thank you for the suggestions

I'm using this GPS module: http://www.aliexpress.com/item/Gms-hpr- ... 92334.html

I tested this module with 3.3V serial cable - messages are coming

connected gpsTx->espRx and gpsRx->espTx, powered GPS VCC from 3.3V output on the Wemos D1 board.

User avatar
deshipu
Posts: 1036
Joined: Thu May 28, 2015 5:54 pm

Re: So you want to use the UART...

Postby deshipu » Sun Jul 31, 2016 8:29 am

You need to cross the data lines -- tx goes to rx, and rx goes to tx. And don't forget to connect gnd too.

torwag
Posts: 173
Joined: Fri Dec 13, 2013 9:25 am

Re: So you want to use the UART...

Postby torwag » Sun Jul 31, 2016 11:55 am

Ok, did you do the serial cable test by powering the gps module via the wemos board?
Could be that the voltage regulator on the wemos can't deliver enough power for both the esp8266 and the gps. Try an external power supply. The Gps unit is given with rather low power consumption but never trust specs on AliExpress. The esp8266 is a good example by itself, it shows current peak power consumption which can easily bring a weak power supply in trouble, even if it should work pretty fine looking at the average power consumption. This together with some possible peaks for the GPS might knock off the on board regulator.

gpson
Posts: 3
Joined: Sun Jul 31, 2016 6:55 am

Re: So you want to use the UART...

Postby gpson » Sun Jul 31, 2016 5:28 pm

Powered my Wemos d1 mini from external battery. OLED and GPS modules are powered from 3.3V Wemos output. Orange wire goes from gpsTx to espRx.

DSC_2735.JPG
DSC_2735.JPG (213.58 KiB) Viewed 1821 times


I took the orange cable out and connected to usb serial - you can see the result output in KiTTy window. New data is comming every second - 1Hz update rate.

When I connected the wire back to espRx, I started to get some data bursts from GPS module. Data is comming in random periods, not every second. And with data the control keys are coming - paste mode is activating and the webrepl is disconnecting.

Capture.PNG
Capture.PNG (204.4 KiB) Viewed 1821 times


Why GPS data is not captured to UART buffer? Any thoughts?..

mflmartin
Posts: 17
Joined: Sat Jul 23, 2016 7:30 pm

Re: So you want to use the UART...

Postby mflmartin » Sun Jul 31, 2016 11:51 pm

I successfully connected a Bluetooth HM-10 via UART to the ESP8266 (Just for testing the UART and learning).

I found that I had to use uart.read, more than uart.readall():

Code: Select all

from machine import I2C, Pin
import utime
from machine import UART

uart = UART(0, 9600)
uart.init(9600)

while True==True:
   val = uart.read()
   print(val)
   utime.sleep(1)


Also, maybe check that your battery is really providing 3.3 V to the ESP and 5.0V to your GPS module, with a multimeter. I can not see clear enough in the image. Does your board already incorporates a logic level converter? If not, you would need to interface both with it:

Image


I had also a problem with not getting back the readings, and it was because my battery was outputing 2.9ish volts. So was not enought for the bluetooth module (or the ESP) but everything seemed ON.

I hope it helps.

User avatar
pythoncoder
Posts: 1564
Joined: Fri Jul 18, 2014 8:01 am

Re: So you want to use the UART...

Postby pythoncoder » Mon Aug 01, 2016 10:12 am

@gpson The data looks as if it's terminated with a newline so I'd try the readline() method: this will block until either a line is received or the timeout elapses. Set the timeout to longer than the interval between messages so that in normal operation it won't occur. The issue of control characters is more of a problem: I'd query whether the GPS device should be sending them.

A previous post suggests that the solution to dealing with binary data is to put the device into raw REPL mode. The question is whether there is a way to do this programmatically.
Peter Hinch

BetterAutomations
Posts: 15
Joined: Mon Mar 20, 2017 10:22 pm

Re: So you want to use the UART...

Postby BetterAutomations » Mon Mar 20, 2017 11:07 pm

So is this circuit required when the ESP will be listening for a command? I wouldn't think so since it's on the TX line but I want to confirm.

In my case a Pi will send the 's' command to a listening ESP.

User avatar
pythoncoder
Posts: 1564
Joined: Fri Jul 18, 2014 8:01 am

Re: So you want to use the UART...

Postby pythoncoder » Tue Mar 21, 2017 7:46 am

The circuit is to ensure that the logic levels supplied to the ESP8266 don't exceed 3.3V.
Peter Hinch


Return to “ESP8266 boards”

Who is online

Users browsing this forum: No registered users and 2 guests