Simple example of I2c code " My World" request
-
- Posts: 35
- Joined: Tue Mar 22, 2022 11:17 pm
Simple example of I2c code " My World" request
I have been looking through the forum and could not find a straightforward and well documented example of being able to display a simple text string like "My World" on a basic Ic2 lcd display. For example, the simple 2 or 4 line displays from Matrix Orbital. Would be greatly appreciated if someone could post!
Re: Simple example of I2c code " My World" request
You might check this thread in the forum
viewtopic.php?f=4&t=956&p=3250
Or check the blog post, where we interface to byte/nibble serial interfaces
https://www.coridium.us/coridium/blog/lcd-interface-pcb
Both turned up in searches for LCD on the main page
viewtopic.php?f=4&t=956&p=3250
Or check the blog post, where we interface to byte/nibble serial interfaces
https://www.coridium.us/coridium/blog/lcd-interface-pcb
Both turned up in searches for LCD on the main page
-
- Posts: 35
- Joined: Tue Mar 22, 2022 11:17 pm
Re: Simple example of I2c code " My World" request
I posted this a year ago and still no example simple code block to send a simple text message.
Neither of the links contain any useful code. Would like a simple example of sending the string "Hello World" to an IC2 display'
Thanks
Neither of the links contain any useful code. Would like a simple example of sending the string "Hello World" to an IC2 display'
Thanks
Re: Simple example of I2c code " My World" request
I don't have any i2c displays, always opted for either serial or SPI.
Do the displays you have supply code examples?
-- edit --
I was looking at the website for Matrix Orbital, very expensive, take a look at New Haven 1/5 the cost and we have published examples. Digikey also carries them.
Do the displays you have supply code examples?
-- edit --
I was looking at the website for Matrix Orbital, very expensive, take a look at New Haven 1/5 the cost and we have published examples. Digikey also carries them.
-
- Posts: 35
- Joined: Tue Mar 22, 2022 11:17 pm
Re: Simple example of I2c code " My World" request
I already have a couple of Matrix Orbital units. I will however look at teh New Haven site for code examples
-
- Posts: 35
- Joined: Tue Mar 22, 2022 11:17 pm
Re: Simple example of I2c code " My World" request
I have set up a test environment with the superpro and a matrix orbital glk19264A-7T display using SCL on pin 11 and SDA on pin 10. 4.7k from both lines to +5v.
The manual for the display can be found at the bottom of this page https://www.matrixorbital.com/glk19264a-7t-1u
The display powers up and the jumpers are preset to I2C.
The display is not returning any response to my code present = 0
The code is as follows:
------[ Display Address]------------
' Matrix Orbital
' Address is 0x50 for Write and 0x51 for read
#include <I2c.bas>
#include <LPC17xx.bas>
#define I2C_SDA 10 ' Pin # 10 ' I2C SDA
#define I2C_SCL 11 ' Pin # 11 ' I2C SCL
#define I2Cspeed50 50 ' clock set to 50kb
#define I2C_LCD_ADDR 80 ' &H50
'---------------[ I2C Routines for the LCD Display ]-------------------
'-----------------------[ Init LCD ]-----------------------------------
' Initialization For ST7036i
' I2COUT (SDApin, SCLpin, addr, OUTcnt, BYREF OUTlist as string)
'----------------------------------------------------------------------
Sub Init_LCD
DIM JMDString(20) as String
DIM msgrow(20) as String ' Holds message to be displayed
DIM LCD_String(6) as String
DIM i2cPresent as integer
DIM ADx as INTEGER
DIM LCD_Row(5) as String
Dim RowNum as Integer
JMDString = "James McDougall"
Print "Init LCD"
LCD_String(0) = 254 ' Function Set Basic
' Continue to send commands in 'Basic mode'
' select protocol
LCD_String(1) = 160 '
LCD_String(2) = 0x00
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 3, LCD_String)
print "i2cPresent = "; i2cPresent
WAIT(250) ' Delay 250mS
'
LCD_String(1) = 82 ' Set Auto Line Feed wrap Off
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 2, LCD_String)
print "i2cPresent = "; i2cPresent
WAIT(250) ' Delay 250mS
'LCD_String(1) = 66 ' Display ON
' i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 2, LCD_String)
' print "i2cPresent = "; i2cPresent
' WAIT(250) ' Delay 250mS
LCD_String(1) = 88 ' Clear Display
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 2, LCD_String)
print "i2cPresent = "; i2cPresent
WAIT(250) ' Delay 250mS
LCD_String(1) = 72 ' Go to Home
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 2, LCD_String)
print "i2cPresent = "; i2cPresent
WAIT(250) ' Delay 250mS
'----------------------------------------------------------------------
' McDougall screen
'----------------------------------------------------------------------
LCD_Row(0) = 254 ' 0011 1000 0x38 Function Set Basic
LCD_Row(1) = 121 ' 1100 0000 0xC0 Set cursor
LCD_Row(2) = 1 ' 1100 0000 0xC0 Set column
LCD_Row(3) = 1 ' 1100 0000 0xC0 Set row
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 4, LCD_Row)
WAIT(250)
' send name string
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 15, JMDString)
WAIT(250) ' Delay 250mS
' Call LCD_DisplayMsg(1,3))
' i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 20, 3)
Wait(250)
JMDString = "@ Copyright 2022 "
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 20, JMDString)
' set led top to green
LCD_Row(0) = 254 ' 0011 1000 0x38 Function Set Basic
LCD_Row(1) = 90 ' 1100 0000 0xC0 Set cursor
LCD_Row(2) = 0 ' 1100 0000 0xC0 Set column
LCD_Row(3) = 1 ' 1100 0000 0xC0 Set row
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 4, LCD_Row)
WAIT(250)
RETURN
EndSub
'----------------------------------------------------------------------
' Clear Display
'----------------------------------------------------------------------
Sub LCD_Clear
DIm clrpresent as integer
DIM LCD_Clr(2) as String
LCD_Clr(0) = 254 ' Function Set Basic
LCD_Clr(1) = 88 ' Clear Screen
clrpresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 1, LCD_Clr)
WAIT(500)
RETURN
EndSub
'----------------------------------------------------------------------
' This is common code for displaying a row on a specific line on the LCD
'----------------------------------------------------------------------
SUB LCD_DisplayMsg(BYREF rownum as integer, BYREF msgrow as String) ' Line Msg
DIM msgpresent as Integer
DIM LCD_Row(5) as String
LCD_Row(0) = 254 ' 0011 1000 0x38 Function Set Basic
LCD_Row(1) = 71 ' 1100 0000 0xC0 Set cursor
LCD_Row(2) = 1 ' 1100 0000 0xC0 Set column
LCD_Row(3) = rownum ' 1100 0000 0xC0 Set row
msgpresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 4, LCD_Row)
WAIT(250)
msgpresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 20, msgrow)
Wait(250)
RETURN
EndSub
MAIN:
GOSUB Init_LCD
END
IS there something I have missed or done wrong?
Thank You
The manual for the display can be found at the bottom of this page https://www.matrixorbital.com/glk19264a-7t-1u
The display powers up and the jumpers are preset to I2C.
The display is not returning any response to my code present = 0
The code is as follows:
------[ Display Address]------------
' Matrix Orbital
' Address is 0x50 for Write and 0x51 for read
#include <I2c.bas>
#include <LPC17xx.bas>
#define I2C_SDA 10 ' Pin # 10 ' I2C SDA
#define I2C_SCL 11 ' Pin # 11 ' I2C SCL
#define I2Cspeed50 50 ' clock set to 50kb
#define I2C_LCD_ADDR 80 ' &H50
'---------------[ I2C Routines for the LCD Display ]-------------------
'-----------------------[ Init LCD ]-----------------------------------
' Initialization For ST7036i
' I2COUT (SDApin, SCLpin, addr, OUTcnt, BYREF OUTlist as string)
'----------------------------------------------------------------------
Sub Init_LCD
DIM JMDString(20) as String
DIM msgrow(20) as String ' Holds message to be displayed
DIM LCD_String(6) as String
DIM i2cPresent as integer
DIM ADx as INTEGER
DIM LCD_Row(5) as String
Dim RowNum as Integer
JMDString = "James McDougall"
Print "Init LCD"
LCD_String(0) = 254 ' Function Set Basic
' Continue to send commands in 'Basic mode'
' select protocol
LCD_String(1) = 160 '
LCD_String(2) = 0x00
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 3, LCD_String)
print "i2cPresent = "; i2cPresent
WAIT(250) ' Delay 250mS
'
LCD_String(1) = 82 ' Set Auto Line Feed wrap Off
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 2, LCD_String)
print "i2cPresent = "; i2cPresent
WAIT(250) ' Delay 250mS
'LCD_String(1) = 66 ' Display ON
' i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 2, LCD_String)
' print "i2cPresent = "; i2cPresent
' WAIT(250) ' Delay 250mS
LCD_String(1) = 88 ' Clear Display
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 2, LCD_String)
print "i2cPresent = "; i2cPresent
WAIT(250) ' Delay 250mS
LCD_String(1) = 72 ' Go to Home
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 2, LCD_String)
print "i2cPresent = "; i2cPresent
WAIT(250) ' Delay 250mS
'----------------------------------------------------------------------
' McDougall screen
'----------------------------------------------------------------------
LCD_Row(0) = 254 ' 0011 1000 0x38 Function Set Basic
LCD_Row(1) = 121 ' 1100 0000 0xC0 Set cursor
LCD_Row(2) = 1 ' 1100 0000 0xC0 Set column
LCD_Row(3) = 1 ' 1100 0000 0xC0 Set row
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 4, LCD_Row)
WAIT(250)
' send name string
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 15, JMDString)
WAIT(250) ' Delay 250mS
' Call LCD_DisplayMsg(1,3))
' i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 20, 3)
Wait(250)
JMDString = "@ Copyright 2022 "
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 20, JMDString)
' set led top to green
LCD_Row(0) = 254 ' 0011 1000 0x38 Function Set Basic
LCD_Row(1) = 90 ' 1100 0000 0xC0 Set cursor
LCD_Row(2) = 0 ' 1100 0000 0xC0 Set column
LCD_Row(3) = 1 ' 1100 0000 0xC0 Set row
i2cPresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 4, LCD_Row)
WAIT(250)
RETURN
EndSub
'----------------------------------------------------------------------
' Clear Display
'----------------------------------------------------------------------
Sub LCD_Clear
DIm clrpresent as integer
DIM LCD_Clr(2) as String
LCD_Clr(0) = 254 ' Function Set Basic
LCD_Clr(1) = 88 ' Clear Screen
clrpresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 1, LCD_Clr)
WAIT(500)
RETURN
EndSub
'----------------------------------------------------------------------
' This is common code for displaying a row on a specific line on the LCD
'----------------------------------------------------------------------
SUB LCD_DisplayMsg(BYREF rownum as integer, BYREF msgrow as String) ' Line Msg
DIM msgpresent as Integer
DIM LCD_Row(5) as String
LCD_Row(0) = 254 ' 0011 1000 0x38 Function Set Basic
LCD_Row(1) = 71 ' 1100 0000 0xC0 Set cursor
LCD_Row(2) = 1 ' 1100 0000 0xC0 Set column
LCD_Row(3) = rownum ' 1100 0000 0xC0 Set row
msgpresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 4, LCD_Row)
WAIT(250)
msgpresent = I2COut(I2C_SDA, I2C_SCL, I2C_LCD_ADDR, 20, msgrow)
Wait(250)
RETURN
EndSub
MAIN:
GOSUB Init_LCD
END
IS there something I have missed or done wrong?
Thank You
Re: Simple example of I2c code " My World" request
As I read the spec sheet, the 254, 160, 0 command would be sent in SERIAL mode to return data in i2c mode
If your jumpers are set to i2c that should not be needed.
Did you change it to i2c (from spec sheet)
The Protocol Select Jumpers provide the means necessary to toggle the GLK19264A-7T-1U between RS232, TTL and I²C protocols. As a default, the jumpers are set to RS-232 mode with solder jumps on the
RS232 jumpers. In order to place the display module in I²C mode you must first remove the solder jumps
from the RS232 jumpers and then place them on the I2
C jumpers. The display will now be in I²C mode
and have a default slave address of 80, unless changed with the appropriate command. Similarly, in
order to change the display to TTL mode, simply remove the zero ohm resistors from the RS232 or I²C
jumpers and solder them to the TTL jumpers.
Very hard for me the guess at the problem, as I don't have that display.
Do you have pullups on the i2c lines?
Actually why not use serial protocol, as that is the default?
What values do you see for i2cPresent? If 0 the device is not ACKnowledging
If your jumpers are set to i2c that should not be needed.
Did you change it to i2c (from spec sheet)
The Protocol Select Jumpers provide the means necessary to toggle the GLK19264A-7T-1U between RS232, TTL and I²C protocols. As a default, the jumpers are set to RS-232 mode with solder jumps on the
RS232 jumpers. In order to place the display module in I²C mode you must first remove the solder jumps
from the RS232 jumpers and then place them on the I2
C jumpers. The display will now be in I²C mode
and have a default slave address of 80, unless changed with the appropriate command. Similarly, in
order to change the display to TTL mode, simply remove the zero ohm resistors from the RS232 or I²C
jumpers and solder them to the TTL jumpers.
Very hard for me the guess at the problem, as I don't have that display.
Do you have pullups on the i2c lines?
Actually why not use serial protocol, as that is the default?
What values do you see for i2cPresent? If 0 the device is not ACKnowledging
Re: Simple example of I2c code " My World" request
Hi,
Have you been able to run a scan detection for the I2C address routine?
It normally scans all legal addresses, and then spits out some kind of address list/display?
'
I am currently looking for one.
Gary Olzeke51
here is some code for scanning devices , I had it working on a different board than yours.
will need to adjust some of the assignments
Have you been able to run a scan detection for the I2C address routine?
It normally scans all legal addresses, and then spits out some kind of address list/display?
'
I am currently looking for one.
Gary Olzeke51
here is some code for scanning devices , I had it working on a different board than yours.
will need to adjust some of the assignments
Code: Select all
' i2c device present per AB example in helpfile
'
'SUB I2CIN ( DATApin, CLKpin, addr, OUTcnt, BYREF shortMessage as string, INcnt, BYREF INlist as string)
'
'FUNCTION I2COUT (DATApin, CLKpin, addr, OUTcnt, BYREF shortMessage as string)
'
'
'
'#define I2Cspeed100 ' add this statement before the #include <I2C.bas> for 100 Kb shift rate
'define I2Cspeed50 ' for 50 Kb shift rate
'#define I2CslaveCLKstretch ' trial code to support slave clock stretching (unverified on a slave that stretches clocks)
#include "coridium_pcb.bas"
#include <I2C.bas>
DIM shortMessage(20) as STRING
DIM shortResponse(20) as STRING
dim chip
' test the EEPROM 24LC02 on pins 0 == SDA and 1 == SCL
'54102 uses
'CONST SDApin = 24 'io pin on the 54102
'CONST SCLpin = 23
#ifdef LPC11U37
IOCON_PIO0_4 = &H0180 '*&H40044010 ' I/O configuration for pin PIO0_4/SCL */
IOCON_PIO0_5 = &H0180
#define I2Cspeed50
#endif
shortMessage(0)= 0 ' address into EEPROM
shortMessage(1)= 11 ' data
shortMessage(2)= 22
shortMessage(3)= 33
shortMessage(5)= 44
shortMessage(6)= 55
shortMessage(7)= 66
wait(12)
print
'****************************
'present = I2COUT (24, 23, 0x24, -1, shortMessage)
'if present = 0 then print "NO i2c device ***"
'stop
'******************************
'/* Function that probes all available slaves connected to an I2C bus */
_i2c_probe_slaves:
DIM i, Dev_addr, present, temp
shortMessage(0)=&H00 'not sure what a probe takes or address query
'I2CM_XFER_T probe
'memset(&probe, 0, sizeof(I2CM_XFER_T))
'probe.rxBuff = rx_buff
'probe.txBuff = tx_buff
'probe.rxSz = 1
print "Probing available I2C devices..."
print " 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F"
print "===================================================="
'for i = 0 to (i <= 0x7F)'
stop
'if (not (i AND 0x0F)) then print "0";i;" "; '( i >> 4);
print " ";
for i = 0 to 7 'then '((i <= 7) or (i > 0x78)) then
print " -";
next
for i = 8 to 120
temp = i
Dev_addr = temp << 1 'shifts the addy one bit
shortMessage(0)=&H00
' present = I2COUT (24, 23, Dev_addr, -1, shortMessage) 'Coridium routine
' present = I2COUT (10, 11, Dev_addr, -1, shortMessage) 'Coridium routine'pinned for 1768-sda2
present = I2COUT(5, 4, Dev_addr, -1, shortMessage) 'STAMP/11U37
if present = 0 then print " .."; else print " "; HEX(i); 'i2c_error(true, probe.status)
if i mod 15 = 0 then
print
print " ";
endif
'i += 1
wait(100) 'was 10
next
'
for i = 121 to 128 '&H78
print " --";
next
print
stop
' got 10 12 4a 76 for addy of devices
-
- Posts: 35
- Joined: Tue Mar 22, 2022 11:17 pm
Re: Simple example of I2c code " My World" request
basicchip
display was order as I2C. Did a visual inspection and the jumpers are set for I2C
I used 4.7k between SCL and +5 and SDA and +5
present returns 0 from all calls
I also tested continuity between the pins and the display for the I2C lines and they are good
olzeke51
I will try to modify your code and run it to see what happens
Thank you
display was order as I2C. Did a visual inspection and the jumpers are set for I2C
I used 4.7k between SCL and +5 and SDA and +5
present returns 0 from all calls
I also tested continuity between the pins and the display for the I2C lines and they are good
olzeke51
I will try to modify your code and run it to see what happens
Thank you
Re: Simple example of I2c code " My World" request
If i2c routines are returning 0, means the target device is NOT acknowledging.
Either miss wired, no pullups, or ...
Either miss wired, no pullups, or ...