Trying to figure out how to update my libraries to not use dtostrf.

I have a couple of issues with the latest version of the Arduino compiler. I would prefer to fix my code to work with the current compiler version. I have 2 Primary failure modes that I am not sure how to fix. I have tried several thing but am having troubles getting a float to convert string without using dtostrf, and assigning a string a name then using the name to determine program flow.

My setup is an Arduino Due, CTE Shield and a 7.0 inch MD070SD Display. I am using The UTFT Library, I have the latest version for RinkyDinks web site.

Issue 1) 'dtostrf' was not declared in this scope

  if (GaugeName = "Water") {
    myGLCD.setFont(SixteenSegment16x24);//16x24
    myGLCD.print("ENG TEMP ", frameWidth + 10, 10);
    myGLCD.drawRoundRect(frameWidth + 5, 5, frameWidth * 2, frameHeight - 30); //Upper Frame with Gauge name and numerical mesurement
    myGLCD.drawRoundRect(frameWidth + 5, frameHeight - 30, frameWidth * 2, frameHeight); //Gauge Goes in this frame
    myGLCD.setFont(DotMatrix_M_Slash);  //16x22
    char bufferWater[7] ; String sWater = dtostrf(WT, 4, 0, bufferWater) ; // Convert float to string for display on tft as string. char bufferValue[7] ; String sValue = dtostrf(Source Variable, 0, Decimal, bufferValue)
    myGLCD.print(String(sWater), frameWidth + 10, 50);

Issue 2) warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

