chipKIT® Development Platform

Inspired by Arduino™

Max32, MPIDE 0023, Serial println doesn't print everything

Created Sat, 09 Aug 2014 23:39:04 +0000 by mdsousa


mdsousa

Sat, 09 Aug 2014 23:39:04 +0000

Hi

I have some Serial.println statements and not all of them print to the serial monitor. The servos all seems behave reasonably, so I know its getting through the code base. I've tried placing strategic delays and serial.flush, but to no avail. There are no errors reported. Below is my code:

#include <SoftPWMServo.h> 

int pos = 0;         // variable to store the servo position, in microseconds
const int portAerilon = 30;  // Choose _any_ pin number on your board
const int starboardAerilon = 32;
const int portEngine = 34;
const int starboardEngine = 36;
int servoValue = 0;
String servoString = "";
 
void setup() 
{
  Serial.begin(9600);
  delay(5000); // wait for 5 seconds for serial to setup
  Serial.println("SoftServoTest up and running");
//  delay(2000);
} 

void shutdown()
{
  Serial.println("SoftServoTest is done");
  while(true)
  {
    delay(1000);
  }
}

void loop()
{
  Serial.println("servos should be centering");
  SoftPWMServoServoWrite(portAerilon, 1500); // set to middle - for MG90S Micro Servo
  SoftPWMServoServoWrite(starboardAerilon, 1500);
  SoftPWMServoServoWrite(portEngine, 1500);
  servoValue = SoftPWMServoServoRead(portAerilon);
  servoString = "portAerilon ServoRead: " + servoValue;
  Serial.println(servoString);
  servoValue = SoftPWMServoServoRead(starboardAerilon);
  servoString = "starboardAerilon ServoRead: " + servoValue;
  Serial.println(servoString);
  servoValue = SoftPWMServoServoRead(portEngine);
  servoString = "portEngine ServoRead: "+ servoValue;
  Serial.println(servoString);
//  Serial.flush();
  delay(5000);

  Serial.println("\nServos should be tracking to starboard");
  SoftPWMServoServoWrite(portAerilon, 2000); // 2ms, 90' (all way to starboard) for MG90S Micro Servo
  SoftPWMServoServoWrite(starboardAerilon, 2000); // 2ms, 90' (all way to starboard) for MG90S Micro Servo
  SoftPWMServoServoWrite(portEngine, 2000); // 2ms, 90' (all way to starboard) for MG90S Micro Servo
  delay(2000);
  servoValue = SoftPWMServoServoRead(portAerilon);
  servoString = "portAerilon ServoRead: " + servoValue;
  Serial.println(servoString);
  servoValue = SoftPWMServoServoRead(starboardAerilon);
  servoString = "starboardAerilon ServoRead: " + servoValue;
  Serial.println(servoString);
  servoValue = SoftPWMServoServoRead(portEngine);
  servoString = "portEngine ServoRead: "+ servoValue;
  Serial.println(servoString);
// Serial.flush();
  delay(3000);

  Serial.println("\nServos should be tracking to port");
  SoftPWMServoServoWrite(portAerilon, 1000); // 1ms, -90' (all way to port)
  SoftPWMServoServoWrite(starboardAerilon, 1000); // 1ms, -90' (all way to port)
  SoftPWMServoServoWrite(portEngine, 1000); // 1ms, -90' (all way to port)
  servoValue = SoftPWMServoServoRead(portAerilon);
  servoString = "portAerilon ServoRead: " + servoValue;
  Serial.println(servoString);
  servoValue = SoftPWMServoServoRead(starboardAerilon);
  servoString = "starboardAerilon ServoRead: " + servoValue;
  Serial.println(servoString);
  servoValue = SoftPWMServoServoRead(portEngine);
  servoString = "portEngine ServoRead: "+ servoValue;
  Serial.println(servoString);
  delay(5000);

  Serial.println("\nServos should be centering");
  SoftPWMServoServoWrite(portAerilon, 1500); // return to zero
  SoftPWMServoServoWrite(starboardAerilon, 1500); // return to zero
  SoftPWMServoServoWrite(portEngine, 1500); // return to zero

  shutdown();
}

Here's the output for a run:

SoftServoTest up and running
servos should be centering
portAerilon ServoRead: 



Servos should be tracking to starboard

Am I using the Serial library incorrectly?

Thanks...


djgardn2

Sun, 10 Aug 2014 01:20:22 +0000

Try to give this a try and see if it works for you.

If you change all of your code that looks like this: servoString = "portAerilon ServoRead: " + servoValue;

Change it to look like this:

servoString = "portAerilon ServoRead: "; Serial.print(servoString); Serial.println(servoValue);


