Need help making Click and GLCD work together

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
egruff
Posts: 7
Joined: 04 Sep 2015 21:06

Need help making Click and GLCD work together

#1 Post by egruff » 25 Jun 2020 05:34

I've written a program to read from a Weather 3 Click in MikroBus Socket 3 and output data to a GLCD plugged into my new EasyPIC v8 board with a P18F45K22 MCU. I had it working on an EasyPIC v7 Pro system, but now, as soon as I go to send a command to the Weather Click, the GLCD doesn't work.

In the abbreviated code below (just to initialize everything and test the GLCD), I have commented out the calls in applicationInit() and the test text appears on the GLCD. If I uncomment any one of the weather_ routines to set parameters, the GLCD is blank.

I'm sure it has something to do with an MCU pin (or pins) being asked to do double duty, but from everything I've read, the Click board pins are different from the GLCD pins. Can someone show me my error?

Code: Select all

' *
' * Project name:
'     GLCD_Test (Demonstration of the GLCD library routines)
' * Copyright:
'     (c) Mikroelektronika, 2019.
' * Revision History:
'     - Initial release
' * Description:
'     This is a simple demonstration of the GLCD library routines:
'     - Init and Clear (pattern fill)
'     - Image display
'     - Basic geometry - lines, circles, boxes and rectangles
'     - Text display and handling
' * Test configuration:
'     MCU:             PIC18F47K42
'                      http://ww1.microchip.com/downloads/en/DeviceDoc/PIC18LF26-27-45-46-47-55-56-57K42-Data-Sheet-40001919E.pdf
'     dev.board:       easypic v8lcd
'                      https://www.mikroe.com/easypic-v8
'     Oscillator:      HS-PLL 32.0000 MHz, 8.0000 MHz Crystal
'     Ext. Modules:    GLCD 128x64, KS108/107 controller
'                      https://www.mikroe.com/glcd-128x64?search_query=GLCD+128x64&results=10
'     SW:              mikroBasic PRO for PIC
'                      http://www.mikroe.com/mikrobasic/pic/
' * Notes:
'      - Turn on GLCD backlight switch and PWM switch SW6.1 and SW6.2 (board specific)
'      - Make sure that CAN switch is toggled to up position (GPIO position) RB3/RB2 (board specific)
' *

program Glcd_Test

' Declarations section
include Click_Weather_types
include Click_Weather_config

dim
    temperature as float
    humidity as float
    pressure as float
    logText as char[50]
    degCel as char[4]

' Glcd module connections
dim GLCD_DataPort as byte at PORTD

dim GLCD_CS1 as sbit at LATB5_bit
    GLCD_CS2 as sbit at LATB4_bit
    GLCD_RS  as sbit at LATB2_bit
    GLCD_RW  as sbit at LATB3_bit
    GLCD_EN  as sbit at LATC1_bit
    GLCD_RST as sbit at LATA3_bit

dim GLCD_CS1_Direction as sbit at TRISB5_bit
    GLCD_CS2_Direction as sbit at TRISB4_bit
    GLCD_RS_Direction  as sbit at TRISB2_bit
    GLCD_RW_Direction  as sbit at TRISB3_bit
    GLCD_EN_Direction  as sbit at TRISC1_bit
    GLCD_RST_Direction as sbit at TRISA3_bit
' End of Glcd module connections

dim counter as byte
    someText as char[18]

sub procedure systemInit()

    mikrobus_gpioInit(_MIKROBUS1, _MIKROBUS_CS_PIN, _GPIO_OUTPUT)
    mikrobus_i2cInit(_MIKROBUS1, @_WEATHER_I2C_CFG[0])
 end sub
 
sub procedure Delay2S()                          ' 2 seconds delay sub function
  Delay_ms(2000)
end sub

sub procedure applicationInit()
    dim STAT as uint8_t
    
    weather_i2cDriverInit(T_WEATHER_P(@_MIKROBUS1_GPIO), T_WEATHER_P(@_MIKROBUS1_I2C), STAT)
    Delay_ms(100)
    'weather_setStandbyTime(_WEATHER_STANDBY_TIME_1_MS)
    'weather_setFilterCoefficient(_WEATHER_FILTER_COEFF_16)
    'weather_setOversamplingTemperature(_WEATHER_OVERSAMP_2X)
    'weather_setOversamplingHumidity(_WEATHER_OVERSAMP_1X)
    'weather_setOversamplingPressure(_WEATHER_OVERSAMP_16X)
    'weather_setOversamplingMode(_WEATHER_NORMAL_MODE)

    Delay_ms(100)
    degCel[0] = 32
    degCel[1] = 176
    degCel[2] = 67
    degCel[3] = 0

end sub

