sketch wont go past setup stage

so it seems my sketch wont go past the setup stage.

lcd displays what is should be during setup,
the serial prints on 9600 reads:
⸮BOOTING
WAITING FOR GPS SAT LOCK…
Initializing…

and 11520:
GPS

using nemo 6m and a mega 2560

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
#include <ClickEncoder.h>
#include <TimerOne.h>
#include <LCD5110_Graph.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <TinyGPS.h>
#include <SPI.h>
#include "i2c.h"
#include "i2c_BMP280.h"
BMP280 bmp280;
SoftwareSerial BTserial(0, 1);
TinyGPS gps;
SoftwareSerial serialgps(3, 2);
float time;
float ref_pressure, air_pressure, pressure_diff;
float airspeed_ratio = 1.54679; // 2/? (? = 1,225 kg/m3 )
float airspeed;
int AIRSPEED_CH = A6;
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
LCD5110 lcd(8, 9, 10, 12, 11);
extern unsigned char SmallFont[];
extern unsigned char TinyFont[];
ClickEncoder *encoder;
int16_t last, value = 11968;
void timerIsr()
{
  encoder->service();
}
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long chars;
unsigned short sentences, failed_checksum;
int lock = 0;
int exceedclear = 0;
int exceed = 0;
void setup(void)
{
  char ALTIMETE[6];
  char PROTOTYPE[6];
  lcd.InitLCD();
  lcd.setFont(SmallFont);
  lcd.print("EFIS", CENTER, 2);
  lcd.print("PROTOTYPE", CENTER, 20);
  lcd.print("1.01", CENTER, 38);
  lcd.update();
  delay(1000);
  bmp280.setPressureOversampleRatio(2);
  bmp280.setTemperatureOversampleRatio(1);
  bmp280.setFilterRatio(0);
  bmp280.setStandby(0);

  // onetime-measure:
  bmp280.setEnabled(0);
  bmp280.triggerMeasurement();
  int i;
  encoder = new ClickEncoder(A1, A2, A0);
  Timer1.initialize(1000);
  Timer1.attachInterrupt(timerIsr);
  last = -1;
  Serial.begin(115200); //For serial monitor debug
  serialgps.begin(9600); //6M Module is 9600 by default!
  Serial.println("");
  Serial.println("GPS BOOTING");
  Serial.println(" WAITING FOR GPS SAT LOCK... ");
  Serial.println("");
  Serial.begin(9600);
  BTserial.begin(9600);
  if (!bmp.begin())
  {
    Serial.print("Ooops, no BMP280 detected ... Check your wiring or I2C ADDR!");
    while (1);
  }
  Serial.println("Initializing...");

  ref_pressure = analogRead(AIRSPEED_CH);

  for (i = 1; i <= 200; i++)
  {
    ref_pressure = (analogRead(AIRSPEED_CH)) * 0.25 + ref_pressure * 0.75;

    delay(20);
  }

  float Af2;
  {
    float feet;
    bmp280.getTemperature(feet);  // throw away - needed for alt.
    bmp280.getPressure(feet);     // throw away - needed for alt.
    bmp280.getAltitude(feet);
    return feet;
    delay(20);

  }

}

