-1

I have a Raspberry Pi 2B+ and some knowledge of Python. I need to control a DC motor, two servos and a LED simultaneously.

The requirements are:

  • Must control two servos, a LED and at least 1 DC motor (obviously)
  • Must be compatible with the Raspberry Pi 2B+ (obviously)
  • Must be controllable through Python and GPIO
  • Must allow an external power source (the DC motor is 12V which the Raspberry Pi cannot provide)
  • Preferably does not require a breadboard

I have tried an Arduino motor shield and the AMSpi library on Github but this does not support servos unfortunately.

Is there any way to achieve this, preferably at a low price with as little additional hardware as possible?

  • 3
    The requirements are - have you done anything at all other than try some hardware not made for the pi using software not made for your requirement? – Jaromanda X Mar 11 at 22:29
  • @Jaromanda X nope. I'm afraid I don't have the budget to try 50 different hats for the pi or the time to search the web for software. I tried a few things I could come up with and when that didn't work, instead of wasting time and money on other solutions which I couldn't be sure would work, I came here for some advice. – user9123 Mar 12 at 13:22
1

There are 26 GPIO pins on the Pi (plus GND, 3V3, 5V). Each device requires a number of GPIO pins, so you have 26 pins' worth of devices to play with.

A servo takes 1 GPIO pin (plus GND & 5V), a motor takes 2 GPIO pins (plus GND & 5V), and an LED takes 1 GPIO (plus GND). Note GND can be shared, as can 5V. So you can easily use the devices you mentioned and have plenty of unused pins.

You probably want to use a motor controller board to control the motor. Ideally one that gives you the pins back rather than using them all up. The CamJam kit robot board covers 26 pins but gives you the unused ones back, including the 5V you need for your servo. Alternatively (though you'd need a breadboard), you can use an H-bridge IC.

For programming, (my) GPIO Zero library is probably easiest, as it provides ready-made classes for these devices: See LED, Servo, Motor and recipes for a taste of how you connect devices together.

  • Would something like this Motor Controller Board and this H-Bridge work? Just want to make sure before I buy. – user9123 Apr 20 at 13:18
  • You don't need the separate H-Bridge. The MCB is fine on its own. – ben_nuttall Apr 20 at 17:56
  • 1
    Yeah, I realised that after posting the comment. Thanks for your help. I will most likely use your library also. Accepted answer :) – user9123 Apr 21 at 9:05
2

See https://www.youtube.com/watch?v=rrRg1guojQE

This shows (my) pigpio library being used to control a variety of devices.

A Raspberry Pi controlling a variety of motors and sensors.

The pan-tilt head is moved by a pair of servos. The head holds a sonar ranger and an ADXL345 3-axis accelerometer. The servos control pins are connected directly to Pi gpios. The sensors communicate to the Pi via the I2C bus.

A pair of DC motors (middle) have their speed controlled by PWM from the Pi's gpios. The motors and a red laser are switched on when an infra-red sensor (bottom-left) detects body heat.

The sonar ranger distance, the XYZ accelerometer co-ordinates, and the body detected data are written to the screen.

There is a Python module

  • Hey, sorry for the late reply. This seems like just what I need but I can't tell what hardware (if any) you are using in between the Pi and your motors and servos. Mind sharing a link as to where I could acquire it? I want to make sure I get the right thing. Thanks for your help also. – user9123 Mar 25 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.