Go Down

Topic: Problems with Serial.println (Read 1 time) previous topic - next topic

James C4S

Quote
millis() returns a large number (float/double), or?

It returns a long.  

print / println should convert ints and longs to an ASCII-decimal.  It normally isn't necessary to call it with the optional format parameter.

Without the additional details that Onions is asking for (and/or complete code from the original poster) this is going to be very difficult to debug.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

denniscj7

#6
Jul 05, 2011, 09:54 pm Last Edit: Jul 07, 2011, 09:02 pm by denniscj7 Reason: 1
I am running on a Win7 x64 system and using Arduino 022 IDE.

Here's what just happened using the following code:
Code: [Select]

#include "Tlc5940.h"

]#include "math.h"
void setup() {
    Serial.begin(9600);
    Serial.println ("setup start");
    Serial.println (millis());
}
void loop(){
 Serial.print("loop start");
 Serial.println(millis());
 delay (1000);
}

RESULT is     fx`f~      actually the line is much longer but this is all I got with copy/paste. Gibberish and all on one line.

The includes are there because they are vital to the main program I'm working with. I also just tried same code without the includes and the results were same as above.

I also just tried with a different UNO board and the results were the same.

NOTE - all of the above was done on a WIN7 x64 platform which is my base system.

NOW - the following is from an XP system in Virtual PC on the same computer.

here's the code:
Code: [Select]
#include <math.h>
int ledpinyellow = 3;
int ledpingreen = 5;
int ledpinred = 9;
int currentmillis=0;
int previousmillis=0;
double startmillis=0;
int N=0;
double clockint=50;
double ledstep = -1;
double x=0;
double y1=0;
double y2=0;
double y3=0;
double z1=0;
double z2=0;
double z3=0;
void setup (){
  Serial.begin(9600);
  x=0;
  y1=0;
  Serial.println("millis");
  Serial.println(millis());
  previousmillis=millis();
  currentmillis=millis();
}
void loop (){
 currentmillis=millis();
 while(currentmillis-previousmillis<clockint){
   delay(10);
   currentmillis=millis();
 }
 previousmillis=currentmillis;
ledstep +=1;
x=10* ledstep*(clockint/1000);

if (x >0 & x <9){
  y1= 4*4*x;
  analogWrite(ledpinyellow, y1);
  analogWrite(ledpingreen,255);
}
if (x>=9 & x<=10 ){
  analogWrite(ledpingreen,0);
  analogWrite(ledpinyellow,y1);
}  
if(x>10  & x<= 20.5){
  y1=4.7*50*sin(.15*x+.1)+18;
  analogWrite(ledpinyellow,y1);
   }



 Serial.println("x");
Serial.println(x);
Serial.println(y1);
Serial.println(y2);
Serial.println(y3);

if (ledstep >=50){
ledstep = -1;
Serial.println("time");
Serial.println(millis()-startmillis);

startmillis=millis();
}
}

and the result is:

millis
6
millis
6
x
0.00
0.00
0.00
0.00
x
0.50
and it goes on

so this result looks very good and is what is expected.

However, when I load my main program - here's the first several lines of setup -
note: I have attached the complete program in a file.
Code: [Select]
void setup() {

     Serial.begin(9600);
     
Tlc.init();
Tlc.clear();
Tlc.update();
//      delay(1000);
   Serial.println ("setup start");
   Serial.println (millis());
//**************************  wakeup  begins  **********************
  x=0;
  y1=0;
   prevmillis=millis();
  curmillis=millis();
    while(ledstepint<50){
 curmillis=millis();
 while(curmillis-prevmillis<clockintdbl){
   delay(10);
   curmillis=millis();
 }
 prevmillis=curmillis;

ledstepint +=1;
x=10* ledstepint*(clockintdbl/1000);
/////////////////////////////////////////////////////////////////////////
if (x >0 & x <9){
  y1= 4*4*x;
    }
if (x>=9 & x<=10 ){
   y1=255;
   }  
if(x>10  & x<= 20.5){
  y1=4.7*50*sin(.15*x+.1)+18;
   }
/////////////////////////////////////////////////////////////////////////    
   brt[ledstepint]=y1;
//   Serial.println(y1);
 }
ledstepint=-1;
// delay (2000);

Serial.println ("setup ends");
Serial.println (millis());
//***********


THE RESULT is blank - nothing at all. This only thing that changed here is the program I loaded into the UNO.

This is driving me nuts and wasting a lot of time - would very much appreciate help.

I just saw a few posts that came in as I was preparing this reply. Before my current problems, I have used Serial.println (millis()) many times with no problems at all.



James C4S

#7
Jul 05, 2011, 09:59 pm Last Edit: Jul 05, 2011, 10:07 pm by James C4S Reason: 1
When posting code, please wrap them in the "Code" tags (the "#" in the editor's tool bar.)  Please edit your post so that your code is easily readable from your results.

The code you posted doesn't seem to match what is in the .pde you attached.  Just a note on that code, I did a quick count and before code even starts to run you have allocated 1218bytes of RAM.  That's a little over half of the ATmega328's available RAM.  Strings, like those used in your Serial.printlns() can add up fast.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

AWOL

Quote
Quote
millis() returns a large number (float/double), or?
It returns a long.

sp. "unsigned long"
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Gadget999


Doesn't work for me.

Code: [Select]

Serial.println( (int) millis() );

println can't print float/double. You have to convert it to int.

I confess this isn't a nice solution..


crikey ! how the hell do you send a number that has a decimal point ie 1.1234567890 ?


Go Up