I am Building a robot and I'm trying to run two dc motors with Vex 6 wire encoders to monitors speed and direction of the wheels. I am trying to use blynk to monitor those encoders wired correctly. however the code uploads but the motors wont spin. but when i remove the Blynk.begin(auth,ssid,pass) from the code the motors spin. no matter what i do for some reason adding the Blynk causes the motors to not turn. please help. Here is my full code. yes i am using a motor driver.
#define BLYNK_TEMPLATE_ID "*****"
#define BLYNK_TEMPLATE_NAME "********"
#define BLYNK_AUTH_TOKEN "********"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#define APP_DEBUG
#include <BlynkSimpleWiFiNINA.h>
#include <Encoder.h>
// Motor pins
int motor1EnablePin = 3; // Enable motor 1
int motor1DirectionPin1 = 8; // INT1
int motor1DirectionPin2 = 7; // INT2
int motor2EnablePin = 5; // Enable motor 2
int motor2DirectionPin1 = 2; // INT3
int motor2DirectionPin2 = 4; // INT4
// Encoder pins
Encoder encoder1(11, 12); // Encoder 1 connected to pins 11 and 12; left encoder
Encoder encoder2(10, 13); // Encoder 2 connected to pins 10 and 13; right encoder
// Constants for wheel size and encoder resolution
const float wheelDiameterInches = 4.0; // Diameter of the wheel in inches
const float encoderResolution = 90.0; // Pulses per revolution of the encoder
char auth[] = "*******"; // Replace with your Blynk authentication token
char ssid[] = "*****";
char pass[] = "*******";
void setup()
{
pinMode(motor1EnablePin, OUTPUT);
pinMode(motor1DirectionPin1, OUTPUT);
pinMode(motor1DirectionPin2, OUTPUT);
pinMode(motor2EnablePin, OUTPUT);
pinMode(motor2DirectionPin1, OUTPUT);
pinMode(motor2DirectionPin2, OUTPUT);
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run();
// Set the direction and speed of both motors
digitalWrite(motor1DirectionPin1, HIGH);
digitalWrite(motor1DirectionPin2, LOW);
digitalWrite(motor2DirectionPin1, HIGH);
digitalWrite(motor2DirectionPin2, LOW);
// Set the motor speed (PWM value between 0 and 255)
analogWrite(motor1EnablePin, 128); // Adjust this value for desired speed
analogWrite(motor2EnablePin, 128); // Adjust this value for desired speed
// Read encoder counts
long count1 = encoder1.read();
long count2 = encoder2.read();
// Calculate wheel speed in MPH
float wheelCircumferenceInches = PI * wheelDiameterInches;
float wheelSpeedMPH1 = (count1 / encoderResolution) * wheelCircumferenceInches / 63360.0 * 3600.0;
float wheelSpeedMPH2 = (count2 / encoderResolution) * wheelCircumferenceInches / 63360.0 * 3600.0;
// Send wheel speed to Blynk
Blynk.virtualWrite(V1, wheelSpeedMPH1); // Virtual pin V1 for left wheel speed in MPH
Blynk.virtualWrite(V2, wheelSpeedMPH2); // Virtual pin V2 for right wheel speed in MPH
delay(100); // Adjust the delay as needed
}