I2C GLCD on MKR board?

Posted by Cambo on Fri 08 Apr 2022 01:37 PM — 7 posts, 30,516 views.

#0
Hi Nick,

Your GLCD I2C hardware and library (http://www.gammon.com.au/lcd) work great for me and I've been using them for some years now, thank you. I'm keen to get the code working on the MKR SAMD boards and whilst the code compiles OK it doesn't work and I can't really see why - would you be up for givung me a pointer as to which parts of the library I should be looking at to get this working? Cheers.
Amended on Fri 08 Apr 2022 01:39 PM by Cambo
Australia Forum Administrator #1
I have virtually no experience with the SAMD boards, so I can't help you, sorry.

I suggest you ask on the Arduino Forum or Arduino Stack Exchange as per the boilerplate below.

Template:Arduino
Please post Arduino-related questions to the Arduino Forum or to StackExchange: Arduino. This saves splitting questions and answers between this forum and the Arduino ones.
#2
Hi Nick,

Thanks for getting back to me, appreciated.

Kind regards
#3
PS, for anyone else follwoing along.... the issue comes from the first call of Wire.endTransmission() in LCD.begin() which crashes the MCU - when I find the solution I will post the fix.
Australia Forum Administrator #4
On the AVR boards the endTransmission is where the work is actually done, so perhaps there is a clash between that and initialising the LCD.
#5
Thanks Nick, I've tested some more and found that this error occurs regardless of whether the LCD is connected or not. I've also found that your I2C Scanner code returns a valid device address as per below. This is leading me to think that whatever is being sent in the first bunch of LCD.begin() data is throwing the issue. I've tried changing the I2C clock speed from 10000 to 1000000 with other speeds in-between but no change is observed.... I will try to figure out 'what' is being sent in that first packet of data.

I2C scanner. Scanning ...
Found address: 32 (0x20)
Found address: 64 (0x40)
Found address: 104 (0x68)
Found address: 110 (0x6E)
Done.
Found 4 device(s).
#6
Hi Nick,

A quick update with a little progress. I can get the backlight LED to blink on and off with the code below so the hardware and basic operation is working on the ARM.... now just have to work out why the demo doesn't work.

#include <Wire.h>

void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}

void loop()
{

Wire.beginTransmission (0x20); // expander has I2C address 0x20
Wire.write (0x00); // register 0 is the I/O direction register for Port A
Wire.write (0x00); // 0x00 for all pins to output mode, 0xFF for all pins to input mode
Wire.endTransmission ();

Wire.beginTransmission (0x20); // expander has I2C address 0x20
Wire.write (0x12); // register 0x12 is the I/O port "A"
Wire.write (0x56); // what to put on that port
Wire.endTransmission ();

Wire.beginTransmission (0x20); // expander has I2C address 0x20
Wire.write (0x12); // register 0x12 is the I/O port "A"
Wire.write (0x3F); // 0x3F turns the backlight on.
Wire.endTransmission ();

delay (1000);

Wire.beginTransmission (0x20); // expander has I2C address 0x20
Wire.write (0x12); // register 0x12 is the I/O port "A"
Wire.write (0x3E); // 0x3E turns the backlight off.
Wire.endTransmission ();

}