I am using Arduino uno wifi to control 2 dc motors. i am using 2 Vex 6wire encoders for motor speed and direction. i was trying to use the Blynk app to monitor those encoders for motor speed. i am using a motor driver. if i include Blynk.begin under void setup with the pinModes the motors dont spin but if i remove the Blynk. begin the motors move. here is my code.
#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);
}
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);
}