DRV8834 with Arduino Uno

First, log in to your Simuli account and navigate to the Simuli Virtual Lab. Here we will create a new emulated instance of the Arduino Uno. Click on the Launch button under the Arduino to get started.

This will open the configuration menu. First, provide a name for the project. Then, we will add the DRV8834 Stepper Motor Driver by selecting it from the list of available components. Finally, review that the name for the project and the selected sensors are correct and click on the Launch button.

Once we have clicked on the Launch button, a new instance of the Arduino Uno will be created. It can take a few minutes, so be patient.

If you have not set up your Arduino IDE, follow the guide linked below.

Once the Arduino IDE is set up, paste the code given below in the IDE.

int stepPin = 9;
int dirPin = 10;
int m1 = 12;
int m0 = 11;
int nsleep = 2;
int nenbl_aenbl = 3;
int configPin = 8;

void setup() {
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(nsleep, OUTPUT);
  pinMode(nenbl_aenbl, OUTPUT);
  pinMode(configPin, OUTPUT);
  pinMode(m0, OUTPUT);
  pinMode(m1, OUTPUT);
  
  Serial.begin(9600);
}
void loop() {
  digitalWrite(nenbl_aenbl, LOW);
  digitalWrite(dirPin, LOW);
  digitalWrite(m1, LOW);
  digitalWrite(m0, HIGH);
  digitalWrite(configPin, HIGH);
  digitalWrite(nsleep, HIGH);
  for (int x = 0; x < 200; x++) {
    digitalWrite(stepPin, HIGH);
    delay(100);  // ms (Note : 1000ms = 1sec)
    digitalWrite(stepPin, LOW);
    delay(100); // ms (Note : 1000ms = 1sec)
    Serial.println(x);
  }
}

Now save the sketch in a folder and keep a note of that folder. We now need to get the compiled binaries for the sketch. Go to Sketch and find Export Compiled Binary. The program will take some time to compile. Once the compilation is complete, go back to IoTIFY Virtual Lab and open the instance we created.

A new tab will open and we can interact with our Arduino. First, we need to uploadour compiled binary. Click on the Arduino, this will open a file explorer, navigate to where you had stored the Arduino sketch. In the same folder, a file called sketch.ino.standard.hex will be present (where sketch is the name of the Arduino sketch). Select this file and click on open. Now the hex file will be uploaded. Finally, reset the Arduino so that it loads the new file. To reset, just click the red power button above the top left corner of the Arduino. The Stepper motor connected to the DRV8834 will now start to rotate.

Now that you know how to drive a stepper motor, try to add a switch to the system, where the motor would start when you toggle the switch on and stop if the switch is off. You need to read the state of one of the switches and then start the motor if the state is on. Keep building and have fun! 🎉

Last updated