web based clock

Post details of your projects here.
basicchip
Posts: 923
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

web based clock

Post by basicchip » Thu Dec 27, 2018 7:51 pm

So what am I going to do with an ESP8266? Living here in the mountains, power is a bit flakey in winter sometimes the summer too. Yes most clocks have battery backup, but over time many internal batteries die or whatever. So why not get a clock that updates the time from the web?

I could start with LED displays, but large ones cost a lot, so why not start with a $10 clock from Amazon? Which is what I did, back in an earlier life my job included building demos for trade shows. Back then on the suggestion of a co-worker many demos started with a trip to Toys 'r Us, with a toy re-purposed for an electronic demo. It was great to piggyback on the tooling of those toys. So here is my starting point--
clock1.jpg
clock1.jpg (204.18 KiB) Viewed 2602 times
My first surprise was that the clock didn't have large LEDs, but instead had LEDs mounted on board with light pipes for the digits. Sure I could 3D print something similar, but my time is also valuable and $10 saved me a lot of time. Originally I thought I could piggyback on the LED drivers, but now I'll just use a lot of individual pins and will switch to an ARMstamp.



basicchip
Posts: 923
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: web based clock

Post by basicchip » Fri Dec 28, 2018 1:57 am

Been going back and forth on how to build this. I could dead bug some components, but that list keeps getting bigger. I could go all out and just design a total replacement board and move the LEDs over.

After probing around on the board, it looks like the LEDs are being muxed with 9 shared low drivers and 4 or maybe 5 high drivers. I can easily drive the low side with any of the GPIO pins, but the high side would be better with a transistor or other high side driver. Well that's a lot of flying wires, and while I have been forced to do that before for time constraints, I think it makes sense to build a small board that will hold ESP8266, ARMstamp and a number of transistors. While this is a one of a kind project, that type of board may come in handy for something else someday.

basicchip
Posts: 923
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: web based clock

Post by basicchip » Sat Dec 29, 2018 1:18 am

