CASP RGPIO Raspberry Pi Pico2 Serial Example
This project demonstrates how to use CASP Remote GPIO (RGPIO) to control pins on Raspberry Pi Pico2 target though serial communication. Similar procedure may be followed for other targets supporting RGPIO through serial communication. For details on RGPIO please refer CASP documentation. For demonstration purpose the target board pins are controlled through two approaches.
· From CASP block diagram model
· From Python
CASP Block Diagram Model Logic
The model shows following simple logics
· Blink Raspberry Pi Pico2 on-board LED at desired frequency settable at run time
· Display digital input value at pin-GP2
· Plot ADC input value from pin-GP26
· Control digital output on pin-GP6
· Control PWM output on pin-GP16
· Control servo connected to pin-GP10

Python Based Logic
The Python file along with pin definition file are located in the ‘python’ folder of the project directory. The Python code implements following logic,
· Display ADC (pin-GP26) and digital input pin (pin-GP2) values
· Blink Raspberry Pi Pico2 on-board LED
· Toggle digital output pin-GP6
· Vary PWM value at pin-GP16
· Vary servo angle at pin-GP10

Installing CASP And Required Components
The following steps may be followed to quickly run this example
· Install CASP along with BSP for Raspberry Pi Pico2. Run CASP. From main tool bar goto Tools -> CASP Python Libraries and click on ‘Install/Update’ to install CASP Python libraries.

Preparing Raspberry Pi Pico2 For Supporting CASP RGPIO
· Within CASP open the project.
· Connect suitable peripherals such as LDR or IR distance sensor to pin-GP26, limit switch to pin-GP2, external LED or relay module to pin-GP6, DC motor driver module to pin-GP16, servo to pin-GP10 etc of Raspberry Pi Pico2.
· Connect Raspberry Pi Pico2 to the host computer on which this example project was running.
· From main tool bar click ‘Setup Simulation’. In ‘Setup Simulation Parameters’ window ensure the RPGIO Pin Source is set to ‘rgpio_rpi_pico2_serial.pins’. Click RGPIO Settings ‘Configure’ button and set ‘Serial Port’ to which the board is connected. Click OK to close Remote GPIO Settings window and click Save and Close to close Setup Simulation Parameters window. Please refer below figure for better understanding.

· From CASP main tool bar select Tools tab and click on Programmer button. Follow the steps mentioned in below figure to program Raspberry Pi Pico2. Raspberry Pi Pico2 is now ready for RGPIO.
Running the CASP Model
· Things are now ready, just open the project in CASP as mentioned above, and click on Run button to build and run the project. Simulation Panel window should start and start communicating with the board as shown in below figure

Running Python Example
· Close the above window and run terminal or command prompt in ‘/rgpio_pico2_serial/python’ folder. Type python or python3 with ‘rgpio_from_pc.py’ as argument and press Enter key. The Python code should start communicating with the board and execute the implemented logic

References
Visit https://aadhuniklabs.com/casp-blog for various examples on CASP.