OLED display and DS18B20

rq3

Senior Member
Having a few spare temp sensors from my fridge project, I soldered one onto the C.0 input of my AXE133Y OLED display. I have code (thanks Marks!) that happily outputs degrees F to the editor serial terminal, but can't wrap my head around getting it to display on the OLED. Any help appreciated!
 

westaust55

Moderator
Do you have a 4k7 ohm resistor between the data line (c.0) and the 5 V supply rail?

Maybe post your section of code where you are adding the ds18B20 code to the AXE133 code.
 

rq3

Senior Member
Yup, pull-up is in place. As I said, I can successfully read the DS18B20 using the download cable and the editor's serial terminal.

Code so far is a mash-up of stripped AXE133 firmware and Marks DS18B20 code. When I run this, it displays the temp in the serial terminal, and steps through characters on the OLED display. I just can't figure out how to get the temp data from the "Temp" routine onto the OLED via C.5 (the serial input of the AXE133).

Code:
#picaxe 18M2
#no_data

symbol baud = N4800                                    ; Serial baud rate 4800,N,8,1
symbol RX        = C.5                                    ; serial receive pin
symbol enable     = C.6                                    ; LCD enable
symbol rs         = C.7                                    ; LCD RS 

oled_init:                                                ; power on OLED initialisation sub routine
    let dirsC = %11000000                            ; PortC 6,7 outputs
    let dirsB = %11111111                            ; PortB all outputs
        pause 500                                         ; Power stabilistation = 500ms
    let pinsB = %00111001                             ; 8 bit, 2 line, 5x8 , Western_European table1
        pulsout enable,1       
    let pinsB = %00001100                            ; Display on, no cursor, no blink
        pulsout enable,1     
    let pinsB = %00000001                             ; Display Clear
        pulsout enable,1
            pause 7                                        ; Allow 6.2ms to clear display
    let pinsB = %00000010                             ; Return Home
        pulsout enable,1
    let pinsB = %00000110                             ; Entry Mode, ID=1, SH=0
        pulsout enable,1
            high rs                                        ; Leave in character mode
                
main:                                                        ; main program loop, runs at 16MHz
for b1=1 to 232
    let pinsB = b1                                        ; output the data
        pulsout enable,1                              ; pulse the enable pin to send data.
            gosub temp
                next b1
goto main                                                ; quickly loop back to top

Temp:                 
Readtemp12 C.0,w1                                ;read in result ds18b20
    let b9 =43                                       ;Display + (43) space (32)
        w1 = w1+880 * 9 / 8 -670                      ;info     + ie w1=2570 Display +257.0 C
   if w1 > 64865 then                             ;info     -  67 degrees = 64866
     w1 = -w1                                    ;info  if - ie w1=670  Display -67.0 C
         let b9 =45                                   ;Display - (45)
    endif
BINTOASCII w1,b8,b7,b6,b5,b4
    if b7 = "0" then 
        B7 = " "                                         ;zero blanking b7
    if b6 = "0" then 
        B6 = " "                                         ;zero blanking b6
    endif
    endif
sertxd (b9,b7,b6,b5,".",b4," F",13,10)            ;resolution to 0.1
return
 

eggdweather

Senior Member
Having a few spare temp sensors from my fridge project, I soldered one onto the C.0 input of my AXE133Y OLED display. I have code (thanks Marks!) that happily outputs degrees F to the editor serial terminal, but can't wrap my head around getting it to display on the OLED. Any help appreciated!
I see what you mean, not that straightforward. So something like convert the code in main after 'serin RX,baud,b1' to a subroutine so that you can load the address b1 with values to be displayed together with screen format commands then call the display subroutine with your 18b20 data. In sequence terms:
1. Send to screen command for cursor at top left so:
Main:
b1=254
gosub display
b1=192
gosub display
2. Gosub get temperature - the result needs to be a sequence of bytes so if temperature is 98.4F save 9 in some address let's say b10 and save 8 in b11 and 4 in b12, then
b1=b10
gosub display
b1=b11
gosub display
b1="."
gosub display
b1=b12
gosub display
b1=deg-symbol
gosub display
goto main
 

westaust55

Moderator
Since you already have the temp data in byte variables B9 to B4
You need to put those one at a time to the pinsB outputs then use PULSOUT on the enable pin.
Last would be pinsB = "F" followed by the PULSOUT command.

