28X2 to drive a Rev-Ed 4x20 OLED to tell the time with a DS3231

PhilHornby

Senior Member
I don't know why, but I find something very appealing about an object as 'delicate' as a clock, being made out of such big pieces of metal :)

(I think it should be steam powered!)
 

Rampz

Well-known member
Ok I have built a board that my picaxe will drive, pic attached its nothing special but it will allow me to understand if the code is doing what I expect it to do, I have 3 inputs Q1, Q2, and Q3 this is as Richards original diagram and I have built my board to give the same polarities with relation to the same inputs as he drew.
So Q1 = electro magnet South pulling
Q1 + Q2 = electro magnet north pushing
Q1 + Q3 = actuator return + electro magnet north
Q1 + Q2 + Q3 = actuator out + electro magnet south

I still need to confirm the north south part and will amend the above when I know.

Waiting for a vdr to arrive since the electro magnet is giving some emf that I can feel so need to sort that before connecting to the picaxe
 

Attachments

Rampz

Well-known member
If I were integrating the clock synchronisation code with RTC, and LCD handling I would start with this -
Hippy i have put your code into the 28X2 is the code at a point where i expect to see something on the screen yet?, I have wired it up as per your code the best i can see, pwered it up and downloaded the code, the terminal opened, and i'm lost at that point, help please
 

Rampz

Well-known member
Ok so i have modified the LCD diagram previously posted by Marks and altered it for the 28X2 to show how i think i am supposed to and actually have connected my OLED screen, just really checking that i am correct

Rich (BB code):
; *****************************************************************
; * HARDWARE                                                      *
; *****************************************************************

#Picaxe 28X2
#No_Table
#No_Data
#Terminal 9600
' Coding by Hippy and Marks
; .---------------------------------------------------------------.
; |    LCD connections                                            |
; `---------------------------------------------------------------'

'           .-----_-----.          .----------------------------------------------------------------------------.
'           | RST   B.7 |-->  DB7  |          16 15  14  13  12  11  10   9   8   7   6   5   4   3   2   1     |
'           | A.0   B.6 |-->  DB6  |                  |   |   |   |   |   |   |   |   |   |   |       |   |     |
'           | A.1   B.5 |-->  DB5  |   Back view     DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0  E  GND  RS      VCC GND   |
'           | A.2   B.4 |-->  DB4  |                  ^   ^   ^   ^   0V  0V  0V  0V  ^   0V  ^       V+  0V    |
'           | A.3   B.3 |          |   Winstar OLED   (2 line controllers 64+64 characters)                     |
'           | SI    B.2 |          |      (128-147)  Line 1 Cursor Position                                     |
'           | A.4   B.1 |          |      (192-211)  Line 2 Cursor Position                                     |
'           |  V-   B.0 |          |      (148-167)  Line 3 Cursor Position ( continuation of line 1 )          |
'           | RES    V+ |          |      (212-231)  Line 4 Cursor Position ( continuation of line 2 )          |
'           | RES    V- |          |           EH002004A/B                                                      | 
'           | C.0   C.7 |--> RS    '----------------------------------------------------------------------------'
'           | C.1   C.6 |--> E
'           | C.2   C.5 |
'    SCL <--| C.3   C.4 |<-> SDA
'           '-----------'


Symbol pinE  = pinC.6 : Symbol dirE  = dirC.6   ; 0 = Idle      1 = Active, oled pin 6
Symbol pinRS = pinC.7 : Symbol dirRS = dirC.7   ; 0 = Command   1 = Data, oled pin 4

Symbol pinD4 = pinB.4 : Symbol dirD4 = dirB.4   ; LCD Data Line 4, oled pin 11
Symbol pinD5 = pinB.5 : Symbol dirD5 = dirB.5   ; LCD Data Line 5, oled pin 12
Symbol pinD6 = pinB.6 : Symbol dirD6 = dirB.6   ; LCD Data Line 6, oled pin 13
Symbol pinD7 = pinB.7 : Symbol dirD7 = dirB.7   ; LCD Data Line 7, oled pin 14
I have tried several times to get this to dsiplay correctly, seems i need to copy for forum, but not sure why i have "color" in places, so i ended up copying the centre part for forum, then adding the top and bottom seperatly otherwise it all goes aweful

Edit

Thank you Jack looks much better
 
Last edited:

Jack Burns

New Member
Ok so i have modified the LCD diagram previously posted by Marks and altered it for the 28X2 to show how i think i am supposed to and actually have connected my OLED screen, just really checking that i am correct

Code:
[color=Green]; *****************************************************************
; * HARDWARE                                                      *
; *****************************************************************[/color]

[color=Navy]#Picaxe [/color][color=Black]28X2[/color]
[color=Navy]#No_Table
#No_Data
#Terminal 9600[/color]
[color=Green]' Coding by Hippy and Marks
; .---------------------------------------------------------------.
; |    LCD connections                                            |
; `---------------------------------------------------------------'

'           .-----_-----.          .----------------------------------------------------------------------------.
'           | RST   B.7 |-->  DB7  |          16 15  14  13  12  11  10   9   8   7   6   5   4   3   2   1     |
'           | A.0   B.6 |-->  DB6  |                  |   |   |   |   |   |   |   |   |   |   |       |   |     |
'           | A.1   B.5 |-->  DB5  |   Back view     DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0  E  GND  RS      VCC GND   |
'           | A.2   B.4 |-->  DB4  |                  ^   ^   ^   ^   0V  0V  0V  0V  ^   0V  ^       V+  0V    |
'           | A.3   B.3 |          |   Winstar OLED   (2 line controllers 64+64 characters)                     |
'           | SI    B.2 |          |      (128-147)  Line 1 Cursor Position                                     |
'           | A.4   B.1 |          |      (192-211)  Line 2 Cursor Position                                     |
'           |  V-   B.0 |          |      (148-167)  Line 3 Cursor Position ( continuation of line 1 )          |
'           | RES    V+ |          |      (212-231)  Line 4 Cursor Position ( continuation of line 2 )          |
'           | RES    V- |          |           EH002004A/B                                                      |
'           | C.0   C.7 |--> RS    '----------------------------------------------------------------------------'
'           | C.1   C.6 |--> E
'           | C.2   C.5 |
'    SCL <--| C.3   C.4 |<-> SDA
'           '-----------'[/color]

