News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Voltmeter with an OLED indicator

Started by tolyan249, Today at 10:22 AM

Previous topic - Next topic

tolyan249

I'm making a voltmeter using an OLED display, displaying 3 digits without a decimal point across the entire display, but something isn't working. I'm posting the project.

trastikata

Quote from: tolyan249 on Today at 10:22 AMbut something isn't working. I'm posting the project.

Hi tolyan249,

it would be good if you can be more specific what exactly is not working.  :)

RGV250

Hi,
You need to give more information on here as to what you think should happen or what is not happening if you expect a reply. Just saying "something isn't working" does not help.
I notice there is a CSV file for EcoEye, if it is the same EcoEye that I use it is current output, not voltage?

Trastikata beat me to it

Regards,
Bob

tolyan249

#3
The indicator doesn't display any numbers, even if you simply substitute numbers into the variable, without performing any measurement — just output 3 numbers. 

   Digit[0] =  2    ' Hundreds
    Digit[1] = 3    ' Tens
    Digit[2] = 4    ' Ones

trastikata

Hello tolyan249,

I can't open the design file, but what pins did you use for the hardware I2C? Did you connect the pull-up resistors? Looked at your code and I think there's a lot missing?

I have had some projects with the SSD1306 I2C displays and all worked fine, but they need much more coding than what I see in your program listing. Here are some basic functions I've taken from my program, so you have an idea what to do.

Symbol SSD1306 = $3C << 1
Symbol ControlByteCMD  = %10000000         ;Co bit set = Command follows
Symbol ControlByteData = %01000000         ;D/C# bit set = GDRAM byte follows

GoSub INITIALIZE_LCD
GoSub LCD_ON
GoSub LCD_NORMAL
GoSub LCD_CLEAR_START
DelayMS 1000
GoSub LCD_CLEAR

INITIALIZE_LCD:
    DelayMS 500
    HBStart
        HBusOut SSD1306
    HBStop
    DelayMS 10
    HBStart                     ;Send a Start condition to the I2C bus
        HBusOut SSD1306         ;Slave Adress
   
        HBusOut ControlByteCMD  ;
        HBusOut $AE             ;turn off oled panel
       
        HBusOut ControlByteCMD  ;
        HBusOut $D5             ;set display clock divide ratio/oscillator frequency
        HBusOut ControlByteCMD  ;
        HBusOut $F0             ;set divide ratio  default=$80 / F0
       
        HBusOut ControlByteCMD  ;
        HBusOut $A8             ;set multiplex ratio 1 to 64
        HBusOut ControlByteCMD  ;
        HBusOut $3F             ;1/64 duty
       
        HBusOut ControlByteCMD  ;
        HBusOut $D3             ;set display offset
        HBusOut ControlByteCMD  ;
        HBusOut $00             ;not offset
       
        HBusOut ControlByteCMD  ;
        HBusOut $8d             ;set Charge Pump enable/disable
        HBusOut ControlByteCMD  ;
        HBusOut $14             ;set $10=disable 14=enable ???Why
       
        HBusOut ControlByteCMD  ;
        HBusOut $40             ;set start line address
        HBusOut ControlByteCMD  ;
        HBusOut $A6             ;set normal display
       
        HBusOut ControlByteCMD  ;
        HBusOut $A4             ;Disable Entire Display On (=RAM to Dispaly)
       
        HBusOut ControlByteCMD  ;
        HBusOut $A1             ;set segment re-map 127 to 0 =Reversed (Normal=$A0)
       
        HBusOut ControlByteCMD  ;
        HBusOut $C8             ;Set COM Output Scan Direction 63 to 0 =Reversed (Normal=$C0)
       
        HBusOut ControlByteCMD  ;
        HBusOut $DA             ;set com pins hardware configuration
       
        HBusOut ControlByteCMD  ;
        HBusOut $12             ;Disable COM remapping & Alternative COM pins
       
        HBusOut ControlByteCMD  ;
        HBusOut $81             ;set contrast control register
        HBusOut ControlByteCMD  ;
        HBusOut $FF             ;Default $8F $FF=Maximum $00=Minimum
       
        HBusOut ControlByteCMD  ;
        HBusOut $D9             ;set pre-charge period
        HBusOut ControlByteCMD  ;
        HBusOut $F1             ;Default $22 ?????
       
        HBusOut ControlByteCMD  ;
        HBusOut $DB             ;set vcomh
        HBusOut ControlByteCMD  ;
        HBusOut $40             ;Value WRONG Only Possible $00, $10, $20, $30
       
        HBusOut ControlByteCMD  ;
        HBusOut $AF             ;turn on oled panel
    HBStop
