You couldn't run a servo or RC speed controller using this technique, because precise timing matters with those.
This kind of rough-as-guts PWM only works for DC motors. Just don't pulse it too fast, (more than 100 khz) because the L298N will burn out from the switching losses. but if you keep a tally of the time spent on and off and vary your wait times, you can smooth out even quite big scheduling bumps. Linux gives very lose guarantees, and you should expect to sometimes not get called for up to a second or two if the machine is under heavy load. Fortunately, small DC motors (which is what you're clearly driving with the '298) can be given a really rough PWM signal at as low as 100hz, which you can probably manage in python with millisecond timer loops.īasically, if you quickly turn it on and off with an overall time ratio of about 50%, your motors will get about 50% power. Unfortunately, on the Pi, PWM is a little problematic. You need to PWM (Pulse Width Modulate) the "Enable" pin. I have used L298 Motor Driver Shield, you can read more about this shield on L298 Motor Driver Library for Proteus.
The best thing? The base model is only $20 $5!.ĭo you know a related subreddit? We'd love to know. L298 is an excellent motor driver, you can control two DC Motors with one L298 driver. Welcome to /r/raspberry_pi, a subreddit for discussing the raspberry pi credit card sized, ARM powered computer, and the glorious things we can do with it. Pi project ideas: There's a huge list right here on this sub! Friendly reminder: Please don't just post pictures of unused pis - do a project!Ĭomplete r/raspberry_pi Rules Check the FAQ and Helpdesk here