DRV8833, Arduino, gyro schematic?

Your Pololu sales order #1J101887 is being processed

I bought both the drv8833 and a Toshiba TB6612FNG - it has a help website
meanpc.com/2012/01/how-to-us … -with.html, also
I noticed in its datasheet that it says Motor supply (2.5 V to 13.5 V) even though your
webpage says A recommended motor voltage of 4.5 – 13.5 V

I find it amazing I can’t find a schematic on the web of a gyro connected to arduino to a motor or motor driver and motor. Do you know where I could find a schematic or wiring diagram showing the sensor connected to the arduino connected to the motor and/or motor driver?

Hello.

I split your post into a separate topic because it was not related to the topic you posted under.

According to page 3 of the datasheet, IOUT is severely limited in the lower voltage range. What gyro are you trying to connect? If you post a schematic here of how you think your parts should be connected, I would be happy to review it before you connect power.

- Ryan

see msg below

Are you referring to page 3 of the toshiba motor driver IOUT rated at 1.2 A?
page 3 TB6612FNGd.pdf;I don’t see any IOUT info on page 3 of the drv8833.pdf datasheet

The gyro is L3G4200D connecting through SCL and SDA to an arduino ATmega640/1280/2560 or Arduino Mega 2560 R3 (Atmega2560 - assembled) from adafruit (already purchased/undelivered as is the gyro) on port D pins PD0 and PD1, respectively. I don’t know how to make a schematic to fit this format - my current design connects GND to GND on the gyro and arduino and +5 on the arduino to Vcc on the gyro. I then connect PC1 on the arduino to AIN1 on the toshiba motor driver and PC0 on the arduino to AIN2 on the toshiba motor driver. I also have GND on the motor driver connected to another GND on the arduino. I have a minimum 3 Volt (I tested a 6.5 volt battery pack on the robot arm motor and it seems to work ok) power supply to VM on the toshiba. I then connect AO1 and AO2 to the plus/minus sides of the motor. From the data below I interpret the motor driver needs to be supplied 6 V on the Vcc pin, however, I don’t see any Vin pin or IN1 or IN2 pins.
page 3 TB6612FNGd.pdf:
Characteristics Symbol Rating Unit Remarks
Supply voltage VM 15 V
VCC 6

Input voltage VIN -0.2 to 6 V IN1,IN2,STBY,PWM pins
Output voltage VOUT 15 V O1,O2 pins

I don’t see any IOUT info on page 3 of the drv8833.pdf datasheet
I also have to figure out the basic code to program the arduino to interpret the data from SDA from the gyro and what signal to send to the motor driver through PC1 and PC0. (Are these appropriate pin choices?)

The way the senior design course works is fall term is a design report and spring term requires building of the design. The way undergraduate EE works is preparation for grad EE school - this is the first course that ever dealt with actual soldering or designing a pcb layout or building anything (spring term).
Thank you for your help and happy Holidays.

I need a pressure sensor for the operator’s hand to squeeze to make the gripper open and close, do you recommend any particular type of pressure sensor or specific pressure sensor? Should this be in a different topic - ultimately the pressure sensor signal has to drive the motor driver to run the motor that opens and closes the gripper.

Yes, I was referring to the TB6612FNG datasheet.

The TB6612FNG’s Vcc should be equal to the logic high voltage of your controller. In your case, Vcc should be 5V (the operating voltage of the Mega’s AVR), not 6V. I think you are mistaking the absolute maximum ratings for the operating range.

Sorry, what pin choices are you asking are appropriate? Your project would be a lot easier to understand if you made a wiring connection diagram. An easy way to do that is copy pictures of all of your parts into a paint program and draw lines between them where you will make connections.

- Ryan

is there any sample code for the arduino to run a dc motor, one-speed, forward and reverse?
is this info from meanpc.com/2012/01/how-to-us … -with.html good?
where are the functions motor_brake() motor_drive() defined?

It turns out, you have to make every connection on the TB6612FNG chip to get it to work properly.
So, to go forward you would need to program:
STBY - HIGH
AIN1 - HIGH
AIN2 - LOW
PWMA - 255
STBY - HIGH
BIN1 - HIGH
BIN2 - LOW
PWMB - 255

