Peristatic Liquid Pump With RPi
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Peristatic Liquid Pump With RPi

by NaderH on Wed Oct 09, 2013 10:45 pm

Hello

I have purchased a peristaltic liquid pump to use with my raspberry pi and I followed the tutorial Lesson 9 located at:
http://learn.adafruit.com/adafruit-raspberry-pi-lesson-9-controlling-a-dc-motor

I have the exact same wiring and same code.

The first time I ran my code, it seemed like everything was working. But on closer inspection I was the motor wasn't turning at all but it was vibrating.

Any ideas?? I assumed the pump is basically just a 12v motor.

Thanks in Advance
NaderH
 
Posts: 24
Joined: Tue Sep 03, 2013 8:07 pm

Re: Peristatic Liquid Pump With RPi

by adafruit_support_mike on Thu Oct 10, 2013 2:33 am

When you say the motor was just vibrating, does that mean you looked inside the pump and confirmed that the rotor wasn't moving? If so, that sounds like a bad connection between the shaft and the rotor.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10122
Joined: Thu Feb 11, 2010 2:51 pm

Re: Peristatic Liquid Pump With RPi

by NaderH on Thu Oct 10, 2013 1:43 pm

yes I took the pump out and saw that the rotor wasn't moving. but I could feel the unit vibrate. I do have another unit I can test with. I will let you know the results of that

I also looked on the other forum posts. The commented about using a 1N4001 diode to help bleed off flyback:

viewtopic.php?f=8&t=37466&p=202532&hilit=peristaltic#p202532
viewtopic.php?f=8&t=37466&p=184956&hilit=peristaltic+diode#p184956

I am using a L293D/RPi and not a Arduino. do I need a diode?
They are only a $1.50 and Im not against getting on

Thanks
N
NaderH
 
Posts: 24
Joined: Tue Sep 03, 2013 8:07 pm

Re: Peristatic Liquid Pump With RPi

by adafruit_support_mike on Thu Oct 10, 2013 8:06 pm

Actually, let's take all the logical hardware out of the equation for now. What you're describing sounds like a mechanical problem within the pump itself.

If you connect power directly to the motor, does the pump rotor turn? If not, can you see the motor's shaft turning without the rotor?

WRT the flyback diode, you don't need an external one. The L293D has one built in, which is why we carry it. Your comment about diodes costing $1.50 threw me for a second until I remembered that's for a 10-pack. A $1.50 single diode is something to get excited about. ;-)
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10122
Joined: Thu Feb 11, 2010 2:51 pm

Re: Peristatic Liquid Pump With RPi

by NaderH on Fri Oct 11, 2013 12:29 am

ok, I checked both pumps against power and they work fine.
I have included a image of the bread board as an attachment. and listed below is the code I am using

Code: Select all | TOGGLE FULL SIZE
import RPi.GPIO as io
io.setmode(io.BCM)

in1_pin = 4
in2_pin = 17

io.setup(in1_pin, io.OUT)
io.setup(in2_pin, io.OUT)

def set (property, value):
   try:
      f = open("/sys/class/rpi-pwm/pwm0/" + property, 'w')
      f.write(value)
      f.close()
   except:
      print("Error writing to: " + property + " value: " + value)

set("delayed", "0")
set("mode", "pwm")
set("frequency", "500")
set("active", "1")

def clockwise():
   io.output(in1_pin, True)
   io.output(in2_pin, False)

def counter_clockwise():
   io.output(in1_pin, False)
   io.output(in2_pin, True)

clockwise()

while True:
   cmd = raw_input("Command, f/r 0...9, ex: f5 :")
   direction = cmd[0]
   if direction == "f":
      clockwise()
   else :
      counter_clockwise()
   speed = int(cmd[1]) * 11
   set("duty", str(speed))




again, I can feel the motor vibrating but not turning the rotor. however, when connected directly to 12 V electricity, it runs fine.
Attachments
IMAG0059.jpg
IMAG0059.jpg (370.89 KiB) Viewed 239 times
NaderH
 
Posts: 24
Joined: Tue Sep 03, 2013 8:07 pm

Re: Peristatic Liquid Pump With RPi

by adafruit_support_mike on Fri Oct 11, 2013 7:17 pm

Okay.. that looks like a code issue.

Try adjusting your PWM code to match the examples here: http://code.google.com/p/raspberry-gpio-python/wiki/PWM
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10122
Joined: Thu Feb 11, 2010 2:51 pm

Re: Peristatic Liquid Pump With RPi

by NaderH on Fri Oct 11, 2013 11:58 pm

Actually I found the problem. GND pin on L293D was wrong. it was on pin 14, should be pin 13. My fault.
SO it is working and its pretty good.

But I do have a question, if I want to run two or more pumps, do I still use GPIO pin 18 and connect it to L293D Pin 9 EN2?
Currently, that pin is connected to L293D PIN 1 EN1 to control the first pump.

Thanks and great job guys. Great Tutorials, very nice pump.
NaderH
 
Posts: 24
Joined: Tue Sep 03, 2013 8:07 pm

Re: Peristatic Liquid Pump With RPi

by adafruit_support_mike on Sat Oct 12, 2013 1:00 pm

Glad to hear you found the problem.. wiring issues can be a pain.

WRT GPIO-18 and the L293D's EN2 pin, I need to lay in a bit of vocabulary:

Each pair of input/output pins on the L293D can both supply current and allow current to drain to GND, and is called a 'half-bridge'. If you put half-bridges on either side of a circuit, you get what's called an 'H-bridge' because the schematic looks like a capital H.. HIGH/LOW connections on either side, and a line connecting them in the middle.

The L293D's 'enable' pins override the input pins for the half-bridges on that side of the chip. If the enable pin is LOW, the half-bridges won't allow current to flow, regardless of the signals at the input pins.

