Error LCD 16x2

Hello:

Running this example with Arduino 1.0.5 …

 # include <LiquidCrystal.h>
LiquidCrystal milcd (12, 11, 5, 4, 3, 2);
smiley byte [8] = {B00000, B10001, B00000, B00000, B10001, B01110, B00000};

void setup () {
         milcd.createChar (0, smiley);
         milcd.begin (16, 2);
         milcd.write (0);
}

void loop () {} [/ code]

I get this error. Why and how can I fix it?
[quote] sketch_feb14a.ino: In function 'void setup ()':
sketch_feb14a: 8: error: call of overloaded 'write (int)' is ambiguous
C: \ Program Files (x86) \ Arduino \ libraries \ LiquidCrystal / LiquidCrystal.h: 82: note: candidates are: virtual size_t LiquidCrystal :: write (uint8_t)
C: \ Program Files (x86) \ Arduino \ hardware \ arduino \ cores \ arduino / PRINT.H: 49: note: size_t Print :: write (const char *) [/ quote]

Best regards.

check this out http://arduino.cc/en/Reference/LiquidCrystalWrite then look at this line

  milcd.write (0);

as I understand 0 is an integer and not a character. hence your integer is ambiguous .

I tried to run your code and I got a lot more errors then you posted too… here is the list of errors I get

sketch_feb12a:2: error: 'LiquidCrystal' does not name a type
sketch_feb12a:3: error: 'smiley' does not name a type
sketch_feb12a.ino: In function 'void setup()':
sketch_feb12a:6: error: 'milcd' was not declared in this scope
sketch_feb12a:6: error: 'smiley' was not declared in this scope

I played a little more with this code, cause I’m curious and trying to learn myself
you had a space in your

# include "LiquidCrystal"

I don’t understand your

milcd.write (0);

anyways this is what I have done, to get rid of the errors , as far as I get, though

#include <LiquidCrystal.h>
LiquidCrystal milcd (12, 11, 5, 4, 3, 2);
byte smiley [8] = {
  B00000, B10001, B00000, B00000, B10001, B01110, B00000};

void setup ()
{
  milcd.begin (16, 2);
  milcd.createChar (0, smiley);
  // milcd.write (0);
}

void loop () 
{

}

The reasons for your problem with address 0x00 have been explained previously in this forum. I'll see if I can find one of the threads and add a link to it.

Meanwhile just use address 0x08 instead of 0x00 to display your first custom character.

Don

Edit: It's explained (by bperrybap) in this thread http://forum.arduino.cc/index.php?topic=140917.0

This is the true reason any write(0) will not work:

http://liudr.wordpress.com/2011/12/26/how-to-update-codes-and-libraries-for-arduino-1-0/

  // Kode for å få æ, ø, å, Æ, Ø, Å i display
    byte Lae[8] = {B00000,B00000,B11010,B00101,B01111,B10100,B11111,B00000}; // æ 
    byte Loe[8] = {B00000,B00001,B01110,B10101,B10101,B01110,B10000,B00000}; // ø 
    byte Laa[8] = {B00100,B00000,B01110,B00001,B01111,B10001,B01111,B00000}; // å 
    byte Sae[8] = {B01111,B10100,B10100,B11110,B10100,B10100,B10111,B00000}; // Æ 
    byte Soe[8] = {B00001,B01110,B10011,B10101,B11001,B01110,B10000,B00000}; // Ø 
    byte Saa[8] = {B00100,B00000,B01110,B10001,B11111,B10001,B10001,B00000}; // Å
    // æ, ø, å, Æ, Ø, Å er plassert i RAMadresse 0, 1, 2, 3, 4, 5
  lcd.createChar(0, Lae); // æ 
    lcd.createChar(1, Loe); // ø 
    lcd.createChar(2, Laa); // å 
    lcd.createChar(3, Sae); // Æ 
    lcd.createChar(4, Soe); // Ø 
    lcd.createChar(5, Saa); // Å
if (garagesensorpinStatus == HIGH) {
        lcd.setCursor(0,0);              
        lcd.print("Garasjen");        
        lcd.setCursor(0,1);             
        lcd.print("er ");          
    
    
       lcd.write(0);    


        lcd.print("pen   ");         
      } else {                
        lcd.setCursor(0,0);       
        lcd.print("Garasjen");         
        lcd.setCursor(0,1);          
        lcd.print("er lukket");            
    }

