hasenradball / LCD-I2C

C++ Library for Liquid Crystal LCD Displays with the HD44780 driver
MIT License
5 stars 0 forks source link

beginning lcd on Wire1 instead of Wire (uno R4 wifi) #11

Closed hugomflavio closed 1 week ago

hugomflavio commented 2 weeks ago

Hi!

Thank you for maintaining this library; it is helping me a lot with programming an arduino uno R4 wifi with a 20x4 LCD.

So far, I've been using pins A4 and A5 for the data and clock pins, but I was hoping to be able to ultimately use the QWIIC connector included with the board. I saw here that, to do that, I must specify that I want to use Wire1.begin(), instead of Wire.begin(). I tried:

1) defining it myself and use the bool beginWire option in the begin() function. I.e.:

#include <LCD-I2C.h>
LCD_I2C lcd(0x27, 20, 4);
...
Wire1.begin();
lcd.begin(false);

2) editing line 11 in the library's LCD_I2C.cpp file to modify the Wire.begin() call to Wire1.begin();

But sadly none of the two worked out.. Would you have any advice towards successfully connect through the QWIIC connector?

Thank you for your time!

hasenradball commented 2 weeks ago

what kind of display are you using? Do you have a picture?

hugomflavio commented 2 weeks ago

It's one of these: https://www.amazon.ca/GeeekPi-Interface-Adapter-Backlight-Raspberry/dp/B086VVT4NH

Some pictures:

PXL_20240831_121546620.jpg

PXL_20240831_121539063.jpg

And one example of it working nicely on pins A4 and A5:

PXL_20240827_121119839.jpg

hasenradball commented 2 weeks ago

So please let me go step by step....

1.) does the LCD work with the normal I2C Pins? on the Picture it does seem yes.

2.) Does it only not work with the QWICK Connector?

3.) Have you checked the wiring of the Connector?

best Frank

hugomflavio commented 2 weeks ago

Yes, that is correct. I was able to code the whole program with the normal I2C pins. It only doesn't work when connected through the qwiic port.

I have been able to find the LCD's address when it is connected to the qwiic port using the Wire1.begin() instead of Wire.begin(), so the port and the LCD are working. I just don't know how to tell LCD_I2C to use the "Wire1" connection instead of the default "Wire"

On Sat, 31 Aug 2024, 09:04 Hasenradball, @.***> wrote:

So please let me go step by step....

1.) does the LCD work with the normal I2C Pins? on the Picture it does seem yes.

2.) Does it only not work with the QWICK Connector?

best Frank

— Reply to this email directly, view it on GitHub https://github.com/hasenradball/LCD-I2C/issues/11#issuecomment-2322891465, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJUETHIBK7M34JQA4VYADZTZUG5NJAVCNFSM6AAAAABNNPYNYGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRSHA4TCNBWGU . You are receiving this because you authored the thread.Message ID: @.***>

hugomflavio commented 2 weeks ago

3.) Have you checked the wiring of the Connector?

Sorry, I didn't see this one, but yes I am able to find the LCD's address when it is connected to the qwiic, so I am confident I plugged everything in correctly.

hasenradball commented 2 weeks ago

ok no I got You Point....

You have to replace the Wire. in the following lines by Wire1.

The it should work fine.

hasenradball commented 2 weeks ago

Does it work?

hugomflavio commented 2 weeks ago

Sorry for the delay, my laptop's upgrade to ubuntu 24 failed halfway through, so I had to spend most of the day fixing it...

Back to this. I tried changing Wire to Wire1 on the lines you mentioned. The LCD still doesn't show any text, but I did notice that now it flashes off and back on every time the arduino resets (while before it stayed on all the time). Like so:

https://github.com/user-attachments/assets/30c08ac9-02aa-44a9-9707-5e6c08dae463

Reverting back from Wire1 to Wire makes the flashing go away, so this seems like a step in the right direction... Not sure why it isn't displaying any text though.

hasenradball commented 1 week ago

See also this…

https://forum.arduino.cc/t/wire1-with-pcf8575-on-uno-r4-only-runs-once/1193877/8

hasenradball commented 1 week ago

Hi Hugo,

Iam sorry it seems to be a Arduino problem, maybee. One think I habe in mind could be if the wire1 lines hascthe pullup resistors mounted for the i2c…?

hasenradball commented 1 week ago

Other point would be check with an other i2c sensor or else on the wire1 line

hugomflavio commented 1 week ago

hm... sad to hear. I don't have another i2c sensor on hand (only a 8x8 Matrix from this kit, but that doesn't use the wire library). I don't really know how to check if the wire library is pulling up the resistors for the QWIIC (sorry, still somewhat new to all this). I'll go back to using A4 and A5 for now; I only wanted to use the QWIIC to make the setup cleaner. :grin:

This sketch is able to find and ID the LCD, which I thought meant it was working right. But alas. Feel free to close, I'll keep an eye out if anything changes in the future :)

// SPDX-FileCopyrightText: 2023 Carter Nelson for Adafruit Industries
//
// SPDX-License-Identifier: MIT
// --------------------------------------
// i2c_scanner
//
// Modified from https://playground.arduino.cc/Main/I2cScanner/
// --------------------------------------

#include <Wire.h>

// Set I2C bus to use: Wire, Wire1, etc.

void setup() {
  Wire1.begin();

  Serial.begin(9600);
  while (!Serial)
     delay(10);
  Serial.println("\nI2C Scanner");
}

void loop() {
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire1.beginTransmission(address);
    error = Wire1.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}
hasenradball commented 1 week ago

maybee thi could be a last point to check…

Some LCDs need 5 V for Vcc, but the quick connector has only 3,3 V…

image

hugomflavio commented 1 week ago

Oh that might actually be it! The amazon description says these LCDs only work at 5V.

On Sun, 1 Sept 2024, 12:20 Hasenradball, @.***> wrote:

maybee thi could be a last point to check…

Some LCDs need 5 V for Vcc, but the quick connector has only 3,3 V…

image.png (view on web) https://github.com/user-attachments/assets/b17178f9-3142-44b6-b65b-7f34da7c0925

— Reply to this email directly, view it on GitHub https://github.com/hasenradball/LCD-I2C/issues/11#issuecomment-2323413971, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJUETHJGYIQ4NSLMXZ2SP2LZUM5FHAVCNFSM6AAAAABNNPYNYGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRTGQYTGOJXGE . You are receiving this because you authored the thread.Message ID: @.***>

hugomflavio commented 1 week ago

Just tried swapping out only the power wires (i.e power from the 5v pin, but data through the QWIIC port), et voilà, it started working!

hugomflavio commented 1 week ago

well, sadly this means I can't use the QWIIC port for this LCD. But at least the mystery is solved. Thanks a lot for the help! :)

hasenradball commented 1 week ago

Hugo your welcome.

maybee it could be a good solution to pass the wire instance to the constructor. So you don‘t need to change the lines discussed above. If i Do such a change would you test it for me?

best Frank

hugomflavio commented 1 week ago

Yeah I can test it 👍

On Sun, 1 Sept 2024, 14:51 Hasenradball, @.***> wrote:

Hugo your welcome.

maybee it could be a good solution to pass the wire instance to the constructor. So you don‘t need to change the lines discussed above. If i Do such a change would you test it for me?

best Frank

— Reply to this email directly, view it on GitHub https://github.com/hasenradball/LCD-I2C/issues/11#issuecomment-2323458250, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJUETHKVHLESRYMSD2QJKEDZUNO2BAVCNFSM6AAAAABNNPYNYGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRTGQ2TQMRVGA . You are receiving this because you authored the thread.Message ID: @.***>

hasenradball commented 1 week ago

@hugomflavio

I created now a new branch where you give the Wire / Wire1 object as reference in the begin Method of the LCD object. See the examples....

#include <LCD-I2C.h>
#include <Wire.h>

LCD_I2C lcd(0x27, 16, 2);

void setup() {
  Wire.begin();
  lcd.begin(&Wire);
  lcd.display();
  lcd.backlight();
}

Would be great if you can test it.

hugomflavio commented 1 week ago

Can confirm that the new_wire_interface branch allowed me to easily switch the wire connection I'm using. I tried both Wire1 (QWIIC) and Wire (A4 and A5), and both worked nicely. Thanks for the update!

hasenradball commented 1 week ago

so thanks a lot, will bring it to main branch in a few days. Youre welcome…

hasenradball commented 1 week ago

@hugomflavio should be tomorrow inthe Arduino library index.