Code and errors, debugging. (im not a coder)

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

Welcome to the forum

Thank you for trying to use code tags but you are supposed to put the code between them not after them

Have you compared what your code does with how the library is used in the examples with the library ?

2 Likes

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

Hi,
No Im absolutley new pt coding and try learning by doing and figuring out. Got some god tips here. :slight_smile:

I suggest that you try the examples that came with the library

Thanks. You are right. Ill check some code corresponding to the library,

In the meanwhile, please correct your first post to enclose the code inside the code tags.
Thanks.

+1 - fix the first post please.

➜ Edit your post using the :pencil2: 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)

➜ do yourself a favour and please read How to get the best out of this forum

One of the suggestions from the tmc2208 library gar this folowing code.

#define EN_PIN    38  // LOW: Driver enabled. HIGH: Driver disabled
#define STEP_PIN  54  // Step on rising edge
#define RX_PIN    63  // SoftwareSerial pins
#define TX_PIN    40  //

What are the number on each line?
Do I connect a wire to the pin and where to?

Hi @eyeflow

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

Hi,
I'm using a UNO. I believe the RX and TX connectors are 0 and 1?

yes

in the example they mention SoftwareSerial, that is a software based implementation of an UART

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