Serial.print()

I need to see my variables during execution of firmware. I use Serial.begin(9600); in the setup structure and Serial.print(variable); in the loop structure. during execution, when I open the serial monitor (tools menu> Serial Monitor) the window remains blank.

is there something I am not doing right?

Is the data rate in the Serial Monitor also set to 9600?

yes the serial monitor also reads 9600.

is there something I am not doing right?

Yes, you're not posting your code.

See number 6 here:
http://forum.arduino.cc/index.php?topic=97455.0

What the heck, read it all. :wink:

is there something I am not doing right?

Yes, either that or they have changed the way the arduino works since this morning.

i think what they mean is that we can maybe help you further if you post the code you are using (using the CODE tags!)
8)

I tried the following example but could not see the output on serial monitor:
(just pasting the relevant lines)

 void setup()
 {
   Serial.begin(9600);
   attachInterrupt(0, rpm_fun, RISING);

  }

 void loop()
 {
   if (half_revolutions >= 20) { 
     rpm = 30*1000/(millis() - timeold)*half_revolutions;
     timeold = millis();
     half_revolutions = 0;
     Serial.println(rpm,DEC);
   }
 }

 void rpm_fun()
 {
   half_revolutions++;
   //Each rotation, this interrupt function is run twice
 }

Post all the code, including any declarations.

This is the entire code:

 /* this program counts tach input from a hall sensor of motor with 2 magnets/ rev
  and converts it into RPM.
  */
  
 volatile byte half_revolutions;
 unsigned int rpm;
 unsigned long timeold;

 void setup()
 {
   Serial.begin(9600);
   attachInterrupt(0, rpm_fun, RISING);

   half_revolutions = 0;
   rpm = 0;
   timeold = 0;
 }

 void loop()
 {
   if (half_revolutions >= 20) { 
     //Update RPM every 20 counts, increase this for better RPM resolution,
     //decrease for faster update
     rpm = 30*1000/(millis() - timeold)*half_revolutions;
     timeold = millis();
     half_revolutions = 0;
     Serial.println(rpm,DEC);
   }
 }

 void rpm_fun()
 {
   half_revolutions++;
   //Each rotation, this interrupt function is run twice
 }

Firstly I would put a Serial.println("Whatever"); immediately after the Serial.begin, just to confirm that things are communicating.

I'm assuming that the hardware is wired up correctly and works? You know that there is a signal on the interrupt pin?

Which Arduino?

An image of your setup is also nice too have so we can check your wiring.
Toggling a LED also helps in debugging.

the serial code looks right to me, so I suspect the interrupt isnt working for some reason;
It might be due to which board you are using, not all of them have the same interrupts on the same pins.

what I would do is to add;

 void rpm_fun()
 {

  // toggle the board LED on pin 13
  digitalWrite(13, !digitalRead(13));

   half_revolutions++;
   //Each rotation, this interrupt function is run twice
 }

This should flash the LED in time with interrupts received, and then you'll know the code is being executed. If it is, then i'm stuck...

MB

you can alway try something like

void setup() {
   Serial.begin(9600);
}

void loop() {
   Serial.println("WORKING!!!");
}

just to check that everything is in order...
:wink:

Thanks a lot everyone..... I will try out these suggestions.... if I still cant make it work, I know where to find you guys..... ]:smiley: