Big Mouth Billy Bass and Motor Shield
Moderators: adafruit_support_bill, adafruit

Big Mouth Billy Bass and Motor Shield

by cjb41183 on Wed Mar 06, 2013 10:47 pm

I am total rookie at this, let me just put that out there!

I am working on hacking a Big Mouth Billy Bass. I have an Arduino Uno, an Adafruit Motor Shield and an Adafruit Wave Shield. I did some research about pin conflicts and so I jumped the LCS, CLK, DI, and LAT to analog 0-3 respectively and CCS to 10. On the Motor Shield I cut the traces to pins 11 and 12 and jumped 12 to 2. (I did not bother jumping 11 since that is the control for M1 and I only need to use M2, M3, M4).

I put three .1uF capacitors on each of the motors to prevent noise and I added am powering the arduino separately from the motor shield. I am using 8 AA batteries on the motor shield which should provide plenty of voltage to power the three 6vdc motors in the Big Mouth Billy Bass.

I ran a test sketch and got the wave shield to play while motors moved. I tested each of the motor ports with success.

Then I connected all three motors from the BBMB to the motor shield. I ran the following sketch as a simple test to make sure I could control each motor.

Code: Select all | TOGGLE FULL SIZE
#include <AFMotor.h>

  AF_DCMotor mouth(2, MOTOR12_64KHZ);
  AF_DCMotor body(3, MOTOR34_64KHZ);
  AF_DCMotor tail(4, MOTOR34_64KHZ);

void setup () {
 
  Serial.begin(9600);
  Serial.println("Here we go!"); //initialize
 
  mouth.setSpeed(255); //set mouth at full throttle
  body.setSpeed(255);  //set body at full throttle
  tail.setSpeed(255);  //set tail at full throttle
 
  mouth.run(RELEASE);   //disengage mouth
  body.run(RELEASE);    //disengage body
  tail.run(RELEASE);    //disengage tail
}

void loop () {
 
  Serial.println("Moving mouth");
 
  mouth.run(FORWARD);    //run mouth
  delay(1000);          //wait 1 second
  mouth.run(RELEASE); //disengage mouth
  delay(1000);        //delay 1 second
  mouth.run(FORWARD);  //run mouth
  delay(2000);          //wait 2 seconds
  mouth.run(RELEASE);    //disengage mouth
 
  Serial.println("Moving tail");
 
  tail.run(FORWARD);   //run tail
  delay(1000);          //wait 1 second
  tail.run(RELEASE);    //disengage tail
  delay(1000);            //wait 1 second
  tail.run(FORWARD);      //run tail
  delay(2000);            //wait 2 seconds
  tail.run(RELEASE);      //disengage tail
 
  Serial.println("Moving body");
 
  body.run(FORWARD);      //run body
  delay(1000);              //wait 1 second
  body.run(RELEASE);      //disengage body
  delay(1000);              //wait 1 second
  body.run(FORWARD);        //run body
  delay(2000);              //wait 2 seconds
  body.run(RELEASE);        //disengage body
 
 
  Serial.println("All's quiet on the western front..."); //tell me that it is over
  delay(5000); //wait 5 seconds
 
}


The way the BMBB works is when the motor is powered, it moves the part of the body until the power is removed and a spring brings back into place. For whatever reason, when I connect all 3 motors and run this sketch, only one part of the body will engage and stay engaged. It isn't controlled. For example, the tail motor (M4) will engage and stay engaged until I unplug the arduino or remove the power supply to the motor shield. If I then unplug the tail from M4, the same thing will happen but with the mouth (on M2). Finally, if I only leave the body motor (M3) plugged in, the same thing happens. It engages and stays engaged until I remove power.

I'm really not sure where to go from here. I have attached pictures of my setup. Please be merciful! I am a total rookie...

Here are the pictures. I did not include the wave shield since I have not had problems making that work. However, I can put them in a separate post if that would help.

[img]
IMG_3441.JPG
The arduino with wave shield and motor shield connected.
IMG_3441.JPG (220.35 KiB) Viewed 902 times

IMG_3449.JPG
The motor shield
IMG_3449.JPG (127.66 KiB) Viewed 902 times

IMG_3452.JPG
Motor shield bottom
IMG_3452.JPG (165.33 KiB) Viewed 902 times

[/img
Last edited by cjb41183 on Thu Mar 07, 2013 8:15 am, edited 2 times in total.
cjb41183
 
Posts: 18
Joined: Sun Mar 03, 2013 11:25 am

Re: Motor Shield Problems

by adafruit_support_bill on Thu Mar 07, 2013 5:29 am

Your photos are probably too large. Re-size them to about 800x600 and you should be able to upload them.
User avatar
adafruit_support_bill
 
Posts: 29218
Joined: Sat Feb 07, 2009 9:11 am

Re: Motor Shield Problems

by cjb41183 on Thu Mar 07, 2013 8:14 am

Thank you for getting back to me and for your suggestion. I resized the pics and edited them into my original post.
cjb41183
 
Posts: 18
Joined: Sun Mar 03, 2013 11:25 am

Re: Big Mouth Billy Bass and Motor Shield

by adafruit_support_bill on Thu Mar 07, 2013 8:58 am

What do you see in the serial monitor when you run this?
Try connecting just one motor at a time.
User avatar
adafruit_support_bill
 
Posts: 29218
Joined: Sat Feb 07, 2009 9:11 am

Re: Big Mouth Billy Bass and Motor Shield

by cjb41183 on Thu Mar 07, 2013 9:11 am

The serial monitor just prints that it is running each motor ("Move mouth" "move body" "move tail" "all's quiet..."). Even if I have all three motors connected but comment out all but one motor's commands, it still acts weird. For example, if I comment out the commands for M2 and M4 (but leave them connected), and just run the motor on M3, the motor on M2 will still engage and stay engaged until I remove power either to the shield or to the arduino. Or if I press reset on the shield it powers down and starts again with the same problem.

If I disconnect all of the motors but one and run the commands for that motor, it does the same thing. Engages and stays engaged until I remove power regardless of the commands to release, etc.
cjb41183
 
Posts: 18
Joined: Sun Mar 03, 2013 11:25 am

Re: Big Mouth Billy Bass and Motor Shield

by adafruit_support_bill on Thu Mar 07, 2013 10:12 am

You moved pin 12 to pin 2. Did you modify the library to match?
User avatar
adafruit_support_bill
 
Posts: 29218
Joined: Sat Feb 07, 2009 9:11 am

Re: Big Mouth Billy Bass and Motor Shield

by cjb41183 on Thu Mar 07, 2013 10:30 am

That's a good catch. I did not. However, I can't find where pin 12 is even mentioned in the AFMotor library.
cjb41183
 
Posts: 18
Joined: Sun Mar 03, 2013 11:25 am

Re: Big Mouth Billy Bass and Motor Shield

by adafruit_support_bill on Thu Mar 07, 2013 10:39 am

See AFMotor.h - line 137: (And don't forget to post photos of Billy Bass when you get him running :D )

Code: Select all | TOGGLE FULL SIZE
// Arduino pin names for interface to 74HCT595 latch
#define MOTORLATCH 12
#define MOTORCLK 4
#define MOTORENABLE 7
#define MOTORDATA 8
User avatar
adafruit_support_bill
 
Posts: 29218
Joined: Sat Feb 07, 2009 9:11 am

Re: Big Mouth Billy Bass and Motor Shield

by cjb41183 on Thu Mar 07, 2013 11:00 am

Ahhhh, I was searching in AFMotor.cpp, not AFMotor.h. Ok, let's see if it works. Thank you for your help and I will post pictures *when* I get it to work!
cjb41183
 
Posts: 18
Joined: Sun Mar 03, 2013 11:25 am

Re: Big Mouth Billy Bass and Motor Shield

by cjb41183 on Thu Mar 07, 2013 11:47 am

I have control! Thank you for helping me troubleshoot that. So simple. Now for that hard part of coordinating words and movements...

One thing I do notice, however, is that whenever motor 2 engages, there is some static on the speaker connected to the wave shield. Any suggestion as to how to quiet that? I already have 3 capacitors on every motor. Maybe when I actually play sound with it it won't be as bad? I will have to test that.

Billy thanks you!

[img]
IMG_3458.JPG
Thank you!
IMG_3458.JPG (178.79 KiB) Viewed 860 times

[/img]
cjb41183
 
Posts: 18
Joined: Sun Mar 03, 2013 11:25 am

Re: Big Mouth Billy Bass and Motor Shield

by adafruit_support_bill on Thu Mar 07, 2013 11:50 am

whenever motor 2 engages, there is some static on the speaker connected to the wave shield.

Try to route the motor leads away from the Wave-shield & associated wiring as much as possible.
User avatar
adafruit_support_bill
 
Posts: 29218
Joined: Sat Feb 07, 2009 9:11 am

Re: Big Mouth Billy Bass and Motor Shield

by cjb41183 on Sat Mar 09, 2013 12:48 pm

I seem to have taken care of the sound problem by routing the wires away from the speaker. Thanks for that advice.

Now for the next problem...

The motors work perfectly with a test sketch that I ran. They sync up well. Now, I tried to do a test where I push a button, the sound plays and the body motor (M3) operates. Unfortunately, the motor does not operate in my sketch. The wave file plays at the push of the button and I can hear a high pitched noise from the motor (like it is trying to operate) but it does not actually engage the mechanism on the body. I can test it with any motor (tail (M4), body (M3), mouth (M2)) with the same result. The only difference is that I only hear the high pitched motor noise with the body motor. So I'm stuck again. Here is my sketch. It is basically the 6 button sketch from the website modified for one button. Thanks again.

Code: Select all | TOGGLE FULL SIZE
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"
#include <AFMotor.h>

  AF_DCMotor mouth(2, MOTOR12_64KHZ);
  AF_DCMotor body(3, MOTOR34_64KHZ);
  AF_DCMotor tail(4, MOTOR34_64KHZ);

SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we're play

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

#define DEBOUNCE 100  // button debouncer

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  extern int  __bss_end;
  extern int  *__brkval;
  int free_memory;
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end);
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval);
  }
  return free_memory;
}

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}

void setup() {
  // set up serial port
  Serial.begin(9600);
  putstring_nl("WaveHC with 6 buttons");
 
   putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!
 
  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(17, OUTPUT);
  pinMode(16, OUTPUT);
  pinMode(15, OUTPUT);
  pinMode(14, OUTPUT);

 
  // enable pull-up resistors on switch pins (analog inputs)
    digitalWrite(18, HIGH);
 
 
  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!) 
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
 


    //define motor speeds
    mouth.setSpeed(255);
    body.setSpeed(255);
    tail.setSpeed(255);
 

    //ensure motors are disengaged
    mouth.run(RELEASE);
    body.run(RELEASE);
    tail.run(RELEASE);

}
 
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
// Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part))
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
 
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?
 
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }
 
  // Whew! We got past the tough parts.
  putstring_nl("Ready!");
}

void loop() {
  //putstring(".");            // uncomment this to see if the loop isnt running
  switch (check_switches()) {
        case 5:
        playcomplete("OHD!~1.WAV");
        break;
   
  }
}

byte check_switches()
{
  static byte previous[6];
  static long time[6];
  byte reading;
  byte pressed;
  byte index;
  pressed = 0;

  for (byte index = 0; index < 6; ++index) {
    reading = digitalRead(14 + index);
    if (reading == LOW && previous[index] == HIGH && millis() - time[index] > DEBOUNCE)
    {
      // switch pressed
      time[index] = millis();
      pressed = index + 1;
      break;
    }
    previous[index] = reading;
  }
  // return switch number (1 - 6)
  return (pressed);
}


// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying) {
  // do nothing while its playing
  }
  // now its done playing
}

void playfile(char *name) {
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file "); Serial.print(name); return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
 
  // ok time to play! start playback and make the body move while it plays
    wave.play();
    body.run(FORWARD);
    delay(1000);
    body.run(RELEASE);
 
 
 
}
cjb41183
 
Posts: 18
Joined: Sun Mar 03, 2013 11:25 am

Re: Big Mouth Billy Bass and Motor Shield

by adafruit_support_bill on Sat Mar 09, 2013 2:06 pm

Hmmm. If you go back to your motor-only test sketch, the motors still run? Make sure your battery pack is not run down.
User avatar
adafruit_support_bill
 
Posts: 29218
Joined: Sat Feb 07, 2009 9:11 am

Re: Big Mouth Billy Bass and Motor Shield

by cjb41183 on Sat Mar 09, 2013 2:15 pm

If you go back to your motor-only test sketch, the motors still run? Make sure your battery pack is not run down.


The motors run perfectly on the motor only sketch. The arduino runs on the USB cable for the tests. The battery pack is 6 AA batteries and the batteries are in great shape. Just in case, I connected the 8 AA battery pack. Same problem.
cjb41183
 
Posts: 18
Joined: Sun Mar 03, 2013 11:25 am

Re: Big Mouth Billy Bass and Motor Shield

by adafruit_support_bill on Sun Mar 10, 2013 8:08 am

Strange. I don't see anything obviously wrong in the code.

Measure the voltage on the body motor when the motor is supposed to be running. Is it any different when running your test sketch?
User avatar
adafruit_support_bill
 
Posts: 29218
Joined: Sat Feb 07, 2009 9:11 am