Hi, I'm new in Arduino... and french Canadian!
My project is to precisely rotate a disk, using a stepper motor and display the RPM on an OLED 128x64. The final usage of the project is to take astro-photos of a pulsar, when it's light is not at full brightness.
My actual problem is that: when I display something on my OLED 128x64, from 'void loop()' it cause my rotating Stepper Motor to be jerky.
As long as I let my script command in the 'void setup() ', it's all good because it only display once and it stays the same.
My second problem is that I would like to replace the ''RPM'' text by the RPM value (motorSpeed), but compil return an error: ''Compilation error: 'motorSpeed' was not declared in this scope''
¨-_-¨ Arduino, it's: Hard We Know!!!!
/*
Stepper Motor Control - speed control
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
A potentiometer is connected to analog input 0.
The motor will rotate in a clockwise direction. The higher the potentiometer value,
the faster the motor speed. Because setSpeed() sets the delay between steps,
you may notice the motor is less responsive to changes in the sensor value at
low speeds.
Created 30 Nov. 2009
Modified 28 Oct 2010
by Tom Igoe
*/
#include <Stepper.h>
// ¨-_-¨ OLED begin
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// ¨-_-¨ OLED end
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0; // number of steps the motor has taken
// ¨-_-¨ OLED begin
// declare an SSD1306 display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// ¨-_-¨ OLED end
void setup() {
// nothing to do inside the setup for stepper sketch
// ¨-_-¨OLED begin
Serial.begin(9600);
// initialize OLED display with address 0x3C for 128x64
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
while (true);
}
delay(2000); // wait for initializing
oled.clearDisplay(); // clear display
oled.setTextSize(2,3); // text size
oled.setTextColor(WHITE); // text color
// ¨-_-¨ 1st line
oled.setCursor(4, 4); // position to display
oled.println("Moteur RPM"); // text to display
// ¨-_-¨ 2nd line
oled.setCursor(40, 44); // position to display
oled.println("*RPM*"); // text to display
oled.display(); // show on OLED
// ¨-_-¨ OLED end
}
void loop() {
// read the sensor value:
int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution (max=200):
myStepper.step(stepsPerRevolution / 100);
}
/*
// ¨-_-¨ OLED begin
oled.clearDisplay(); // clear display
oled.setTextSize(2,3); // text size
oled.setTextColor(WHITE); // text color
// ¨-_-¨ 1st line
oled.setCursor(4, 4); // position to display
oled.println("Moteur RPM"); // text to display
// ¨-_-¨ 2nd line
oled.setCursor(40, 44); // position to display
oled.println(motorSpeed); // text to display
oled.display(); // show on OLED
// ¨-_-¨ OLED end
*/
}