void loop(void)
{
  float q = value / 4 * 0.01;
  value += encoder->getValue();
  sensors_event_t event;
  bmp.getEvent(&event);
  if (event.pressure)
    if ((millis() - time) >= 20)
    {
      time = millis();
      air_pressure = analogRead(AIRSPEED_CH) * 0.25 + air_pressure * 0.75;
      if (air_pressure >= ref_pressure)
      {
        pressure_diff = air_pressure - ref_pressure;
      }
      else
      {
        pressure_diff = 0.0;
      }
      int asi;
      airspeed = sqrt(pressure_diff * airspeed_ratio);
      asi = (airspeed * 3.6) * 0.621371;
      {
        float temperature;
        bmp.getTemperature(&temperature);
        float ep = (event.pressure * 304) / 305 + (event.pressure / 305);
        float seaLevelPressure = (q * 33.8638870320855);
        float Am = (bmp.pressureToAltitude(seaLevelPressure, ep));
        float Af = Am * 3.28084 + 40;
        float Af2 = (Af * 304) / 305 + (Af / 305);
        float feet = Af2;
        float distance, velocity;
        static uint32_t time_now, time_was = millis(), dt;
        static float alt_was = Af2;
        static uint32_t sample_time_was = millis();
        static uint32_t readings = 0;
        static float values = 0, avg_alt = 0;
        static float meters;

        if ( (millis() - sample_time_was) > 0) { // read at a specific rate.

          if (!bmp280.awaitMeasurement()) Serial.println("MEASURE FAILED");

          feet = Af2;
          readings++;
          values += feet;

          bmp280.triggerMeasurement();

          sample_time_was = millis();
        }


        time_now = millis();
        dt = time_now - time_was;
        if (dt >= 250) {

          avg_alt = values / readings;
          distance = avg_alt - alt_was;
          velocity = (distance / ((float)dt / 1000.0 * 60));
          alt_was  = avg_alt;
          time_was = time_now;
          float fpm = (velocity);
          while (serialgps.available()) {
            int c = serialgps.read();

            if (gps.encode(c)) {

              float latitude, longitude;
              gps.f_get_position(&latitude, &longitude);
              int GS = gps.f_speed_kmph(); // Remove decimals from raw value
              float gs = (GS * 0.621);
              Serial.print("ground speed(mph): ");
              Serial.println(GS);
              Serial.println();
              gps.stats(&chars, &sentences, &failed_checksum);


              Serial.print("#");
              Serial.print(asi);
              Serial.print("|");
              Serial.print(GS);
              Serial.print("|");
              Serial.print(Af2);
              Serial.print("|");
              Serial.print(q);
              Serial.print("|");
              Serial.print(fpm, 0);

              values = 0;
              readings = 0;


              lcd.clrScr();
              char qnh[6];
              char Alt[6];
              char vsi[6];
              char asimph[6];
              char gsm[6];
              dtostrf(q, 3, 2, qnh);
              dtostrf(Af2, 3, 0, Alt);
              dtostrf(asi, 1, 0, asimph);
              dtostrf(GS, 1, 0, gsm);
              dtostrf(fpm, 3, 0, vsi);
              lcd.print(" 360*", CENTER, 2);
              lcd.print(asimph, LEFT, 15);
              lcd.print(Alt, RIGHT, 15);
              lcd.print("MPH", LEFT + 20, 15);
              lcd.print(gsm, LEFT, 30);
              lcd.print("GS", LEFT + 20, 30);
              lcd.print(vsi, RIGHT, 30);
              lcd.print(qnh, CENTER, 38);
              lcd.update();
              BTserial.print("360*");
              BTserial.print(",");
              BTserial.print(asi);
              BTserial.print(",");
              BTserial.print(Alt);
              BTserial.print(",");
              BTserial.print(q);
              BTserial.print(";");
              delay(20);
            }
          }
        }
      }
    }
}

Put another print statement as the last line in setup()

Serial.println("Setup complete");

If that shows then you know the program has moved on to loop() and you can start your investigations there.

If you were to break your code in loop() into a number of single-purpose functions it would make your code much easier to debug. Have a look at Planning and Implementing a Program

...R

Hi,

SoftwareSerial BTserial(0, 1);

You can't SoftwareSerial Pin0 and Pin1, they are already UART for serial comms and programming.

If it is waiting for GPS sat lock, it has to be able to receive satellites.

If you are inside, take your project outside where it can get a good lock on some satellites.

Also your code assumes that the GPS is booting.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Forget your code for the minute and try the [u]example code[/u] that comes with TinyGPS to make sure your connections are correct.

Thanks.. Tom.. :)

forgot to mention that i had it working on my uno, but it only had about 300 bites of memory left so i tried switching to the mega which is when the issues came up.

i modified the code as suggested, it only gets to “setup continues”

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
#include <ClickEncoder.h>
#include <TimerOne.h>
#include <LCD5110_Graph.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <TinyGPS.h>
#include <SPI.h>
#include "i2c.h"
#include "i2c_BMP280.h"
BMP280 bmp280;

