I've based my software on the "Linux User & Developer" (issue 132) robot tutorial (my source code can be found here) and hardware connections according to Adafruits PWM tutorial.
The problem is that MotorR (right motor, DUH!) behaves "strangely". It spins backwards as expected. The problem is with forward motion, more precisely, it behaves like this when set to go forward:
- spins only at the start of the program i.e. if first mode is forward,
- sometimes spins 3 circles, sometimes 10,
- when forward motion is stopped manually (either by stop or by any backward motion), it never spins forward until the program is stopped.
Now, I have lost my eyes looking at the code (which is farely simple) and I have changed both IN1 and IN2 (from GPIO 4 & 17 to other pins) without any change.
Any ideas how to solve this problem?
Update
Changed IN1 to GPIO 25 --> same problem.
The pin voltage discretly and sporadically fluctuates between 0 and 3v3 thus affecting the motor.
The program doesn't do that as it runs 1 method (e.g. MotorR_forward()
) which sets up the pin levels correctly for the direction of the rotation and then the EN(1) pin is the one that oscilates in the set frequency (50) based on the duty cycle (90).
I have tested the pin by opening it directly in shell:
echo "25" | sudo tee /sys/class/gpio/export
echo "out" | sudo tee /sys/class/gpio/gpio25/direction
echo "1" | sudo tee /sys/class/gpio/gpio25/value
and the voltmeter stays on 0v and after 5-6s it jumps to 3v3 and immediately (0.5s) falls to 0v. This repeats "forever".
Changed IN1 to GPIO 18 --> motor works.
So, this is the question now -- why GPIO 4 and GPIO 25 behave in such way (and e.g. 17, 18, 22, 27 don't)?
Why 4 & 25 can't keep the logical 1 (3v3) as instructed?