Question and Answer from Part 1
M5Stack Forum member Felmue aka Felix asks:
1, Trying Thonny and import units._ID0 causes a crash.
You can not use:
Trying this will cause a crash and restart. You have to import the library exactly as I have posted.
2, Where is _ID used?
_ID is a module name found under units in Micropython. I found this by running:
in Thonney using repel.
In example code ID_0 is defined as a sub class of module _ID.Finding the Micropython API's.
In the previous part of this guide I showed you how to use a few function but didn't cover how I found them. In this section I will show you how I found them.
For this I use the Thonny IDE https://thonny.org
When you open Thonny you will be presented with the view.
Plug in the Core2 AWS then click on Run > Select Interpreter to bring up the Thonny options window.
Set the options as shown but the Port or WebREPL address may be slightly different.
When you are returned to the main screen, Thonny will attempt to access the REPL on the Core2 AWS but throw up and error.Resize the shell box at the bottom as big as you can and then hit CTRL+C a few times to interrupt what program is running on the Core2 AWS and gain access to REPL.
Now that we are into REPL type:
and hit return. after a few seconds the shell panel will show a list of available modules installed in the micropython firmware.
What we are looking for is the module Unit/_ID. to access the module we first need to import the units function using:
from units import _ID
the module must be imported like this otherwise Kernal panics and/or Guru meditation faults will show causing the Core2 AWS to restart.
In order to gain access to the API's we first type:
to list the module and then type
To access the specific API's in the ID class.
Once I had access to this I next needed to define A class to start testing functions. To do this I had to import unit and then define a class as the subclass of unit!
ID_0 = unit.get(unit.ID, (21,22))
I used ID_0 for the identifier as this is what M5Stack used in the example code. I started testing various API functions using the print command to give me feedback on what each command did. The ID-0 has to be added before each API call or REPL with bring up errors.
ID_0 doesn't have to be used and could be replaced with something more informative like ATECC (the chip name) for example.
After all the experimentation I was still getting random crashes when accessing the TEACC608b to get around this I altered the code and came up with the following:
ATECC = unit.get(unit.ID, (21,22))
After this I was able to get a stable REPL without crashes.What was the source of the crashes?
First off, I am no expert and I don't understand what's happening but I suspect that the errors could be fulling up memory, causing the Guru errors. the gc.collect command is used to clean the esp32's memory and so I believe that could be helping.
This is as far as I have gone in order to get a stable connection and I am now able to test functions. In Part 3 I will try to explain the functions I have tested and what they do.Stalk/Contact me!
If you would like to reach out you can drop a message here or you can drop a message on our Facebook group here: https://www.facebook.com/groups/m5stack
The Official forums here: https://community.m5stack.com
Via Twitter : https://twitter.com/Cpt_J_Purcell