Then why does the above code work ? (above are relevant excerpts)
(see attached photo)
Is there anything different about the library ?(the command is lcd.write(0); and not "milcd.write(0);"

garagesensor_w_Init_BL_cmds.ino (2.49 KB)

OK.

I already work. is lcd, not milcd.

You noticed you are NOT using LiquidCrystal library?! RTFL! You have hundreds of post already, you know where to find the library files. If it is not deriving from Print, it has no such problem.

raschemmel:

  // Kode for å få æ, ø, å, Æ, Ø, Å i display

byte Lae[8] = {B00000,B00000,B11010,B00101,B01111,B10100,B11111,B00000}; // æ
   byte Loe[8] = {B00000,B00001,B01110,B10101,B10101,B01110,B10000,B00000}; // ø
   byte Laa[8] = {B00100,B00000,B01110,B00001,B01111,B10001,B01111,B00000}; // å
   byte Sae[8] = {B01111,B10100,B10100,B11110,B10100,B10100,B10111,B00000}; // Æ
   byte Soe[8] = {B00001,B01110,B10011,B10101,B11001,B01110,B10000,B00000}; // Ø
   byte Saa[8] = {B00100,B00000,B01110,B10001,B11111,B10001,B10001,B00000}; // Å
   // æ, ø, å, Æ, Ø, Å er plassert i RAMadresse 0, 1, 2, 3, 4, 5






lcd.createChar(0, Lae); // æ
   lcd.createChar(1, Loe); // ø
   lcd.createChar(2, Laa); // å
   lcd.createChar(3, Sae); // Æ
   lcd.createChar(4, Soe); // Ø
   lcd.createChar(5, Saa); // Å






if (garagesensorpinStatus == HIGH) {
       lcd.setCursor(0,0);              
       lcd.print(“Garasjen”);        
       lcd.setCursor(0,1);            
       lcd.print("er ");          
   
   
      lcd.write(0);

lcd.print("pen   ");        
     } else {                
       lcd.setCursor(0,0);      
       lcd.print(“Garasjen”);        
       lcd.setCursor(0,1);          
       lcd.print(“er lukket”);            
   }




Then why does the above code work ? (above are relevant excerpts)
(see attached photo)
Is there anything different about the library ?(the command is lcd.write(0); and **not "milcd.write(0);**"

Whatever it is you think I should already know because I know where to find the libraries. please clarify. It sounds like you are saying that because I noticed it is "LiquidCrystal" library and not "LiquidCrystal_I2C" like the one I posted, please say so ...ie: "The code you posted is not relevant because it is using the I2C Liquid Crystal library, not the regular LiquidCrystal library". If that is what you are saying then now I understand. I do not know why that makes a difference but I'll accept that and you don't have to explain it. I can assure you, having hundreds of posts in no way implies that one knows everything about lcd print or write statements as they relate to one library or another. You obviously are a programmer with extensive experience so I can understand how you think all of this is obvious to everyone. I am just trying to help but it seems I am getting in the way.

Have a look at my link WITH the explanation why the write(0) wont work. i dont feel like retyping it. Also there is no easier way to explain it. If you dont know enough of inheritance and pure virtual member methods, it is useless to you till you do your background reading. I meant to say you are NOT using LiquidCrystal library, but a different library, thus the explanation doesn't apply because the class structures and inheritance are not the same. All standard arduino library with write will have this problem. If adafruit does its own lib, which I consider iffy, such as half baked oled lib that just dont work, then they can use any rules and their writes are not affected by inheritance from Print. I believe my blog post also reveals a solution, which you can follow regardless your level of understanding of the programming language.

Any time you have a hardware serial write command with zero as argument such as Serial.write(0) or Serial.write(‘\ 0?), you will have to replace them with the following: Serial.write((uint8_t)0). The reason behind this is that in the new Print class, which Serial class inherits from, the write(char*) method is no longer virtual but actually defined. This write(char*) method and the write(uint8_t) method are both non-virtual and become ambiguous when the argument is zero. The zero could mean zero BYTE value or zero pointer to char array, which is allowed (no other constant values are allowed as pointer). To clear it up, you force the zero into BYTE, or the unsigned 8-bit integer type: uint8_t Any other libraries that derive from the Print class will have the same issues. You have to do the above regarding to write(0).

Got it. Thanks for the explanation.

ooh cool I think I get it. This complies fine. Don’t know if it works, but it compiles with no errors. What a great learning experience for me.

#include <LiquidCrystal.h>
LiquidCrystal milcd (12, 11, 5, 4, 3, 2);
byte smiley [8] = {
  B00000, B10001, B00000, B00000, B10001, B01110, B00000};

void setup ()
{
  milcd.begin (16, 2);
  milcd.createChar (0, smiley);
  milcd.write((uint8_t)0);
}

void loop () 
{

}

Gist of the problem: two write functions exist, one with write(byte) and the other with write(address). Both byte (aka uint_8) and address can be 0. write(0) is ambiguous since it could be write(byte 0) or write(address 0), but only one function should be called. You indicated you want to call the write(byte 0) so the ambiguity was removed. Exactly why there are these two functions, Print.cpp is a fun read. Do it after a refresher on inheritance and pure virtual member function ;)

Couldn't we just define an integer (char) constant as zero and use that?

Paul__B: Couldn't we just define an integer (char) constant as zero and use that?

That should work, or you type cast the zero. Ehat’s wrong with the forum?! All caps!?

liudr: Gist of the problem: two write functions exist, one with write(byte) and the other with write(address). Both byte (aka uint_8) and address can be 0. write(0) is ambiguous since it could be write(byte 0) or write(address 0), but only one function should be called. You indicated you want to call the write(byte 0) so the ambiguity was removed. Exactly why there are these two functions, Print.cpp is a fun read. Do it after a refresher on inheritance and pure virtual member function ;)

I can't seem to get info on print.cpp , every time I google it I keep getting Canada Pension Plan (apparently i can get a print out),,, I don't suppose you can get me a link to read up on this?

Try here : (I think this is the same print.cpp we are talking about )
https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/Print.cpp

raschemmel: Try here : (I think this is the same print.cpp we are talking about ) https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/Print.cpp

Whoa, I will be reading that over and over. Thanks for the link.

Oh yeah, great bedtime reading....