Hello, I am trying to make an elevator, using a tmc 2208 v3, two nema 17 stepper motors, and using the nut and leadscrew method to lift an platform up.
I am using a 600 p/r incremental rotary encoder and coded it so when I move the encoder clockwise and anticlockwise the motor move in that direction.
The problem that I am having is, the microcontroller atmega328p works perfectly when its on the Arduino board, with no hassle etc, but I want to move it on a breadboard, so that I am able to use one power source. I also do not want an Arduino board in my final PCB board.
How the power moves:
I am using a wall plug, 3.5mm Barrell outputting 12v @ 2A
That is connected to a 12v DC module. and that module is connected to a buck converter (12v to 5v) 12v power rail is connected to the motor. the 12v power module is also connected to the 5v buck converter. The power output of the 5v is connected to the rotary encoder, microcontroller and the tmc 2208 VCC pin.
I have followed https://docs.arduino.cc/built-in-examples/arduino-isp/ArduinoToBreadboard/ to move the Arduino to a breadboard. The microcontroller does seem to work. It just that the problem is (when moved anticlockwise) it starts squeaking, and doesn't move accordingly like when I move it clockwise.
Note: Without changing anything on the code, pins, etc moving the microcontroller back on the Arduino board works perfectly. Could be a insufficient current issue, as In the case of moving it back on the Arduino I am powering the microcontroller using usb.
#include <AccelStepper.h>
AccelStepper stepper(1, 5, 4); // Stepper motor 1: pulses Digital 5; Direction Digital 4 (CCW)
AccelStepper stepper2(1, 12, 13); // Stepper motor 2: pulses Digital 12; Direction Digital 13 (CCW)
// Defining pins for the rotary encoder
const int RotaryCLK = 8; // CLK pin on the rotary encoder (IRE = WHITE = A)
const int RotaryDT = 9; // DT pin on the rotary encoder (IRE = GREEN = B)
const int RotarySW = 2; // SW pin on the rotary encoder (Button function)
// Defining variables
int stepsPerPulse = 500; // Increase steps per pulse for larger movements
int maxSpeed = 10000; // Increase max speed (steps per second) for faster movement
// Variables to track encoder states
int CLKState;
int DTState;
int lastCLKState;
int lastDTState;
// Speed and position variables
long currentPosition = 0; // Current position of the stepper motors
void setup() {
Serial.begin(9600);
pinMode(RotaryCLK, INPUT_PULLUP);
pinMode(RotaryDT, INPUT_PULLUP);
stepper.setMaxSpeed(1000000);
stepper.setAcceleration(100000);
stepper2.setMaxSpeed(1000000);
stepper2.setAcceleration(100000);
lastCLKState = digitalRead(RotaryCLK);
lastDTState = digitalRead(RotaryDT);
}
void loop() {
// Read encoder states
CLKState = digitalRead(RotaryCLK);
DTState = digitalRead(RotaryDT);
// Check for rotation
if (CLKState != lastCLKState)
{
if (DTState != CLKState)
{
// Clockwise rotation
stepper.setSpeed(maxSpeed);
stepper2.setSpeed(maxSpeed);
currentPosition += stepsPerPulse;
}
else
{
// Counter-clockwise rotation
stepper.setSpeed(-maxSpeed);
stepper2.setSpeed(-maxSpeed);
currentPosition -= stepsPerPulse;
}
}
else {
// No rotation, stop motors
stepper.setSpeed(0);
stepper2.setSpeed(0);
}
// Update last state for next loop iteration
lastCLKState = CLKState;
// Run the motors
stepper.runSpeed();
stepper2.runSpeed();
}
Any advice would be perfect. as I have no idea what is going on.