Teensy 4.0: LCD screen via I2C on wire2

nounours18200

Active member
Hello,

I work on a project using Teensy 4.0 and a LCD screen (its address is 0x27) that should be connected via I2C on the wire2 pins, i.e. pin 24 (SCL2) and pin 25 (SDA2).

The regular I2C pins (pin 18 for SDA0 and pin19 for SCL0) are used for other purposes, so I cannot connect the LCD screen to these pins 18 and 19.

Consequently (unless I am wrong), I need a I2C library that can use wire2 instead of wire, in order to control the LCD screen.

Do you know where I can find such a library ?

Thank you very much,
 
These days almost all drivers allow you to specify which Wire instance to use in their constructor. You didn't say which screen or driver you are using in your OP
 
The TwoWire library that ships as part of Teensyduino already supports 3 interfaces (Wire, Wire1 and Wire2) for Teensy 4.0.
 
These days almost all drivers allow you to specify which Wire instance to use in their constructor. You didn't say which screen or driver you are using in your OP
The screen is a "buydisplay.com" 24x2, using a hd44780 chip (see attached file) with a I2C backboard. It is correctly detected at 0x27 by an I2C scanner. I use the hd44780 library , just trying to display anything to check that it works, but it displays nothing.
Here is the code:
#include <Arduino.h>
#include <Wire.h>
#include <hd44780.h> // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
// Ce pgm a été fait avec PlatformIO, et se trouve donc ici: C:\Users\ordic\Documents\PlatformIO\Projects\W9_T4__INT_v1.10\src\main.cpp
char version[21]="W9_T4_Test LCD_v1.00"; // Affichera la version du Firmware
// La longueur de "version" passe à 21 caractères car ça ne rentrait pas dans les 17 habituels.
/*
Le but de ce pgm est de tester si la librairie hd44780 gère les dépassements des valeurs "ligne" et "colonne" par rapport l'écran utilisé.
Par exemple si colonne devient >24, est-ce que "colonne" revient à 0 ? ou faut-il gérer ce dépassement dans ISR_WR ?
*/
const uint8_t nbCols = 24;
const uint8_t nbRows = 2;
hd44780_I2Cexp lcd;
// put function declarations here:
// int myFunction(int, int);
void setup() {
// put your setup code here, to run once:
lcd.begin(nbCols, nbRows);

for (uint8_t i = 0; i < nbCols * nbRows; i++)// on dépasse vraiment la ligne
{
lcd.print(i % 10);
delay(100);
}
}
void loop() {
// put your main code here, to run repeatedly:
}
// put function definitions here:
/*
int myFunction(int x, int y) {
return x + y;
}
*/


The TwoWire library that ships as part of Teensyduino already supports 3 interfaces (Wire, Wire1 and Wire2) for Teensy 4.0.
This would be a perfect solution: where can I download this library to add it to my PlatformIO project ???

Meantime I have installed Teensyduino to add it to my arduino 1.8.19 IDE: if it is not possible to add this library to PlatformIO, I will try with Arduino 1.8.19...

Under arduino 1.8.19+Teensyduino, what is the syntax to use this "TwoWire" librairy: is there an "inlude TwoWire.h" somewhere ??

Thank you very much
 

Attachments

  • Arduino LCD 24x2 I2C Pin Header Character Display Module_BuyDisplay.com.pdf
    1.2 MB · Views: 18
Last edited:
The screen is a "buydisplay.com" 24x2, using a hd44780 chip (see attached file) with a I2C backboard. It is correctly detected at 0x27 by an I2C scanner. I use the hd44780 library , just trying to display anything to check that it works, but it displays nothing.
Here is the code:




This would be a perfect solution: where can I download this library to add it to my PlatformIO project ???

Meantime I have installed Teensyduino to add it to my arduino 1.8.19 IDE: if it is not possible to add this library to PlatformIO, I will try with Arduino 1.8.19...

Under arduino 1.8.19+Teensyduino, what is the syntax to use this "TwoWire" librairy: is there an "inlude TwoWire.h" somewhere ??

Thank you very much
You could look at this one. Has an ability to choose which wireX to use.
Alternatively you could choose a library with a fixed wire and change all entries to wire2 or wire3.
 
