LoRa Communication with HC-12 using CASP

 

This example project demonstrates how to establish communication between host PC and a remote micro-controller using HC-12 wireless serial communication modules at both ends for LoRa wireless data transmission. We try to acquire analog data from the target board to the host PC through HC-12 wireless communication and plot the data on the host PC. We also try to control the on-board LED and PWM present on the target board from the host PC.

 

Target

Arduino Leonardo is used for this project. However, any micro-controller board supported by CASP can be used in similar manner.

 

Description

Connect the circuit as shown below. Connect any sensor to the ADC pin A0 and A1 of the target board for sensing. We use the on-board LED at pin-13 and PWM at pin-3 for controlling.

 

Following are the steps to properly program the target board.

·     Connect the target to the host PC via a USB cable.

·     Note the serial port number to which the board is connected to the host PC, from the host operating system.

·     Run CASP and load the ‘hc12_target’ project. Open the workspace file ‘hc12_target’.

·     All blocks are pre-configured for proper functioning. However, user may change the configuration of any block as required. By default data encryption is disabled user may enable the same in HC-12 block parameters.

·     For Arduino Leonardo ‘Serial1’ is selected in the HC-12 block as the serial interface for communicating with the module. Choose suitable serial interface if other micro-controller targets are used.

·     Open Home->Simulation->Setup Simulation Parameters menu item. Under TargetHW->General tabs set ‘Target Hardware Programmer Port’ parameter to the serial port to which the board is connected.

·     Build the model and program the board by clicking on Run button.

 

Following are the steps to run the native model on the native PC

·     Run another instance of CASP and load the ‘hc12_native’ project. Open the workspace file ‘hc12_native’.

·     From HC-12 block parameters enter the serial port to which the FTDI module is connected to the PC.

·     Click on Run button to build and run the model. Both devices should now communicate wirelessly.

 

Target and Native models are shown below

 

Screen shot of the output simulation panel running on host PC is shown below.

 

Debugging

Serial debugging can be enabled by selecting ‘Local & Remote‘ option from Setup Simulation->Build->Code Debug and re-building the project. The output can be viewed in ‘Serial Monitor’ window from CASP main window.

 

References

Please go through our video tutorials, tutorial projects and CASP main documentation for getting started with CASP.