pyboard UART -> GSM SIM800l module. Command responses aren't consistent

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
HStro
Posts: 6
Joined: Wed May 17, 2017 7:04 pm

pyboard UART -> GSM SIM800l module. Command responses aren't consistent

Post by HStro » Wed May 17, 2017 7:39 pm

Hi everyone!

So, bit of a strange issue here. I am using the GSM SIM800l module for internet.
(http://wiki.seeedstudio.com/images/4/46 ... _V1.00.pdf)

I have some code that has been tested with a Raspberry pi and also with my computer (via screen). The code is able to successfully send API requests to a server via the GSM. However, when I try the code with the pyboard, connected via UART, I am seeing erratic and inconsistent behaviour. Sometimes the commands that are sent to the GSM spontaneously fail and sometimes things go smoothly, where API requests are successful (albeit far less of the time!). There doesn't seem to be any consistency.

Does anyone have any suggestions as to how this inconsistency might arise?

Cheers for the help! Very much appreciated!
Harry

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: pyboard UART -> GSM SIM800l module. Command responses aren't consistent

Post by pythoncoder » Thu May 18, 2017 5:43 am

Unless someone else has the same hardware it's hard to see how anyone else can debug this. The approach I'd use is to use a logic analyser (you can get Chinese clones of the Saleae one for a few £/$). Put that on the UART lines, turn on the protocol analyser function, and examine what's going on. Perhaps it's a timing issue? Are you using UART flow control? Both the Pyboard and your chip support it.

As a general point the Pyboard UART code is widely used and has been extensively tested; I'd be surprised if it was causing the problem.
Peter Hinch
Index to my micropython libraries.

HStro
Posts: 6
Joined: Wed May 17, 2017 7:04 pm

Re: pyboard UART -> GSM SIM800l module. Command responses aren't consistent

Post by HStro » Fri Jun 09, 2017 8:56 am

Hi pythoncoder,

Firstly thank you very much for the reply! I must have missed the notification as I have only just seen it today.

Yes, I doubt there is an issue with the pyboard UART, but it is strange that it works fine via my laptop (via screen /dev/.... 9600) and then fails when connected to the pyboard.

For a bit more depth:
  • the most basic command does work (namely sending 'AT' to the GSM).
  • Sending others do successfully send and receive from the GSM, but the GSM returns 'ERROR' each time.
So it seems that the UART back and forth does work, but perhaps longer messages sent across (longer than just 'AT') could generate the error.

I tried using both UART.RTS and CTS but it caused no UART commands to work. I am not very experienced, so I am not entirely sure how to implement flow control, is it as simple as setting the parameter when initialising UART? I understand that it should fix issues that arise when the transmitter and receiver don't have the same capacity.

Thanks again for your help! Very much appreciated!

chuckbook
Posts: 135
Joined: Fri Oct 30, 2015 11:55 pm

Re: pyboard UART -> GSM SIM800l module. Command responses aren't consistent

Post by chuckbook » Fri Jun 09, 2017 10:01 am

What kind of power supply is used for the GSM module?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: pyboard UART -> GSM SIM800l module. Command responses aren't consistent

Post by pythoncoder » Sat Jun 10, 2017 5:27 am

Flow control works if the target hardware supports it. Connect the Pyboard's RTS to the target's CTS and vice versa. This ensures that, if a receive buffer becomes full, the transmitter will stop until space is available. Enable it on the Pyboard and it should work automatically.

Some units (rarely) use signals other than RTS and CTS for flow control. RTS on the Pyboard is an output, it needs to be connected to the target's flow control input. CTS on the Pyboard is the flow control input.

If it still doesn't work check the following. Along with power supplies - ensure there's a 0V link between the units - check logic levels. The Pyboard output logic 1 is 3.3V. It can tolerate input logic 1 levels of up to 5V. This is usually fine, but there are other standards.
Peter Hinch
Index to my micropython libraries.

HStro
Posts: 6
Joined: Wed May 17, 2017 7:04 pm

Re: pyboard UART -> GSM SIM800l module. Command responses aren't consistent

Post by HStro » Sat Jun 10, 2017 10:46 am

Hi guys. I hooked everything up again this morning and strangely the commands which were failing are now working. It is so hit and miss! Eventually I want to run the program in a mobile setting, so I would like to get it to a point where I can 99% trust it'll function :P

@chuckbook - I am using a 3.7v LiPo, like this one: https://shop.pimoroni.com/products/lipo ... 0wod8YIJMA. I am fairly sure that the battery is not the problem. To eliminate this uncertainty, I always test the same configuration with UART commands sent from my PC and then from the pyboard. As the commands work consistently from my PC in every test, I can (reasonably?) conclude that the changes in performance should be related to using the pyboard for UART control...

@pythoncoder - I had a look at the SIM800 documentation (https://cdn-shop.adafruit.com/product-f ... _V1.01.pdf). There is a software flow control option (page 12), but it says that it should not be used in TCP/IP applications, as binary data might be read in as flow control commands. There is then a stated hardware option, but I do not see CTS nor RTS ports on the SIM800l device. Here is an image showing the port options:http://www.uruktech.com/wp-content/uplo ... 800L-5.jpg. I do not have a logic analyser at the moment, but I will get one. I am grounding everything onto the pyboard so that should mean a shared 0V?

In the documentation, on page 12, it does state that "in the cases of a data or fax call, the sending device is transferring data faster that the receiving side is ready to accept...", so it does sound like this can become a problem and might explain why the PC is fine, but pyboard isn't? However, what I find strange is that the SIM device does return back a response successfully, it just returns "ERROR" which would indicate that either it is having trouble, or perhaps it isn't consistently reading in the longer UART commands properly?

Thanks for the responses!!

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: pyboard UART -> GSM SIM800l module. Command responses aren't consistent

Post by pythoncoder » Sun Jun 11, 2017 4:27 pm

The datasheet indicates that the device can auto-detect baud rate. It might be worth, for a test, setting the Pyboard UART to a lower baud rate. Send 'AT' repeatedly, checking each time for an 'OK' response (page 11). If it works at a low baud rate this would suggest that the device was losing characters and so issuing the 'ERROR' response. The datasheet refers to RTS and CTS but these don't seem to be brought out to pins on your module so hardware flow control looks not to be an option.

There are potential hazards with software flow control. I don't think the Pyboard supports it natively so you'd have to handle it on a character-by-character basis. I'd avoid if possible.

A slight concern is that the device specifies a maximum logic 1 voltage of 3.0V where the Pyboard will produce 3.3V. This could easily be fixed but I rather doubt that it's the cause of your problems. My guess is that the device is losing characters on input.
Peter Hinch
Index to my micropython libraries.

HStro
Posts: 6
Joined: Wed May 17, 2017 7:04 pm

Re: pyboard UART -> GSM SIM800l module. Command responses aren't consistent

Post by HStro » Sun Jun 18, 2017 7:27 pm

So, I tried the lower baud rate and the level I put it at didn't seem to work. I think there is a command to trigger the baud rate sync on the gsm but I need to look into it more.

I stopped going down that route because I noticed that the GSM was working very well and consistently at 9600 baud rate. I then realised that the ground cable I had between the GSM's battery and pyboard had broken off. So that means I had the GSM TX, RX and RST lines going to the pyboard, and then the GND and VIN from the GSM only connected to the LiPo battery.
I am not a hardware guy so the initial setup of also sharing the GSM - LiPo GND to the pyboard was advised to me (could someone explain why it was the right thing to do?). Whilst the GSM responds well the UART commands, the disconnected GND means that the RST line doesn't behave. I imagine this is because without the GND being set, it doesn't correctly form a circuit with the RST and pyboard?

I thought these events might help us determine what is going wrong with the GSM when the GND is connected properly and the UART command activity becomes inconsistent.

Thanks!

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: pyboard UART -> GSM SIM800l module. Command responses aren't consistent

Post by dhylands » Mon Jun 19, 2017 12:58 am

When you say a signal is high, what you're really saying is that that the voltage of the signal is 3.3v higher than the ground voltage. If you don't connect the grounds and the grounds between the two devices are at differential voltages relative to each other, then what looks like a high signal to one device might look like a low signal to a different device with a different ground reference.

HStro
Posts: 6
Joined: Wed May 17, 2017 7:04 pm

Re: pyboard UART -> GSM SIM800l module. Command responses aren't consistent

Post by HStro » Fri Jun 30, 2017 9:56 am

That makes sense. Still though, it is odd that disconnecting it causes the UART communication to be more consistent. Do you have any ideas as to why this might be?

Post Reply