I am using 2 grove components in order to display a temperature. I use an I2C High Accuracy Temperature Sensor - MCP9808 and an OLED Screen using this script:
#include <U8g2lib.h>
#include <SPI.h>
#include <Wire.h>
#include "Seeed_MCP9808.h"
MCP9808 sensor;
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/SCL, /* data=*/SDA, /* reset=*/U8X8_PIN_NONE); //Software I2C
char strTemp\[16\];
float temp;
void setup() {
u8g2.begin();
Serial.begin(115200);
if (sensor.init()) {
Serial.println("sensor init failed!!");
}
sensor.set_config(SET_CONFIG_ADDR, 0x0008);
Serial.println("sensor init!!");
}
void loop() {
sensor.get_temp(&temp);
Serial.print("temperature value is: ");
Serial.println(temp);
delay(1000);
dtostrf(temp, 7, 2, strTemp);
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_luBIS08_tf); // choose a suitable font
u8g2.drawStr(0, 10, "Hello Seeed!"); // write something to the internal memory
u8g2.drawStr(0, 30, "Temp. value:"); // write something to the internal memory
u8g2.drawStr(0, 50, strTemp); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
}
The temperature output is not updated on the screen and I think it might be related to I2C addresses. Is it possible?
I run an I2C scanner and I think that the OLED address is 0x3C and the temp. sensor is 0x18. How can I assign them correctly. I never done something like that so any help is welcome.
Thanks a lot.