Pages: [1]   Go Down
Author Topic: Unable to run this code on arduino uno.  (Read 318 times)
0 Members and 1 Guest are viewing this topic.
India
Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi
i am trying to run this program, however after uploading it
i do not get anything on the serial monitor. it remains blank.
what could be the reason ?
i tried to see if the interrupt was getting triggered somehow, but doesn't seem that way.
here is the code
edit : i forgot to add, the programs gets uploaded without any issues.
Code:
/*
  IR Capture
  Copyright 2012, all rights reserved.
  James M. Eli
  1/14/2012
 
  project parts:
    (1) arduino 16MHz
    (1) 38KHz IR receiver
    (1) breadboard
    (3) wires
 
  IR - Arduino
  SIG - D2
  GND - GND
  VCC - VCC
*/

//definitions
#define IN_PIN 2
#define MAX_CAPTURE 584  // Line number 1
 
//globals
uint32_t now, start, capture[MAX_CAPTURE];
volatile bool flag_complete;
uint16_t i;    // Line number 2 uint8_t to uint16_t Key point of RAWBUF. uint8_t maximum range 255

void setup() {
  flag_complete = false;
  start = 0;
  now = 0;
  i = 0;
  Serial.begin(9600);
  Serial.print("Ready to capture.");
  attachInterrupt(0, IRInterrupt, CHANGE);
}
  
//interrupt fires on ir event (rise/fall)
void IRInterrupt() {
  Serial.print("entered interrupt");
  now = micros();
  capture[i++] = now - start;
  start = now;
  if (i >= MAX_CAPTURE) {
    detachInterrupt(0);
    flag_complete = true;
  }
}
 

void loop() {
  while (1) {
    if (flag_complete) {
      for (i=0; i < MAX_CAPTURE; i++) {        
        Serial.println(capture[i]);
        //Serial.print(",");
        flag_complete = false;
      }
    }
  }
}
« Last Edit: May 12, 2013, 09:05:05 am by fuzail » Logged

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can't call serial.print inside of an ISR.  You should at least be seeing the "Ready to capture" message after removing the print from the ISR.
Logged

Experience, it's what you get when you were expecting something else.

India
Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i do not get the "ready to capture" message.
i thought for some reason the isr is getting triggered. so i added the serial print there to see if it was in fact entering the isr. but good to know that u cant use Serial.print in an isr
Logged

India
Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i have noticed something,
the maximum voltage i am getting is around 4.5 volts(between any of the high pins and ground) and not 5 volts.
would this be effecting the program in any way?
Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
#define MAX_CAPTURE 584  // Line number 1
uint32_t now, start, capture[MAX_CAPTURE];

584 * 4 = 2.3 k-bytes RAM.
Logged

India
Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks.!
Logged

Pages: [1]   Go Up
Jump to: