Why Isn't My OLED Screen Updating with Pressure Readings on AVR128DA48?

Hey guys, I'm trying to display real-time pressure readings on an OLED screen using I2C in my AVR128DA48-based pressure monitoring project. However, the OLED screen does not update as expected. the I2C wiring and connection to the OLED screen are quite cool, and I also ensured that the pressure readings were valid and correctly formatted. Yet, I'm still encountering the OLED screen failing to display any pressure readings. What might be causing this issue, and how can I ensure that the OLED screen updates correctly with real-time pressure values? this is my code instructions:
#include <zephyr.h>
#include <device.h>
#include <drivers/i2c.h>
#include <drivers/sensor.h>
#include <display/cfb.h>

#define OLED_I2C_DEV "I2C_0"

void main(void)
{
const struct device *oled_dev = device_get_binding(OLED_I2C_DEV);
struct sensor_value pressure;

if (oled_dev == NULL) {
printk("Failed to bind to OLED I2C device\n");
return;
}

const struct device *bmp280 = device_get_binding(DT_LABEL(DT_INST(0, bosch_bmp280)));

while (1) {
sensor_sample_fetch(bmp280);
sensor_channel_get(bmp280, SENSOR_CHAN_PRESS, &pressure);

char buffer[20];
snprintf(buffer, sizeof(buffer), "Pressure: %d kPa", pressure.val1);
cfb_print(oled_dev, buffer, 0, 0);

cfb_framebuffer_finalize(oled_dev);
k_sleep(K_SECONDS(2));
}
}
#include <zephyr.h>
#include <device.h>
#include <drivers/i2c.h>
#include <drivers/sensor.h>
#include <display/cfb.h>

#define OLED_I2C_DEV "I2C_0"

void main(void)
{
const struct device *oled_dev = device_get_binding(OLED_I2C_DEV);
struct sensor_value pressure;

if (oled_dev == NULL) {
printk("Failed to bind to OLED I2C device\n");
return;
}

const struct device *bmp280 = device_get_binding(DT_LABEL(DT_INST(0, bosch_bmp280)));

while (1) {
sensor_sample_fetch(bmp280);
sensor_channel_get(bmp280, SENSOR_CHAN_PRESS, &pressure);

char buffer[20];
snprintf(buffer, sizeof(buffer), "Pressure: %d kPa", pressure.val1);
cfb_print(oled_dev, buffer, 0, 0);

cfb_framebuffer_finalize(oled_dev);
k_sleep(K_SECONDS(2));
}
}
2 Replies
Nayel
Nayel4mo ago
Hi @Dtynin How are you? what you can try is to make sure both the OLED display and BMP280 sensor are properly set up by checking that device_get_binding for each device doesn’t return NULL. If it does, print an error message and stop the program. Also, remember to initialize the framebuffer with cfb_framebuffer_init() before printing anything to the OLED to ensure it’s good to go. Lastly, to keep the display clear and avoid any text overlap, use cfb_framebuffer_clear(oled_dev, true); before each update.
Dtynin
Dtynin4mo ago
Thanks @Nayel for the prompt response...I would try them out
Want results from more Discord servers?
Add your server