Pages: [1]   Go Down
Author Topic: Why won't this sketch work? Using a potentiometer with a motor shield  (Read 633 times)
0 Members and 1 Guest are viewing this topic.
Hyperspace
Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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);
 
 
}
Logged

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'

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31366
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Hyperspace
Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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'

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 27
Posts: 1179
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You have probably wired it up incorrectly. The wiper terminal goes to the analog input.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Hyperspace
Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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'

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31366
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is that possible, for just one part of the IC to be affected?
Yes that can happen quite a lot with pin abuse.
Logged

Hyperspace
Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-cool 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.
Logged

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'

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31366
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: