How to Implement Real-Time Logging for Pressure Data and Resolve SD Card Write Errors?

Hey guys, how can I implement a real-time logging system for pressure data using an ATmega2560, MCP2515 CAN controller, BMP280 sensor, and an SD card with Zephyr OS, and resolve the SD card file write error? I have successfully mounted the SD card and opened the file, but yet I encountered the error "Failed to write data." If the implementation is successful, the output should log a message indicating that the data has been successfully logged to the SD card. Here is my code in the attached file:
attachment 0
2 Replies
wafa_ath
wafa_ath5mo ago
Hey @Dtynin Try to Put sensor reading and logging in a loop with a delay. Also Your code doesn't use the MCP2515 CAN controller. If you want to transmit the sensor data over CAN, you'll need to set up the CAN device and send messages. Consider using a RAM buffer before writing to SD for better performance.
Joseph Ogbonna
Joseph Ogbonna5mo ago
To implement real-time logging with your setup and fix the SD card write error: Implementation Steps 1. Configure Zephyr OS: - Add to prj.conf:
CONFIG_CAN=y
CONFIG_I2C=y
CONFIG_FAT_FILESYSTEM=y
CONFIG_SDMMC=y

CONFIG_CAN=y
CONFIG_I2C=y
CONFIG_FAT_FILESYSTEM=y
CONFIG_SDMMC=y

2. Initialize Peripherals: - Set up CAN, BMP280, and SD card with SPI/I2C. 3. Mount SD Card:
struct fs_mount_t mp = {
.type = FS_FATFS,
.fs_data = &fatfs_data,
.mnt_point = "/SDCARD"
};
int err = fs_mount(&mp);

struct fs_mount_t mp = {
.type = FS_FATFS,
.fs_data = &fatfs_data,
.mnt_point = "/SDCARD"
};
int err = fs_mount(&mp);

4. Open and Write to File: 5. Read BMP280 Data: - Use I2C to get pressure data from BMP280. Troubleshooting SD Card Write Error 1. Check Connections and power supply. 2. Verify SD Card Format (FAT32). 3. Inspect Buffer Sizes and data. This should help you get your logging system working and fix the write error.
Want results from more Discord servers?
Add your server