mdsousa

Sun, 10 Aug 2014 13:22:37 +0000

Thanks djgardn2, I did as you recommended and was able to get the first set of printouts but the following two set did not show up. Output now is below (not sure why the first servo read is 0, but that will be another problem to check out).

SoftServoTest up and running
servos should be centering
portAerilon ServoRead: 0
starboardAerilon ServoRead: 1500
portEngine ServoRead: 1500

Servos should be tracking to starboard

Thanks...


Jacob Christ

Sun, 10 Aug 2014 18:48:09 +0000

What is the exact version of MPIDE you are using?

Jacob


djgardn2

Sun, 10 Aug 2014 20:50:56 +0000

Here is a modified version of your code attached with the changes I mentioned above so you can copy and paste this and try it, just in case I was to vague on the changes to make.

Also, notice I called the "servoValue = SoftPWMServoServoRead(portAerilon);" twice for the very first time as seen in the code, this is a quick fix for reading 0 for the first time that you experienced.

Also note, I have tested this on the chipKIT Pi's PIC32MX250F128B microcontroller and not on the Max32, but hopefully there is no difference in functionality.

#include <SoftPWMServo.h>

int pos = 0;         // variable to store the servo position, in microseconds
const int portAerilon = 30;  // Choose _any_ pin number on your board
const int starboardAerilon = 32;
const int portEngine = 34;
const int starboardEngine = 36;
int servoValue = 0;
String servoString = "";

void setup()
{
  Serial.begin(9600);
  delay(5000); // wait for 5 seconds for serial to setup
  Serial.println("SoftServoTest up and running");
  //  delay(2000);
}

void shutdown()
{
  Serial.println("SoftServoTest is done");
  while(true)
  {
    delay(1000);
  }
}

void loop()
{
  Serial.println("servos should be centering");
  SoftPWMServoServoWrite(portAerilon, 1500); // set to middle - for MG90S Micro Servo
  SoftPWMServoServoWrite(starboardAerilon, 1500);
  SoftPWMServoServoWrite(portEngine, 1500);
  servoValue = SoftPWMServoServoRead(portAerilon);
  servoString = "portAerilon ServoRead: ";
  servoValue = SoftPWMServoServoRead(portAerilon); //read twice to fix the 0 issue
  Serial.print(servoString);
  Serial.println(servoValue);
  servoValue = SoftPWMServoServoRead(starboardAerilon);
  servoString = "starboardAerilon ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  servoValue = SoftPWMServoServoRead(portEngine);
  servoString = "portEngine ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  //  Serial.flush();
  delay(5000);

  Serial.println("\nServos should be tracking to starboard");
  SoftPWMServoServoWrite(portAerilon, 2000); // 2ms, 90' (all way to starboard) for MG90S Micro Servo
  SoftPWMServoServoWrite(starboardAerilon, 2000); // 2ms, 90' (all way to starboard) for MG90S Micro Servo
  SoftPWMServoServoWrite(portEngine, 2000); // 2ms, 90' (all way to starboard) for MG90S Micro Servo
  delay(2000);
  servoValue = SoftPWMServoServoRead(portAerilon);
  servoString = "portAerilon ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  servoValue = SoftPWMServoServoRead(starboardAerilon);
  servoString = "starboardAerilon ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  servoValue = SoftPWMServoServoRead(portEngine);
  servoString = "portEngine ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  // Serial.flush();
  delay(3000);

  Serial.println("\nServos should be tracking to port");
  SoftPWMServoServoWrite(portAerilon, 1000); // 1ms, -90' (all way to port)
  SoftPWMServoServoWrite(starboardAerilon, 1000); // 1ms, -90' (all way to port)
  SoftPWMServoServoWrite(portEngine, 1000); // 1ms, -90' (all way to port)
  servoValue = SoftPWMServoServoRead(portAerilon);
  servoString = "portAerilon ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  servoValue = SoftPWMServoServoRead(starboardAerilon);
  servoString = "starboardAerilon ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  servoValue = SoftPWMServoServoRead(portEngine);
  servoString = "portEngine ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  delay(5000);

  Serial.println("\nServos should be centering");
  SoftPWMServoServoWrite(portAerilon, 1500); // return to zero
  SoftPWMServoServoWrite(starboardAerilon, 1500); // return to zero
  SoftPWMServoServoWrite(portEngine, 1500); // return to zero

  shutdown();
}

Side note on available options for the Serial.println(servoValue), you can do this in two different ways (not sure which is better verse the other):

servoValue = SoftPWMServoServoRead(portEngine); servoString = "portEngine ServoRead: "; Serial.print(servoString); Serial.println(servoValue);

