After receiving a new Arduino R4 WiFi, one of the first tests I ran was to connect a Grove Barometer sensor to the SCL and SDA pins (and of course, power and ground). I then ran the Barometer demo V1.0. The R4 showed crazy high numbers for temperature (118.2 deg C) and pressure (3345 Pa, which equates to an altitude of 21,000 meters). I moved the sensor to an Uno R3 using the same pins and got correct temperature and pressure using the exact same barometer demo sketch. I am using the SCL and SDA pins rather than the Qwiic connector.
Do I need to initialize the I2C port somehow? I tried Wire.begin() but it didn't seem to matter. Any ideas?
Note that "Uno R4" is not a next release of the "Uno R3", it is a completely different controller. A code, developed for R3 uno, can be incompatible with R4
/* Barometer demo V1.0
* Based largely on code by Jim Lindblom
* Get pressure, altitude, and temperature from the BMP085.
* Serial.print it out at 9600 baud to serial monitor.
*
* By:https://www.seeedstudio.com
*/
#include "Barometer.h"
#include <Wire.h>
float temperature;
float pressure;
float atm;
float altitude;
Barometer myBarometer;
void setup(){
Serial.begin(9600);
myBarometer.init();
}
void loop()
{
temperature = myBarometer.bmp085GetTemperature(myBarometer.bmp085ReadUT()); //Get the temperature, bmp085ReadUT MUST be called first
pressure = myBarometer.bmp085GetPressure(myBarometer.bmp085ReadUP());//Get the temperature
altitude = myBarometer.calcAltitude(pressure); //Uncompensated calculation - in Meters
atm = pressure / 101325;
Serial.print("Temperature: ");
Serial.print(temperature, 2); //display 2 decimal places
Serial.println("deg C");
Serial.print("Pressure: ");
Serial.print(pressure, 0); //whole number only.
Serial.println(" Pa");
Serial.print("Ralated Atmosphere: ");
Serial.println(atm, 4); //display 4 decimal places
Serial.print("Altitude: ");
Serial.print(altitude, 2); //display 2 decimal places
Serial.println(" m");
Serial.println();
delay(1000); //wait a second and get values again.
}