Go Down

Topic: How to monitor the output using Adruino 328 (Read 1 time) previous topic - next topic

zolofy

[size=14]I've got several problem here :[/size]

[size=14]1 - How to send the pulses that generated by the quadrature encoder to my Adruino Duemilanove 328? My input should be like this [/size]




[size=14]and this is my program in order to get the desire output[/size]

Code: [Select]
int value = 0;

void setup()
{
Serial.begin(9600);
 pinMode(13, INPUT);
}

void loop()
{
while (1)
{
{
 if (!(digitalRead(13)))
 {

 Serial.println ("one");
 
 
 }
 else
 
 Serial.println ("zero");
}
}
}


[size=14]and after I've done compiling and uploading the program, can I just monitor the output using serial monitor that already have in Adruino Environment?[/size]

retrolefty

Yes. Also there is no need for the while (1) loop in your sketch. The void loop() funtion will keep repeating your code. That is why it's called loop.  ;D

Lefty

robtillaart

Be aware that at 9600 baud your serial communication takes ~1 millisec per character send. If your pulses are faster than that you will miss them so set the baudrate at highest value possible e.g. 115200 is approx 10 times as fast.

below a variation on your code that holds the state and will only produce a timestamp + state if the value of the squarewave has changed.

(not tested)
Code: [Select]


int state = 0;
int value = 0;

void setup()
{
 Serial.begin(115200);
 Serial.println("Start");
 pinMode(13, INPUT);
}

void loop()
{
 value = digitalRead(13);
 if (1 == value && 0 == state)
 {
   Serial.print(millis());
   Serial.println ("  one");
   state = 1;
 }
 if (0 == value && 1 == state)
 {
   Serial.print(millis());  
   Serial.println ("  zero");
   state = 0;
 }
}

If you can use another pin iso 13 you could use the led of pin 13 to show the state of the square wave too.

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up