I had a look at the HD44780 repository on github, I hope you took note of this warning:
WARNING
Use caution when using 3v only processors like arm and ESP8266 processors when interfacing with 5v modules as not doing proper level shifting or incorrectly hooking things up can damage the processor.

It seems this library does not allow use of any I2C interface except Wire, it isn't possible to use it with Wire2 unless you edit the code yourself.
 
I had a look at the HD44780 repository on github, I hope you took note of this warning:


It seems this library does not allow use of any I2C interface except Wire, it isn't possible to use it with Wire2 unless you edit the code yourself.
The one (library) that I highlighted does.
 
where can I download this library to add it to my PlatformIO project ???

This is the default Wire library. Normally it's pre-installed.

But if for some difficult-to-imagine reason you don't have it already installed (almost anything is possible with PlatformIO), you can download it from this github repository.


Under arduino 1.8.19+Teensyduino, what is the syntax to use this "TwoWire" librairy: is there an "inlude TwoWire.h" somewhere ??

With Arduino IDE, you just use #include <Wire.h> to use this library. Of course make sure Teensy is selected in Tools > Board menu, because Arduino IDE configures which libraries it will use depending on the selected board.

On Teensy 4.0 including Wire.h will define Wire (for use with pins 18 & 19), Wire1 (for pins 16 & 17) and Wire2 (for pins 24 & 25 on the bottom side).

The library comes with a Scanner example which will look for any I2C devices on all the ports. Running this Scanner example is usually the best way to begin troubleshooting. In Arduino IDE, again with Tools > Board set to Teensy 4.0, simply click File > Examples > Wire > Scanner to open this program.
 
You could look at this one. Has an ability to choose which wireX to use.
Alternatively you could choose a library with a fixed wire and change all entries to wire2 or wire3.
Thank you very much BriComp: it seems to be what I needed.

The purpose of my test program (herebelow) is to check what happens when the cursor goes over the length of the LCD row. For ex, I use a 2x24 display, and I need to know what happens if the program sends the cursor in position 25: does it goes back to the beginning of the line or not.

I have adapted the program with your library, here it is:
Code:
#include <Arduino.h>
#include <Wire.h>

/*
The two following libraries are no longer in use, they are replaced by "LCDi2c.h" that undertakes wire2.
#include <hd44780.h>                        // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h>  // i2c expander i/o class header
*/
#include <LCDi2c.h>

#define LCD_ROWS    2
#define LCD_COLUMNS 24

// This pgm is built with PlatformIO, so it located here: C:\Users\ordic\Documents\PlatformIO\Projects\W9_T4__INT_v2.00\src\main.cpp
char version[21]="W9_T4_Test LCD_v2.00"; // Initialize the Firmware version, to be use later
                                    // The length of "version" is increased to 21 digits (too long for the 17 digits that i normally use).
/*
The purpose of this program is to test the LCD display with I2C on wire 2
We will see if the values of "LCD_ROWS" and "LCD_COLUMNS" are correctly managed, i.e. does the cusor comes back
to column 1 when column is > 24 (?); if not we will be obliged to manage this manually.
------------
Le but de ce pgm est de tester le fonctionnement du LCD sur wire2.
On verra si les dépassements des valeurs "ligne" et "colonne" sont gérés ou pas.
Par exemple si colonne devient >24, est-ce que "colonne" revient à 0 ? ou faut-il gérer ce dépassement dans ISR_WR ?
*/
/*
ces lignes s'utilisaient avec hd44780
const uint8_t nbCols = 24;
const uint8_t nbRows = 2;
hd44780_I2Cexp lcd;
*/

LCDi2c lcd(0x27, Wire2); //initialize on Wire2


// put function declarations here:
// int myFunction(int, int);

void setup() {
  // put your setup code here, to run once:
  // lcd.begin(nbCols, nbRows); avant: c'était avec hd44780
  lcd.begin(LCD_ROWS, LCD_COLUMNS); // for 2x24 display
  lcd.cls(); // clear LCD and set the cursor up and left.
 
  for (uint8_t i = 0; i < LCD_COLUMNS * LCD_ROWS; i++)// on dépasse vraiment la ligne
                                                      // we really exceed the normal length of the row
  {
    lcd.print(i % 10);
    delay(100);
  }
}

void loop() {
  // put your main code here, to run repeatedly:
}

// put function definitions here:
/*
int myFunction(int x, int y) {
  return x + y;
}
  */

