Print servo postion to 16x2 lcd without Varible resistor

Hi.
Ive been at this for a few days now and i simply cant get around the problem.
"NOOB PROGRAMMER"

Ive decided to build a robotic arm, (still in software development) is there anyway to show the 4 servos position on an 16x2 lcd?

ive included my code to date not sure if its the right way though :stuck_out_tongue:

LCD_SERVO_sep21b.ino (895 Bytes)

is there anyway to show the 4 servos position on an 16x2 lcd?

Yes. Make the servo positions variables and print the variables. Does your LCD work and show what you are printing at the moment ?

yes it does, im now beating around the bush just to test the lcd.

#include <LiquidCrystal.h>
#include <VarSpeedServo.h>

LiquidCrystal lcd(38, 40, 42, 44, 46, 48);
const int numRows = 2;
const int numCols = 16;

VarSpeedServo servo1;
VarSpeedServo servo2;
VarSpeedServo servo3;
VarSpeedServo servo4;

const int servo1Pin = 22;
const int servo2Pin = 24;
const int servo3Pin = 26;
const int servo4Pin = 28;

void setup() {

servo1.attach(servo1Pin);
servo2.attach(servo2Pin);
servo3.attach(servo3Pin);
servo4.attach(servo4Pin);

servo1.write(0, 255, true);
servo2.write(0, 255, true);
servo3.write(0, 255, true);
servo4.write(0, 255, true);

lcd.begin(16, 2);

lcd.setCursor (0, 0);
lcd.print("SV1");
lcd.setCursor (0, 1);
lcd.print("SV2");
lcd.setCursor (8, 0 );
lcd.print("SV3");
lcd.setCursor(8, 1);
lcd.print("SV4");
;

}

void loop() {

servo1.write(0, 0, true);
lcd.setCursor (0, 0);
lcd.print("SV1 0");
servo2.write(0, 0, true);
lcd.setCursor (0, 1);
lcd.print("SV2 0");
servo3.write(0, 0, true);
lcd.setCursor (8, 0);
lcd.print("SV3 0");
servo4.write(0, 0, true);
lcd.setCursor (8, 1);
lcd.print("SV4 0");

servo1.write(100, 100, true);
lcd.setCursor (0, 0);
lcd.print("SV1 100");
servo2.write(80, 10, true);
lcd.setCursor (0, 1);
lcd.print("SV2 80");
servo3.write(150, 100, true);
lcd.setCursor (8, 0);
lcd.print("SV3 150");
servo4.write(90, 50, true);
lcd.setCursor (8, 1);
lcd.print("SV4 90");
delay (2000);

and its working

and its working

But, there is a lot of repetitive code. Use arrays and for loops.
But, there is a lot of repetitive code. Use arrays and for loops.
But, there is a lot of repetitive code. Use arrays and for loops.
But, there is a lot of repetitive code. Use arrays and for loops.

PaulS:
But, there is a lot of repetitive code. Use arrays and for loops.
But, there is a lot of repetitive code. Use arrays and for loops.
But, there is a lot of repetitive code. Use arrays and for loops.
But, there is a lot of repetitive code. Use arrays and for loops.

yes i know its repetitive, currently its the only way i can get it to print to lcd, ill look into arrays and for loops.

"sorry, not sure on how to put the code into the "Code:" block here."

"sorry, not sure on how to put the code into the "Code:" block here."

Select it in the forum editor window and click on the </> icon top/left of the edit window

It will then look like this when posted

  servo1.attach(servo1Pin);
  servo2.attach(servo2Pin);
  servo3.attach(servo3Pin);
  servo4.attach(servo4Pin);
etc, etc
  servo1.write(0, 0, true);
  lcd.setCursor (0, 0);
  lcd.print("SV1 0");

Do yourself a favour and use a variable to hold the servo position (and arrays) to make the servo control and printing easier and smarter. A function to print the servo name and position would be handy, don't you think ?

Hi, thanks for your inputs, maybe its because im rather new to programming, but im struggling with the function option, i simply dont under stand how to get it to work to lcd, .it got to the point that i switched off went outside and kicked a rock! :stuck_out_tongue:

pls if you could help me out with the coding a bit, i wish i hadnt just switched off so i could show you wat i tried. temper temper lol.

This may give you some ideas

const char * servoNames[] = {"SV0 ", "SV1 ", "SV2 "};
const byte positions[] = {10, 120, 170};
const byte lcdCols[] = {0, 20, 0};
const byte lcdRows[] = {0, 0, 1};

void setup()
{
  Serial.begin(115200);
  for (int servoNum = 0; servoNum < 3; servoNum++)
  {
    printDetails(servoNum);
  }
}

void loop()
{
}

void printDetails(int servoToPrint)
{
  Serial.print("LCD position ");
  Serial.print(lcdCols[servoToPrint]);
  Serial.print(" ");
  Serial.print(lcdRows[servoToPrint]);
  Serial.print(" ");  
  Serial.print(servoNames[servoToPrint]);
  Serial.println(positions[servoToPrint]);
}

Obviously you need to print to the LCD rather than the Serial monitor but the function could use the details that I have printed to position the LCD cursor before printing the servo details. Using a function means that you don't have to duplicate code and you can supply a function with parameters to be used within it. The source of that data is up to you. It could be fixed, as in my example, or could come from user input.

@UKHeliBob, and BOOOOM!! it works like a charm!
karma added!
you legend!