void loop()
{
  motor_brake();               
  delay(1000);
  motor_drive(FORWARD, 50); 
  delay(1000);
  motor_drive(FORWARD, 75);
  delay(1000);
  motor_drive(FORWARD, 100); 
  delay(1000);
  motor_drive(FORWARD, 125); 
  delay(1000);
  motor_drive(FORWARD, 150); 
  delay(1000);
  motor_drive(FORWARD, 175); 
  delay(1000);
  motor_drive(FORWARD, 200); 
  delay(1000);
  motor_drive(FORWARD, 255); 
  delay(1000);

Hello.

I don’t see anything wrong with that tutorial. That tutorial refers back to another forum topic on our thread and you can find the full code in that thread:

NOTE: You need to click the “Expand” button above the code or use the scroll bar to see the entire code. That will let you see the definitions of those functions.

Also, please note that the code was posted at a time when the system was not behaving properly, so you will need to read the remainder of the thread to see if any code changes had to be made to get the motor working.

If you have trouble getting it to work, please simplify your code as much as possible and post a complete description of everything you did to set up the system, and the expected behavior of the system versus the actual behavior.

–David

There are no include files in the code,
are these functions part of the arduino operating system?

pinMode(PWMA,OUTPUT);
delay(1000)
digitalWrite(STBY,LOW)
analogWrite(PWMB,speed)

motor_standby(false); //Must set STBY pin to HIGH in order to move

are false and true default values of the arduino operating system?
false=0?
true=1?
the code doesn’t define any values for false or true

Yes, those functions are available by default and you don’t need any includes to get them. They are part of Arduino. (Though it’s not technically an operating system.)

The expressions “true” and “false” are defined by C++ and they are basically 1 and 0 I think. C++ also defines a type called “bool”.

–David

Re:
Connect to PWM pin on the Arduino. On the Arduino Uno, this would be either pin 3,5,6,9,10,or 11.
Connect to a digital pin on the Arduino.

I am connecting to a mega 2560 board
digital pins 22-53
pwm 38-40, 15-18, 0-13

I can connect to any digital or pwm pin and compile code as is in arduino sketch without any include files?

Yes, that generally sounds OK. I would avoid pins 0 and 1 because they are used for uploading sketches, though.

–David

the code compiles without error
Is there a simple printf(" ") type command in arduino to print to the Serial Monitor

motor_drive(FORWARD, 150); //Move FORWARD at full speed for 1s
delay(1000);
// print here “forward”

motor_brake(); //STOP for 1s
delay(1000);
// print here “brake”

The println function would work. Also, don’t forget to call Serial.begin in setup(). More info is here:

arduino.cc/en/Reference/Serial

–David

I connected the mega and driver board and uploaded the program successfully. However, I haven’t
connected the motor power supply (4.5V = 3 AAA) and motors (3V dc on OWI robot arm Edge) yet.

Do the defines below have to match the connections to the mega board pin numbers?
Does the define PWMA have to be the number of pin (7) where connected on the mega?
Does the define PWMB have to be the number of pin (4) where connected on the mega?
etc.

//PWMA - Connect to PWM pin on the Arduino.  On the Arduino Uno, this would be either pin 3,5,6,9,10,or 11.
//AIN2 - Connect to a digital pin on the Arduino.


#define PWMA 0
    #define AIN1 2
    #define AIN2 1
    #define BIN1 4
    #define BIN2 5
    #define PWMB 6
    #define STBY 3



 pinMode(PWMA,OUTPUT);
      pinMode(AIN1,OUTPUT);
      pinMode(AIN2,OUTPUT);
      pinMode(PWMB,OUTPUT);
      pinMode(BIN1,OUTPUT);
      pinMode(BIN2,OUTPUT);
      pinMode(STBY,OUTPUT);

Hello. The answers to your three questions are all yes.

–David

nothing happens when I connect the power supply (4.5 or 6.5 Volts) and motors (3V dc)
the program compiles and uploads successfully
it appears to run from the messages on the serial monitor from upload and each reset press:
starting loop
inside loop

all I am trying to do is simply rotate the motors 1 sec cw (forward), 1 sec ccw (reverse)
could this be the problem?
//Must set STBY pin to HIGH in order to move
Does the pin STBY is on (42) need to be set high by a s/w command?
doesn’t this code set STBY to high?

 pinMode(STBY,OUTPUT);
           motor_standby(false);        //Must set STBY pin to HIGH in order to move

  //Turns off the outputs of the Motor Driver when true
    void motor_standby(char standby)
    {
      if (standby == true) digitalWrite(STBY,LOW);
      else digitalWrite(STBY,HIGH);
    }

I get an error msg from the arduino sketch when I click ‘copy for forum’

Binary sketch size: 4,886 bytes (of a 258,048 byte maximum)
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 23
	at processing.app.tools.DiscourseFormat.appendFormattedLine(DiscourseFormat.java:192)
	at processing.app.tools.DiscourseFormat.show(DiscourseFormat.java:99)
	at processing.app.Editor$34.actionPerformed(Editor.java:1156)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
	at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1225)
	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1266)
	at java.awt.Component.processMouseEvent(Component.java:6263)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
	at java.awt.Component.processEvent(Component.java:6028)
	at java.awt.Container.processEvent(Container.java:2041)
	at java.awt.Component.dispatchEventImpl(Component.java:4630)
	at java.awt.Container.dispatchEventImpl(Container.java:2099)
	at java.awt.Component.dispatchEvent(Component.java:4460)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
	at java.awt.Container.dispatchEventImpl(Container.java:2085)
	at java.awt.Component.dispatchEvent(Component.java:4460)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