PlatformIO compiles it with "success", and before I upload it into the T4, I would like your feedback.
Thank you very much,
 
Well i have uploaded the program into the T4 located on my motherboard, and the probleme is still the same: no display.

Here is the PlatfomIO upload report:
05.Test I2C v2 uploaded_no display.jpg

and here is the photo of the T4 with no display:
06.MB Test I2C v2_s_b.jpg


The LCD backlight is turned on but nothing is displayed.

I don't understand the problem: could it be my motherboard ? I doubt but it is always possible...

I could:
-remove the T4 from the motherboard,
-feed the T4 with 5V coming from the MB with Dupont wires,
-connect SDA and SCL with Dupont wires directly from the T4,
-power up the LCD with Dupont wires coming directly from the 3V3 of the MB (there would not be the 4k7 pull-up resistors in that case)...

But this is a lot of work maybe you have a better idea ?

Thank you very much,
 
Can you tell us the exact display module 6that you are using, so that we may be able to look it up.
Someone might even have the display and be able to more easily work out why it is not working.
 
Can you tell us the exact display module 6that you are using, so that we may be able to look it up.
Someone might even have the display and be able to more easily work out why it is not working.
Here is a
connexions a l'arriere.jpg
photo of the LCD, it is a "buydisplay" LCD but bought on Aliexpress: it arrived in a "buydisplay.com" parcel and looks authentic.
The backboard is this one: https://fr.aliexpress.com/item/1005003270817900.html

I have other possible I2C adapters (I can send a photo tomorrow if you wish) but the above is the most similar to the one shown on the "buydisplay.com" website.

... also, what is the motherboard you are using?
it is a MB that I have designed myself for this project, allowing to test the program that I will upload as soon as the I2C works.

Even if I have designed hundreds of PCBs, I may have done an error: this is why I have imagined to use Dupont wires instead of my motherboard (cf my post above).

Maybe not useful but here is an extract of the motherboard PCB:
01.MB T4 1.13 extract.jpg


I have designed and ordered a variant of this PCB that allow the use of the usual I2C pins (18 & 19), but for the time being, we don't know if it is a software problem or an hardware problem... This costs me weeks of time, as I cannot progress on the final program as long as this bloody I2C display does not work...

Thank you very much !
 
My quick look and I did not find any HD44780 that are 24x2... so probably not much help
Did find some on EBAY that are BOLYMIN BC2402A

Not sure if that is similar?
 
it is a "buydisplay" LCD but bought on Aliexpress: it arrived in a "buydisplay.com" parcel and looks authentic.
The backboard is this one: https://fr.aliexpress.com/item/1005003270817900.html

Can you tell us all the items you are using with exact links to buy? This Aliexpress link is only to the backboard. Which display are you using? Did you buy them together, or as separate items?

Edit: in other words, if I were attempt to reproduce the exact problem you're seeing, which specific items do I order from Aliexpress, buydisplay, or other sites? If some assembly is required, can you show photos of exactly how you soldered or otherwise wired them together, so I can try to follow the exact same steps? Also on the software side, how do I recreate exactly the same compile? PlatformIO allows almost anything to be changed, so for the sake of exactly reproducing a problem, Arduino IDE with almost nothing configurable gives a much better "known quantity" on the software side. But even with Arduino IDE, to precisely recreate a problem even with the full code also means knowing exactly which libraries were installed. I want to help you. So does everyone else here. Please consider giving us more specific info so we can see exactly which hardware and software you're really using, ideally precisely enough that anyone could attempt to reproduce the problem.
 
Last edited:
OK, lots of things here. If the display is a Buydisplay.com display, and I have no reason to believe that it isn't,
1) If you were to buy the display from Buydisplay.com, you are asked if you want a 5V interface or 3.3V interface. Which version do you have!?
If you have the 5v version you will have to use level translators 3.3v to 5v.​
2) You don't need a HD44780 driver but a LiquidCrystal_I2C driver. I suggest you use the one from the buyDisplay website here.
In fact a LiquidCrystal_I2C driver is included with Teensyduino but both are set to use the base Wire I2C.​
3) I suspect that the I2C to Display board already has I2C pull ups on it. Adding extra 4k7 may possibly cause a problem.
As far as I can see, the easiest solution would be to modify the library to use Wire2.
I have modified the Buydisplay driver to use Wire2 and re named it LiquidCrystal_I2Cw2.h and .cpp. Copies below:
LiquidCrystal_I2Cw2.h
C++:
//YWROBOT
#ifndef LiquidCrystal_I2Cw2_h
#define LiquidCrystal_I2Cw2_h

