Go Down

Topic: Why won't this sketch work? Using a potentiometer with a motor shield (Read 820 times) previous topic - next topic

compuslave

I'm trying to use a potentiometer to adjust the feedrate of steppers attached to an adafruit motor shield. The pot seems to have no effect.

Code: [Select]

#include <AFMotor.h>

//Setup steppers
AF_Stepper motorY(48, 2);

//setup other variables
int feedrt;
int potpinY = 0;

void setup() {
  Serial.begin(9600);           
  motorY.setSpeed(feedrt); 
}

void loop() {
 
  feedrt = analogRead(potpinY);
  feedrt = map(feedrt, 0, 1023, 0, 179);
  motorY.setSpeed(feedrt);
  motorY.step(100, FORWARD, MICROSTEP);
 
 
}
Never judge a man until you walk a mile in his shoes. But, by that time you're a mile away and you got his shoes, so screw em'

Grumpy_Mike

Try printing out your pot value to see if it is changing.

compuslave

Interesting, it's not. It's at maximum all the time. Why didn't I think to check that?

I've used a pot for servos and other things and never had a problem. Thanks for the tip. I'll see if I can figure out what I've done here.
Never judge a man until you walk a mile in his shoes. But, by that time you're a mile away and you got his shoes, so screw em'

marco_c

You have probably wired it up incorrectly. The wiper terminal goes to the analog input.
Arduino libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com

compuslave

No, that's not it. Like I said I'm pretty familiar with using a pot. Even before I ever had an arduino I had electric guitars, lots of them. Besides, I checked with a meter and I was getting a nice variable voltage with my meter, just not on the serial monitor. Maybe my arduino sustained some damage when I burned out that H-Bridge, because the sketch is right as well. Is that possible, for just one part of the IC to be affected? I have an olimexino stm32 that could stand in should this be in need of a new microcontroller. I also have a brand spanking new Mega2560 that I haven't used yet
Never judge a man until you walk a mile in his shoes. But, by that time you're a mile away and you got his shoes, so screw em'

Grumpy_Mike

Quote
Is that possible, for just one part of the IC to be affected?

Yes that can happen quite a lot with pin abuse.

compuslave

I haven't had time to verify whether my Atmega328 is damaged or not. The only way I know to check it is to hook it up to my Mega and see if it works there. I got a box of solar cells today, so I'm a bit preoccupied 8) But, just looking at my sketch, will it work? Anyone else using a motor shield?

I'm thinking of doing what I did last time I did something like this and just building a simple driver board and hooking that directly to a parallel port being controlled with EMC2. It worked perfectly, this motor shield business seems to be making things harder, not easier.
Never judge a man until you walk a mile in his shoes. But, by that time you're a mile away and you got his shoes, so screw em'

Grumpy_Mike

Quote
But, just looking at my sketch, will it work?

Who can tell, it uses a library that you have not provided a link for. It looks reasonable enough.

Quote
I was getting a nice variable voltage with my meter, just not on the serial monitor.

Then it is either not connected or you pin is shafted. Try using another analogue pin.

Go Up