So, I have something to ask, Is there any good documentation on how to interface a dc gear motor from L298n to pca 9685 using arduino uno?. I did interface these dc gear motor from L298n directly to arduino, and now I want to hook it up to a pca9685 chip, to control it via i2c, I have implemented this using micropython, but on arduino side I found nothing from github.
Any help would be great.
Confusing question. Do you mean you want to replace the L298N with the PCA9685 driving the motor directly from the PCA9685? Or you want to connect the L298N and motor to the PCA9685 for control?
I'm not sure either of them is possible, though they may be with some additional hardware. What exactly are you trying to achieve with this setup?
No, I dont want to replace the motor driver L298n with pca9685. I only want to connect the 6 pins from L298n to pwm pins on pca9685, Also I dont think the pca9685 alone can handle the dc gear motors without a motor driver( atleast to me)
I only want to control the motors via i2c pins from pca9685, I did this on micropython since there is a module there to control servos and dc motors as well.
I'm looking for arduino version on those.
Thanks for the response.
well this is doable but partly more or less a misuse of the pca9685.
The pca9685 has 16 PWM-outputs. But only the enable-pin of the L298 really needs PWM.
Input 1,2,3,4 need a constant voltage beeing +5V or 0,0V.
You can create a "PWM" signal for that which means setting the dutycycle to 100% which results in constant +5V or setting dutycycle to 0% which results in 0,0V.
Electronic professionals and advanced electronic hobbyists don't like fritzing-pictures.
fritzing-pictures add a lot of NON-relevant information. A hand-drawn schematic will do.
In this picture the L298 is used in an unusual way. The inputs are used to create the PWM.
This will only work if the pwm-signals are synchronised to each other. I don't know if they are on this pca9685-chip. Seems to be so. If the PWM-feature is not used which means the code does just switch full on or full off you should use a 16 channel I2C-digital IO-expander like the MCP23017
So all in all what do you want to do? Do you need PWM = controlling the speed of the motor in small steps or is full motor stop motor full throttle sufficient?
Thanks for the quick response, I'm sorry for the picture as I couldn't find any images with arduino in used. Your words gives me a lime light, Can you give me just a single line code for me to start with?
Or Can I control motors in this single line code?:
how the code looks like depends on your application.
So before I post a single line of code give a description in normal words what the functionality shall be
For simplicity, I just want the motor to run fully on or fully off, attaching enA,enB only to pca9685 pwm pins or attaching all the 6 pins to pca9685 pwm pins
in this simpicity leave away the the pca9685 and connect the input1 and input2 straight forward to two IO-pins of the arduino. Same amount of IO-pins needed as with I2C.
This shows that you have no idea yet how the L298 works.
You have to learn some more than just "Alexa drive motor clockwise"
I insist on describing what you want to do in the end.
Maybe I only have a little amount of idea on how this L298n works, but I have attached all the 6 pins of L298n to pca pwm pins, and control the dc gear with its speed and rotate direction using python as I am connecting it to raspberry pi, I can control it with ease.
Now I want to avoid connecting again the 1,2,3,4 pins to arduino, all because I'm using Arduino Due, If the 4 pins not be connected in pca9685 then I will just use level shifter as the signal output of L298n is 5v and Arduino Due operates at 3.3v
I already have 3 servos attached on pca9685 and planning to use unused pwm pins on it with all 6 pins from l298n to avoid using the level shifter to my arduino Due. If I cant find any solution for this, I think I have no choice but add another hardware (level shifter)
very important information you should have posted right in the very first post.
sure there are different solutions
I already described them
If you don't know yet how to do this. It is about time to learn it.
If you don't learn it you would depend on other users knowledge so much that you would have to ask for almost any detail on how to change this or that.
What did you do to learn how to control the pca9685 with your arduino leonardo?
Without any googling I'm 101% sure that there are demo-codes on the web demonstrating this
You should look up such a demo-code. I'm pretty sure that you will have questions.
You are welcome to ask as many questions as you like how to use or to modify the demo-code that you have found.
Thanks, I'm confident that I can modify a code the way I like, I'm ordering an 8 channel biderectional level shifter to handle the 6 pins from L298n to arduino Due IO pins, By the way whole project is using raspberrypi 4 with INTEL NEURAL COMPUTE STICK for ARTIFICIAL INTELLIGENCE only , sending data to arduino DUE serial, A mega 2560 that is busy on processing 3 ultrasonic sensor and 1 tf-luna lidar sensor to be send in arduino DUE serial1
I believe this is important information (from Adafruit):
" Each PWM runs completely independently but they must all have the same PWM frequency. That is, for LEDs you probably want 1.0 KHz but servos need 60 Hz - so you cannot use half for LEDs @ 1.0 KHz and half @ 60 Hz"
..and for the L298n you´ll need a variable PWM...
So, your path (logic level converter + connecting L298n to Arduino) seems to be the a better direction .