#include <inttypes.h>
#include "Print.h"
#include <Wire.h>

// commands
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80

// flags for display entry mode
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00

// flags for display on/off control
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00

// flags for display/cursor shift
#define LCD_DISPLAYMOVE 0x08
#define LCD_CURSORMOVE 0x00
#define LCD_MOVERIGHT 0x04
#define LCD_MOVELEFT 0x00

// flags for function set
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00

// flags for backlight control
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00

#define En B00000100  // Enable bit
#define Rw B00000010  // Read/Write bit
#define Rs B00000001  // Register select bit

class LiquidCrystal_I2Cw2 : public Print {
public:
  LiquidCrystal_I2Cw2(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows);
  void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS );
  void clear();
  void home();
  void noDisplay();
  void display();
  void noBlink();
  void blink();
  void noCursor();
  void cursor();
  void scrollDisplayLeft();
  void scrollDisplayRight();
  void printLeft();
  void printRight();
  void leftToRight();
  void rightToLeft();
  void shiftIncrement();
  void shiftDecrement();
  void noBacklight();
  void backlight();
  void autoscroll();
  void noAutoscroll();
  void createChar(uint8_t, uint8_t[]);
  void setCursor(uint8_t, uint8_t);
#if defined(ARDUINO) && ARDUINO >= 100
  virtual size_t write(uint8_t);
#else
  virtual void write(uint8_t);
#endif
  void command(uint8_t);
  void init();

////compatibility API function aliases
void blink_on();                        // alias for blink()
void blink_off();                           // alias for noBlink()
void cursor_on();                               // alias for cursor()
void cursor_off();                          // alias for noCursor()
void setBacklight(uint8_t new_val);                // alias for backlight() and nobacklight()
void load_custom_character(uint8_t char_num, uint8_t *rows);    // alias for createChar()
void printstr(const char[]);

////Unsupported API functions (not implemented in this library)
uint8_t status();
void setContrast(uint8_t new_val);
uint8_t keypad();
void setDelay(int,int);
void on();
void off();
uint8_t init_bargraph(uint8_t graphtype);
void draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len,  uint8_t pixel_col_end);
void draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len,  uint8_t pixel_col_end);
   

private:
  void init_priv();
  void send(uint8_t, uint8_t);
  void write4bits(uint8_t);
  void expanderWrite(uint8_t);
  void pulseEnable(uint8_t);
  uint8_t _Addr;
  uint8_t _displayfunction;
  uint8_t _displaycontrol;
  uint8_t _displaymode;
  uint8_t _numlines;
  uint8_t _cols;
  uint8_t _rows;
  uint8_t _backlightval;
};

#endif
...and LiquidCrystal_I2C_Wire2.cpp

C++:
//Support Forum: http://www.buydisplay.com
//Compatible with the Arduino IDE 1.6.0


#include "LiquidCrystal_I2Cw2.h"
#include <inttypes.h>
#if defined(ARDUINO) && ARDUINO >= 100

#include "Arduino.h"

#define printIIC(args)    Wire2.write(args)
inline size_t LiquidCrystal_I2Cw2::write(uint8_t value) {
    send(value, Rs);
    return 0;
}

#else
#include "WProgram.h"

#define printIIC(args)    Wire2.send(args)
inline void LiquidCrystal_I2Cw2::write(uint8_t value) {
    send(value, Rs);
}

#endif
#include "Wire.h"



// When the display powers up, it is configured as follows:
//
// 1. Display clear
// 2. Function set:
//    DL = 1; 8-bit interface data
//    N = 0; 1-line display
//    F = 0; 5x8 dot character font
// 3. Display on/off control:
//    D = 0; Display off
//    C = 0; Cursor off
//    B = 0; Blinking off
// 4. Entry mode set:
//    I/D = 1; Increment by 1
//    S = 0; No shift
//
// Note, however, that resetting the Arduino doesn't reset the LCD, so we
// can't assume that its in that state when a sketch starts (and the
// LiquidCrystal constructor is called).

