Arduino video of turning and spinning motors

Here’s a video of my Arduino robot with some nextrox motors attached to Di servo servos. This is so it can turn and also move forward or backward.

https://youtu.be/4bpG65nveMk

 

Here’s the code:

 

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

//SERVO SECTION
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

//for servo 0
#define MIN_PULSE_WIDTH_0 900
#define MAX_PULSE_WIDTH_0 1800

//for servo 1
#define MIN_PULSE_WIDTH_1 900+100
#define MAX_PULSE_WIDTH_1 1800+100

//for servo 2
#define MIN_PULSE_WIDTH_2 900-250
#define MAX_PULSE_WIDTH_2 1800-250

//for servo 3
#define MIN_PULSE_WIDTH_3 900-250
#define MAX_PULSE_WIDTH_3 1800-250

#define FREQUENCY 50
//50 for digital

//DC MOTOR SECTION
//Motor A
const int motorPin1 = 9; // Pin 14 of L293
const int motorPin2 = 10; // Pin 10 of L293
//Motor B
const int motorPin3 = 6; // Pin 7 of L293
const int motorPin4 = 5; // Pin 2 of L293

//Motor C
const int motorPin5 = 14;
const int motorPin6 = 15;

//Motor D
const int motorPin7 = 16;
const int motorPin8 = 17;

void setup() {
Serial.begin(9600);

//DC MOTOR SECTION
pwm.begin();
pwm.setPWMFreq(FREQUENCY); // Analog servos run at ~60 Hz updates

//SERVO STUFF
//Set pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);

pinMode(motorPin5, OUTPUT);
pinMode(motorPin6, OUTPUT);
pinMode(motorPin7, OUTPUT);
pinMode(motorPin8, OUTPUT);

delay(1000);
}

//SERVO SECTION
void turnServo(int channel, int angle) {
pwm.setPWM(channel, 0, pulseWidth(channel, angle));
}

void turnServosLeft() {
//turn servos to 0
turnServo(0, 0);
turnServo(1, 0);
turnServo(2, 0);
turnServo(3, 0);
delay(2000);
}

void turnServosRight() {
//turn servos to 180
turnServo(0, 180);
turnServo(1, 180);
turnServo(2, 90);
turnServo(3, 90);
delay(2000);
}

void setServosStraight() {
turnServo(0, 90);
turnServo(1, 90);
turnServo(2, 90);
turnServo(3, 90);
delay(1000);
}

int pulseWidth(int channel, int angle)
{
int MY_MIN_PULSE_WIDTH;
int MY_MAX_PULSE_WIDTH;

if(channel ==0) {
MY_MIN_PULSE_WIDTH=MIN_PULSE_WIDTH_0;
MY_MAX_PULSE_WIDTH=MAX_PULSE_WIDTH_0;
}
else if(channel == 1) {
MY_MIN_PULSE_WIDTH=MIN_PULSE_WIDTH_1;
MY_MAX_PULSE_WIDTH=MAX_PULSE_WIDTH_1;
}
else if(channel == 2) {
MY_MIN_PULSE_WIDTH=MIN_PULSE_WIDTH_2;
MY_MAX_PULSE_WIDTH=MAX_PULSE_WIDTH_2;
}
else if(channel == 3) {
MY_MIN_PULSE_WIDTH=MIN_PULSE_WIDTH_3;
MY_MAX_PULSE_WIDTH=MAX_PULSE_WIDTH_3;
}

int pulse_wide, analog_value;
pulse_wide = map(angle, 0, 180, MY_MIN_PULSE_WIDTH, MY_MAX_PULSE_WIDTH);

analog_value = int(float(pulse_wide) / 1000000 * FREQUENCY * 4096);
Serial.println(analog_value);
return analog_value;
}

//END SERVO SECTION

//DC MOTOR SECTION
void goForwardWithMotorA() {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
}

void goForwardWithMotorB() {
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
}

void goForwardWithMotorC() {
digitalWrite(motorPin5, LOW);
digitalWrite(motorPin6, HIGH);
}

void goForwardWithMotorD() {
digitalWrite(motorPin7, LOW);
digitalWrite(motorPin8, HIGH);
}

void goBackWithMotorA() {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
}

void goBackWithMotorB() {
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
}

void goBackWithMotorC() {
digitalWrite(motorPin5, HIGH);
digitalWrite(motorPin6, LOW);
}

void goBackWithMotorD() {
digitalWrite(motorPin7, HIGH);
digitalWrite(motorPin8, LOW);
}

void goForwardWithDCMotors() {
//motor a
goForwardWithMotorA();

//motor b
goForwardWithMotorB();

//motor c
goForwardWithMotorC();

//motor d
goForwardWithMotorD();

}

void goBackWithDCMotors() {
//motor a
goBackWithMotorA();

//motor b
goBackWithMotorB();

//motor c
goBackWithMotorC();

//motor d
goBackWithMotorD();
}

void stopDCMotors() {

analogWrite(motorPin1, 0);
analogWrite(motorPin2, 0);
analogWrite(motorPin3, 0);
analogWrite(motorPin4, 0);

analogWrite(motorPin5, 0);
analogWrite(motorPin6, 0);
analogWrite(motorPin7, 0);
analogWrite(motorPin8, 0);
}

void rightSideDCMotorsBackward() {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
}

void leftSideDCMotorsBackward() {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
}

//END DC MOTOR SECTION

void loop() {

setServosStraight();

goForwardWithDCMotors();

delay(2000);

stopDCMotors();

turnServosLeft();

}

Robot progress

Here are some pics of my project so far. I got some servo mounts from ServoCity and they are mounted in order to turn the other motors. They turn on carpet in tandem which is pretty cool. I am waiting on a 1/4 20 tap to connect the plexiglass to the 80 20 pieces.

Voltage Regulator for PCA9685 board and 7+ volt power supply

In my previous post https://blog.andytriboletti.com/which-servo-motor-im-using-for-my-arduino-project/ I mentioned I had a problem with the servo controller board I was using.

I followed the instructions here:
http://wiki.sunfounder.cc/index.php?title=PCA9685_16_Channel_12_Bit_PWM_Servo_Driver

It says to use a max of 6 volts.

It also says to use -2 x 18650 Li-on Batteries which equal over 7 volts.

Since the board started smoking when the servo was hitting against the wheel, I decided to try a couple different things.

-Write an email to the people who wrote the wiki
-Buy a voltage regulator. I searched Amazon for “Voltage regulator” and found this:
https://smile.amazon.com/gp/product/B01GJ0SC2C.
-Stop causing the servo to hit against the wheel by buying a new regulator that didn’t have the problem of moving without instructions.
-Bought a replacement servo controller board. https://smile.amazon.com/SunFounder-PCA9685-Channel-Arduino-Raspberry/dp/B014KTSMLA/

Magic orchid cloning stuff

Amazon recommended me “Keiki Power Pro Orchid Plant Cloning Paste” today. I like orchids.

I ran the site through fakespot.com and it got an A.

https://smile.amazon.com/dp/B00948K1J4

I bought it directly from the company instead of Amazon. I will let you know if it works.

 

Update 12/2/2018: It didn’t work for me.

It has a bit less memory than it used to, since some corrupted sectors had to be quarantined?

“…though it has a bit less memory than it used to, since some corrupted sectors had to be quarantined.”

Mars Rover Curiosity is switching brains so it can fix itself

What does that mean?

Which servo motor I’m using for my Arduino project

I purchased 2 different kinds of servo motors for my robot Arduino project.

One on Amazon:

https://smile.amazon.com/gp/product/B076CNKQX4

Four on Ebay.

They both arrived quickly.

I tried using the four on Ebay first.

“4PCS Digital MG996R MG995 High Torque Metal Gear Servo For Racing Futaba JR RC”

 

Eventually the pwm servo driver board I was using started smoking. I sent the people who make the board, SunFounder an email:

“I bought a SunFounder PCA9685 16 Channel 12 Bit PWM Servo Driver for Arduino and Raspberry Pi  on Amazon for 11.99.

I followed the instructions here:

 

After awhile, the 9685 board started smoking. I was wondering what it could be? I was trying to adjust the min/max of the servo and noticed every time I restarted the power it would rotate a bit in one direction consistently. I think that’s a bug in the software. I Googled and found someone who had the same problem.

 

I also have this problem:

 

 

I was also wondering if the voltage from that wiki page could be too high?

 

I think without some help if I bought another 9685 board it would just start smoking too and be ruined.

 

It did work for awhile, but I tried running the example code where you could set the min and max and it knocked up against the metal not being able to move.

 

I attached a picture. The smoking came from the component to the left of the word power.”
I then bought a new SunFounder PCA9685 servo controller board and tried the one on Amazon. It did not move when I first gave it power, like the one from Ebay.

 

The ones on Amazon “ANNIMOS 20KG Digital Servo High Torque Full Metal Gear Waterproof for RC Model DIY, DS3218MG,Control Angle 270°” were 4 times more expensive than the Ebay MG 996R ones I found on Ebay, but the DS3218MG works better for my application.