-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
ports/esp8266: Software Serial (SoftUART) support. #7784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
select.select now works.
Ensuring that timing is correct (to allow for 115200 baud).
Allows to work with 1200 baud or lower.
Used provided tools/codeformat.py.
Merge branch 'master' into esp8266-softuart
Now multiple instances of SoftUART possible. softuart.c: Removed os_printf calls (they reset my ESP). softuart.c: Moved validation to machine_softuart.c (as in regular UART). machine_softuart.c: Tx/Rx can now only be defined via constructor (as uart_id regular UART). machine_softuart.c: Unsupported parameters now raise ValueErrors.
esp8266/examples: Added 2 examples for SoftUART (read, write).
This sounds very useful. Has it been tested with uasyncio StreamReader and StreamWriter? |
No. EDIT Unfortunately I can't find any reference for how to use timers (God I wish It'd be as simple as avr). Anyone can help with some documentation about timers? This claims to use best practices but writing still blocks. EDIT 2 |
For what it is worth, I tested it out in a rather non-strenuous task: Decoding packets from IKEA's Vindriktning air quality sensor. It's a burst of about 120 bytes every 30s or so at 9600bps. It's been working great! My full project requires SoftI2C and MQTT running at the same time, but @MrJake222 's binary release doesn't include SoftI2C and it'll take a bit longer before I'm up to building my own. But I look forward to seeing if it still works when multiple timing-sensitive stacks are running. |
Thanks @MrJake222 ! This is definitely something we see a few requests for, and glad to hear from @mmmdwyer that it's working well. We probably need to clarify the license situation for the softuart code and ensure that we're compliant. My understanding is that it's almost exactly based on https://github.com/plieningerweb/esp8266-software-uart which is MIT, so at the very least we need to include attribution and copyright headers. It might also be possible to use it as a submodule instead? |
What do you mean? Like, making it separate from |
A git submodule. Like the other libraries in the |
Ahh like that... But which repository should it be linked to? |
In general, if this were a third-party library, then it should point to the upstream repo of that library. I think that's what plieningerweb is (unless you've made modifications?). That's why I was asking where the code comes from. I think in this case it's a small enough that the submodule is unnecessary, but we need to sort out exactly where this code comes from and what the license is. |
I've linked the forum link. There you can see that at least 3 people have attempted to port this. I've only adapted dmascord version (which I think based on p-v-o-s one, which is based on the original one). I'll ask him to clarify this. EDIT |
Hi guys, The code licensed is as per original MIT. It has been adapted from the code bases mentioned above, hardly any of the work is actually my own code, all I did was just making it work as a micropython module with a recent micropython build. I find the implementation quite stable at a variety of baud rates. I found some ports worked fine at 9600 and others at 115200, so combining what I could had it working at most baud rates, even higher than 115200. Cheers, Damien |
Same here, I've edited API a little bit, changed code style and commit message style to be compatible with this repo and that's about it. |
Hello. Great works! This PR will works with ESP32 too? Of course that I see the PR name as target ESP8266 ("ports/esp8266:"), but as ESP32 is from Espressif as well and a bit similar, I would like if will works. Thank you. |
I tested an old version of the code, and it worked fine on ESP32, so it should be fine, but can't guarantee. |
I've removed ESP32 code as I was unable to test it. |
Hey @MrJake222 @jimmo , what needs to be done next in order to get this into upstream? :) Can confirm that its working great for me with 9600 baud on this little project: |
This doesn't appear to implement the UART.any() method which should return the number of characters that can be read without blocking (the size of what is in the buffer) or simply 1 or 0 depending on whether there is anything to read. |
Is there any idea when this could be merged ? It's very demanded especially on 8266 devices. |
esp32software serial mr has been submitted, i have used for a long time, but till now to submit, you can refer this. #8829 |
Great work. Do you still have a copy of the esp32 code, I would be more than happy to test it out as I really need this feature! |
See original post for the links. See other repos. There should be some esp32 code. |
Thanks for the pointer, unfortunately I have struggled to integrate any of the linked code. I'm using an ESP32-S3 which requires idf V4.4 and I think this might be causing the problem. I'm getting a cryptic error I haven't come across before:
|
@MrJake222 I tested your repos and it seems to work well so far to communicate with SIM800L. But I have an issue with RXBufffer. when I read all SMS from SIM, some data is missed so I think it's related with rxbuffer. But there's no option to set RXBuffer in your SoftUART. |
You mean it's size? |
I documented the process of building my own firmware with SoftUART and micropython-lib here: https://gist.github.com/robtinkers/b653b045e3425903eff681d278e3823c I hope this helps someone out! |
…n-main Translations update from Hosted Weblate
This is an automated heads-up that we've just merged a Pull Request See #13763 A search suggests this PR might apply the STATIC macro to some C code. If it Although this is an automated message, feel free to @-reply to me directly if |
Software serial communication for ESP-8266
class SoftUART - half-duplex serial communication
SoftUART implements the standard UART/USART half-duplex serial communications protocol.
Supported communication parameters are:
Initialization
Constructors
class machine.SoftUART(tx=Pin(Tx), rx=Pin(Rx))
Tx
- pin used for data transmissionRx
- pin used for data receptionMethods
SoftUART.init(tx=Pin(Tx), rx=Pin(Rx), baudrate=9600, bits=8, parity=None, stop=1)
Basically constructor without additional memory allocation.
Tx
- pin used for data transmissionRx
- pin used for data receptionbaudrate
- data ratebits
- data bits (only 8 supported)parity
- data parity bit (only None supported)stop
- stop bits (only 1 supported)SoftUART.deinit()
Frees memory.
SoftUART.read(n)
SoftUART.readline()
Unreliable.
SoftUART.readinto()
Not tested.
SoftUART.write(buf)
Stream API
SoftUART supports stream API (
select.select
,select.poll
, etc.)Work done
Based on work of:
I did a clean-up, fixed code formatting, tried to stay as close as possible to
machine.UART
implementation. Examples.