Well, it's been a couple of weeks since my ADABOX006 kit arrived. I was busy with the latest IOT Virtual Bootcamp, Dec. 12-14th, 2017, sponsored by ADAFRUIT, Microsoft/Azure Services, Hackster IO and the Raspberry Pi Foundation. This was again an interesting 3 days....16 hour days actually and thankfully I had taken the week off from my day job (but actually had to supply phone support for some issues). It has been three months since I started this build...too many distractions..
Back to this build. The ADABOX006 had featured the Circuit Playground Express board that I had not played with or had done coding for before. I had watched a few videos last summer when the board 1st was released. Lady ADA incorporated, many sensors and features to learn and explore but those would not be part of this initial build.
Basically, I would be using the Circuit Playground Express, a L9110 motor controller, 2 or 4 DC motors (depending upon which platform i use.... those of you who are followers know I have alot of hardware to pick from and I never like to take apart a robot) and a generic Robot base/platform. Possibly adding an Ultrasonic sensor and a servo to make it autonomous.
I will reuse previous Arduino code from other builds (and by other authors) to test subassemblies as I build it up.
Along the way, things didn't work...cheap yellow motors...decided to use a 2 wheeled vs a 4 wheeled platform. I wanted to incorporate LM393 speed sensors but the CPE was short one input pad. I used an UNO to do preliminary testing of code (I don't know why...it was there) and final code would be run on the CPE once the build was complete. Space and layout and features and code snippets were changing causing further delays.
My daytime real job drew excessive time from my project time....
But I made progress...
From the above "taking shape" assembly, I began testing code snippets...
Code:
#include <Servo.h> //Servo motor library. This is standard library
#include <NewPing.h> //Ultrasonic sensor function library. You must install this library
//#include <Ultrasonic.h>
//our L298N L9110 control pins
//const int LeftMotorForward = 10; //A3 5
//const int LeftMotorBackward = 9; //A2 6
//const int RightMotorForward = 6; //A1 11
//const int RightMotorBackward = 12; //A0 12
const int AIA = 10; //A3 5
const int AIB = 9; //A2 6
const int BIA = 6; //A1 11
const int BIB = 12; //A0 12
byte speed = 255;
//sensor pins
#define trig_pin 3 //analog input 1 A0 A6 9
#define echo_pin 4 //analog input 2 A1 A7 10
#define maximum_distance 300
boolean goesForward = false;
int distance = 100;
NewPing sonar(trig_pin, echo_pin, maximum_distance); //sensor function
Servo servo_motor; //our servo name
void setup(){
//pinMode(RightMotorForward, OUTPUT);
//pinMode(LeftMotorForward, OUTPUT);
//pinMode(LeftMotorBackward, OUTPUT);
//pinMode(RightMotorBackward, OUTPUT);
pinMode(AIA, OUTPUT);
pinMode(AIB, OUTPUT);
pinMode(BIA, OUTPUT);
pinMode(BIB, OUTPUT);
Serial.begin(9600); // Starts the serial communication
servo_motor.attach(11); //our servo pin A5 13
servo_motor.write(115);
delay(2000);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
}
void loop(){
int distanceRight = 0;
int distanceLeft = 0;
delay(50);
if (distance <= 20){
moveStop();
delay(300);
moveBackward();
delay(400);
moveStop();
delay(300);
distanceRight = lookRight();
delay(300);
distanceLeft = lookLeft();
delay(300);
if (distance >= distanceLeft){
turnRight();
moveStop();
}
else{
turnLeft();
moveStop();
}
}
else{
moveForward();
}
distance = readPing();
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}
int lookRight(){
servo_motor.write(50);
delay(500);
int distance = readPing();
delay(100);
servo_motor.write(115);
return distance;
}
int lookLeft(){
servo_motor.write(170);
delay(500);
int distance = readPing();
delay(100);
servo_motor.write(115);
return distance;
delay(100);
}
int readPing(){
delay(70);
int cm = sonar.ping_cm();
if (cm==0){
cm=250;
}
return cm;
}
void moveStop(){
//analogWrite(RightMotorForward, 0);
//analogWrite(LeftMotorForward, 0);
//analogWrite(RightMotorBackward, 0);
//analogWrite(LeftMotorBackward, 0);
analogWrite(AIA, 0);
analogWrite(AIB, 0);
analogWrite(BIA, 0);
analogWrite(BIB, 0);
}
void moveForward(){
if(!goesForward){
goesForward=true;
//analogWrite(LeftMotorForward, 90);
//analogWrite(RightMotorForward, 95);
//analogWrite(LeftMotorBackward, 0);
//analogWrite(RightMotorBackward, 0);
analogWrite(AIA, speed);
analogWrite(AIB, 0);
analogWrite(BIA, speed);
analogWrite(BIB, 0);
}
}
void moveBackward(){
goesForward=false;
//analogWrite(LeftMotorBackward, 90);
//analogWrite(RightMotorBackward, 95);
//analogWrite(LeftMotorForward, 0);
//analogWrite(RightMotorForward, 0);
analogWrite(AIA, 0);
analogWrite(AIB, speed);
analogWrite(BIA, 0);
analogWrite(BIB, speed);
}
void turnRight(){
//analogWrite(LeftMotorForward, 90);
//analogWrite(RightMotorBackward, 95);
//analogWrite(LeftMotorBackward, 0);
//analogWrite(RightMotorForward, 0);
analogWrite(AIA, speed);
analogWrite(AIB, 0);
analogWrite(BIA, 0);
analogWrite(BIB, speed);
delay(450);
//analogWrite(LeftMotorForward, 90); //(AIA, speed)
//analogWrite(RightMotorForward, 95); //(BIA, speed)
//analogWrite(LeftMotorBackward, 0); //(AIB, 0)
//analogWrite(RightMotorBackward, 0); //(BIB, 0)
analogWrite(AIA, speed);
analogWrite(AIB, 0);
analogWrite(BIA, speed);
analogWrite(BIB, 0);
}
void turnLeft(){
//analogWrite(LeftMotorBackward, 90); //(AIB, 0)
//analogWrite(RightMotorForward, 95); //(BIA, speed)
//analogWrite(LeftMotorForward, 0); //(AIA, speed)
//analogWrite(RightMotorBackward, 0); //(BIB, 0)
analogWrite(AIA, 0);
analogWrite(AIB, speed);
analogWrite(BIA, speed);
analogWrite(BIB, 0);
delay(450);
//analogWrite(LeftMotorForward, 90); //(AIA, speed)
//analogWrite(RightMotorForward, 95); //(BIA, speed)
//analogWrite(LeftMotorBackward, 0); //(AIB, 0)
//analogWrite(RightMotorBackward, 0); //(BIB, 0)
analogWrite(AIA, speed);
analogWrite(AIB, 0);
analogWrite(BIA, speed);
analogWrite(BIB, 0);
}
Now the set-backs... yellow motor left hand side does not drive/spin well or at all... I need to dig through my boxes of components to find more....HC-SR04 needed mounting holes enlarged (but you knew they would)...figuring how to split the battery box into two separate supplies...
I needed to locate metal eyelets, screws, washers and nuts to be used to connect "dupont wires" from accessories to Circuit Playground Express...
Its again been a few weeks..2 months actually... since revisiting this build. Needed to create jumpers to tie all grounds together, Then build 2k/1k resistor voltage divider jumper for HC-SR04 sensor to go from "ECHO" to Circuit Playground Express pin (the echo return will be a 3.3vdc pulse that can be processed via the code).
I am powering this build with separate 3 power packs; two (2x3.7vdc batteries-18650 Li-Ion) each: 1st to "5vdc regulator" for servo and HC-SR04 and 2nd to DC Motor/L9110S and 3rd 3.7vdc Lipo from Adafruit for Circuit Playground Express.
There is enough "juice" on Desktop to test code and Motor functions and reaction to HC-SR04 and obstacles, but these "old" batteries don't last long enough on floor with the higher DC motor current draw from my left wheel.
At least it all works now. My cable management could be alot better (using shorter wires) and a better support with standoffs for the Circuit Playground Express board. Most of all, better access to batteries or a different power schema...or even a 2nd/top platform for the CPE
Comments
Please log in or sign up to comment.