This repository contains a C code implementation for interfacing the Sensirion SCD30 CO2 sensor with the STM32L4 microcontroller. The sensor is connected using I2C, and sensor data (CO2 concentration, humidity, and temperature) is transmitted via UART to a terminal application like Tera Term.
This project implements the integration of the Sensirion SCD30 CO2 sensor with the STM32L4 microcontroller using a single-file C code approach main.c. The code establishes communication with the sensor via the I2C protocol to collect environmental data, which is then transmitted over UART for real-time monitoring and analysis through a terminal interface.
To build and run the project, ensure the following dependencies are met:
- STM32CubeIDE or STM32CubeMX for STM32L4 firmware development
- Tera Term or other UART terminal software for receiving sensor data
- Download STM32CubeMX from the STMicroelectronics website.
- Install STM32CubeMX following the provided installation instructions.
- Launch STM32CubeMX after installation.
- Create a new project or open an existing one where you intend to configure the STM32L4 microcontroller.
- Click on the "Pinout & Configuration" tab.
- Navigate to the "Connectivity" section.
- Click on "I2C1" to add the I2C peripheral.
- Click on the newly added I2C1 peripheral to configure its parameters.
- Set the I2C Mode to "I2C".
- Click on "USART2" under "Connectivity" to add the UART peripheral.
- Click on the newly added "USART2" peripheral to configure its parameters.
- Set the UART Mode to "Asynchronous".
- Click on "PA5" or any desired GPIO pin to configure it for LED2.
- Set the GPIO Pin Mode to "Output".
- After configuring I2C, UART, and GPIO settings, click on the "Project", then "Settings" tab.
- Set the toolchain/IDE to be used (e.g., STM32CubeIDE).
- Click "Generate Code" to generate the code for your STM32L4 project.
- Open your preferred STM32 IDE (e.g., STM32CubeIDE).
- Import the project by selecting the folder where you generated the code.
- Build and flash the code onto your STM32L4 microcontroller.
-
Hardware Setup:
- Connect the SCD30 CO2 sensor to the STM32L4 microcontroller using the I2C interface.
- Ensure proper power and ground connections.
-
Software Setup:
- Import the main.c file into your STM32CubeIDE project or use it directly with your preferred STM32 development environment.
- Configure the UART interface settings according to your setup (baud rate, parity, etc.).
-
Build and Flash:
- Compile the code main.c using your STM32 development environment.
- Flash the compiled firmware onto the STM32L4 microcontroller.
-
Terminal Setup:
- Open Tera Term or a compatible terminal application on your computer.
Make sure that the speed is at 115200 Bits/s and the data is at 8 bit.
-
Monitor Sensor Data:
- Configure Tera Term to receive UART data from the STM32L4 microcontroller.
- Power on the setup and observe CO2 concentration, humidity, and temperature readings in real-time.
After setting up and running the code on the STM32L4 microcontroller, you should be able to see the following results:
-
CO2, Temperature, and Humidity Data:
- The SCD30 sensor will capture CO2 concentration, temperature, and humidity data.
- This data will be transmitted via the UART interface.
-
Displaying Data on Terminal:
- Open Tera Term or any other terminal emulator.
- Connect to the corresponding UART port.
- You should see the CO2, temperature, and humidity readings displayed on the terminal in real-time.
-
LED2 Status:
- The LED2 connected to the GPIO pin (e.g., PA5) can be used to indicate various statuses, such as data transmission or sensor activity.
For more information about the SCD30 sensor, refer to the Sensirion SCD30 Product Page.
Contributions are welcome! Fork the repository, make your changes in main.c, and submit a pull request. Please adhere to code style guidelines and ensure compatibility with the STM32L4 platform.
This project is licensed under the MIT License - see the LICENSE file for details.
For questions or suggestions, contact [email protected].