I hope there is a moderator or staff member who reads this and can help and help rectify the issues.
I've been tinkering on MCU's for about 2 years, all different kinds, from Adafruit Metro's of various cpu types and Adafruit feathers and RPI Pico/PicoW.
I am fond of the Pico as it has been the first MCU I started this journey on and I got to know it well. I programmed it using pure C and the official SDK (not Arduino's weird version of c/c++) using Visual Studio code. Now that I have gotten into the PicoW and using Wifi trying to program and use that effectively in C is beyond my scope even with a dedicated book for it. I saw the MicroPython (MP) for wifi and saw how short the lines of code were so I embarked to learn MP for use with everything the Pico2040 does. I found MP very easy to learn, I'm no pro but can do just about anything I want in it sometimes with some help from google
.
I had seen the RP2040NANO from Arduino had been out for sometime, it seemed overpriced and with less functionality than a PicoW who size difference is maybe 1/2 smaller?
I started messing around using Adafruit's circuitpython which is essentially MP on a few MCU's and bam I'm on the internet, built the "weather station using openweather" and other things NTP server that uses GPS to get the most accurate time. Point is the code works and the documentation was a tad clunky sometimes I had to find different guides on their site on my own but in the end the projects were possible.
I decided to buy an RP2040NANO due to its 16MB of of flash storage, I do a lot of work with LCD screens and the Pico and PicoW only have 2MB of storage. Since the 2040 only has 264kb ram after installing MP you are left with about 190kb of usable ram which is not alot for displaying full color images on say a 3.2 or 3.5 inch screen. If the LCD has an SDcard I can use that other wise I have to use local storage to save images and read them there so they do not use up the frame buffer in ram. So not a lot of room for images. The NANO has 16MB so I figured ok that's plenty of space for images (though after MP install on the NANO i'm only left with 8.3MB) I noticed that the NANO's MP U2F is 1.1MB! Thats huge! why so big?? I'm used to anywhere from 160-600Kb for a MP U2F.
Ok that's the backstory. I was (am?) interested in the Arduino IoT implementation and reading on your website that MP is "Officially supported" I think that article is from 2021. I figured ok I want to get into the IoT space with something like Adruino IoT Cloud (I had only fiddled for a second with adafruit's IOT cloud which was impressively easy.
So I start to prep my NANO with MP per the directions on your website. My god. What a complete mess. Information scattered everywhere, other MCU's mixed in under the MP section instead of separate and unique pages for each MCU and how to get MP on it.
Let me pause and say first I tried connecting using Ardiuno's 'version' of c/c++ things worked great the simple blink the light on the 2040NANO worked, got it working on my phone, I'm thinking this is pretty awesome. (almost paid for the cloud membership right then and there). I had to use Arudino's IDE because surprise (for MP) you have to update the wifi chip's firmware to 1.50 to connect when using MP. I eventually found this in the documentation. So I used the IDE to update the firmware and install the certificates. Didn't go smoothly, IDE said it had installed it but when I tried to connect to your cloud it would find the board and get to the very end where it checks the firmware (which your documentation said it would update automatically as needed which was also appealing). The cloud completed my device was listed showing as (online) after I entered my wifi details on the web editors screen. I checked and sure enough my wifi firmware was still at 1.48. I went through the process about two more times on the IDE saying "firmware updated" yet the cloud was at 1.48. Finally after retrying several times it worked and now the cloud and manual checking of the firmware version showed indeed 1.5 was running. So now I was ready for MP. I flashed the chip from using Arudino's IDE platform to MP using the official MP for this exact MCU from MicroPython.org.
I pieced together the mixed steps all over the place. That's when things went horrible wrong and I'm still dealing with this mess. I followed all the instructions running the terminal commands on my Mac to get the serial number ect.. I installed the agent that runs in the background. I copied the "example MP" code and used the absolutely horrid "Arduino Lab for Micropython". Where I was reading that Micropython is considered experimental. Wait what your other page says its officially supported?!? So which is it?
I had followed all the instructions to use the command line to have it install the Arduino IoT libraries on my RP2040NANO. I tried to connect and immediately got an error "that it could not import "asynio" in one of the sub-modules -- mainly it was in the ucloud.py file.
I checked the modules loaded by MP there was no asyncio there was a uasyncio however. Before diving into this more deeply I went the the official github repository and downloaded all of the modules that had been imported by the terminal and basically overwrote them. I noticed some were larger in size the the originals so this gave me hope that the ones that were loaded from the command line terminal were maybe out of date (as I saw on github changes happening to the Arduino IoT packages daily. I manually replaced all the files with the latest on what you have on your official github page(s).
Tried again, same error can't find asyncio modules. I thought well maybe it has something to do with the fact I downloaded MP from MP.org directly. So I wiped the device and used Arduino's little app that installs MP. Took while it finished and checked the version, it was identical to the official MP release in terms of version numbers. I'm willing to bet the Arduino app just pulls it from the official MP repo. Either way I am now running MP that was loaded by Arduino's app. I have all the official Arduino libraries from github with wifi firmware 1.5.
Tried the example script to do a basic connect and control the led/switch. I built all of this in the cloud before adding the NANO as instructed. I added the 2040NANO to the cloud as "other" since it was running MP. It added the device and it was showing offline.
Back to the example code provided. I try to run it. Bam immediately the same asyncio error. A quick Googling and checking the official MP documentation it appears that asyncio is for python not Micropython. At this point I'm confused and angry...
I have no choice but to dive into the ucloud.py file provided to me and poke around, sure enough its trying to import asyncio. I start changing this modules code to usyncio I started getting further in the connect process. Another error, another place in ucloud.py that was reference asyncio. Replaced it. Tried again, got a little further then a similar type error. Went back to ucloud.py and just decided to heck with it I'm replacing all instances of asyncio with uasyncio.
Run the example hey look at the its running! Sort of!
Now I have sporadic behavior when trying to connect...seems like a different error each time I try to connect.
-
RTC time set from NTP. --->this would time out sometimes other times it would not, I added a delay which helped reduced the amount times it would timeout but it still happens just less often.
-
task: ledSwitch created.
task: conn_task created.
Connecting to Arduino IoT cloud...
This would lead to random errors of timeouts
Sometimes I would get "index is out of range (presumably for my cloud passcode in secrets.py?)"
not very many maybe 1 in 20 tries I would get past this no errors (I quickly check the cloud and I see the device as online)
- task: discovery created.
task: mqtt_task created.
Subscribe: b'/a/d/MY SECRET CLOUD ID PROVIDED BY THE CLOUD/e/i'.
task: discovery complete.
at this point I'm seeing my device as online but I know more connections are coming so this online status is going to be short lived...
- task: conn_task raised exception: can't gather.
This one is the death nail. I tried to trace down in the module but I can't figure it out. This is the point where the IDE just sits there doing nothing printing nothing.
My device is now offline in the cloud and I'm dead in the water.
I cannot help but squarely blame Arduino for this failure(s).
-
I had to hack the heck of the modules to point them to uasyncio to even get started
-
In consistent connection errors as talked about
-
Ultimately the example code does not work the final error of "conn_task raised exception: can't gather." brings me to a hard stop. I have no idea what to hack, or if my hacking led this condition. Unless someone can help me out from Arduino or another brilliant mind I wont be buying anymore 2040NANO's (I was read to buy a ton for all my different projects). I am so glad I didn't pay for a cloud subscription when it was working using the baked in sketches as examples.
-
Arduino needs to explain why there code includes asyncio calls when that module simple is not in the MP build. Seems like a half baked try slap something together and not "a fully supported language" as advertised. A fully supported MP would have example code that calls only MP modules OR adds the said modules to the MP installer package they put out.
-
I had also purchased an NANO ESP32, which I'm going to see how that behavior differs.
Arduino - please help me understand/fix the asyncio issue and the "task: conn_task raised exception: can't gather." Or else I'm ditching all of it I'll just use the RP2040 with MP for some project that doesn't require much/wifi which would be a disappointment.
Here is a full output of the "best" case scenario which still results is the connection in the could dropping immediately upon the last message.
MPY: soft reboot
19:55:37.000 WiFi Connected ('192.168.1.83', '255.255.255.0', '192.168.1.1', '192.168.1.1')
23:55:46.000 RTC time set from NTP.
23:55:46.000 task: ledSwitch created.
23:55:46.000 task: conn_task created.
23:55:46.000 Connecting to Arduino IoT cloud...
23:55:57.000 task: discovery created. <----device shows online in the cloud
23:55:57.000 task: mqtt_task created.
23:55:57.000 Subscribe: b'/a/d/CLOUD SECRET KEY NOT POSTED HERE OF COURSE/e/i'.
23:55:59.000 task: discovery complete. <------online up to this point
23:55:59.000 task: conn_task raised exception: can't gather. <----device now offline and the IDE doest error out it just sits there.
Help.