main:
  ANSELB = 0                                          ' Configure PORTB pins as digital
  ANSELC = 0
  ANSELD = 0                                          ' Configure PORTD pins as digital
  
  systemInit()
  applicationInit()
  
  Glcd_Init()                                         ' Initialize Glcd
  Glcd_Fill(0x00)                                     ' Clear Glcd

  while TRUE

    
    Glcd_Fill(0x00)                                   ' Fill GLCD

    Glcd_Set_Font(@font5x7, 5, 7, 32)            ' Change font
    Glcd_Write_Text("TEXT DEMO", 0, 0, 2)            ' Write string
    Delay2S()
    'Glcd_Fill(0x00)                                   ' Clear Glcd

    'Glcd_Set_Font(@Character8x7, 8, 7, 32)            ' Change font
    someText = "8x7 Font"
    Glcd_Write_Text(someText, 0, 2, 2)                ' Write string
    Delay_ms(200)

    'Glcd_Set_Font(@System3x5, 3, 5, 32)               ' Change font
    someText = "3X5 CAPITALS ONLY"
    Glcd_Write_Text(someText, 0, 4, 2)               ' Write string
    Delay_ms(200)

    'Glcd_Set_Font(@font5x7, 5, 7, 32)                 ' Change font
    someText = "5x7 Font"
    Glcd_Write_Text(someText, 0, 6, 2)                ' Write string
    Delay_ms(200)

    'Glcd_Set_Font(@FontSystem5x7_v2, 5, 7, 32)        ' Change font
    someText = "5x7 Font (v2)"
    Glcd_Write_Text(someText, 0, 8, 2)               ' Write string
    Delay_ms(2000)

  wend
end.

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: Need help making Click and GLCD work together

#2 Post by jovana.medakovic » 25 Jun 2020 14:19

Hello,

MikroBUS3 slot uses RD0 and RD1 pins for I2C and also these pins are used for GLCD, because of that, your code doesn't work.
You cannot use mikroBUS3 and mikroBUS4 slots if you want to use GLCD to see the result.

Kind regards,
Jovana

egruff
Posts: 7
Joined: 04 Sep 2015 21:06

Re: Need help making Click and GLCD work together

#3 Post by egruff » 25 Jun 2020 15:14

Jovana,

Thanks for the explanation, but I'm confused. The Weather Click is in MikroBUS Slot 1 and the code also calls Slot 1. I am not using Slot 3 at all, so why does the code still not work?

I have checked and any call to the Weather library kills the GLCD, so presumably something is triggering MikroBUS Slot 3, but what? The libraries seem to only call it if explictly coded.

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: Need help making Click and GLCD work together

#4 Post by jovana.medakovic » 26 Jun 2020 11:04

Hi,

In the attachment, you can find hex file. Place Weather click on mikroBUS 1 slot and check if jumpers on your click board are placed on the right position for I2C and jumper for ADDR need to be placed on the left position (see the picture in the attachment).
Load the hex file and let me know do you get the data of temperature, humidity and pressure on the GLCD. Don't forget to turn on switch SW6.1 for BCKL on your EasyPIC v8 board.

Kind regards,
Jovana
Attachments
Click_Weather_PIC.zip
(17.98 KiB) Downloaded 56 times
IMG_20200626_115700.jpg
IMG_20200626_115700.jpg (231.55 KiB) Viewed 1347 times

egruff
Posts: 7
Joined: 04 Sep 2015 21:06

Re: Need help making Click and GLCD work together

#5 Post by egruff » 26 Jun 2020 16:06

Unfortunately that didn't work. All of the jumpers are identical to the picture you posted.

I am able to make my simple weather program work by logging to the UART interface, but for some reason, the GLCD isn't working properly once I access the ClickBUS Slot 1 via the Weather library.

Weather Click
-----------------------------

Temperature : 89.99 °F
Humidity : 43.64%
Pressure : 28.97 in Hg
-----------------------------
Temperature : 89.88 °F
Humidity : 43.68%
Pressure : 28.96 in Hg
-----------------------------
Temperature : 89.88 °F
Humidity : 43.65%
Pressure : 28.96 in Hg
-----------------------------
Temperature : 89.86 °F
Humidity : 43.66%
Pressure : 28.96 in Hg
-----------------------------
Temperature : 89.90 °F
Humidity : 43.64%
Pressure : 28.96 in Hg
-----------------------------

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: Need help making Click and GLCD work together

#6 Post by jovana.medakovic » 29 Jun 2020 13:50

Hello,

What exactly happens when you load my hex file which I sent you in the last post? Did you see any text on the GLCD?
Can you send me a picture of your board, where I can see how you set it?

Kind regards,
Jovana

Post Reply

Return to “mikroBasic PRO for PIC General”