Hello,
I have some problems when using Blynk and the Adafruit Motorshield V2.3 on my Arduino Uno R3. I have a HC-05 Bluetooth module to work with Blynk and a stepper motor attached to the Motorshield. I can control the on-board LED via the Blynk app and I can get the stepper motor to rotate when running the test program from Adafruit, however, when I try to combine both so I can control the stepper motor using Bluetooth on my cellphone the motor won’t turn anymore, while I am still able to control the LED.
// BLUETOOTH/BLYNK STUFF #################################
#define BLYNK_USE_DIRECT_CONNECT
// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(0, 1); // RX, TX
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleSerialBLE.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "auth_code";
// ADAFRUIT MOTORSHIELD STUFF ###############################
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.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);
// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
void setup()
{
// Debug console
DebugSerial.begin(9600);
// Blynk will work through Serial
// 9600 is for HC-06. For HC-05 default speed is 38400
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
AFMS.begin(); // create with the default frequency 1.6KHz
myMotor->setSpeed(10); // 10 rpm
}
BLYNK_WRITE(V1)
{
int pinValue = param.asInt();
if(pinValue == 1)
{
myMotor->step(35, FORWARD, SINGLE); //It wont rotate the stepper
myMotor->release();
digitalWrite(13, pinValue); //It will execute this line, the LED is on
}else
{
// myMotor->release();
digitalWrite(13, pinValue);
}
}
void loop()
{
// myMotor->step(100, FORWARD, SINGLE);
// myMotor->step(100, BACKWARD, SINGLE);
Blynk.run();
}
When commenting out the Blynk.begin(Serial, auth) the two lines in void loop() suddenly start working again…
Thanks in advance