-
8 Attachment(s)
SSD1306 INCLUDE for PBP3
Features :-
Pic 16 or 18
Tiny size about 1.5k words for soft i2c 1.3k for hw i2c
64X128 OR 32X128 DISPLAYS
SOFT I2C OR HARDWARE I2C
NORMAL OR DOUBLE SIZE CHAR
HORIZ and VERT LINES
Speed for hw i2c tested up to 2,666,666 clock rate, makes soft i2c look like a snail
Simple Usercommand Commands
-
1 Attachment(s)
Re: SSD1306 INCLUDE for PBP3
update include
added inline const string capability for pic16 chips
-
Re: SSD1306 INCLUDE for PBP3
Looks good. I don't have lcd to try it out.
I hope that you didn't write all user command wrapper manually.
I posted app for that
http://www.picbasic.co.uk/forum/showthread.php?t=20208
-
Re: SSD1306 INCLUDE for PBP3
Code:
I hope that you didn't write all user command wrapper manually.
I posted app for that
I am aware of your app but the base code for this preceded it , so yes it was a manual work:frown:
I haven't done anything pbp wise with enough user command code in it to use your app yet .it seems that
I have spent most of my time coming to terms with the mcc and xc8 lately . I don't see myself coming back
from that exercise now . development wise C is just so much easier, I will still keep hacking away at pbp
for now anyway.
-
Re: SSD1306 INCLUDE for PBP3
Nice work, thanks Richard for sharing.
Ioannis
-
1 Attachment(s)
Re: SSD1306 INCLUDE for PBP3
Thank you for posting an SSD1306 example, Richard. I'd like to bring up my 128x32 OLED display using a 16F1823 and XC8 with a 'retro' TIL311 type font.
Cheerful regards, Mike
-
1 Attachment(s)
Re: SSD1306 INCLUDE for PBP3
Richard, may I ask if you did anything special to run the SSD1306 display and I2C interface at ~2.6-MHz, please? I'm amazed that my setup (on a solderless breadboard) is running without any problems at 1-MHz but when I tried a 2-MHz I2C clock the display doesn't come up. I'm using 3.6 kOhm pull-up resistors on the I2C bus.
Cheerful regards, Mike
-
Re: SSD1306 INCLUDE for PBP3
mike
I had "setup" the display at a lower rate and kept increasing the i2c baud rate till the display failed to update .
only one of my 6 displays could exceed 1mhz , one had issues above 400khz. I did not look at the pull up resistors .just trusted that the modules were fitted out appropriately. vcc was 3.3 v
the data sheet specs give a ic2 clock of 2.5uS 400khz so its probably not the best idea I have had.
i'm running them a 400k for reliability
-
Re: SSD1306 INCLUDE for PBP3
I didn't realize there were pull-up resistors already installed on the display module. I pulled the 3.6k resistors and the display works fine. My circult and display are running on 5v.
Thank you again for new info'...
Hope you and family are well and enjoying a wonderful summer.
Cheerful regards, Mike
-
Re: SSD1306 INCLUDE for PBP3
Hi Richard,
it's any possibilities to drawing a line like a progress bar?
For example, I had ADVAL value from 0 to 120, and I want to draw line on OLED.
I try this:
Code:
GLCDDHL 0,0,adval,1
This didn't work because GLCDDHL accept only numbers not variables like ADVAL.
It there any way to do it with your include?
-
Re: SSD1306 INCLUDE for PBP3
Quote:
This didn't work because GLCDDHL accept only numbers not variables like ADVAL.
It there any way to do it with your include?
EASY , Just add the highlighted macro's to the include file
Code:
;----------------------HORIZ LINE------------------------------------ GLCDDHL?CCCC macro Xin ,Yin , Win ,Cin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?CB Win ,_gl
MOVE?CB Cin ,_glcdData
L?CALL _xyx
endm
GLCDDHL?CCBC macro Xin ,Yin , Win ,Cin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?BB Win ,_gl
MOVE?CB Cin ,_glcdData
L?CALL _xyx
endm
GLCDDHL?CCWC macro Xin ,Yin , Win ,Cin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?WB Win ,_gl
MOVE?CB Cin ,_glcdData
L?CALL _xyx
endm
-
Re: SSD1306 INCLUDE for PBP3
Thanks Richard, tomorrow I try it.
And this probably for vertical lines:
Code:
;----------------------VERT LINE------------------------------------
GLCDDVL?CCC macro Xin ,Yin , Hin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?CB Hin ,_gl
L?CALL _xyy
endm
GLCDDVL?BCC macro Xin ,Yin , Hin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?CB Hin ,_gl
L?CALL _xyy
endm
GLCDDVL?WCC macro Xin ,Yin , Hin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?CB Hin ,_gl
L?CALL _xyy
endm
Right?
-
Re: SSD1306 INCLUDE for PBP3
Quote:
And this probably for vertical lines:
no , the Hin is what you would change
Code:
;----------------------VERT LINE------------------------------------
GLCDDVL?CCC macro Xin ,Yin , Hin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?CB Hin ,_gl
L?CALL _xyy
endm
GLCDDVL?CCB macro Xin ,Yin , Hin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?BB Hin ,_gl
L?CALL _xyy
endm
GLCDDVL?CCW macro Xin ,Yin , Hin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?WB Hin ,_gl
L?CALL _xyy
endm
-
Re: SSD1306 INCLUDE for PBP3
I tried it, and it works for drawing smooth line from variable 0 to 120 for example, but if the value decreasing from 120 to 0 then I'm not able to clean the line without clearing the whole display and it causes flickering.
Why I need that? I'm trying to make a voltmeter with bargraph.
Here are the code snipet:
Code:
gosub glcd_init
GLCD_CLR
do
for n=0 to 120 step 1
GLCDDHL 0,0,n,1
next n
for n=120 to 0 step -1
GLCD_CLR
GLCDDHL 0,0,n,1
next n
loop
It would be good to have variable option in all options like:
Code:
GLCDDHL var1,0,var2,0
GLCDDVL var1,0,var2,0
GLCD_CLR var1,0,var2,0
It's that possible?
-
1 Attachment(s)
Re: SSD1306 INCLUDE for PBP3
I Think a new command is easier
USERCOMMAND "GLCD_BAR" ;clear/SET area x,y,X1,Y1,COLOUR
eg
GLCD_BAR 0,0,var1,3,1 ;draw a horiz bar from 0,0 to var1 . three pixels wide
GLCD_BAR 0,0,var1,3,0 ;clear a bar from 0,0 to var1 . three pixels wide
or
GLCD_BAR 0,0,3,var1,1 ;draw a vert bar from 0,0 to var1 . three pixels wide
GLCD_BAR 0,0,3,var1,0 ;clear a bar from 0,0 to var1 . three pixels wide
i don't have anything setup so this is untested, caveat emptor
ps if GLCD_BAR 0,0,3,var1,1 is not right then
GLCD_BAR 0,0,3,var1,255 might be needed
-
Re: SSD1306 INCLUDE for PBP3
an improvement if bar cmd fails
Code:
gosub glcd_init
GLCD_CLR
do
for n=0 to 120 step 1
GLCDDHL 0,0,n,1
next n
for n=120 to 0 step -1
GLCD_CLR 0,0,120,1 ;is a lot more efficient
GLCDDHL 0,0,n,1
next n
loop
-
Re: SSD1306 INCLUDE for PBP3
Thanks for reply,
It doesn't work quite well. It draw four lines instead one line. For me is more suitable to have variables in usercommands like I wrote before.
Code:
GLCDDHL var1,0,var2,0
GLCDDVL var1,0,var2,0
GLCD_CLR var1,0,var2,0
because in this case I can point exactly what and where I want to clear the line, or draw a for example 10pixel wide line and move it horizontally wherever I want with changing variables.
Code:
do
for n=0 to 120 step 1
GLCDDHL 0,0,n,1
next n
for n=120 to 0 step -1
GLCD_CLR 0,0,120,1 ;is a lot more efficient
GLCDDHL 0,0,n,1
next n
loop
This solution I tried before as well, it still flicker if line goes from 120 to 0.
-
Re: SSD1306 INCLUDE for PBP3
i can't follow what your saying
show some code of what you try an describe what you get or post a pic
did you try new include file like this for narrow bar?
GLCD_BAR 0,0,var,1,1 ;draw a horiz bar from 0,0 to var . 1 pixels wide ;//or GLCD_BAR 0,0,var,1,255 ;draw a horiz bar from 0,0 to var . 1 pixels wide
-
Re: SSD1306 INCLUDE for PBP3
I want to create this just with straight one pixel line.
https://www.youtube.com/watch?v=R0YfQ6O7H3E
-
Re: SSD1306 INCLUDE for PBP3
i understand what you are trying to do.
i don't follow how you are trying to implement it
-
Re: SSD1306 INCLUDE for PBP3
while usercmd helps alleviate the turpitude of pbp's immutable condition when it comes to
support for any peripheral devices/hardware module less than 20 years old.
usercmd is by no means perfect, a macro needs to exist for each and every permutation of input term/s
and that can be lots and lots of macros. i create only the ones i require ,its not difficult to
add more . a close look at the error messages when compiling tells you whats missing if there is an issue
pedja089 made this if you want an easy way to cover many bases
http://www.picbasic.co.uk/forum/show...hlight=usercmd
-
Re: SSD1306 INCLUDE for PBP3
I suppose you are aware of the Darrel's Bargraph include file (http://dt.picbasic.co.uk/CODEX/LCDBARgraphs). Isn't this enough for your needs?
Ioannis
-
Re: SSD1306 INCLUDE for PBP3
It took a little while to figure out how to do it, but finally I made it.
Thanks for help to Richard. He pointed me how to modify usercomands for my needs. Endless possibilities to create a bargraphs, progress bars etc. On camera looks a bit flickery, but in real life no flicker whatssoever.
Here a little demo how it works:
https://www.youtube.com/watch?v=6hfGOawnZ-M
-
Re: SSD1306 INCLUDE for PBP3
-
Re: SSD1306 INCLUDE for PBP3
Very nice! Congratulations for the conquer of the Usercommand. Never could find how to make use of it.
Ioannis
-
Re: SSD1306 INCLUDE for PBP3
Hello,
I need help getting this to work. My oled display does not respond at all and appears off. I'm running the sd1306_demo_16.pbp program. Everything compiles fine. I'm using a 16F1619. Here is what I've tried so far.
1. I tried both the old and newer i2c.inc files
2. Confirmed the oled works by using it on an Arduino
3. Confirmed the proper oled address with the Arduino (0x3C). I made the change in the demo.pbp file
4. Ran blink LED program on the PIC16F1619 to verify functionality
5. Tried at lower 4Mhz clock speed
6. Checked Clock and Data pins with scope to make sure data was being output to the display, it is
7. Tried two other oled
I'm not sure what else to try. I've never used an include file before so maybe I'm doing something wrong. I put all the include files and font files in the same folder as the .pbp file location.
Code:
'****************************************************************
'* Name : ssd1306_DEMO.PBP *
'* Author : richard *
'* Notice : *
'* : *
'* Date : 19/11/2017 *
'* Version : *
'* Notes : *
'* :FOR pic 16F1619 SSD1306 *
'****************************************************************
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & _ZCD_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_HI & _LVP_ON
__config _CONFIG3, _WDTCPS_WDTCPS6 & _WDTE_OFF & _WDTCWS_WDTCWS100 & _WDTCCS_LFINTOSC
#ENDCONFIG
define OSC 32
'define OSC 4
; --- *** Oscillator *** ---------------------------------------------------
OSCCON = %11110000 ;32 MHz,
'OSCCON = %01101000 ;4 MHz,
ANSELb = 0
ANSELA = 0
ANSELC = 0
char var byte
x var byte
y var byte
BUFF VAR BYTE[16]
;use this define for hw i2c
;#define hwi2c 1
#DEFINE PIC16 1
;set and uncomment these to use softi2c
SCL var PortB.6 ' I2C Clock PICpin 11
SDA var PortB.4 ' I2C Data PICpin 13
;set these to match display
ssdheight con 7 ; 7 = 8 PAGES 64*128 , 3 = 4 pages 32*128
ssdwidth con 127 ; 128 PIXELS WIDE
'sdd1306_addr con $78
sdd1306_addr con $3C
Include "ssd1306_I2C.INC" ' bring it in
include "font7x5_16.bas"
'========================== MAIN Routine ==============================
gosub glcd_init
BIG_TEXT = 0
looper:
GLCD_CLR
GLCDDHL 0,0,75,1 ;x,y,len,patten
GLCDDHL 0,2,75,128
GLCDDVL 0,0,3 ;x,y,height [in pages]
GLCDDVL 75,0,3
;GLCDSTR 5,1,"--SSD1306--" ;x,y, cont string PIC 18 ONLY
ARRAYWRITE BUFF,["--SSD1306--",0]
GLCDSTR 5,1,BUFF
ARRAYWRITE BUFF,["ABCDEF",0]
CHAR="!"
GLCDC 100,1,CHAR ;x,y , chr
BIG_TEXT = 1
if ssdheight > 3 then
GLCDSTR 2,4,BUFF
ARRAYWRITE BUFF,["@12456-=#",0]
BIG_TEXT = 0
GLCDSTR 2,7,BUFF ;x,y ,str buffer [null terminated]
else
pause 1000
GLCD_CLR
GLCDSTR 2,0,BUFF
ARRAYWRITE BUFF,["@12456-=#",0]
BIG_TEXT = 0
GLCDSTR 2,3,BUFF
endif
PAUSE 3000
GOTO looper
END
-
Re: SSD1306 INCLUDE for PBP3
Quote:
3. Confirmed the proper oled address with the Arduino (0x3C). I made the change in the demo.pbp file
arduino use a 7 bit address pbp uses an 8 bit addresss , correct address to use is (arduino address)<<1
0x3c<<1 = 0x78
-
Re: SSD1306 INCLUDE for PBP3
thanks Richard,
I had no idea. I changed the address back to 0x78 just now and I still don't get anything on the screen. I get this ASM Warning in the results window after compiling. Not sure if it matters
[ASM WARNING] SD1306_DEMO_16.ASM (400) : Found label after column 1. (GLCD_BAR?CCBWC)
[ASM WARNING] SD1306_DEMO_16.ASM (432) : Found label after column 1. (GLCD_BAR?CCBWC)
-
Re: SSD1306 INCLUDE for PBP3
Quote:
I get this ASM Warning in the results window after compiling. Not sure if it matters
[ASM WARNING] SD1306_DEMO_16.ASM (400) : Found label after column 1. (GLCD_BAR?CCBWC)
[ASM WARNING] SD1306_DEMO_16.ASM (432) : Found label after column 1. (GLCD_BAR?CCBWC)
it does matter, it means you are not compiling the code you posted.
Found label after column 1 means the macro you are trying to compile does not exist.
the GLCD_BAR usercommand does not exist in the original include it was added to for louis' setup and only a small subset of input var combinations are
catered for. i have not tested the added code and am not sure what louis wound up with.
get the demo working first
-
Re: SSD1306 INCLUDE for PBP3
thanks, I went back and used the original ssd1306_I2C.inc. Now no warning when I compile. With no changes to the demo I still can't get anything to show on the oled. To make sure the oled hardware is still good I just checked it with the arduino and it's working fine. I've triple checked my wiring and don't see any mistakes.
-
Re: SSD1306 INCLUDE for PBP3
i havent used one of those displays for some time ,my other demo for a pic16f1619 used the mssp i2c module
try this ,it worked on my curiosity board , plugged straight in to click socket
Code:
'****************************************************************
'* Name : ssd1306_DEMO.PBP *
'* Author : richard *
'* Notice : *
'* : *
'* Date : 19/11/2017 *
'* Version : *
'* Notes : plugs into click port note !!!!sda/scl swapped on click skt*
'* :FOR pic 16F1619 SSD1306 *
'****************************************************************
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & _ZCD_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_HI & _LVP_ON
__config _CONFIG3, _WDTCPS_WDTCPS6 & _WDTE_OFF & _WDTCWS_WDTCWS100 & _WDTCCS_LFINTOSC
#ENDCONFIG
define OSC 32
; --- *** Oscillator *** ---------------------------------------------------
OSCCON = %11110000 ;32 MHz,
ANSELb = 0
ANSELA = 0
ANSELC = 0
char var byte
x var byte
y var byte
BUFF VAR BYTE[16]
;use this define for hw i2c
#define hwi2c 1
#DEFINE PIC16 1
;set and uncomment these to use softi2c
'SCL var PortB.4 ' I2C Clock
'SDA var PortB.6 ' I2C Data
RB VAR WORD
;set these to match display
ssdheight con 7 ; 7 = 8 PAGES 64*128 , 3 = 4 pages 32*128
ssdwidth con 127 ; 128 PIXELS WIDE
sdd1306_addr con $78
Include "ssd1306_I2C.INC" ' bring it in
include "font7x5_16.bas"
'========================== MAIN Routine ==============================
TRISB = $F0;
PPSLOCK = $55;
PPSLOCK = $AA;
PPSLOCK = 0 ; unlock PPS
SSPCLKPPS = $0C; //RB4->MSSP:SCL;
SSPDATPPS = $0E; //RB6->MSSP:SDA;
RB6PPS = $11; //RB6->MSSP:SDA;
RB4PPS = $10; //RB4->MSSP:SCL;
PPSLOCK = $55;
PPSLOCK = $AA;
PPSLOCK = 1; ; lock PPS
gosub glcd_init
GLCD_CLR
BIG_TEXT = 0
ARRAYWRITE BUFF,["READY",0]
GLCDSTR 10,1,BUFF
-
Re: SSD1306 INCLUDE for PBP3
unfortunately I don't get anything on the oled
-
Re: SSD1306 INCLUDE for PBP3
Maybe it is nonsense this but, is there a contrast control? I had an issue once on LCD with this.
Ioannis
-
Re: SSD1306 INCLUDE for PBP3
thanks but no, there is no contrast control. if anyone has any ideas let me know. i'll post if I ever figure it out
-
Re: SSD1306 INCLUDE for PBP3
Hi Guys
Can anyone help! I am trying to get this code to work with a 16f88 and a 128x32 OLED.
-
4 Attachment(s)
Re: SSD1306 INCLUDE for PBP3
I'm using Richards code with a small 0.96" 128x32 OLED display, soft I2C (because the 18F46K42 doesn't have the "old" MSSP module).
I've managed to print text and variables on the screen but in order to update those values without clearing the whole screen I'm trying to figure out how to use the GLCD_CLR command to clear an area.
I can make it do something but what it does doesn't make much sense to me. It seems to be pixel by row based but still, it's acting weirdly on me.
For example, with the following screen as a starting point:
Attachment 9033
GLCD_CLR 0,0,5,1 or GLCD_CLR 0,0,10,1 does absolutely nothing while GLCD_CLR 0,0,10,2 does this:
Attachment 9032
GLCD_CLR 10,0,40,1 does this (which is reasonable, clearing a section of 30pixels wide, 1 row high):
Attachment 9031
While GLCD_CLR 10,0,41,1 does this:
Attachment 9030
I'm also getting strange results with the GLCD_BAR command. Anyone knows/understands what's going on here? Am I using it wrong or have I stumbled across an issue?
/Henrik.
-
Re: SSD1306 INCLUDE for PBP3
Well, it turns out I don't have to worry about manually blanking out "stuff" - it just works. Still curious about the GLCD_CLR though.
-
Re: SSD1306 INCLUDE for PBP3
henrik
there is a great probability i never tested it to any great extent , was just happy that it cleared to whole screen at a default setting
this works for one line as i intended things to [you need to work around the limited size of the data buffer glcd_buff]
Code:
gx=5:gx_=32:gy=0:gy_=0 ; clear from x=5 for 32 bits one line
gosub setxy
j=0
for i=0 to gx_
glcd_buff[i]=0 ;by default the buffer is 32 bytes so be wary
next
glcd_rad=gx_
gosub ssd_data
two lines
Code:
gx=5:gx_=32:gy=0:gy_=1
gosub setxy
j=0
for i=0 to gx_
glcd_buff[i]=0
next
glcd_rad=gx_
gosub ssd_data
gosub ssd_data
you may be able to figure out why the command fails , i'm just not seeing it at the present time
-
Re: SSD1306 INCLUDE for PBP3
try this
Code:
glcd_clrxy: ' clear area x1y1 to x2 y2
FOR GRX = 0 TO 31
glcd_buff[GRX] = glcdData
NEXT
CTEMP = (1 + GX_ - GX)*(1 + GY_ - GY)
gosub setxy
glcd_rad=32
for GRX = 0 to CTEMP/32
gosub ssd_data
next
glcd_rad = CTEMP//32
IF glcd_rad THEN
gosub ssd_data
ENDIF
return
-
Re: SSD1306 INCLUDE for PBP3
Thank you Richard!
Replacing the glcd_clrxy subroutine with that from post #38 seems to have fixed it.
It also seems to have made GLCD_BAR more predictable but I have not looked into how they're interconnected.
I also got the two Label after column 1 warnings (GLCDS_BAR_?CCBWC) etc but it turns out that there's a whitespace infront of those two macro labels on the include file. There was also an ELSE in column 1 causing another warning.
I need to spend some time trying to figure out how it does it's things, would like to be able to add a slightly larger font for example. Guessing I need to replace/change the unpack routine - at the very least.
This SSD1306-driver saved me alot of time, much appreciated Richard!
/Henrik.