Could someone please point out the errors of my ways. After fumbling around on the Dark Side with my Spindle Cooling Controller project and Arduino for a couple of weeks, I gave up and decided at great cost to invest in a PCF8574N i2c to 8 bit decoder and use one of my little 16F18326 SBC (Single Board Computer) which has most of the features I need for the project.
So here I am at the first Hurdle, Failed..... or more to the point fallen.
I am trying to get my i2c bus to talk with a 4x20 LCD Display, I have dug out of the the Demo's some code written by Evan but I cannot get it to work. in the attachments is an image of my i2c Discovery showing the i2c adapter sits at 0x7E which is peculiar as in Arduino speak the same adapter sits on 0x3F.
the other noticeable thing is there is no back-light command ??
As always any help or comments is greatly appreciated.
The code I have is as follows:
'''A demonstration program for GCGB and GCB.'''----------------------------------------------------------------------------------'''----------------------------------------------------------------------------------'''ThisprogramdemonstratesshowsoneLCD (16x2&16x4)beingdrivenusingaLCDI2C'''adapters.'''ThisusestheGCBhardwareimplementationofIC2forMicrochipdevices.'''Two types are supported as shown below. This example is using "#define LCD_IO 10"'''-SetLCD_I0to10fortheYwRobotLCD1602IICV1ortheSainsmartLCD_PICI2Cadapter.'''- Set LCD_I0 to 12 for the Ywmjkdz I2C adapter with pot bent over top of chip.'''-UsethefollowingtoaddressadiferentI2Cdevice.'''- #define LCD_I2C_Address 0x4e This is the default value, change as appropiate'''@authorEvanV'''@licence GPL'''@version1.0a'''@date 21.10.2015'''********************************************************************************#chip 16f18326,32#option explicit'Set the PPS for this solution. #startup InitPPS, 85 #include <lowlevel\hwi2c.h> ; ----- Define Hardware settings 'DefineI2Csettings#define HI2C_BAUD_RATE 100#define hi2c_DATA PORTC.1#define hi2c_CLOCK PORTC.0'I2C pins need to be input for SSP module Dir HI2C_DATA in Dir HI2C_CLOCK in 'MASTERMODEHI2CModeMaster'''Set up LCD #define LCD_IO 10 #define LCD_I2C_Address_1 0x7F '#define LCD_I2C_Address_1 0x7E'You may need to use SLOW or MEDIUM if your LCD is a slower device. #define LCD_SPEED SLOW 'Youmayneedtoinvertthesestates.DependentofLCDI2Cadapter.#define LCD_Backlight_On_State 1#define LCD_Backlight_Off_State 0;-----Constants'None required beyond the scope of the hardware.; ----- Quick Command Reference: '''SetLCD_10to10fortheYwRobotLCD1602IICV1ortheSainsmartLCD_PICI2Cadapter'''Set LCD_10 to 12 for the Ywmjkdz I2C adapter with pot bent over top of chip; ----- Main body of program commences here. InitLCD wait 100 ms CLS PRINT "Great Cow Basic" Locate 1,0 Print "@v.0.95.010" WAIT 3 s Do Forever CLS WAIT 3 s PRINT "START TEST" locate 1,0 PRINT "DISPLAY ON" wait 3 s CLS Locate 0,0 Print "Cursor ON" Locate 1,0 'LCDcursorCursorOnwait3SCLS' LCDcursor CursorOFF locate 0,0 Print "Cursor OFF" wait 3 s CLS Locate 0,0 Print "FLASH ON" Locate 1,0'LCDcursorFLASHONwait3sCLSlocate0,0Print"FLASH OFF"' LCDCURSOR FLASHOFF wait 3 sec Locate 0,0 Print "CURSR & FLSH ON" locate 1,0'LCDCURSORCURSORON' LCDCURSOR FLASHON Wait 3 sec Locate 0,0 Print "CURSR & FLSH OFF" locate 1,0'LCDCURSORCursorOFF' LCDCURSOR FLASHOFF Wait 3 sec CLS Locate 0,4 PRINT "Flashing" Locate 1,4 Print "Display" wait 500 ms repeat 10'LCDCURSORLCDOFFwait500ms' LCDCURSOR LCDON wait 500 ms end repeat CLS Locate 0,0 Print "DISPLAY & BACKL." Locate 1,0 Print "FOR 5 SEC" Wait 2 SEC'LCDCURSORLCDOFF' LCDBacklight OFF WAIT 5 s 'LCDBacklightONCLSLocate0,0' LCDCURSOR LCDON Print "END TEST" wait 3 s loop Sub InitPPS UNLOCKPPS RC1PPS = 0x19 'RC1<-MSSP1:SDA1SSP1CLKPPS=0x10' RC0->MSSP1:SCL1 SSP1DATPPS = 0x11 'RC1->MSSP1:SDA1RC0PPS=0x18' RC0->MSSP1:SCL1LOCKPPSEndsubend
Try changing the address to 0x7E. This is the address I use for these adapters.
Have you adjusted the contrast potentiometer on the PFC 8574 Backpack module? The voltage at the contrast pin on the LCD module ( center tap of pot) should typically be about 1/2 volt.
Last edit: William Roth 2023-01-26
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@William,
Hi again William and thank you for your help. This is really becoming another nemesis to me, The little OLed GLCG works a treat on these board of mine but for the life of me I cannot get a wink let alone a twinkle out of an 4x20 LCD.
Some of the things I found wrong in the code was the i2c baud rate and the i2c port addresses.
on my SBC'c the i2c Clock and Data pins are C0 and C1
I'm still unsure about the PCF8574T IC2/Serial_Expander address. i2c Discovery still reports 0x7E as the address but the same adapter and Display is plugged into the Black Arts Arduino on the Dark Side it it's address is 0x3E
Still nothing on the display and no backlight
When I compile your code I get an error on the line LCDBacklight ON which I have to rem out to get it to compile.
It's really frustrating that I'm falling down flat on my hooter with something as basic as this.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@William,
Hi again William and thank you for your help. This is really becoming another nemesis to me, The little OLed GLCG works a treat on these board of mine but for the life of me I cannot get a wink let alone a twinkle out of an 4x20 LCD.
Some of the things I found wrong in the code was the i2c baud rate and the i2c port addresses.
on my SBC'c the i2c Clock and Data pins are C0 and C1
I'm still unsure about the PCF8574T IC2/Serial_Expander address. i2c Discovery still reports 0x7E as the address but the same adapter and Display is plugged into the Black Arts Arduino on the Dark Side it it's address is 0x3E
Still nothing on the display and no backlight
When I compile your code I get an error on the line LCDBacklight ON which I have to rem out to get it to compile.
It's really frustrating that I'm falling down flat on my hooter with something as basic as this.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The Arduino address is correct for that language. I will explain.
Arduino uses a 7bit address plus a read or write bit. So, to communicate with a Slave I2C device the Arduino compiler does this. 0x3E shifted to the left plus the Read bit (0) or Write Bit (1).
So, this means 0x3E * 2 = 0x7C; add 0 or 1 give an 8 address of 0x7C (read) or 0x7D (write).
However, the addresses shown in the I2C discovery JPG above shows addresses 0x7E/0x7F which means the something is odd.
Please rerun the I2C discovery from the URL I posted, adapted only for I2C ports. I want to see the complete terminal screen.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The chip is likely a PC7584"A" Version. If it works with Arduino at address 0x3E, then it should work with GCB at Address 0x7E.
These are the only possible addresses for this chip:
0X70
0x72
0x74
0x76
0x78
0x7A
0X7C 0X7E
The address is determined by the states of Pins 1,2,&3. I have not seen these at any other address than 0x7E for 8-bit addressing. If Pins 1,2 & 3 are all 5V then the 12c address for GCB is 0x7E.
My guess is there is something wrong other than the I2C Address. We know it's communicating, because the discovery returns 0x7E for the address.
Note: This chip/LCD combo will absolutely not operate at 3.3V so make sure the supply voltage is at least 4.5 V with 5V being preferred.
Also there will be no visible display if the contrast pot on the backpack board is not adjuster correctly. Also check that the clock and data signals are not reversed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have done as you said Evan and compiled the i2c Discovery the Git hub repository with some changes which right or wrong I thought were needed..
' ----- Configuration'ChipSettings.#CHIP16f18326,32#OPTIONExplicit#INCLUDE<lowlevel\hwi2c2.h>'Set the PPS of the PWM and the RS232 ports.'SetthePPSforthissolution.#STARTUPInitPPS,85#DEFINESWITCH_DOWN1#DEFINESWITCH_UP0**''Ihadtoaddthesetwolines**#defineLCD_IO10#defineLCD_I2C_Address_10x7E''''-------------------LATC-----------------''Bit#:-7---6---5---4---3---2---1---0---''LED:---------------|D5|D4|D3|D2|-''-----------------------------------------''**HadtoreconfiguretheportsasC.0andC.1areusedformyi2cbus**#DEFINELEDD2PORTC.2#DEFINELEDD3PORTC.3#DEFINELEDD4PORTC.4#DEFINELEDD5PORTC.5#DEFINELEDBANKportc#DEFINESWITCHPORTA.1DirLEDD2OutDirLEDD3OutDirLEDD4OutDirLEDD5OutDirSWITCHIn#DEFINEUSART_BAUD_RATE19200#DEFINEUSART_TX_BLOCKING' ----- Define Hardware settings for HWI2C2'DefineI2Csettings-CHANGEPORTSifrequiredforyourspecificdevice.#DEFINEHI2C2_BAUD_RATE400#DEFINEHI2C2_DATAPORTC.1#DEFINEHI2C2_CLOCKPORTC.0'Initialise I2C Master'I2CpinsneedtobeinputforSSP2moduleDirHI2C2_DATAInDirHI2C2_CLOCKIn'MASTER Second PortHI2C2Mode Master'-----Mainbodyofprogramcommenceshere.' Now assumes Serial Terminal is operationalDim DeviceID As ByteDim DISPLAYNEWLINE As ByteHSerPrintCRLFHSerPrint "Hardware I2C2 "HSerPrintCRLF 2Do Forever Set LEDD2 Off Set LEDD3 Off Set LEDD4 Off Set LEDD5 Off HSerPrint " " For DeviceID = 0 To 15 HSerPrint Hex(deviceID) HSerPrint " " Next For DeviceID = 0 To 255 DisplayNewLine = DeviceID % 16 If DisplayNewLine = 0 Then HSerPrintCRLF HSerPrint Hex(DeviceID) HSerPrint ": " End If HSerPrint " " HI2C2Start If HI2C2WaitMSSPTimeout <> TRUE Then HI2C2Send ( deviceID ) If HI2C2AckpollState = FALSE Then HSerPrint Hex(deviceID) Else HSerPrint "--" End If HI2C2Send ( 0) End If HI2C2Stop Next HSerPrintCRLF 2 HSerPrint "End of Search - Press button to repeat test" HSerPrintCRLF 2 Set LEDD2 On Set LEDD3 On Set LEDD4 On Set LEDD5 On Wait While switch = SWITCH_UPLoopSub InitPPS UNLOCKPPS 'PinRC5sourceisaninputforRXRXPPS=0x15'Pin RC4 source is TX/CK RC4PPS = 0x14 'RA2->MSSP2:SDA2;RA2PPS=0x001b'RA2->MSSP2:SDA2; SSP2DATPPS = 0x0002 'RA4->MSSP2:SCL2;SSP2CLKPPS=0x0004'RA4->MSSP2:SCL2;RA4PPS=0x001aLOCKPPSEndSubEnd
@Kieth. I took you code, removed the two comments and compiled and got the display below.
For your results where you get NO -- then you may have the DATA line disconnected.
Inspect your circuit. With the power off. Do you have the 2k-5k(ish) on the DATA line pullup to 5v0, and do you have the 2k-5k(ish) on the LOCK line pullup to 5v0 ? These pullsup must be there ( there may be many that say you can use the internal pullsup but you cannot verify the circuit and it prevents reusable code as the internal pulls are specific to a chip).
Once I confirmed the I2c address using your program. I loaded C:\GCstudioDemo\GreatCowBASIC\demos\Vendor_Boards\Great_Cow_Basic_Demo_Board\16f18326_ChipRange_Demonstrations\24_using_ic2_lcd_1602_display.gcb with no changes and it worked.
This is really, really getting to me now. I have replaced the PCF8574T Serial adapter, Display and even put another 16F18326 onto a breadboard wired it up including the 4k7 Pull-ups on the i2c Clock and data lines and still with your Keithi2c.hex file, Now't, Nada Nix, in other words Nothing.
To add insult to my battered confidence, I hooked the little SSD1306 GLCD display up and loaded my Clock and Temperature code onto both the breadboard 16F18326 and my little 16F18326 SBC and it sprang into life on both occasions.
To make matters worse, I crossed onto the dark side and booted an Arduino Uno with the 4x20 LCD and 2x20 LCD and within a couple of minutes both were nattering away happily with both displays.
This has gone on for nearly three days now trying to get this project of the ground, my patience is running a bit thin. I don't want to go down the Arduino route, I keep getting stuck with those curly braces among other things.
As a final resort, could you let me see the code you created for the Keithi2c.hex to see if I can cross reference it with what I have.
After that it is time for some serious Recreational Chemistry.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Could someone please point out the errors of my ways. After fumbling around on the Dark Side with my Spindle Cooling Controller project and Arduino for a couple of weeks, I gave up and decided at great cost to invest in a PCF8574N i2c to 8 bit decoder and use one of my little 16F18326 SBC (Single Board Computer) which has most of the features I need for the project.
So here I am at the first Hurdle, Failed..... or more to the point fallen.
I am trying to get my i2c bus to talk with a 4x20 LCD Display, I have dug out of the the Demo's some code written by Evan but I cannot get it to work. in the attachments is an image of my i2c Discovery showing the i2c adapter sits at 0x7E which is peculiar as in Arduino speak the same adapter sits on 0x3F.
the other noticeable thing is there is no back-light command ??
As always any help or comments is greatly appreciated.
The code I have is as follows:
Hi Keith
Try this simplified code.
Do you get a display?
Does the backlight come on?
Last edit: William Roth 2023-01-26
Try changing the address to 0x7E. This is the address I use for these adapters.
Have you adjusted the contrast potentiometer on the PFC 8574 Backpack module? The voltage at the contrast pin on the LCD module ( center tap of pot) should typically be about 1/2 volt.
Last edit: William Roth 2023-01-26
The address is 0x7E. The I2C discovery shows the two address the write and read addresses.
Also, see https://github.com/GreatCowBASIC/Demonstration_Sources/tree/main/Vendor_Boards/Great_Cow_Basic_Demo_Board/16f18326_ChipRange_Demonstrations
@William,
Hi again William and thank you for your help. This is really becoming another nemesis to me, The little OLed GLCG works a treat on these board of mine but for the life of me I cannot get a wink let alone a twinkle out of an 4x20 LCD.
Some of the things I found wrong in the code was the i2c baud rate and the i2c port addresses.
on my SBC'c the i2c Clock and Data pins are C0 and C1
I'm still unsure about the PCF8574T IC2/Serial_Expander address. i2c Discovery still reports 0x7E as the address but the same adapter and Display is plugged into the Black Arts Arduino on the Dark Side it it's address is 0x3E
Still nothing on the display and no backlight
When I compile your code I get an error on the line LCDBacklight ON which I have to rem out to get it to compile.
It's really frustrating that I'm falling down flat on my hooter with something as basic as this.
@William,
Hi again William and thank you for your help. This is really becoming another nemesis to me, The little OLed GLCG works a treat on these board of mine but for the life of me I cannot get a wink let alone a twinkle out of an 4x20 LCD.
Some of the things I found wrong in the code was the i2c baud rate and the i2c port addresses.
on my SBC'c the i2c Clock and Data pins are C0 and C1
I'm still unsure about the PCF8574T IC2/Serial_Expander address. i2c Discovery still reports 0x7E as the address but the same adapter and Display is plugged into the Black Arts Arduino on the Dark Side it it's address is 0x3E
Still nothing on the display and no backlight
When I compile your code I get an error on the line LCDBacklight ON which I have to rem out to get it to compile.
It's really frustrating that I'm falling down flat on my hooter with something as basic as this.
The Arduino address is correct for that language. I will explain.
Arduino uses a 7bit address plus a read or write bit. So, to communicate with a Slave I2C device the Arduino compiler does this. 0x3E shifted to the left plus the Read bit (0) or Write Bit (1).
So, this means 0x3E * 2 = 0x7C; add 0 or 1 give an 8 address of 0x7C (read) or 0x7D (write).
However, the addresses shown in the I2C discovery JPG above shows addresses 0x7E/0x7F which means the something is odd.
Please rerun the I2C discovery from the URL I posted, adapted only for I2C ports. I want to see the complete terminal screen.
I see nothing odd ...
The chip is likely a PC7584"A" Version. If it works with Arduino at address 0x3E, then it should work with GCB at Address 0x7E.
These are the only possible addresses for this chip:
0X70
0x72
0x74
0x76
0x78
0x7A
0X7C
0X7E
The address is determined by the states of Pins 1,2,&3. I have not seen these at any other address than 0x7E for 8-bit addressing. If Pins 1,2 & 3 are all 5V then the 12c address for GCB is 0x7E.
My guess is there is something wrong other than the I2C Address. We know it's communicating, because the discovery returns 0x7E for the address.
Note: This chip/LCD combo will absolutely not operate at 3.3V so make sure the supply voltage is at least 4.5 V with 5V being preferred.
Also there will be no visible display if the contrast pot on the backpack board is not adjuster correctly. Also check that the clock and data signals are not reversed.
I have done as you said Evan and compiled the i2c Discovery the Git hub repository with some changes which right or wrong I thought were needed..
These is the results from my terminal
Hardware I2C2
00:
10:
20:
30:
40:
50:
60:
70:
80:
90:
A0:
B0:
C0:
D0:
E0:
F0:
End of Search - Press button to repeat test
00:
10:
20:
30:
40:
50:
60:
70:
80:
90:
A0: A9
I will try this code for you. This needs to verified.
@Kieth. I took you code, removed the two comments and compiled and got the display below.
For your results where you get NO
--
then you may have the DATA line disconnected.Inspect your circuit. With the power off. Do you have the 2k-5k(ish) on the DATA line pullup to 5v0, and do you have the 2k-5k(ish) on the LOCK line pullup to 5v0 ? These pullsup must be there ( there may be many that say you can use the internal pullsup but you cannot verify the circuit and it prevents reusable code as the internal pulls are specific to a chip).
Once I confirmed the I2c address using your program. I loaded C:\GCstudioDemo\GreatCowBASIC\demos\Vendor_Boards\Great_Cow_Basic_Demo_Board\16f18326_ChipRange_Demonstrations\24_using_ic2_lcd_1602_display.gcb with no changes and it worked.
My chip on the LCD is a 8574T.
Last edit: Anobium 2023-01-28
@Kieth. I did notice.
Your I2C discover is using the second I2C channel and the LCD demo I used was the first I2C channel.
This is all good. I am just pointing it out. Using second I2C channel for i2C discovery needs to work regardless.
@Kieth. My hex, from your code, this will rule out your compiler and toolchain. It works here.
This is really, really getting to me now. I have replaced the PCF8574T Serial adapter, Display and even put another 16F18326 onto a breadboard wired it up including the 4k7 Pull-ups on the i2c Clock and data lines and still with your Keithi2c.hex file, Now't, Nada Nix, in other words Nothing.
To add insult to my battered confidence, I hooked the little SSD1306 GLCD display up and loaded my Clock and Temperature code onto both the breadboard 16F18326 and my little 16F18326 SBC and it sprang into life on both occasions.
To make matters worse, I crossed onto the dark side and booted an Arduino Uno with the 4x20 LCD and 2x20 LCD and within a couple of minutes both were nattering away happily with both displays.
This has gone on for nearly three days now trying to get this project of the ground, my patience is running a bit thin. I don't want to go down the Arduino route, I keep getting stuck with those curly braces among other things.
As a final resort, could you let me see the code you created for the Keithi2c.hex to see if I can cross reference it with what I have.
After that it is time for some serious Recreational Chemistry.
I hope the Chemistry helped.
What results did you get with
Keithi2c.hex
? No serial ? Nothing or something ?The code I used fro
Keithi2c.hex
was the code you post yesterday. I removed the two comments and compiled. See attached.The Arduino is an option.
Do have any test equipment ? like an scope or protocol analyser.?
Last edit: Anobium 2023-01-29