LiquidCrystal_I2Cw2::LiquidCrystal_I2Cw2(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows)
{
  _Addr = lcd_Addr;
  _cols = lcd_cols;
  _rows = lcd_rows;
  _backlightval = LCD_NOBACKLIGHT;
}

void LiquidCrystal_I2Cw2::init(){
    init_priv();
}

void LiquidCrystal_I2Cw2::init_priv()
{
    Wire2.begin();
    _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
    begin(_cols, _rows);
}

void LiquidCrystal_I2Cw2::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
    if (lines > 1) {
        _displayfunction |= LCD_2LINE;
    }
    _numlines = lines;

    // for some 1 line displays you can select a 10 pixel high font
    if ((dotsize != 0) && (lines == 1)) {
        _displayfunction |= LCD_5x10DOTS;
    }

    // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
    // according to datasheet, we need at least 40ms after power rises above 2.7V
    // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
    delay(50);
 
    // Now we pull both RS and R/W low to begin commands
    expanderWrite(_backlightval);    // reset expanderand turn backlight off (Bit 8 =1)
    delay(1000);

      //put the LCD into 4 bit mode
    // this is according to the hitachi HD44780 datasheet
    // figure 24, pg 46
   
      // we start in 8bit mode, try to set 4 bit mode
   write4bits(0x03 << 4);
   delayMicroseconds(4500); // wait min 4.1ms
 
   // second try
   write4bits(0x03 << 4);
   delayMicroseconds(4500); // wait min 4.1ms
 
   // third go!
   write4bits(0x03 << 4);
   delayMicroseconds(150);
 
   // finally, set to 4-bit interface
   write4bits(0x02 << 4);


    // set # lines, font size, etc.
    command(LCD_FUNCTIONSET | _displayfunction);
   
    // turn the display on with no cursor or blinking default
    _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
    display();
   
    // clear it off
    clear();
   
    // Initialize to default text direction (for roman languages)
    _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
   
    // set the entry mode
    command(LCD_ENTRYMODESET | _displaymode);
   
    home();
 
}

/********** high level commands, for the user! */
void LiquidCrystal_I2Cw2::clear(){
    command(LCD_CLEARDISPLAY);// clear display, set cursor position to zero
    delayMicroseconds(2000);  // this command takes a long time!
}

void LiquidCrystal_I2Cw2::home(){
    command(LCD_RETURNHOME);  // set cursor position to zero
    delayMicroseconds(2000);  // this command takes a long time!
}

void LiquidCrystal_I2Cw2::setCursor(uint8_t col, uint8_t row){
    int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
    if ( row > _numlines ) {
        row = _numlines-1;    // we count rows starting w/0
    }
    command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
}

