Skip to content

Commit 81fa01f

Browse files
authored
Merge pull request #2996 from caternuson/drv8833_examples
Add DRV8833 code examples
2 parents f327f68 + 24261aa commit 81fa01f

File tree

11 files changed

+219
-3
lines changed

11 files changed

+219
-3
lines changed

.github/workflows/arduino_cron.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ jobs:
9797
git clone --quiet https://github.com/adafruit/HID /home/runner/Arduino/libraries/HID_Project
9898
rm -rf /home/runner/Arduino/libraries/ArduinoHttpClient
9999
git clone --quiet https://github.com/arduino-libraries/ArduinoHttpClient.git /home/runner/Arduino/libraries/ArduinoHttpClient
100+
git clone --quiet https://github.com/pschatzmann/ESP32-A2DP /home/runner/Arduino/libraries/ESP32-A2DP
101+
git clone --quiet https://github.com/pschatzmann/arduino-audio-tools /home/runner/Arduino/libraries/arduino-audio-tools
100102
101103
- name: test platforms
102104
run: python3 ci/build_platform.py ${{ matrix.arduino-platform }}

Adafruit_DRV8833/arduino/drv8833_onoff/.uno.test.only

Whitespace-only changes.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-FileCopyrightText: 2025 Carter Nelson for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
// Basic ON/OFF control of DC motor via DRV8833
6+
7+
#define AIN1 5
8+
#define AIN2 6
9+
#define SLP 7
10+
11+
void setup() {
12+
Serial.begin(115200);
13+
Serial.println("Adafruit DRV8833 DC Motor Example - ON/OFF");
14+
15+
// configure pins
16+
pinMode(AIN1, OUTPUT);
17+
pinMode(AIN2, OUTPUT);
18+
pinMode(SLP, OUTPUT);
19+
20+
// enable DRV8833
21+
digitalWrite(SLP, HIGH);
22+
}
23+
24+
void loop() {
25+
//
26+
// FORWARD
27+
//
28+
Serial.println("Forward");
29+
digitalWrite(AIN1, HIGH);
30+
digitalWrite(AIN2, LOW);
31+
delay(1000);
32+
33+
//
34+
// REVERSE
35+
//
36+
Serial.println("Reverse");
37+
digitalWrite(AIN1, LOW);
38+
digitalWrite(AIN2, HIGH);
39+
delay(1000);
40+
}

Adafruit_DRV8833/arduino/drv8833_pwm/.uno.test.only

Whitespace-only changes.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// SPDX-FileCopyrightText: 2025 Carter Nelson for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
// PWM speed control of DC motor via DRV8833
6+
7+
#define AIN1 5
8+
#define AIN2 6
9+
#define SLP 7
10+
11+
void setup() {
12+
Serial.begin(115200);
13+
Serial.println("Adafruit DRV8833 DC Motor Example - PWM");
14+
15+
// configure pins
16+
pinMode(AIN1, OUTPUT);
17+
pinMode(AIN2, OUTPUT);
18+
pinMode(SLP, OUTPUT);
19+
20+
// enable DRV8833
21+
digitalWrite(SLP, HIGH);
22+
}
23+
24+
void loop() {
25+
//
26+
// FORWARD
27+
//
28+
Serial.println("Forward");
29+
digitalWrite(AIN2, LOW);
30+
// ramp speed up
31+
Serial.println(" ramping up");
32+
for (int duty_cycle=0; duty_cycle<256; duty_cycle++) {
33+
analogWrite(AIN1, duty_cycle);
34+
delay(10);
35+
}
36+
// ramp speed down
37+
Serial.println(" ramping down");
38+
for (int duty_cycle=255; duty_cycle>=0; duty_cycle--) {
39+
analogWrite(AIN1, duty_cycle);
40+
delay(10);
41+
}
42+
43+
//
44+
// REVERSE
45+
//
46+
Serial.println("Reverse");
47+
digitalWrite(AIN1, LOW);
48+
// ramp speed up
49+
Serial.println(" ramping up");
50+
for (int duty_cycle=0; duty_cycle<256; duty_cycle++) {
51+
analogWrite(AIN2, duty_cycle);
52+
delay(10);
53+
}
54+
// ramp speed down
55+
Serial.println(" ramping down");
56+
for (int duty_cycle=255; duty_cycle>=0; duty_cycle--) {
57+
analogWrite(AIN2, duty_cycle);
58+
delay(10);
59+
}
60+
}

