Adafruit Motor Shield V2 - Netduino Plus Driver - Netduino Plus 2 (and Netduino Plus 1) - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Adafruit Motor Shield V2 - Netduino Plus Driver

Adafruit Motor Shield V2 Netduino Plus

  • Please log in to reply
12 replies to this topic

#1 vission

vission

    New Member

  • Members
  • Pip
  • 3 posts

Posted 13 November 2013 - 07:09 PM

Hi there!

 

I'm taking an non-working Sony 400Disc DVD Changer(ebay) and turning it into a 400Disc BluRay changer for use with Windows Media Center via webservices.  I thought this might be a great project to actually use my Netduino Plus for!  There are 3 DC motors(non-stepper) used to handle the various mechanics and a multitude of optical sensors.  Well I needed to be able to drive those motors so I picked up the Adafruit Motor Shield V2.  Come to find out there is little support for this shield on the Netduino Plus(that I could find) but Adafruit had schematics and source code(C++).  So after many days trying to translate the code I finally got it to work and can now drive each motor/direction/speed.  I wanted to share my code since this forum and the Adafruit information was very helpful to me.  Also, I try to write as concise code as possible but if anyone has any suggestions for optimization I'd be happy to hear it.  Enjoy!

 

Attached is the class for driving the shield. Below is sample code to use it:

