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 running on host computer remotely through WIFi 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.
- ESP01 WiFi dongle.
- 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 USB cable. Connect ESP01 WiFi module to Aries Eco as shown in the above figure. 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.
Reconnect USB cable to Aries Eco to power up the board. After 3 seconds the blue light on ESP01 should give two or three short blinks indicating its readiness. On your host computer, open WiFi settings and connect to ‘CASP_RGPIO’ WiFi network with password ‘0000000000’.
Note: If the WiFi connection could not be established, try to power the ESP01 from 5V pin instead of 3.3V pin. After changing the pin, disconnect and re-connect the USB cable to re-power the board.
Run the basic Python script 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()
#establish communication with the board. loop till connection is established
connected: bool = False
while connected == False:
connected = rgpio.ConnectEth("192.168.2.1", 42001, False, 10, 20, 20) #ip, port, tcp, 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_aries_eco_esp01_wifi.pins
Target details:
Name: VegaAriesEco
Read size (bytes): 20
Write size (bytes): 20
Communication type: serial
Serial port: set during runtime
Serial baud: 0
Serial flow control (0-none, 1-dtr, 2-hardware, 3-software): 0
IP address: 192.168.2.1
IP port: 42001
"""
#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: 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()
#establish communication with the board. loop till connection is established
connected: bool = False
while connected == False:
connected = rgpio.ConnectEth("192.168.2.1", 42001, False, 10, 20, 20) #ip, port, tcp, 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()