Custom board with Mega328 - interrupt on PB0?

Hello,

I use function, which is execute following:

stepper.rotate(10000)

and i would like to stop this by press button attached to PB0 calling function stop_motor();

Is it even possibile to use pin PB0 as interrupt trigger?

Custom made board using mega328 with Arduino bootloader.

What does the data sheet say?

All port pins can be used as interrupt sources.

But you don't need an interrupt at all, if you write non-blocking stepper code. Don't use delay(), and don't use a stepper library or function that blocks while stepping.

I have to use AccelStepper library, so DRV8825 is also required... I would like to learn about interrupts due to future projects. Datasheet says that i can use PD2 and PD3 as hardware interrupt (INT0/INT1), but it's possible to use other pins by software.

All examples i found using default pins PD2 and PD3 :frowning:

See pin change interrupts.

I have to use AccelStepper library, so DRV8825 is also required

A motor driver is indeed required, but that has nothing to do with using port pin interrupts.

The AccelStepper library is intended to be used in the non-blocking mode. That is the purpose of the stepper.run() function call, which allows you to check switches, and do other things instead of waiting for the move to complete.

jremington:
That is the purpose of the stepper.run() function call, which allows you to check switches, and do other things instead of waiting for the move to complete.

Hmm i use

   DRV8825 stepper(MOTOR_STEPS, DIR, STEP, MODE0, MODE1, MODE2);
   stepper.setSpeedProfile(stepper.LINEAR_SPEED, MOTOR_ACCEL, MOTOR_DECEL);
   stepper.begin(RPM, MICROSTEPS);
   [b]stepper.rotate(10000);[/b]

How can i use stepper.run in that way (with button detection)?

There are many examples of non blocking Accelstepper code on line to study. Here is one that blinks LEDs at different rates while the stepper is moving.

Basically you issue commands like

  stepper.setMaxSpeed(900.0);
  stepper.setAcceleration(900.0);
  stepper.moveTo(1360);

and then in some loop (like the loop() function):

void loop() {
  stepper.run();
  check_buttons();
  if (stepper.distanceToGo() == 0) reverse_and_restart();
...
}

i got:
'class DRV8825' has no member named 'moveTo'; did you mean 'move'?

when i change do 'move'

i got:
'class DRV8825' has no member named 'run'

Those functions are part of AccelStepper. Please read the AccelStepper library documentation and study the library examples.

I have no idea how to fire it up...

In example of AccelStepper.h library:

AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

I dont know what should i put in config (non-default)... I think something like:

AccelStepper stepper(DIR, STEP);

I'm using Pololou DRV8825 board, and i have only DIR, STEP, ENABLE, MODE0, MODE1, MODE2 - i don't have directly connected motor's A1, B1, A2, B2 to Atmega...

DRV8825 stepper(MOTOR_STEPS, DIR, STEP, MODE0, MODE1, MODE2); - i configured drv8825 in that way...

You don't need a library for the motor driver. Just tell Accelstepper which pins to use for DIR and STEP.

As in this example.

Don't forget to set the motor driver current limit correctly.