Controlling Arduino Motor Shield R3 with Spark Core

I am trying to run a motor shield without the shield shield with a spark core. I got an Arduino to run the motor shield using this code :

int a = 12;
int abrake = 9;
int aspeed = 3;

void setup()
{
  // Initialize D0 pin as output
  pinMode(a, OUTPUT);
  pinMode(abrake, OUTPUT);
}

// This routine loops forever
void loop()
{
  digitalWrite(a, HIGH);
  digitalWrite(abrake, LOW);
  analogWrite(aspeed, 225);
}

I then wiped the arduino so it wasn’t running any code but was powering the shield. Then I tried to use a spark core to control the motor shield.

I hooked

D0 -> 12

D1 -> 9

D0 -> 3

And used this code :

int a = D0;
int abrake = D1;
int aspeed = D2;

void setup()
{
  // Initialize D0 pin as output
  pinMode(a, OUTPUT);
  pinMode(abrake, OUTPUT);
}

// This routine loops forever
void loop()
{
  digitalWrite(a, HIGH);
  digitalWrite(abrake, LOW);
  analogWrite(aspeed, 225);
}

My wiring :


Is this way even possible? Am i doing something wrong? Is there an easier solution?

So what is powering the Spark core in your setup? I don’t see any USB or other power connections to your core, just the data connections. Does the main Spark LED light up at all?

You should be able to use the Arduino Motor Shield without the Arduino – it has a separate power input for the motor and the logic, you just need to connection both as well as the data connections to the Spark pins.

The spark core is powered by USB into my computer and code can be successfully flashed to it. I also tried hooking up a 9v into the motor shield and it didn’t change the outcome. Is there something wrong with my code or wiring?

In your second to last photo above, there is nothing powering the Spark core. If you are connecting the USB cable when you run that is fine, but as shown, I can’t see how the Spark core is getting power. You don’t have a USB plugged in and you don’t have anything on the VIN and GND pins to supply +5V to core.

When I tried to run it the spark core was powered by the USB in the computer along with the arduino which was also plugged into the computer. I just happened to not have it in when I took the photo. Sorry bout that.

OK – how about a common ground connection between them? I would not depend on ground going back to the PC to be connected between the parts of your system. Should be easy to try, just jump Spark GND to Arduino GND.

Just tried, same result. Should this theoretically work?

Hi @xebex

Yes this should work, but I would disconnect the UNO from the motor shield–you don’t need it and it can only hurt things. Best bet would be motor shield and Spark with clear power wiring and test it by taking the wires you are controlling with the core and tying them high/low as needed to get the motor to run. Until it works without the core, you can’t really begin to test the software.

It is possible you might need a 3v–>5v logic level converter but I didn’t think so when I looked at the motor shield schematic briefly. Maybe someone with more experience with that shield in a 3.3V environment can comment.

I still think the problem is in your wiring since the software side is so simple.

I ended up getting a Shield Shield and here is a simple program to run motors with the arduino motor shield r3

void setup() {
  
  //Setup Channel A
  pinMode(A4, OUTPUT); //Initiates Motor Channel A pin
  pinMode(D6, OUTPUT); //Initiates Brake Channel A pin
  pinMode(D0, OUTPUT); //Iitiates PWM Channel A pin
  
  //Setup Channel B
  pinMode(A3, OUTPUT); //Initiates Motor Channel A pin
  pinMode(D5, OUTPUT); //Initiates Brake Channel A pin
  pinMode(A5, OUTPUT); //Iitiates PWM Channel A pin
}

void loop(){
  
  //forward at full speed
  digitalWrite(A4, HIGH); //Establishes forward direction of Channel A
  digitalWrite(D6, LOW);   //Disengage the Brake for Channel A
  analogWrite(D0, 225);   //Spins the motor on Channel A at 
  
  
  // B
  digitalWrite(A3, HIGH); //Establishes forward direction of Channel A
  digitalWrite(D5, LOW);   //Disengage the Brake for Channel A
  analogWrite(A5, 225);   //Spins the motor on Channel A at
  
  
  delay(3000);
  
  //Backwards at half speed
  
  digitalWrite(A4, LOW); //Establishes forward direction of Channel A
  digitalWrite(D6, LOW);   //Disengage the Brake for Channel A
  analogWrite(D0, 112);
  
  // B
  digitalWrite(A3, LOW); //Establishes forward direction of Channel A
  digitalWrite(D5, LOW);   //Disengage the Brake for Channel A
  analogWrite(A5, 112);   //Spins the motor on Channel A at
  
  delay(3000);
}