The main engine of the Modis Lock host module is a Raspberry Pi Compute Module 3. The CM3 module also uses an ARM core microcontroller to facilitate reliable communication with its remote reader modules.
Setting up an interface between a Raspberry Pi and a remote peripheral is pretty straight forward with the help of a few libraries such as RPi.GPIO and WiringPi. The final protocol used to communicate with the peripheral will depend on the specific needs of individual scenario as well as the protocols supported by the peripheral.
Most basic peripherals support protocols like UART, I2C, CAN, SPI and USB. Even wireless communication is possible now using WiFi and Bluetooth.
This guide will take a look at establishing a simple UART connection between a Raspberry Pi and an ARM core MCU using pyserial python library. We will use a Raspberry Pi 3 Model B running the Raspberry Foundation recommended Raspbian OS and a NUCLEO-F401RE development board by ST. This nucleo board has a STM32M401RE MCU. We’ll use ARM’s mbed platform to speed up the development on the MCU.
Mis en Place (Things you will need before starting):
- One Raspberry Pi (3 Model B in our case. Others are fine.) running Raspbian
- One NUCLEO-F401RE board
- One Mini USB cable to program and power the Nucleo board
- Three or more male-female jumper wires to connect Nucleo board with RPi 3
- One Micro USB cable and power supply for RPi3
Setting up the Nucleo Board using mbed
1.Connect the Nucleo board to your computer using a mini USB cable.
2. Sign up with ARM mbed developer account here if needed.
3. Log in to mbed and select ‘Compiler’ to open up online IDE.
4. Select ‘NUCLEO-F401RE’ on the top right of the IDE. and click ‘Select Platform’.
5. Select ‘New’ on the top right of the IDE, and ‘New Program.’
6. From the pop-up window double check the platform is selected as Nucleo-F401RE. Then from the ‘Template option’, select ‘Display a message on PC using UART.’
7. Name your program. The default is ‘Nucleo_printf’ in this case.
8. Select ‘OK’ to generate a template. There should be one file called main.cpp.
9. Change line 8 to read as ‘serial pc(PA_11, PA_12, 9600); // tx, rx’ so that we can use UART6 of the MCU for communicating with the RPi 3.
10. Open the main.cpp and click over the word ‘Serial’ on line 8. Click ‘A’ that appears on the top right to show more information about the UART function.
11. Clicking on the icon that appears next ‘A’ will reveal even more information about UART implementation in mbed environment.
12. Select ‘Compile’ from the top menu or hit ‘Ctrl-D’. It will save, compile the demo code and download the binary file to your computer. Now we can program or ‘flash’ the Nucleo MCU with that binary file.
13. Open a file browser and go to the download folder.
14. Locate the downloaded binary file (Nucleo_printf_NUCLEO_F401RE.bin in this case) as well as the Nucleo board. The Nucleo board should show up as a USB mounted storage device as if it was a USB thumbdrive.
15. Drag the binary file and drop it over the Nucleo board.
16. One of the LEDs on the Nucleo board will alternate between two colors while it’s ‘flashing’ the binary onto the MCU. Once flashing is complete, our program should start working right away. You should see another green LED (LD2) flash toggle every second as it’s instructed in the code (line 19).
17. You can now disconnect the board from your PC for the moment. The program will run as soon as it’s powered up next time. Now we will set up our RPi 3 to receive the signal in the next part.