Weird characters in serial monitor window

1,073 views
Skip to first unread message

laurynas...@gmail.com

unread,
Apr 23, 2013, 10:16:11 AM4/23/13
to accels...@googlegroups.com
Hello,

I want to make calculations in code, which in result will be used for defining  position for stepper. But when I open serial monitor windows, there is always weird characters in first string. In second and further bottom strings numbers are correct (130.25). 

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper1(AccelStepper::FULL4WIRE, A3,A1,A2,A0); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper2(AccelStepper::FULL4WIRE, 0,2,1,3);

void setup()
{  
  // Change these to suit your stepper if you want
  stepper1.setMaxSpeed(2000);
  stepper2.setMaxSpeed(2000);

  Serial.begin(9600);
  
}

void loop()
{
  int a = 1000;
  int b = 2;
  float c = sqrt(a*a+b*b);
  Serial.println(c); 
  delay(200);  

   stepper1.moveTo(c);  // set target forward c steps
  stepper2.moveTo(c);  // set target forward c steps
  
  while (stepper1.distanceToGo() != 0 || stepper2.distanceToGo() != 0) 
  {
    stepper1.setSpeed(300);
    stepper2.setSpeed(300);   
    stepper1.runSpeedToPosition();
    stepper2.runSpeedToPosition(); 
  }
   

  }


When I try to run this code without accestepper library, like this:

void setup()
{  

  Serial.begin(9600);
  
}

void loop()
{
  int a = 1000;
  int b = 2;
  float c = sqrt(a*a+b*b);
  Serial.println(c); 
  delay(200);  
  }

then I got normal serial monitor data from beginning. How should code perform calculation to get the right value from beginning?

Thank you help, Laurynas

Jan E

unread,
Oct 4, 2013, 4:23:24 AM10/4/13
to accels...@googlegroups.com
hello.

Im having same problem.

As soon as i put in the blelow line in my program, the output to serial monitor doesnt work/show/shows less characters from a string printed with Serial.println instruction.
AccelStepper stepperX(1, sXpin_s, sXpin_d);
Im using big easy driver.

best regards

Jan E

unread,
Oct 4, 2013, 4:25:30 AM10/4/13
to accels...@googlegroups.com
...and my environment is Arduino mega 2560 with last version of accelstepper lib and windows 7.

thank you

Po Lee

unread,
Oct 18, 2013, 8:28:37 PM10/18/13
to accels...@googlegroups.com
Hey Laurynas,

Fair warning - I'm really a beginner at this, so take the following with a grain of salt.

I uploaded your sketch and it worked fine for me -130.25 from the very second I opened the serial monitor.  I'm using an easydriver, not the 4wire setup that you have, so I did change that.  However, I recently ran into another unrelated problem where I was getting strange output from my serial monitor.  After asking around, I was told to Serial.flush() and Serial.end() before the action and then Serial.begin() again afterwards.  In my case, I was putting the Arduino to sleep, and on wake up, the Serial monitor would output strange characters.  That cleared up the problem for me... Hopefully that helps!

Jan E

unread,
Nov 19, 2013, 11:00:17 AM11/19/13
to accels...@googlegroups.com
hi.
My problems was running out of (variable) memory :)
regards

kl. 16:16:11 UTC+2 tirsdag 23. april 2013 skrev Laurynas Valuzis følgende:
Reply all
Reply to author
Forward
0 new messages