Please review my Push-up code

Hello,

I am doing an internship at a company where I was given the assignment to repair a ‘tiger stop’. A ‘tigerstop’ is a push-up system that pushes a desired length in order to be able to saw off. The function of this tool is simple, you type a measurement on the keypad which is showed in a LCD display and the controller motor.

the problem i have now is arduino doesn’t know what ‘POSITIVE’ means. I thought there was no need to describe what POSITIVE means to illuminate an LCD display. Another problem I have is that I get the message ‘virtual void AccelStepper :: step (long int)’ is protected within this context '. I have no idea what it stands for. Why I’m only asking this now is because I also just got the problem after 2 months of working on the project, and I haven’t even changed much in the past 2 weeks.

Can someone perhaps verify whether the POSITIVE problem is with my laptop?

If correct, everything is explained in // if you have any questions please tell me so I can answer you as soon as possible!

Entire code

#include <AccelStepper.h>
#include <Stepper.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

#define step_pin 5    // Pin 5 connected to Steps pin on EasyDriver
#define dir_pin 6     // Pin 6 connected to Direction pin
#define MS1 2         // Pin 3 connected to MS1 pin
#define MS2 3         // Pin 4 connected to MS2 pin
#define sleep_pin 8   // Pin 8 connected to SLEEP pin
#define wit_rood 50
#define groen_groen 51
#define rood 52 // sawthichness 3.0mm
#define groen 53 // sawthichness 3.8mm

#define home_switch 9 // Pin 9 connected to Home Switch (MicroSwitch)

AccelStepper stepper(1, 5, 6);

int pos = 0;
int target = 0; // enterd value
int target1 = 0; //
int target2 = 0; // total length
int target3 = 0; // add length
int target5 = 0; // sawthickness
byte digitCount = 0;
int LENGTH = 6000;
int switchstate = 0;
int switchstate1 = 0;


//SETUP THE LCD
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

//SETUP THE KEYPAD
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  '1', '2', '3', '\a',
  '4', '5', '6', '\b',
  '7', '8', '9', '\e',
  '*', '0', '#', '\f'
};

byte rowPins[ROWS] = {22, 24, 26, 28}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {30, 32, 34, 36}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int direction;    // Variable to set Rotation (CW-CCW) of the motor
int steps; // Used to set HOME position after Homing is completed


void setup() {
  //stepper setup
  stepper.setMaxSpeed(1000);
  stepper.setAcceleration(200.0);
  //stepper.setSpeed(150);

  // driver setup
  digitalWrite(sleep_pin, HIGH);  // Wake up EasyDriver
  delay(5);  // Wait for EasyDriver wake up
  digitalWrite(MS1, HIGH);      // Configures to Full Steps
  digitalWrite(MS2, LOW);    // Configures to Full Steps


  // in- en outputs
  pinMode(MS1, OUTPUT);
  pinMode(MS2, OUTPUT);
  pinMode(dir_pin, OUTPUT);
  pinMode(step_pin, OUTPUT);
  pinMode(sleep_pin, OUTPUT);
  pinMode(home_switch, INPUT_PULLUP);
  pinMode(50, INPUT_PULLUP);
  pinMode(51, INPUT_PULLUP);
  pinMode(52, OUTPUT);
  pinMode(53, OUTPUT);

  //lcd text setup
  lcd.begin(20, 4);
  lcd.backlight();
  lcd.print("ENTER LENGTH IN mm");
  lcd.setCursor(0, 1);
  lcd.print("--------------------");
  lcd.setCursor(0, 2);
  lcd.print("===>       mm");
  lcd.setCursor(0, 3);
  lcd.print("STOP POSITION= 0");
  lcd.setCursor(5, 2);

  Serial.begin(115200);

  // Start Homing procedure of Stepper Motor at startup

  while (digitalRead(home_switch)) {  // Do this until the switch is activated
    digitalWrite(dir_pin, LOW);      // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(step_pin, HIGH);
    delay(10);                       // Delay to slow down speed of Stepper
    digitalWrite(step_pin, LOW);
    delay(10);
  }

  while (!digitalRead(home_switch)) { // Do this until the switch is not activated
    digitalWrite(dir_pin, HIGH);
    digitalWrite(step_pin, HIGH);
    delay(5);                       // More delay to slow even more while moving away from switch
    digitalWrite(step_pin, LOW);
    delay(5);
    stepper.setCurrentPosition(0);
  }

  steps = 0; // Reset position variable to zero

}




void loop() {
  switchstate = digitalRead(wit_rood); 
  switchstate1 = digitalRead(groen_groen);
  if (switchstate == HIGH) {
    target5 = 3,0; 
    digitalWrite(rood, HIGH); // these are colors of the leds (red)
    digitalWrite(groen, LOW); // green

  }

  else {
    target5 = 4,0;
    digitalWrite(rood, LOW);
    digitalWrite(groen, HIGH);
  }
  //FUNCTION TO HOME WHEN THE * IS PRESSED
  char keypressed = keypad.getKey();
  if (keypressed == '*') {
    Serial.println("Homing....");
    lcd.setCursor(14, 3);
    lcd.print("       ");
    lcd.setCursor(14, 3);
    lcd.print("HOMING");
    lcd.setCursor(5, 2);
    while (digitalRead(home_switch)) {  // Do this until the switch is activated
      digitalWrite(dir_pin, LOW);      // (HIGH = anti-clockwise / LOW = clockwise)
      digitalWrite(step_pin, HIGH);
      delay(10);                       // Delay to slow down speed of Stepper
      digitalWrite(step_pin, LOW);
      delay(10);
    }
    while (!digitalRead(home_switch)) { // Do this until the switch is not activated
      digitalWrite(dir_pin, HIGH);
      digitalWrite(step_pin, HIGH);
      delay(5);                       // More delay to slow down even more while moving away from switch
      digitalWrite(step_pin, LOW);
      delay(5);
      lcd.setCursor(14, 3);
      lcd.print("       ");
      lcd.setCursor(14, 3);
      lcd.print(steps);
      lcd.setCursor(5, 2);
      //Serial.println(steps);
      stepper.setCurrentPosition(0);

    }
    steps = 0; // Reset position variable to zero

  }


  //FUNCTION TO ADD 0.1MM WHEN THE B IS PRESSED
  if (keypressed == '\b') { // B
    target3 = (target2 + target + target5); // target3 = add length
    stepper.step(target3);

    lcd.setCursor(14, 3);
    lcd.print("       ");
    lcd.setCursor(5, 2);
   
  }

  // totale maat balk
  if (keypressed == '\e') { // C

    target2 = (LENGTH - target - target5); // total length of object

    lcd.setCursor(14, 3);
    lcd.print("       ");
    lcd.setCursor(14, 3);
    lcd.print(target); 
    lcd.setCursor(5, 2);
    stepper.runToNewPosition(target2);
  }

  if (keypressed == '\f') { // D

  }

  if (keypressed == '#') {

  }

  // FUNCTION TO DELETE THE INPUT DIMENTION WHEN A IS PRESSED
  if (keypressed == '\a') {
    digitCount = 0;
    target1 = 0;
    lcd.setCursor(5, 2);
    lcd.print("      ");
    lcd.setCursor(5, 2);
  }
  //FUNCTION TO INPUT DIRECTION TO MOVE AFTER 4 DIGITS IS ENTERED
  if (keypressed >= '0') { // && Key <= '9') {
    lcd.print(keypressed);
    target1 = (target1 * 10) + keypressed - '0';
    digitCount++;
    delay(300);


    if (digitCount == 4) {
      target = target1;
      lcd.setCursor(5, 2);
      lcd.print(target);



      digitCount = 0;
      target1 = 0;
      lcd.setCursor(5, 2);
      lcd.print("     ");
      keypressed = 0;
      lcd.setCursor(14, 3);
      lcd.print("       ");
      lcd.setCursor(14, 3);
      lcd.print(target);
      lcd.setCursor(5, 2);
      Serial.println(target);

    }
  }

}

POSITIVE error

#include <AccelStepper.h>
#include <Stepper.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

#define step_pin 5    // Pin 5 connected to Steps pin on EasyDriver
#define dir_pin 6     // Pin 6 connected to Direction pin
#define MS1 2         // Pin 3 connected to MS1 pin
#define MS2 3         // Pin 4 connected to MS2 pin
#define sleep_pin 8   // Pin 8 connected to SLEEP pin
#define wit_rood 50
#define groen_groen 51
#define rood 52 // sawthichness 3.0mm
#define groen 53 // sawthichness 3.8mm

#define home_switch 9 // Pin 9 connected to Home Switch (MicroSwitch)

AccelStepper stepper(1, 5, 6);

int pos = 0;
int target = 0; // enterd value
int target1 = 0; //
int target2 = 0; // total length
int target3 = 0; // add length
int target5 = 0; // sawthickness
byte digitCount = 0;
int LENGTH = 6000;
int switchstate = 0;
int switchstate1 = 0;


//SETUP THE LCD
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

//SETUP THE KEYPAD
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  '1', '2', '3', '\a',
  '4', '5', '6', '\b',
  '7', '8', '9', '\e',
  '*', '0', '#', '\f'
};

byte rowPins[ROWS] = {22, 24, 26, 28}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {30, 32, 34, 36}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

Error ‘virtual void accelstepper is protected within this context’

Arduino:1.8.13 (Linux), Board:"Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

/home/pi/Arduino/BavAsToP/BavAsToP.ino: In function 'void loop()':
BavAsToP:173:25: error: 'virtual void AccelStepper::step(long int)' is protected within this context
     stepper.step(target3);
                         ^
In file included from /home/pi/Arduino/BavAsToP/BavAsToP.ino:1:0:
/home/pi/Arduino/libraries/AccelStepper/src/AccelStepper.h:568:20: note: declared protected here
     virtual void   step(long step);
                    ^~~~
exit status 1
'virtual void AccelStepper::step(long int)' is protected within this context

The error with POSITIVE means you are using a different library for the LiquidCrystal_I2C.h file than the one the code you copied was written for.

There are multiple Arduino libraries which contain a file named "LiquidCrystal_I2C.h" and some of these have incompatible APIs. I would recommend looking at any comments/documentation/tutorials/etc. that accompanied the code you copied to see whether the author bothered to document where you can get the library the code was written for. If not, this is a very common problem so if you do a bit of searching you'll be sure to find a link to the right library.

It's unusual to pass so many parameters to an I2C LCD. The library I'm using expects three.

Your other error is the compiler telling you that step is a protected function. It's not intended for your use - the library uses it to implement the higher level interface it offers you. Again, take a look at the library examples.

So you want to say with it that I can't use 'stepper.step' because it's virtual void protected?
Do you know an alternative to 'stepper.step'?

When 'relative X' (add number) is pressed, a entered number will be added. so I enter the number 800. it has to keep adding 800 every time I press it. So 'runToNewPosition is not what I am looking for because it would just stay at 800 steps.

I am still confused because I have another pc (a raspberry pi 3 with arduino v1.8.13) on which the code works. I also have 1.8.13 my main PC

If you turn on verbose output during compilation in File > Preferences, compile the sketch on your Raspberry Pi, then examine the output in the black console pane at the bottom of the Arduino IDE window, you'll find the location of the folders containing the libraries that are used.

If you delete the libraries currently being from the libraries folder of your sketchbook (look at File > Preferences > Sketchbook location if you don't know where it is) on your main PC and then replace them with the libraries from the Raspberry Pi, then the code will compile on your main PC just like it does on the Raspberry Pi.

Thank you very much for your time. I tried your way with little luck. so i chose to continue programming on the raspberry pi 3 where the code apparently works.

thanks again!

I also solved the problem of ‘stepper.step’ by replacing ‘stepper.step’ to ‘stepper.move’ and ‘stepper.runToPosition’.

And it works!

//FUNCTION TO ADD 0.1MM WHEN THE B IS PRESSED
  if (keypressed == '\b') { // B
    target3 = (target2 + target + target5); // target3 = add length
    stepper.step(target3);
    stepper.setCurrentPosition(target2);
    stepper.runToNewPosition(target3);
    lcd.setCursor(14, 3);
    lcd.print("       ");
    lcd.setCursor(5, 2);
   
  }

  // totale maat balk
  if (keypressed == '\e') { // C

    target2 = (LENGTH - target - target5); // total length of object

    lcd.setCursor(14, 3);
    lcd.print("       ");
    lcd.setCursor(14, 3);
    lcd.print(target); 
    lcd.setCursor(5, 2);
    stepper.move(target2);
    stepper.runToPosition();
  }