Introduction
In the previous blog, I have used Nucleo board to measure the signal and just pass the measurement to Jetson nano. We did some processing on Jetson and developed a logic to detect high and annoying vibrations that We could create. This logic was running on Jetson nano. In this blog we are trying to remove the Jetson Nano as the signal processor and do the FFT calculation and Signal Processing on the Nucleo Board. I would still use Jetson Nano as a remote programmer and debugger for my Nucleo board. In this blog I am also demoing the end to end prototype from measurement on Nucleo board, send a notification via Bluetooth to send notification via a telegram bot.
REMOTELY Programming and Debugging the Nucleo Board (via WiFi)
I recently learned from this guy https://youtu.be/p1-S9G3pl4I that I can remotely program and debug my code on Nucleo board without disconnecting it from Jetson board and connecting it to my workstation. This is really amazing. I have a short video demoing it. It may be useful to others as well. If you do not know why this is very useful to me, please have a look at my previous blog (#4) to read about my measurement setup.
Detecting Vibration on Nucleo Board alone (No Jetson Nano Anymore)
Here I managed to implement the same detection that we had in python in previous blog now in C and all in Nucleo board. I had to fine tune it a bit more. Because FFT library in CMSIS only accepts the signals of length with power of 2. So now I am using 512 samples and also I would check the frequencies between 75 Hz and 85 Hz only. Checking for higher frequency like until 150 Hz made the detection too sensitive in a way that when I was dropping something on the table 2 meters away, it was detecting it. We do not want that much sensitivity. Here is a short demo of working example. The notification system is a green LED, so make sure you watch the video with enough high quality that the LED would be visible. The LED stays on for one second when it detects vibration.
You may find the code on my GitHub. The link is at the exact commit that I used here. On Blog #3 we have discussed briefly on how to calculate FFT on Nucleo board and how to use the CMSIS library for that, I am using mostly the same code with a bit of refactoring and small added logic.
Bluetooth Working
This is the first time I am using Bluetooth as a developer and not a user. I spent a lot of time at the end of 2020 on learning the BLE and Bluetooth and how it works. It seems very complicated but fortunately there are a lot of good examples for it on the STM32CubeIDE to get started.
The BLE expansion board needs a small modification to make it work with the NUCLEO-H7 board. On the expansion board the R6 is not soldered by default. And it is needed to be filled with a zero ohm resistor. Then all of the SPI and other pins would be compatible with this specific board.
I have added a lot of resources to learn about BLE at the end of this blog in "Related Links" section. You can check them out if you are interested. Two of them is about how to setup the STM development environment to work with BLE. They are using old development platforms but it should be easy to transfer that knowledge to the new STM32CubeIDE.
I developed most of the BLE code before knowing what I am going to do with it exactly so I have defined too many services. I am just using one of them for now to notify the BLE client. Here is a short video of getting notification on "ST BLE Sensor" application on my android phone. This is only for testing if the BLE application on the Nulceo board works. So it is not clean or user friendly. Here is a short video of it. I am using scrcpy to control and capture the screen of my android phone on Ubuntu.
End to End Prototype Working
So I got the end to end prototype working. By end to end I mean:
- Nucleo board measures the output of the Kemet Sensor at frequency of 1 kHz using a timer and ADC
- A DMA is triggered at end of each conversions to a buffer with length of 512 values.
- When the buffer is full, the FFT calculation is done on the buffer.
- The value of FFT is checked for frequencies between 75 Hz and 85 Hz and if they are higher than 15, A notification is triggered.
- There is a small difference here from when we were calculating the FFT on Jetson Nano. On Jetson Nano we were calculating FFT every few samples like having a circular buffer. But on Nucleo board, each calculation of FFT is being done on a bunch of completely new data. So if the vibration is too short and it exactly happens at close to the end of the buffer, it may not trigger the notification threshold.
- The notification is being sent via BLE to a BLE client.
- In the demo below I have a python script as the BLE client which uses the workstation's Bluetooth to connect to the Nucleo board. This can run on any PC. Even a raspberry pi or the Jetson nano with BLE module as a hub.
- The BLE client sends a message to a telegram bot to notify me on my smart phone.
Related Links
- Resources about Bluetooth:
- X CUBE BLE1 for STM32CubeMX: https://youtu.be/eiknW5Ml9dA
- STM32CubeMX- easy integration - 01 Introduction and agenda: https://youtu.be/YtII8hNxgfk
- STM32CubeMX- easy integration - 02 Creating STM32 BLE - STM32CubeMX: https://youtu.be/jGSdMAFVI_U
- STM32CubeMX- easy integration - 03 Creating STM32 BLE - TrueStudio: https://youtu.be/fS_ZQqa7rXI
- MOOC - STM32WB workshop: https://youtube.com/playlist?list=PLnMKNibPkDnGRfqUO1Q_-1nW-tOKfDQbc
- Bluetooth Low Energy Series: https://www.youtube.com/playlist?list=PLSdxNjcHc0u9PdQSd3l3-gDJGzJ_eB50f
- Introduction to BLE by Adafruit: https://learn.adafruit.com/introduction-to-bluetooth-low-energy/introduction
- About GATT and BLE https://www.bluetooth.com/specifications/gatt/
- Python Library for BLE: gattlib
- Telegram Bot
- Python Telegram Bot Library
Top Comments