#define PWMA 7
    #define AIN1 38
    #define AIN2 34
    #define BIN1 49
    #define BIN2 51
    #define PWMB 4
    #define STBY 42
    #define motor_A 0
    #define motor_B 1
    #define FORWARD 1
    #define REVERSE 0
    #define RIGHT 1
    #define LEFT 0

    void setup()
    {
      pinMode(PWMA,OUTPUT);
      pinMode(AIN1,OUTPUT);
      pinMode(AIN2,OUTPUT);
      pinMode(PWMB,OUTPUT);
      pinMode(BIN1,OUTPUT);
      pinMode(BIN2,OUTPUT);
      pinMode(STBY,OUTPUT);
           motor_standby(false);        //Must set STBY pin to HIGH in order to move
      // open the serial port at 9600 bps:
        Serial.begin(9600); 	
 
         Serial.println("starting loop");

    }

    void loop()    {

 Serial.println("inside loop");

      motor_brake();               //STOP for 1s
      delay(1000);
      motor_drive(FORWARD, 150);   //Move FORWARD at full speed for 1s
      delay(1000);
      motor_brake();               //STOP for 1s
      delay(1000);
      motor_drive(REVERSE, 150);   //REVERSE at about half-speed for 1s
      delay(1000);
      motor_brake();               //STOP for 1s
      delay(1000);
      motor_turn(RIGHT, 150, 150); //Spin RIGHT for 0.5s
      delay(1000);
      motor_brake();
      delay(100000000);
      }

    //Turns off the outputs of the Motor Driver when true
    void motor_standby(char standby)
    {
      if (standby == true) digitalWrite(STBY,LOW);
      else digitalWrite(STBY,HIGH);
    }

    //Stops the motors from spinning and locks the wheels
    void motor_brake()
    {
      digitalWrite(AIN1,1);
      digitalWrite(AIN2,1);
      digitalWrite(PWMA,LOW);
      digitalWrite(BIN1,1);
      digitalWrite(BIN2,1);
      digitalWrite(PWMB,LOW);
    }

    //Controls the direction the motors turn, speed from 0(off) to 255(full speed)
    void motor_drive(char direction, unsigned char speed)
    {
      if (direction == FORWARD)
      {
        motor_control(motor_A, FORWARD, speed);
        motor_control(motor_B, FORWARD, speed);
      }
      else
      {
        motor_control(motor_A, REVERSE, speed);
        motor_control(motor_B, REVERSE, speed);
      }
    }

    //You can control the turn radius by specifying the speed of each motor
    //Set both to 255 for it to spin in place
    void motor_turn(char direction, unsigned char speed_A, unsigned char speed_B )
    {
      if (direction == RIGHT)
      {
        motor_control(motor_A, REVERSE, speed_A);
        motor_control(motor_B, FORWARD, speed_B);
      }
      else
      {
        motor_control(motor_A, FORWARD, speed_A);
        motor_control(motor_B, REVERSE, speed_B);
      }
    }

    void motor_control(char motor, char direction, unsigned char speed)
    {
      if (motor == motor_A)
      {
        if (direction == FORWARD)
        {
          digitalWrite(AIN1,HIGH);
          digitalWrite(AIN2,LOW);
        }
        else
        {
          digitalWrite(AIN1,LOW);
          digitalWrite(AIN2,HIGH);
        }
        analogWrite(PWMA,speed);
      }
    
      {
        if (direction == FORWARD)  //Notice how the direction is reversed for motor_B
        {                          //This is because they are placed on opposite sides so
          digitalWrite(BIN1,LOW);  //to go FORWARD, motor_A spins CW and motor_B spins CCW
          digitalWrite(BIN2,HIGH);
        }
        else
        {
          digitalWrite(BIN1,HIGH);
          digitalWrite(BIN2,LOW);
        }
        analogWrite(PWMB,speed);
      }
    }

