I’ve a project which needs a motor shield to drive 4 DC motors. I’m using the Adafrut Motor Shield (http://www.adafruit.com/products/81) which is then connected to the SparkCore via the Spark Core “Shield Shield”.
A quick look reveals they are using 4 PWM’s for the Adjustable Frequency Motor output (1 for each motor), 2 PWM’s for servos, and reusing the 4 PWM’s for stepper control, along with some I/O for shifting data to relay’s for direction control on the motors.
You would need to port the library by combining the .h and .cpp files all together with your application.cpp (the sketch), and put that into the Sparkulator (Spark Build, aka Cloud IDE, aka Web IDE aka Spark IDE). This would be possible!
This, coupled with a bunch of chopping to the #defines AVR / PIC32 / etc… and the library should be working.
That said, you need the pins that have this hardware functionality to couple to the pins of the shield that need that functionality. Since the Core has more PWM’s than the Arduino, you should be in good shape, just need to check.
If you want to take a stab at it… please do! Otherwise I could try to port it maybe this weekend. Wish I had a motor shield though to test it
@BDub, you must already know this, but you are awesome. A giant high-five from the Spark team in China (and everywhere, I’m sure) for being so active and helpful on the community.
Thanks @will for the kind words! I envision the Spark Core as being the next big thing since Arduino or Raspberry Pi, and to make that happen a thriving community is a very integral part of the equation! Doing what I can to help it along
Wooh BDub! Seriously awesome. People like you make communities like this flourish
I’m going to have a go at what you’ve suggested over the weekend… and I’d also like to shout you a few motor shields if you feel included to do some testing - let me know the easily way for me to do this
Just a shout out to @BDub for his awesome work on this, he’s managed to port the Adafruit library so we can use these motor shields (which you can buy clones of via ebay for around $6). If you see him in person be sure to shout him a beer, and make sure your Sparkcore robot armies remember who their creator is
Hey @BDub, I’m trying to get this working in the web ide, and I keep getting compile errors. I created two new files in the ide for the project named Spark_MotorShield_V1.h and Spark_MotorShield_V1.cpp and pasted the contents from your github files into them. Then I pasted the contents from the example into the main app file. Compiling produces the following errors:
the_user_app.cpp:65:1: error: 'AF_DCMotor' does not name a type
the_user_app.cpp:66:1: error: 'AF_DCMotor' does not name a type
the_user_app.cpp:67:1: error: 'AF_DCMotor' does not name a type
the_user_app.cpp:68:1: error: 'AF_DCMotor' does not name a type
the_user_app.cpp: In function 'void setup()':
the_user_app.cpp:78:3: error: 'motor1' was not declared in this scope
the_user_app.cpp:79:3: error: 'motor2' was not declared in this scope
the_user_app.cpp:80:3: error: 'motor3' was not declared in this scope
the_user_app.cpp:81:3: error: 'motor4' was not declared in this scope
So I thought maybe I needed a
#include "Spark_MotorShield_V1.h"
at the top of my main file, but then I get the following errors:
the_user_app.o: In function `setup':
/spark/compile_server/shared/workspace/worker_1/core-firmware/build/the_user_app.cpp:79: multiple definition of `TIM4_ARR'
Spark_MotorShield_V1.o:(.bss+0x6): first defined here
the_user_app.o: In function `setup':
/spark/compile_server/shared/workspace/worker_1/core-firmware/build/the_user_app.cpp:79: multiple definition of `TIM3_ARR'
Spark_MotorShield_V1.o:(.bss+0x4): first defined here
the_user_app.o: In function `setup':
/spark/compile_server/shared/workspace/worker_1/core-firmware/build/the_user_app.cpp:79: multiple definition of `TIM2_ARR'
Spark_MotorShield_V1.o:(.bss+0x2): first defined here
the_user_app.o: In function `setup':
/spark/compile_server/shared/workspace/worker_1/core-firmware/build/the_user_app.cpp:80: multiple definition of `TIM1_ARR'
Spark_MotorShield_V1.o:(.bss+0x0): first defined here
the_user_app.o:(.data+0x2): multiple definition of `TIM_ARR'
Spark_MotorShield_V1.o:(.data+0x12): first defined here
the_user_app.o: In function `setup':
/spark/compile_server/shared/workspace/worker_1/core-firmware/build/the_user_app.cpp:80: multiple definition of `TIM_OCInitStructure'
Spark_MotorShield_V1.o:(.bss+0xa): first defined here
collect2: error: ld returned 1 exit status
make: *** [49b1ca310b0760fa9000e04d4f91c25eb3a819a999d3c8aa54dbaa4fc526.elf] Error 1
Bah, yes I know exactly why that happens! I had the same problem when I tested it in the web IDE… and fixed it. But I guess it never made it back to my source files before I pushed them to github.
Check my latest commit for the fix! Thanks for trying this out
And you will need "#include “Spark_MotorShield_V1.h” in your application.cpp