Pretty much as eggdweather has indicated above.
Sorry but using iPhone at this time so not going to try and write many lines of "drop in" code.
 

marks

Senior Member
Hi rq3,
here's an example you can try
Code:
#picaxe 18m2    'version 2.D AXE132 8Bit marks   							
'     DB7            = B.7	
'     DB6            = B.6	
'     DB5            = B.5	
'     DB4            = B.4	
'     DB3            = B.3	
'     DB2            = B.2	
'     DB1            = B.1		
'     DB0            = B.0
      SYMBOL Rx      = C.5
     	SYMBOL E       = C.6			                  
      SYMBOL RS      = C.7
	SYMBOL DS18B20 = C.0				                  
 SYMBOL senddata     = pinsb
 SYMBOL index        = b0		   
 SYMBOL Temperature  = W1  SYMBOL TempMsb   = b3  SYMBOL TempLsb  = b2
 SYMBOL T            = W2  
 SYMBOL Sign         = b9
 SYMBOL D0           = b10
 SYMBOL D1           = b11 
 SYMBOL D2           = b12 
 SYMBOL D3           = b13 
 SYMBOL D4           = b14

SETFREQ M32
 	dirsB = %11111111			
 	dirsC = %11001111
Initialise: 	
	FOR  index = 0 to 6                                               
          LOOKUP index, ($38,$38,$38,$0C,$01,$02,$06),senddata : PULSOUT E,1 ' Initialise LCD/OLED
          '(8bit/2line/5x8)*3(Display On/flashing Cursor)(Clear Display)(Return Home)(Entry Mode Set)	
 	NEXT index : PAUSE 10
Main:            

  ConvertTemperature:
  ReadTEMP12 DS18B20,T
       Temperature = T                                        
       Sign = " "                                                    ' Display +   
     IF TempMsb > 127 THEN                       
       Sign = "-"                                                    ' Display - 
       Temperature = - Temperature                                    
     ENDIF 
            Temperature = Temperature *8**51200+5                    ' Celsius(-55.0°C to 125.0°C)rounded up
                  BinTOASCII Temperature,D4,D3,D2,D1,D0 
                  IF  D4 = "0" THEN : D4 = " "                       ' leading zero blanking 
                   IF D3 = "0" THEN : D3 = " " : ENDIF               ' leading zero blanking 
                  ENDIF 
    DisplayTemperature:
           LOW  RS : senddata = 128 : PULSOUT E,1                    ' commandmode (128-147) Line 1 Cursor Position
           HIGH RS                                                   ' charactermode
           FOR  index = 0 TO 7
 	          LOOKUP index,(Sign,D4,D3,D2,".",D1,223,"C"),senddata 
 	                       PULSOUT E,1                             ' sending characters  
           NEXT index 
            
    ConvertTemperatureF:
        Temperature = T                                    
       Sign = " "                                                    ' Display +
       Temperature = Temperature +880 *16**46080 -6700               ' Fahrenheit(-67.0°F to 257.0°F)rounded up   
     IF TempMsb > 127 THEN                       
       Sign = "-"                                                    ' Display - 
       Temperature = - Temperature                                    
     ENDIF    
       Temperature =   Temperature +5                                                   
                  BinTOASCII Temperature,D4,D3,D2,D1,D0 
                  IF  D4 = "0" THEN : D4 = " "                       ' leading zero blanking 
                   IF D3 = "0" THEN : D3 = " " : ENDIF               ' leading zero blanking 
                  ENDIF 
    DisplayTemperatureF:
           HIGH RS                                                   ' charactermode
           FOR  index = 0 TO 7
 	          LOOKUP index,(Sign,D4,D3,D2,".",D1,223,"F"),senddata 
 	                       PULSOUT E,1                             ' sending characters  
           NEXT index                                                                                 
GOTO main
 

rq3

Senior Member
Marks, that was no fun at all ;). Works perfectly, and should definitely be in the snippets or finished projects category!

Many Thanks,
Rip
 

rq3

Senior Member
marks, one quick question. In both the celsius and fahrenheit "convert temp" routines, there is a +5 offset just before bintoascii. Is that a correction for the individual DS18B20?

PS: I made a trivial modification to your code so that the display width "autoscales" for missing leading zeros. Tested with a lighter and a can of freon. Many thanks again!!!
 

marks

Senior Member
Hi again rq3,
The +5 is for rounding up a bit of a gimmick really...
D0 actually represents the second decimal but we don't show it.
example 32.16F to round up we add 5 which is 32.2F which is what's displayed.

