How to connect to Arduino Adafruit Motor Shield v2.3 in Embed for DC motor control
I am trying to figure out how to connect to the Arduino Adafruit Motor Shield v2.3 in Embed. I think this can be done through an "Extern Definition" block, but I'm having trouble figuring out how this works exactly. I want to be able to control the speed of the motor and start/stop it within an Embed program with real-time communication (target interface).
The arduino IDE code works fine for controlling this DC motor (pump) https://www.adafruit.com/product/3910?gclid=CjwKCAjwv8qkBhAnEiwAkY-ahgqUj49YKtkMp8jH2lJlxgONtRuHkpO-wr6ib4FphCpDM7MUROdV-RoCTYYQAvD_BwE
via this board: https://www.adafruit.com/product/1438
with this Arduino example code: DC Motor Test
/*
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control
*/
#include <Adafruit_MotorShield.h>
// 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);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Adafruit Motorshield v2 - DC Motor test!");
if (!AFMS.begin()) { // create with the default frequency 1.6KHz
// if (!AFMS.begin(1000)) { // OR with a different frequency, say 1KHz
Serial.println("Could not find Motor Shield. Check wiring.");
while (1);
}
Serial.println("Motor Shield found.");
// Set the speed to start, from 0 (off) to 255 (max speed)
myMotor->setSpeed(150);
myMotor->run(FORWARD);
// turn on motor
myMotor->run(RELEASE);
}
void loop() {
uint8_t i;
Serial.print("tick");
myMotor->run(FORWARD);
for (i=0; i<255; i++) {
myMotor->setSpeed(i);
delay(10);
}
for (i=255; i!=0; i--) {
myMotor->setSpeed(i);
delay(10);
}
Serial.print("tock");
myMotor->run(BACKWARD);
for (i=0; i<255; i++) {
myMotor->setSpeed(i);
delay(10);
}
for (i=255; i!=0; i--) {
myMotor->setSpeed(i);
delay(10);
}
Serial.print("tech");
myMotor->run(RELEASE);
delay(1000);
}
(I don't need most of that example code, mainly just including the library, specifying the port to connect to the motor, setting the speed and running the motor in one direction. I'm not sure how the syntax is supposed to change between Arduino IDE code and the Embed Extern definition block, or whether one of the other Extern blocks is needed for the set speed / run motor commands, since the motor shield has its own PWM commands...)