void BarGauge(String GaugeName) {
  //Get Display size
  int Width = myGLCD.getDisplayXSize();
  int Height = myGLCD.getDisplayYSize();
  //int sBarX2;
  //int sBarY2;
  // Show Display Size
  //myGLCD.print("Width " + String(Width) , 10, 100);  myGLCD.print("Height " + String(Height) , 10, 130);

  extern uint8_t SixteenSegment16x24[];
  extern uint8_t DotMatrix_M_Slash[];
  extern uint8_t oil ; // include bitmap
  myGLCD.setFont(SixteenSegment16x24);
  float frameWidth = (Width / 2) - 2;
  float frameHeight = (Height / 2) - 2;
  myGLCD.setBackColor(VGA_NAVY);
  myGLCD.setColor (VGA_LIME) ;

  //--------------------------------------------------------------------------------------------------------------------------------------
  //OIL Top Left
  //--------------------------------------------------------------------------------------------------------------------------------------
  String strOil;
  if (GaugeName = "Oil") {
    myGLCD.setFont(SixteenSegment16x24);
    myGLCD.print("OIL PSI ", 10, 10);
    myGLCD.drawRoundRect(5, 5, frameWidth, frameHeight - 30); //Upper Frame with Gauge name and numerical mesurement
    myGLCD.drawRoundRect(5, frameHeight - 30, frameWidth, frameHeight); //Gauge Goes in this frame
    myGLCD.setFont(DotMatrix_M_Slash);  //16x22
    //char bufferOil[7] ; String sOil = dtostrf(OP, 4, 0, bufferOil) ; // Convert float to string for display on tft as string. char bufferValue[7] ; String sValue = dtostrf(Source Variable, 0, Decimal, bufferValue)
    
    myGLCD.print(String(strOil) ,  10, 50);
    
    //myGLCD.drawBitmap(5, 5, frameWidth, frameHeight - 30, oil,0,); 
    
    float sBarScale = 0.00 ;
    sBarScale = frameWidth / 100; //set up scale for measurements
    float sBarX2 = (OP * sBarScale) ; //determine length of bar based on measured value.
    myGLCD.setColor(VGA_NAVY); myGLCD.fillRoundRect(sBarX2, frameHeight - 29, frameWidth - 1 , frameHeight - 1) ; //Draw blank part of bar,
    if (OP <= 10) {
      myGLCD.setColor (VGA_RED) ;
      myGLCD.fillRoundRect(5, frameHeight - 29, sBarX2, frameHeight - 1) ; //Draw Bar
    }
    if (OP > 10) {
      myGLCD.setColor (VGA_LIME) ;
      myGLCD.fillRoundRect(5, frameHeight - 29, sBarX2, frameHeight - 1) ; //Draw Bar
    }
      myGLCD.setColor (VGA_LIME) ;
  }
  //--------------------------------------------------------------------------------------------------------------------------------------
  // Water Top Right
  //--------------------------------------------------------------------------------------------------------------------------------------
  if (GaugeName = "Water") {
    myGLCD.setFont(SixteenSegment16x24);//16x24
    myGLCD.print("ENG TEMP ", frameWidth + 10, 10);
    myGLCD.drawRoundRect(frameWidth + 5, 5, frameWidth * 2, frameHeight - 30); //Upper Frame with Gauge name and numerical mesurement
    myGLCD.drawRoundRect(frameWidth + 5, frameHeight - 30, frameWidth * 2, frameHeight); //Gauge Goes in this frame
    myGLCD.setFont(DotMatrix_M_Slash);  //16x22
    char bufferWater[7] ; String sWater = dtostrf(WT, 4, 0, bufferWater) ; // Convert float to string for display on tft as string. char bufferValue[7] ; String sValue = dtostrf(Source Variable, 0, Decimal, bufferValue)
    myGLCD.print(String(sWater), frameWidth + 10, 50);

    float sBarScale = 0 ;
    sBarScale = frameWidth / 250; //set up scale for measurements
    float sBarX2 = (WT * sBarScale) ; //determine length of bar based on measured value.
    myGLCD.setColor(VGA_NAVY); myGLCD.fillRoundRect(sBarX2 + frameWidth, frameHeight - 29, frameWidth * 2 - 1 , frameHeight - 1) ; //Draw blank part of bar,
    if (WT >= 230) {
      myGLCD.setColor (VGA_RED) ;
      myGLCD.fillRoundRect(frameWidth + 5, frameHeight - 29, frameWidth + sBarX2, frameHeight - 1) ; //Draw Bar
    }
    if (WT < 230) {
      myGLCD.setColor (VGA_LIME) ;
      myGLCD.fillRoundRect(frameWidth + 5, frameHeight - 29, frameWidth + sBarX2, frameHeight - 1) ; //Draw Bar
    }
  myGLCD.setColor (VGA_LIME) ;
  }

  //--------------------------------------------------------------------------------------------------------------------------------------
  // Fuel Bottom Left

Print out the integer part as an integer, then print out the decimal part by subtracting the integer part. Watch out for negative numbers and zero-padding.

Or just use something like this. I assume you have a 'print this charcater at x,y' function

// note that the lenght of the ouput will be maxdigits +1.
// f must be positive
// maxDigits must be at least 1 greater than decimals.
void printfixedpoint(float f, int x, int y, int maxDigits, int decimals) {
  for(i = 0; i<decimals; i++) {
    f *= 10;
  }

  long l = f+.5; // add .5 for rounding 
  x += maxDigits+1; // one past the end
  for(int i =0; i<maxDigits; i++) {
    if(i == decimals) {
      print('.', --x, y); // decimal point
    }
    
    if(i > decimals && l==0) {
      print(' ', --x, y); // leading blank
    }
    else {
      print((l % 10) + '0', --x, y); // a single digit
    }
  }
}

For the second code, your if statements use '=' instead of '=='. Not sure if it's the cause of the warning but it probably will not do what you think it does.

For the first one, show what you have tried. What is wrong with dtostrf()? Why do you use String (with capital S)?

kilgorq:
Issue 1) 'dtostrf' was not declared in this scope

Works for me...

#include <avr/dtostrf.h>

void setup( void ) 
{
  char bufferWater[31];
  float WT;
  dtostrf(WT, 4, 0, bufferWater);
}

void loop( void ) { }

Obviously, the Arduino folks need to add that first line to Arduino.h for the Due.

I figured it out.

  1. The issue was the library. I ended up adding a dtostrf library to my libraries.

  2. Was actually a switch in my UTFT library that had to be changed for CTE sheild with DUE.

// Uncomment the following line if you are using this shield
//#define CTE_DUE_SHIELD 1