output (after each press of the reset button):
starting loop
inside loop

starting loop
inside loop

starting loop
inside loop

starting loop
inside loop

I edited your post this time, but in future posts please surround any code snippets with [code ] and [/code ] tags (without the inner spaces) to make them readable. You can just select the code and then click the “Code” button about the text area.

Yes, the TB6612FNG’s STBY pin must be driven high to take the driver out of standby mode and allow the motor to run and the lines of code you pasted are supposed to do that.

Have you gotten the motor to spin at all yet? If not, I recommend doing that as a first step.

Do you have a multimeter available? If so, you should measure the voltage on all of the TB6612FNG’s inputs to make sure they are what you would expect, to verify that your Arduino program is doing the right thing. I think I see at least one bug in that program, so it would be good to simplify it down to the simplest possible thing that should work but doesn’t. One way to simplify it is to get rid of all the functions except setup and loop.

–David

success. I reduced the code and tried the pins and they all seemed to be working
properly and then I found the motor leads were connected to the original manual
controller on the arm instead directly to the motor.

  1. one question, does it matter if the power supply to the motor driver
    is connected while uploading the program?

  2. do you sell a battery clip to power the mega directly?

    #define PWMA 7
    #define AIN1 38 // AO1 - Connect to the negative lead of motor A.
    #define AIN2 34  // AO2 - Connect to the positive lead of motor A.
    #define BIN1 49
    #define BIN2 51
    #define PWMB 4
    #define STBY 42
    #define motor_A 0
    #define motor_B 1
    #define FORWARD 1
    #define REVERSE 0
    #define RIGHT 1
    #define LEFT 0
  
    void setup()
    {
      pinMode(PWMA,OUTPUT);
      pinMode(AIN1,OUTPUT);
      pinMode(AIN2,OUTPUT);
      pinMode(PWMB,OUTPUT);
      pinMode(BIN1,OUTPUT);
      pinMode(BIN2,OUTPUT);
      pinMode(STBY,OUTPUT);
      digitalWrite(STBY,HIGH);
 
        Serial.begin(9600); 	

  Serial.println("starting loop");
    }

    void loop()    {

digitalWrite(STBY,HIGH);

    //  digitalWrite(AIN1,HIGH);
     //      digitalWrite(AIN2,LOW);
        digitalWrite(AIN1,LOW);
        digitalWrite(AIN2,HIGH);
   analogWrite(PWMA,255);
      delay(1000);
      analogWrite(PWMA,0);
  
     Serial.println("inside loop");
   delay(100000000);
   
      }

I am glad you were able to figure out your problem by methodically checking everything.

I don’t see any reason why that would matter.

Looking at the Arduino Mega schematic, it seems like you should be able to plug one of our battery packs into the GND/VIN pins on the female header. However, you would be giving up the reverse protection provided by diode D1, which you normally would get if you use the normal power jack. To make this work, you would need:

A battery pack with the 1x3 0.1"-spaced header:
pololu.com/catalog/category/54

Double-sided male headers:
pololu.com/catalog/product/1065
A 1x2 piece of these can go between the Arduino and the battery.

A battery charger, such as
pololu.com/catalog/product/2260

–David