Strange character in display

I am working on a dual stepper motor design.
So i would like to display the to go value (X/Y) and the ‘actual’ values (Dish).

But strangly there are two strange characters on the second line of my 4 line I2C display.
This i the sketch for testing:

#include "Arduino.h"
#include <Streaming.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>             // http://www.dfrobot.com/image/data/DFR0154/LiquidCrystal_I2Cv1-1.rar
#include <AccelStepper.h>                  // http://www.airspayce.com/mikem/arduino/AccelStepper/index.html

// PINS
int      YAxisDIR          =  13;          // Stepper direction output
int      XAxisDIR          =  12;
int      YAxisPWM          =  11;          // Stepper steps output
int      XAxisPWM          =  10;

// DEGREES / STEPS CONVERSION
float    stepsPerRotation  = 200;          // 200 steps per rotation (1.8 degrees per step)
int      xGearRatio        =  42;          // stepper ratio per X degree of rotation (1:42)
int      yGearRatio        =  42;          // stepper ratio per Y degree of rotation 
int      xMicroSteps       =   2;          // Value of the microsteps
int      yMicroSteps       =   2;          // Posible value's are 1, 2, 4, 8 and 16
int      xOffset           =   8;          // Numer of degrees offset from 0 or 180 degree
int      yOffset           =   8;          // Numer of degrees offset from 0 or 180 degree

typedef enum { 
  X_ROTOR, Y_ROTOR } 
stepperfn;

long deg2step( float degrees, stepperfn stepper );
long deg2step( float degrees, stepperfn stepper ) {
  if(stepper == X_ROTOR)	return (( degrees/1.8)*xMicroSteps*xGearRatio);
  if(stepper == Y_ROTOR)	return (( degrees/1.8)*yMicroSteps*yGearRatio);
}

float step2deg(long steps, stepperfn stepper);
float step2deg(long steps, stepperfn stepper) {
  if(stepper == X_ROTOR)        return (( steps*1.8)/(xMicroSteps*xGearRatio));
  if(stepper == Y_ROTOR)        return (( steps*1.8)/(yMicroSteps*yGearRatio));
}

// Steppers , see AccelStepper documotation for more information
AccelStepper stepperX(1,XAxisPWM,XAxisDIR);
AccelStepper stepperY(1,YAxisPWM,YAxisDIR);

byte     lcdDisplayAddress = 0x21;

int xMotorSpeed            = 500;          // Maximum steps per second
int yMotorSpeed            = 500;          // Maximum steps per second
int xMotorAccel            =  25;          // Steps per second for acceleration
int yMotorAccel            =  50;          // Steps per second for acceleration

float newXAxis = 23L;
float newYAxis = 13L;

char     xStrBuffer[8]     = {
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
char     yStrBuffer[8]     = {
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

// LCD display and Keyboard
LiquidCrystal_I2C lcdSerial(lcdDisplayAddress, 20, 4);

void setup() {
  Serial.begin(19200);                     // Start the Serial communication
  while(!Serial);
  lcdSerial.init();                         // Initialize the LCD display
  lcdSerial.backlight();                    // Turn on the back-light

    stepperX.setMaxSpeed(xMotorSpeed/1);        // Set the X rotor-motor maximum speed
  stepperX.setAcceleration(xMotorAccel);    // Set the X rotor-motor acceleration speed
  stepperY.setMaxSpeed(yMotorSpeed/1);        // Set the Y rotor-motor maximum speed
  stepperY.setAcceleration(yMotorAccel);    // Set the Y rotor-motor acceleration speed

  stepperX.setCurrentPosition(deg2step(0.0, X_ROTOR));  
  stepperY.setCurrentPosition(deg2step(0.0, Y_ROTOR));  

  Serial << "Test Setup Ready" << endl;

  stepperX.moveTo(deg2step(newXAxis, X_ROTOR)); // Move to new X position
  stepperY.moveTo(deg2step(newYAxis, Y_ROTOR)); // Move to new Y position

  dtostrf(newXAxis,7, 2, xStrBuffer);   // Make it alse printable
  dtostrf(newYAxis,7, 2, yStrBuffer);

  lcdSerial.setCursor(0,1);
  lcdSerial << "X/Y " << xStrBuffer << "  " << yStrBuffer;
}

void loop() {

  while(stepperX.currentPosition() != deg2step(newXAxis, X_ROTOR)) {

    stepperX.run();
    stepperY.run();

    lcdSerial.setCursor(0,2);
    dtostrf(step2deg(stepperX.currentPosition(), X_ROTOR),7, 2, xStrBuffer);   // Make it alse printable
    dtostrf(step2deg(stepperY.currentPosition(), Y_ROTOR),7, 2, yStrBuffer);
    lcdSerial << "Dish" << xStrBuffer << "  " << yStrBuffer << endl;
  }
}

The characters on the first 2 position of line 2 look like 3 horizontal stripes.
Anny suggestions?

Harry

float newXAxis = 23L;
float newYAxis = 13L;

Why are you casting an int to a long, and storing the result in a float?

The characters on the first 2 position of line 2 look like 3 horizontal stripes. Anny suggestions?

I suggest you post a picture of it, since you didn't define what the rest of the display looks like.

I'd also suggest that maybe the two buffers should be a bit larger - say 10 elements.

Hi Paul,
Attached is the picture of what i see.
The buffer should only hold the 7 characters to print plus the ending 0x00 as needed by the dtostrf function.
By using a buffer that’s only eight positions long it should work, making it longer doesn’t change the result.

  lcdSerial << "X/Y " << xStrBuffer << "  " << yStrBuffer;

I’m curious what you expect the LCD do to with the carriage return and line feed. They often result in garbage on the LCD. Hmmm, I know someone who’s having that kind of problem.

Is that really easier to deal with than:

lcdSerial.print("X/Y ");
lcdSerial.print(xStrBuffer);
lcdSerial.print(" ");
lcdSerial.print(yStrBuffer);

Your code certainly uses more memory.

Sorry Paul,

Youre answer makes no senso to me.
There’s no CR+LF in that line.

I am using streaming all the time without problem.
With streaming, if i would have a CRLF i use << endl;
And it uses noextra memory.

Harry

Sorry Paul,

Youre answer makes no senso to me.
There’s no CR+LF in that line.

The endl does something. Perhaps you ought to write a program in C++ on your PC, and see what happens if you don’t use endl.

With streaming, if i would have a CRLF i use << endl;

Exactly. And what is the LCD supposed to do with a carriage return or a line feed? It is NOT a printer!

And it uses noextra memory.

That I do NOT believe.