lcd.write

Hey there

I have started making a new character for my display. I have included "LiquidCrystal.h" and done everything according to instructions, but when I compile, I get an error messege at the lcd.write code, saying "call of overload 'write (int)' is ambiguous".

And I can't figure it out. Does anyone have a suggestion?

but when I compile, I get an error messege at the lcd.write code

When you compile what?

Without seeing your code, I'd suggest that you have to fix the line that the compiler is complaining about.

Here is the code:

#include <LiquidCrystal.h>

int sensorPin = 3; // select the input pin for the temperatur sensor
int sensorValue = 0; // variable to store the value coming from the sensor
int ledPin = 9; // select the output pin for the buzzer
int temperatur; //En værdi til at holde grader celcious

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(10, 11, 12, 13, 14, 15, 16);

//Opret en ny character (grader tegnet);
byte newChar1[8] = {
B00110,
B01001,
B01001,
B00110,
B00000,
B00000,
B00000,
B00000,

};

void setup() {
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
lcd.createChar(0, newChar1); //Opret den nye character, som før var defineret.
// Print a message to the LCD.
lcd.setCursor(0, 0);
lcd.print(“Current temp is:”);
}

void loop() {

// read the value from the sensor:
sensorValue = analogRead(sensorPin);

temperatur = sensorValue/24;

// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):

lcd.setCursor(0, 1);
lcd.print(sensorValue);
lcd.print(" Value");

lcd.setCursor(10, 1);
lcd.print(temperatur);
lcd.write(0); <---- here comes the error message !!!
lcd.print(" C");
}

and the error message: call of overload ‘write (int)’ is ambiguous

change

 lcd.write(0);

to

lcd.write((int)0);

thanks for the reply, but it did not help either, it still gives the same error message

A constant zero is treated special/differently by the compiler than other constants. It could be several different data types. That combined with the Print class definition is what causes the error. The compiler isn't sure which data type you wanted it to be in order to match it up with the proper Print class function.

The proper cast actually should be:

lcd.write((uint8_t)0);

as you are wanting to send the raw 8 bit value.

A quick and dirty solution in your case would be to pick one of the other custom character locations as 0 (zero) is the only constant that will have this issue with the Arduino Print class. i.e. if you switched to 1 instead, the error would not happen. (no cast needed)

An alternative is to fix the Arduino teams Print class to support all the possibilities and never have to deal with this problem again. You can do this by modifying the file Print.h in {installdir}/hardware/arduino/cores/arduino Add these lines

    inline size_t write(unsigned long n) { return write((uint8_t)n); }
    inline size_t write(long n) { return write((uint8_t)n); }
    inline size_t write(unsigned int n) { return write((uint8_t)n); }
    inline size_t write(int n) { return write((uint8_t)n); }

Just after this line in the public section of the Print class definition:

    virtual size_t write(const uint8_t *buffer, size_t size);

--- bill

A thousand thank you bill, it helped me. So far I have taken the quick and dirty solution. The alternative solution, I will look at later. Thanks again.

Torben

Another possibility, I just remembered, is that some HD44780 displays have a degree character in their font.
Often it is at location 0xdf or 223 decimal or 337 octal.

So if your display has this, you can simply use:

lcd.write(0xdf);

or

lcd.write(223);

rather than have to define a custom character.

And another option. To print the , degree and ‘C’ together at the same time:

lcd.print(" \337C");

— bill