The simulation project involves creating a physical and virtual dashboard for a tractor using various components:
- Physical Simulation: Includes a breadboard, 2 potentiometers, 2 LEDS, 1 LCD, a matrix keypad, and various jumper cables.
- LCD: Displays data such as current gear, direction, speed, and engine speed of the tractor.
- LEDs: Used to simulate the tractor's blinkers.
- Potentiometers:
- One controls the LCD's brightness.
- The other functions as the tractor's throttle.
- Matrix Keypad:
- Number 5 is used as the brake.
- Number 4 changes the tractor's direction to the left.
- Number 6 changes the tractor's direction to the right.
The circuit is connected to the MCU, coded in C to receive data from the potentiometer, interpret it as tractor values (speed, gear, etc.), display it on the LCD, and transmit it to the RPi using UART protocol. The MCU also features a real time operating system (RTOS) which helps to schedule and monitor tasks. The RPi, programmed in Python, receives the data, creates a figure with 3 animated graphs using Matplotlib, and saves the data in a .csv
file.
The repository is organized into three main folders:
-
FTDI Codes:
- Contains an Arduino code to use if an FTDI module is unavailable. The code can be uploaded to an Arduino to utilize its RX and TX ports.
-
RPi Codes:
- Contains two Python scripts:
config.py
: Contains plot characteristics and serial communication settings between the STM32 and the RPi.main.py
: Contains plotting and saving functions. This is the script you need to run.
- Contains two Python scripts:
-
RPi Codes V2:
- Contains optimized versions of the scripts in the
RPi Codes
folder. These scripts utilize threading and queues to ensure real-time updating of the graphs.config.py
: Contains plot characteristics and serial communication settings between the STM32 and the RPi.main.py
: Contains plotting and saving functions, optimized for real-time performance.
- Contains optimized versions of the scripts in the
-
RPi Codes V3:
- Contains the same optimized versions of the scripts in the
RPi Codes V2
folder. However, a GUI created with Tkinter was included. Also, bidirectional communication between the MCU and the MPU was implemented.
- Contains the same optimized versions of the scripts in the
-
STM32 Codes:
- Contains all the header and source files used to code the MCU and the circuit components.
- The file to compile in the STM32 Cube IDE is
main.c
.
-
STM32 V2 Codes:
- Contains the same scripts from
STM32 Codes
, but this version includes the capability of simulating the tractor's blinkers with LEDs.
- Contains the same scripts from
-
STM32 Codes RTOS:
- Contains an RTOS-supported version of the STM32 project. This modification features:
- Priority scheduling.
- Intercommunication between tasks.
- Shared resources management (USART).
- Capability of simulating the tractor's blinkers with LEDs.
- Contains an RTOS-supported version of the STM32 project. This modification features:
Before using the codes in this repository, ensure you have the following prerequisites:
- STM32 Nucleo-F103RB Module
- STM32CubeIDE
- Python
- matplotlib.pyplot
- pyserial
- numpy
- Raspberry Pi
- STM32 Cube IDE
- 2 LEDs to simulate the tractor's blinkers.
- 2 potentiometers (1 for the LCD and 1 to control the tractor's acceleration)
- An LCD (Liquid Crystal Display)
- A breadboard
- An FTDI module
- A matrix keypad
To use this repository, follow these steps:
-
Clone the repository on two different machines: one with the STM32 Cube IDE and the other with the RPi module. Use the following command:
git clone https://github.com/HumbertoBM2/Tractor-dashboard.git
-
Prepare the physical circuit following the pin specifications in the STM32 Codes folder.
-
Upload the compiled code to the MCU using STM32 Cube IDE.
-
Run the main Python script on the RPi:
python3 main.py
-
Check the outputs:
- A window with the Matplotlib figure and 3 subplots should appear, updating in real-time with the circuit's values.
- The data should also display on the LCD. Test all the functionalities as described.
Feel free to explore and modify the code as needed for your project. For any issues or contributions, please open an issue or a pull request.
- TS indicates Tractor's speed.
- ES indicates Engine's speed.
- The direction of the tractor is shown in the top left corner.
- Th indicates the throttle's value.
- Units are now shown for each parameter.
- The tractor's direction is now represented with symbols (^,<,>,*).
- Bidirectional communication was implememted between the MCU and the MPU.