(be sure to update your namespace as necessary.

 

namespace I2C_Motors
{
    public class Program
    {
 
 
        public static void Main()
        {
            MotorShieldV2 myMotor = new MotorShieldV2();
            myMotor.startUp(1600);  //1600 is the frequency used
 
            //Run Motor 1 & 3 at the same time
            myMotor.runMotor(1, 150, true);  //Motor #1-4, Speed (0 - 255), Direction (true/false)
            myMotor.runMotor(3, 150, true);
 
            Thread.Sleep(2000);
 
            //Stop Motor 1& 3 at the same time
            myMotor.runMotor(1, 0, true);
            myMotor.runMotor(3, 0, true);
 
            //Cleanup
            myMotor.Dispose();
        }
    }
}

Attached Files



#2 vission

vission

    New Member

  • Members
  • Pip
  • 3 posts

Posted 19 November 2013 - 07:27 PM

Sorry guys found a bug in the speed code.  Fixed and attached.

 

Attached Files



#3 herman.schmit

herman.schmit

    New Member

  • Members
  • Pip
  • 9 posts

Posted 03 February 2014 - 05:25 AM

This code has some errors and did not include stepper motor support.

 

I have re-written it based on the Adafruit/Arduino code, and have tested it on some of the DC motors and steppers that I have in my garage. It certainly isn't fully debugged, and I'll probably make some improvements. Let me know if you are interested in this code, and I will set up a git. 

 

MICROSTEPPING is not working. I'm unclear whether MICROSTEPPING when you have PWM controlled switching may not be achieve the right objective anyway.

 

Thanks,

 

Herman

 

Attached File  MotorShieldV2.cs   14.62KB   48 downloads



#4 herman.schmit

herman.schmit

    New Member

  • Members
  • Pip
  • 9 posts

Posted 05 February 2014 - 05:42 AM

I wanted to add an update. I am pretty sure that the Adafruit Motor Shield is not good for driving anything but tiny stepper motors. I think that it just can't generate the current necessary for my 3A/12V motor. It seems to work briefly, and then shut down. If somebody finds a bug in my code, I would be happy to get any feedback because I'd love to use the this product. I went back to my easydriver and it works like a charm.



#5 wendo

wendo

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts

Posted 05 February 2014 - 08:36 AM

Given the FET's are only rated for 1.2A continuous then you're probably right. Since the power is supposedly split between arduino/netduino and the actual motor power it shouldn't be shutting down anything. if anything I would expect you to burn out the FET drivers if you we're continuously pulling more than 1.2A

 

You are supplying external power to this right?



#6 Jeff

Jeff

    New Member

  • Members
  • Pip
  • 3 posts

Posted 24 May 2014 - 01:06 PM

Herman and Vission,

 

Thank you for sharing this code. I bought this shield as well because I want to drive two stepper motors I pulled off an old Xerox printer. Would you mind sharing your Program.cs file or a sample project so I can see how you were calling the library?  I’m using the Minebea CO. Stepper Motor Type 23LM-K202-23, 3.5 V/PH, 1.0 A/PH.

 

http://cnc25.free.fr...pap/pap_nmb.pdf

 

Thank You,

 

Jeff



#7 herman.schmit

herman.schmit

    New Member

  • Members
  • Pip
  • 9 posts

Posted 02 June 2014 - 06:43 PM

Wendo: yes I was using a separate power supply. I even hooked it up to my bench supply and it didn't work. I don't actually think I was burning out the FETs because when I power-cycled I would get some reasonable behavior briefly. Unless the FET block has a thermal shutdown thing internally... Even that doesn't make sense entirely either, because the motors would basically still twitch (and get hot).

 

BTW: I even used really light hobby steppers, and they behaved the same way. I think it is not the FETs but the capacitance of the board. It is also weird to drive steppers with a PWM driver, I think.

 

Jeff: I'll post some version of my code soon. I'm sure it is in some ridiculous state because of my frustration with its dysfunction. I can't imagine it is going to be actually useful. But its no problem.



#8 herman.schmit

herman.schmit

    New Member

  • Members
  • Pip
  • 9 posts

Posted 03 June 2014 - 06:22 AM

Jeff: here is Program.cs, as I left it when I threw in the towel on this.

 

Hope it is useful. Please share if you find problems in my code. I doubt I'd go back to that shield, but it would make me feel I didn't waste that completely waste that weekend a few months ago when I tried to get this to work.

Attached Files



#9 CCorio

CCorio

    New Member

  • Members
  • Pip
  • 3 posts

Posted 20 June 2014 - 04:55 PM

Hello - I'm trying to use this code to get the Adafruit Motor Shield V2 working on my N2P (4.3.1.0) 

 

I am new to the Netduino world so I appreciate any and all advice you have regarding setup of this shield. 

 

What I've done so far:

1. I've soldered all of the leads onto the adafruit including the pins for SCL\SDA.

2. I've removed the jumper for the 5V and put in a solder jumper for 3.3V on the power pad

3. I attached an external power supply with 6 AA batteries.  The green light is on.

4. I downloaded the code attached to this thread and brought it into a C# project and started stepping through the program.cs code.

 

What I see is that when I call MyI2C.Execute it appears to return the number of bytes that was intended to be sent.  However, none of my motors are turning.

 

Can anyone send feedback on how I can debug this?  Further, I saw that there is a mention of pullup resistors.  I think that the shield has these but I haven't done anything other than I described above. 

 

Thanks in advance.

 

Chris



#10 herman.schmit

herman.schmit

    New Member

  • Members
  • Pip
  • 9 posts

Posted 22 June 2014 - 08:08 PM

Chris:

 

Are you using DC motors or stepper motors?

 

DC motors work great with this shield and this driver. BUT the Program.cs that I attached above is for stepper motors. AND it doesn't work. I basically posted it to see if somebody else could get it to work.

 

You should try to use the first version of this code. Or use the "program.cs" that is quoted above. I had DC motors turning right out of the box.

 

Herman



#11 CCorio

CCorio

    New Member

  • Members
  • Pip
  • 3 posts

Posted 22 June 2014 - 09:02 PM

Hi Herman -

 

Just for some background, I am trying to replace another motor shield (SainSmart L239D) because I could only drive the motors with 4 AAs and I needed 6...  I had that one working well.

 

Anyway, I'm using DC motors.  Thanks for the heads up regarding the initial Program.cs.  I switched to that but I'm still not getting anything from the motors.  When I touch them with the battery leads, they turn, so I'm pretty sure they're working...

 

I see that when I call I2CDevice.Execute that I get back the number of bytes that I'm sending in.  My initial concern is that there was something wrong with the I2C connection but I would guess that these APIs wouldn't immediately return the number of bytes written if there was a problem.

 

I'm sort of stuck regarding how to debug this from here.  Any suggestions?  I can write out all of the sequence of registry writes if that would be helpful...

 

Chris



#12 herman.schmit

herman.schmit

    New Member

  • Members
  • Pip
  • 9 posts

Posted 22 June 2014 - 09:32 PM

Connect voltmeter to output motor lead ports?

 

I can't really debug remotely. 

 

I do know that Vission's original code absolutely worked for DC Motors. Maybe this is my fault and I broke something while trying to get steppers to work. 

 

I guess the only suggestion I can make is divide and conquer. Be positive that the motors work. Be positive that your connections to the adafruit are good. Be positive that the netduino is communicating with the adafruit motor board. THEN worry about the software.

 

Good luck.

 

Herman



#13 CCorio

CCorio

    New Member

  • Members
  • Pip
  • 3 posts

Posted 23 June 2014 - 05:33 AM

Herman - thanks for your help. 

 

I spent the day debugging this:

1. I ran jumpers to the TB6612FNG and the motors start turning.

2. I changed the address to 0x61 and the I2CDevice.Execute function call failed returning 0 bytes written.  When the address is 0x60 the calls return a number greater than zero.

 

But when I run the code above I cannot get the LED outputs to go HIGH.  I am seriously beginning to wonder if I have a bad PCA9685PW chip on this board. 

 

Also, is it possible that this is an I2C bug on the 4.3.1 firmware?  Is there a way to test this? 

 

I appreciate any and all advice at this point. 







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.