Looking for assistance with first project.

I am just getting in to using an Arduino, and am starting off with a tank-tracked robot project.

I am using an Arduino UNO R3, with and Adafruit Motorshield V2. I have 12VDC supplied to the motor shield, and 9VDC supplied to the Arduino via barrel jack. I am using four 12V brushless motors, with hall sensors (have no idea how to utilize this), one motor to run each track (4 in total). My transmitter is a FlySky-I6X, receiver is FS-IA6B. The following code is what I have come up with based on quite a bit of searching online, with the expectations of having Channel 2 run the RIGHT track (2 motors), and Channel 3 run the LEFT track (2 motors). So far, there is no response in any way when powered up and connected to the transmitter. Any assistance with what might be the issue would be greatly appreciated.

#include <Wire.h>
#include <Adafruit_MotorShield.h>
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
Adafruit_DCMotor *LF = AFMS.getMotor(4);  //Port M4
Adafruit_DCMotor *RF = AFMS.getMotor(3);  //Port M3
Adafruit_DCMotor *LR = AFMS.getMotor(1);  //Port M1
Adafruit_DCMotor *RR = AFMS.getMotor(2);  //Port M2
int ch2,ch3,LEFT,RIGHT;
const int in1 = A2, in2 = A3;
 
void setup() {
  Serial.begin(9600);        
  AFMS.begin();
  pinMode(in1, INPUT);
  pinMode(in2, INPUT);
  LF->setSpeed(255);
  LF->run(RELEASE);
  RF->setSpeed(255);
  RF->run(RELEASE);
  LR->setSpeed(255);
  LR->run(RELEASE);
  RR->setSpeed(255);
  RR->run(RELEASE);
  }
 
void loop() { 
  ch2 = pulseIn(in1, HIGH, 35000);
  ch2 = pulseIn(in1, LOW, 35000);
  ch3 = pulseIn(in2, HIGH, 35000);
  ch3 = pulseIn(in2, LOW, 35000);
 if(ch2 != 0 || ch3 != 0){{
    ch2 = constrain(ch2, 1010, 1985);
    ch3 = constrain(ch3, 1010, 1985);
    ch2 = map(ch2, 1010, 1985, 490, -485);
    ch3 = map(ch3, 1010, 1985, 490, -485);
    }
   LEFT = ch3;
   RIGHT = ch2;
   LEFT = constrain(LEFT, -100, 100);
   RIGHT = constrain(RIGHT, -100, 100);
    if(LEFT >= 1550){
      LF->setSpeed(map(LEFT, 1550, 1985, 0, 255));
      LF->run(FORWARD);
      LR->setSpeed(map(LEFT, 1550, 1985, 0, 255));
      LR->run(FORWARD);
      } 
    else if(LEFT <= 1450){
      LF->run(BACKWARD);
      LR->run(BACKWARD);
      LR->setSpeed(map(LEFT, 1450, 1010, 0, 255));
      LF->setSpeed(map(LEFT, 1450, 1010, 0, 255));
      }
    else{
      LF->run(RELEASE);
      LR->run(RELEASE);
      }
    if(RIGHT >= 1550){
      RF->run(FORWARD);
      RR->run(FORWARD);
      RR->setSpeed(map(RIGHT, 1550, 1985, 0, 255));
      RF->setSpeed(map(RIGHT, 1550, 1985, 0, 255));
      } 
    else if(RIGHT <= 1450){
      RF->run(BACKWARD);
      RR->run(BACKWARD);
      RR->setSpeed(map(RIGHT, 1450, 1010, 0, 255));
      RF->setSpeed(map(RIGHT, 1450, 1010, 0, 255));
      }
   else{
    RF->run(RELEASE);
    RR->run(RELEASE);
    LF->run(RELEASE);
    LR->run(RELEASE);
   }
  }
}

Start with a much simpler sketch. Do you get anything from pulseIn() ?

I don't know where you got that code from but I would throw it away and find something else (or better yet learn to write your own).

It make very little sense. E.g. ch2 is set to the length of a HIGH pulse and then without being used it is immediately overwritten with the length of a LOW pulse. At one point a value is mapped to the the range 490 to -485 then constrained to be in the range 100 to -100 and then you immediately check to see that it is >=1550 (it can't possibly be). It's nonsense.

Steve

Hi verse,

To focus on the positive aspects:
Well done to post code as a code-section in the first post and adding a picture of your project.

Me too I think using this as the first project is pretty sporty and ambitiuos.
I see two basic paths to walk down to make your project working:

first path would be to ask "the forum" if somebody could write the code for you - more or less and waiting for the very very rare case that somebody finds your project interesting enough to do most of the work for you.

second path is running up the learning curve yourself. I guess you want to take the second path.
So the "assistance" starts with guiding you to that part of the programming-knowledge that is important for your project.

to compare learning programming with an allday-situation

imagine you want to learn to ride a bike.
You have looked at somebody who is doing it
and think AH! I understand sit on the saddle put your hands on the handlebars
and kick your feet down and then it is moving.

You know from your own experience that's not all.

  • You have to learn how to put the pedal in a certain position to start,
  • you have to learn where is the brake,
  • you have to learn how to shift gears

you have to practice BALANCING on the bike with your OWN BODY

it is similar with learning to program

You have to learn some basics. You have to practice

Asking here in the forum in this style

"I have this code here but it does not do what it should" End of message

is like you fell off the bike and then go to a experienced biker
telling him "I was unable to ride the bike" can YOU drive my bike for 200 meters to get me going?"

makes no sense at all. It's the same thing with programming.

Though the difference is your "programming"-Bike has fivehundred wheels, fifty pedals, eighty gearshifting-levers
five handlebars etc.

For starting to move (=programming) it is enough to get explained use handlebar number three, pedals number 27 and wheels 1,2,3 and 4.

But that's a different exercise than doing a backflip in the halfpipe. You simple don't start freestyle BMX-ing with backflips in the halfpipe. You start with basic exercises. It's the same thing with learning programming. You start with small exercises.

So as an introduction to programming I recommend working through this tutorial

Of course you can ask here in the forum. But then you have to wait for the answers. If you start to learn how coding works you become more and more independent of waiting for answers.

Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

I'm a somehow advanced programmer and this has the effect of beeing partially blind about beginners difficulties. But I would like to become an "expert" about beginners difficulties and therefore I appreciate feedback about that and to receive questions what is still hard to understand in this tutorial.

In addition: the more parts of a program you put together before testing the more possible sources of bugs are put together. In the long run it will take more time to write the whole code "at once" than writing a small testprogram and testing this small testprogram. Then write the next small testprogram for the next functionality.

Writing the whole code at once means not knowing where the bug is sitting and doing a lot more testing until the bug is found because you have to test so many combinations.

So as a first attempt write a small testprogram that does nothing more then measuring pulse-length of one channel of your RC-receiver and printing the measured value to the serial monitor.

best regards Stefan