Pages: [1]   Go Down
Author Topic: How to monitor the output using Adruino 328  (Read 1186 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

[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:
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]
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17253
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13469
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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.

Logged

Rob Tillaart

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

Pages: [1]   Go Up
Jump to: