Tonight I got my v2 adafruit motor shield. After soldering on the pins and hooking up a stepper, I tested it with a regular arduino. Works great.
I ported the library last week and got it compiling, but it’s turning out not to be as simple to get working on the spark core as plugging it into the shield shield. I noticed that the motor shield expects i2c SDA to be on pin A4 and SCL to be on pin A5, but the sparkcore’s SDA and SCL is on D0 and D1 respectively. (A4 and A5 are not even connected on the shield-shield) So I ran a jumper wire between A4->D0 and A5->D1.
Still no dice. I’m not sure if the spark core is even finding the i2c device. I’ve been digging through the adafruit library code tonight trying to see if I noticed anything.
I’m starting to think this is a good opportunity to finally purchase a good logic analyzer so I can see what’s going on.
I’ll keep messing with it and post my progress here as I go. Any suggestions are welcome.
I was totally going to mention this little SNAFU... but you know how things go.
I've had a lot of trouble with the Shield Shield and high speed signals and longer wires. It tends to oscillate at 50MHz instead of clocking through the various signals that you would expect.
Try this... plug the Spark Core into the breadboard, and run jumpers over to the motor shield pins. Hopefully you have some of those female to male jumpers. Or if you are lucky the shield came with stackable headers with the female tops. Check to make sure the shield has pull up resistors on the A4, A5 lines. GND to GND and you can initially try powering the shield VIN or 5V... from the spark's VIN. Just don't load it down too hard. The I2C lines are 5V tolerant if you want to pull up the lines to VIN.
@BDub, I second that approach and the motor shield already has pull-ups to +5V.
@Hypnopompia, I got a kickstarter logic analyzer from DSLogic but the software is not ready for prime time yet. They are working on it and at $89 it was a small risk. It may be worth investing in a Saleae analyzer at some point.
Sorry to bother everyone for something that is
probably stupid, but I am a newbie and I’m trying to learn. So I’m
using the adafruit motor shield v2 with the spark > arduino shield shield
and a 12v power supply.
I’m using the example code and I can’t seem to get the motor to do
anything. Any thoughts? I have the motor connected to M1 and I have
tested the motor, it works fine.
#include "application.h"
#include "Adafruit-MotorShield-V2/Adafruit-MotorShield-V2.h"
#include "Adafruit-MotorShield-V2/Adafruit_PWMServoDriver.h"
/*
Visit the following url for help on connecting the motor shield
to the spark core:
https://community.spark.io/t/adafruit-motor-shield-v2-progress/5218
*/
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);
// You can also make a stepper motor on M1/M2
//Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Adafruit Motorshield v2 - DC Motor test!");
AFMS.begin(); // create with the default frequency 1.6KHz
myMotor->setSpeed(100);
}
void loop() {
myMotor->run(FORWARD);
Serial.print("Run");
delay(1000);
}
@james211, if you read carefully the first few entries in this topic, @Hypnopompia discusses the need for adding jumpers between the shield-shield and the Motor shield for it to work. Have you done this?
@james211, @peekay123 I actually was only able to get it working by not using the shield-shield at all and running jumper wires from the spark to the motor shield like i mentioned above.
Edit: I just made a quick youtube video on how to hook it up. Hopefully this helps.
(I called it one-wire, but it’s actually I2C - sorry)
Ahh…Well isn’t that a bugger! When I initially read I was thinking he just didn’t have a shield shield - now that I read that again it makes sense. Maybe you can provide some insight then. I’m looking for an additional option for my project,
I want to post a DIY on a couple of reef aquarium forums so people can build these dosers themselves, but I want to give them the option of using a less expensive 12v dosing pump vs the more expensive 115VAC dosing pumps. The advantage of the 12v is the PWM control. With that information, do you have any suggestions?
@james211, Pololu make some great motor driver “carriers” that would work nicely I believe. Or you could use discreet FET transistors and drive the pumps that way.
Hey @peekay123, I appreciate the recommendations. This is where I get scared though. I know nothing about the programming aspects so for me to dive into a shield that has not been ported to spark freaks me out. If there is no simple solution I can wait it out. I just figured if I could use PWM to control the speed of the doser that would be an added benefit.
@james, those breakouts are super easy to use and I can help you with the software! Otherwise, you could use FET drivers for each motor like this set on eBay and control them right off the Spark with PWM!
@Hypnopompia have you found any instability in the I2C connection? I find the data drops out as the motor ramps up even though I’ve given the Spark it’s own USB power from the motor shield.
I’m curious why the 5V line on the motor shield goes to the VIN on the Spark. Don’t they just need to share a ground?
Cant get motors working. I have the spark core plugged in to the motor shield the same way as in the video and have a 9v battery hooked up to the shield. I used the code :
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Select which ‘port’ M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);
// You can also make a stepper motor on M1/M2
//Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println(“Adafruit Motorshield v2 - DC Motor test!”);
AFMS.begin(); // create with the default frequency 1.6KHz
myMotor->setSpeed(100);
}
void loop() {
myMotor->run(FORWARD);
Serial.print(“Run”);
delay(1000);
}
And nothing happens. On the core neither D0 or D1 are showing any changes in voltage. On the motor shield m1 isn’t showing any change in voltage either. However, the shield is getting proper power. Not sure if this would b a hardware or code problem. Thanks in advance, Jonathan
@Hypnopompia, thanks for the great post as this video solved an issue I was having trying to use the shield shield with the Adafruit Motor Shield v2. However I then discovered something a little odd. When I run the following code the wheels do not turn in predictable fashion. The start off going back and forward OK then just seem to stray and do what ever they want. I was wondering if you had seen anything similar in your experiences with the spark core and motor shields?
Anyway any thoughts on this would be great, oh and here is my code…
#include "application.h"
#include "Adafruit-MotorShield-V2/Adafruit-MotorShield-V2.h"
#include "Adafruit-MotorShield-V2/Adafruit_PWMServoDriver.h"
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *leftMotor = AFMS.getMotor(1);
Adafruit_DCMotor *rightMotor = AFMS.getMotor(2);
int speed = 100;
String direction = "STOP";
void setup() {
Serial.begin(9600);
Serial.println("Adafruit Motorshield v2 - DC Motor test!");
AFMS.begin();
leftMotor->setSpeed(100);
rightMotor->setSpeed(100);
}
void loop() {
leftMotor->run(FORWARD);
rightMotor->run(BACKWARD);
delay(1000);
leftMotor->run(BACKWARD);
rightMotor->run(FORWARD);
delay(1000);
}
Has anyone tried to use this code with the Photon instead of the Spark Core. I am trying to get this running using the Photon and am not having any success. Could someone please offer some advice? I really need this to work :’(
Hi, I am experiencing an even weirder issue - loading the sample code crashes the core and I have to factor reset it. Has anyone come across this problem?