Comments on: MicroPython: ESP32/ESP8266 Asynchronous Programming – Run Multiple Tasks https://randomnerdtutorials.com/micropython-esp32-esp8266-asynchronous-programming/ Learn ESP8266, ESP32, Arduino, and Raspberry Pi Fri, 06 Dec 2024 19:01:46 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: wyzarddoc https://randomnerdtutorials.com/micropython-esp32-esp8266-asynchronous-programming/#comment-989292 Fri, 06 Dec 2024 19:01:46 +0000 https://randomnerdtutorials.com/?p=163461#comment-989292 Great tutorial!! Would this work or be the beginning for a network attached print server? I have a older printer that has a usb port for connection. I would like to attach a ESP32 usb port and allow it to pass the print commands to the printer over my local net work

]]>
By: Don https://randomnerdtutorials.com/micropython-esp32-esp8266-asynchronous-programming/#comment-985646 Sat, 23 Nov 2024 14:29:41 +0000 https://randomnerdtutorials.com/?p=163461#comment-985646 In reply to Sara Santos.

AFAIK C/C++ does not have a coroutine structure built-in to the language. I do see a few attempts to define a coroutine system for Arduino C/C++ using macros and ‘Duff’s device’ but I find the resulting code rather ugly and hard to read.

There are a number of libraries of task schedulers that have been written for Arduino C/C++ but I don’t know if any of them have gained any acceptance as the ‘right way to do it’.

]]>
By: Sara Santos https://randomnerdtutorials.com/micropython-esp32-esp8266-asynchronous-programming/#comment-985623 Sat, 23 Nov 2024 12:06:57 +0000 https://randomnerdtutorials.com/?p=163461#comment-985623 In reply to ChuckS.

Hi.
Thanks for noticing.
It’s fixed now.
Regards,
Sara

]]>
By: ChuckS https://randomnerdtutorials.com/micropython-esp32-esp8266-asynchronous-programming/#comment-985535 Sat, 23 Nov 2024 06:33:03 +0000 https://randomnerdtutorials.com/?p=163461#comment-985535 Hi Sara, This tutorial code has the same problem seen in the similar tutorial you just published for the RPi Pico. Namely the example code shows:

Define coroutine function

async def blink_blue_led():
while True:
blue_led.value(not blue_led.value())
await asyncio.sleep(1)

The line “await asyncio.sleep(1)” should have a sleep time of 2.0 Sec to agree with the description Green LED: GPIO 14 >> blinks every two seconds;

Note: The code snippet in the section “How the Code Works” shows the correct value.

]]>
By: Sara Santos https://randomnerdtutorials.com/micropython-esp32-esp8266-asynchronous-programming/#comment-985006 Thu, 21 Nov 2024 19:16:21 +0000 https://randomnerdtutorials.com/?p=163461#comment-985006 In reply to Don.

Hi.
Not yet.
I plan to write something similar using Arduino IDE.
Regards,
Sara

]]>
By: Don https://randomnerdtutorials.com/micropython-esp32-esp8266-asynchronous-programming/#comment-985002 Thu, 21 Nov 2024 19:08:37 +0000 https://randomnerdtutorials.com/?p=163461#comment-985002 Is there anything similar to this for Arduino C/C++ on the ESP32?

]]>
By: Dave https://randomnerdtutorials.com/micropython-esp32-esp8266-asynchronous-programming/#comment-984271 Tue, 19 Nov 2024 22:05:15 +0000 https://randomnerdtutorials.com/?p=163461#comment-984271 time.sleep() needs to be time.sleep(0)

Create and run the event loop

loop = asyncio.get_event_loop()
loop.create_task(main()) # Create a task to run the main function
loop.run_forever() # Run the event loop indefinitely

Is helpful as it shows what is happening in the background. In recent examples you now see a “one-liner”:

asyncio.run(main())

]]>