Receiving IMU data with STM32F4 and transferring data to ROS based code via UART communication
I performed the programming of the STM32F4 card through the Windows operating system. I used STM32CubeIDE for programming the STM32F4 board. We set the I2c pins and UART pins that we will use using the STM32CubeIDE. After making the pin adjustments, we move on to the coding part of our STM32F4 floor. You can see the processes done during programming in the video on Youtube. Video-> https://www.youtube.com/watch?v=sQWgtBUbNjk
We used USB to TTL converter for UART communication. The connections of STM32F4 and USB to TTL converter should be as follows;
USB to TTL STM32F4
TXD -> PA3
RXD -> PA2
5V -> 5V
GND -> GNDWe used MPU6050 as IMU. The connection of MPU6050 and STM32F4 is as follows;
MPU6050 STM32F4
SCL -> PB6
SDA -> PB7
VCC -> 3V
GND -> GNDThe operations performed in this section were carried out on the Ubuntu 18.04 operating system. We can start by creating a ROS-based workspace.
$ source /opt/ros/melodic/setup.bash
$ mkdir -p ~/uart_ws/src
$ cd ~/uart_ws/
$ catkin_make
$ source devel/setup.bashLet's create the ROS package we will use.
$ cd ~/uart_ws/src
$ catkin_create_pkg uart_pkg std_msgs rospy roscpp
$ cd ~/uart_ws
$ catkin_make
$ source ~/uart_ws/devel/setup.bashAfter creating the ROS environment, we set our .xml and Cmake files according to the codes given above. We run the python files in the scripts folder as follows;
NOTE: Make sure you have UART communication before running the codes. Don't forget to connect the USB to TTL converter connected to the STM32F4 stage to the computer.
Use the following command to allow the USB port;
NOTE: The dev/ttyUSB0 part may differ for you.
$ sudo chmod 666 dev/ttyUSB0Let's make python files executable.
$ cd ~/uart_ws/src/uart_pkg/src/scripts
$ sudo chmod +x uart_pub.py
$ sudo chmod +x uart_sub.pyNow we are ready to run our code
$ cd ~/uart_ws
$ source ~/uart_ws/devel/setup.bash
$ roscoreLet's open a new terminal and run our python files
$ cd ~/uart_ws
$ source ~/uart_ws/devel/setup.bash
$ rosrun uart_pkg uart_pub.py
$ rosrun uart_pkg uart_sub.pyThat's it.