CASP models can interface with hardware input outputs on embedded micro-controller boards. This example, demonstrates a model that interface GPS module (such as NEO, Ublox, Foxeer etc.) with micro-controller targets (such as Arduino) as well as with the native target.

Pre-Requisites

  • Arduino Leonardo board or any supported micro-controller board having dedicated serial port other than USB serial.
  • Any GPS module supporting UART/serial communication
  • CASP software is installed along with CASP Python Libraries.
  • Arduino BSP is installed.
  • The project files are located at CASP installed directory ‘CASP/support/examples/hardware_interface/11_gps’. These are also available for download at this link.

Description

For this example NEO-6M GPS module is used. It is connected to the target board as shown in the circuit diagram. If the GPS module supports USB interface it can also be connected to the host PC directly. This example shows both interfaces. Two models (one for micro-controller target and the other for the native target) are developed to communicate with the GPS module and measure some of the parameters such as time in hours, minutes and seconds and location in latitude and longitude. User can also measure other parameters by changing the block configuration.

On the micro-controller target the on-board LED blinks steadily if the GPS module position is locked. The measured values are sent to the USB serial port for viewing on the host PC. User can see the measured data from the ‘Configure Simulation Hardware’ interface window by clicking on Simulation->Configure Simulation IO menu item from the CASP main tool bar. A Python script is also provided that plots the data from the board.

On the native target the text box displays GPGGA formatted text received from the module. Please go through the individual block parameters used in the model along with respective documentation for better understanding.

CASP Model

Procedure to Read GPS Data from Computer Directly

  • Connect the GPS module to the computer, directly if dedicated USB cable is provided or use any USB to UART converter (eg. FT232 module) to connect the GPS module to the computer.
  • Run CASP and open the project ‘CASP/support/examples/hardware_interface/11_gps/11_gps.prj’ from CASP installed directory.
  • Set the target to native.
  • Inside the model, enable the left section with respect to the red vertical line and disable the right section.
  • Run the model to start simulation. The simulation should start and connect to the GPS module. Please note that GPS module may take some time to lock with the GPS satellites and display GPS data.

Procedure to Read GPS Data from Arduino

  • Connect the GPS module to the Arduino Leonard serial port.
  • Run CASP and open the project ‘CASP/support/examples/hardware_interface/11_gps/11_gps.prj’ from CASP installed directory.
  • Set the target to Arduino Leonard.
  • Inside the model, enable the right section with respect to the red vertical line and disable the left section.
  • Open ‘Setup Simulation’ window and change the ‘Target Programmer Port’ to which the board is connected.
  • Click Run button to build the model and program the board.
  • After the program starts running on the board the on-board LED starts blinking. GPS module may take some time to lock with the GPS satellites. Continuous glow of the on-board LED indicates that the GPS module has locked with the satellites.

Python Script

The Python script that plots the data from the Arduino board is shown below. The script file is available in the project directory. Within the script, change the serial port in the method ‘obj.InitSerialPort()’ to which the board is connected and run the script from Python terminal.

import casp
import casp_targets
import casp_defs
from models import casp_plot_n_control

#Initialize CASP
casp.Init()

# Create and open default project.
casp.ProjectOpenDefault()

# Instantiate class object
obj = casp_plot_n_control.Model(24,24)

# Initiate serial port. Change serial port with actual port to which the board is connected
obj.InitSerialPort("COM34") #serial_port_name, master
#obj.InitEthernet(False, False, "0.0.0.0", "0.0.0.0", 52001, "127.0.0.1", 42001) #server, tcp, gateway_ip, local_ip, local_port, remote_ip, remote_port

# Add plot
obj.AddDigitalMeter(False, 0, 3, "yy_mm_dd") #data_type_real, data_index, title
obj.AddPlotter(False, 3, 1, "gps_active_nsats") #data_type_real, data_index, data_size, title
obj.AddDigitalMeter(True, 4, 2, "latitude_longitude")

# Finalize plotter
obj.Finalize()

# Set simulation to real time (by setting simulation speed factor to 1).
casp.SimSetupSpeedFactor(1)

# Build and program the board.
casp.SimStart()

# Open project folder. Go through the log files (log_build_wnd.txt and log_msg_wnd.txt) in the project folder for any error/warning messages.
#casp.FolderProject()

# Promptly close CASP model editor program. simulation panel program will still be running.
casp.Close()

Related Links