Functions not running in Loop Function

Ok, so I have a UNO, a sparkfun zed-f9p GPS RTK board, and a serial LCD screen. I also have a sparkfun bluetooth modem feeding RTK corrections into the GPS module.

I am using sparkfuns ublox gps library and sparkfun ser.LCD library. The UNO, GPS board, and LCD all communicated via I2C. The bluetooth modem communicates with the GPS board on the boards UART2

What I am running into is when I power up the UNO everthing powers up and runs, but it seems to stop after it executes the void setup() function. I wrote the program void loo() function calling 3 other functions, but it seems that none of them are running. However I do call one of the functions in the void setup() and it does run. So im not sure why the functions wont run in the void loop().

Can someone take a look and see if you can find an issue? Please go easy on me as this is the first program ive written that is this complex(yet im sure is still on the novice level when it comes to programming)

I tried to add a few comments at the start of each function in the code below to help explain things

the code below is just an example of the layout, the real code makes the post more than 9000 characters so I attached it in a file.

Thanks

//define some things
//run the void setup()
// call speedSet() within void setup() and it does run as the value shown on the lcd is correct


/* Nothing in the void loop function seems to run regardless of switch states)
 * The LCD screen goes blank(becuse the last command to the lcd was lcd.clear)
 */
void loop() {
  while (speedSetSwitch == HIGH){     // run the program to select desired ground speed
     speedSet();
  }
  
  if (modeSwitch == LOW){            //run the program for information only, no automatic speed adjustments
    infoUpdate();
  }
  if (modeSwitch == HIGH) {         //run the program for automatic speed control
    infoUpdate();
    speedCorrection();  
  }
}

void speedSet(){
    run some code
}

void infoUpdate(){
    run some code
}

void speedCorrection(){
    run some code
}

PivotSpeedController_Xv2.1.ino (17.6 KB)

Most probably your program is stuck in setup(), which you did not show.

Ude test prints, Serial.print telling " Entering function X". After returning from function X make a test print “Reurned from X”.
Serial monitor will tell what happends.

it seems to stop after it executes the void setup() function

Post the printout from setup(), so we can see how far it gets.

Why is this code disabled? Do you expect the rest of the code to work if you ignore error conditions?

  rtkType = myGPS.getCarrierSolutionType();   // for some reason this is not working, it never sees its in rtk float or fixed, but the led on gps boad indicates float, then fixed
  //if (rtkType != 1 || rtkType !=2){   // wait for RTK before starting
    // Serial.println(F("waiting for RTK"));
    // lcd.clear();
    // lcd.print("Waiting for RTK");
    // while (1);
  //}

Note: if the above is enabled, the code will NOT wait for RTK. The while(1); is a permanent infinite loop, equivalent to a processor halt. With the UBlox M8P, it can take up to 15 minutes to get an RTK carrier solution.

When the code is large You can send the first 9000 chars in one code tsg and then another batch in a second code tag.
Give us the beginning, from the top down to the end of setup.

Railroader:
When the code is large You can send the first 9000 chars in one code tsg and then another batch in a second code tag.

You can send the first 9000 chars in one posting and then another batch in a second posting.

The full code has already been attached.

Which messages appear on the LCD?

Paul__B:
You can send the first 9000 chars in one posting and then another batch in a second posting.

Thanks!
I've seen double code tags in one posting but now I know more about that.

DrDiettrich:
The full code has already been attached.

Which messages appear on the LCD?

Not readable on my phone.....

I can’t see the attached code, but is if (modeSwitch == HIGH) modeSwitch a pin number by any chance?

Many people seem to have missed that PivotSpeedController_Xv2.1.ino is attached to the original posting, answering most questions already.

Now we should know what the LCD shows during setup().

DrDiettrich:
Many people seem to have missed that PivotSpeedController_Xv2.1.ino is attached to the original posting, answering most questions already.

Some people seem to have missed the fact that some other people on mobile devices can’t open .ino files.

No digitalRead in the code, so TheMemberFormerlyKnownAsAWOL is right in reply #9 :wink:

TheMemberFormerlyKnownAsAWOL:
Some people seem to have missed the fact that some other people on mobile devices can’t open .ino files.

Thanks for the update, one more reason for not using a mobile device. On Windows I can open .ino files without the IDE, e.g. using Notepad. I’d think that mobile devices have similarly powerful editors.

That’s great to know, but none of my laptops fit in my shirt pocket.

It never ceases to amaze me that code can get so big without basic testing.

Ok thanks everyone, I figured it out (mostly)

Adding Serial.print("entering loop") or "this part of the code") helped find my issue, basically had to add a print before each line almost but it found it,

Apparently I never called for the program to poll the state of the switches(pins 2&3) so when it got to the loop code, when it looked at the condition, example:

void loop() {
  while (speedSetSwitch == HIGH){     // run the program to select desired ground speed
     speedSet();
  }

I had it looking at the pin# the switch was assigned to and not the state, so duhh the speedSetSwitch was connected to pin 2. So the value 2 is not equal to 1 or 0, so it never entered the call functions (same for the other functions also)

So I fixed that but for some reason when calling speedSetSwitch == HIGH, I had to change HIGH to 1 in order for the code to work. I thought HIGH or LOW is the same as calling 1 or 0.

Anyways its all seems to be working. Now i just need to get it outside and test if my calculation function is doing the math right when the receiver is actually moving.

KEwert:
So I fixed that but for some reason when calling speedSetSwitch == HIGH, I had to change HIGH to 1 in order for the code to work. I thought HIGH or LOW is the same as calling 1 or 0.

Maybe give us a look at your new code.

I thought HIGH or LOW is the same as calling 1 or 0.

It is.