Stepper Powered Tank - Please Help

Hello,

I am very new to coding and have thrown myself well into the deep end for a school project I need completed in a few weeks. The project is to design in CAD, 3D print and construct a scale rc tank that will eventually be line following.

I am struggling to get accelstepper and blynk to work together this is the hardware I am trying to use:

Arduino Uno
HC-06
4 x nema 23 steppers
4 x t6600 stepper drivers

I have spent the last three days trying to get everything to work together but it just isn't working and I can't find any examples that solve all of my problems without some issue. Here is some code I tried adapting could someone please tell me anything I forgot or need to change. Thank you so much in advance.

#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>

#include <AccelStepper.h>
#include <MultiStepper.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "LxY-KW2kIcoCYMXmEoTS2MjVTR5VhDWc";

// Select which 'port' M1, M2, M3 or M4.
//Adafruit_DCMotor *motor1 = AFMS.getMotor(1);
//Adafruit_DCMotor *motor2 = AFMS.getMotor(2);
//Adafruit_DCMotor *motor3 = AFMS.getMotor(3);
//Adafruit_DCMotor *motor4 = AFMS.getMotor(4);

AccelStepper stepper1(AccelStepper::DRIVER, 2, 3);
AccelStepper stepper2(AccelStepper::DRIVER, 4, 5);
AccelStepper stepper3(AccelStepper::DRIVER, 6, 7);
AccelStepper stepper4(AccelStepper::DRIVER, 8, 9);

//######### SETUP ######################################
void setup() {
// Debug console
DebugSerial.begin(9600);

DebugSerial.println("Waiting for connections...");

// 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);
}

//########## LOOP ######################################
void loop() {
Blynk.run();
}

//######### Subrutines ################################

// This function will set the speed
BLYNK_WRITE(V0)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
Serial.print("V0 Slider value is: ");
Serial.println(pinValue);
stepper1.setSpeed(pinValue);
stepper2.setSpeed(pinValue);
stepper3.setSpeed(pinValue);
stepper4.setSpeed(pinValue);
}

// Motor 1 Forward
BLYNK_WRITE(V1)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
Serial.print("Motor 1 Forward: ");
Serial.println(pinValue);
if (pinValue == 1) {
stepper1.moveTo(1);
stepper3.moveTo(1);
}
if (pinValue == 0) {
stepper1.stop();
stepper3.stop();
}
}

// Motor 2 Forward
BLYNK_WRITE(V2)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
Serial.print("Motor 2 Forward: ");
Serial.println(pinValue);
if (pinValue == 1) {
stepper2.moveTo(1);
stepper4.moveTo(1);
}
if (pinValue == 0) {
stepper2.stop();
stepper4.stop();
}
}

// Motor 1 Backward
BLYNK_WRITE(V3)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
Serial.print("Motor 1 Backward: ");
Serial.println(pinValue);
if (pinValue == 1) {
stepper1.moveTo(-1);
stepper3.moveTo(-1);
}
if (pinValue == 0) {
stepper1.stop();
stepper3.stop();
}
}

// Motor 2 Backward
BLYNK_WRITE(V4)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
Serial.print("Motor 2 Backward: ");
Serial.println(pinValue);
if (pinValue == 1) {
stepper2.moveTo(-1);
stepper4.moveTo(-1);
}
if (pinValue == 0) {
stepper2.stop();
stepper4.stop();
}
}

You will get more help if you follow the forum guidelines as described in the how to get the best from the forum post..

Start by going back and putting your code in code tags.

That conveys no useful information. What does the code actually do? How is that different from what you want.

It makes no sense to use SoftwareSerial on the hardware serial pins.

Thank so very much for your reply. I havent posted on this forum before so thank you for the advice. I am not actually sure whether this code works or not (I am going to try it tonight) but wanted to ask if anyone sees obvious issues with it.

What should I use instead?

Thanks

Hardware serial, obviously. i.e. the Serial object.

Incidentally why use steppers for traction? They are about the least efficient motor its possible to have so will have a massive impact on battery life compared to the standard gearmotor+encoder used in wheeled robots everywhere.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.