Too many arguments to function?

Hello,

I am working in a project that utilizes an Arduino nano which reads the serial output of a digital vacuum manometer. However, I am trying to make the reading a bit easier, thus I am trying to modify the output.

The output of the pressure is expressed like “7.06E+2 Torr” which I would want to be expressed as 706 Torr or 7.06 x 102 Torr. My approach for this is to save the exponent in a variable, remove the decimal and “E+2” characters, and then save the pressure as a float value and multiply it by 10 to the exponent.

Here is the code:

// include the library code:
#include <LiquidCrystal.h>  
 LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
 
String sensorValue;

void setup() {
 Serial.begin(9600);
 //Contrast
 analogWrite(6,300);
  // set up the LCD's number of columns and rows:
 lcd.begin(16, 2);
}

void Pressure() {
lcd.setCursor(0, 0);
lcd.print("Pressure:"); //text

Serial.write ("@253PR3?;FF");
//print pressure only when receiving data
if (Serial.available() > 0) {

  //read sensor value
  sensorValue = Serial.readString();
  sensorValue.remove(0, 7); //Remove first 7 characters of @253ACK7.10E+2;FF to get 7.10E+2;FF
  sensorValue.remove(7); //Remove characters from the 7th, to get 7.10E+2
    //Convert the string to a float number
  char charexp = sensorValue[6]; //save the exponent as a variable
  int exponent = charexp - '0';
  sensorValue.remove(4); //remove characters from the 4th, to get 7.10
  sensorValue.remove(1,1); //remove decimal
  sensorValue.toFloat();
  lcd.setCursor(0,1);
  lcd.print(sensorValue * (pow(10,exponent, 2);
  lcd.print(" Torr");
  
  }

}


void loop() {
 //loop of sensorValue
Pressure();
}

However, the code says that there are "Too many arguments to function ‘double pow(double, double)’ in this line

lcd.print(sensorValue * (pow(10,exponent, 2);

How could I fix this?

Thanks!

pllagunos: lcd.print(sensorValue * (pow(10,exponent, 2);

What is the '2' doing there?

The problem seems obvious

Too many arguments to function ‘double pow(double, double)’

The pow function takes two arguments

lcd.print(sensorValue * (pow(10,exponent, 2);

you have supplied 3

What’s more you have mismatched brackets in that line
I assume that you are trying to print 2 decimal places and have made a mess of it

Thanks!

I feel like an idiot, but yes indeed my brackets were mismatched.

However, I still have a problem. Variable "sensorValue" if I am correct, is an ASCII character, and what I am trying to do is remove all non-digit characters (which I've successfully done) and then be left with only the number, afterwards I would print in an LCD that number multiplied by 10 to the corresponding exponent. But I can't do an operation in an ASCII variable, and converting it to a float or integer variable is just giving me 0. What could I do in order to fix this?

But I can't do an operation in an ASCII variable, and converting it to a float or integer variable is just giving me 0. What could I do in order to fix this?

The atoi() or atof() functions will take a number represented in a null terminated character array (string) and convert to an int or float data type.

Tried both the atoi() and atof() functions but I get the following error message: "can not convert String to const char for argument ‘1’ to ‘int atoi(const char*)’

// include the library code:
#include <LiquidCrystal.h>  
 LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <stdio.h>      
#include <stdlib.h> 
String sensorValue;

void setup() {
 Serial.begin(9600);
 //Contrast
 analogWrite(6,300);
  // set up the LCD's number of columns and rows:
 lcd.begin(16, 2);
}

void Pressure() {
lcd.setCursor(0, 0);
lcd.print("Pressure:"); //text

Serial.write ("@253PR3?;FF");
//print pressure only when receiving data
if (Serial.available() > 0) {

  //read sensor value
  sensorValue = Serial.read();
  sensorValue.remove(0, 7); //Remove first 7 characters of @253ACK7.10E+2;FF to get 7.10E+2;FF
  sensorValue.remove(7); //Remove characters from the 7th, to get 7.10E+2
  char charexp = sensorValue[6]; //save the exponent as a variable
  int exponent = charexp - '0';

  //convert the string to a usable float
  sensorValue.remove(4); //remove characters from the 4th, to get 7.10
  sensorValue.remove(1,1); //remove decimal
  int realpressure = atoi(sensorValue);
  lcd.setCursor(0,1);
  lcd.print(realpressure);

  }

}


void loop() {
 //loop of sensorValue
Pressure();
}

Tried many different things, including defining sensorValue as a character like this

char sensorValue[(0,1,2)];

But couldn’t get it to work. Any idea on what to do next? Thanks!

int realpressure = atoi(sensorValue);

atoi() and the likes work on c-strings (nul terminated character array), not on Strings (capital S). Strings (capital S) have a toCharArry() method that will convert it to a c-string; but you can just as well use the String's (capital S) toInt() method.

sensorValue = Serial.read();

Serial.read() returns a single character, not a String (capital S).

Note: You should forget that String (capital S) exists; in bigger code its usage can result in difficult to track bugs due to memory fragmentation. Use c-strings (nul terminated character arrays instead).

Thanks, I see I made an error in that code.

sensorValue = Serial.read();

This was an attempt (which resulted in failure) I did while trying to set up the code for the atoi() and atof() functions.

I tried using
sensorValue = Serial.readString();
And it also results in failure. Tried toInt() method, but couldn’t get it to work.

How could I get sensorValue as a c-string, and could that work? My main goal here is just getting the number out of sensorValue and performing operations with it.

Went a different path all night (2:29 AM right now), and now it is working perfectly but I decided to use other methods instead of operations.

// include the library code:
#include <LiquidCrystal.h>  
 LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <stdio.h>     
#include <stdlib.h> 
 
String sensorValue;
String txt;

void setup() {
 Serial.begin(9600);
  // set up the LCD's number of columns and rows:
 lcd.begin(16, 2);
}

void Pressure() {
lcd.setCursor(0, 0);
lcd.print("Pressure:"); //text

Serial.write ("@253PR3?;FF");
//print pressure only when receiving data
if (Serial.available() > 0) {

  //read sensor value
  sensorValue = Serial.readString();
  sensorValue.remove(0, 7); //Remove first 7 characters of @253ACK7.15E+2;FF to get 7.15E+2;FF
  sensorValue.remove(7); //Remove characters from the 7th, to get 7.15E+2
  
  }
  
  //We print accordingly to the range of the pressure
  //First we define E+2 
  if (sensorValue.indexOf("E+2") > 0) {
    sensorValue.remove(4); //remove characters from the 4th, to get 7.15
    sensorValue.remove(1,1); //remove the decimal to get 715 
      
    if (txt != "Torr") {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Pressure:");
      lcd.setCursor(0,1);
      lcd.print(sensorValue + " Torr");
      txt = "Torr"; 
      }
    
    else {
      lcd.setCursor(0,1);
      lcd.print(sensorValue + " Torr");
      txt = "Torr";  
      }
    }
    
  //In the latter we define E+1 
  else if (sensorValue.indexOf("E+1") > 0) {
    sensorValue.remove(4); //remove characters from the 4th, to get 7.15
    sensorValue.remove(1,1); //remove the decimal to get 715
    String x = sensorValue.substring(2); //save character 5
    sensorValue.remove(2); //remove characters from the 2th, to get 71
    
    if (txt != "Torr") {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Pressure:");
      lcd.setCursor(0,1);
      lcd.print(sensorValue + "." + x + " Torr"); //print 71.5 Torr
      txt = "Torr";
      }

    else {
      lcd.setCursor(0,1);
      lcd.print(sensorValue + "." + x + " Torr"); //print 71.5 Torr
      txt = "Torr";
      }
    }
    
  //In the latter we define E+0
  else if (sensorValue.indexOf("E+0") > 0) {
    sensorValue.remove(4); //remove characters from the 4th, to get 7.15

    if (txt != "Torr") {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Pressure:");
      lcd.setCursor(0,1);
      lcd.print(sensorValue + " Torr"); //print 7.15 Torr
      txt = "Torr";
      }
      
    else {
      lcd.setCursor(0,1);
      lcd.print(sensorValue + " Torr"); //print 7.15
      txt = "Torr";
      }
    }
    
  //In the latter we print only milliTorr of E-1 (also known as microns)
  else if (sensorValue.indexOf("E-1") > 0) {
    sensorValue.remove(4); //remove characters from the 4th, to get 7.15
    sensorValue.remove(1,1); //remove the decimal to get 715
    lcd.setCursor(0,1);
    lcd.print(sensorValue + " milliTorr"); //print 715 milliTorr
    txt = "milliTorr";
    }
    
  //In the latter we print only milliTorr of E-2 (also known as microns)
  else if (sensorValue.indexOf("E-2") > 0) {
    sensorValue.remove(4); //remove characters from the 4th, to get 7.15
    sensorValue.remove(1,1); //remove the decimal to get 715
    String x = sensorValue.substring(2); //save character 5
    sensorValue.remove(2); //remove characters from the 2th, to get 71
    lcd.setCursor(0,1);
    lcd.print(sensorValue + "." + x + " milliTorr"); //print 71.5 milliTorr
    txt = "milliTorr";
    }
    
  //In the latter we print only milliTorr of E-3 (also known as microns)
  else if (sensorValue.indexOf("E-3") > 0) {
    sensorValue.remove(4); //remove characters from the 4th, to get 7.15
    lcd.setCursor(0,1);
    lcd.print(sensorValue + " milliTorr"); //print 7.15 milliTorr
    txt = "milliTorr";
    }
    
  //In the latter we print low pressures of E-X<E-3 (e.g 7.10E-4)
  else { 
    
    if (txt != "E") {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Pressure:");
    lcd.setCursor(0,1);
    lcd.print(sensorValue);  
    lcd.print(" Torr"); //print 71E-X milliTorr
    txt = "E";
    }

    else {
    lcd.setCursor(0,1);
    lcd.print(sensorValue);  
    lcd.print(" Torr"); //print 71E-X milliTorr  
    }
  
    }

}


void loop() {
 //loop of sensorValue
Pressure();
}

That’s all Folks!