Hello
Wonder if anyone can help with this as an apparently simple task is driving me mad!
I’m trying to control a Cytron MDDS60 24v motor driver from a Blynk joystick using a NodeMCU, but just cannot get it working.
I have confirmed that the hardware is all good by running the following test sketch on the NodeMCU:
* This example shows how to control MDDS60 in PWM mode with Arduino.
* Set MDDS60 input mode to 0b10110100
*
* Reference Tutorial:
* - Let's Arduino Controlling Your SmartDriveDuo-60
*
* - SmartDriveDuo-60:
*
* URL: http://www.cytron.com.my
*/
int DIG1 = 0; // Arduino pin 3 is connected to MDDS60 pin DIG1.
int AN1 = 12; // Arduino pin 6 is connected to MDDS60 pin AN1.
void setup()
{
pinMode(DIG1, OUTPUT); // Set Arduino pin 7 (DIG1) as output.
pinMode(AN1, OUTPUT); // Set Arduino pin 6 (AN1) as output.
delay(5000); // Delay for 5 seconds.
}
void loop()
{
// Controlling motor 1.
analogWrite(AN1, 100); // Set motor 1 speed less than half. Max is 255.
digitalWrite(DIG1, LOW); // Motor 1 start moving for 2s.
delay(2000);
digitalWrite(DIG1, HIGH); // Motor 1 move to another direction for 2s.
delay(2000);
analogWrite(AN1, 0); // Stop motor 1.
delay(1000); // Delay for 1s
// Controlling motor 2.
}
This works, the motor moves forward and backwards, pausing between movements.
However, when I upload the following sketch, nothing happens. Working with a joystick widget on pin V1, I can see output in Serial Monitor so the app is working, the pins are connected correctly as the previous sketch proves, but the motor simply will not move.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "Auth Key";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "MY_SSID";
char pass[] = "Network Password";
int DIG1 = 0;
int AN1 = 12;
BLYNK_WRITE(V1){
int y = param[1].asInt();
Serial.print(y);
if ( y > 700 ){
analogWrite(AN1, 200);
digitalWrite(DIG1, LOW);
}
else if ( y < 500 ) {
analogWrite(AN1, 200);
digitalWrite(DIG1, HIGH);
}
else {
analogWrite(AN1, 200);
}
}
void setup() {
Serial.begin(9600);
pinMode(DIG1, OUTPUT);
pinMode(AN1, OUTPUT);
Blynk.begin(auth, ssid, pass);
}
void loop() {
// put your main code here, to run repeatedly:
Blynk.run();
}