Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Troubleshooting / Re: help with first upload (Diecimila)? on: March 13, 2008, 04:56:32 pm
That worked, problem solved!  Thanks!!
2  Forum 2005-2010 (read only) / Troubleshooting / Re: help with first upload (Diecimila)? on: March 13, 2008, 07:36:04 am
Yes, I did install the FTDIUSB Intel drivers that I downloaded with the Arduino distribution.  Version v2_2_6.
And my understanding from the Mac documentation is that I don't need to set the Serial device because I am using USB.
From the documentation, it looks like all I should have to do is hit Upload...


3  Forum 2005-2010 (read only) / Troubleshooting / help with first upload (Diecimila)? on: March 12, 2008, 09:05:23 pm
I just got my first Arduino (Diecimila) yay! but it's not working right off.
I wonder if someone can help.

When I connect the board to USB I get the green power LED and an LED that blinks quickly and erratically at pin 13.
The computer is an Intel Mac OS X 10.4.11.  I installed the Intel drivers and restarted my Mac.
When I hit the reset button, the LED blinks once, turns off for a second, then begins the fast blinking again.

I ran the Arduino application and opened the Blink example.  When I hit "upload" I get:

Binary sketch size: 1108 bytes (of a 14336 byte maximum)

java.lang.NullPointerException
      at processing.app.Serial.setDTR(Serial.java:480)
      at processing.app.Uploader.flushSerialBuffer(Uploader.java:76)
      at processing.app.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:69)
      at processing.app.Sketch.upload(Sketch.java:1699)
      at processing.app.Sketch.exportApplet(Sketch.java:1761)
      at processing.app.Editor$42.run(Editor.java:1955)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

The I tried to "Burn Diecimila Bootloader" under the Tools menu and got:

avrdude: usbdev_open(): did not find any USB device "usb"

Can someone help with this?

4  Forum 2005-2010 (read only) / Interfacing / Re: Interfacing a NEC IR remote on: August 03, 2008, 11:42:18 am
Well, I found a solution by trial and error which I'll offer here for anyone else that may run into a similar problem.  I found that I could not receive signals from the remote while the motors were running.  If I stopped the motors I had no problem receiving IR.  So my solution was to implement a motor "duty-cycle" within the loop() function.
Here's a copy of the working code:

#include <NECIRrcv.h>
#include <ServoTimer1.h>

/* Pin assignments */
#define EYEPIN    0    // IR detector/emitter
#define SERVOPIN  9    // eye control
#define BUMPERPIN  7   // bump switch
#define IRPIN     8    // NCR IR detector is connected to
#define MOTOR_L1  5
#define MOTOR_L2  6
#define MOTOR_R1  11
#define MOTOR_R2  12
#define LEDPIN    13

// Servo motor contstants
#define SERVO_STEP_SIZE     5      
#define NUM_SERVO_STEPS    36
#define STRAIGHT_AHEAD     18  

// IR distance constants
#define DANGER_DISTANCE     500

ServoTimer1 servo;
NECIRrcv ir(IRPIN);

void setup()
{
  pinMode(MOTOR_L1, OUTPUT);
  pinMode(MOTOR_L2, OUTPUT);
  pinMode(MOTOR_R1, OUTPUT);
  pinMode(MOTOR_R2, OUTPUT);
  pinMode(LEDPIN, OUTPUT);
  servo.attach(SERVOPIN);
  moveServo(STRAIGHT_AHEAD);
  ir.begin() ;
//  Serial.begin(9600) ;
//  Serial.println("NEC IR code reception") ;
}

void loop()
{
  unsigned long ircode=0;
  static boolean remoteControl = false;
  
 //The motors go off at the end of every loop to give the remote a chance to get caught.
 //Turn it on here and make sure it runs a bit (do it yourself PWN)
  motorOn();  
  for (int i=0; i<250; i++);  // Make sure the motor gets to run a little
 
 //Check to see if we smashed into anything.  If so, back up and look for a better way to go.
  if (digitalRead(BUMPERPIN) == HIGH) {
    motorReverse();
    motorOn();
    delay(1000);
    motorOff();
    if (bestDirection() > 0)
      motorSpinRight();
    else
      motorSpinLeft();
    motorOn();
    delay(500);
    motorOff();
   }
 
  //This section controls the 'bot with the NCR IR remote.
  //Buttons used are Power ON/OFF, the four arrow keys, and the enter key.
  if (ir.available()) {
    ircode = ir.read();
//    Serial.print("got code: 0x") ;
//    Serial.println(ircode,HEX) ;
  }
  //Power button toggles the variable remoteControl on and off.
  if (ircode == 0xED12BA45) {  
    motorStop();
    if (remoteControl == true) {
      digitalWrite(LEDPIN, LOW);
      remoteControl = false;
    }
    else {
      digitalWrite(LEDPIN, HIGH);
      remoteControl = true;
    }
  }

  //When we're under remoteControl, obey the buttons, otherwise ignore them.
  if (remoteControl == true) {
    switch (ircode) {    // Up arrow
      case 0x7F80BA45:
        motorForward();
        break;
      case 0x7E81BA45:  // Down arrow
        motorReverse();
        break;
      case 0xB24DBA45:  // Left arrow
        if (isMoving())
          motorTurnRight();
        else
          motorSpinRight();
        break;
      case 0xAE51BA45:  // Right arrow
        if (isMoving())
          motorTurnLeft();
        else
          motorSpinLeft();
        break;
      case 0xDE21BA45:  // Emter
        motorStop();
        break;
      default:          // Anthing else, including nothing at all, is ignored.
        break;
    }
  }
  else {                // Remote control = off
 
   // Check to see if there's anything in front of us.  Debounce the IR even though we are moving...
   int distance = analogRead(EYEPIN);
    while (abs(distance - analogRead(EYEPIN)) > 20) {
      distance = analogRead(EYEPIN);
    }

    // If there's an obstacle too close to us, stop and turn around.
    if (distance > DANGER_DISTANCE) {
      motorOff();
      if (bestDirection() > 0) motorSpinRight();
      else motorSpinLeft();
      motorOn();
      delay(500);
      motorStop();
    }
    else {    
      motorForward();
    }
  }
  
  // Turning the motor off allows IR button presses to be received.
  motorOff();
}


/*
 * Routine to return the direction of least obstruction so we can turn that way.
 * Greater than zero for right, less than zero for left.
 */
int bestDirection() {
  int total=0, distance;
  
  for (int i=0; i<=NUM_SERVO_STEPS; i++) {
    moveServo(i);
    
    //Debounce the IR reading, the servo is bouncing around a lot.
    distance = analogRead(EYEPIN);
    while (abs(analogRead(EYEPIN) - distance) > 10) {
      distance = analogRead(EYEPIN);
    }
    if (i < NUM_SERVO_STEPS/2)
      total -= distance;
    else
      total += distance;
  }
  moveServo(STRAIGHT_AHEAD);  // Center it back again.
  return(total);
}

/* Routines to move the servo */
void moveServo(int distance) {
  servo.write(distance*SERVO_STEP_SIZE);
  delay(50);  /* For the servo to settle */
}


/* Routines to move the motors */
int motorL1, motorL2, motorR1, motorR2;

bool isMoving(void) {
  if ((motorL1 == motorL2) and (motorR1 == motorR2))
    return(false);  //not moving
  return(true);    //moving
}
    
void motorOff(void) {
  digitalWrite(MOTOR_L1, LOW);
  digitalWrite(MOTOR_L2, LOW);
  digitalWrite(MOTOR_R1, LOW);
  digitalWrite(MOTOR_R2, LOW);
}

void motorOn(void) {
  digitalWrite(MOTOR_L1, motorL1);
  digitalWrite(MOTOR_L2, motorL2);
  digitalWrite(MOTOR_R1, motorR1);
  digitalWrite(MOTOR_R2, motorR2);
}
  
void motorStop(void) {
  motorL1 = LOW;
  motorL2 = LOW;
  motorR1 = LOW;
  motorR2 = LOW;
}    
  
void motorForward(void) {
  motorL1 = HIGH;
  motorL2 = LOW;
  motorR1 = HIGH;
  motorR2 = LOW;
}    
  
