I made a barometer with bmp180 sensor and Arduino anno, using display 16x2 lcd, shows temperature and pressure, it is working perfectly in Arduino nano(atmega328p) but when the same code uploaded in another Arduino nano(atmega328pb) the temperature value is not showing, only shows pressure... here is my code
/////////////////////////////////////////////////////////////////
// Arduino Weather Station Project #2 v1.02 //
// Get the latest version of the code here: //
// http://educ8s.tv/arduino-weather-station-2 //
/////////////////////////////////////////////////////////////////
#include <LiquidCrystal.h>
#include <SFE_BMP180.h> //https://github.com/sparkfun/BMP180_Breakout
#include <Wire.h>
SFE_BMP180 pressure;
float temperature;
#define ALTITUDE 50.44 //
LiquidCrystal lcd(8,9,4,5,6,7);
void setup(void) {
lcd.begin(16, 2);
lcd.print(" BMP180 Sensor");
lcd.setCursor(0, 1);
lcd.print("Temp. & Pressure");
lcd.setCursor(0, 2);
pressure.begin();
}
void loop() {
float pressure;
pressure = readPressureAndTemperature();
delay(3000);
lcd.clear();
char tempF[6];
char pressF[7];
dtostrf(temperature, 5, 1, tempF);
dtostrf(pressure, 7, 2, pressF);
//Printing Temperature
lcd.print("Temp:");
lcd.print(tempF);
lcd.print((char)223);
lcd.print("C ");
//Printing Pressure
lcd.setCursor(0,1);
lcd.print("P: ");
lcd.print(pressF);
lcd.print(" Mb ");
}
float readPressureAndTemperature()
{
char status;
double T,P,p0,a;
status = pressure.startTemperature();
if (status != 0)
{
delay(status);
status = pressure.getTemperature(T);
if (status != 0)
{
temperature = T;
status = pressure.startPressure(3);
if (status != 0)
{
delay(status);
status = pressure.getPressure(P,T);
if (status != 0)
{
p0 = pressure.sealevel(P,ALTITUDE);
return p0;
}
}
}
}
}
That's not particularly well written code, and that's being kind. Mixing globals and locals willy nilly, having global and local variables with the same name and different types? Ugh. I'm not surprised you are having trouble with it. Why you should only have trouble with a 328PB is unclear, and I'm unwilling to spend the time to try and wrap my head around that badly written piece of code to try and figure it out.
And your description of the problem you're seeing is lacking in both precision and detail. Both of which are necessary to successfully diagnose a problem. What exactly do you mean when you say "the temperature value is not showing"? Is its value blank on the LCD? Is it zero? What? Be precise. Be detailed. No one can see what you're seeing. If you don't tell us, if you don't show us, you're just wasting everyone's time. Yours and ours.
And? What debugging have you tried? What's the value of the variables when it doesn't work? Before and after? At various stages? Don't make others constantly drag information out of you.
I try debugging using serial monitor, my BMP180 well works with atmega328pb Arduino nano and shows temperature and pressure value on serial monitor, but it fails to print temperature value on my 1602 lcd... I am surprized that my other Arduino nano atmega328p works well , but I used that in my other radio project....