In this video lesson we show you how you can control a small DC motor using the Raspberry Pi Pico W and a TA6586 DC Motor Controller. We show you how to control both the speed and direction. The schematic for the circuit we use is here:

When using the breadvolt, or any battery power supply on a breadboard project, do not turn the power supply on while the Raspberry Pi Pico is connected to USB, as you could generate voltage conflicts. It is an either or. If the USB is connected, the power supply should be OFF. Or if you are going to connect the USB, first turn off the power supply.
In the lesson, we developed the following code for your convenience:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# ==================================================================== # DISCLAIMER: # This code is provided as-is for educational and experimental # purposes only. The author makes no representations or warranties of # any kind concerning the safety, suitability, or accuracy of this # code. Use at your own risk. The author assumes no liability for any # damages, system failures, security breaches, or network issues # resulting from the use or implementation of this script. # ==================================================================== from machine import Pin,PWM import time icPin1=Pin(14,Pin.OUT) icPin2=Pin(15,Pin.OUT) fPWM=PWM(icPin1) rPWM=PWM(icPin2) fPWM.freq(1000) rPWM.freq(1000) try: while True: ts=.25 tr=2 for speed in range(20,101,10): rPWM.duty_u16(0) fPWM.duty_u16(int(speed/100*65535)) time.sleep(ts) for speed in range(100,-1,-10): rPWM.duty_u16(0) fPWM.duty_u16(int(speed/100*65535)) print(int(speed/100*65535)) time.sleep(ts) time.sleep(tr) for speed in range(20,101,10): fPWM.duty_u16(0) rPWM.duty_u16(int(speed/100*65535)) time.sleep(ts) for speed in range(100,-1,-10): fPWM.duty_u16(0) rPWM.duty_u16(int(speed/100*65535)) print(int(speed/100*65535)) time.sleep(ts) time.sleep(tr) except KeyboardInterrupt: print("Program Stopped by User") rPWM.duty_u16(0) fPWM.duty_u16(0) time.sleep(ts) rPWM.deinit() fPWM.deinit() icPin1.off() icPin2.off() |