The hardware setup from Lesson 9 uses GPIO pins 4 and 17 to set the half-bridges on either side of the motor HIGH or LOW, thus controlling the direction the motor will spin. Then it uses pin EN1 to turn the half-bridges on and off, controlling the motor's speed.

If you use the half-bridges on the other side of the L293D to make an H-bridge around another motor, then connect GPIO-18 to both EN1 and EN2, you'll get the same PWM duty cycle through both H-bridges. In practical terms, both motors will run at the same speed, but you'll be able to set their direction of rotation independently of each other.

If you want to run two motors that do the same thing, use jumpers to connect L293D pins 2 and 15 (the input pins for the upper half-bridges on either side of the chip), pins 7 and 10 (the inputs for the lower half-bridges), and pins 1 and 9 (the enable lines).
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10122
Joined: Thu Feb 11, 2010 2:51 pm

Re: Peristatic Liquid Pump With RPi

by NaderH on Mon Oct 14, 2013 1:41 pm

OK, I think I understand the wiring.
What I need to do is have both motors running independently (sometime one motor is on, sometimes the other and maybe even both), but they will always be running in same direction (possibly at different speeds).

"If you use the half-bridges on the other side of the L293D to make an H-bridge around another motor, then connect GPIO-18 to both EN1 and EN2, you'll get the same PWM duty cycle through both H-bridges. In practical terms, both motors will run at the same speed, but you'll be able to set their direction of rotation independently of each other."

By using the software, can I set the movement of either motor that I want. This means one pump can be off and one on. Direction is always the same, but speed is the issue.
If I wanted speed control, how would I do that in the code?

I would need to use another GPIO pin connected to EN2 but nowhere in the code do I see reference to GPIO using pin 18. I do see the Duty write to file call.
Can you explain how the GPIO uses 18 and its interaction with DUTY file? is there a doc we can read. sorry for the questions, but I am a RPi newbie.

Thanks
Nader
NaderH
 
Posts: 24
Joined: Tue Sep 03, 2013 8:07 pm

Re: Peristatic Liquid Pump With RPi

by adafruit_support_mike on Mon Oct 14, 2013 9:32 pm

NaderH wrote:By using the software, can I set the movement of either motor that I want. This means one pump can be off and one on. Direction is always the same, but speed is the issue.
If I wanted speed control, how would I do that in the code?

That's where things get difficult.

NaderH wrote:Can you explain how the GPIO uses 18 and its interaction with DUTY file? is there a doc we can read. sorry for the questions, but I am a RPi newbie.

Don't apologize.. that's exactly the right question to ask.

Again, there are a couple of basic ideas that need to be laid in as a foundation before the answer makes sense.

First, a quick introduction to operating systems: when your computing needs get complicated enough, it becomes difficult to manage all the "do this, but also do that" in a single program. What you need is a 'multitasking' system where you can break the work down into multiple, independent programs. Making that work with a single CPU involves some trickery.

Computer programs operate in what's called 'discrete time'.. you do step 1, then step 2, then step 3, etc. Thing is, you can save a copy of all the data in the CPU's registers at the end of step 2, go do something else for a while, write the stored data back into the registers, then execute step 3 of the original program. That's called 'time slicing'.

In Linux, the OS uses timers in the CPU to give each program a certain amount of runtime, then when the timer goes off, the OS stores the data for the current program and swaps in another. That's called 'preemptive multitasking'.

For programs that just need to crunch some numbers and produce a result, suspending and resuming the code doesn't make any difference. The average time slice in Linux is about 1/100th of a second, so interactive programs like word processors swap in and out fast enough that the person at the keyboard doesn't notice.

For a servo driver that needs to generate pulses every 20 milliseconds, that's a problem.

To deal with that kind of thing, the OS needs to bypass the time-slicing/multiprocessing techniques and use hardware that can do the job in real time.

The microprocessor at the heart of the RasPi has built-in hardware to support PWM. It's connected to GPIO-18. The code that tells the microprocessor to use the PWM circuitry can't be written as a regular program (because that would be time-sliced), so it has to be written in a form that the OS can handle differently. The package of code that can do that is called a 'kernel driver', and we've built one of those into Occidentalis.

This takes us about halfway to where you want to be.. but only halfway.

As I explained above, the code that drives the L293D sets the direction of rotation through the half-bridge input pins. It controls speed through the PWM signal (which comes out of the RasPi on GPIO-18) going to the L293D's EN1 pin.

To control two motors with independent speeds, you'd need another PWM signal. The microprocessor doesn't have the hardware to do that, and you can't generate a PWM signal in a Linux program because time-slicing will mess up the timing.

The solution for this is another piece of hardware: the PCA9685 PWM servo driver. It has the same kind of PWM circuit as the RasPi's microprocessor, but the PCA9685 has 16 copies of it. All 16 run independently of each other, and can have 4096 different values.

Each channel of the PCA9685 can supply 10mA or receive 25mA from another circuit, so it isn't strong enough to drive a motor directly, but it can drive the EN1/EN2 pins of an L293D.

To get a general idea of how to use the PCA9685 Servo Driver (http://www.adafruit.com/products/815), take a look at this tutorial: http://learn.adafruit.com/adafruit-16-c ... pberry-pi/
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10122
Joined: Thu Feb 11, 2010 2:51 pm

Re: Peristatic Liquid Pump With RPi

by NaderH on Tue Dec 03, 2013 8:15 pm

Thank you Mike for the great answer.
Im working on a raspberry Pi Christmas project for my better half but as soon as I am done, I will give this a try and report back.
Thanks again
You & Adafruit are the best!
NaderH
 
Posts: 24
Joined: Tue Sep 03, 2013 8:07 pm