Is there a way to re-route pin 7 in code on the motor shield?

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
allanonmage
 
Posts: 19
Joined: Mon Dec 24, 2012 4:32 pm

Is there a way to re-route pin 7 in code on the motor shield?

Post by allanonmage »

I have an Arduino Mega ADK and would like to make use of the motor shield and the USB port on the Mega ADK for my project. I would like to use the motor controller to drive DC motors on an OWI 535 arm, like I saw on an instructable:

http://www.instructables.com/id/Intro-a ... oull-need/

I opened up AFMotor.h and AFMotor.cpp hoping I could just change a pin number, but it looks more complicated than that, as the code was written for the machine, not a n00b programmer like me.

I have this board:
http://www.ladyada.net/make/mshield/
and this arduino:
http://arduino.cc/en/Main/ArduinoBoardADK

This is why I need to move pin 7 (from Arduino main page):
USB Host: MAX3421E. The MAX3421E comunicate with Arduino with the SPI bus. So it uses the following pins:

Digital: 7 (RST), 50 (MISO), 51 (MOSI), 52 (SCK).
NB:Please do not use Digital pin 7 as input or output because is used in the comunication with MAX3421E
Non broken out on headers: PJ3 (GP_MAX), PJ6 (INT_MAX), PH7 (SS).

Is moving around pin 7 in code even possible? If so, is it feasible? it looks to me like it's kind of important and would be hard to move or replace. I did try to head this off at the pass by looking up pin numbers and all, but it seems I missed this one. Thankfully I found it before I started trying to get everything working.

The project is an OWI 535 arm on a roomba, and there will be an onboard android phone. Since I'm still testing, the USB is used for bluteooth, and I'll bring the Android in later.
Last edited by allanonmage on Tue Dec 25, 2012 1:22 am, edited 1 time in total.

allanonmage
 
Posts: 19
Joined: Mon Dec 24, 2012 4:32 pm

Re: Is there a way to re-route pin 7 in code on the motor shield?

Post by allanonmage »

I did a little reading about SPI and there might be a way to make everything play nice. Maybe. If I were to recode a whole lot of libraries... :(

I think it might be easier to have a dedicated Uno or something run that and then somehow share data between the 2 arduinos. Although that seems like a real waste to me over a bus that was meant to be shared.

I mean if I'm going to use different hardware I might as well use a different motor controller. Why is SPI even used at all on the adafruit board? It's using a bunch of IO pins *AS* IO pins, why does it need data too??

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Is there a way to re-route pin 7 in code on the motor shield?

Post by adafruit_support_bill »

A genuine adafruit motor shield does not use spi. No idea about clone boards like yours.

allanonmage
 
Posts: 19
Joined: Mon Dec 24, 2012 4:32 pm

Re: Is there a way to re-route pin 7 in code on the motor shield?

Post by allanonmage »

This is the item I ordered:
http://www.amazon.com/gp/product/B00685 ... 01_s00_i00

Here's the description (my emphasis):
Easy to use and full featured motor driver shield for Arduino. Made by Adafruit. Comes in kit form, requires soldering. 2 connections for 5V 'hobby' servos connected to the Arduino's high-resolution dedicated timer - no jitter! 4 H-Bridges: L293D chipset provides 0.6A per bridge (1.2A peak) with thermal shutdown protection, internal kickback protection diodes. Can run motors on 4.5VDC to 36VDC. Up to 4 bi-directional DC motors with individual 8-bit speed selection (so, about 0.5% resolution) Up to 2 stepper motors (unipolar or bipolar) with single coil, double coil or interleaved stepping. Pull down resistors keep motors disabled during power-up Big terminal block connectors to easily hook up wires (18-26AWG) and power Arduino reset button brought up top 2-pin terminal block and jumper to connect external power, for separate logic/motor supplies Tested compatible with Arduino Mega 1280 & 2560, Diecimila, Duemilanove, and UNO Download the easy-to-use Arduino software library, check out the examples and you're ready to go!
I put the black mark on the ground for the main power so i didn't fry anything. The "kit" came preassembled as a board, btu I have no reason to think things are not working, save for my other thread about the power draw from USB.

For the sake of argument, let's move past whether or not it's a real, fake, or even working board. This thread is all about software anyways, so it doens't even matter about the hardware.

If the adafruit controlelr does not use SPI, that's great, that means i shoudl be able to re-route what it uses pin 7 for in software. As I said before, it's not clear to me on how to do that.

In AFMotor.h, I find a reference to pin 7:

Code: Select all

// Arduino pin names for interface to 74HCT595 latch
#define MOTORLATCH 12
#define MOTORCLK 4
#define MOTORENABLE 7
#define MOTORDATA 8
In looking at both AFMotor.h and AFMotor.cpp that's the only reference that I can see. However, I see a lot of code written at a very low level, which I can't really read all that well. I do recognize that timers are being used, which doesn't make sense to me, as all the pins used have hardware PWM and shouldn't need software PWN using timers (do I have that right?).

I'm not sure this would be the only place to change it. I can't tell if this is for DC motor use or steppers. I'm not using stepepr motors, so I thought about ripping out all the code meant for steppers and other arduinos to see if I could improve readability
Attachments
.<br />.<br />.<br />You will note the URl printed on the board yes?<br />.<br />.
.
.
.
You will note the URl printed on the board yes?
.
.
Slide1.PNG (787.25 KiB) Viewed 1616 times
.<br />.<br />Side by side comparison of what I have to a picture found on http://www.ladyada.net/make/mshield/.  The board I have is blue and on the left, the one from the website is on the right.<br />.<br />.
.
.
Side by side comparison of what I have to a picture found on http://www.ladyada.net/make/mshield/. The board I have is blue and on the left, the one from the website is on the right.
.
.
Slide2.jpg (225.37 KiB) Viewed 1616 times

allanonmage
 
Posts: 19
Joined: Mon Dec 24, 2012 4:32 pm

Re: Is there a way to re-route pin 7 in code on the motor shield?

Post by allanonmage »

I think I've hit a road block. The code I mentioned before in the .h file

Code: Select all

#define MOTORENABLE 7
doesn't appear to have any mention of pin 7 or MOTORENABLE anywhere else in the .h file.

Going to the .cpp file and I only find a few references to MOTORENABLE, the final one being to set it LOW and keep it there.

Code: Select all

void AFMotorController::enable(void) {
  // setup the latch
  /*
  LATCH_DDR |= _BV(LATCH);
  ENABLE_DDR |= _BV(ENABLE);
  CLK_DDR |= _BV(CLK);
  SER_DDR |= _BV(SER);
  */
  pinMode(MOTORLATCH, OUTPUT);
  pinMode(MOTORENABLE, OUTPUT);
  pinMode(MOTORDATA, OUTPUT);
  pinMode(MOTORCLK, OUTPUT);

  latch_state = 0;

  latch_tx();  // "reset"

  //ENABLE_PORT &= ~_BV(ENABLE); // enable the chip outputs!
  digitalWrite(MOTORENABLE, LOW);
}
Based on the FAQ it seems there is some serial data going on:
Digital pin 4, 7, 8 and 12 are used to drive DC motors and Stepper motors via the 74HC595 serial-to-parallel latch
All these pins are in use if any DC motors or steppers are used
so based on the SPI page
http://arduino.cc/en/Reference/SPI
and the Arduino Mega ADK page
http://arduino.cc/en/Main/ArduinoBoardADK

that pin is a RST function, which I presume to be a shortened form of Reset. I couldn't find any mention of that on the SPI page though, save the pic of a header, so I'm not sure what to think of that.
and one line specific for every device:
SS (Slave Select) - the pin on each device that the master can use to enable and disable specific devices.
I'm thinking it might be the slave select line for the SPI, but that doesn't make much sense either. If it is that simple, pin 7 is not required and it would be easy to change the definition and that would be the end of it, compatibility problem solved.

But I saw a lot of loops and things that might not take into account the referenced pin numbers, so I will keep thinking this through.

allanonmage
 
Posts: 19
Joined: Mon Dec 24, 2012 4:32 pm

Re: Is there a way to re-route pin 7 in code on the motor shield?

Post by allanonmage »

After getting a reply on the arduino forum, I realize I haven't been as clear as I could have been describing what I would like help with:
Quote from: dc42 on Today at 06:08:45 PM ****on the arduino forum***
What you will need to do is:

1. Break the connection from the motor shield to digital pin 7 of the Arduino. The easiest way to do this is to cut off that pin on the bottom of the motor shield.

2. Connect that pin on the motor shield to an unused pin, for example pin 13 or one of the analog pins. You can do this by connecting a jumper between pin 7 and your chosen pin on the top of the motor shield.

3. Modify the motor shield software to redefine MOTORENABLE as your chosen replacement pin.
Yes, my thoughts exactly. I'm asking for help on part 3. Sorry if I didn't make that clear. I'm not convinced it's as simple as changing it in that one place... that seems too easy. FYI my guardian angle is some kind of cross between Murphy (of Murphy's law) and a giant sky-being with a giant magnifying glass with the light focused on me.

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Is there a way to re-route pin 7 in code on the motor shield?

Post by adafruit_support_bill »

What you have is a counterfeit board. You should demand a refund from Amazon as it is clearly not as advertised.

All our designs are open source and you are free to use them according to the terms of the Creative Commons license. We provide technical support to customers of our kits. We do not support clones and counterfeits.

allanonmage
 
Posts: 19
Joined: Mon Dec 24, 2012 4:32 pm

Re: Is there a way to re-route pin 7 in code on the motor shield?

Post by allanonmage »

I was able to accomplish what I was looking for with help from the arduino forum. By keeping this post up to date I am making sure the next guy or gal has info to go about making things work.
See the whole thread:
http://arduino.cc/forum/index.php/topic,138979.0.html

Success!! Thanks for your help dc42!! ((arduino forum member))

I flipped the pin for 7 upside down, changed that one value assignment, and ran a new wire and the sample code works!

Before I did this I tested the board on an arduino uno since I did hear back from the guy on amazon and he said sometimes the chips come fried. It worked pretty good on the uno, better than with the shield being stock on the mega adk.

The first pic is the stack of boards in the roomba bay, the second is just the flipped pin with a wire coming off of it. I pulled out a wire from an old CDROM audio cable. Guess I need some female to male jumpers in my kit now, eh?
What you have is a counterfeit board. You should demand a refund from Amazon as it is clearly not as advertised.
OK, that's reasonable advice I guess, given your position that has not changed since I joined the board. Not very useful mind you, but reasonable.
All our designs are open source and you are free to use them according to the terms of the Creative Commons license.
If it's open source, how can a "counterfeit" exist? That's an awfully strong word for this case.
We provide technical support to customers of our kits. We do not support clones and counterfeits.
That's understandable. You've also mentioned that like 5 times now too.

What I would have preferred to see from a moderator/tech support person was help up to the point that it was obvious that the kit was defective. In this case, it didn't matter whose hardware I had, or even that I *had* hardware; I had a software question and needed help figuring out how to use the library that Adafruit puts out.

Yes I understand the business side of things from Adafruit's point of view. I won't go into detail but I get it.

However, now that I've tasted adafruits tech support and forums, I have somewhere between 0 and negative desire to go buy adafruit stuff. So you maynot have "wasted time" supporting someone else's product, but unless somehow you guys do backflips in customer service, I won't buy anything adafruit unless I have too, and I will certainly repeat this story to anyone who will listen.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Is there a way to re-route pin 7 in code on the motor shield?

Post by adafruit »

the seller is claiming to be "adafruit" and selling boards with our name, it's rare but happens.

we will work with amazon to do our best to get them removed (open source is sharing designs, not using other's names/doing business as). we did our best over christmas eve and christmas day to assist you (18 posts) as we noted, we cannot provide support for counterfeit goods - please let the seller know, and report them to amazon to get a refund. most of all, so this does not happen to someone else.

we realize this is not your fault at all or ours, and if you cannot get a refund please let us know and we'll do what we can as well.

since you "did hear back from the guy on amazon and he said sometimes the chips come fried" - please send along their contact information so we can assist amazon resolving this and getting the products removed.

we are locking the topic(s) for now. we've received your email, we'd appreciate if you left out the cursing, but we do value the feedback and will always do our best to improve, even in situations like this.

thank you,
adafruit support

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”