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.