CASP supports accessing micro-controller pins from a standard Python script on host computer through low latency serial or WiFi communication. This feature allows the micro-controller pins to be visualized as if they were part of the host computer. This example shows how to easily access Aries Eco pins from a Python script on host computer through serial communication. It also shows how to plot and control the data from a GUI based control panel invoked from a Python script.
The Python code in this example implements following logic
- Display ADC (pin-A1) and digital input pin (GPIO8) values
- Blink Aries Eco on-board blue LED
- Toggle digital output pin-GPIO2 value
- Vary PWM on pin-PWM2
- Vary Servo angle on pin-PWM7
Pre-Requisites
- Aries Eco board.
- Compatible USB cable.
- CASP software along with Vega Aries BSP is installed. From CASP GUI install CASP Python libraries. Please refer this page for details.
- Download the project zip file from this link and extract the downloaded file. The Python files are located in the ‘python’ folder of the extracted directory.
Procedure
- Connect Aries Eco board to the host computer through a serial cable.

Flashing Aries Eco with the binary file: On the Aries Eco board temporarily remove the BOOL SEL jumper and reset the board. In the extracted project directory, open terminal or command prompt in the ‘python’ folder and type the following command twice (without and with serial port as argument).
#first type the below command to display available serial ports in which Aries Eco serial port is one of them
python(or python3) rgpio_flasher.py
#now repeat the above command with serial port (to which the board is connected) as an argument
python(or python3) rgpio_flasher.py "COM3"
#the above command should program Aries Eco board with the hex file supporting python communication
Once the board is programmed, re-insert the BOOL SEL jumper, disconnect the USB cable. Connect suitable peripherals such as LDR or IR distance sensor to pin-A1, limit switch to pin-GPIO8, external LED or relay module to pin-GPIO2, DC motor driver module to pin-PWM2, servo to pin-PWM7 etc. of Aries Eco and re-connect the USB cable to the board.
Run the basic Python script file: Open ‘rgpio_from_pc.py’ in a text editor. Locate text “COM62” and replace it with the actual serial port to which Aries Eco board is connected. Save and close the file. Run terminal or command prompt in ‘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. Python script from ‘rgpio_from_pc.py’ file is shown below.
# This example demonstrates how to use CASP Remote GPIO from Python script that runs on host computer. Ensure matching target's casp_pins.py file in present in the script folder before running.
import sys
import time
#modify this path to point to 'casp_user_data/pycasp' directory in your system
#sys.path.append("C:/Users/AL/Documents/casp_user_data/pycasp/src")
import casp_rgpio as rgpio
import casp_pins as pins
#initialize GPIO instance
rgpio.Init()
#displays available serial ports
#rgpio.SerialPorts()
#establish communication with the board. loop till the connection is established
#modify serial port ("COM42") to which the target is connected on your system.
#to know about available serial ports, use above commented command.
connected: bool = False
while connected == False:
connected = rgpio.ConnectSerial("COM42", 115200, False, 1, 20, 20) #port, baud, enable_dtr, delay_msec, read_bytes, write_bytes
time.sleep(5)
#run a for loop to blink on-board LED, read ADC value and control pwm and servo every one second
pwm_val = 0
servo_val = -90
for i in range(1000):
di = rgpio.ReadDigital(pins.GPIO8_DI)
adc = rgpio.ReadAnalog(pins.A1)
print(f"di={di}, adc={adc}")
#
rgpio.WriteDigital(pins.LD1_B_DO, (i % 2)) #blink logic
rgpio.WriteDigital(pins.GPIO2_DO, (i % 2))
#
pwm_val += 50
if pwm_val > 4095:
pwm_val = 0
rgpio.WriteAnalog(pins.PWM2, pwm_val) #pwm control
#
servo_val += 10
if servo_val > 90:
servo_val = -90
rgpio.WriteAnalog(pins.PWM7_SERVO, servo_val) #servo control
#
time.sleep(1)
#close CASP GPIO instance
rgpio.Close()
The contents of ‘casp_pins.py’ file referred in above code is shown below
"""! Python module for GPIO pins from pin source: rgpio_vega_aries_eco_serial.pins
Target details:
Name: VegaAriesEco
Read size (bytes): 20
Write size (bytes): 20
Communication type: serial
Serial port: set during runtime
Serial baud: 115200
Serial flow control (0-none, 1-dtr, 2-hardware, 3-software): 0
IP address: set during runtime
IP port: 0
"""
#Pin details:
GPIO4_DI = 0 #DI0
GPIO5_DI = 1 #DI0
GPIO6_DI = 2 #DI0
GPIO7_DI = 3 #DI0
GPIO8_DI = 4 #DI0
GPIO9_DI = 5 #DI0
GPIO10_DI = 6 #DI0
GPIO0_DO = 0 #DO0
GPIO1_DO = 1 #DO0
GPIO2_DO = 2 #DO0
GPIO3_DO = 3 #DO0
LD1_G_DO = 4 #DO0
LD1_B_DO = 5 #DO0
LD1_R_DO = 6 #DO0
A0 = 2 #ADC
A1 = 4 #ADC
A2 = 6 #ADC
A3 = 8 #ADC
PWM0 = 2 #PWM
PWM1 = 4 #PWM
PWM2 = 6 #PWM
PWM3 = 8 #PWM
PWM4_SERVO = 10 #PWM
PWM5_SERVO = 12 #PWM
PWM6_SERVO = 14 #PWM
PWM7_SERVO = 16 #PWM
Run advanced Python script file that shows a GUI panel for plotting and control: Open ‘rgpio_from_pc_plot.py’ in a text editor. Locate text “COM62” and replace it with the actual serial port to which Aries Eco board is connected. Save and close the file. Run terminal or command prompt in ‘python’ folder.
- Run GUI Panel Server: Type python or python3 with ‘rgpio_plot_n_control_server.py’ as argument and press Enter key. This will start GUI panel server.
- Run the Python script: Type python or python3 with ‘rgpio_from_pc_plot.py’ as argument and press Enter key. The Python code should start communicating with the board and execute the implemented logic. Output control panel displaying pin values from Aries Eco board is shown below. You can control LED, DO, PWM and servo from the panel UI.

