I have an arduino mega 1280 using a motor shield from seeedstudio SLD80256P powered by a 7.2 1300mAh rc battery pack attached to two dc motors. It works fine with the manufacturers arduino code. I want to add a sonic range finder but with the attached shield i cannot add the sonic range finder using normal vss, gnd, pins. The shield has covered them up. There are four pin connectors all around the board labelled G, V, A1, A0, for one four pinout, then G, V, A2, A3, and going up to only G, V, A4, A5. Same with the digital pins G, V, D1, D2 ect.... Am i safe to assume that if i use a parralax servo or range finder with a three pin attachment that i only want to connect to G, V, D1 / G, V, A1 with a modified pin out to the sonic range finder. Then specify this with my arduino code? any help would be greatful.. Actually now that I think about it, might have answered my own question by only attaching the three pins to range finder using G, V, D1. Thanks to all that provide answers or same questions. Thanks to LuckyLarry, et al. for inspiration. Techdetect
I was able to get this working. Not much change, just had to read a little bit more. It works, thanks… Sorry, didn’t post code. here it is… using IDE 1.0.1 w/ two futaba s3003 servos w/ parallax ping ()() giving a little back from all the post here. THanks Lucky Larry for your inspiration…
#include <Ping.h>
const int numOfReadings = 10; // number of readings to take/ items in the array
int readings[numOfReadings]; // stores the distance readings in an array
int arrayIndex = 0; // arrayIndex of the current item in the array
int total = 0; // stores the cumlative total
int averageDistance = 0; // stores the average value
// setup pins and variables for SRF05 sonar device
const int pingpin = 2; // ping pin (digital 2 pin)
unsigned long pulseTime = 0; // stores the pulse in Micro Seconds
unsigned long distance = 0; // variable for storing the distance (cm)
int motor1Pin1 = 8; // one of leads from DC motor
int motor1Pin2 = 11; // pin 7 on L293D
int enable1Pin = 9; // pin 1 on L293D
int motor2Pin1 = 12; // pin 10 on L293D
int motor2Pin2 = 13; // pin 15 on L293D
int enable2Pin = 10; // pin 9 on L293D
int spead =100;//define the spead of motor origionally set at 127.
void setup() {
// set the motor pins as outputs:
Serial.begin(115200);
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(enable1Pin, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(enable2Pin, OUTPUT);
// set enablePins high so that motor can turn on:
digitalWrite(enable1Pin, HIGH);
digitalWrite(enable2Pin, HIGH);
pinMode(pingpin, OUTPUT);
pinMode(pingpin, INPUT);
// create array loop to iterate over every item in the array
for (int thisReading = 0; thisReading < numOfReadings; thisReading++) {
readings[thisReading] = 0;
}
}
void loop() {
Serial.println();
Serial.print("in, ");
pinMode(pingpin, OUTPUT);
digitalWrite(pingpin, HIGH); // send 10 microsecond pulse
delayMicroseconds(10); // wait 10 microseconds before turning off
digitalWrite(pingpin, LOW); // stop sending the pulse
pinMode(pingpin, INPUT);
pulseTime = pulseIn(pingpin, HIGH); // Look for a return pulse, it should be high as the pulse goes low-high-low
distance = pulseTime/58; // Distance = pulse time / 58 to convert to cm.
total= total - readings[arrayIndex]; // subtract the last distance
readings[arrayIndex] = distance; // add distance reading to array
total= total + readings[arrayIndex]; // add the reading to the total
arrayIndex = arrayIndex + 1; // go to the next item in the array
// At the end of the array (10 items) then start again
if (arrayIndex >= numOfReadings) {
arrayIndex = 0;
}
averageDistance = total / numOfReadings; // calculate the average distance
delay(10);
// check the average distance and move accordingly
if (averageDistance <= 23){
// go backwards
analogWrite(enable1Pin,spead);//input a simulation value to set the speed
analogWrite(enable2Pin,spead);
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, HIGH);
digitalWrite(motor2Pin2, LOW);
}
if (averageDistance <= 33 && averageDistance > 23) {
// turn
analogWrite(enable1Pin,spead);//input a simulation value to set the speed
analogWrite(enable2Pin,spead);
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, HIGH);
}
if (averageDistance > 33) {
// go forward
analogWrite(enable1Pin,spead);//input a simulation value to set the speed
analogWrite(enable2Pin,spead);
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, HIGH);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, HIGH);
}
}
Does anyone actually read and reply to these post. If anyone has a this motor shield and can provide some insight that would be great. Thanks, last night i fried an led on one of the digital pins using 9v walwart powering the shield from the arduino.
On the shield were the white pins are (four pins per white connetion on motor shield) there seem to be overlapping digital pins and analog pins. Any help would be greatful.
Thanks to all.