IR time-set OLED digital clock w/ 08M2 and old wall clock quartz module

mrburnette

Senior Member
Part 1

"the 18M2 port" continues in Part 2: http://www.picaxeforum.co.uk/entry.php?39-IR-set-18M2-clock-implemented-into-AXE133Y-OLED-display

My wife works in a doctor's office and was going to throw away two old "drug company" wall clocks because the batteries had leaked. Fortunately, she brought them home first. It was my good fortune to find that the works was as described by Jose Pino: http://www.josepino.com/?one_second_timebase and I am aware this has previously been discussed. I followed the recommended instructions and the circuit performs well with an 08M2; my only modification being the addition of a 4R7K resistor from the diode outputs to ground (reduces issues with hum tremendously... on the breadboard, getting my hands too close to the clock jumper caused the count to be erratic and the resistor terminates the signal and cleans up the pulse nicely.)

After I had a 1 second quartz source, I decided to move forward and build an elapse time digital clock from the 08M2. That was easy. Then, I got to thinking about a real time digital clock... in 24 hour format. The code was again easy.

Then it came the time to incorporate the physical buttons for setting the time. I searched my push-button switch drawer and found some nice momentary contact switches. For some reason, I just decided that adding switches to such a simple circuit was an overkill. Why not use an old TV remote control? I even have one on the work desk that is one of the universal kinds that I sometimes use for the little digital TV over in the corner of the work room.

I used this IR receiver:
http://www.goldmine-elec-products.com/prodinfo.asp?number=G16737

I searched the forum but did not find exactly anything that I could plagiarize, so I wrote it and decided to share. I intend on porting the entire code into an AXE133Y and dedicate the OLED display as a clock with temperature... in the next phase.

The code is more of a work in progress, but it does work. Since getting the formatting and such is somewhat of a pain, I thought someone else may wish to have access, too. The full PICAXE 08M2 program is included in the ZIP.

Let's talk a bit about the individual sections:

Code:
Initialize:
	' Set frequency
	setfreq CLOCK
	' Set time - time is 24Hr mode
	hour = 00
	mins = 00
	secs = 00
	
Top:
	; Send startup message to serial port
	DispFlag = 0 : Gosub Display

	[B]If ISset = 0 Then[/B]
		DispFlag = 1
		Gosub Display
		PAUSE 5000
		Goto SetClock
	Else
		DispFlag = 4
		GoSub Display
		DispFlag = 5
		GoSub Display
	EndIf
In the above snippet, ISset is "0" at power-up, so the clock is unset. After setting using a Sony-compatible remote, ISset will be 1.

You will notice that I use bunches of DispFlag settings with a GoSub Display... this is my way of keeping the display code and formatting to a bare minimum. Nothing is ever repeated exactly, so the code space required for LCD output formatting is minimized. Each DispFlag/GoSub represents something unique.

Code:
Main:
	[B]Do while PINC.3 = 0 : Loop[/B]
	
	secs = secs + 1 // 60

	If secs = 0 Then
		mins = mins + 1 // 60
      	If mins = 0 Then
      		hour = hour + 1 // 24
      	EndIf
      EndIf

	[B]Do while PINC.3 = 1 : Loop[/B]
	
	DispFlag = 2 : GoSub Display
	
	Goto Main
Nothing very exciting here. The repurposed quartz circuit, with diode modifications, produces a 50mS positive pulse of approximately 4.4 volts. The first PINC.3 statement holds the program until a positive pulse is seen from the timebase. The second PINC.3 statement holds the program until the pulse drops from high to low. After this, there is approximately 900mS to play around with display and formatting stuff and get back to the first PINC.3 wait.

