Don’t Push Me¶
Let us give Pico-4wd a little self-protection awareness and let it learn to use its own grayscale module to avoid rushing down the cliff.
In this example, the car will be dormant. If you push it to a cliff, it will be awakened urgently, then back up, and shake its head to express dissatisfaction.
How to do？
Select Correct Interpreter
Plug the Pico into your computer with a micro USB cable and select the “MicroPython (Raspberry Pi Pico).COMXX” interpreter in the bottom right corner.
Go to the
pico_4wd_car_main/examplespath and double click on
donot_push_me.pyto open it.
Click the Run current script button or just press F5 to run it.
After the code runs, if you push it to a cliff, it will be awakened urgently, then back up, and shake its head to express dissatisfaction.
If the result is not satisfactory, please modify the fourth line
car.GRAYSCALE_EDGE_REFERENCE = 1000.
This is a threshold that tells the car if the grayscale sensor detected values are below 1000, then it should be considered a cliff and can move backward.
This threshold can be obtained in the Test the Grayscale Sensor Module section, for example, in my test, the detected cliff value is basically around 700, so here it is set to 1000, as long as it is lower than 1000, it can be considered to detect a cliff.
To enable Pico-4wd to run this code on boot, you need to save
donot_push_me.pyto the Raspberry Pi Pico as
main.py, as follows.
Stop the script from running and click File -> Save as.
Select Raspberry Pi Pico in the popup window that appears.
Set the file name to
After clicking OK, the Raspberry Pi Pico will have an additional
Afterwards, you can unplug the USB cable, turn on the power switch on the car, and the script
main.pywill begin running.
How it Work?