// Turn the display on/off (quickly)
void LiquidCrystal_I2Cw2::noDisplay() {
    _displaycontrol &= ~LCD_DISPLAYON;
    command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal_I2Cw2::display() {
    _displaycontrol |= LCD_DISPLAYON;
    command(LCD_DISPLAYCONTROL | _displaycontrol);
}

// Turns the underline cursor on/off
void LiquidCrystal_I2Cw2::noCursor() {
    _displaycontrol &= ~LCD_CURSORON;
    command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal_I2Cw2::cursor() {
    _displaycontrol |= LCD_CURSORON;
    command(LCD_DISPLAYCONTROL | _displaycontrol);
}

// Turn on and off the blinking cursor
void LiquidCrystal_I2Cw2::noBlink() {
    _displaycontrol &= ~LCD_BLINKON;
    command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal_I2Cw2::blink() {
    _displaycontrol |= LCD_BLINKON;
    command(LCD_DISPLAYCONTROL | _displaycontrol);
}

// These commands scroll the display without changing the RAM
void LiquidCrystal_I2Cw2::scrollDisplayLeft(void) {
    command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
}
void LiquidCrystal_I2Cw2::scrollDisplayRight(void) {
    command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
}

// This is for text that flows Left to Right
void LiquidCrystal_I2Cw2::leftToRight(void) {
    _displaymode |= LCD_ENTRYLEFT;
    command(LCD_ENTRYMODESET | _displaymode);
}

// This is for text that flows Right to Left
void LiquidCrystal_I2Cw2::rightToLeft(void) {
    _displaymode &= ~LCD_ENTRYLEFT;
    command(LCD_ENTRYMODESET | _displaymode);
}

// This will 'right justify' text from the cursor
void LiquidCrystal_I2Cw2::autoscroll(void) {
    _displaymode |= LCD_ENTRYSHIFTINCREMENT;
    command(LCD_ENTRYMODESET | _displaymode);
}

// This will 'left justify' text from the cursor
void LiquidCrystal_I2Cw2::noAutoscroll(void) {
    _displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
    command(LCD_ENTRYMODESET | _displaymode);
}

// Allows us to fill the first 8 CGRAM locations
// with custom characters
void LiquidCrystal_I2Cw2::createChar(uint8_t location, uint8_t charmap[]) {
    location &= 0x7; // we only have 8 locations 0-7
    command(LCD_SETCGRAMADDR | (location << 3));
    for (int i=0; i<8; i++) {
        write(charmap[i]);
    }
}

// Turn the (optional) backlight off/on
void LiquidCrystal_I2Cw2::noBacklight(void) {
    _backlightval=LCD_NOBACKLIGHT;
    expanderWrite(0);
}

void LiquidCrystal_I2Cw2::backlight(void) {
    _backlightval=LCD_BACKLIGHT;
    expanderWrite(0);
}



/*********** mid level commands, for sending data/cmds */

inline void LiquidCrystal_I2Cw2::command(uint8_t value) {
    send(value, 0);
}


/************ low level data pushing commands **********/

// write either command or data
void LiquidCrystal_I2Cw2::send(uint8_t value, uint8_t mode) {
    uint8_t highnib=value&0xf0;
    uint8_t lownib=(value<<4)&0xf0;
       write4bits((highnib)|mode);
    write4bits((lownib)|mode);
}

void LiquidCrystal_I2Cw2::write4bits(uint8_t value) {
    expanderWrite(value);
    pulseEnable(value);
}

void LiquidCrystal_I2Cw2::expanderWrite(uint8_t _data){                                      
    Wire2.beginTransmission(_Addr);
    printIIC((int)(_data) | _backlightval);
    Wire2.endTransmission();  
}

void LiquidCrystal_I2Cw2::pulseEnable(uint8_t _data){
    expanderWrite(_data | En);    // En high
    delayMicroseconds(1);        // enable pulse must be >450ns
   
    expanderWrite(_data & ~En);    // En low
    delayMicroseconds(50);        // commands need > 37us to settle
}


// Alias functions

void LiquidCrystal_I2Cw2::cursor_on(){
    cursor();
}

void LiquidCrystal_I2Cw2::cursor_off(){
    noCursor();
}

void LiquidCrystal_I2Cw2::blink_on(){
    blink();
}

void LiquidCrystal_I2Cw2::blink_off(){
    noBlink();
}

void LiquidCrystal_I2Cw2::load_custom_character(uint8_t char_num, uint8_t *rows){
        createChar(char_num, rows);
}

void LiquidCrystal_I2Cw2::setBacklight(uint8_t new_val){
    if(new_val){
        backlight();        // turn backlight on
    }else{
        noBacklight();        // turn backlight off
    }
}

void LiquidCrystal_I2Cw2::printstr(const char c[]){
    //This function is not identical to the function used for "real" I2C displays
    //it's here so the user sketch doesn't have to be changed
    print(c);
}


// unsupported API functions
void LiquidCrystal_I2Cw2::off(){}
void LiquidCrystal_I2Cw2::on(){}
void LiquidCrystal_I2Cw2::setDelay (int cmdDelay,int charDelay) {}
uint8_t LiquidCrystal_I2Cw2::status(){return 0;}
uint8_t LiquidCrystal_I2Cw2::keypad (){return 0;}
uint8_t LiquidCrystal_I2Cw2::init_bargraph(uint8_t graphtype){return 0;}
void LiquidCrystal_I2Cw2::draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len,  uint8_t pixel_col_end){}
void LiquidCrystal_I2Cw2::draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len,  uint8_t pixel_row_end){}
void LiquidCrystal_I2Cw2::setContrast(uint8_t new_val){}
...and a HelloWorld example.
Code:
//www.buydisplay.com
//Compatible with the Arduino IDE 1.6.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2Cw2.h>

LiquidCrystal_I2Cw2 lcd(0x27,24,2);  // set the LCD address to 0x27(PCF8574T)

void setup()
{
  lcd.init();                      // initialize the lcd
 
  // Print a message to the LCD.
  lcd.backlight();
  lcd.print("Hello, world!");
}

void loop()
{
}
 
Which version do you have!?
If you have the 5v version you will have to use level translators 3.3v to 5v.
I have ordered a 3V3 version: is there a way to check that they have not sent a 5V version ?

2) You don't need a HD44780 driver but a LiquidCrystal_I2C driver. I suggest you use the one from the buyDisplay website here.
In fact a LiquidCrystal_I2C driver is included with Teensyduino but both are set to use the base Wire I2C.
You are probably right: I thought about the same because on the "buydisplay.com" website, amm the examples use the LiquidCrystal_I2C library. I had been told to use the hd44780, but it is maybe not a good choice.
I will modify the program to use the LiquidCrystal_I2C library, and I come back here to give you te result.
I have modified the Buydisplay driver to use Wire2 and re named it LiquidCrystal_I2Cw2.h and .cpp. Copies below:
Congratulations for this code and thank you very much: it is too late this evening but I will test tomorrow.
3) I suspect that the I2C to Display board already has I2C pull ups on it. Adding extra 4k7 may possibly cause a problem.
I used to add the pull-up resistors with the Arduino boards, but if there is no risk for the Teensy 4.0 I can unsoldered the resistors and bypass them with a piece of wire: will do it tomorrow.
This Aliexpress link is only to the backboard. Which display are you using? Did you buy them together, or as separate items?

