New to stepper motors.. trying to tie GPS into stepper mapping

Hi there,

I’ve found some excellent examples online of TinyGPS++ along with some stepper motor examples. What i’ve managed to do so far is get the GPS itself to set a motor speed and start making tiny steps depending on where it is going forward. But since the GPS doesn’t have a “you’re slowing down now, so you’re actually needing to go back”, I’m having a hard time wrapping my head around how to get the stepper motor to go back.

Here’s the code i’ve ran so far with a mixture of different examples I’ve found online through the tinygps++ library along with some arduino examples. So far, this seems to actually give me the ability to get the stepper motor to move forward slightly. But nothing else.

#include <Stepper.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>

// The TinyGPS++ object
TinyGPSPlus gps;

SoftwareSerial ss(12, 3, false);

const int STEPS = 600; // change this to fit the number of steps per revolution
const int TEST = 100;
int stepCount = 0;

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(STEPS, 4, 5, 6, 7);

void setup() {
// initialize the serial port:
{
Serial.begin(115200);
ss.begin(9600);
}
}

void loop() {

int sensorReading = gps.speed.mph();
Serial.print(“Miles Per Hour=”);
Serial.print(sensorReading);
int motorSpeed = map(sensorReading, 0, 180, 0, 100);

if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);

myStepper.step(-STEPS / 100);
}

}

This doesn’t actually control anything that’s calibrated though.

So in this case, if the motorspeed is above 0, which is determined by yanking the tinygps++ mph mark, and then the stepper motor goes up in steps, faster if you go faster, but with no actual ability to map it to a specific mph.

If I’m going 5, I want it to step up 10 steps. If I’m going 10mph I want it to jump another 10 steps. If I slow down and my speed goes down, I want it to be able to reduce the steps and go back one value.

I’m at a bit of a hair pull on this one because I’ve never worked with stepper motors on this. I also thing mine /may/ be wired in backwards as it seems to go /forward/ with -values and backwards with +values.

If this sounds incredibly stupid, you have my apologies. I’m still learning this stuff. I did manage to get it to at least move one one little 5mph scoot down the road while I had someone hold the mess of wires and we got, “HEY IT’S MOVING!”

So I know the GPS recall for MPH in TinyGPS++ works, and the stepper motor seems to be fine. But I’m at a loss on how to specifically loop this in a manner where I can get precise angles.

I read on adafruit’s website that this automotive stepper motor gauge does 600 steps per rotation, 1 rotation is a full 315 degrees. I’m going to be using closer to only 300 degrees on my gauge. So if I chop that down I’m close to 2 steps per 1mph on that rotation, it’s more like 1.9.

I don’t expect anyone to write anything for me, but if anyone has any recommendations on what functions I need to read up on since I’m new to this, I would greatly appreciate learning.

TheJalpa:
So in this case, if the motorspeed is above 0, which is determined by yanking the tinygps++ mph mark, and then the stepper motor goes up in steps, faster if you go faster, but with no actual ability to map it to a specific mph.

Are you trying to use the stepper motor to move the needle on a speedometer? It would help to say so. Or else explain what the motor is intended to do.

If it is a speedometer you don't want to change the stepper's speed to match the MPH value, you need to change its position.

You don't seem to have any code to get the motor to move to the ZERO position to start. Then you need to figure how many steps are required to get to the max indicated speed. And then you can relate the position between 0 and the max to the GPS speed.

...R
Stepper Motor Basics
Simple Stepper Code

Sounds like you need the programmed stepper position to match a variable set from the GPS.

Using AccelStepper that would be just:

void loop ()
{
  stepper.run() ;  // call everytime round loop
  handle_gps () ; // do whatever the GPS stuff needs
  stepper.moveTo (gps_mph) ; // ensure the stepper target position is what you want
}

Robin2:
Are you trying to use the stepper motor to move the needle on a speedometer? It would help to say so. Or else explain what the motor is intended to do.

If it is a speedometer you don't want to change the stepper's speed to match the MPH value, you need to change its position.

You don't seem to have any code to get the motor to move to the ZERO position to start. Then you need to figure how many steps are required to get to the max indicated speed. And then you can relate the position between 0 and the max to the GPS speed.

...R
Stepper Motor Basics
Simple Stepper Code

Yes, apologies. The stepper motor is being used to drive the needle on a speedometer. I'll check these pages and review. Thank you.

MarkT:
Sounds like you need the programmed stepper position to match a variable set from the GPS.

Using AccelStepper that would be just:

void loop ()

{
  stepper.run() ;  // call everytime round loop
  handle_gps () ; // do whatever the GPS stuff needs
  stepper.moveTo (gps_mph) ; // ensure the stepper target position is what you want
}

I read about a few stepper libraries, sounds like i need to look up AccellStepper, I will go take a look at that this morning.

Thank you both for your time, apologies if some of my stuff was confusing, I'm brand new to this stepper motor use. It'd be 10x easier to have already thrown it on an LCD but I want analog looking gauges to use.

You might find this automotive gauge stepping motor interesting. Example code is posted.

jremington:
You might find this automotive gauge stepping motor interesting. Example code is posted.

That is the exact H-Bridge and stepper motor i'm using.