void motorReverse(void) {
  motorL1 = LOW;
  motorL2
5  Forum 2005-2010 (read only) / Interfacing / Re: Interfacing a NEC IR remote on: July 27, 2008, 09:04:38 pm
Is there a way to check how much RAM I'm using?
Not sure why I'd get the symptoms I'm seeing vs. the program crashing if it was RAM ...
6  Forum 2005-2010 (read only) / Interfacing / Interfacing a NEC IR remote on: July 27, 2008, 04:51:17 pm
I wonder if anyone can give me an idea as to what may be wrong.
I am unable to intreface a NEC IR remote to my Arduino Decimilla.

Here's the situation:
I've built an object-avoiding 'bot.  It has geared motors, driven by a LM293 on pins 4,5 and 11,12.
It has a Sharp IR sensor for seeing objects, connected to analog pin zero.
The IR sensor is mounted on a servo.  The servo is connected to pin 10 and is driven using the ServoTimer1 library, which I understand uses timer 1.  All is well with this setup.

Now I want to optionally control the 'both with a remote.  I ripped the IR receiver out of a dead DVD player (Toshiba) and I have the corresponding remote.  I'm using the NECir library.  Hooking up the IR and running the sample program works great.  The program prints out codes as I push buttons on the remote.  

Now even without wiring the IR to the 'bot, if I simply include libraary NECir and add an ir.begin() statement to my setup() function, all heck breaks loose.  One of my motors stops turning completely.  The other seems to turn sporadically.  The servo seems to "slip" to its zero position, almost as if it was being disconnected for short periods of time.

From what little I can tell NECir used Timer 2, not Timer 1.  Any idea what might be going on?
7  Forum 2005-2010 (read only) / Exhibition / Re: Control Arduino with Universal Remote on: December 17, 2008, 08:26:23 am
No that code worked fine for me, make sure you've got the NECIR library installed.
8  Forum 2005-2010 (read only) / Exhibition / Re: Control Arduino with Universal Remote on: December 16, 2008, 10:00:31 pm
Maybe a syntax error of some kind?  Did you cut and paste the code exactly as is, or type it in yourself?  If the latter, post your code and maybe I can spot the problem.  By the way, I got this working perfectly, basically by making sure the servo was stopped anytime I was reading the receiver.  I think there was some interference going on.
9  Forum 2005-2010 (read only) / Exhibition / Re: Control Arduino with Universal Remote on: July 28, 2008, 06:33:52 pm
Well I don't think it is a memory problem.  I tried two different memory tests down in the innermost loop.  One showed 638 bytes free, the other, 697.  

For reference, here's my code, I'd sure appreciate the help.  I wonder if the NECIRrcv library is colliding with servoTimer1 in some way.  When I uncomment the ir.begin() line, things go bonkers.


#include <ServoTimer1.h>
#include <NECIRrcv.h>

int eyePin = 0;
int servoPin = 10;
int bumperPin = 7;
int motor_leftdig=4;
int motor_leftpwm=5;
int motor_rightdig=12;
int motor_rightpwm=11;
int irPin = 8;

/* Object constants */
#define DANGER_DISTANCE     500
#define MAX_SAFE_DISTANCE   400

/* Servo motor contstants */
#define SERVO_STEP_SIZE     5      
#define NUM_SERVO_STEPS    36
#define STRAIGHT_AHEAD     18  

/* Motor speeds.  PWM output pins turn 0-255 into 0-5v */
#define  NO_SPEED      0
#define  HALF_SPEED  127
#define  FULL_SPEED  255

#define  ON  0
#define OFF  1

int view[NUM_SERVO_STEPS];
ServoTimer1 servo;
NECIRrcv ir(irPin);

void setup() {
  pinMode(motor_leftdig, OUTPUT);
  pinMode(motor_rightdig, OUTPUT);
  servo.attach(servoPin);
  moveServo(STRAIGHT_AHEAD);
//  Serial.begin(9600);  /* For debugging purposes only */
//  ir.begin();

}

void loop() {
  static int remoteControl = OFF;

  if (remoteControl == ON) {
      stopMoving();
  }
  else {  // Remote control = OFF

    /* If we hit something with the bump switch, back up and turn around */
    if (digitalRead(bumperPin) == HIGH) {
      stopMoving();
      reverse();
      delay(1000);
      stopMoving();
      turnAround(bestDirection());
    }
  
    /* Debounce the Sharp IR sensor.  I suspect a capacitor would work just as well... */
    int distance = analogRead(eyePin);
    while (abs(distance - analogRead(eyePin)) > 20) {
      distance = analogRead(eyePin);  /* Debounce */
    }

    /* Too close to something?  Stop and turn around */
    if (distance > DANGER_DISTANCE) {
      stopMoving();
      turnAround(bestDirection());
    }
    
    /* Getting close to something, slow down */
    else if (distance > MAX_SAFE_DISTANCE) {
      halfSpeed();
    }
    
    /* All clear ahead, full on */
    else {    
      moveStraight();
    }
  }
}

void moveServo(int distance) {
  servo.write(distance*SERVO_STEP_SIZE);
  delay(50);  /* For the servo to settle */
}



/*
* Routine to figure out where to rotate to get the most unobstructed angle.
 */
int bestDirection() {
  /*
   * Rotate the servo, building a map of the obstacles we see in front of us.
   * Record the position that is most unobstructed, scaled up to use as a delay factor when turning.
   */
   refresh_view(0, NUM_SERVO_STEPS);
   int safest = furthestView();
   return ((safest - STRAIGHT_AHEAD) * 50);
}


/* Routine to return the least number in the view[] array. */
int furthestView() {
   int furthest=view[0];
   int servo_position=0;
  
   for (int i=0; i<NUM_SERVO_STEPS; i++)  {
     if (view < furthest) {
       furthest = view;
       servo_position = i;
     }  
    }
   return(servo_position);  
}

/* Routine to scan around, recording what we see where */
void refresh_view(int start, int end) {  
  for (int i=start; i<end; i++) {
    moveServo(i);
    /* Debounce the Sharp IR sensor */
    while (abs(analogRead(eyePin) - view) > 10) {
      view = analogRead(eyePin);
    }
  }
  moveServo(STRAIGHT_AHEAD);
}  


/* Negative turnAmount means turn left, positive turnAmount means turn right */
void turnAround(int turnAmount) {
  if (turnAmount < 0) {
    setSpeed(-FULL_SPEED, FULL_SPEED);
  }
  else {
    setSpeed(FULL_SPEED, -FULL_SPEED);
  }
  delay(500);  /* Arbitrary delay factor, it just works well */
}

void moveStraight() {
  setSpeed(FULL_SPEED, FULL_SPEED);
}

void stopMoving() {
  setSpeed(NO_SPEED, NO_SPEED);
  delay(500);
}

void halfSpeed() {
  setSpeed(HALF_SPEED, HALF_SPEED);
}


void reverse() {
  setSpeed(-FULL_SPEED, -FULL_SPEED);
  delay(500);
}

void setSpeed(int left, int right) {
   if (left >= 0) {  /* Forward */
      digitalWrite(motor_leftdig, LOW);
      analogWrite(motor_leftpwm, left);
    }
    else {  /* Reverse */
      digitalWrite(motor_leftdig, HIGH);
      analogWrite(motor_leftpwm, FULL_SPEED+left);
    }


    if (right >= 0) {  /* Forward */
      digitalWrite(motor_rightdig, LOW);
      analogWrite(motor_rightpwm, right);
    }
    else {  /* Reverse */
      digitalWrite(motor_rightdig, HIGH);
      analogWrite(motor_rightpwm, FULL_SPEED+right);
    }
}

10  Forum 2005-2010 (read only) / Exhibition / Re: Control Arduino with Universal Remote on: July 28, 2008, 03:40:12 pm
This library works great for me using the sample program to print out the remote codes.
But, when I try to integrate it into my object-avoiding robot, things go bad.  One of two motors stops completely, the other becomes intermittent.  The stepper motor used for vision control "drifts" when not being driven, like it is being disconnected for short periods of time.  I am using the servotimer1 library, but that just uses timer 1 and it looks like NECIRrcv is using timer 2.

Any idea what could be going wrong?
Any idea how much RAM this library uses?

Thanks!
Pages: [1]