Dtynin
Dtynin
DIIDevHeads IoT Integration Server
Created by Enthernet Code on 5/23/2024 in #middleware-and-os
C program in embedded Linux reads data from BMP280 temperature sensor and displays it on Adafruit1.2
@Enthernet Code To read data from the BMP280, you need to send a command to the sensor specifying the temperature register and then read the temperature data from the sensor. you can try this #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> #include <linux/i2c-dev.h> #define BMP280_ADDRESS 0x76 int file; char *filename = "/dev/i2c-1"; if ((file = open(filename, O_RDWR)) < 0) { perror("Failed to open the i2c bus"); return 1; } if (ioctl(file, I2C_SLAVE, BMP280_ADDRESS) < 0) { perror("Failed to acquire bus access and/or talk to slave"); return 1; } char reg[1] = {0xFA}; // Temperature register address write(file, reg, 1); char data[3] = {0}; if (read(file, data, 3) != 3) { perror("Failed to read from the i2c bus"); } else { // Process the data (e.g., convert raw data to temperature) int temp_raw = (data[0] << 16) | (data[1] << 8) | data[2]; // Convert temp_raw to actual temperature // ... (calculation based on BMP280 datasheet) printf("Temperature: %d\n", temp_raw); } close(file); These steps should read the temperature data from the BMP280 sensor. After that, you can use the SPI interface to communicate with the Adafruit OLED display and send the temperature data to it for display.
4 replies