Difference between revisions of "Template:Photo Interrupter Sensor Pico Guide"
m (Text replacement - "https://www.waveshare.com/w/upload/" to "https://files.waveshare.com/upload/") |
|||
Line 19: | Line 19: | ||
sudo apt-get install p7zip-full | sudo apt-get install p7zip-full | ||
cd ~ | cd ~ | ||
− | sudo wget https:// | + | sudo wget https://files.waveshare.com/upload/f/f6/Photo_Interrupter_Sensor_Demo.7z |
7z x Photo_Interrupter_Sensor_Demo.7z -o./Photo_Interrupter_Sensor_Demo | 7z x Photo_Interrupter_Sensor_Demo.7z -o./Photo_Interrupter_Sensor_Demo | ||
cd ~/Photo_Interrupter_Sensor_Demo | cd ~/Photo_Interrupter_Sensor_Demo |
Revision as of 06:53, 2 September 2023
Get Started at Pico
If you are the first time o use the Pico, you need to first learn how to get started at the Pico before you run other examples.
The Pico supports C and the Micropython which requires different firmware.
In most of the examples archives (Demo codes), we provide a Micropython firmware (uf2 file), we recommend you to use the provided firmware to test the board. Because the codes may run abnormally with different firmware.
If the board is tested to be workable, you can also download the newest firmware from Raspberry Pi and do further programming.
- If you want to use C codes, please refer to the C/C++ Guides
- If you want to use Micropython codes, please refer to the Micropython Guides.
- The link of the newest Micropython firmware of Pico
- Official Guides of Raspberry Pi Pico
Hardware Connection
Sensor | Pico | Description |
---|---|---|
VCC | 3.3V | Power input |
GMD | GND | Power ground |
DOUT | GP22 | Digital data output |
Download examples
Use Raspberry Pi as the host device. Open a terminal and run the following commands to download the example.
sudo apt-get install p7zip-full cd ~ sudo wget https://files.waveshare.com/upload/f/f6/Photo_Interrupter_Sensor_Demo.7z 7z x Photo_Interrupter_Sensor_Demo.7z -o./Photo_Interrupter_Sensor_Demo cd ~/Photo_Interrupter_Sensor_Demo cd Pico/c/build/
Examples
C codes
- Go into the c directory:
cd ~/Photo_Interrupter_Sensor_Demo/Pico/c/build
- Add the path of the SDK.
export PICO_SDK_PATH=../../pico-sdk
- Note that if the path of your SDK is different, you need to modify the command and use the correct path to export
- Generate Makefile and build.
cmake .. make -j9
- After building, a uf2 file is generated.
- Press and hold the button of Pico, connect it to Raspberry Pi then release the button.
- Copy/Drag the uf2 file to the portable disk (RPI-RP2) recognized.
cp main.uf2 /media/pi/RPI-RP2/
Micropython codes
Use in Windows
- 1. Press and hold the BOOTSET button on the Pico board, connect the Pico to the USB port of the computer through the Micro USB cable, and release the button after the computer recognizes a removable hard disk (RPI-RP2).
- 2. Copy the rp2-pico-20210418-v1.15.uf2 file in the python directory to the recognized removable disk (RPI-RP2).
- 3. Open Thonny IDE (Note: Use the latest version of Thonny, otherwise there is no Pico support package, the latest version under Windows is v3.3.3).
- 4. Click Tools->Settings->Interpreter, and select Pico and the corresponding port as shown in the figure.
- 5. File -> Open -> the corresponding .py file, click to run, as shown in the following figure:
This demo provides a simple program...
Use in Raspberry Pi
- Flash the Micropython firmware first.
- Open the Thonny IDE (Menu -> Programming -> Thonny Python IDE).
- 【Optional】If the Thonny IDE in the Raspberry Pi is not the new version that supports Pico, please upgrade it first.
sudo apt upgrade thonny
- Configure Interpreter, choose Tools -> Options... -> Interpreter, choose MicroPython (Raspberry Pi Pico) and the ttyACM0 port.
- Click File -> Open.. and browser the Micropython codes (Photo Interrupter Sensor.py) to run the codes.
Expected result
When a barrier is placed above the sensor, the signal indicator will turn on and the serial port will say "ON" or else the serial port will say "OFF".