• 0

Arduino motor shield rev3 : the first approach running a dc-motor (without a library)


Question

hello dear experts good day .

 

 

well first of all - i want to express that i am not 100% sure if this belongs to this forum - or to the hardware forum. (as it covers a arduino-question)

 

I have buyes a arduino motor shield rev3 (revision 3) see the page where it is being sold:  https://store.arduino.cc/arduino-motor-shield-rev3 When I follow the link for "Getting Started section" the page lists a lot of shields but not the motor shield. I am looking for a library for the motor board - or at least for an first approach to get the thing up and running. 
What is aimed: I'm trying to drive 2 DC motors - for a rc-car.  Therefore i have connected two DC Servo Motors to the Motor Shield and wrote the following sequence:

 


 void setup() 
    {
      //Setup Channel A
      pinMode(12, OUTPUT);     //Initiates Motor Channel A pin
      pinMode(9, OUTPUT);      //Initiates Brake Channel A pin

      //Setup Channel B
      pinMode(13, OUTPUT);     //Initiates Motor Channel A pin
      pinMode(8, OUTPUT);      //Initiates Brake Channel A pin
    }


and afterwards we have the following piece of code: 

 

 

    void loop()
    {
      //Phase 1 - going to the wall
      //Motor A forward - Max Speed
      digitalWrite(12, LOW);   //this should try to establishes forward direction of Channel A
      digitalWrite(9, LOW);    //this is for the Disengage of the Brake for Channel A
      analogWrite(3, 255);     //this should help to spin the motor on Channel A at max speed

      //Motor B forward - Max Speed
      digitalWrite(13, HIGH);  //this is to establish forward direction of Channel B
      digitalWrite(8, LOW);    //this should help to disengage the brake for Channel B
      analogWrite(11, 255);    //this spins the motor on channel B at max speed

      delay(4000); // Adjust to correspond the distance

  //Phase 2 - getting back to initial point
  //Motor A backward - max speed
  digitalWrite(12, HIGH);  // this should establish backward direction of Channel A
  digitalWrite(9, LOW);    //now we need to disengage the Brake for Channel A
  analogWrite(3, 255);     //at this point i want to spins the motor on Channel A at max speed

  //Motor B backward - max speed
  digitalWrite(13, LOW);   // right now i try to establishes backward direction of Channel B
  digitalWrite(8, LOW);    //and now we want to disengage the Brake for Channel B
  analogWrite(11, 255);    //finally we want to spins the motor on Channel B at max speed

  delay(4000);

  //Phase 3 Stop for 7.5 seconds
  // Motor A stop
  digitalWrite(9, HIGH);   // here we try to engage the Brake for Channel A
    //Motor B 


 

 

what happens now While connected to USB, the device executes perfectly the sequence.

but wait: whein i run the sequence using the DC Source, the device does not respect any part of the coding. 
It started simply going forward while then it wante to  reverse the polarity randomly blocking the movement sometimes.


i afterwards tried another approach as a library-replacement i have tried this code is simple enough:

 

 

void setup() {

  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin

}

void loop(){

  //forward @ full speed
  digitalWrite(12, HIGH); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 255);   //Spins the motor on Channel A at full speed

  delay(3000);

  digitalWrite(9, HIGH); //Engage the Brake for Channel A
}

 

conclusio: Well - what is very very funny - with the second code-example it runs like a charme.

 

Looking forward to your suggestions.

Edited by tarifa

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I can't believe it was only two years since the last time MS raised their prices and now they think they can do it again so soon. Of course they needed to backtrack on this. I hope Nintendo is next.
    • I guess I gotta be even more specific then since I'm looking for an absolute confirmation.  The mini PC has never booted up or powered on by me. I'm assuming it'll be like buying a new PC from a store. Nothing is set up. Like absolutely nothing on the mini PC because I can't emphasize this enough. My USB drive already has Windows set up on it from my other desktop so I know it's clean. So now I connect it to the mini PC before it's even booted up or go to the desktop. I then turn on the mini PC and boot into the USB drive. I should see an existing partition. I'll delete it and then install Windows again over the entire drive. I don't necessarily want to create a separate partition. Once it installs and boots to the desktop, I'm assuming the drive is "clean" and free of any malware/viruses. Basically, this process will eliminate any potential for malware/viruses to still somehow hide in the SSD and then potentially affect me later.  I'm being very anal about this because I really don't trust anything bought from AliExpress, but the price was very tempting.  Is Windows Defender reliable? Afterwards, if I do a full scan and it doesn't find anything in the SSD and the USB drive, can I be confident the mini PC is now safe and secured to enter my banking credentials? If not, what else can I do to be absolutely certain?
    • I got an ESR Qi2 vent charger for my car and it's fantastic. It's very strong magnet and holds the phone securely over the worst potholes/roads, and my iPhone does charge. In Summer, the AC blows on the vent keeps and keeps the phone cold. In winter, I just close that vent, so it still stays cold. I agree with you on the Android front. Why not just build in the magnets like Apple does? It's frustrating to buy a case that adds magnets.
    • Hey, I've been using Windows since I was a little tyke. But for the last 15 years, I have been using Linux. I'm using EndeavourOS/Arch atm. wipe it, as in deleting anything from the SSD in the computer. Make a new partition. USB booting device should be free of malware, as long as you download it directly friom MS. Not some XYZ company.
    • "Nuking it" is slang for doing a clean install. USB installation media... delete the partition... start fresh.
  • Recent Achievements

    • Collaborator
      fernan99 earned a badge
      Collaborator
    • Collaborator
      MikeK13 earned a badge
      Collaborator
    • One Month Later
      Alexander 001 earned a badge
      One Month Later
    • One Month Later
      Antonio Barboza earned a badge
      One Month Later
    • Week One Done
      Antonio Barboza earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      584
    2. 2
      ATLien_0
      219
    3. 3
      Michael Scrip
      173
    4. 4
      Xenon
      138
    5. 5
      +FloatingFatMan
      127
  • Tell a friend

    Love Neowin? Tell a friend!