Adafruit_DRV8833/arduino/drv8833_stepper/.uno.test.only

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// SPDX-FileCopyrightText: 2025 lady ada for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Stepper.h>
6+
7+
// change this to the number of steps on your motor
8+
#define STEPS 200
9+
10+
// create an instance of the stepper class, specifying
11+
// the number of steps of the motor and the pins it's
12+
// attached to
13+
Stepper stepper(STEPS, 4, 5, 6, 7);
14+
15+
16+
void setup()
17+
{
18+
Serial.begin(9600);
19+
Serial.println("Stepper test!");
20+
// set the speed of the motor to 30 RPMs
21+
stepper.setSpeed(60);
22+
}
23+
24+
void loop()
25+
{
26+
Serial.println("Forward");
27+
stepper.step(STEPS);
28+
Serial.println("Backward");
29+
stepper.step(-STEPS);
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-FileCopyrightText: 2025 Carter Nelson for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import board
7+
import digitalio
8+
9+
# Configure pins
10+
AIN1 = digitalio.DigitalInOut(board.D5)
11+
AIN2 = digitalio.DigitalInOut(board.D6)
12+
SLP = digitalio.DigitalInOut(board.D7)
13+
14+
AIN1.switch_to_output()
15+
AIN2.switch_to_output()
16+
SLP.switch_to_output()
17+
18+
# Enable DRV8833
19+
SLP.value = True
20+
21+
# Loop forever
22+
while True:
23+
#
24+
# FORWARD
25+
#
26+
print("Forward")
27+
AIN1.value = True
28+
AIN2.value = False
29+
time.sleep(1)
30+
31+
#
32+
# REVERSE
33+
#
34+
print("Reverse")
35+
AIN1.value = False
36+
AIN2.value = True
37+
time.sleep(1)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# SPDX-FileCopyrightText: 2025 Carter Nelson for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import board
7+
import digitalio
8+
import pwmio
9+
10+
# Configure pins
11+
AIN1 = pwmio.PWMOut(board.D5, frequency=2000)
12+
AIN2 = pwmio.PWMOut(board.D6, frequency=2000)
13+
SLP = digitalio.DigitalInOut(board.D7)
14+
15+
SLP.switch_to_output()
16+
17+
# Enable DRV8833
18+
SLP.value = True
19+
20+
# Loop forever
21+
while True:
22+
#
23+
# FORWARD
24+
#
25+
print("Forward")
26+
AIN2.duty_cycle = 0
27+
print(" ramping up")
28+
for duty_cycle in range(0, 65536, 100):
29+
AIN1.duty_cycle = duty_cycle
30+
time.sleep(0.01)
31+
print(" ramping down")
32+
for duty_cycle in range(65535, -1, -100):
33+
AIN1.duty_cycle = duty_cycle
34+
time.sleep(0.01)
35+
36+
#
37+
# REVERSE
38+
#
39+
print("Reverse")
40+
AIN1.duty_cycle = 0
41+
print(" ramping up")
42+
for duty_cycle in range(0, 65536, 100):
43+
AIN2.duty_cycle = duty_cycle
44+
time.sleep(0.01)
45+
print(" ramping down")
46+
for duty_cycle in range(65535, -1, -100):
47+
AIN2.duty_cycle = duty_cycle
48+
time.sleep(0.01)

Factory_Tests/Feather_RP2040_Adalogger/Feather_RP2040_Adalogger.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
//
33
// SPDX-License-Identifier: MIT
44

5-
#include <SdFat.h>
65
#include <SPI.h>
7-
#include "Adafruit_TestBed.h"
6+
#include <Adafruit_TestBed.h>
87

98
SdFat SD;
109
SdFile file;

0 commit comments

Comments
 (0)