Hello, I was very active around 10 years ago when I taught robotics. However since I retired, it is like starting from scratch and I need some help. I am making a drive system for a Sand Buggy to transport scuba equipment from the car to the shore using an arduino with a qwiic shield to enable an easy i2c network… Each controller and the joystick identify as an address on the i2c network. And I can run the instruction manual’s arduino i2c example program, addressing one controller at a time… The problem is that I want to control both controllers at the same time. I don’t know what I am missing. Can someone show me a bare bones example of how I could run both controllers passing independent speed variables to each controller separately? Many thanks in advance.
Not the cleanest method in the world but it works. It is a shame that C won’t allow you to next functions or I could have made it smaller. I wanted to use the Sparkfun Qwiic connect system because it appears to be able to take some vibration instead of conventional jumper wires. The idea of using a single joystick instead of a skid steer, tank drive type method is my next biggest coding problem. FYI, this thing I am building is a folding six wheel (balloon tire) articulated sand cart that looks like the Mars rover. My code is below.
#include <Wire.h>
// code for first smc g2
void exitSafeStart()
{
Wire.beginTransmission(13);
Wire.write(0x83); // Exit safe start
Wire.endTransmission();
}
void setMotorSpeed(int speed)
{
uint8_t cmd = 0x85; // Motor forward
if (speed < 0)
{
cmd = 0x86; // Motor reverse
speed = -speed;
}
Wire.beginTransmission(13);
Wire.write(cmd);
Wire.write(speed & 0x1F);
Wire.write(speed >> 5 & 0x7F);
Wire.endTransmission();
}
// code for second smc g2
void exitSafeStart2()
{
Wire.beginTransmission(14);
Wire.write(0x83); // Exit safe start
Wire.endTransmission();
}
void setMotorSpeed2(int speed2)
{
uint8_t cmd2 = 0x85; // Motor forward
if (speed2 < 0)
{
cmd2 = 0x86; // Motor reverse
speed2 = -speed2;
}
Wire.beginTransmission(14);
Wire.write(cmd2);
Wire.write(speed2 & 0x1F);
Wire.write(speed2 >> 5 & 0x7F);
Wire.endTransmission();
}
void setup()
{
Wire.begin();
exitSafeStart();
}
void loop()
{
int speed = 0; //speed variable supplied by joystick routine
int speed2 = 0; //speed variable supplied by joystick routine
setMotorSpeed(speed); //Right tram motor
setMotorSpeed2(speed2); //Left tram motor
}
Hello.
I am glad to see that you are making progress! Your project sounds exciting, and we would love to see pictures of it once you have things assembled and working. A new thread in the “Share Your Projects” category would be a good place for that.
A quick tip for your next coding challenge regarding the joysticks, what you are talking about is usually called “mixing,” so you should find a lot of useful advice if you internet search something like “mixing joystick signals.”
- Patrick