Sketch won't go past setup

So my sketch seems only to want to execute the set up portion and won't go into the loop portion.
My LCD is stuck displaying "EFIS PROTOTYPE"

Can't seem to figure out why.

#include <SFE_BMP180.h>
#include <Wire.h>
#include <LCD5110_Graph.h>
#include <ClickEncoder.h>
#include <TimerOne.h>
SFE_BMP180 pressure;
LCD5110 lcd(8, 9, 10, 12, 11);
extern unsigned char SmallFont[];
extern unsigned char TinyFont[];
double baseline; // baseline pressure

ClickEncoder *encoder;
int16_t last, value = 11968;
void timerIsr()
{
encoder->service();
}

void setup()
{
encoder = new ClickEncoder(A1, A0, A2);
Timer1.initialize(1000);
Timer1.attachInterrupt(timerIsr);
last = -1;
lcd.InitLCD();
lcd.setFont(SmallFont);
lcd.print("EFIS", CENTER, 2);
lcd.print("PROTOTYPE", CENTER, 12);
lcd.update();
delay(2000);
}

void loop()
{
double a, P;
int Al;
int encoderValue;
float q = value / 4 * 0.01;
a = pressure.altitude(P, baseline);
baseline = q * 33.8638870320855;
P = getPressure();
Al = a * 3.28084;
value += encoder->getValue();
if (value != last) {
last = value;

lcd.setFont(SmallFont);
char qnh[3];
char Alt[3];
lcd.clrScr();
lcd.print("360*", CENTER, 2);
dtostrf(q, 3, 2, qnh);
dtostrf(Al, 3, 0, Alt);
lcd.print("100", LEFT, 13);
lcd.print(Alt, LEFT + 52, 13);
lcd.print(qnh, LEFT, 30);
lcd.print("+1500", LEFT + 52, 30);
lcd.update();
}

}
double getPressure()
{
char status;
double T, P, p0, a;
status = pressure.startTemperature();
delay(status);
status = pressure.getTemperature(T);
status = pressure.startPressure(3);
delay(status);
status = pressure.getPressure(P, T);
if (status != 0)
{
return (P);
}
}

What does the IDE report memory usage as?

You have not designed your program to help you find the cause of your problem.

Why not put a print statement at the top of loop()? I feel sure it would be printed.

Within loop() the only printing that can take place is governed by your IF statement - you have nothing that prints if the IF test is false or to show you the values as they are before the IF statement.

Your getPressure() function seems to have some strange stuff. Why would you set a delay() for a time determined by a pressure? And you have a return value for when status is not 0, but no value for when it is 0.

...R

CtrlAltElite:
What does the IDE report memory usage as?

CtrlAltElite:
What does the IDE report memory usage as?

4% program storage space. 13% dynamic memory

ok so i made the changes that were recommended.
still the LCD only displays the text in setup. nothing showing up on the serial monitor either.

#include <SFE_BMP180.h>
#include <Wire.h>
#include <LCD5110_Graph.h>
#include <ClickEncoder.h>
#include <TimerOne.h>
SFE_BMP180 pressure;
LCD5110 lcd(8, 9, 10, 12, 11);
extern unsigned char SmallFont[];
extern unsigned char TinyFont[];
double baseline; 
ClickEncoder *encoder;
int16_t last, value = 11968;
void timerIsr()
{
  encoder->service();
}

void setup()
{
  encoder = new ClickEncoder(A1, A0, A2);
  Timer1.initialize(1000);
  Timer1.attachInterrupt(timerIsr);
  last = -1;
  Serial.begin(9600);
  Serial.print("efis");
  Serial.print("prototype");
  lcd.InitLCD();
  lcd.setFont(SmallFont);
  lcd.print("EFIS", CENTER, 2);
  lcd.print("PROTOTYPE", CENTER, 12);
  lcd.update();
  delay(1000);
}

void loop()
{
  double a, P;
  int Al;
  int encoderValue;
  float q = value / 4 * 0.01;
  a = pressure.altitude(P, baseline);
  baseline = q * 33.8638870320855;
  P = getPressure();
  Al = a * 3.28084;
  value += encoder->getValue();
  Serial.begin(9600);
  Serial.print(q);
  Serial.print(Al);
  lcd.setFont(SmallFont);
  char qnhqnh[3];
  char Altalt[3];
  lcd.clrScr();
  lcd.print("360*", CENTER, 2);
  dtostrf(q, 3, 2, qnhqnh);
  dtostrf(Al, 3, 0, Altalt);
  lcd.print("100", LEFT, 13);
  lcd.print(Altalt, LEFT + 52, 13);
  lcd.print(qnhqnh, LEFT, 30);
  lcd.print("+1500", LEFT + 52, 30);
  lcd.update();


}
double getPressure()
{
  char status;
  double T, P, p0, a;
  status = pressure.startTemperature();
  status = pressure.getTemperature(T);
  status = pressure.startPressure(3);
  status = pressure.getPressure(P, T);

}