it was an example to get started actually a quick cut n paste from another post
we should cover all possibilities we think of for the fussy and keen lol.
here's a slight improvement for the formatting you can try
like yourself I always look at trying to improve... cheers
Code:
#picaxe 18m2    'version 2.D AXE132 8Bit marks   							
'     DB7            = B.7	
'     DB6            = B.6	
'     DB5            = B.5	
'     DB4            = B.4	
'     DB3            = B.3	
'     DB2            = B.2	
'     DB1            = B.1		
'     DB0            = B.0
      SYMBOL Rx      = C.5
     	SYMBOL E       = C.6			                  
      SYMBOL RS      = C.7
	SYMBOL DS18B20 = C.0				                  
 SYMBOL senddata     = pinsb
 SYMBOL index        = b0		   
 SYMBOL Temperature  = W1  SYMBOL TempMsb   = b3  SYMBOL TempLsb  = b2
 SYMBOL T            = W2  
 SYMBOL Sign         = b9
 SYMBOL D0           = b10
 SYMBOL D1           = b11 
 SYMBOL D2           = b12 
 SYMBOL D3           = b13 
 SYMBOL D4           = b14

SETFREQ M32
 	dirsB = %11111111			
 	dirsC = %11001111
Initialise: 	
	FOR  index = 0 to 6                                               
          LOOKUP index, ($38,$38,$38,$0C,$01,$02,$06),senddata : PULSOUT E,1 ' Initialise LCD/OLED
          '(8bit/2line/5x8)*3(Display On)(Clear Display)(Return Home)(Entry Mode Set)	
 	NEXT index : PAUSE 10
Main:            

  ConvertTemperature:
  ReadTEMP12 DS18B20,T
  
       Temperature = T                                        
       Sign = " "                                                    ' Display +   
     IF TempMsb > 127 THEN                       
       Sign = "-"                                                    ' Display - 
       Temperature = - Temperature                                    
     ENDIF 
            Temperature = Temperature *8**51200+5                    ' Celsius(-55.0°C to 125.0°C)rounded up
                  BinTOASCII Temperature,D4,D3,D2,D1,D0 
                  IF  D4 = "0" THEN : D4 = Sign                      ' leading zero blanking 
                   IF D3 = "0" THEN : D3 = Sign : D4 = " " : ENDIF   ' leading zero blanking 
                  ENDIF 
    DisplayTemperature:
           LOW  RS : senddata = 128 : PULSOUT E,1                    ' commandmode (128-147) Line 1 Cursor Position
           HIGH RS                                                   ' charactermode
           FOR  index = 0 TO 8
 	          LOOKUP index,(D4,D3,D2,".",D1,223,"C  "),senddata 
 	                       PULSOUT E,1                             ' sending characters  
           NEXT index 
            
    ConvertTemperatureF:
        Temperature = T                                    
       Sign = " "                                                    ' Display +
       Temperature = Temperature +880 *16**46080 -6700               ' Fahrenheit(-67.0°F to 257.0°F)rounded up   
     IF TempMsb > 127 THEN                       
       Sign = "-"                                                    ' Display - 
       Temperature = - Temperature                                    
     ENDIF    
       Temperature =   Temperature +5                                                   
                  BinTOASCII Temperature,D4,D3,D2,D1,D0 
                  IF  D4 = "0" THEN : D4 = Sign                       ' leading zero blanking 
                   IF D3 = "0" THEN : D3 = Sign : D4 = " " ENDIF      ' leading zero blanking 
                  ENDIF 
    DisplayTemperatureF:
           HIGH RS                                                   ' charactermode
           FOR  index = 0 TO 6
 	          LOOKUP index,(D4,D3,D2,".",D1,223,"F"),senddata 
 	                       PULSOUT E,1                             ' sending characters  
           NEXT index                                                                                 
GOTO main
 

rq3

Senior Member
Hi again rq3,
The +5 is for rounding up a bit of a gimmick really...
D0 actually represents the second decimal but we don't show it.
example 32.16F to round up we add 5 which is 32.2F which is what's displayed.