Return


LCD_ON:
    HBStart
        HBusOut SSD1306, [ControlByteCMD, $AF]
    HBStop
Return

LCD_OFF:
    HBStart
        HBusOut SSD1306, [ControlByteCMD, $AE]
    HBStop
Return

LCD_NORMAL:
    HBStart
        HBusOut SSD1306, [ControlByteCMD, $A6]
    HBStop
Return

LCD_HORIZONTAL_ADDRESSING:
    HBStart
        HBusOut SSD1306         ;Slave address
        HBusOut ControlByteCMD  ;
        HBusOut $20             ;Set Memory Addressing Mode
        HBusOut ControlByteCMD  ;
        HBusOut $00            ;Horizontal Adressing ($01=Vertical $20=Paged)
    HBStop     
Return

LCD_VERTICAL_ADDRESSING:
    HBStart
        HBusOut SSD1306         ;Slave address
        HBusOut ControlByteCMD  ;
        HBusOut $20             ;Set Memory Addressing Mode
        HBusOut ControlByteCMD  ;
        HBusOut $01            ;Horizontal Adressing ($01=Vertical $20=Paged)
    HBStop     
Return

LCD_START_POSITION:
    HBStart
        HBusOut SSD1306         ;Slave address
       
        HBusOut ControlByteCMD  ;
        HBusOut $20             ;Set Memory Addressing Mode
        HBusOut ControlByteCMD  ;
        HBusOut $00            ;Horizontal Adressing ($01=Vertical $20=Paged)
       
        HBusOut ControlByteCMD  ;
        HBusOut $21             ;Set Colomn Address
        HBusOut ControlByteCMD  ;
        HBusOut $00             ;Start Colomn
        HBusOut ControlByteCMD  ;
        HBusOut 127             ;End Colomn
       
        HBusOut ControlByteCMD  ;
        HBusOut $22             ;Set Page Address
        HBusOut ControlByteCMD  ;
        HBusOut $00             ;Start Page
        HBusOut ControlByteCMD  ;
        HBusOut 7               ;End Page
    HBStop   
Return

LCD_CLEAR_START:
    GoSub LCD_START_POSITION
    HBStart
        HBusOut SSD1306
        HBusOut ControlByteData
        For c = 0 To 127   
            For d = 0 To 7
                HBusOut 255
            Next   
        Next
    HBStop
   
    DelayMS 1500
   
    GoSub LCD_START_POSITION
    HBStart
        HBusOut SSD1306
        HBusOut ControlByteData
        For c = 0 To 127   
            For d = 0 To 7
                HBusOut 0
            Next   
        Next
    HBStop
   
    HBStart
        HBusOut SSD1306         ;Slave address
        HBusOut ControlByteCMD  ;
        HBusOut $20             ;Set Memory Addressing Mode
        HBusOut ControlByteCMD  ;
        HBusOut $20            ;Paged Adressing ($01=Vertical $20=Paged)
    HBStop
Return

LCD_CLEAR:
    GoSub LCD_START_POSITION
    HBStart
        HBusOut SSD1306
        HBusOut ControlByteData
        For c = 0 To 127   
            For d = 0 To 7
                HBusOut 0
            Next   
        Next
    HBStop
   
    HBStart
        HBusOut SSD1306         ;Slave address
        HBusOut ControlByteCMD  ;
        HBusOut $20             ;Set Memory Addressing Mode
        HBusOut ControlByteCMD  ;
        HBusOut $20            ;Paged Adressing ($01=Vertical $20=Paged)
    HBStop
Return

Print_GLCD:
    HBStart
        HBusOut SSD1306         ;Slave address
        HBusOut ControlByteCMD  ;
        HBusOut $21             ;Set Colomn Address
        HBusOut ControlByteCMD  ;
        temp1 = (pos * 8)
        HBusOut temp1           ;Start Colomn
        HBusOut ControlByteCMD  ;
        HBusOut 127             ;End Colomn
        HBusOut ControlByteCMD  ;
        HBusOut $22             ;Set Page Address
        HBusOut ControlByteCMD  ;
        temp1 = row
        HBusOut temp1           ;Start Page
        HBusOut ControlByteCMD  ;
        HBusOut temp1           ;End Page
    HBStop 
   
    'Send pixel data
    HBStart
        HBusOut SSD1306
        HBusOut ControlByteData
        For c = 0 To 7
            HBusOut page1_array[c]
        Next
    HBStop
    Clear page1_array
Return