im also getting this showing up in orange:

C:\Users\Quintin\Documents\Arduino\EFIS PROJECT\testalt\testalt.ino: In function 'void setup()':

C:\Users\Quintin\Documents\Arduino\EFIS PROJECT\testalt\testalt.ino:29:30: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

lcd.print("EFIS", CENTER, 2);

^

C:\Users\Quintin\Documents\Arduino\EFIS PROJECT\testalt\testalt.ino:30:36: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

lcd.print("PROTOTYPE", CENTER, 12);

^

C:\Users\Quintin\Documents\Arduino\EFIS PROJECT\testalt\testalt.ino: In function 'void loop()':

C:\Users\Quintin\Documents\Arduino\EFIS PROJECT\testalt\testalt.ino:53:30: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

lcd.print("360*", CENTER, 2);

^

C:\Users\Quintin\Documents\Arduino\EFIS PROJECT\testalt\testalt.ino:56:28: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

lcd.print("100", LEFT, 13);

^

C:\Users\Quintin\Documents\Arduino\EFIS PROJECT\testalt\testalt.ino:59:35: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

lcd.print("+1500", LEFT + 52, 30);

Qhergt1987:
nothing showing up on the serial monitor either.

If there's "something funny going on", it might be useful to add LOTS of debug printout like:

void loop()
{
  double a, P;
  int Al;
  int encoderValue;

Serial.println("debug 1");delay(100);

  float q = value / 4 * 0.01;
  a = pressure.altitude(P, baseline);

Serial.println("debug 2");delay(100);

  baseline = q * 33.8638870320855;
  P = getPressure();

Serial.println("debug 3");delay(100);

...and see how far it gets.

Also, you should only call Serial.begin() once in setup(), not again in loop().

Yours,
TonyWilk

TonyWilk:
If there's "something funny going on", it might be useful to add LOTS of debug printout like:

void loop()

{
  double a, P;
  int Al;
  int encoderValue;

Serial.println("debug 1");delay(100);

float q = value / 4 * 0.01;
  a = pressure.altitude(P, baseline);

Serial.println("debug 2");delay(100);

baseline = q * 33.8638870320855;
  P = getPressure();

Serial.println("debug 3");delay(100);



...and see how far it gets.

Also, you should only call Serial.begin() once in setup(), not again in loop().

Yours,
TonyWilk

debug 1 and 2 work, but not 3

Delta_G:
Have you fixed that buffer overrun? I feel like maybe my posts aren't coming through. Can you hear me? Cause I've spotted your problem and you seem to be ignoring it.

Sorry I'm still new to Arduino,.
Buffer overrun?

Qhergt1987:
debug 1 and 2 work, but not 3

Well, the only thing between 2 and 3 is that call to the getPressure() function.

Add more Serial.print() debug lines into the getPressure() function, at least one before

 status = pressure.startTemperature();

and another one after.

See how far it gets.

It is likely that the program is stopping when it tries to read the BMP180 device.

And eventually you will have to fix that buffer overrun :slight_smile:

Yours,
TonyWilk

Delta_G:
Yes pointed out in reply #2. If you will stop ignoring that point you'll have your code fixed. Your arrays aren't big enough to hold what you're trying to put in them. When you write past the end of the array you corrupt memory. All bets are off and anything can happen at that point. Doing any further debugging with that problem still there is just stupid and a waste of time.

How do I do that?

Delta_G:
Do you not know which lines defined the array or where you told it what size to be? If that's really the case then this code is a bit over your head. You should back down and do some learning and come back to it.

This line: char qnh[3]. Figure out how many characters it needs to hold to hold the number you want and make the number one larger than that.

Facepalm! Doh! Brain fart!!! I had copied code I had written for something else that showed only 2 characters so I had it set for 3

Success!
Thanks gents. LCD now shows everything.
However, I might have some further code issues as turning the encoder no longer changes the baseline pressure value as smoothly as it did before, and the altitude number doesn't change accordingly