you are right: the link to the LCD has disappeared on Aliexpress, only the link to the backbard remains: strange.
I bought them separately, there were 2 different URLs.
If some assembly is required, can you show photos of exactly how you soldered or otherwise wired them together, so I can try to follow the exact same steps?
Here they are:
01.LCD & MB_s_b.jpg

02.LCD back_s_b.jpg


I don't know if these photos are enough for you (?): I will add a zoom on the I2C connector on my next post.
 
Here is a zoom on the PCB I2C connector:
03.zoom on the PCB.jpg

From Left to right the PCB connector shows: SDA (Blue), SCL (Yellow), GND (Black), 3V3 (Red).
Unless I am wrong, the color match with the backboard of the LCD.
 
Amazon delivered the display. As a first test, I powered with 5 volts. Indeed it does have pullup resistors to 5V. A quick ohms measurement with power off shows 4.7K.

I connected on a breadboard, with 5V power and adding 4.7K resistors to 3.3V.

lcd2.jpg


Quick voltage measurement without any connection to Teensy showed 4.2V.

When I connect wires to Teensy pins 18 & 19, the voltage drops to 3.7V. So some current is flowing into the Teensy pins and gets directed to 3.3V by the ESD protection diodes. Not wonderful, but should work.

Next I installed the LiquidCrystal_I2C library in Arduino IDE 2.3.7.

lcd3.png


I opened its Hello World example. When I updated to Teensy, the display does indeed show Hello World.

lcd1.jpg


This is with no changes to the Hello World example, not even editing the display size which is 20 by 4 in the example (which might explain the garbled text on the 2nd line).

Just to wrap up this first quick tests, here's a photo of the back side of the display, so you see how the wires are connected and the small details of the display Amazon delivered today.

lcd4.jpg
 
Next I tried connecting the display power to 3.3V instead of 5V (using the exact same known-good example code from the previous test). I can confirm this display does *NOT* work with 3.3V power. The backlight turns on, but nothing appears on the screen.

lcd5.jpg


For another "nothing happens" test, I programmed Teensy with basic LED blink so it would not communicate with the display. Then I plugged the display power back into 5V. Here is the result:

lcd6.jpg


You can see in this photo the display initializes its first line to all the pixels on. Even though this could be described as "nothing", you can use this difference to easily see whether the electronics on the display are running and waiting for communication.

I'm pretty sure the problems you're seeing are because the display simply does not work with 3.3V power, since your photo in msg #12 looks like this first case where the pixels in the first row are not turned on. Assuming your display works the same way, if the problem were no communication or wrong communication, you'd expect to at least see pixels turned on for some or all of the first line (some other displays might turn on the pixels in the first 8 characters only... based on my experience with other character displays).
 
Last edited:
Back
Top