0

DRV8833: pulseio.PWMOut also for Arduino
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

DRV8833: pulseio.PWMOut also for Arduino

by calavera81 on Tue Dec 29, 2020 11:56 am

Helly everybody,

I am using the DRV8833 and I am pretty happy with it. I am using it with my Raspberry and the following code to drive my Lego motors:
Code: Select all | TOGGLE FULL SIZE
import board
import pulseio
mytrainmotor = pulseio.PWMOut(board.D17, frequency=1200, duty_cycle=0)
# then e.g. max speed
mytrainmotor.duty_cycle = 65535


Now I try to do the same with Arduino, but my code doesn't do anything:
Code: Select all | TOGGLE FULL SIZE
void setup() {
  // put your setup code here, to run once:
  pinMode(3, OUTPUT);
  analogWrite(3, 0);
}

void loop() {
  // put your main code here, to run repeatedly:
  analogWrite(3, 128);
  delay(2000);
  analogWrite(3, 256);
  delay(2000);


I connected the A3 and A4 pins of my Arduino Nano AIN1 and AIN2 of my DRV8833.

Maybe someone can give me a hint?

Many thanks in advance.

calavera81
 
Posts: 13
Joined: Fri Nov 13, 2020 6:21 am

Re: DRV8833: pulseio.PWMOut also for Arduino

by adafruit_support_bill on Tue Dec 29, 2020 12:39 pm

Please post a photo showing how you have everything connected.

adafruit_support_bill
 
Posts: 80362
Joined: Sat Feb 07, 2009 10:11 am

Re: DRV8833: pulseio.PWMOut also for Arduino

by calavera81 on Tue Dec 29, 2020 12:56 pm

Sure,

I consider the DRV8833 to work perfectly, as it does exactly what it is supposed to do using my Raspberry & Python. I can control two Lego Motors using AOUT1, AOUT2 and BOUT1 and BOUT2.

I only struggle with the Arduino here. Maybe I am missing some includes?
Attachments
20201229_174736.jpg
20201229_174736.jpg (806.62 KiB) Viewed 96 times
20201229_174725.jpg
20201229_174725.jpg (906.34 KiB) Viewed 96 times

calavera81
 
Posts: 13
Joined: Fri Nov 13, 2020 6:21 am

Re: DRV8833: pulseio.PWMOut also for Arduino

by adafruit_support_bill on Tue Dec 29, 2020 1:18 pm

A little wider view would be helpful. We can't really follow where all the wires go.

adafruit_support_bill
 
Posts: 80362
Joined: Sat Feb 07, 2009 10:11 am

Re: DRV8833: pulseio.PWMOut also for Arduino

by calavera81 on Tue Dec 29, 2020 1:28 pm

Sure.
Attachments
20201229_182313.jpg
20201229_182313.jpg (760.93 KiB) Viewed 93 times

calavera81
 
Posts: 13
Joined: Fri Nov 13, 2020 6:21 am

Re: DRV8833: pulseio.PWMOut also for Arduino

by calavera81 on Tue Dec 29, 2020 2:02 pm

Btw, if I change to the digital pins D3 and D4, then this works:
Code: Select all | TOGGLE FULL SIZE
void setup() {
  // put your setup code here, to run once:
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(3, HIGH);
  delay(2000);
  digitalWrite(3, LOW);
  delay(2000);
  digitalWrite(4, HIGH);
  delay(2000);
  digitalWrite(4, LOW);
  delay(2000);
}


So, it looks like the analog pins only don't work for me. Unfortunately I need them so set different speeds for my motor.

calavera81
 
Posts: 13
Joined: Fri Nov 13, 2020 6:21 am

Re: DRV8833: pulseio.PWMOut also for Arduino

by calavera81 on Tue Dec 29, 2020 2:29 pm

Okay, I made it work. The pins I used are no PWM pins.
https://i.stack.imgur.com/GB2hw.jpg

So, I switched to Pins D5 and D6 and now it works:
Code: Select all | TOGGLE FULL SIZE
void setup() {
  // put your setup code here, to run once:
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  analogWrite(5, 128);
  delay(2000);
  analogWrite(5, 255);
  delay(2000);
  analogWrite(5, 0);
  delay(2000);
  analogWrite(6, 128);
  delay(2000);
  analogWrite(6, 255);
  delay(2000);
  analogWrite(6, 0);
  delay(2000);
}


Thanks for your support anyway!

calavera81
 
Posts: 13
Joined: Fri Nov 13, 2020 6:21 am

Re: DRV8833: pulseio.PWMOut also for Arduino

by adafruit_support_bill on Tue Dec 29, 2020 2:44 pm

Wiring looks OK - expect that A3 and A4 on a Nano are analog inputs and are capable of PWM output. They are also not addressed as '3' and '4'. Without the 'A' prefix, the compiler assumes you are referring to the digital pins. So your code is writing to the D3 pin.

Note that D3 is PWM capable, but D4 is not. PWM is possible on digital pins 3, 5, 6, 9, 10 and 11. See the Nano documentation here:
https://store.arduino.cc/usa/arduino-nano

adafruit_support_bill
 
Posts: 80362
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.