avatar

Integrated Teaching & Learning Program (ITLP) at CU Boulder

Member Since: June 2, 2021

Country: United States

  • -- HELP: Long Strings Truncating At 30-characters --

    I have a student group who is attempting to integrate this LCD into their project. It's almost certainly an issue with the code, but they are experiencing a truncation of strings that are printed to the screen, specifically when strings are longer than 30 characters.

    For context, they are using the Qwic connection, using the Wire library to communicate with the screen via I2C. The long strings are successfully wrapped from the first 20-character-long line down to the second line, but as I said, strings are consistently truncated to 30 characters (cutting off in the middle of the second row)...

    As for the code, we've simply tried using the example code found here, then modifying the sample string to be longer...

    #include <Wire.h>
    
    #define DISPLAY_ADDRESS1 0x72 //This is the default address of the OpenLCD
    
    void setup()
    {
        Wire.begin(); //Join the bus as master
    
        //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz
        //Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz
    
        Wire.beginTransmission(DISPLAY_ADDRESS1);
        Wire.write('|'); //Put LCD into setting mode
        Wire.write('-'); //Send clear display command
        Wire.endTransmission();
    }
    
    void loop()
    {
        writeToScreen(); //Send the four characters to the display
        delay(50); //The maximum update rate of OpenLCD is about 100Hz (10ms). A smaller delay will cause flicker
    }
    
    void writeToScreen()
    {
        Wire.beginTransmission(DISPLAY_ADDRESS1); // transmit to device #1
    
        Wire.write('|'); //Put LCD into setting mode
        Wire.write('-'); //Send clear display command
    
        Wire.print("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
    
        Wire.endTransmission(); //Stop I2C transmission
    }
    

    This displays the following on the 20x4 display:

    abcdefghijklmnopqrst
    uvwxyzABCD