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

Controlling 2WD Chassis using Motor Driver 1A Dual TB6612FNG

Netduino Plus 2 Motor Driver 1A Dual TB6612F 2WD Chassis uPLibrary 4.3.1.0

Best Answer Spammy786, 10 November 2014 - 06:56 AM

Hey CW2

 

Your suggestion above worked so I investigated the code a bit further. The problem was the PWM code. See all the examples I found, PWMA was connected to pin5, So we were choosing channel5, So basically we physically connected it to pin5 to the N+2 but in code you have to choose PIN0. I think this is because I am using 4.3.1.0.  The code below works :)

Thanks everybody for your help. 

using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace MotorController
{
    public class Program
    {
        public static void Main()
        {
            OutputPort stby = new OutputPort(Pins.GPIO_PIN_D0, true);

            //motorA
            PWM motorA = new PWM(Cpu.PWMChannel.PWM_0, 10000, 1, true);
            OutputPort a1 = new OutputPort(Pins.GPIO_PIN_D1, false);
            OutputPort a2 = new OutputPort(Pins.GPIO_PIN_D2, false);
            motorA.Start();

            //motorB
            PWM motorB = new PWM(Cpu.PWMChannel.PWM_1, 10000, 1, true);
            OutputPort b1 = new OutputPort(Pins.GPIO_PIN_D8, false);
            OutputPort b2 = new OutputPort(Pins.GPIO_PIN_D9, false);
            motorB.Start();


            while (true)
            {
                //this controls motorA
                a1.Write(false);
                a2.Write(true);
                motorA.DutyCycle = (double)0.7;

                //this controls motorB
                b1.Write(false);
                b2.Write(true);
                motorB.DutyCycle = (double)0.7;
             }
        }
    }
}
Go to the full post


  • Please log in to reply
17 replies to this topic

#1 Spammy786

Spammy786

    Member

  • Members
  • PipPip
  • 26 posts

Posted 04 November 2014 - 12:20 PM

Hi Guys
 
I have done some minimal work on the Netduino for our company and it was so interesting, I decided to order 1 for myself with a few extra components and try to build a simple 2WD robot that I can control using my android phone over Bluetooth. I got the Bluetooth parts working with my PC to test. I will code the android stuff at a later stage using Xamarin Android.
 
The Problem I am having is controlling the 2 motors. I will post my poor attempt of code below. I found a few examples online but I could not get any of them to work. I am running firmware version 4.3.1.0. So I think the reason some of the examples do not work for me is because they are using an older version of the framework. I tried a cool library I found on codeplex, the link http://uplibrary.codeplex.com/
I tried to this to work but I was not so lucky. I tried a few breakpoints and nothing seems to break but the motors will not turn, they just refuse to turn :(
 
The Components :
1 x Netduino Plus 2
1 x Bluetooth Device (Got this working well with my PC and Netduino, used a framework called 32feet.Net)
1 x Magician Chassis
1 x Motor Driver 1A Dual TB6612FNG
 
Wiring of Motor Driver :
Netduino to TB6612FNG breakout
DIO0 = Standby
DIO1 = AIN1
DIO2 = AIN2
DIO5 = PWMA
DIO6 = PWMB
DIO8 = BIN1
DIO9 = BIN2
Ground to ground 

TB6612FNG breakout to motors
AO1 = Red motor lead (Right)
AO2 = Black motor lead (Right)
BO2 = Black motor lead (Left)
BO1 = Red motor lead (Left) 
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace MotorController
{
    public class Program
    {
        public static void Main()
        {

            OutputPort stby = new OutputPort(Pins.GPIO_PIN_D0, true);
            TB6612FNG motors = new TB6612FNG(Cpu.Pin.GPIO_Pin1, Cpu.Pin.GPIO_Pin2, Cpu.PWMChannel.PWM_5);
            motors.MotorModeA = MotorMode.CW;
            motors.MotorSpeedA = 50;  // Set the motor to 50% speed   
           
            while (true)
            {
                motors.MotorModeA = MotorMode.CW;
                motors.MotorSpeedA = 50;  // Set the motor to 50% speed  
            }

        }

    }
}



#2 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 04 November 2014 - 03:58 PM

Wild guess since I do not have any of the pieces, but I suspect changing the motor mode and speed over and over again as fast as possible might have unintended consequences.

 

Try setting them both, sleep 1 second then set speed to 0; get rid of the while loop.  If that works you need to rethink your logic.



#3 Spammy786

Spammy786

    Member

  • Members
  • PipPip
  • 26 posts

Posted 04 November 2014 - 07:52 PM

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace MotorController
{
    public class Program
    {
        public static void Main()
        {

            OutputPort stby = new OutputPort(Pins.GPIO_PIN_D0, true);
            TB6612FNG motors = new TB6612FNG(Cpu.Pin.GPIO_Pin2, Cpu.Pin.GPIO_Pin3, Cpu.PWMChannel.PWM_5);
            motors.MotorModeA = MotorMode.CW;
            motors.MotorSpeedA = 1;
            Thread.Sleep(2000);
            motors.MotorSpeedA = 2;
            Thread.Sleep(2000);
            motors.MotorSpeedA = 4;
            Thread.Sleep(2000);
            motors.MotorSpeedA = 6;
            Thread.Sleep(2000);
            motors.MotorSpeedA = 8;
           
            //while (true)
            //{
            //    motors.MotorModeA = MotorMode.CW;
            //    motors.MotorSpeedA = 50;  // Set the motor to 50% speed  
            //}

        }

    }
}

Hi Spiked, thanks for the prompt reply, I tried what you said and the motor still does not turn

I just have 1 motor connected for now, If I can get it to work with 1 then I can get it to work with 2. I cant seem to find out why the motors don't turn. Any other advice ?



#4 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 05 November 2014 - 05:14 AM

Motor speed 8 may be too low. My motors generally do not start until around 30 or so. Stick with 50 for now.

 

Other than that, perhaps take a pic to show your wiring. Maybe someone who has the device can spot an issue.



#5 Spammy786

Spammy786

    Member

  • Members
  • PipPip
  • 26 posts

Posted 05 November 2014 - 06:18 AM

Ok, I will take a pic of the wiring and upload it. Il change the motor speed back to 50 and give that a try.

Il keep yourll post,



#6 Spammy786

Spammy786

    Member

  • Members
  • PipPip
  • 26 posts

Posted 05 November 2014 - 11:19 AM

Hi Guys

 

Heres a link to my wiring, the code above as not changed, Im pretty sure im missing something small. Im not sure what it is. Probably a part of my brain perhaps :(

Thanks

 

Link to wiring

http://s14.postimg.o..._Controller.jpg



#7 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 05 November 2014 - 12:24 PM

There is no power supply for the motors - VM is not connected (?)



#8 Spammy786

Spammy786

    Member

  • Members
  • PipPip
  • 26 posts

Posted 05 November 2014 - 12:41 PM

I thought the motors will get its power from the board because I am supplying power to the board from the N+2. 

I have a battery holder that takes 4 AA batteries that came with the chassis. That as a plug that connects straight to the N+2 power socket.

So now I need to buy additional batteries for the motors and solder the positive to VM ? and ground to Ground ?

Can I not use the 4 AA Batteries to power up the N+2 and the motors ?



#9 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 05 November 2014 - 12:57 PM

The motor driver IC has separate power supply for motors (VM) and logic (VCC). You can use the batteries to power both Netduino and motors (if it is a standard AA battery holder, you should be able to insert a wire between battery and the positive contact lead and solder it to motor board VM input).



#10 Spammy786

Spammy786

    Member

  • Members
  • PipPip
  • 26 posts

Posted 05 November 2014 - 01:15 PM

ok so solder 2 wires to the (4xAA battery holder with barrel jack termination)

Connect the positive to VM and the negative to Ground on the N+2

If this solves my problem, I am having a drink tonight

Thank you for your prompt reply. I will give this a try.



#11 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 05 November 2014 - 02:42 PM

That will get you going, but down the road keep in mind there is a reason logic voltage and motor voltage are usually kept apart. There are several ways to accomplish isolation, one the easiest/best being 2 different batteries.

 

The problem is, in some configurations the motor pull can drop the voltage below what the logic can tolerate, even if just for a microsecond the results can be bad. Also motors, being mechanically/electrically connected (brushes sparking) tend to introduce 'noise' on the circuit and cause all  kinds of hard to find problems.

 

Again, hook it up as you described, see if it works, then think a more permanent solution.


  • CW2 likes this

#12 Spammy786

Spammy786

    Member

  • Members
  • PipPip
  • 26 posts

Posted 05 November 2014 - 07:20 PM

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace MotorController
{
    public class Program
    {
        public static void Main()
        {

            OutputPort stby = new OutputPort(Pins.GPIO_PIN_D0, false);
            TB6612FNG motors = new TB6612FNG(Cpu.Pin.GPIO_Pin1, Cpu.Pin.GPIO_Pin2, Cpu.PWMChannel.PWM_5);
            motors.MotorModeA = MotorMode.CW;
            motors.MotorSpeedA = 60;
            Thread.Sleep(100000);
        }

    }
}

I tried taking the power directly from the 4 AA batteries and connected 1 end to VM and the other to GND and it still does not work. When I measure VM and GND I get 3v, so now there is power going to the motors. Is there anything else I can try ? I mean instead of connecting a Motor, Can I connect an LED to A01 and A02 and pulse the LED. just so we know the hardware is working correctly, there must be an easier way to debug this. if I connect the motors directly to the battery they turn quite fast, so I know the  motors are working.



#13 Spammy786

Spammy786

    Member

  • Members
  • PipPip
  • 26 posts

Posted 07 November 2014 - 09:23 AM

Any ideas guys ?



#14 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 07 November 2014 - 11:56 AM

Well, it does not seem right to have VM = 3V for 4 AA batteries, it should be around 6V (4*1.5V) for regular alkaline or 4.8 (4*1.2V) for NiMH cells. Where have you soldered the wire on the battery holder? 3V would mean you are using only two batteries, i.e. wrong terminal.



#15 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 07 November 2014 - 11:57 AM

Can you share the photo of the actual wiring?



#16 Spammy786

Spammy786

    Member

  • Members
  • PipPip
  • 26 posts

Posted 07 November 2014 - 01:38 PM

Sure, I shall take out a pic tonight and upload it, no problem. 

I was reading this article online : http://bildr.org/201...612fng-arduino/

And it talks about the StandBy Pin. Could that be my problem ? Im not sure. I did set it to true and ran the program, did nothing, I set it to false and it didnt do anything. So im not entirely sure.



#17 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 07 November 2014 - 02:57 PM

I have checked the datasheet again and I think there is a problem with control signal voltage levels: if you power the motor control board by 5 - 6 V, the Netduino 3.3V outputs do not have high enough voltage (VIH = 0.7*VCC = 0.7*5 = 3.5V).

 

So, connect VCC to Netduino 3.3V, STBY to 3.3V, VM to 5-6V.

 

To manually test the motors, connect PWM to 3.3V and then either IN1 or IN2 to 3.3V. 



#18 Spammy786

Spammy786

    Member

  • Members
  • PipPip
  • 26 posts

Posted 10 November 2014 - 06:56 AM   Best Answer

Hey CW2

 

Your suggestion above worked so I investigated the code a bit further. The problem was the PWM code. See all the examples I found, PWMA was connected to pin5, So we were choosing channel5, So basically we physically connected it to pin5 to the N+2 but in code you have to choose PIN0. I think this is because I am using 4.3.1.0.  The code below works :)

Thanks everybody for your help. 

using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace MotorController
{
    public class Program
    {
        public static void Main()
        {
            OutputPort stby = new OutputPort(Pins.GPIO_PIN_D0, true);

            //motorA
            PWM motorA = new PWM(Cpu.PWMChannel.PWM_0, 10000, 1, true);
            OutputPort a1 = new OutputPort(Pins.GPIO_PIN_D1, false);
            OutputPort a2 = new OutputPort(Pins.GPIO_PIN_D2, false);
            motorA.Start();

            //motorB
            PWM motorB = new PWM(Cpu.PWMChannel.PWM_1, 10000, 1, true);
            OutputPort b1 = new OutputPort(Pins.GPIO_PIN_D8, false);
            OutputPort b2 = new OutputPort(Pins.GPIO_PIN_D9, false);
            motorB.Start();


            while (true)
            {
                //this controls motorA
                a1.Write(false);
                a2.Write(true);
                motorA.DutyCycle = (double)0.7;

                //this controls motorB
                b1.Write(false);
                b2.Write(true);
                motorB.DutyCycle = (double)0.7;
             }
        }
    }
}






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.