Go Down

Topic: Serial Monitor Serial.println errors (Read 273 times) previous topic - next topic

VizorTrip

Apr 29, 2018, 08:32 am Last Edit: Apr 29, 2018, 08:33 am by VizorTrip
Hi! My serial monitor is "misspells" stuff. Im not sure what the cause of that is, but it would simply miss a letter or outputs extra spaces randomly in between. Here is an example (image attached) where it wont add 'o' at the end of "Hello" after first print. There is nothing in the code that tells it to do that. Other times it would add extra spaces in between lines. The board is Uno by Osepp in Canada. It's my first Arduino board and i've been happy with it so far, haven't had much problems with hit before.

Best Regards


pert

Please post your full sketch. If possible you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's ok to add it as an attachment. Don't put your code in some external file service like dropbox, etc. We shouldn't need to go to an external website just to help you. I do feel it's reasonable to post a link to code hosted on GitHub or similar code hosting sites since that's an platform specifically designed for this sort of thing

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor then you will not  have access to this useful tool. I recommend using the standard Arduino IDE instead.

VizorTrip

#2
Apr 29, 2018, 10:28 am Last Edit: Apr 29, 2018, 10:34 am by VizorTrip
Hey, thanks, will do. I wasn't sure if should post it, it's kinda ugly and incomplete. It doesn't affect the function but I'm just really curious why it's doing it.

Best Regards

Code: [Select]

#include "pitches.h"

const int cook = 25;
const int relax = 25;
int soundDelayTime = 15;

const int cookTimes = 9;
const int relaxTimes = 8;

int led; // the PWM pin the LED is atteched to
int red = 9;
int blue = 10;
int green = 11;
int buzzerPin = 8;



unsigned long chronos;
float seconds;



void setup()
{
  Serial.begin(9600);
  pinMode(led, OUTPUT); // declares pin to be an output
}

void loop()
{
  chronos = millis();
  Serial.println("Hello World"); 
  Serial.print("Time in milsec: ");   
  Serial.println(chronos);
   
  seconds = chronos / 1000;
  Serial.print("Time in sec: ");
  Serial.println(seconds,0);
 
  int cookCounter;
  for (cookCounter = 0; cookCounter < cookTimes; cookCounter++)
  {
    analogWrite(green, 255);
    alert();
    delay(cook);
    analogWrite(green, 0);

    if (cookCounter < relaxTimes)
    {
      analogWrite(red, 255);
      alert();
      delay(relax);
      analogWrite(red, 0);
    }
  }
  analogWrite(blue, 255);
  alert();
  delay(50);
  analogWrite(blue, 0);
}

void alert()
{
  tone(buzzerPin, NOTE_C6, soundDelayTime);
  delay(soundDelayTime);
  tone(buzzerPin, NOTE_D6, soundDelayTime);
  delay(soundDelayTime);
  tone(buzzerPin, NOTE_E6, soundDelayTime);
  delay(soundDelayTime);
  tone(buzzerPin, NOTE_F6, soundDelayTime);
  delay(soundDelayTime);
  tone(buzzerPin, NOTE_G6, soundDelayTime);
  delay(soundDelayTime);
  tone(buzzerPin, NOTE_A6, soundDelayTime);
  delay(soundDelayTime);
  tone(buzzerPin, NOTE_B6, soundDelayTime);
  delay(soundDelayTime);
  tone(buzzerPin, NOTE_C7, soundDelayTime);
  delay(soundDelayTime);
}



bos1714

Hi there!

I noticed in the final Serial.println() command you have the following:

Serial.println(seconds,0);

With the Serial.println() command, there can be two arguments inside he parenthesis, the first being the data, and the second being the format of he data, such as printing a number in decimal, hexadecimal, or binary format. This may cause errors if you try to print data or text afterwards. In the screen capture you put, the first sequence of printing is successful, but after that there are errors. Try deleting the zero and the comma in that last command like below and see if that works.

Serial.println(seconds);
Time line? Time isn't made out of lines. It is made out of circles. That is why clocks are round.

VizorTrip

Hi there!

I noticed in the final Serial.println() command you have the following:

Serial.println(seconds,0);

With the Serial.println() command, there can be two arguments inside he parenthesis, the first being the data, and the second being the format of he data, such as printing a number in decimal, hexadecimal, or binary format. This may cause errors if you try to print data or text afterwards. In the screen capture you put, the first sequence of printing is successful, but after that there are errors. Try deleting the zero and the comma in that last command like below and see if that works.

Serial.println(seconds);
Hey, Thanks. Didn't even noticed it there.

bos1714

Time line? Time isn't made out of lines. It is made out of circles. That is why clocks are round.

Go Up