Speed and direction

Hi,

I'm having some REALLY weird bugs with my motor shield.
I tested every connection and everything looks fine.
However, when I put the speed 0 in my programme, the voltage is at its maximum and when I put the speed at 255 (manualy), there is no longer any voltage.
Also, only ONE of my motors can to go in reverse! The other one can't get any voltage in reverse.

I just want to be sure if it's not a programming issue. I'm new to programming.

Thank you,
Max.

These are my variables:

  // Nom pour les pin directionnel du motorshield
const unsigned char M1DIR = 7;
const unsigned char M2DIR = 8;
const unsigned char M1PWM = 9;
const unsigned char M2PWM = 10;
const unsigned char LED = 13;
  // Déclaration des variables
int vitesse;
int delai;
int DIR1;
int DIR2;

This is my setup

void setup() {
  // put your setup code here, to run once:

  //On setup toute les pins directionnelles et le LED
  Serial.begin(9600);
  pinMode(M1PWM, OUTPUT);
  pinMode(M2PWM, OUTPUT);
  pinMode(M1DIR, OUTPUT);
  pinMode(M2DIR, OUTPUT);
  pinMode(LED, OUTPUT);
}

This is my loop when I try to use directly my motor without using my functions to avoid errors.

void loop() {

  digitalWrite(M1DIR,LOW);
  digitalWrite(M2DIR,LOW);

   digitalWrite(LED,LOW);
  analogWrite(M1PWM,0);
  analogWrite(M2PWM,0);
  delay(5000);

  digitalWrite(LED,HIGH);
  analogWrite(M1PWM,255);
  analogWrite(M2PWM,255);
  
  delay(5000);


  digitalWrite(M1DIR,HIGH);
  digitalWrite(M2DIR,HIGH);

   digitalWrite(LED,LOW);
  analogWrite(M1PWM,0);
  analogWrite(M2PWM,0);
  delay(5000);

  digitalWrite(LED,HIGH);
  analogWrite(M1PWM,255);
  analogWrite(M2PWM,255);
  
  delay(5000);
}

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long to study quickly.

Also please use the AutoFormat tool in the IDE to indent the code properly.

...R

Robin2:
Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long to study quickly.

Also please use the AutoFormat tool in the IDE to indent the code properly.

...R

It's done! Thank you for the retroaction.

This is my loop when I try to use directly my motor without using my functions to avoid errors.

If that code does not make the motors run correctly, you have a hardware problem.

What motor shield? Do you have a schematic of how it is connected? What happens if you use a speed of 125 for example?

If you are getting higher voltage when the value is 0, perhaps you are measuring the voltage between pin and +5v instead of the voltage between the pin and earth?

You cannot get a reverse voltage off a pin. You can get 0v, +5v, or +5v turned on and off really fast to simulate a voltage somewhere between. To run a motor forward and back, the usual way is to use an H-Bridge. You can wire up your own, or buy a premade one as a shield.

gpsmikey:
What motor shield? Do you have a schematic of how it is connected? What happens if you use a speed of 125 for example?

It's a DRV8835 for arduino from Pololu.
When I put 125, I have half the voltage of my powersource. I tested with USB and with a 6V battery.

PaulMurrayCbr:
If you are getting higher voltage when the value is 0, perhaps you are measuring the voltage between pin and +5v instead of the voltage between the pin and earth?

You cannot get a reverse voltage off a pin. You can get 0v, +5v, or +5v turned on and off really fast to simulate a voltage somewhere between. To run a motor forward and back, the usual way is to use an H-Bridge. You can wire up your own, or buy a premade one as a shield.

No I'm directly testing at the exit of the motor shield, where I'm supposed to plug my motors.

I'm trying to identify the issue, to know if it's from my code (I don't think so but I want to be sure since I'm new to this.) or if it's with my motor shield.

PaulS:
If that code does not make the motors run correctly, you have a hardware problem.

Also, according to pauIS, it's an hardware issue.

Should I contact my motorshield manufacturer right away or is there some kind of test in between to do?

MaxiMax07:
Should I contact my motorshield manufacturer right away

I suspect their first question will be, "Did you use our library?"

@MaxiMax07, please post your program as a single block so I don't have the trouble of joining the parts together and perhaps making a mistake doing so.

That shield could easily be plugged in the wrong way.

How is yours connected ?

...R

JimboZA:
I suspect their first question will be, "Did you use our library?"

I used there library to understand how Arduino work. However, to have a better understanding and control, I created my own functions.

Robin2:
@MaxiMax07, please post your program as a single block so I don't have the trouble of joining the parts together and perhaps making a mistake doing so.

That shield could easily be plugged in the wrong way.

How is yours connected ?

...R

Okay!
For the shield, well I don't have it with me right now, I'm studying at my uni the all day. However tonight I will be able to send some pictures if you want. Altought I think I plugged it right. I plug de pins 10,9,8,7,6 of the motorshield to the 10,9,8,7,6 of the arduino, and the same goes for de Vin GND GND and 5V pins.
I also plugged the jumper to power my arduino throw my motorshield. I didn't touch de mode pin, cause with the arduino uno I can only use the Phase/Enable mode.

Thank you for your help guys!

Arduino_PHASE-ENABLE.ino (2.97 KB)

MaxiMax07:
I used there library to understand how Arduino work.

And did it work with their library? If so, does it still work if you go back to the configuration that worked?

JimboZA:
And did it work with their library? If so, does it still work if you go back to the configuration that worked?

Well I didn't try it out. It's a great idea! I'll know if the issue is from my program, or is electrical.
I'll do it tonight!

So I just ran some tests!
Here are the results:
My M1B (motor 1 output B) doesn't seem to work at all! I can't get any voltage out of it. (It does explain the fact that I can't go in reverse.
Also, my M1A and M2A seems to work in reverse! (I can't explain why, when I put 255, each one of them is at 0V and when I put 0, they are both at 4,4V when using an USB alimentation.

I tested individualy each of the pin of arduino, and they all send the good voltage at the right time. There is no reason for the PWM speed to be inverse by the motorshield. And it's seems like the M1B can't work propely.

I also included some pictures.

I also tested the connection in the amplificator. All the inputs are good for sure. However, it's hard to test the connection of the output so I'm not sure if there are some issues in the connection between my motors output and the output of the amplificator. However, I'm thinking the issue come from the amplificator.

Any advice or opinion anyone? I don't know a lot in electronics and my assumptions could be wrong.

Thank you!

Either I'm getting really old (definite possibility) or something got lost in translation - what the heck is the "amplifactor" ??

gpsmikey:
Either I'm getting really old (definite possibility) or something got lost in translation - what the heck is the "amplifactor" ??

Ah, so it's not just me :slight_smile:

Yeah I litteraly translated the world from french.
I can't find the translation thought cause the name in french is a synonyme of a way more commun object.

Its this:

Operational Amplifier - more commonly just called opamp. Now we know :slight_smile:

gpsmikey:
Operational Amplifier - more commonly just called opamp. Now we know :slight_smile:

I wasn't so far from it :stuck_out_tongue:

Altought, I'm not totaly sure it's an amplifier. It's the only composant in electronic that I know that combine many wires. It might be something else.
To be simple, it's the composant that seems to control the output voltage of my motors in the motor shield. All the input go to their and the output come from their.