Da Vinci Kit for Raspberry Pi - motor.py - will not work

Despite numerous attempts to get the DC motor running, it will not work. I have checked the wiring several time… the motor.py program is running, but the motor not.
I use RPI 4 Model B and Bullseye (updated - Ver 11) - python3 ver.3.9.2
The Blinking LED and RGB LED does work…
and I use Thonny for testing.
Furthermore the Python code for 1.3.1 on the project page is the the wrong one… it refers to the temperature sensor… - but I use the one from the Directory…
My Pin Setup is:
MotorPin1 = 27
MotorPin2 = 17
MotorEnable = 22

defsetup()
GPIO.setmode(GPIO.BCM)
… etc

Can it be, that L239D does not work properly ? the Power Supply Module does deliver 5 V on the breadboard 's +/- Pins - I used a new 9 V battery (LED is on)
So how to check, whether or not the L239D does work properly.?

This is my wiring:
Google Photos

This hint / error message I get in Python3:

%Run 1.3.1_Motor.py
/home/pi/davinci-kit-for-raspberry-pi/python/1.3.1_Motor.py:15: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(MotorPin1, GPIO.OUT)
/home/pi/davinci-kit-for-raspberry-pi/python/1.3.1_Motor.py:16: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(MotorPin2, GPIO.OUT)
/home/pi/davinci-kit-for-raspberry-pi/python/1.3.1_Motor.py:17: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(MotorEnable, GPIO.OUT, initial=GPIO.LOW)
Clockwise
Stop
Counterclockwise
Stop
Clockwise


and here is the code I use:

#!/usr/bin/env python3

import RPi.GPIO as GPIO
import time

# Set up pins
MotorPin1   = 27
MotorPin2   = 21
MotorEnable = 22

def setup():
	# Set the GPIO modes to BCM Numbering
	GPIO.setmode(GPIO.BCM)
	# Set pins to output
	GPIO.setup(MotorPin1, GPIO.OUT)
	GPIO.setup(MotorPin2, GPIO.OUT)
	GPIO.setup(MotorEnable, GPIO.OUT, initial=GPIO.LOW)

# Define a motor function to spin the motor
# direction should be 
# 1(clockwise), 0(stop), -1(counterclockwise)
def motor(direction):
	# Clockwise
	if direction == 1:
		# Set direction
		GPIO.output(MotorPin1, GPIO.HIGH)
		GPIO.output(MotorPin2, GPIO.LOW)
		# Enable the motor
		GPIO.output(MotorEnable, GPIO.HIGH)
		print ("Clockwise")
	# Counterclockwise
	if direction == -1:
		# Set direction
		GPIO.output(MotorPin1, GPIO.LOW)
		GPIO.output(MotorPin2, GPIO.HIGH)
		# Enable the motor
		GPIO.output(MotorEnable, GPIO.HIGH)
		print ("Counterclockwise")
	# Stop
	if direction == 0:
		# Disable the motor
		GPIO.output(MotorEnable, GPIO.LOW)
		print ("Stop")

def main():

	# Define a dictionary to make the script more readable
	# CW as clockwise, CCW as counterclockwise, STOP as stop
	directions = {'CW': 1, 'CCW': -1, 'STOP': 0}
	while True:
		# Clockwise
		motor(directions['CW'])
		time.sleep(5)
		# Stop
		motor(directions['STOP'])
		time.sleep(5)
		# Anticlockwise
		motor(directions['CCW'])
		time.sleep(5)
		# Stop
		motor(directions['STOP'])
		time.sleep(5)

def destroy():
	# Stop the motor
	GPIO.output(MotorEnable, GPIO.LOW)
	# Release resource
	GPIO.cleanup()    

# If run this script directly, do:
if __name__ == '__main__':
	setup()
	try:
		main()
	# When 'Ctrl+C' is pressed, the program 
	# destroy() will be executed.
	except KeyboardInterrupt:
		destroy()


any help is appreciated…
Thanks
Bernhard
from Lüneburg/Germany

Your circuit connections seem to be fine, but the pins on your code don’t correspond to your circuit connections, please change the MotorPin2 pin in your code to 17 and try again.
101602

thanks for ur prompt reply!

I did change it to read:

import RPi.GPIO as GPIO
import time

# Set up pins
MotorPin1   = 27
**MotorPin2   = 17**
MotorEnable = 22

def setup():
	# Set the GPIO modes to BCM Numbering
	GPIO.setmode(GPIO.BCM)
	# Set pins to output
	GPIO.setup(MotorPin1, GPIO.OUT)
	GPIO.setup(MotorPin2, GPIO.OUT)
	GPIO.setup(MotorEnable, GPIO.OUT, initial=GPIO.LOW)

now I get:

>>> %Run 1.3.1_Motor.py
/home/pi/davinci-kit-for-raspberry-pi/python/1.3.1_Motor.py:17: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  GPIO.setup(MotorEnable, GPIO.OUT, initial=GPIO.LOW)

I assume, that it refers to line [17] which is:

GPIO.setup(MotorEnable, GPIO.OUT, initial=GPIO.LOW)

any idea ?

Please try to run the code through Terminal instead of Thonny, because Thonny sometimes doesn’t perform the post-termination processing operation GPIO.cleanup() when terminating the program, resulting in the io being occupied.

SOLVED . . .
Hi, I got it !
I checked the 5 V power supply throughout the breadboard and found out, that half of the board was not supplied with 5 V power…
I did use a breadboard (from a former RPI project) with interrupted pin-wholes on the side for power suply + and - and not the Sunfounder breadboard of the Da Vinci Kit.
The side of the Power-Module did only supply power up to the middle of the board…
the wiring of the extension board was not supplied with 5 V or even GND connected to minus…
I must admit I did not know, that different breadboards do exist.
I know changed to the Sunfounder breadboard and everything (for the Motor-Tutorial) does work fine
Thanks ur assistance anyway…
brgds
Bernhard

1 Like