Offline
Newbie
Karma: 0
Posts: 30
|
 |
« on: February 26, 2012, 08:00:47 pm » |
Hi, I'm trying to create this project I found on fritzing and I'm having issues. Project: http://fritzing.org/projects/ir-obot/When ever I press right on my remote it freezes and on the serial monitor, the hex value is always 0. This only happens when I press right on the remote. I've tried different buttons on the remote and it just wont work. The IRremote library worked great and it always works. Thats what I used to get the HEX values.Anyone wanna help? Please reply, Gobi P.S. I've never received my motor shield yet, just testing out the code. #include <IRremote.h> #include <IRremoteInt.h>
// Robot With IR remote // by Neil Hendrick //
//this imports the IR Library (must be present in libraries folder) int dirbpinB = 13; // Direction pin for motor B is Digital 13 int speedbpinB = 11; // Speed pin for motor B is Digital 11 (PWM) int dirbpinA = 12; // Direction pin for motor A is Digital 12 int speedbpinA = 3; // Speed pin for motor A is Digital 3 (PWM) int speed = 100; int dir = 0; int RECV_PIN = 10; // IR receiver IRrecv irrecv(RECV_PIN); decode_results results; void setup() { pinMode(dirbpinB, OUTPUT); pinMode(dirbpinA, OUTPUT); 7 Serial.begin(9600); //begin serial connection, prints output to your PD irrecv.enableIRIn(); // Start the receiver
}
void loop(){ //start loop if (irrecv.decode(&results)) { if (results.value == 0xBEEC847B) { //UP forward digitalWrite(dirbpinB, 1); // set direction digitalWrite(dirbpinA, 1); // set direction analogWrite(speedbpinB, speed); // set speed (PWM) analogWrite(speedbpinA, speed); // set speed (PWM) }// close UP else if (results.value == 0xBEECA45B) { //DOWN backward digitalWrite(dirbpinB, 0); // set direction digitalWrite(dirbpinA, 0); // set direction analogWrite(speedbpinB, speed); // set speed (PWM) analogWrite(speedbpinA, speed); // set speed (PWM) } else if (results.value == 0xBEEC44BB) { //LEFT digitalWrite(dirbpinB, 1); // set direction digitalWrite(dirbpinA, 1); // set direction analogWrite(speedbpinB, speed); // set speed (PWM) analogWrite(speedbpinA, 50); // set speed (PWM) } else if (results.value == 0xBEEC24DB) { //RIGHT digitalWrite(dirbpinB, 1); // set direction digitalWrite(dirbpinA, 1); // set direction analogWrite(speedbpinB, 50); // set speed (PWM) analogWrite(speedbpinA, speed); // set speed (PWM) } else if (results.value == 0xBEECC43B) { //STOP * analogWrite(speedbpinB, 0); // set speed (PWM) analogWrite(speedbpinA, 0); // set speed (PWM) } else if (results.value == 0xBEECCA35) { // Spin Left RW digitalWrite(dirbpinB, 1); // set direction digitalWrite(dirbpinA, 0); // set direction analogWrite(speedbpinB, speed); // set speed (PWM) analogWrite(speedbpinA, speed); // set speed (PWM) } else if (results.value == 0xBEEC2AD5) { //Spin Right FF digitalWrite(dirbpinB, 0); // set direction digitalWrite(dirbpinA, 1); // set direction analogWrite(speedbpinB, speed); // set speed (PWM) analogWrite(speedbpinA, speed); // set speed (PWM) } Serial.println(results.value, HEX); //sends the IR code to computer so you can see what codes you are sending irrecv.resume(); // Receive the next value }//close first IF "if (irrecv.decode(&results)){" } //close loop Moderator edit: CODE TAGS
|
|
|
|
« Last Edit: February 29, 2012, 05:09:35 am by AWOL »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #1 on: February 26, 2012, 08:03:40 pm » |
Which remote are you using ? I am guessing its protocol is not yet supported by the IRLib
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #2 on: February 26, 2012, 08:04:11 pm » |
Try a different remote.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #3 on: February 26, 2012, 10:04:37 pm » |
Nope, I also tried a Sony remote which I'm sure that is supported. Do you think its because I didn't plugin my motor shield yet? Its coming in the mail and its going to take days or weeks.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 1
Posts: 478
|
 |
« Reply #4 on: February 26, 2012, 11:55:15 pm » |
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #5 on: February 27, 2012, 11:30:48 pm » |
That project uses servos, I got no servos. I want to use a motor shield. How can I possibly do that?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 1
Posts: 478
|
 |
« Reply #6 on: February 27, 2012, 11:38:56 pm » |
just a matter of moving the code around...
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #7 on: February 28, 2012, 11:58:02 pm » |
I'm a beginner, can you please help me move the code around so I can use it with an Arduino?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 1
Posts: 478
|
 |
« Reply #8 on: February 29, 2012, 05:32:29 pm » |
so is everyone going to write your code for you? #include <IRremote.h> long int Buttons[7] = { 3203171451, //0Up in decimal 3203179611, //1Down 3203155131, //2Left // 3203146971, //3right // 3203187771, //stop // 3203189301, //spin left RW // 3203148501 //spin right ff };
//-----IR-Stuff---------------------------------------------------// int RECV_PIN = 10; IRrecv irrecv(RECV_PIN); decode_results results; int BtnPressed = 0; //----------------------------------------------------------------//
//robotstuff int dirbpinB = 13; // Direction pin for motor B is Digital 13 int mtrspeedbpinB = 11; // mtrspeed pin for motor B is Digital 11 (PWM) int dirbpinA = 12; // Direction pin for motor A is Digital 12 int mtrspeedbpinA = 3; // mtrspeed pin for motor A is Digital 3 (PWM) int mtrspeed = 100; int dir = 0;
void setup() { Serial.begin(9600); pinMode(dirbpinB, OUTPUT); pinMode(dirbpinA, OUTPUT); irrecv.enableIRIn(); // Start the receiver }
void dump(decode_results *results) { if (results->decode_type == NEC) { unsigned long store = (results->value); //Serial.println(store); for(int x=0; x<7; ++x) { if(store == Buttons[x]) { BtnPressed = x; // Serial.println(x); } } } }
void loop() { if (irrecv.decode(&results)) { dump(&results); if(BtnPressed == 0) //up { Serial.println("up"); digitalWrite(dirbpinB, 1); // set direction digitalWrite(dirbpinA, 1); // set direction analogWrite(mtrspeedbpinB, mtrspeed); // set mtrspeed (PWM) analogWrite(mtrspeedbpinA, mtrspeed); // set mtrspeed (PWM) } else if(BtnPressed == 1) //down { Serial.println("down"); digitalWrite(dirbpinB, 0); // set direction digitalWrite(dirbpinA, 0); // set direction analogWrite(mtrspeedbpinB, mtrspeed); // set mtrspeed (PWM) analogWrite(mtrspeedbpinA, mtrspeed); // set mtrspeed (PWM) } else if(BtnPressed == 2) //left { Serial.println("left"); digitalWrite(dirbpinB, 1); // set direction digitalWrite(dirbpinA, 1); // set direction analogWrite(mtrspeedbpinB, mtrspeed); // set mtrspeed (PWM) analogWrite(mtrspeedbpinA, 50); // set mtrspeed (PWM) } else if(BtnPressed == 3) //right { Serial.println("right"); digitalWrite(dirbpinB, 1); // set direction digitalWrite(dirbpinA, 1); // set direction analogWrite(mtrspeedbpinB, 50); // set mtrspeed (PWM) analogWrite(mtrspeedbpinA, mtrspeed); // set mtrspeed (PWM) } else if(BtnPressed == 4) //stop { Serial.println("stop"); analogWrite(mtrspeedbpinB, 0); // set mtrspeed (PWM) analogWrite(mtrspeedbpinA, 0); // set mtrspeed (PWM) } else if(BtnPressed == 5) //Spin Left RW { Serial.println("Spin Left"); digitalWrite(dirbpinB, 1); // set direction digitalWrite(dirbpinA, 0); // set direction analogWrite(mtrspeedbpinB, mtrspeed); // set mtrspeed (PWM) analogWrite(mtrspeedbpinA, mtrspeed); // set mtrspeed (PWM) } else if(BtnPressed == 6) //Spin Right FF { Serial.println("Spin Right"); digitalWrite(dirbpinB, 0); // set direction digitalWrite(dirbpinA, 1); // set direction analogWrite(mtrspeedbpinB, mtrspeed); // set mtrspeed (PWM) analogWrite(mtrspeedbpinA, mtrspeed); // set mtrspeed (PWM) } irrecv.resume(); // Receive the next value } }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #9 on: March 03, 2012, 08:01:47 am » |
Well, no. I'm very pleased that you helped me write this code. Thank you so much. I'm still learning how to do this so it will take a while. But thank you!
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 6
|
 |
« Reply #10 on: March 03, 2012, 02:49:05 pm » |
u knw softserial.... ? if so...pls tell me how to use it....
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 1
Posts: 478
|
 |
« Reply #11 on: March 03, 2012, 04:17:04 pm » |
random... but yeah, for what?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #12 on: March 10, 2012, 11:34:21 pm » |
Hey, sorry for the late post, the code still doesn't work. I'm still not sure how to fix this problem. The code you gave me has the same problem. When ever I press right, it gets stuck and doesn't work. On the serial monitor it just shows right. Do I need a motor shield? I'm still waiting for it in the mail.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 1
Posts: 478
|
 |
« Reply #13 on: March 11, 2012, 10:22:11 am » |
can you press all the other buttons and make left/down etc show up in serial? it should still work without the motor controller.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #14 on: March 11, 2012, 11:11:16 am » |
What do your serial debug prints tell you?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
|