OK did some more probing on the main board, turns out it has 4 PNP transistors with resistors on the base for digit drive, and 8 common segment lines with series resistors. Removed the chip on board clock chip. So just need to add some wires. It had a diode protection for power input (seems useless on a USB connector. But I pulled that off and dead bugged a P MOSFET, resistor pullup and wire out so PWM can regulate the brightness. Power and GND and away we go. I like using 30 AWG wire wrap wire and hot glue, and different colors so I can keep stuff straight. Didn't much worry about the segment order hookup as that will get #defined anyway.
clock2.jpg
clock2.jpg (80.04 KiB) Viewed 2603 times
ANd how it will mount in the box
clock3.jpg
clock3.jpg (129.88 KiB) Viewed 2603 times

Now on to some programming

olzeke51
Posts: 337
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina
Contact:

Re: web based clock

Post by olzeke51 » Sat Dec 29, 2018 1:45 am

Lookin' good.
'
I did some muxing in my Dicer-deluxe program. I buffered the signals because they weren't 5v tolerant;
and the segments were 2 LEDs in series and needed the full 5v.
'
Good looking G-job!!
Gary

basicchip
Posts: 923
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: web based clock

Post by basicchip » Sat Dec 29, 2018 1:55 am

OK quick test program lights it up, one goof dead bugging the PMOS, but quickly fixed

Code: Select all

'	web clock display drive

IO(7)=0    ' PMOS drive -- will be PWM someday

for y=45 to 48
	IO(y)=0			' digit drive
	for x=8 to 15
		IO(x)=0		' segment drive
		wait(500)
		IO(x)=1
	next x
	DIR(y)=0
next y


basicchip
Posts: 923
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: web based clock

Post by basicchip » Sat Dec 29, 2018 3:42 am

Modified the program to light up everything 82 mA at 5V
clock4.jpg
clock4.jpg (97.4 KiB) Viewed 2595 times
And a closeup of deadbug PMOSFET and 1206 pullup, got to use my cheapo USB microscope, that replaced my Intel Play Microscope that just ran out off software support.
clock5.jpg
clock5.jpg (90.59 KiB) Viewed 2595 times

basicchip
Posts: 923
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: web based clock

Post by basicchip » Sat Dec 29, 2018 3:55 am

thumbsUp.jpg
thumbsUp.jpg (1.4 KiB) Viewed 2595 times
Gary

... had to capture that from FB

basicchip
Posts: 923
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: web based clock

Post by basicchip » Sat Dec 29, 2018 6:40 am

Incrementally building the display program. You'll see it was in 3 parts, trying to figure out which segment is which, then mapping segments to decimal digits, and then try displaying some 4 digit numbers.

Next onto counting time. In the long run the clock will check the time from the web, then run on its own checking every 24 hours or so, and adjusting time delays. Using divides throws a little uncertainty into it, unless I keep time in hex digits which is possible.

So here is the test program

Code: Select all


'	web clock display drive

#include "LPC11U3x.bas"


#define SEG_0	&HBB00		' (&HBB << 8)
#define SEG_1	&H1800 		' (&H18 << 8)
#define SEG_2	&HD300 		' (&HD3 << 8)
#define SEG_3	&HD900 		' (&HD9 << 8)
#define SEG_4	&H7800 		' (&H78 << 8)
#define SEG_5	&HE900 		' (&HE9 << 8)
#define SEG_6	&HEB00 		' (&HEB << 8)
#define SEG_7	&H9800 		' (&H98 << 8)
#define SEG_8	&HFB00 		' (&HFB << 8)
#define SEG_9	&HF800 		' (&HF8 << 8)
                	
#define SEG_o	&H4B00 		' (&H4B << 8)
#define SEG_f	&HE200 		' (&HE2 << 8)

const DIGarray = { SEG_0, SEG_1, SEG_2, SEG_3, SEG_4, SEG_5, SEG_6, SEG_7, SEG_8, SEG_9, SEG_o, SEG_f }

#define DIG_WAIT	1

sub	display_4num(x)
	dim d1, d2, d3, d4, i
	
	d1 = x / 1000
	x = x - d1*1000
	d2 = x / 100
	x = x - d2*100
	d3 = x / 10 
	x = x - d3*10
	d4 = x
	
	for i = 1 to 100
		IO(45) = 0
	
		GPIO_DIR(0) = (GPIO_DIR(0) & &HFFFF00FF) + DIGarray(d1)
		GPIO_CLR(0) = DIGarray(d1)
		
		wait(DIG_WAIT)
	
		INPUT(45)
		
		IO(46) = 0
	
		GPIO_DIR(0) = (GPIO_DIR(0) & &HFFFF00FF) + DIGarray(d2)
		GPIO_CLR(0) = DIGarray(d2)
		
		wait(DIG_WAIT)
	
		INPUT(46)


		IO(47) = 0
	
		GPIO_DIR(0) = (GPIO_DIR(0) & &HFFFF00FF) + DIGarray(d3)
		GPIO_CLR(0) = DIGarray(d3)
		
		wait(DIG_WAIT)
	
		INPUT(47)


		IO(48) = 0
	
		GPIO_DIR(0) = (GPIO_DIR(0) & &HFFFF00FF) + DIGarray(d4)
		GPIO_CLR(0) = DIGarray(d4)
		
		wait(DIG_WAIT)
	
		INPUT(48)
	next i
endsub
		
	
	


main:

'  first section to figure out which segment is which

#define CHK_WAIT1	100
#define CHK_WAIT2	500

IO(7)=0    ' PMOS drive -- will be PWM someday

for y=45 to 48
	IO(y)=0			' digit drive
	for x=8 to 15
		IO(x)=0		' segment drive
		wait(CHK_WAIT1)
		IO(x)=1
	next x
	DIR(y)=0
next y

' then check for mapping segments to digit value

for i = 0 to 11
	IO(45)=0
	IO(46)=0
	IO(47)=0
	IO(48)=0
	
	GPIO_DIR(0) = (GPIO_DIR(0) & &HFFFF00FF) + DIGarray(i)
	GPIO_CLR(0) = DIGarray(i)
	
	wait(CHK_WAIT2)
	
	GPIO_DIR(0) = GPIO_DIR(0) & &HFFFF00FF
	
next i

	
INPUT(45)
INPUT(46)
INPUT(47)
INPUT(48)

' now try some 4 digit numbers

for i=1 to 9
	display_4num(i)
	display_4num(i*10)
	display_4num(i*100)
	display_4num(i*1000)
	
next i		

basicchip
Posts: 923
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: web based clock

Post by basicchip » Sat Dec 29, 2018 5:37 pm

Clock function now working, using a 32 bit timer interrupt to update the displayed time. Now back to getting the time from the web... OMG the government shutdown finally affected me, some woke engineer at the deep state NIST shut down the time webpage, like he really has to be there to enter the numbers.

Code: Select all


'	web clock display drive

#include "LPC11U3x.bas"

' globals

hr = 0		' define hour
min = 0		' define minute


#define SEG_0	&HBB00		
#define SEG_1	&H1800 		
#define SEG_2	&HD300 		
#define SEG_3	&HD900 		
#define SEG_4	&H7800 		
#define SEG_5	&HE900 		
#define SEG_6	&HEB00 		
#define SEG_7	&H9800 		
#define SEG_8	&HFB00 		
#define SEG_9	&HF800 		
                	
#define SEG_o	&H4B00 		
#define SEG_f	&HE200 		

const DIGarray = { SEG_0, SEG_1, SEG_2, SEG_3, SEG_4, SEG_5, SEG_6, SEG_7, SEG_8, SEG_9, SEG_o, SEG_f }

#define DIG_WAIT	1

#define US_TIME

sub	display_time(err, hr, min)
	dim hr10, hr1, min10, min1, i
	
#ifdef US_TIME
	if hr > 12 then hr -= 12
	if hr = 0  then hr = 12
#endif	
	
	hr10 = hr / 10
	hr1 = hr MOD 10
	min10 = min / 10 
	min1 = min MOD 10
	
	for i=0 to 1
		if hr10 then
			IO(45) = 0
		endif
		
		GPIO_DIR(0) = (GPIO_DIR(0) & &HFFFF00FF) + DIGarray(hr10)
		GPIO_CLR(0) = DIGarray(hr10)
		
		wait(DIG_WAIT)
	
		INPUT(45)
		
		IO(46) = 0
	
		GPIO_DIR(0) = (GPIO_DIR(0) & &HFFFF00FF) + DIGarray(hr1) + IF(i , &H400 , 0)
		GPIO_CLR(0) = DIGarray(hr1) + IF(i , &H400 , 0)
		
		wait(DIG_WAIT)
	
		INPUT(46)


		IO(47) = 0
	
		GPIO_DIR(0) = (GPIO_DIR(0) & &HFFFF00FF) + DIGarray(min10)
		GPIO_CLR(0) = DIGarray(min10)
		
		wait(DIG_WAIT)
	
		INPUT(47)


		IO(48) = 0
	
		GPIO_DIR(0) = (GPIO_DIR(0) & &HFFFF00FF) + DIGarray(min1)
		GPIO_CLR(0) = DIGarray(min1)
		
		wait(DIG_WAIT)
	
		INPUT(48)
	next i
endsub
		
		
' user TIMER1 (32 bit) to interrupt each minute


INTERRUPT SUB TIMER1IRQ
	T1_IR = 1	      ' Clear interrupt
  
  	min += 1
	if min > 59 then
		min = 0
		hr += 1
		if hr > 23 then
			hr = 0
		endif
	endif

ENDSUB

SUB ON_TIMER ( max_cnt, dothis )
	TIMER1_ISR   = dothis + 1              'set function of VIC   -- need the +1 for Thumb operation
	SYSCON_SYSAHBCLKCTRL OR= (1<<10)		  ' enable TIMER1
	T1_PR  = 0	                         'no prescale -- will adjust the value for more accurate time
	VICIntEnable OR= (1<<TIMER1_IRQn)  	 'Enable interrupt
	T1_MR0 = max_cnt-1 ' set up match number of ms
	T1_MCR = 3      ' Interrupt and Reset on MR0
	T1_IR  = 1      ' clear interrupt
	T1_TC  = 0      ' clear timer counter
	T1_TCR = 1      ' TIMER1 Enable
	
ENDSUB

		
#define MINUT_PCLK	2880000000				' 60 seconds at 48 MHz	
	


main:

	hr = 9
	min = 33

	ON_TIMER(MINUT_PCLK , ADDRESSOF TIMER1IRQ)		
'	ON_TIMER(MINUT_PCLK / 100, ADDRESSOF TIMER1IRQ)		' testing for now

	
IO(7) = 0		' PWM some day -- need to move to P0_22 ??


while 1
		display_time(0, hr, min)
loop	
	

basicchip
Posts: 923
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: web based clock

Post by basicchip » Sat Dec 29, 2018 11:44 pm

Side tracked for a while. Between NIST disabling their website -- pretty lame I hope they don't get back pay. And looking at all the JavaScript needed to read sites like theirs, which is not going to happen on the ARMstamp.

I poked around php and found code I can stick on a website to generate the time I needed.

Code: Select all

<!DOCTYPE html>
<html lang=en>
 <head>
  <title>Coridium Time Server</title>
 </head>

<body>

<?php

    $tz_object = new DateTimeZone('America/Los_Angeles');

    $datetime = new DateTime();
    $datetime->setTimezone($tz_object);
    
    echo "time is- ",$datetime->format('H:i:s');
    echo "<br><br>";
    echo "date is- ",$datetime->format('m/d/Y');
?>

</body>
</html>

Now back to PWM for brightness. I have a photo transistor on order, and will use that to auto-dim the display. In the meantime it will just key on time of day, say 9PM to 8AM.

Post Reply