TinyGPS gps;
SoftwareSerial serialgps(3, 4);
float time;
float ref_pressure, air_pressure, pressure_diff;
float airspeed_ratio = 1.54679; // 2/? (? = 1,225 kg/m3 )
float airspeed;
int AIRSPEED_CH = A3;
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
LCD5110 lcd(8, 9, 10, 12, 11);
extern unsigned char SmallFont[];
extern unsigned char TinyFont[];
ClickEncoder *encoder;
int16_t last, value = 11968;
void timerIsr()
{
  encoder->service();
}
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long chars;
unsigned short sentences, failed_checksum;
int lock = 0;
int exceedclear = 0;
int exceed = 0;
void setup(void)
{
  char ALTIMETE[6];
  char PROTOTYPE[6];
  lcd.InitLCD();
  lcd.setFont(SmallFont);
  lcd.print("EFIS", CENTER, 2);
  lcd.print("PROTOTYPE", CENTER, 20);
  lcd.print("1.01", CENTER, 38);
  lcd.update();
  delay(1000);
  bmp280.setPressureOversampleRatio(2);
  bmp280.setTemperatureOversampleRatio(1);
  bmp280.setFilterRatio(0);
  bmp280.setStandby(0);

  // onetime-measure:
  bmp280.setEnabled(0);
  bmp280.triggerMeasurement();
  int i;
  encoder = new ClickEncoder(A1, A2, A0);
  Timer1.initialize(1000);
  Timer1.attachInterrupt(timerIsr);
  last = -1;
  Serial.begin(9600);
  Serial.begin(115200); //For serial monitor debug
  serialgps.begin(9600); //6M Module is 9600 by default!
  Serial.println("");
  Serial.println("GPS BOOTING");
  Serial.println(" WAITING FOR GPS SAT LOCK... ");
  Serial.println("");

  Serial.begin(9600);
  if (!bmp.begin())
  {
    Serial.print("Ooops, no BMP280 detected ... Check your wiring or I2C ADDR!");
    while (1);
  }
  Serial.println("Initializing...");
  Serial.println("setup continues");
  ref_pressure = analogRead(AIRSPEED_CH);

  for (i = 1; i <= 200; i++)
  {
    ref_pressure = (analogRead(AIRSPEED_CH)) * 0.25 + ref_pressure * 0.75;

    delay(20);
  }

  float Af2;
  {
    float feet;
    bmp280.getTemperature(feet);  // throw away - needed for alt.
    bmp280.getPressure(feet);     // throw away - needed for alt.
    bmp280.getAltitude(feet);
    return feet;
    delay(20);
    Serial.println("setup done");

  }

}

void loop(void)
{
  float q = value / 4 * 0.01;
  value += encoder->getValue();
  sensors_event_t event;
  bmp.getEvent(&event);
  if (event.pressure)
    if ((millis() - time) >= 20)
    {
      time = millis();
      air_pressure = analogRead(AIRSPEED_CH) * 0.25 + air_pressure * 0.75;
      if (air_pressure >= ref_pressure)
      {
        pressure_diff = air_pressure - ref_pressure;
      }
      else
      {
        pressure_diff = 0.0;
      }
      int asi;
      airspeed = sqrt(pressure_diff * airspeed_ratio);
      asi = (airspeed * 3.6) * 0.621371;
      {
        float temperature;
        bmp.getTemperature(&temperature);
        float ep = (event.pressure * 304) / 305 + (event.pressure / 305);
        float seaLevelPressure = (q * 33.8638870320855);
        float Am = (bmp.pressureToAltitude(seaLevelPressure, ep));
        float Af = Am * 3.28084 + 40;
        float Af2 = (Af * 304) / 305 + (Af / 305);
        float feet = Af2;
        float distance, velocity;
        static uint32_t time_now, time_was = millis(), dt;
        static float alt_was = Af2;
        static uint32_t sample_time_was = millis();
        static uint32_t readings = 0;
        static float values = 0, avg_alt = 0;
        static float meters;

        if ( (millis() - sample_time_was) > 0) { // read at a specific rate.

          if (!bmp280.awaitMeasurement()) Serial.println("MEASURE FAILED");

          feet = Af2;
          readings++;
          values += feet;

          bmp280.triggerMeasurement();

          sample_time_was = millis();
        }


        time_now = millis();
        dt = time_now - time_was;
        if (dt >= 250) {

          avg_alt = values / readings;
          distance = avg_alt - alt_was;
          velocity = (distance / ((float)dt / 1000.0 * 60));
          alt_was  = avg_alt;
          time_was = time_now;
          float fpm = (velocity);
          while (serialgps.available()) {
            int c = serialgps.read();

            if (gps.encode(c)) {

              float latitude, longitude;
              gps.f_get_position(&latitude, &longitude);
              int GS = gps.f_speed_kmph(); // Remove decimals from raw value
              float gs = (GS * 0.621);
              Serial.print("ground speed(mph): ");
              Serial.println(GS);
              Serial.println();
              gps.stats(&chars, &sentences, &failed_checksum);


              Serial.print("#");
              Serial.print(asi);
              Serial.print("|");
              Serial.print(GS);
              Serial.print("|");
              Serial.print(Af2);
              Serial.print("|");
              Serial.print(q);
              Serial.print("|");
              Serial.print(fpm, 0);

              values = 0;
              readings = 0;


              lcd.clrScr();
              char qnh[6];
              char Alt[6];
              char vsi[6];
              char asimph[6];
              char gsm[6];
              dtostrf(q, 3, 2, qnh);
              dtostrf(Af2, 3, 0, Alt);
              dtostrf(asi, 1, 0, asimph);
              dtostrf(GS, 1, 0, gsm);
              dtostrf(fpm, 3, 0, vsi);
              lcd.print(" 360*", CENTER, 2);
              lcd.print(asimph, LEFT, 15);
              lcd.print(Alt, RIGHT, 15);
              lcd.print("MPH", LEFT + 20, 15);
              lcd.print(gsm, LEFT, 30);
              lcd.print("GS", LEFT + 20, 30);
              lcd.print(vsi, RIGHT, 30);
              lcd.print(qnh, CENTER, 38);
              lcd.update();

            }
          }
        }
      }
    }
}

