DIY I²C motor driver with Arduino
Verfasst: 23 Apr 2021, 00:32
Hi everyone,
I'm working on a module to control two encoder motors and two servos via I2C. The idea is nothing new, but I want the module to do all the "heavy lifting" so the client code is kept as simple as possible. I'm using the micro:bit as a client, but of course any I2C-capable device should work (ftDuino, TXT, TX-Pi, etc.). One of the main reasons I like the micro:bit is because of MakeCode, it can be simple and powerful at the same time. I'm also quite comfortable with JavaScript, and I've quickly created a simple custom library to help me with my tests:
In terms of hardware, the module should be inexpensive and use components that are readily available. I plan to use an Arduino Pro Mini clone, a generic DRV8833 board (I'm using a L293D for now), and a step-down converter for the module. I also have hardware questions, mainly regarding I/O and power lines protection. But I'll leave those for another post. And I have yet to draw the schematics. Here's my test setup:
What should this module do? At least in ft, encoder motors tend to be configured in a very standard way: A limit switch that sets the home position, two motor outputs, and the counter input. Another common configuration is to use a second limit switch to signal the end position and ignore the counter. I've already tested these and the program works, but I stumbled upon my own limited knowledge of the fine details of actuators, interrupts and the like. Therefore the counter precision is low because I'm only stopping the motor when the limit is reached and nothing else. No dynamic speed control, no PID. In the future also want to be able to move the two motors in sync, improve the speed control (torque is quite low), control the servos and maybe create a learn mode with position slots saved to EEPROM. My I2C commands are:
I'm no I2C specialist at all, so if there are some known standards I'll be glad to use them. The code is published in this GitHub repo. It should be simple enough for the wizards among you to read without even testing it, I'm sure. But of course testing is very welcome as well
My main issues for the moment are: 1) Improving the motor precision; 2) A better way to send commands back to the micro:bit. AFAIK I2C is a multimaster protocol, but I'm not sure how to set up the micro:bit for it. For now I've used a pin to receive events from the Arduino (main.ts, line 38), but I think this is ugly and it also implies an extra wire between the module and the client.
I've already created another DIY module using an old two-wire ultrasonic module as the housing. This is simple enough (see the code at my repo). I have other modules in mind too.
I'll be very glad if this is also useful for someone, I hope some of you like the idea.
Many greetings from Southern Brazil,
Rubem Pechansky
I'm working on a module to control two encoder motors and two servos via I2C. The idea is nothing new, but I want the module to do all the "heavy lifting" so the client code is kept as simple as possible. I'm using the micro:bit as a client, but of course any I2C-capable device should work (ftDuino, TXT, TX-Pi, etc.). One of the main reasons I like the micro:bit is because of MakeCode, it can be simple and powerful at the same time. I'm also quite comfortable with JavaScript, and I've quickly created a simple custom library to help me with my tests:
In terms of hardware, the module should be inexpensive and use components that are readily available. I plan to use an Arduino Pro Mini clone, a generic DRV8833 board (I'm using a L293D for now), and a step-down converter for the module. I also have hardware questions, mainly regarding I/O and power lines protection. But I'll leave those for another post. And I have yet to draw the schematics. Here's my test setup:
What should this module do? At least in ft, encoder motors tend to be configured in a very standard way: A limit switch that sets the home position, two motor outputs, and the counter input. Another common configuration is to use a second limit switch to signal the end position and ignore the counter. I've already tested these and the program works, but I stumbled upon my own limited knowledge of the fine details of actuators, interrupts and the like. Therefore the counter precision is low because I'm only stopping the motor when the limit is reached and nothing else. No dynamic speed control, no PID. In the future also want to be able to move the two motors in sync, improve the speed control (torque is quite low), control the servos and maybe create a learn mode with position slots saved to EEPROM. My I2C commands are:
I'm no I2C specialist at all, so if there are some known standards I'll be glad to use them. The code is published in this GitHub repo. It should be simple enough for the wizards among you to read without even testing it, I'm sure. But of course testing is very welcome as well
My main issues for the moment are: 1) Improving the motor precision; 2) A better way to send commands back to the micro:bit. AFAIK I2C is a multimaster protocol, but I'm not sure how to set up the micro:bit for it. For now I've used a pin to receive events from the Arduino (main.ts, line 38), but I think this is ugly and it also implies an extra wire between the module and the client.
I've already created another DIY module using an old two-wire ultrasonic module as the housing. This is simple enough (see the code at my repo). I have other modules in mind too.
I'll be very glad if this is also useful for someone, I hope some of you like the idea.
Many greetings from Southern Brazil,
Rubem Pechansky