I ave read many articles on the L9110 H-Bridge. It has only two pins per motor: DIR and PWM. Code examples vary. Some say use digitalWrite(DIR, HIGH/LOW) and use an analogWrite(PWM, speed); I have even found some that say use analog writes for both, but that simply doesn't work.
Here is my confusion. Controlling direction is easy: DIR == HIGH --> Forward, DIR == LOW --> Backward; However, setting the PWM pin to a speed value in the range 0..255 works for forward, but when I try backward, the motor starts for a second, then stops.
The setSpeed highlights this problem. No matter What values I use to set the speed, the "real speed" as read by analogRead(_PWM) doesn't change. So I cannot go backwards and I cannot set the speed.
rhj4:
I ave read many articles on the L9110 H-Bridge. It has only two pins per motor: DIR and PWM.
lookin the datasheet here I would say that that statement is incorrect
from what I could understand from the datasheet is that to be able to run the motor in either direction, IA and IB need to be opposites
ie IA = NOT(IB).
that would mean all you need to control the motor speed is to send analogWrite(_PWM, _speed) to 'IA' and the inverted PWM to 'IB' to run the motor one way.
to go the other way send analogWrite(_PWM, _speed) to 'IB' and the inverted PWM to 'IA'
rhj4:
Would you please share the datasheet you are taking this from?
Thanks!
postd the link. just click on 'here' in my previous post!
Have a look at the truth table, can you see why your code might not work?
one more thing; analogRead does not return the average voltage resulting from the PWM output but the instantaneous value ie either the HIGH or LOW value.
what you could try is something like this in a simple sketch with pre-set 'speed' values to see what happens: