CASP RGPIO Arduino Uno Serial Example
This project demonstrates how to use CASP Remote GPIO (RGPIO) to control pins on Arduino Uno 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 Arduino Uno on-board LED at desired frequency settable at run time.
· Display digital input value at pin-2
· Plot ADC input value from pin-A0
· Control digital output on pin-12
· Control PWM output on pin-3
· Control servo connected to pin-9

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-A0) and digital input pin (pin-2) values
· Blink Arduino Uno on-board LED (pin-13)
· Toggle digital output pin-12 value
· Vary PWM value at pin-3
· Vary servo angle at pin-9

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

Preparing Arduino Uno For Supporting CASP RGPIO
· Within CASP open the project.
· Connect suitable peripherals such as LDR or IR distance sensor to pin-A0, limit switch to pin-2, external LED or relay module to pin-12, DC motor driver module to pin-3, servo to pin-9 etc of Arduino Uno.
· Connect Arduino Uno 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_arduino_uno_nano_r3_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 Arduino Uno. Arduino Uno 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_arduino_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.