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.
