Uncategorised

Using the x27.168 Stepper Motor with a Raspberry Pi Pico and L298N Motor Driver

The x27.168 stepper motor is a precise and reliable motor commonly used in automotive applications, particularly for gauge instrumentation such as speedometers and tachometers. Its compact size and accuracy make it an excellent choice for DIY projects that require precise movement and control. In this blog post, we will cover how to use the x27.168 stepper motor with a Raspberry Pi Pico using the Arduino IDE and an L298N motor driver.

Components Needed

  • Raspberry Pi Pico
  • x27.168 stepper motor
  • L298N motor driver
  • Jumper wires
  • Breadboard (optional)

Wiring the Components

To control the x27.168 stepper motor with the Raspberry Pi Pico, you need to connect it to the L298N motor driver. The L298N allows you to drive the stepper motor with adequate power and control signals from the Pico.

  1. Connect L298N to Raspberry Pi Pico:
    • Connect the IN1, IN2, IN3, and IN4 pins of the L298N to GPIO pins on the Pico (for example, GPIO 0, 1, 2, and 3).
    • Connect the GND and VCC pins of the L298N to the GND and VBUS pins of the Pico.
  2. Connect the motor (see diagram)

Here is a simplified wiring diagram:

Test Code to Move the Motor

Here is a basic test code to move the x27.168 stepper motor using the Raspberry Pi Pico. Ensure you have the SwitecX25 library installed in the Arduino IDE.

#include <SwitecX25.h>

// Pin definitions for the motor
#define MOTOR_PIN1 0
#define MOTOR_PIN2 1
#define MOTOR_PIN3 2
#define MOTOR_PIN4 3

// Number of steps for 315 degrees (full range)
#define STEPS_PER_REV 945
#define MAX_DEGREES 315
#define TARGET_DEGREES 200
#define STEPS_PER_DEGREE (STEPS_PER_REV / MAX_DEGREES)

// Create an instance of the SwitecX25 motor
SwitecX25 motor(STEPS_PER_REV, MOTOR_PIN1, MOTOR_PIN2, MOTOR_PIN3, MOTOR_PIN4);

void setup() {
  motor.zero();        // Move the motor to its zero position
  delay(1000);         // Wait for 1 second to allow motor to zero
}

void loop() {
  // Move to 200 degrees
  int steps = TARGET_DEGREES * STEPS_PER_DEGREE;
  motor.setPosition(steps);
  while (motor.stopped == 0) {
    motor.update();
  }
  delay(1000); // Wait for 1 second

  // Move back to 0 degrees
  motor.setPosition(0);
  while (motor.stopped == 0) {
    motor.update();
  }
  delay(1000); // Wait for 1 second
}

If you have wired your controller, H-Bridge and motor correctly this code should see the motor move 200 degrees and back to 0 repeatedly like a window wiper,

What cars use this motor? Quite a few:

  • Cadillac Escalade GMT800 (models from 2003 to 2006);
  • Chevrolet Avalanche GMT800 (models from 2003 to 2006);
  • Chevrolet Frontera (models from 1998 to 2004);
  • Chevrolet Silverado GMT800 (models from 2003 to 2007);
  • Chevrolet Suburban GMT800 (models from 2003 to 2006);
  • Chevrolet Tahoe GMT800 (models from 2003 to 2006);
  • Fendt 206 (models from 2003 to 2009)
    all models including 206S, 206V, 206F;
  • Fendt 207 (models 2003 from 2009)
    all models including 207S, 207V, 207F;
  • Fendt 208 (models from 2003 to 2009)
    all models including 208S, 208V, 208F, 208P;
  • Fendt 209 (models from 2003 to 2009)
    all models including 209S, 209V, 209F, 209P;
  • Fendt Farmer 307Ci (models from 2003 to 2008);
  • Fendt Farmer 308Ci (models from 2003 to 2008);
  • Fendt Farmer 309Ci (models from 2003 to 2008);
  • GMC Sierra GMT800 (models from 2003 to 2007);
  • GMC Suburban GMT800 (models from 2003 to 2006);
  • GMC Yukon GMT800 (models from 2003 to 2006);
  • GMC Yukon XL GMT800 (models from 2003 to 2006);
  • GMC Yukon XL Denali GMT800 (models from 2003 to 2006);
  • Holden Frontera (models from 1999 to 2004);
  • Honda Passport (models from 1998 to 2002);
  • Hummer H2 (models from 2003 to 2007);
  • Hürlimann H-1200 SX (models from 1998 to 2004);
  • Hürlimann H-1350 SX (models from 1998 to 2004);
  • Hürlimann H-1500 SX (models from 1998 to 2004);
  • Hürlimann H-1600 SX (models from 2000 to 2004);
  • Hürlimann H-1800 SX (models from 2000 to 2004);
  • Hürlimann H-2000 SX (models from 2000 to 2004);
  • Isuzu Amigo (models from 1998 to 2001);
  • Isuzu Frontier (models from 1998 to 2004);
  • Isuzu MU / Wizard (models from 1998 to 2004);
  • Isuzu Rodeo (models from 1998 to 2002);
  • KTM 690 Enduro (models from 2009 to 2017)
    all versions including 690 Enduro R, 690 Enduro Rally Replica;
  • KTM 690 Duke (models from 2007 to 2016);
    all versions including 690 Duke R;
  • KTM 690 SMC (models from 2008 to 2011);
  • KTM 690 SMC R (models from 2012 to 2017);
  • KTM 690 Supermoto (models from 2006 to 2012);
  • KTM 990 Adventure (models from 2009 to 2014)
    all versions including 990 Adventure ABS, 990 Adventure Dakar ABS and 990 Adventure R;
  • KTM 990 Super Duke (models from 2007 to 2013)
    all versions including 990 Super Duke R;
  • KTM 990 Supermoto (models from 2007 to 2013)
    all versions including 990 Supermoto R, Supermoto T and Supermoto T ABS;
  • Lamborghini Champion 120 (models from 1998 to 2004);
  • Lamborghini Champion 135 (models from 1998 to 2004);
  • Lamborghini Champion 150 (models from 1998 to 2004);
  • Lamborghini Champion 160 (models from 2000 to 2004);
  • Lamborghini Champion 180 (models from 2000 to 2004);
  • Lamborghini Champion 200 (models from 2000 to 2004);
  • Lombardini Marine speedometers
    some versions;
  • Opel Frontera (models from 1998 to 2005);
  • Peugeot Geopolis 125 (modeli from 2006 to 2013);
  • Peugeot Geopolis 250 (models from 2005 to 2012);
  • Peugeot Geopolis 300 (models from 2010 to 2015);
  • Peugeot Geopolis 400 (models from 2007 to 2013);
  • Peugeot Geopolis 500 (models from 2008 to 2012);
  • Same Rubin 120 (models from 1998 to 2004);
  • Same Rubin 135 (models from 1998 to 2004);
  • Same Rubin 150 (models from 1998 to 2004);
  • Same Rubin 160 (models from 2000 to 2004);
  • Same Rubin 180 (models from 2000 to 2004);
  • Same Rubin 200 (models from 2000 to 2004);
  • Vauxhall Frontera (models from 1998 to 2004);
  • Volkswagen Passat B3 / B4 (models from 1988 to 1997)
    some versions.