-->
Page 1 of 10

Panel Meter Clock (yet another one)

PostPosted: Sat Aug 27, 2016 9:08 pm
by russm
Have wanted to make one of these for a while so I finally got it started. Code is really easy in ESP8266Basic!

Here is a picture of two panel meters for hours and minutes. When I get another panel meter I'll add seconds, it is pretty cool to see them tick by.
Image

The panel meters are 1mA max. I found some 3.2K ohm resistors which are just slightly higher than needed. I will add a trim pot for each to adjust. Also, fighting some breadboard resistance that changes with wire movement.

I used a program to generate the simple panel meters. You can adjust the size for your particular panel meter. http://www.tonnesoftware.com/meterbasicdownload2.html Took a few prints to get it right. The meters come apart pretty easily. I'll redo them with better paper eventually, this was good enough for now.

The basic code is pretty simple. I have a few things to add as noted in the header. Running on V3.0 Alpha 42
Code: Select all'******************************************************
'* Analog Panel Meter Clock                           *
'*   by Russ McIntire, 8/27/16                        *
'*   D0 = Hours                                       *
'*   D1 = Minutes                                     *
'*   D2 = Seconds                                     *
'*                                                    *
'* To do: HTML setup screen to select DST, TZ, SSID   *
'*        Daily NTP timesetup call                    *
'******************************************************

timesetup(-4,1)  'Need to figure out what is wrong with DST
delay 5000

udpbegin 5001

hour = 0
min = 0
sec = 0
M = " "
udptimer = 0
hourpwm = 0
minpwm = 0
secpwm = 0

timer 1000, [updatetime]
wait
end



[updatetime]
'Get time values from NTP server
 hour = val(time("hour"))
 min = val(time("min"))
 sec = val(time("sec"))

'For UDP message show AM/PM
 if hour > 12 then
  hour = hour - 12
  M = "PM"
 else
  if hour = 0 then
   hour = 12
  endif
  M = "AM"
 endif

'Panel PWM calculation
hourpwm = 93.1 * (hour - 1)  'divide 1024/11
minpwm = 17.36 * min         'divide 1024/59
secpwm = 17.36 * sec         'divide 1024/59

'Panel output
io(pwo,d0,hourpwm)
io(pwo,d1,minpwm)
io(pwo,d2,secpwm)


'Send UDP broadcast message out for current time
 udptimer = udptimer + 1
 if udptimer > 30 then
  ct = str(hour)&":"&time("min:sec")&" "&M
  udpwrite "192.168.10.255", 5001, ct
  udptimer = 0
 endif
wait



It will eventually go into a wood cabinet and be constructed on a little perf board or perhaps I'll make a PCB. Hoping I can get DST working right someday. Can't seem to get it to actually do anything, had to make a work around for the aquarium timer.

Re: Panel Meter Clock (yet another one)

PostPosted: Sat Aug 27, 2016 9:24 pm
by russm
Just did an OTA update to V3.0 A43. Hilarious to watch the panel meters dance as the upgrade occurs.

Re: Panel Meter Clock (yet another one)

PostPosted: Sun Aug 28, 2016 12:57 am
by russm
Added a couple features:
1) Determines udp broadcast address from current address (assumes class c)
2) Added once/day (2:00 AM) update for NTP

Code: Select all'******************************************************
'* Analog Panel Meter Clock                           *
'*   by Russ McIntire, 8/27/16                        *
'*   D0 = Hours                                       *
'*   D1 = Minutes                                     *
'*   D2 = Seconds                                     *
'*                                                    *
'* To do: HTML setup screen to select DST, TZ, SSID   *
'******************************************************

timesetup(-4,1)  'Need to figure out what is wrong with DST
delay 5000

udpbegin 5001

i = 0
x = 0
x1 = 0
broadcastaddr = " "
hour = 0
min = 0
sec = 0
M = " "
udptimer = 0
hourpwm = 0
minpwm = 0
secpwm = 0

'Determine broadcast address
ipaddr = ip()
for i = 1 to 3
 x = instr(ipaddr,".",x1+1)
 x1 = x
next
broadcastaddr = left(ipaddr,x)&"255"

timer 1000, [updatetime]
wait
end

[updatetime]
'Get time values from NTP server
 hour = val(time("hour"))
 min = val(time("min"))
 sec = val(time("sec"))

'Set 12 hour time and determine AM/PM
 if hour > 12 then
  hour = hour - 12
  M = "PM"
 else
  if hour = 0 then
   hour = 12
  endif
  M = "AM"
 endif

'Panel PWM calculation
hourpwm = 93.1 * (hour - 1)  'divide 1024/11
minpwm = 17.36 * min         'divide 1024/59
secpwm = 17.36 * sec         'divide 1024/59

'Panel output
io(pwo,d0,hourpwm)
io(pwo,d1,minpwm)
io(pwo,d2,secpwm)

'Daily NTP refresh
if ((hour=2) and (min=0) and (sec>0) and (sec<5) and (M="AM")) then
 timesetup(-4,1)  'Need to figure out what is wrong with DST
 delay 5000
endif

'Send UDP broadcast message out for current time every 30 seconds
 udptimer = udptimer + 1
 if udptimer > 30 then
  ct = str(hour)&":"&time("min:sec")&" "&M
  udpwrite broadcastaddr, 5001, ct
  udptimer = 0
 endif
wait




Re: Panel Meter Clock (yet another one)

PostPosted: Sun Aug 28, 2016 4:20 am
by forlotto
an excellent use of your time! :P
First time I seen the analog meter type clock personally I've seen some pretty interesting clocks but guess I missed these or forgot about them.

I like your code example as well it gives people a grasp on how to handle time in a fairly easy manner.

think the following should work for you

timesetup():
Will set up the time time zone and daylight savings attribute.
timesetup({number or var for time zone},{number or var for dst})

So for instance:

timesetup(6,1)
delay 5000
get time value

6 would be central and 1 I believe is DST enable 0 is DST disabled.

You need a delay after time setup for time adjustment 5 seconds is likely overkill but play with it and see where the magic number is .

I am not sure if you have to do it after each request for hour minute I don't think you'll be doing seconds in this case just not likely imho unless you have some snazzy way of doing it in code well technically you could do so you could actually with a for x loop then increase the number of minutes you could actually be your own timer with a for x loop but you would likely lose seconds and have to resync every so often but it would be possible to do if I am thinking correctly with the right code.

Anyways good stuff thank you for sharing this one with us lots of useful info.