LoRa Communication with nRF24L01 wireless module using CASP

This example project demonstrates LoRa wireless data transmission between host PC and two remote micro-controllers using three similar nRF24L01 wireless communication modules. We try to acquire analog data from the two remote micro-controller boards to the host PC wirelessly and plot the data on the host PC. We also try to control the on-board LED and PWMs present on the target boards from the host PC. Since the nRF24L01 modules supports only SPI communication, an intermediate micro-controller is required between host PC and nRF24L01 module at the host PC end.

Target

Aries Vega v3.0 and Arduino Nano development boards are used as the remote micro-controller boards connected to the respective nRF24 modules. As mentioned earlier, since nRF24L01 supports only SPI communication, Raspberry Pi Pico (RPiPIco) development board is used as an intermediate micro-controller between the host PC and the third nRF24 module. These micro-controller boards can be replaced with any other micro-controller board supported by CASP and 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 Vega Aries board for sensing. We use the on-board LED at pin GPIO24 and PWM0 for controlling. Similarly, Arduino Nano A0,A1 and PMW pins 5 and 6 are used for data acquisition and control. Data from the host PC is transferred to RPiPico through serial communication and from RPiPico to Vega Aries and Arduino Nano through wireless communication

Following are the steps to properly program the Vega Aries 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 ‘nrf24_target_vega’ project. Open the workspace file ‘nrf24_target_vega.wsp’ from CASP main window.

· 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 the nRF24 block parameters.

· For Aries Vega, SPI1 is selected for SPI communication. Choose suitable SPI interface if other micro-controller targets are used.

· Open Home->Simulation->Setup Simulation Parameters menu item. Under TargetHW->General tabs set ‘Target 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 properly program the Arduino Nano 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 ‘nrf24_target_nano’ project. Open the workspace file ‘nrf24_target_nano.wsp’ from CASP main window.

· 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 the nRF24 block parameters.

· Open Home->Simulation->Setup Simulation Parameters menu item. Under TargetHW->General tabs set ‘Target 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 properly program the Raspberry Pi Pico 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 ‘nrf24_target_pico’ project. Open the workspace file ‘nrf24_target_pico.wsp’ from CASP main window.

· 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 the nRF24 block parameters.

· Open Home->Simulation->Setup Simulation Parameters menu item. Under TargetHW->General tabs set ‘Target 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 ‘nRF24_target_native’ project. Open the workspace file ‘nRF24_native.wsp’.

· From ‘Serial’ block parameters enter the serial port to which the Arduino Nano is connected to the PC.

· Click on Run button to build and run the model.

Target and Native models are shown below

Screen shot of the output simulation panel running on host PC is shown below. User can control the on-board LED on Vega Aries board by toggling the switch (sw0) in SubWindow1.

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.