Python script from ‘rgpio_from_pc_plot.py’ file is shown below.
# This example demonstrates how to use CASP Remote GPIO from Python script that runs on host computer. Ensure matching target's casp_pins.py file in present in the script folder before running.
import sys
import time
#modify this path to point to 'casp_user_data/pycasp' directory in your system
#sys.path.append("C:/Users/AL/Documents/casp_user_data/pycasp/src")
import casp_rgpio as rgpio
import casp_pins as pins
import casp_udio
server = casp_udio.UdioClass()
server.ConnectEth("127.0.0.1", 42001, False, 1, 8, 8) #ip, port, tcp, delay, udi_size, udo_size
#initialize RGPIO instance
rgpio.Init()
#displays available serial ports
#rgpio.SerialPorts()
#establish communication with the board. loop till the connection is established
#modify serial port ("COM62") to which the target is connected on your system.
#to know about available serial ports, use above commented command.
connected: bool = False
while connected == False:
connected = rgpio.ConnectSerial("COM42", 115200, False, 1, 20, 20) #port, baud, enable_dtr, delay_msec, read_bytes, write_bytes
time.sleep(5)
#run a for loop to blink on-board LED, read ADC value and control pwm and servo every one second
for i in range(1000):
di = rgpio.ReadDigital(pins.GPIO8_DI) #digital input
adc = rgpio.ReadAnalog(pins.A1) #analog input
server.WriteI(0, di)
server.WriteI(1, adc)
print(f"di={di}, adc={adc}")
#
led_on = server.ReadI(0)
rgpio.WriteDigital(pins.LD1_B_DO, led_on) #led control
#
do_on = server.ReadI(1)
rgpio.WriteDigital(pins.GPIO2_DO, do_on) #digital output
#
pwm_val = server.ReadI(2)
rgpio.WriteAnalog(pins.PWM2, pwm_val) #pwm control
#
servo_val = server.ReadI(3)
rgpio.WriteAnalog(pins.PWM7_SERVO, servo_val) #servo control
#
time.sleep(0.05)
#close CASP GPIO instance
rgpio.Close()