Symbol pinE  = pinC.6 : Symbol dirE  = dirC.6   ; 0 = Idle      1 = Active, oled pin 6
Symbol pinRS = pinC.7 : Symbol dirRS = dirC.7   ; 0 = Command   1 = Data, oled pin 4

Symbol pinD4 = pinB.4 : Symbol dirD4 = dirB.4   ; LCD Data Line 4, oled pin 11
Symbol pinD5 = pinB.5 : Symbol dirD5 = dirB.5   ; LCD Data Line 5, oled pin 12
Symbol pinD6 = pinB.6 : Symbol dirD6 = dirB.6   ; LCD Data Line 6, oled pin 13
Symbol pinD7 = pinB.7 : Symbol dirD7 = dirB.7   ; LCD Data Line 7, oled pin 14
I have tried several times to get this to dsiplay correctly, seems i need to copy for forum, but not sure why i have "color" everywhere
If you change your code tag at the beginning to code=rich then it should display the colours correctly.
 

Rampz

Well-known member
No, it simply initialises the display but doesn't write anything to it.
Ok Hippy

Based on Marks code for sending data to a 4-bit display i added

Code:
 Display:
  LOW DIRRS 
       senddata = 128 : outpinsB = senddata >> 4 : PULSOUT dirE,1 : outpinsB = senddata : PULSOUT dirE,1'(128-147) Line 1 Cursor Position
       HIGH DIRRS 
     
     FOR  index = 0 TO 18                                ' sending characters to LCD line 1
LOOKUP index,(year,":",month,":",day," ",hour,":",minutes,":",seconds),senddata 
    outpinsB = senddata >> 4 : PULSOUT dirE,1 : outpinsB = senddata : PULSOUT dirE,1'
     next index
return
I can see from your code that some parts of this are already done, i just can't get my head around sending anything along they way you have done it, i can see there is loads of info there regards layout of data and spaces needed and : etc, i just can't seem to get anything to display, any ideas?

I asked the above to be "gosub display" as below

Code:
ReadLocalTime:
  ; Read the BCD data from the clock, ignore day of week
  HI2cSetup I2CMASTER, %11010000, I2CSLOW, I2CBYTE
  HI2cIn  $00, (seconds, minutes, hour, day, day, month, year)
  ; Convert BCD to decimal
  BcdToDec( year    )
  BcdToDec( month   )
  BcdToDec( day     )
  BcdToDec( hour    )
  BcdToDec( minutes )
  BcdToDec( seconds )
  Gosub AdjustReadTimeForDST
  If localTime <> UNKNOWN Then
    localTime = hour // 12 * 60 + minutes * 60 + seconds 
  End If
gosub display
  Return
Seemed sense that after read local time be good place to display it?
 

hippy

Technical Support
Staff member
To test the RTC and display is working I would strip out what you have done and then replace the existing 'MainLoop' with -
Code:
MainLoop:
  Do
    Do
      Gosub ReadLocalTime
    Loop while seconds = lastSeconds
    lastSeconds = seconds
    ; -- Gosub CheckForPowerFail
    ; -- Gosub HandleButtonPushes
    ; -- Gosub ClockFSM
    Gosub DisplayTime
  Loop

DisplayTime:
  ; Date display
  b0 = $80     : Gosub SendCmdByte  
  b0 = year    : Gosub SendDec2
  b0 = "-"     : Gosub SendDataByte
  b0 = month   : Gosub SendDec2
  b0 = "-"     : Gosub SendDataByte
  b0 = day     : Gosub SendDec2
  ; Time display
  b0 = $C0     : Gosub SendCmdByte  
  b0 = hour    : Gosub SendDec2
  b0 = ":"     : Gosub SendDataByte
  b0 = minutes : Gosub SendDec2
  b0 = ":"     : Gosub SendDataByte
  b0 = seconds : Gosub SendDec2
  Return

SendDec2:
  b1 = b0
  b0 = b0 /  10 + "0" : Gosub SendDataByte
  b0 = b1 // 10 + "0" : Gosub SendDataByte
  Return
 

Rampz