it was an example to get started actually a quick cut n paste from another post
we should cover all possibilities we think of for the fussy and keen lol.
here's a slight improvement for the formatting you can try
like yourself I always look at trying to improve... cheers
Aha! Very clever! I lost track of the data bytes, and now understand completely.
Your original code, modified for leading zero deletion by me (a trivial mod, which is all I am capable of) looks like:
Code:
'version 2.D AXE132 8Bit marks via picaxe forum
'modified 10/7/2016 by rq3 to autoadjust display width
'for number of digits

#PICAXE 18M2                                   
#NO_DATA
SETFREQ M32
     dirsB = %11111111            
     dirsC = %11001111
    
SYMBOL Rx=C.5
SYMBOL E=C.6                              
SYMBOL RS=C.7
SYMBOL DS18B20 = C.0                                  
SYMBOL senddata=pinsb
SYMBOL index=b0           
SYMBOL Temperature=w1
SYMBOL TempMsb=b3
SYMBOL TempLsb=b2
SYMBOL T=w2  
SYMBOL Sign=b9
SYMBOL D0=b10
SYMBOL D1=b11 
SYMBOL D2=b12 
SYMBOL D3=b13 
SYMBOL D4=b14

Initialise:     
    FOR  index = 0 to 6                                               
       LOOKUP index, ($38,$38,$38,$0C,$01,$02,$06),senddata : PULSOUT E,1 ' Initialise LCD/OLED
          '(8bit/2line/5x8)*3(Display On/flashing Cursor)(Clear Display)(Return Home)(Entry Mode Set)    
    NEXT index
        PAUSE 10
Main:            
  ConvertTemperatureC:
      ReadTEMP12 DS18B20,T
       Temperature=T                                        
           Sign="+"                                                       ' Display +   
         IF TempMsb>127 THEN                       
          Sign="-"                                                       ' Display - 
           Temperature = -Temperature                                    
         ENDIF 
         Temperature=Temperature*8**51200+5                                  ' Celsius(-55.0C to 125.0C)rounded up
             BinTOASCII Temperature,D4,D3,D2,D1,D0 
                IF  D4="0" THEN:D4=" "                                        ' leading zero blanking 
               IF D3="0" THEN:D3=" "                                        ' leading zero blanking 
                    ENDIF 
                    ENDIF
  DisplayTemperatureC:
      LOW  RS:senddata=128:PULSOUT E,1                                              ' commandmode (128-147) Line 1 Cursor Position
   HIGH RS                                                               ' charactermode
       FOR  index=0 TO 7
            IF D3=" " AND D4=" " THEN
                LOOKUP index,(Sign,D2,".",D1,223,"C",32,32),senddata
            ELSEIF D4=" " THEN
                LOOKUP index,(Sign,D3,D2,".",D1,223,"C",32),senddata
            ELSE
                LOOKUP index,(Sign,D4,D3,D2,".",D1,223,"C"),senddata
            ENDIF
                PULSOUT E,1                                                     ' sending characters  
      NEXT index 
  ConvertTemperatureF:
      Temperature=T                                    
       Sign="+"                                                          ' Display +
          Temperature=Temperature+880*16**46080-6700                       ' Fahrenheit(-67.0F to 257.0F)rounded up   
        IF TempMsb>127 THEN                       
          Sign="-"                                                    ' Display - 
           Temperature=-Temperature                                    
         ENDIF    
           Temperature=Temperature+5                                                   
             BinTOASCII Temperature,D4,D3,D2,D1,D0 
                IF D4="0" THEN:D4=" "                                     ' leading zero blanking 
               IF D3="0" THEN:D3=" "                                            ' leading zero blanking 
                    ENDIF 
                    ENDIF
  DisplayTemperatureF:
      HIGH RS                                                               ' charactermode
       FOR index=0 TO 7
            IF D3=" " AND D4=" " THEN
                LOOKUP index,(32,32,Sign,D2,".",D1,223,"F"),senddata
            ELSEIF D4=" " THEN
                LOOKUP index,(32,Sign,D3,D2,".",D1,223,"F"),senddata
            ELSE
               LOOKUP index,(Sign,D4,D3,D2,".",D1,223,"F"),senddata 
            ENDIF
               PULSOUT E,1                                                     ' sending characters  
      NEXT index                                                                                 
GOTO main
IMG_0029.JPGIMG_0030.JPG
So now I guess I'll have to split the display into two lines (Fahrenheit on top, Celsius on bottom) and chase the 5th digit. Noooo, don't do it. I wanna do it myself ;).

PS: I like your formatting better than mine. Losing the "+" sign is much cleaner and more readable.
 
Last edited:
Top