Code:
Display:
	Select Case DispFlag
  
  	Case 0
  		serout Serial,BAUD,(254,1)	'Clear
  		Pause 750
  		
  	Case 1
  		; Line 1 Pos 1
  		serout Serial,BAUD,(254,128, "Clock not set...")
 
 	Case 2
 		serout Serial,BAUD,(254,192)	' Line 2 Pos 1
 
 		If hour = 0 then
 			serout Serial,BAUD,("    00:")
 		elseif hour < 10 then
 			serout Serial,BAUD,("    0",#hour,":")
 		else
 			serout Serial,BAUD,("    ",#hour,":")
 		endIf
 		
 		If mins = 0 then
 			serout Serial,BAUD,("00:")
 		elseif mins < 10 then
 			serout Serial,BAUD,("0",#mins,":")
 		else
 			serout Serial,BAUD,(#mins,":")
 		endIf
 		
 		If secs = 0 then
 			serout Serial,BAUD,("00")
 		elseif secs < 10 then
 			serout Serial,BAUD,("0", #secs)
 		else
 			serout Serial,BAUD,(#secs)
 		endIf
 
 	Case 3
  		; Line 1 Pos 1
  		serout Serial,BAUD,(254, 128, "  Clock Setup   ")
  		; Line 2 Pos 1
  		serout Serial,BAUD,(254, 192, " Use TV Remote  ")
 
 	Case 4
  		; Line 1 Pos 1
  		serout Serial,BAUD,(254, 128, "Current time:   ")
  
  	Case 5
  		; Line 2 Pos 1
  		serout Serial,BAUD,(254, 192, "                ")
  		
  	EndSelect
  
	Return
The "Display" section should require no comments, it is very generic. Formatting commands come straight from the OLED reference documents. Change if required for other displays.

Code:
GetIR:
	IRIN C.2, B9		; X_:__:__
	GoSub CorrectVal
	hour = B9 * 10
	
	DispFlag = 5 : GoSub Display
	DispFlag = 2 : GoSub Display
	
	IRIN C.2, B9		; _X:__:__
	GoSub CorrectVal
	hour = hour + B9
	GoSub Display
	
	IRIN C.2, B9		; __:X_:__
	GoSub CorrectVal
	mins = B9 * 10
	GoSub Display
	
	IRIN C.2, B9		; __:_X:__
	GoSub CorrectVal
	mins = mins + B9
	GoSub Display
	
	IRIN C.2, B9		; __:__:X_
	GoSub CorrectVal
	secs = B9 * 10
	GoSub Display
	
	IRIN C.2, B9		; __:__:_X
	GoSub CorrectVal
	secs = secs + B9
	GoSub Display
	
	ISset = 1
	GoTo Top
GetIR is simply brute-force code. The 3-wire IR receiver output is normally "high" when idle. I make no attempts to filter for multiple IR values that come from the remote if one holds a button too long... learn to press the button firmly and fast or write code to drop all but the first digit.

Code:
CorrectVal:
	If B9 < 9 then
		INC B9
	else
		B9 = 0
	EndIf
	Return
Using the PICAXE references, the subroutine CorrectVal changes the IR received value to a normalized digit, 0-9. Consult the table in the Rev Ed documentation on IR interfacing.

View attachment 9803
View attachment 9804

I will post the success (or failure) for incorporating this code directly into the OLED PICAXE 18M2 for the AXE133Y module. At present, I'm debating if I will remove the SERIN functionality or attempt some strange magic spell that will just toss up the time/date if no activity is on the SERIN receive pin after a timeout period. The top line of the display is a static "Current time:" phrase which I was going to replace with the temperature, but I may implement some kind of scrolling across the top for other inputs, too. Just thinking...

- Ray

More thoughts... higher number values, more recent chronology:

(1) In multiple PICAXE systems (quasi-network), it may be possible to dedicate a single 08M2 to perform the IR receive various inputs and alignment calibration. This would minimize overall cost by only having one IR receiver in the system.

(2) I wanted to use a simple 1-second, 50-60Hz, or other pulse train divided-down-to 1 second to keep the entire clock near the co$t of the AXE133Y... but it is going to be difficult (opinion) to add sufficient functionality to the code of the 18M2 serial PICAXE without having a RTC off-board doing clock-ish stuff. I also only have 3 spare 18M2 lines; 4 if I kill the serial input. The more I think about the features that users are requesting which would require IR to be processed while keeping-time up-to-date, the more I am thinking that IR may have to be off-loaded.
 

Mattchou

New Member
Hey, im new to electronics this year as it is a new subject at my school but i really enjoy it and made a 5x7 LED matrix not to long ago and now i would really like to make a clock.
i have four 20m2 chips, an OLED screen and access to most basic parts but i am not quite sure how to go about it.
would you be interested in helping me?

Cheers
Matthew.
 

mrburnette

Senior Member
@Mattchou,
Certainly. The clocks that I have built relied on an external 1-second time source. But, a less complex approach would be to use an external clock IC such as this one: AXE034 with the OLED I2C display #AXE033. You do not indicate which OLED screen you have, so if you have the serial-budget display, you may wish to consider the DS1307 RTC which is I2C or the DS1337 which is a serial clock IC.
Now, if absolute accuracy is not required and you are just wishing to play with the software code and demonstrate a clock for a few hours, you can really use the internal oscillator in the PICAXE. There are lots of choices and the 1st thing to do is to decide on how you will "clock" the clock!
To help, you may wish to review search results based on DS1307 and another search on DS1337. Lots of discussion.

If you want to simply use the existing OLED 18M2 and play around with an external 1-second time source, then you may want to try this implementation: OLED Clock 18M2
The interesting thing about this version, is that you can simply change the basic code in the 18M2 (or change the chip) add an IR receiver for setting the time and use an external 1-second pulse and you have a working clock... then you can evolve the software. Just know that my software DOES NOT implement calendar functions, so if this is where you want to go, it would be best to use one of the two dedicated clock/calendar ICs and search for example code to match your part. Here is my Instructables on the clock: http://www.instructables.com/id/Oh-my-OLED-PICAXE-Digital-Clock-IR-set/

Think about what you want to achieve and primarily if you want the calendar functions. We can go from there.

- Ray

EDIT: Also take a look in the Program Editor Folder C:\Program Files\Programming Editor\projects\Alarm Clock.pdf for some ideas.
 
Last edited:
Top