Go Down

Topic: Adafruit MotorShield IR Remote Controlled Car (Read 504 times) previous topic - next topic

oumardawg1234

So I decided to resurrect a project I was working on as a kid. Its a 4 motor remote controlled car, controlled by the Adafruit MotorShield V2, and an Infra-red receiver with the numbers and letters, VS, 1838B.

Now I'm nearly finished with the project, the motors can run perfectly, I've recorded the codes that the remote sends, and the receiver receives the code and acts. There is one problem though, that I encountered last time. With my code the receiver accepts the code for instance "0xFF629D," which tells the motors to run forward, but it is unable to accept the next code as the arduino is focused on running the motors, and not accepting the next code from the remote.

I'm quite sure the solution is very simple, but I'm only 15, and up and coming engineer.

Of course here's my code:

Code: [Select]
#include "IRLibAll.h"
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(2);
Adafruit_DCMotor *myMotor3 = AFMS.getMotor(3);
Adafruit_DCMotor *myMotor4 = AFMS.getMotor(4);



int ledPin = 10;


IRrecvPCI myReceiver(2);


IRdecode myDecoder;

void setup() {
  pinMode(ledPin, OUTPUT);

  AFMS.begin();
  Serial.begin(9600);
  delay(2000); while (!Serial);
  myReceiver.enableIRIn();
  Serial.println(F("Ready to receive IR signals"));

  myMotor->setSpeed(150);
  myMotor2->setSpeed(150);
  myMotor3->setSpeed(150);
  myMotor4->setSpeed(150);
}

void loop() {

  if (myReceiver.getResults()) {
    myDecoder.decode();
    if (myDecoder.protocolNum == NEC) {
      switch (myDecoder.value) {
        case 0xFFA857: //DOWN BUTTON
          myMotor->run(BACKWARD);
          myMotor2->run(BACKWARD);
          myMotor3->run(BACKWARD);
          myMotor4->run(BACKWARD);
         
          myReceiver.enableIRIn();
          break;
        case 0xFF629D: //UP BUTTON
          myMotor->run(FORWARD);
          myMotor2->run(FORWARD);
          myMotor3->run(FORWARD);
          myMotor4->run(FORWARD);
         
          myReceiver.enableIRIn();
          break;
        case 0xFF02FD: //OK BUTTON
          myMotor->run(RELEASE);
          myMotor2->run(RELEASE);
          myMotor3->run(RELEASE);
          myMotor4->run(RELEASE);
          myReceiver.enableIRIn();
          break;
        case 0xFF220D: //LEFT BUTTON
          myReceiver.enableIRIn();
          break;
        case 0xFFC23D: //RIGHT BUTTON
          myReceiver.enableIRIn();
          break;




      }
      myReceiver.enableIRIn();
    }


  }
}



Sorry for all the words, but thanks in advance.

jremington

#1
Aug 27, 2018, 05:37 am Last Edit: Aug 27, 2018, 05:42 am by jremington
I don't use the Adafruit motor driver or library, but glancing through the frustratingly incomplete documentation suggests that the run() command is not blocking. That is, it tells the driver to run the motor at the desired speed, in the desired direction and exits.

So, what is your evidence for this conclusion?
Quote
it is unable to accept the next code as the arduino is focused on running the motors,
I suspect a power supply problem, for example starting up all the motors crashes the Arduino, but you forgot to post a hand drawn (not Fritzing) wiring diagram. Also post links to the data sheets or product page for the motors, so we can see the voltage and current requirements (especially, the motor stall current).

See the "How to use this forum" posts on how to do that.

vinceherman

First post and you used code tags.  Well done!  Karma++

Go Up