my students bought a bricktronics shield a few weeks ago, they are going to participate in a sumo competition in Alcazar de San Juan (Spain), they aren´t good a programing arduino but they decided to use one old nxt lego kit with arduino.
If some of you has a code for this we will be graceful, we have tried to use drawbot.
Hello, thanks for your message. The drawbot code example should be a good introduction to the different concepts of building a robot with Arduino, for example motor control and button sensors.
Is there something specific that your students are experiencing difficulty with? What is the general behavior you want for the sumo competition?
Hello, to create our sumo robot we have based on drawbot, I copy our code, but the robot only move forward but no detecte nothing with ultrasonic, furthermore light sensor does not work:
//Libraries
#include <BricktronicsShield.h>
#include <BricktronicsButton.h>
#include <BricktronicsMotor.h>
#include <BricktronicsUltrasonic.h>
#include <BricktronicsLight.h>
#include <Wire.h>
//setup
//motors
BricktronicsMotor ml (BricktronicsShield::MOTOR_1);
BricktronicsMotor mr (BricktronicsShield::MOTOR_2);
//UltraSonic
BricktronicsUltrasonic u(BricktronicsShield::SENSOR_3);
//light sensor
BricktronicsLight ls(BricktronicsShield::SENSOR_4);
//Button
BricktronicsButton b (BricktronicsShield::SENSOR_1);
void setup()
{
// Be sure to set your serial console to 115200 baud
Serial.begin(115200);
// Initialize the Bricktronics Shield--I think this is the Ic2 stuff
BricktronicsShield::begin();
//Initialize the ultrasonic Sensor
u.begin();
//initialize light
ls.begin();
//Initalize motors
ml.begin();
mr.begin();
//Initalize button
//b.begin();
}
void competicion()
{
//Comenzar de la competicion, back until black line
while (ls.value() > 200) {
ml.setFixedDrive(-100);
mr.setFixedDrive(-100);
}
ml.setFixedDrive(0);
mr.setFixedDrive(0);
}
void updateMotors()
{
//This is to make sure that we are keeping track
//of the motor position during the program
ml.update();
mr.update();
}
void loop(){
Serial.println(u.getDistance());
delay(100);
if (b.isPressed())
{
competicion();
}
while (b.isReleased())
if(ls.value() < 200){
ml.setFixedDrive(-50);
mr.setFixedDrive(50);
}else{
if (u.getDistance() > 15){
ml.setFixedDrive(-50);
mr.setFixedDrive(50);
delay (500);
ml.setFixedDrive(50);
mr.setFixedDrive(-50);
delay (500);
}else{
ml.setFixedDrive(255);
mr.setFixedDrive(255);
}
}
Serial.println(u.getDistance());
delay(100);
}
Hello, thanks for sharing code. I think the first suggestion is to try each of the sensors independently, to ensure they are generating the correct values you expect. Try one of the example sketches for each sensor type, to see if it is working correctly. Also, ensure that the jumper pins are set correctly for the light sensor (2-3 and 4-5) and ultrasonic sensor (1-2 and 4-5).
You don’t have to unplug any motors or sensors to try out the individual example code. For example, here is a quick sketch to test light sensor values:
#include <BricktronicsShield.h>
#include <BricktronicsLight.h>
#include <Wire.h>
BricktronicsLight ls(BricktronicsShield::SENSOR_4);
void setup()
{
// Be sure to set your serial console to 115200 baud
Serial.begin(115200);
// Initialize the Bricktronics Shield
BricktronicsShield::begin();
//initialize light
ls.begin();
}
void loop()
{
Serial.print(ls.value());
}
With this code sketch you should test the light sensor is working correctly.