Im trying to get a stepper to run a partial section using a UNO , TMC2208, 2 sensors, 1 to confirm posit , second as a trigger. Got som code of the nett. However the online Arduino EDI give a error. Code below. Line 29 '' driverX.begin(); //function initializes the TMC2208 driver'', error: 'class TMC2208Stepper' has no member named 'begin'. Could be more. Can som one help an old man solvin this or suggeting a new code. Thx /Matt
#include <TMC2208Stepper.h>
#include <Stream.h>
#include <SPI.h>
#define DRIVER_ADDRESS 0b00 // TMC2209 Driver address
#define R_SENSE 0.11f // BIGTREETECH 110mOhm
// Define the stepper motor parameters
const int stepsPerRevolution = 200; // Number of steps per motor revolution
TMC2208Stepper driverX(&Serial, R_SENSE, DRIVER_ADDRESS);
// Define the motor object
// Define the trigger sensor pin
const int triggerPin = 2;
// Define the start position sensor pin
const int startPositionPin = 6;
// Define the rotation parameters
const int partialRotationSteps = 30; // Number of steps for partial rotation
const int returnDelay = 2000; // Delay after partial rotation (in milliseconds)
// Variable to store the start position status
bool isStartPosition = false;
void setup() {
Serial.begin(115200);
driverX.begin(); //function initializes the TMC2208 driver
driverX.toff(4); // (Off Time): It is the time when the signal remains low within a period of time
// Set the trigger pin as an input
pinMode(triggerPin, INPUT);
// Set the start position pin as an input
pinMode(startPositionPin, INPUT_PULLUP);
// Set the motor speed (in RPM)
driverX.rampSpeed(20); // Change this value to adjust the motor speed
}
void loop() {
// Read the state of the trigger sensor
int triggerState = digitalRead(triggerPin);
// If the trigger is activated and the motor is in the start position, rotate the motor partially and then return
if (triggerState == HIGH && isStartPosition) {
// Rotate the motor for a partial rotation
driverX.relativeMove(partialRotationSteps);
// Delay after partial rotation
delay(returnDelay);
// Rotate the motor back to the initial position
driverX.relativeMove(-partialRotationSteps);
}
// Check the start position sensor
if (digitalRead(startPositionPin) == LOW) {
isStartPosition = true;
} else {
isStartPosition = false;
}
It seems the stepper library on your computer does not have a begin() function.
Best is to start from an example. Usually those are included with the library.
Test only the stepper motor using such an example...
Code from the net might be wrong or using a different version of the library...
➜ Edit your post using the in the tool bar just below your post
select the code part and press the <code/> icon in the tool bar to mark it as code. (also make sure you indented the code in the IDE before copying, that’s done by pressing ctrlT on a PC or cmdT on a Mac)
welcome to the arduino-forum.
Well done putting the code into a code-section.
Well done asking precise for details.
Yes the numbers are IO-pin-numbers.
Form the value of the numbers I assume that the code is written for an Arduino-Mega-board
Not many microcontroller-boards have so much IO-pins as an arduino Mega
by the way which microcontroller-board are you using?
I haven't worked with the TMC2208-library. Me personal I prefer using the mobatools-library for stepper-motor-driving. The mobatool-library enables to do things in parallel with step-pulse-creation in an easier way than other stepper-motor-libraries