so iv tried this code with both uno and mega, again it works on the uno but not the mega at all.

#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <SPI.h>
TinyGPS gps;
SoftwareSerial serialgps(3, 4);
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long chars;
unsigned short sentences, failed_checksum;
int lock = 0;
int exceedclear = 0;
int exceed = 0;
void setup() {


  Serial.begin(115200); //For serial monitor debug
  serialgps.begin(9600); //6M Module is 9600 by default!
  Serial.println("");
  Serial.println("GPS BOOTING");
  Serial.println(" WAITING FOR GPS SAT LOCK... ");
  Serial.println("");
  Serial.println("setup done");
}


void loop() {

  while (serialgps.available()) {
            int c = serialgps.read();

            if (gps.encode(c)) {

              float latitude, longitude;
              gps.f_get_position(&latitude, &longitude);
              int GS = gps.f_speed_kmph(); // Remove decimals from raw value
              float gs = (GS * 0.621);
              Serial.print("ground speed(mph): ");
              Serial.println(GS);
              Serial.println();
              gps.stats(&chars, &sentences, &failed_checksum);
            }}}

iv tried this code with both uno and mega, again it works on the uno but not the mega at all.

I assume that you know that the SPI pins on the Mega are different to those on the Uno unless you use the ICSP connector

Which pins should I use?

https://www.arduino.cc/en/reference/SPI

Also, why use software serial on a MEGA ? It has FOUR hardware serial ports that won’t interfere with each other..

lastchancename: Also, why use software serial on a MEGA ? It has FOUR hardware serial ports that won’t interfere with each other..

So delete the code assigning the RX and TX pins and use the pins labeled as such in the board?

  Serial.println("GPS BOOTING");
  Serial.println(" WAITING FOR GPS SAT LOCK... ");
  Serial.println("");
  Serial.println("setup done");

Big waste of RAM. Use the F() macro.

  Serial.println(F("GPS BOOTING"));
  Serial.println(F(" WAITING FOR GPS SAT LOCK... "));
  Serial.println("");
  Serial.println(F("setup done"));

etc etc

for (i = 1; i <= 200; i++)

using global variable here is OK , but …

232:
for (i = 1; i <= 200; i++)

using global variable here is OK , but …

But what?
But you’re starting from one?
But you’re ending on 200?
But you’re wasting time doing pointless calculations?

Was this an (cut and paste) attempt for a function ?

float Af2; { float feet; bmp280.getTemperature(feet); // throw away - needed for alt. bmp280.getPressure(feet); // throw away - needed for alt. bmp280.getAltitude(feet);

return feet; this exits the Setup function - in theory to loop() so add some test Serial prints at the beginning of loop() to verify that or better FIX this block of code Actually placing test Serial prints in code to really find out WHERE it goes astray is better than just stating "it won't go past Setup" .

delay(20); how do you suppose the code gets here ?

}