Hello everyone,
I have been making a mini Sumo-bot for competition coming up soon. I have been trying to code QRE1113 Analog line sensors to detect the white ring around the sumo arena to prevent my robot driving off the edge. To drive the motors I have been using the Pololu Motoron M3S256 triple motor controller.
I have been working off of the I2Csimple e.g. code (which works from default ) from the#include <Motoron.h>
library, but when I add the line sensor readings to the void_loop the code the motor controller stops working, the error light coming on and the status light blinking once per second on the motor controller. Despite this, the code complies in the IDE fine. I believe the problem is in the void_loop with the line sensor code with the problem being when I tell the board to assign the values to the variables. Even though this happens to the motors the line sensors still give me constant readings when I use Serial.print(LS2_read);
etc. I am fairly new to ardiuno, so if I have overlooked something obvious don't be surprised.
I have checked all the connections on senors a few times so I don't think it is that, but if that becomes the only answer I can check again
here is the example code from Motoron that works
#include <Motoron.h>
MotoronI2C mc;
void setup()
{
Wire.begin();
// Reset the controller to its default settings, then disable
// CRC. The bytes for each of these commands are shown here
// in case you want to implement them on your own without
// using the library.
mc.reinitialize(); // Bytes: 0x96 0x74
mc.disableCrc(); // Bytes: 0x8B 0x04 0x7B 0x43
// Clear the reset flag, which is set after the controller
// reinitializes and counts as an error.
mc.clearResetFlag(); // Bytes: 0xA9 0x00 0x04
// By default, the Motoron is configured to stop the motors if
// it does not get a motor control command for 1500 ms. You
// can uncomment a line below to adjust this time or disable
// the timeout feature.
// mc.setCommandTimeoutMilliseconds(1000);
mc.disableCommandTimeout();
// Configure motor 1
mc.setMaxAcceleration(1, 140);
mc.setMaxDeceleration(1, 300);
// Configure motor 2
mc.setMaxAcceleration(2, 200);
mc.setMaxDeceleration(2, 300);
}
void loop()
{
if (millis() & 2048)
{
mc.setSpeed(1, 800);
mc.setSpeed(2, -800);
}
else
{
mc.setSpeed(1, -800);
mc.setSpeed(2, 800);
}
}
Here is my code that doesn't work. This code is meant to recognize when either back 2 line sensors read less than the white int and make the robot move forward, away from the edge.(have not added the rest as this didn't work)
#include <Motoron.h>
MotoronI2C mc;
int White = 700;
int Black = 800;
int LS2_read; // A2 reading
int LS3_read; // A3 reading
int LS4_read; // A4 reading
int LS5_read; // A5 reading
#define LS2 A2 //Defineing Line senor pins
#define LS3 A3
#define LS4 A4
#define LS5 A5
void setup()
{
Wire.begin();
// Reset the controller to its default settings, then disable
// CRC. The bytes for each of these commands are shown here
// in case you want to implement them on your own without
// using the library.
mc.reinitialize(); // Bytes: 0x96 0x74
mc.disableCrc(); // Bytes: 0x8B 0x04 0x7B 0x43
// Clear the reset flag, which is set after the controller
// reinitializes and counts as an error.
mc.clearResetFlag(); // Bytes: 0xA9 0x00 0x04
// By default, the Motoron is configured to stop the motors if
// it does not get a motor control command for 1500 ms. You
// can uncomment a line below to adjust this time or disable
// the timeout feature.
// mc.setCommandTimeoutMilliseconds(1000);
mc.disableCommandTimeout();
// Configure motor 1
mc.setMaxAcceleration(1, 140);
mc.setMaxDeceleration(1, 300);
// Configure motor 2
mc.setMaxAcceleration(2, 140);
mc.setMaxDeceleration(2, 300);
}
void loop()
{
LS2_read= analogRead(LS2);
LS3_read= analogRead(LS3);
LS4_read= analogRead(LS4);
LS5_read= analogRead(LS5);
if (LS4_read < White || LS5_read < White) {
mc.setSpeed (1, 800);
mc.setSpeed(2, -800);
}
else
{
mc.setSpeed(1, -800);
mc.setSpeed(2, 800);
}
delay(10);
Any suggestions would be great as I have been stuck for a couple of days on this
My specs are:
- Arduino Uno R4 wifi
- M3S256 Motoron motor controller
- 2x yellow geared 12V DC motors
- 2x rechargeable 9V batteries in parallel connected to the motor controller
- 4x QRE1113 Analog line sensors in pins A2, A3, A4, A5
- solder-less breadboard