Hello everyone. I have a code that works for my X/Y stepper control. I am using a joystick to control them. I would like to add a simple code that will display the x and y steps that have been taken but be able to reset it with the select button of the joystick. I am not using any limit switches or anything so X0 and Y0 can start anywhere on the stepper. I hope that makes sense. Here is the components I am using with my Uno.
Display
Joystick
and finally the code:
#include <Stepper.h>
#define STEPS 2000 // the number of steps in one revolution of your motor (28BYJ-48)
Stepper stepper(STEPS, 8, 10, 9, 11);
Stepper stepper1(2000, 2, 4, 3, 5);
int potState = 0;
int pot1State = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
potState = analogRead(A0); //reads the values from the potentiometers
pot1State = analogRead(A1); //
Serial.println(pot1State); // sends joystick data to serial port for debuging
stepper.setSpeed(100);
stepper1.setSpeed(100);
if (potState > 600){ //all code below controls movement
stepper.step(1000);
}
if (potState < 400){
stepper.step(-1000);
}
if (pot1State < 400){
stepper1.step(-1000);
delay(5);
}
if (pot1State > 600){
stepper1.step(1000);
}
}
I guess I should have mentioned, this is my first time using an LCD readout. I read up on the basics but I do not know what to do about getting the data from the steps taken, nor how to reset the step count.
When I said simple, I am wanting something like this:
When powered on first time:
X Axis = 0.000
Y Axis = 0.000
Then after steps are counted, and the user wants to reset it they press the select button on the joystick to reset the display (not move the steppers).
The stepper library is pretty basic and doesn't appear to keep a step count (at least looking at the reference).
You could write your own wrapper for the library's step function and have that do the counting. Alternatively, look for a more sophisticated library, maybe Accelstepper.
Hi, I have a SSD1306 test sketch downloadable off my site. This shows how an 128x32 SSD1306 is used. https://www.bezelsanddisplays.co.uk/ See the download link/