2

initially my question was about how to fix my code. You informed me that usage of that python class will not work with my setup of one motor. I agree and I want to instead use the GPIO library to control the board controlling the motor. the example code I found:
enter image description here

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
while True:
   if ( GPIO.input(23) == False ):
      print(‘do something’)

I do not know how to edit the code to work with my project.] but I am using IN1 on the controller board and GPIO2 from the pi.

I answered this question but it's not an answer, it is more of a notice that I am going to use different parts. Many of the answers here pointed out that I should try the tutorials and/or use different parts so I will. thanks to everyone who helped!!

4 Answers4

1

I am just going to use different parts. These parts are not usable or are too hard to use at this point so I am going to use different motors and stick with GPIOzero

0

The line robot = Robot(left = (2, 2), right = (2, 2)) is saying you are controlling the left motor with GPIO 2 and 2 and the right motor with GPIO 2 and 2. This is illegal.

You need to specify four different GPIO. Two GPIO are needed to control each motor as follows:

GPIO#1 GPIO#2  motor
0      0       stop
0      1       clockwise
1      0       counterclockwise
1      1       brake

See https://gpiozero.readthedocs.io/en/stable/api_boards.html#robot

joan
  • 71,852
  • 5
  • 76
  • 108
0

I suggest you return to using gpiozero, but select a suitable class.

We don't know anything about your robot (include detail in your question).

I guess it has a single motor with forward/reverse so the following would be appropriate:-

https://gpiozero.readthedocs.io/en/v1.2.0/api_output.html#motor

Milliways
  • 62,573
  • 32
  • 113
  • 225
0

Question

Usage of that python class will not work with my setup of one motor. I agree and I want to instead use the GPIO library to control the board controlling the motor.

Example code I found: import RPi.GPIO as GPIO

I do not know how to edit the code to work with my project.] but I am using IN1 on the controller board and GPIO2 from the pi.

Answer

  1. It is not at all clear what DC motor driver you are using. Is it L293D, L298N? You might like to compare you motor driver board the L298N used by the following tutorial.

    Build a robot buggy - projects.raspberrypi.org

build a robot buggy

  1. It is also not clear if you are use Rpi.GPIO module or gpiozero1.5. Gpiozero assumes a generic motor driver board. If your motor is not that generic, you might find teething problem. If you are using gpioZero, you should start with "from gpiozero import Robot".

  2. gpiozero's Robot is a bit complicated. For example, it has a "curve" thing:

curve_left (float) – The amount to curve left while moving backwards, by driving the left motor at a slower speed. Maximum curve_left is 1, the default is 0 (no curve). This parameter can only be specified as a keyword parameter, and is mutually exclusive with curve_right.

The curve function to drive two motors at different speeds is for sure not for newbies. I would recommend to start with Build a robot buggy - projects.raspberrypi.org, which takes you by the hand, starts with simple movements, and finally hints you how to drive you robot along a square path.

But if you have already begun and got stuck with GpioZeroRobot, I would suggest you to remove all advanced stuff like class "curve" and "phase/enable". They are too advanced for newbies.

References

Build a robot buggy - projects.raspberrypi.org

Why isn’t my Raspberry Pi motor spinning?

Why don't my motors rotate?

Gpio Zero Robot 16.1.15. - GPIO Zero

A generic dual-motor robot

This class is constructed with two tuples representing the forward and backward pins of the left and right controllers respectively. For example, if the left motor’s controller is connected to GPIOs 4 and 14, while the right motor’s controller is connected to GPIOs 17 and 18.

Example to drive the robot

from gpiozero import Robot
robot = Robot(left=(4, 14), right=(17, 18))
robot.forward()

curve_left (float)

The amount to curve left while moving backwards, by driving the left motor at a slower speed. Maximum curve_left is 1, the default is 0 (no curve). This parameter can only be specified as a keyword parameter, and is mutually exclusive with curve_right.

Phase/Enable motor board

class gpiozero.PhaseEnableRobot(left, right, *, pwm=True, pin_factory=None)

Extends CompositeDevice to represent a dual-motor robot based around a Phase/Enable motor board.

tlfong01
  • 4,847
  • 3
  • 12
  • 24