or

servoValue = SoftPWMServoServoRead(portEngine); servoString = "portEngine ServoRead: "; servoString += servoValue; Serial.println(servoString);


mdsousa

Mon, 11 Aug 2014 13:38:27 +0000

What is the exact version of MPIDE you are using? Jacob

Hi Jacob, it's Mpide v 0023-linux64-20140316

djgardn2, I copied and pasted your version, which is below.

#include <SoftPWMServo.h>

int pos = 0;         // variable to store the servo position, in microseconds
const int portAerilon = 30;  // Choose _any_ pin number on your board
const int starboardAerilon = 32;
const int portEngine = 34;
const int starboardEngine = 36;
int servoValue = 0;
String servoString = "";

void setup()
{
  Serial.begin(9600);
  delay(5000); // wait for 5 seconds for serial to setup
  Serial.println("SoftServoTest up and running");
  //  delay(2000);
}

void shutdown()
{
  Serial.println("SoftServoTest is done");
  while(true)
  {
    delay(1000);
  }
}

void loop()
{
  Serial.println("servos should be centering");
  SoftPWMServoServoWrite(portAerilon, 1500); // set to middle - for MG90S Micro Servo
  SoftPWMServoServoWrite(starboardAerilon, 1500);
  SoftPWMServoServoWrite(portEngine, 1500);
  servoValue = SoftPWMServoServoRead(portAerilon);
  servoString = "portAerilon ServoRead: ";
  servoValue = SoftPWMServoServoRead(portAerilon); //read twice to fix the 0 issue
  Serial.print(servoString);
  Serial.println(servoValue);
  servoValue = SoftPWMServoServoRead(starboardAerilon);
  servoString = "starboardAerilon ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  servoValue = SoftPWMServoServoRead(portEngine);
  servoString = "portEngine ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  //  Serial.flush();
  delay(5000);

  Serial.println("\nServos should be tracking to starboard");
  SoftPWMServoServoWrite(portAerilon, 2000); // 2ms, 90' (all way to starboard) for MG90S Micro Servo
  SoftPWMServoServoWrite(starboardAerilon, 2000); // 2ms, 90' (all way to starboard) for MG90S Micro Servo
  SoftPWMServoServoWrite(portEngine, 2000); // 2ms, 90' (all way to starboard) for MG90S Micro Servo
  delay(2000);
  servoValue = SoftPWMServoServoRead(portAerilon);
  servoString = "portAerilon ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  servoValue = SoftPWMServoServoRead(starboardAerilon);
  servoString = "starboardAerilon ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  servoValue = SoftPWMServoServoRead(portEngine);
  servoString = "portEngine ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  // Serial.flush();
  delay(3000);

  Serial.println("\nServos should be tracking to port");
  SoftPWMServoServoWrite(portAerilon, 1000); // 1ms, -90' (all way to port)
  SoftPWMServoServoWrite(starboardAerilon, 1000); // 1ms, -90' (all way to port)
  SoftPWMServoServoWrite(portEngine, 1000); // 1ms, -90' (all way to port)
  servoValue = SoftPWMServoServoRead(portAerilon);
  servoString = "portAerilon ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  servoValue = SoftPWMServoServoRead(starboardAerilon);
  servoString = "starboardAerilon ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  servoValue = SoftPWMServoServoRead(portEngine);
  servoString = "portEngine ServoRead: ";
  Serial.print(servoString);
  Serial.println(servoValue);
  delay(5000);

  Serial.println("\nServos should be centering");
  SoftPWMServoServoWrite(portAerilon, 1500); // return to zero
  SoftPWMServoServoWrite(starboardAerilon, 1500); // return to zero
  SoftPWMServoServoWrite(portEngine, 1500); // return to zero

  shutdown();
}

The printout shrunk:

SoftServoTest up and running
servos should be centering
portAerilon ServoRead: 0
starboardAerilon ServoRead: 1500
portEngine ServoRead: 1500

I'm on a laptop with Ubuntu 12.04 if that helps.

Thanks...

Mike


djgardn2

Tue, 12 Aug 2014 03:11:18 +0000

Unfortunately I do not have a Max32 in order to try to figure out the issues any further.

Hopefully someone else might be able to test out your code on a Max32 or help you with your issues.

My only other guess would be to check the pins you are using and possibly try different available pins to see if anything changes.

Using the chipKIT Pi's microcontroller I am able to see all the expected outputs even the first "portAerilon ServoRead: 1500", once the second "servoValue = SoftPWMServoServoRead(starboardAerilon);" was added in the code just like the above post. Although, I'm not using Ubuntu 12.04 either.