Call custom py library
Friends who have used Python should know that Python supports calling custom py libraries (or third-party py libraries) in the same directory, and MicroPython also supports calling custom py libraries. Before calling the custom py library, the py library file needs to be imported into K210 in advance.
Import py library file
Here we take importing simplePID.py as an example.
There are two ways to import a custom py library. The first is to directly copy the custom py library file to the root directory of the memory card, and then insert the memory card to call it.
The second is to import through CanMV IDE, please refer to the following content for specific operations.
Open Tools->Save file to CanMV Cam.
Click Open, then select the py library file to be passed in, change the file name to simplePID.py, then click OK to start writing the file, and wait for the file writing to complete.
Note: The files written here are written to the memory card first.
Call py library
from simplePID import PID
print("import simplePID OK")
PID_controller = PID(0, 10, 0, 1)
print("PID test OK")
Run the above code, if it is normal, the test OK prompt message will be printed on the serial terminal at the bottom of the IDE.
If the simplePID.py file is not imported in advance, or the imported name does not correspond, an error will be prompted.