Well-known member
To test the RTC and display is working I would strip out what you have done and then replace the existing 'MainLoop' with -
Hippy i put the code in as you said but still not seeing anything happening on the screen, i checked my connections again and they all seem good, i think i'm in the correct poins on the AXE091 board, i added some code for the terminal and managed to get it to display something, but am at a loss with the oled
Rich (BB code):
MainLoop:
  Do
    Do
      Gosub ReadLocalTime
    Loop while seconds = lastSeconds
    lastSeconds = seconds
    ; -- Gosub CheckForPowerFail
    ; -- Gosub HandleButtonPushes
    ; -- Gosub ClockFSM
    Gosub DisplayTime
    sertxd (CR,LF,#day,"-",#month,"-","20",#year,"   ",#hour,":",#minutes,":", #Seconds) '(11.59.00 PM )
  Loop

DisplayTime:
  ; Date display
  b0 = $80     : Gosub SendCmdByte  
  b0 = year    : Gosub SendDec2
  b0 = "-"     : Gosub SendDataByte
  b0 = month   : Gosub SendDec2
  b0 = "-"     : Gosub SendDataByte
  b0 = day     : Gosub SendDec2
  ; Time display
  b0 = $C0     : Gosub SendCmdByte  
  b0 = hour    : Gosub SendDec2
  b0 = ":"     : Gosub SendDataByte
  b0 = minutes : Gosub SendDec2
  b0 = ":"     : Gosub SendDataByte
  b0 = seconds : Gosub SendDec2
  Return

SendDec2:
  b1 = b0
  b0 = b0 /  10 + "0" : Gosub SendDataByte
  b0 = b1 // 10 + "0" : Gosub SendDataByte
  Return
 

Jack Burns

New Member
My 16x2 OLED always needs longer than 500ms to reliably initialise. As a test try increasing the pause time in the InitialiseLcd subroutine to pause 1000 and see if that makes any difference.
 

hippy

Technical Support
Staff member
am at a loss with the oled
This is one of the reasons we recommend using AXE133 serial modules.

I would probably remove all the code except that which relates to the display, check with a logic analyser that the correct output signals are being sent.

You could post a picture of what you have to allow your connections to be checked.
 

Rampz

Well-known member
This is one of the reasons we recommend using AXE133 serial modules.

I would probably remove all the code except that which relates to the display, check with a logic analyser that the correct output signals are being sent.

You could post a picture of what you have to allow your connections to be checked.
I don't have access to a logic analyzer unfortunately. I will move connections back to the 20X2 tomorrow where it was working on code from Marks just to check everything still functions and I haven't killed the screen
 

Attachments

hippy

Technical Support
Staff member
It's hard to say if the wiring is correct or not as it doesn't appear to be the same OLED as used on an AXE134 so I don't know what its pinout would be. The pinout for the AXE134 display when viewed from the screen side is -
Code:
.-----------------------------------------------------------------.
| .-------------------------------------------------------------. |
| |                                                             | |                        
| |                                                             | |                        
| |                                                             | |                        
| |                                                             | |                        
| `-------------------------------------------------------------' |
|   O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O                |
`-----------------------------------------------------------------'
    14 13 12 11 10 9  8  7  6  5  4  3  2  1  16 15
    D7 D6 D5 D4 D3 D2 D1 D0 E  RW RS Vo V+ 0V K  A
 

Rampz

Well-known member
It's hard to say if the wiring is correct or not as it doesn't appear to be the same OLED as used on an AXE134
Hippy it is the 20x4 oled from the picaxe store AXE134Y I just didn't fit the backpack, I will compare what you wrote against my connections and keep trying
Looking at my screen from the screen side the pins start top left going towards the right.
I can't see how what I have got is the same pinout as what your showing?
 

Attachments

Last edited:

hippy

Technical Support
Staff member
If I were integrating the clock synchronisation code with RTC, and LCD handling I would start with this -
And then belatedly have a D'Oh! moment when I realised #NO_DATA cannot be used when I am actually using DATA to hold LCD initialisation sequences and other data the code is entirely dependent upon.

And I might have also noticed that the LCD initialisation wasn't correct for 4-bit mode, that there'd been a copy and paste or editing error somewhere along the line.

This should work for testing the 4-bit display though it's untested -
Code:
; *****************************************************************
; * HARDWARE                                                      *
; *****************************************************************

#Picaxe 28X2
#No_Table
#Terminal 9600

; .---------------------------------------------------------------.
; |    LCD connections                                            |
; `---------------------------------------------------------------'

Symbol pinE  = pinC.6 : Symbol dirE  = dirC.6   ; 0 = Idle      1 = Active
Symbol pinRS = pinC.7 : Symbol dirRS = dirC.7   ; 0 = Command   1 = Data

Symbol pinD4 = pinB.4 : Symbol dirD4 = dirB.4   ; LCD Data Line 4
Symbol pinD5 = pinB.5 : Symbol dirD5 = dirB.5   ; LCD Data Line 5
Symbol pinD6 = pinB.6 : Symbol dirD6 = dirB.6   ; LCD Data Line 6
Symbol pinD7 = pinB.7 : Symbol dirD7 = dirB.7   ; LCD Data Line 7

; *****************************************************************
; * EEPROM DATA                                                   *
; *****************************************************************

Symbol LCD_ADR   = $20 ; LCD initialisation sequence

Data LCD_ADR,    ( $33,$32, $2B,$0C,$06,$1F,$01, 0 ) ; 4-bit mode

; *****************************************************************
; * LCD COMMANDS                                                  *
; *****************************************************************

Symbol LCD_CLEAR     = $01
Symbol LCD_HOME      = $02
Symbol LCD_LINE_1    = $80
Symbol LCD_LINE_2    = $94
Symbol LCD_LINE_3    = $C0
Symbol LCD_LINE_4    = $D4

; *****************************************************************
; * VARIABLES                                                     *
; *****************************************************************

Symbol reserveW0     = w0 ; b1:b0
Symbol reserveW1     = w1 ; b3:b2

; *****************************************************************
; * INITIALISATION                                                *
; *****************************************************************

PowerOnReset:
  Gosub InitialiseLCD

; *****************************************************************
; * MAIN LOOP                                                     *
; *****************************************************************

MainLoop:
  Do
    Gosub DisplayCount
    Pause 1000
    w1 = w1 + 1
  Loop

DisplayCount:
  b0 = LCD_LINE_1 : Gosub SendCommand
  b0 = "Y"        : Gosub SendChar
  b0 = "a"        : Gosub SendChar
  b0 = "y"        : Gosub SendChar
  b0 = "!"        : Gosub SendChar
  b0 = LCD_LINE_3 : Gosub SendCommand
  b0 = w1 / 10000 : Gosub SendDigit
  b0 = w1 / 1000  : Gosub SendDigit
  b0 = w1 / 100   : Gosub SendDigit
  b0 = w1 / 10    : Gosub SendDigit
  b0 = w1 / 1     : Gosub SendDigit
  Return

; *****************************************************************
; * LCD HANDLING                                                  *
; *****************************************************************

InitialiseLcd:

  dirE  = 1             ; Set LCD control lines as outputs
  dirRS = 1
  dirD4 = 1
  dirD5 = 1
  dirD6 = 1
  dirD7 = 1

  Pause 600

  ; 4-bit initialisation : $33,$32, $2B,$0C,$06,$1F,$01, 0
  
  b1 = LCD_ADR
  Do
    Read b1, b0
    If b0 <> 0 Then
      Gosub SendInitCommand
      b1 = b1 + 1
    End If
  Loop Until b0 = 0

  ; Nibble commands - To initialise 4-bit mode
  ;
  ;   $33       %0011----               8-bit
  ;   $33       %0011----               8-bit
  ;   $32       %0010----               4-bit
  ;
  ; Byte commands - To configure the LCD or OLED
  ;
  ;                 LNFff
  ;   $2B       %00101011               Display Format
  ;
  ;               L : 0 = 4-bit Mode    1 = 8-bit Mode
  ;               N : 0 = 1 Line        1 = 2 Lines
  ;               F : 0 = 5x7 Pixels    1 = N/A
  ;
  ;               f : OLED Font table   00 English-Japanese
  ;                                     01 Western European 1
  ;                                     10 English-Russian
  ;                                     11 Western European 2
  ;
  ;                   DCB
  ;   $0C       %00001100               Display Control
  ;
  ;               D : 0 = Display Off   1 = Display On
  ;               C : 0 = Cursor Off    1 = Cursor On
  ;               B : 0 = Cursor Steady 1 = Cursor Flash
  ;
  ;                    IS
  ;   $06       %00000110               Cursor Move
  ;
  ;               I : 0 = Dec Cursor    1 = Inc Cursor
  ;               S : 0 = Cursor Move   1 = Display Shift
  ;
  ;                  GP
  ;   $1F       %00011111               Graphics Mode
  ;
  ;               G : 0 = Text Display  1 = Graphics Mode
  ;               P : 0 = Int Power Off 1 = Int Power On
  ;
  ;   $01       %00000001               Clear Screen
  ;
  ; Additional OLED Graphics commands
  ;
  ;   $80       %1xxxxxxx               GXA
  ;
  ;   $40       %0100000y               GYA 

  Return

SendInitCommand:

  Pause 15              ; Delay 15mS

SendCommand:

  pinRS = 0             ; Send to Command register

  Gosub SendChar

  If b0 <= 3 Then       ; Pause to allow Home or Clear to complete
    Pause 10
  End If

  Return

SendDigit:

  b0 = b0 // 10 + "0"

SendChar:

  pinD7 = bit7          ; Put MSB out first
  pinD6 = bit6
  pinD5 = bit5
  pinD4 = bit4

  pinE  = 1             ; Give a pulse on E
  pinE  = 0

  pinD7 = bit3          ; Put LSB out second
  pinD6 = bit2
  pinD5 = bit1
  pinD4 = bit0

  pinE  = 1             ; Give a pulse on E
  pinE  = 0

  pinRS = 1             ; Send to Data register next

  Return
 

hippy

Technical Support
Staff member
I can't see how what I have got is the same pinout as what your showing?
Sorry; you are right - I was looking at the pinout for an AXE133 16x2 which I hadn't realised was different to an AXE134 20x 4. I have added a footnote to my notes.
 

Rampz

Well-known member
This should work for testing the 4-bit display though it's untested -
Hippy i didn't have any joy so to test the screen I tried some code by Marks and that worked ok.
Moved the wires back to the 28X2 and still not working, pulled the ground wires for DB0 - DB3 and put them back and now seem to have something, maybe not what is expected but maybe enough to workout what its not doing now? The screen keeps moving to a new set of letters every second i guess.
I did try it on your previous code and it was much the same, no idea what its saying, but atleast its lit and there is some life
 

Attachments

Last edited:

marks

Senior Member
Hi rampz,
the 28x2 executes a bit faster than the other picaxes
also in 4bit only the character sets $28 and $2A work.
and from memory you cant create your own 8 characters.
I quess winstar didnt finish their driver .(maybe the latest display models work?)
however all these will work using 8bit interface so maybe use the full port
you should be able to get the following to work on your 28x2 plus 4line oled using 4bit.
Rich (BB code):
'#picaxe 18m2  '  4Bit Using Alternative pins marks
#picaxe 28x2
 SYMBOL DB7  = outpinB.7
 SYMBOL DB6  = outpinB.6
 SYMBOL DB5  = outpinB.5 
 SYMBOL DB4  = outpinB.4 
 SYMBOL E    = c.6 
 SYMBOL RS   = c.7  
 SYMBOL senddata  = b0
 SYMBOL index     = b1
      
      EEPROM 25,("Picaxe18M2")
      SETFREQ M16
     dirsB = %11111111
     dirsC = %11001111
 
Initialise:     
    FOR  index = 0 to 6 
          LOOKUP index, ($33,$32,$2A,$08,$01,$06,$0C),senddata : GOSUB Send    ' Initialise LCD/OLED
                       '(WakeUp)*3(Set4Bit)(4Bit/2Line)(DisplayOff)(Clear Display)(Entry Mode Set)(DisplayOn)
     NEXT index : PAUSE 10
  
      DisplayHello:
            LOW  RS                                                                      ' commandmode
            senddata = 132 :                                     GOSUB Send              ' (128-147) Line 1 Cursor Position
           HIGH RS                                                                       ' charactermode
            senddata = "H" :                                     GOSUB Send
            senddata = "e" :                                     GOSUB Send
            senddata = "l" :                                     GOSUB Send
            senddata = "l" :                                     GOSUB Send
            senddata = "o" :                                     GOSUB Send
pause 5000
            LOW  RS                                                                      ' commandmode
            senddata = $01 :                                     GOSUB Send : PAUSE 10   ' Clear Display
            senddata = 192 :                                     GOSUB Send              ' (192-211) Line 2 Cursor Position
           HIGH RS                                                                       ' charactermode 
           FOR  index = 25 to 34
           READ index, senddata :                                GOSUB Send              ' sending character    
          NEXT index 
pause 4000

      Count1:
            LOW  RS                                                                      ' commandmode 
            senddata = 202 :                                     GOSUB Send              ' (192-211) Line 2 Cursor Position
      HIGH RS                                                                            ' charactermode 
      INC W1                                                                             ' add to W1
           BinToAscii W1,b8,b7,b6,b5,b4
           FOR  index = 0 TO 5                                                           ' sending characters
          LOOKUP index,(" ",b8,b7,b6,b5,b4),senddata :          GOSUB Send                 
           NEXT index
      PAUSE 2000                                                                         ' 1 second (M32)   
            
goto count1

       Send:
         DB7 =   bit7        
         DB6 =   bit6        
         DB5 =   bit5        
         DB4 =   bit4       
        PULSOUT E,1 
         DB7 =   bit3       
         DB6 =   bit2        
         DB5 =   bit1    
         DB4 =   bit0       
        PULSOUT E,1        :                                     RETURN
 

Rampz

Well-known member
Hi rampz,
the 28x2 executes a bit faster than the other picaxes
Hello Marks, yep that works fine thank you, i took the setup string of hexdecimal

Rich (BB code):
Data LCD_ADR,   ( $33,$32,$2A,$08,$01,$06,$0C )
and moved it back into Hippy's pervious code to get the display to say "YAY!" and that also worked.
Then moved the same string to Hippy's previous previous code where he had given me a base program layout and interchanged that string and that code then works just great, so it seems its all in getting just the right setup of the screen, i can see how you arrive at the hexadecimal and i guess the oled is expecting this data in a set order too.
 

Attachments

Last edited:

hippy

Technical Support
Staff member
also in 4bit only the character sets $28 and $2A work.
Now you mention that I have some vague recollection of that issue. Thanks for the reminder.
and from memory you cant create your own 8 characters.
That might be worth testing. I recall one issue is that setting CGRAM appears to alters the DDRAM address when it supposedly shouldn't so it needs a positioning command before writing character data.
i took the setup string of hexdecimal and moved it back into Hippy's pervious code to get the display to say "YAY!" and that also worked.
That's good news.
pulled the ground wires for DB0 - DB3 and put them back and now seem to have something
The DB0-DB3 wires aren't actually necessary in 4-bit mode, and I prefer to leave them out.
 

Rampz

Well-known member
The DB0-DB3 wires aren't actually necessary in 4-bit mode, and I prefer to leave them out.
Yep that fine just removed, i think it came from possible solutions previously
That might be worth testing. I recall one issue is that setting CGRAM appears to alters the DDRAM address when it supposedly shouldn't so it needs a positioning command before writing character data.
Not sure if this is related to positioning issue i seem to be having.
Line one should start at Hex 80 or 128 decimal but it starts me at the 7th character position
line two should start at Hex C0 or 192 decimal but it starts me at the 7th character position

this means that line 3 starts at Hex 8E or decimal 142 rather than Hex 94 or 148 decimal
and similar for line 4 being displaced by 6

i can't seem to find a way to get to the first 6 characters of line 1 and line 2

I have to assume the set up string for the OLED has set it for a smaller screen size maybe?

Edit

when i add the following at the start of the sending of characters

Rich (BB code):
b0 = $02     : Gosub SendCmdByte
Then it starts where it should, so a command of "Return Home" at the start seems to work nicely
 
Last edited:

Jack Burns

New Member
Rampz, I know you want to drive the OLED (without a backpack) directly from the 28X2, but is there a particular reason for wanting to drive it in 4-bit mode?
 

Rampz

Well-known member
Rampz, I know you want to drive the OLED (without a backpack) directly from the 28X2, but is there a particular reason for wanting to drive it in 4-bit mode?
At the start of the project i asked about with regards to what was best and explored different options, so when Hippy put together the basis of my code he used 4-bit setup along with some macro's and other parts i struggle with, i don't have the knowledge to go altering it back to 8-bit or with backpack, so i thought best try and get it working, will make for lesser component count in the end and always good to learn, but in answer to your question, no reason
 

hippy

Technical Support
Staff member
At the start of the project i asked about with regards to what was best and explored different options, so when Hippy put together the basis of my code he used 4-bit setup along with some macro's and other parts i struggle with
That was because it seemed 4-bit had been settled on. My Post #52 was the 8-bit and it should be easy enough to change what you have to 8-bit if you want to.
Line one should start at Hex 80 or 128 decimal but it starts me at the 7th character position
line two should start at Hex C0 or 192 decimal but it starts me at the 7th character position
a command of "Return Home" at the start seems to work nicely
That is odd but I will admit I've done nothing with 20x4 OLED displays and not in 4-bit mode. I would guess there's a lingering 'display shift' which 'home' clears. It might be an anomaly with the OLED controller chip or for 4-bit mode. If you change the initialisation from -

Data .... $01, 0 )

to

Data ... $01, $02, 0 )

That will hopefully fix things, mean it's not required every output.
 

Rampz

Well-known member
That was because it seemed 4-bit had been settled on. My Post #52 was the 8-bit and it should be easy enough to change what you have to 8-bit if you want to.
Hippy i think after all the issues i have had with 4-Bit and now it seems to be working i will carry on with 4-Bit for the project, it does keep the component count down and i have enough pins i think on the 28X2 for what i need

That is odd but I will admit I've done nothing with 20x4 OLED displays and not in 4-bit mode. I would guess there's a lingering 'display shift' which 'home' clears. It might be an anomaly with the OLED controller chip or for 4-bit mode. If you change the initialisation from -

Data .... $01, 0 )

to

Data ... $01, $02, 0 )

That will hopefully fix things, mean it's not required every output.
Rich (BB code):
Data LCD_ADR,   ( $33,$32,$2A,$08,$01,$06,$0C,$02 )
Yep i added $02 to the end of the string i found that worked and did a full clear followed by a download and it seems to do as was required
 
Last edited:

Rampz

Well-known member
Hello All

I have attached code as it stands at the moment, i have added inputs and outputs and tried to give a clear explanation of these and what they do.

I got the control board built as i showed previously, the relays are switched using the BCX38C i have a 1K base resistor between the transistor and the picaxe, i noticed in testing that just touching the base resistor and the relay would trigger, didn't think any more of it, but when connecting wires to the board just a unconnected wire 1m long was enough to trigger the transistor, so i had to use some pull down resistors between base and Gnd to stop this, i used a high value so not to load the picaxe pin

Regards the code the 4-bit setup is working really well now as long as wires don't ping out of the development board, the holes for the jumper wires don't tend to grip jumper wires very well next to the picaxe's

I have looked at DST code from both Hippy and Marks and i can't work out how to add there code into my project can anyone give any help please?
 

Attachments

Last edited:

Goeytex

Senior Member
I got the control board built as i showed previously, the relays are switched using the BCX38C i have a 1K base resistor between the transistor and the picaxe, i noticed in testing that just touching the base resistor and the relay would trigger, didn't think any more of it, but when connecting wires to the board just a unconnected wire 1m long was enough to trigger the transistor, so i had to use some pull down resistors between base and Gnd to stop this, i used a high value so not to load the picaxe pin

Looking at the supplied code, at initialization C.0,C.1 & C.2 (Q1,Q2, & Q3) are floating. Nowhere in the code are these pin set as outputs. Suggest these pins be set as outputs (Low) at the start of the initalization process. You may want to retain the pulldown resistors to prevent a glitch at power on.
 
Last edited:

marks

Senior Member
With this code the RTC expects expects to be programmed in GMT(00:00) all year round.
so its easiest to turn off daylightsavings on your laptop on the bottom right of your screen
you can usually right click on the time and select Adjust date/time, before programming the picaxe.
Rich (BB code):
#picaxe 20X2   '  version C.3     * marks
'           .-----_-----.          .----------------------------------------------------------------------------.
'           | V+     0V |          |          16 15  14  13  12  11  10   9   8   7   6   5   4   3   2   1     |
'           | SI     SO |          |                  |   |   |   |   |   |   |   |   |   |   |       |   |     |
'           | C.7   B.0 |-->  DB4  |   Back view     DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0  E  GND  RS      VCC GND   |
'           | C.6   B.1 |-->  DB5  |                  ^   ^   ^   ^   0V  0V  0V  0V  ^   0V  ^       V+  0V    |
'           | C.5   B.2 |-->  DB6  |   Winstar OLED  (2 line controllers (128-191)(192-255) 64+64 characters)   |
'           | C.4   B.3 |-->  DB7  |      (128-147)  Line 1 Cursor Position                                     |
'     E  <--| C.3   B.4 |          |      (192-211)  Line 2 Cursor Position                                     |
'     RS <--| C.2   B.5 |<-> SDA   |      (148-167)  Line 3 Cursor Position ( continuation of line 1 )          |
'           | C.1   B.6 |          |      (212-231)  Line 4 Cursor Position ( continuation of line 2 )          |
'           | C.0   B.7 |--> SCL   |    EH002004A/B                                                             | 
'           '-----------'           '----------------------------------------------------------------------------'    
      dirsC = %10111111    
     dirsB = %00001111    
     HI2Csetup off
    pause 400
    SYMBOL E      = C.3
    SYMBOL RS     = C.2 
    SYMBOL senddata = b0    
TABLE   0, ($3,$3,$3)  ' parrallel interface expects 8bit data first
TABLE   3, ($2)  ' ($20)sets to 4bit ,will now allow data too be received in two nibbles
TABLE   4, ($2,$A)  ' data in two parts Msb first ($28)2lineControllers/5x8font/Eng-Jap)  ($2A)Eng-Rus)
TABLE   6, ($0,$8,$0,$1,$0,$2,$0,$6,$0,$C) ' ($08)Display Off) ($01)Clear Display) ($02)Return Home) ($06)Entry Mode Set) ($0C)Display On)
TABLE  18, ("SatSunMonTueWedThuFri")
TABLE  40, ("marks......")

SYMBOL index    = b1  :  SYMBOL CRC      = b1    
SYMBOL Day = b2
SYMBOL secs  = b3 
SYMBOL mins  = b4 
SYMBOL hours = b5
SYMBOL date  = b6 
SYMBOL month = b7
SYMBOL year  = b8
SYMBOL CommonYear = b9
SYMBOL PM_AM = b10 

SYMBOL DayNumber = W6
SYMBOL DSTend = W7
SYMBOL DSTstart = W8 SYMBOL DayS = W8
SYMBOL D0 = b20
SYMBOL D1 = b21
SYMBOL D2 = b22
SYMBOL D3 = b23
SYMBOL D4 = b24
SYMBOL D5 = b25

SETFREQ M64
pause 400
IntialiseOLed:  
FOR  index = 0 to 15                                           
READTABLE index, senddata : outpinsB = senddata : PULSOUT E,1 ' Initialise OLED/LCD 
     NEXT index  :  PAUSE 20    
    
    Display:
       LOW RS                                                                                                                              
       senddata = 129 : outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1'(128-147) Line 1 Cursor Position
       HIGH RS                                                                                                                              
       pause 400        
       FOR index = 40 TO 50                                                  
 READTABLE index, senddata 
         outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1 ' sending characters to Line 1             
       NEXT index

IntialiseRTC:
 HI2Csetup I2Cmaster, %11010000, I2Cfast_64, I2Cbyte ' DS3231
;;;;   Collect  date and time from the PICAXE Editor 
          bptr=28
          FOR  index = 2 TO 18     
            LOOKUP index,(ppp_datetime),@bptrinc      '  ("2015-01-31 10:00:25")
          NEXT index
;;;;    Entering date and time in $BCD  convert from ASCII 
#terminal 76800
bptr =28
year  = @bptrinc*$10+@bptrinc-$30 :inc bptr          ' $0 to $99
month = @bptrinc*$10+@bptrinc-$30 :inc bptr          ' $1 to $12
date  = @bptrinc*$10+@bptrinc-$30 :inc bptr          ' $1 to $31
hours = @bptrinc*$10+@bptrinc-$30 :inc bptr          ' $0 to $23
mins  = @bptrinc*$10+@bptrinc-$30 :inc bptr          ' $0 to $59
secs  = @bptrinc*$10+@bptrinc-$30                    ' $0 to $59 
 
    READ  255,CRC : IF CRC <> 0 THEN Main     ' Skip if time already programmed  
      HI2Cout $0 , (secs,mins,hours)          ' RTC always expects (GMT +00:00)
     HI2Cout $4 , (date,month,year)
    Adjustsecs:
    HI2Cin  $0 , (secs)
    IF secs <> $32 THEN adjustsecs
     secs  = secs + $27              ' add seconds (to allow for how long it takes to program)
      HI2Cout $0 , (secs)
    WRITE 255,53                     ' we can make use of an existing eeprom entry 
  
Main:    
      HI2Cin  $0 , (secs,mins,hours) ' Read DS3231
      HI2Cin  $4 , (date,month,year) ' Read DS3231   
    ; 
        FOR bptr = 3 TO 8  
        @bptr = bcdtobin @bptr     ' Convert BCD to DECimal
        NEXT
     
DayNumberOfTheYear:
CommonYear = year //4 +3 /4          'CommonYear =1
DayNumber = month +9 /12
DayNumber = CommonYear + DayNumber * DayNumber
DayNumber = month *275 /9 +date -30 -DayNumber
DayOfWeek:
DayS = year *368 **65046   '365.2485 * year 1-99
Day = days + DayNumber //7 'Sat=0 Sun=1 Mon=2 Tue=3 Wed=4 Thu=5 Fri=6

BritishSummerTime:                   ' United Kingdom 
DSTstart = Days +89 //7               
DSTstart = 91 -CommonYear -DSTstart  ' Last SunDay in March      
   DSTend = Days +303 //7                
   DSTend = 305 -CommonYear -DSTend  ' Last SunDay in October 
    IF DayNumber < DSTstart OR DayNumber > DSTend THEN GMT
    IF DayNumber = DSTstart AND hours <1 THEN GMT ' DST starts at GMT 0100
    IF DayNumber = DSTend   AND hours >0 THEN GMT ' DST ends at GMT 0100   
       IF hours =23 THEN  
        INC date : day=day+1//7
      IF date =31 AND month =4 OR month =6 OR month =9 THEN : date =1 INC month: ENDIF
        IF date =32 THEN : date =1 INC month: ENDIF   
       ENDIF                  
   BST: Sertxd ("BST  ") : hours =hours +1//24 : GOTO DisplayTime ' DST +1       
   GMT: Sertxd ("GMT  ")                                 ' StandardTime 
 
DisplayTime: day =day*3 +18 
   PM_AM = "P" : IF hours <12 THEN : PM_AM ="A": ENDIF ' Indicate PM or AM
     hours = hours //12 : IF hours =0 THEN: hours =12 : ENDIF ' 24 to 12 hour format
D5 = hours  /10 +$30 : IF D5 = "0" THEN : D5 = " " : ENDIF 'Zero blanking   
D4 = hours //10 +$30
D3 = mins /10 +$30
D2 = mins //10 +$30
D1 = secs /10 +$30
D0 = secs //10 +$30

DisplayOled:
       LOW RS 
       senddata = 128 : outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1'(128-147) Line 1 Cursor Position
       HIGH RS   

   FOR  index = 0 TO 2                                   ' sending characters to LCD line one
     readtable day,senddata
      outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1'
     INC day
     sertxd (senddata) ' comment out to remove day from terminal
   NEXT index

          FOR  index = 0 TO 11                                ' sending characters to LCD line 1
LOOKUP index,(" ",D5,D4,":",D3,D2,":",D1,D0," ",PM_AM,"M"),senddata 
    outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1'
NEXT index 

 sertxd (" ",#date,"/",#month,"/20",#year,"  ")       ' (Date dd/mm/20yy) uncomment to display on terminal
sertxd (" ",D5,D4,":",D3,D2,":",D1,D0," ",PM_AM,"M",cr,lf) ' (Time HH:MM:SS AM)

GOTO main
 

hippy

Technical Support
Staff member
I have looked at DST code from both Hippy and Marks and i can't work out how to add there code into my project can anyone give any help please?
In the attachment of my code there is an "AdjustReadTimeForDST" where I would put the code for converting the RTC running on non-DST time to the local time, DST or not. If the read date and time is before DST starts, or after it has ended, it is as it should be, otherwise add an hour and adjust the day and month as required.

The other part of it is adjusting the setting of date and time from the front panel. You need to take the local time entered and convert to a non-DST time to be stored in the RTC. So, if you are setting during DST you need to subtract an hour and adjust the day and month as required.

When the program starts up, you change the year, or it rolls into another year you will need to recalculate when the start and end of DST is. That's because both are, for the UK, 'last Sunday of March and October' rather than fixed dates. That likely means having a Day of the Week routine though there are probably other ways to calculate them just from just the year.

It's all quite involved so I would recommend getting it to work for the clock prototyping code before trying to add it to code which handles pendulum grabbing.
 

Rampz

Well-known member
Hello All

Just to test my relays i used the following code

Code:
#picaxe 08M2


symbol Q1 = C.1
symbol Q2 = C.2
symbol Q3 = C.4


init:
low Q1
low Q2
LOw Q3



main:
pause 5000
High Q1
high Q2
High Q3
pause 50
low Q1
low Q2
Low Q3
pause 3000
High Q1
high Q2
High Q3
pause 50
low Q1
low Q2
Low Q3
pause 3000
High Q1
high Q2
High Q3
pause 50
low Q1
low Q2
Low Q3
pause 3000
high Q1
high Q3
pause 2000
low Q1
low Q3
end
from this i expected the actuator would move out 3x times and then return, what seems to happen wasn't as expected, it moved out many times and on occasion returned, the sequences of led's was correct eith all on Q1 + Q2 +Q3 or Q1 + Q3 but the quantity of moves out was random, i must be making a stupid mistake here some where

I did try

Code:
High Q1, Q2, Q3
pause 100
low Q1, Q2, Q3
that had same random effect, the above being only a small part, all my relays have back emf diodes, something was having a bad effect, seemed as though the picaxe was restarting several times, need to investigate further, i do have just over 1m of cable between the picaxe and the relays maybe thats having an effect, really strange
 

papaof2

Senior Member
How much power does each relay need? How stable is the power supply voltage AT THE PICAXE TERMINALS when the relay are operated?
 

Rampz

Well-known member
How much power does each relay need? How stable is the power supply voltage AT THE PICAXE TERMINALS when the relay are operated?
Hello papaof2 the relays need 33ma by the data sheet each, these are being switched by a BCX38C darlington pair transistor, with a 1k base resistor, the relay board is supplied from a 12v source of a 7ah lead acid battery and charger.

The 08M2 is on the development board AXE091 powered from the plug in transformer.

I will test voltages later but i would expect there was plenty of power atleast for the picaxe

Sometimes the code does 1 cycle as you would expect but often with more pulses of Q1 Q2 Q3 than is written, sometimes it will do more than one cycle, giving the feeling that the picaxe is re-starting

i have altered code to show on terminal whats happening

Code:
#picaxe 08M2
#terminal 4800

pause 1000

symbol Q1 = C.1
symbol Q2 = C.2
symbol Q3 = C.4


init:
sertxd("initallation",13,10)
low Q1
low Q2
LOw Q3
pause 100



main:
sertxd("code start",13,10)
pause 10000
High Q1, Q2, Q3
sertxd("first pulse on",13,10)
pause 100
low Q1, Q2, Q3
sertxd("first pulse off",13,10)
pause 1000
High Q1, Q2, Q3
sertxd("second pulse on",13,10)
pause 100
low Q1, Q2, Q3
sertxd("second pulse off",13,10)
pause 1000
High Q1, Q2, Q3
sertxd("third pulse on",13,10)
pause 100
low Q1, Q2, Q3
sertxd("third pulse off",13,10)
pause 5000
high Q1, Q3
sertxd("actuator return on",13,10)
pause 2000
low Q1, Q3
sertxd("actuator return off",13,10)
pause 100
sertxd("end",13,10)
end
From the terminal i had the following

first pulse on
firinitallation
code start
first pulse on
first pulse off
second pulse on
secinitallation
code start
first pulse on
first pulse off
second pulse on
secinitallation
code start
first pulse on
firinitallation
code start
first pulse on
firinitallation
code start
first pulse on
first pulse off
second pulse on
secinitallation
code start
first pulse on
firinitallation
code start
first pulse on
first pulse off
second pulse on
secinitallation
code start
first pulse on
first pulse off
second pulse on
second pulse off
third pulse on
third pulse off
actuator return on
actuator return off
end

seems its struggling
 
Last edited:

hippy

Technical Support
Staff member
High Q1, Q2, Q3
sertxd("first pulse on",13,10)
pause 100
low Q1, Q2, Q3
sertxd("first pulse off",13,10)
first pulse on
firinitallation
Given SERTXD outputs at 4800 baud that would suggest the PICAXE is being reset about 7ms after Q1,Q2,Q3 are set low, and that seems consistent with other times it resets, in those cases when it does.

You can try disconnecting whatever is connected to Q1, Q2 and Q3 in turn to perhaps figure out which of those is causing the reset.

Putting a scope on the power rails and other pins of the PICAXE may show what is happening. My gut feeling would be that it's the power rails collapsing but it could be induced EMI, perhaps over-current through output pins..
 

Rampz

Well-known member
Given SERTXD outputs at 4800 baud that would suggest the PICAXE is being reset about 7ms after Q1,Q2,Q3 are set low, and that seems consistent with other times it resets, in those cases when it does.

You can try disconnecting whatever is connected to Q1, Q2 and Q3 in turn to perhaps figure out which of those is causing the reset.

Putting a scope on the power rails and other pins of the PICAXE may show what is happening. My gut feeling would be that it's the power rails collapsing but it could be induced EMI, perhaps over-current through output pins..
Thank you Hippy, circuit is posted in post 106 above
 

Jack Burns

New Member
Not specifically related to your reset problem, however I’ve just been looking at your circuit board and it has raised a couple of questions with the design.
I have built a board that my picaxe will drive, pic attached
Are the 3 push buttons for manual operation?
I don’t know where the stripboard has cut tracks, but assuming the 4 way connector is connected to the picaxe outputs, then the photo suggests the picaxe outputs are shorted to +5v when pushed.

I also assume the 2 terminal connector is for the pendulum sensor, if so what voltage is on that connector as the photo suggests it’s 12v rather than 5v, as it looks like the connection has been made to the input of the voltage regulator rather than its output.
 

hippy

Technical Support
Staff member
circuit is posted in post 106 above
Thanks. If I have unravelled that correctly ...
Code:
        Relay Q1    Relay Q2         Relay Q3
        .........   .........        .........   .-.
        :       :   :    o--:----.---:-------:---|O| 1
        :    o--:---:--o    :    |   :       :   | |
+12V >--:--o    :   :   \o--:-.--|---:-------:---|O| 2
        :   \o  :   :       : |  |   :       :   | |
        :       :   :    o--:-'  |   :    o--:---|O| 3
  0V >--:-------:---:--o    :    }---:--o    :   `-'
        :       :   :   \o--:----'   :   \o  :
        :.......:   :.......:        :.......:
        
         Tran Q3     Tran Q1          Tran Q2
It's a bit confusing which Q1, Q2 and Q3 are as the relay labelling doesn't match the transistor labelling underneath them, but that perhaps doesn't matter greatly.

I am guessing connections 1-2 go to a reversible motor, the left and middle relay control on-off and direction it will turn in. Not so sure about how connection 3 is used, what that controls.

One thing I was thinking is that the order of turning the relays on might be creating a short-term incorrect circuit configuration. For example the left relay may apply power before the middle has decided which direction will be used.

Given the 7ms between activation and reset I would guess that reflects the speed of moving the relay contacts, reset happening once a circuit has been completed. That would suggest a current in-rush issue, but it could be something else. Does what's connected to 1-2-3 have suppression ?
 

Rampz

Well-known member
Are the 3 push buttons for manual operation?
Jack i put them in for testing the pcb, so i could check what was going on, they are normally open and are fed by a 5v LDO regulator along with the positive feen to the pendulum sensor, the neg rail is commoned with the picaxe, i did check several times and think the voltage regulator is the correct way around, but will check again later
 

Rampz

Well-known member
It's a bit confusing which Q1, Q2 and Q3 are as the relay labelling doesn't match the transistor labelling underneath them, but that perhaps doesn't matter.
Hippy Good point i did label the input on the connector but the software wouldn't allow me to alter connector pin labels, i never thought about the transistor labelling.

The relay setup is the same as Richard White uses on his clock regulation, there is a varistor on the electromagnet connections, all the relays have back emf diodes fitted.

The motor doesn't have any back emf control at the moment because it is reversible. but that said its supply is different to the picaxe supply only sharing the neg rail, maybe opto isolators between the picaxe and the darlington transistors would help to provide isolation?

Relay Q2 inverts the supply to Relay Q3, Relay Q1 and Q3 could be solid state relays
 

Jack Burns

New Member
i did check several times and think the voltage regulator is the correct way around, but will check again later
I wasn’t suggesting that the regulator had been installed the wrong way around, what I was saying is that the 12v input side of the regulator appears to go across to the 2 terminal connector which I’m assuming is the pendulum connector.

Have you checked the voltage across that 2 terminal connector to see if it’s 5v or 12v?
 

Jack Burns

New Member
i put them in for testing the pcb, so i could check what was going on, they are normally open and are fed by a 5v LDO regulator
I guessed the switches were there for test purposes, however the point I was trying to make is that if any of those buttons get pushed with the picaxe connected then 5v will get forced into a picaxe output pin.
 
Top