PDA

View Full Version : PIC Nixie Clock project



Heckler
- 3rd January 2016, 18:48
Hey Group,

I am designing an adapter board to allow a 20 pin pic (like a 16F690 or 16F1828, etc) to take the place of an MSP430 processor. Why?? You might ask.

Well I bought one of these...8144

from here... https://www.tindie.com/products/RobG/msp430-nixie-clock-kit/ and want to modify the way it works. Unfortunately, for me, it is controlled by an TI MSP430 processor and coded in C.

The clock is (I believe) an outstanding value as far as nixie clocks go. ($50 usd) which includes the NIXIE tubes and optional case.
I have actually purchased 2 additional clocks, 3 total. One for my son to build. Then my daughter liked it so much that I told her if she would put it together then I would get her one for Christmas.

Though the clock is quite a beautiful piece it is lacking in some features that I wanted.

Self setting time from NTP time source.
Able to blank the display during certain hours as the clock is in my bedroom and quite bright at night.
Able to blank the display when not at home to extend life of the nixie's.
Able to alternately display indoor/outdoor temperature.
(Add your own feature here...you are the programmer) :)

So I designed this... 8141

Based on this schematic...8142

Which includes one of these... 8143

The adapter PCB has a spot for a ds18b20 to provide indoor room temperature.
There is a couple of extra I/O pins to allow you to remotely recieve outdoor temperature if desired.
Will be able to get NTP time via the ESP wifi module and auto set the clock and keep accurate time.
Will have a web interface, also via the ESP, to allow you to choose hours of display on/off and easily change other parameters.
Includes a PICKIT programming header to allow firmware updates easily.

And will be coded in our favorite PBP BASIC so it will be easy to customize.
The little 1.5" x 1.5" board is an adapter that will plug into the socket for the MSP430 and fit nicely inside the case.

So if you are interested in joining in and having some fun and ending up with a nice little nixie clock... well... stay tuned. Or better yet get your clock on order! (be sure to get the optional case) assuming you want it.

I am not associated with the maker of the tindie clock kit just a satisfied customer.

I'd be happy to share my code and you can order your own adapter board from oshpark (3 for $12)

Here is another link to someones webpage reviewing the clock kit... http://maniacallabs.com/2015/03/11/msp430-nixie-clock-by-rob/

I have not yet received the adapter PCB from Oshpark, so at this time it's untested. I'll post back here when I get it and assuming no errors, etc. Here is the link to the adapter board... https://oshpark.com/shared_projects/VGYjILPE

What do you all think??

Heckler
- 15th February 2016, 01:04
Hey Group (again),

I have a pretty decent beta version of the code up and running.
My clock will now...
> auto set the time via wifi from the esp module (ntp time source) on initial power up
and every day at 0500
> blanks the display between 2200 and 0600
> cycle through all nixie digits to prevent cathode poisioning (every 15 minutes for 5 sec)
probably overkill but it looks cool
> you can choose 12 hr, 24 hr or a mode where the hours alternate between 12/24 hr
for those who can't read 24 hr time but want to learn
> can display room temperature (but I haven't actually added this to the code yet)

here are some pics...
8183

8184

8185

8186

8187

8188

here is my beta version of the code...
It runs on an 16F1828 or 16F1829 and with minor mods will run on an 16f690

'************************************************* ***************
'* Name : MSP to PIC Nixie clock.BAS * *
'* Author : [Dwight Merkley] *
'* Notice : Copyright (c) 2016 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 1/2/2016 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
#CONFIG
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_25 & _LVP_OFF
#endconfig

DEFINE OSC 8
include "ALLDIGITAL.Pbp"
'================================================= =

H10 VAR PortC.0 'hours tens digit enable
H1 var PortC.1 'hours ones digit enable
M10 var PortC.2 'minutes tens digit enable
M1 var PortC.3 'minutes ones digit enable
symbol PORT_PIN = PORTC 'used to sequentially enable portC.0-3 nixie tubes

res var PortC.4 '0-9 digit reset
clk var PortC.6 '0-9 digit counter input
ena var PortC.7 'ENA on nixie decade counter

led var LATC.5 'pwm led backlight
sw1 var portA.2 'input upper switch
sw2 var portA.1 'input lower corner switch
swflg var bit 'bit used to debounce switch pushes

ts var portB.4 'OneWire Temperature sensor
rxE var portB.5 'input rx data from esp8266
txE var portB.7 'tx data to esp8266
fet var portB.6 'High Voltage shutdown

tube var byte 'refrence tube 0-3 [hh h mm m]
hh var byte 'variable holding hours
h12 var byte
mm var byte 'variable holding minutes
ss var byte 'variable holding seconds
d1 var byte
d2 var byte
d3 var byte
d4 var byte
s1 var byte
s0 var byte
mode var byte '12 to 24 hour conversion flag'
num var byte 'current digit's pulse count
x var byte 'general purpose variable
y var byte 'counter to track time between esp serial request output
dgt var byte
temp var byte 'temporary lcd display data
IntCnt var word
IntFlag var bit
dispflag var bit 'flag to indicate if display should be off
temptime var byte 'var to determine if time to check temperature
'the following var's are used in the anti-cathode poisoning routine
position var byte
numx var byte
cath var byte
index var byte
'-------------[variables and constants for temperature routine]--------------
DS18B20_9bit CON %00011111 ' set resolution on DS18B20 93.75ms, 0.5 C
DQ VAR PortB.4 ' One-wire Data-Pin "DQ" on PortB.4
Busy VAR BIT ' Busy Status-Bit
Raw VAR WORD ' RAW Temperature readings
TempF VAR WORD ' Temp in deg F
Cold_Bit VAR Raw.BIT11 ' Sign-Bit for +/- Temp. 1 = Below 0 deg C
Sign VAR BYTE[1] ' +/- sign for temp display
TempH var word ' var for highest temp
TempL var word ' var for lowest temp
SignH var byte[1]
SignL var byte[1]
C VAR WORD ' Celsius
F VAR WORD ' Fahrenheit

INCLUDE "Temp_Convert.pbp"
'================================================= ==
'================================================= ==
TRISA = %00000110
TRISB = %00100000
TRISC = %00000000
WPUA = %00000110
OSCCON = %01110000 'set internal osc to 8 mhz
'================================================= ===
espbaud con 84
hh = 99
mm = 00
ss = 00
mode = 2 'modes
'0=24 hour only display
'1=12 hour only display
'2=24 hour with alternating 12 hour
' for dummies who don't know 24 hour time

IntCnt = 0
temp = 0

' -----[ Timer setup ]------------------------------
disable interrupt
On Interrupt goto MyInt 'define where interrupts should go
INTCON = %11000000 'now enable GIE,PEIE,x,x,GPIE,x,x,x
T1CON = %00110101 'Enable Timer1 with 1:8 prescaler
PIE1 = %00000001 'Enable Timer1 overflow interrupt
PIE2 = %00000000
PIR1.0=0 'clear the timer1 interupt flag
txe=1 'high the serial output pin, needs to start high

'************************************************* **
'======== MAIN ===========
'************************************************* **
Enable Interrupt

Main:
if swflg = 1 and sw1=1 then swflg = 0 '(sw debounce) clear swflg when switch released

if swflg = 0 and sw1=0 then
swflg = 1
if mode = 0 then
mode = 1 'switch to 12 hr mode
goto SkipSw
endif
if mode = 1 then
mode = 2 'switch to 24 hrr mode with 12 hr flash
goto SkipSw
endif
if mode = 2 then
mode = 0 'switch to 24 hr mode
endif
endif
SkipSw:

'an interrupt is generated every .005 sec
'so clear the IntFlag and cycle to the next nixie tube
if IntFlag=1 then
IntFlag=0
IntCnt = IntCnt + 1
gosub Tubes
endif

if IntCnt > 199 then gosub NextSec 'time to increment seconds

'this next routine fires every 15 minutes between 55 and 58 seconds
'it causes all digits in each nixie to be cycled to prevent
'cathode poisioning
if mm//15=0 and (ss >54 and ss<58) then
if intcnt//10 = 0 then gosub NixieBurn
endif

'this routine blanks the display between 2200 and 0600
if (hh>21) or (hh<6) then 'turn display off between 2200 and 0600
dispflag = 0
else
dispflag = 1
endif

'this routine only runs on startup and waits for 30 sec
'then it goes and reads the time from the ESP module
if hh = 99 then
d1=s0
d2=s1
dispflag = 1
if ss=30 then gosub GetTime
endif

'this routine sets the clock once a day at 0500
if hh=5 and mm=0 and ss=0 then gosub GetTime

toggle led 'for backlight brigtness at 50%
' use O-Scope to determine Main loop timing
goto Main

'************************************************* **
' interrupt every 5 msec
'************************************************* **
disable interrupt
MyInt:
IntFlag=1 ' INT has fired so set this flag for Main code usage
'>H & L size determine INT timing, INT every .005 seconds
TMR1H = $FB ' reset timer1h
TMR1L = $1F ' reset timer1l
PIR1.0 = 0 ' clear timer1 overflow flag
resume 'to Main
enable interrupt
'================================================= ============
' increment seconds and trickle down time
'================================================= ============
NextSec:
intCnt = 0
ss = ss +1
if ss = 60 then
ss = 00
mm = mm + 1
endif
if mm = 60 then
mm = 0
hh = hh + 1
endif
if hh = 24 then
hh = 0
endif

if hh>12 then
h12=hh-12
else
h12=hh
endif

d1=mm//10
d2=mm/10
d3=hh//10
d4=hh/10
s1=ss/10
s0=ss//10
if mode=1 then '12 hr only mode
d3=h12//10
d4=h12/10
endif

'this routine causes the display to alternate between 24 and 12 hr display
if mode = 2 and (s0=0 or s0=5) then '24 hr mode with
d3=h12//10 '12 hr overlay at 0 & 5 sec
d4=h12/10
endif

return
'=================================================
'--- Routine to cycle all digits on all tubes ---
'--- to prevent cathode poisoning (look it up) ---
'=================================================
NixieBurn:
numx=numx+1
if numx=10 then numx=0
for position=0 to 3
index=numx+position
if index>9 then
index=index-10
endif
lookup2 index,[1,6,2,7,5,0,4,9,8,3],cath
if position = 0 then d1=cath
if position = 1 then d2=cath
if position = 2 then d3=cath
if position = 3 then d4=cath
next position
return
'================================================= ============
' display next NIXIE digit
'================================================= ============
Tubes:
PORT_PIN.0[tube] = 0 'Turn OFF the current tube
if dispflag = 0 then
led = 1
return 'display is off so skip tubes
endif
tube=tube + 1
if tube > 3 then tube = 0

Digit:
high res 'reset the decade counter
@ nop
low res 'release the reset
lookup2 tube,[d4,d3,d2,d1],num
for x = 1 to num 'pulse the clock for "num" counts
high clk
@ nop
low clk
next x

PORT_PIN.0[tube] = 1 'Turn ON the next tube
return
'================================================= ============
' Get TIME from ESP8266-01 NTP Time Server
'================================================= ============
Disable Interrupt
SerTmout:
led=0
pause 200
led=1
pause 200
led=0
pause 200
led=1
pause 200
GetTime:
PORT_PIN.0[tube] = 0 'Turn OFF the current tube
' Wait for >,CR,LF from ESP module
serin2 rxe,espbaud,3000,SerTmout,[wait(">"),wait(13),wait(10)]
' ESP module expects "Time?" before it will give hhmmss
' to change this modify the ESP code
serout2 txe,espbaud,["Time?"]
serin2 rxe,espbaud,3000,SerTmout,[dec2 hh,dec2 mm, dec2 ss]
' set NIXIE tube positions for their
' respective h h m m, d4,d3,d2,d1
d4=hh/10
d3=hh//10
d2=mm/10
d1=mm//10
s1=ss/10 ' s0 & s1 only gets used when displaying seconds
s0=ss//10 ' untill time retreval from ESP module at 30 sec
Return
Enable Interrupt
'================================================= ============
' Read Temp Sensor and convert to deg F
'================================================= ============
disable interrupt
GetTemp:
PORT_PIN.0[tube] = 0 'Turn OFF the current tube
OWOUT DQ,%001,[$CC, $4E, 0, 0, DS18B20_9bit] 'set resolution of sensor
Start_Convert:
OWOUT DQ,%001,[$CC, $44] ' Skip ROM search & do temp conversion

Wait_Convert:
OWIN DQ,%100,[Busy] ' Read busy-bit
IF Busy = 0 THEN Wait_Convert ' Still busy..?, Wait_Convert..!
OWOUT DQ,%001,[$CC, $BE] ' Skip ROM search & read scratchpad memory
OWIN DQ,%010,[Raw.byte0, Raw.byte1]' Read two bytes / end comms

'-------------- Convert_Temp: -----------------------
Sign="+"
IF Cold_Bit = 1 THEN 'it's below zero Celsius
C=(ABS Raw>>4)*-10 'so shift the ABS value right and mult X -10
ELSE
C=(Raw>>4)*10 'else shift value right and mult X 10
ENDIF

@ CtoF _C, _F ; Convert Celsius to Fahrenheit
'converted value will be X 10, ie. 756=75.6 deg F
'so devide by 10 to get whole degrees
IF f.15=1 THEN Sign="-" 'if converted value is below zero F then sign is "-"
TempF = (ABS f)/10 'take tha ABS value and /10
IF f//10 >4 THEN TempF=TempF+1 'check remainder, if >4 then round up
PIR1.0 = 0 ' clear timer1 overflow flag
return 'with TempF containing current temperature
enable interrupt

'===========================================
end

and here is the code that runs on the ESP8266-01 module


memclear
cls
timesetup(-7,0)
baudrate 9600
serialtimeout 2000
delay 1000
button "Exit " [Exit]
[Main]
timer 100 [PicSer]
wait
'
[PicSer]
serialflush
input picIN
picIN = mid(picIN,1,5)
if picIN == "Time?" then gosub [gettime]
wait
'
[gettime]
bla = time()
hh = mid(bla,12,2) 'hour
mm = mid(bla,15,2) 'min
ss = mid(bla,18,2) 'sec
'
picOUT = hh & mm
picOUT = picOUT & ss
serialprint picOUT
'
return
'
[Exit]
end

this has been fun and a real challenge
IF anyone would like to build one let me know and I'd be glad to help you out with parts procurement, etc for the little adapter board.

Heckler
- 13th March 2016, 16:41
My latest working version of the code is posted below.
It incorporates Darrell Taylor's Instant Interrupts modified by Tabsoft in this thread...
http://www.picbasic.co.uk/forum/showthread.php?t=19910

It incorporates a check for USA Daylight Saving Time

I currently have commented out the temperature sensor code as I have not decided how/or if I am going to implement a temperature display.

enjoy
dwight


'************************************************* ***************
'* Name : Nixie_DST_InstantInt.BAS *
'* Author : [Dwight Merkley, N7KBC] *
'* Notice : Copyright (c) 2016 *
'* : All Rights Reserved *
'* Date : 3/10/2016 *
'* Version : 1.0 *
'* Notes : 16F1828 *
'* : *
'************************************************* ***************
#CONFIG
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_25 & _LVP_OFF
#endconfig


;-- Copied from DT_INTS-14 as per instruction in DT_INTS-14 -------------
;-- The compiler will tell you which lines to un-comment --
;-- Do Not un-comment these lines --
;---------------------------------------------------------------------------
;wsave VAR BYTE $20 SYSTEM ' location for W if in bank0
wsave VAR BYTE $70 SYSTEM ' alternate save location for W
' if using $70, comment wsave1-3

' --- IF any of these three lines cause an error ?? ------------------------
' Comment them out to fix the problem ----
' -- Which variables are needed, depends on the Chip you are using --
;wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
;wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
;wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3
' --------------------------------------------------------------------------


define OSC 8
OSCCON = %01110000 'set internal osc to 8 mhz
include "ALLDIGITAL.Pbp"
include "DT_INTS-14.bas" 'Needs to be in same PBP folder as PBPW.EXE
include "ReEnterPBP.bas" 'Needs to be in same PBP folder as PBPW.EXE
include "ElapTimer_5ms_Interrupt.pbp" 'Needs to be in same PBP folder as PBPW.EXE
'================================================= =

H10 VAR PortC.0 'hours tens digit enable
H1 var PortC.1 'hours ones digit enable
M10 var PortC.2 'minutes tens digit enable
M1 var PortC.3 'minutes ones digit enable
symbol PORT_PIN = PORTC 'used to sequentially enable portC.0-3 nixie tubes

res var PortC.4 '0-9 digit reset
clk var PortC.6 '0-9 digit counter input
ena var PortC.7 'ENA on nixie decade counter

led var LATC.5 'pwm led backlight
sw1 var portA.2 'input upper switch
sw2 var portA.1 'input lower corner switch
swflg1 var bit 'bit used to debounce switch pushes
swflg2 var bit 'bit used to debounce switch pushes

ts var portB.4 'OneWire Temperature sensor
rxE var portB.5 'input rx data from esp8266
txE var portB.7 'tx data to esp8266
fet var portB.6 'High Voltage shutdown

tube var byte 'refrence tube 0-3 [hh h mm m]
'hh var byte 'variable holding hours
h12 var byte
'mm var byte 'variable holding minutes
'ss var byte 'variable holding seconds
d1 var byte
d2 var byte
d3 var byte
d4 var byte
s1 var byte
s0 var byte

dow var byte 'sun = 0, sat = 6
mth var byte 'Jan = 01 ... Dec = 12
date var byte 'numerical day of month
dst var bit

mode var byte '12 to 24 hour conversion flag'
num var byte 'current digit's pulse count
x var byte 'general purpose variable
y var byte 'counter to track time between esp serial request output
dgt var byte
temp var byte 'temporary lcd display data
IntCnt var word
IntFlag var bit
dispflag var bit 'flag to indicate if display should be off
temptime var byte 'var to determine if time to check temperature

'the following var's are used in the anti-cathode poisoning routine
posx var byte
numx var byte
cath var byte
index var byte
CatCnt var word
CC var bit
'-------------[variables and constants for temperature routine]--------------
''DS18B20_9bit CON %00011111 ' set resolution on DS18B20 93.75ms, 0.5 C
''DQ VAR PortB.4 ' One-wire Data-Pin "DQ" on PortB.4
''Busy VAR BIT ' Busy Status-Bit
''Raw VAR WORD ' RAW Temperature readings
''TempF VAR WORD ' Temp in deg F
''Cold_Bit VAR Raw.BIT11 ' Sign-Bit for +/- Temp. 1 = Below 0 deg C
''Sign VAR BYTE[1] ' +/- sign for temp display
''TempH var word ' var for highest temp
''TempL var word ' var for lowest temp
''SignH var byte[1]
''SignL var byte[1]
''C VAR WORD ' Celsius
''F VAR WORD ' Fahrenheit

''INCLUDE "Temp_Convert.pbp"
'================================================= ==
TRISA = %00000110
TRISB = %00100000
TRISC = %00000000
WPUA = %00000110
'================================================= ===
espbaud con 84
Hours = 99
Minutes = 00
Seconds = 00
mode = 2 'modes
'0=24 hour only display
'1=12 hour only display
'2=24 hour with alternating 12 hour
' for dummies who don't know 24 hour time
swflg1=0 'flag used to debounce sw1 press
swflg2=0 'flag used to debounce sw1 press
CC = 0
numx=0
IntCnt = 1
temp = 0

'================================================

' Define and Create the Instant Interrupt for Timer1
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm

INT_CREATE ; Creates the interrupt processor

INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
ENDASM

Gosub ResetTime ' Reset Time to 0d-00:00:00.000
Gosub StartTimer ' Start the Elapsed Timer
Hours = 99
txe=1 'high the serial output pin, needs to start high
pause 1000
']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
Main:
if swflg1 = 1 and sw1=1 then swflg1 = 0 '(sw debounce) clear swflg when switch released
if swflg1 = 0 and sw1=0 then 'sw1 button detected
swflg1 = 1
mode=mode+1
if mode = 3 then mode = 0
endif

if sw2=0 then gosub gettime 'sw2 button detected

'an interrupt is generated every .005 sec
'so clear the IntFlag and cycle to the next nixie tube
if MSecsChanged = 1 then
MSecsChanged = 0
catcnt = catcnt + 1
gosub Tubes
endif
iF SecondsChanged = 1 then
SecondsChanged = 0
gosub NextSec
endif
'this next routine fires every 15 minutes between 4 and 7 seconds
'it causes all digits in each nixie to be cycled to prevent
'cathode poisioning
if (Hours !=99 and Minutes//15=0) and (Seconds >4 and Seconds<11) then
cc=1
else
cc=0
endif
if catcnt>19 and cc=1 then gosub CatClean
if cc=0 then catcnt=0

'this next routine blanks the display between 2200 and 0600
if (Hours>21) or (Hours<6) then 'turn display off between 2200 and 0600
dispflag = 0
led=1 'turn off the LED backlight
else
dispflag = 1
endif

'this routine only runs on startup and waits for 30 sec
'then it goes and reads the time from the ESP module
if Hours = 99 then
d1=Seconds//10
d2=Seconds/10
d3=0
d4=0
dispflag = 1
if Seconds=40 then gosub GetTime
endif

'this routine sets the clock once a day at 0500
if Hours=5 and Minutes=0 and Seconds=0 then gosub GetTime

if dispflag =1 then toggle led 'for backlight brigtness at 50%
' can use O-Scope to determine Main loop timing
goto Main
'================================================= ============
' increment seconds and trickle down time
'================================================= ============
NextSec:
if cc=1 then SkipSec
gosub dstcalc
if Hours > 12 then
h12=Hours - 12
else
h12 = Hours
endif

d1=Minutes//10
d2=Minutes/10
d3=Hours//10
d4=Hours/10
s1=Seconds/10
s0=Seconds//10

if mode=1 then '12 hr only mode
d3=h12//10
d4=h12/10
endif

if mode = 2 and (s0=0 or s0=5) then '24 hr mode with
d3=h12//10 '12 hr overlay at 0 & 5 sec
d4=h12/10
endif
SkipSec:
Return
'=================================================
'--- Routine to cycle all digits on all tubes ---
'--- to prevent cathode poisoning (look it up) ---
'=================================================
CatClean:
catcnt=0
if Hours=99 then
d1=Minutes//10
d2=Minutes/10
goto SkipClean
endif
numx=numx + 1
if numx >9 then numx=0

for posx=0 to 3
index = numx + posx
lookup index,[1,6,2,7,5,0,4,9,8,3,1,6,2,7,5,0,4,9,8,3],cath
if posx = 0 then d1=cath
if posx = 1 then d2=cath
if posx = 2 then d3=cath
if posx = 3 then d4=cath
next posx
SkipClean:
return
'================================================= ============
' display next NIXIE digit
'================================================= ============
Tubes:
PORT_PIN.0[tube] = 0 'Turn OFF the current tube
if dispflag = 0 then Skipdisp

tube=tube + 1
if tube > 3 then tube = 0

Digit:
high res 'reset the decade counter
@ nop
low res 'release the reset

lookup2 tube,[d4,d3,d2,d1],num

for x = 1 to num 'pulse the clock for "num" counts
high clk
@ nop
low clk
next x
PORT_PIN.0[tube] = 1 'Turn ON the next tube

SkipDisp:
return
'================================================= ============
' Get TIME from ESP8266-01 NTP Time Server
'================================================= ============
SerTmout:
led=0
pause 200
led=1
pause 200
led=0
pause 200
led=1
pause 200
GetTime:
@ INT_DISABLE TMR1_INT ; Disable Timer 1 Interrupts
PORT_PIN.0[tube] = 0 'Turn OFF the current tube
' Wait for >,CR,LF from ESP module
serin2 rxe,espbaud,2000,SerTmout,[wait(">"),wait(13),wait(10)]
' ESP module expects "Time?" before it will give hhmmss
' to change this modify the ESP code
serout2 txe,espbaud,["Time?"]
serin2 rxe,espbaud,3000,SerTmout,_
[dec1 dow,wait("/"),dec2 mth,wait("/"),dec2 date,wait("/"),_
dec2 Hours,dec2 Minutes,dec2 Seconds]

gosub dstcalc 'check to see if DST is in effect
if dst=1 then Hours = Hours + 1
if Hours = 24 then Hours = 00

' set NIXIE tube positions for their
' respective h h m m, d4,d3,d2,d1
d4=Hours/10
d3=Hours//10
d2=Minutes/10
d1=Minutes//10
s1=Seconds/10 ' s0 & s1 only gets used when displaying seconds
s0=Seconds//10 ' untill time retreval from ESP module at 30 sec
@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts

Return
'================================================= ============
' Read Temp Sensor and convert to deg F
'================================================= ============
''GetTemp:
'' PORT_PIN.0[tube] = 0 'Turn OFF the current tube
'' OWOUT DQ,%001,[$CC, $4E, 0, 0, DS18B20_9bit] 'set resolution of sensor
''Start_Convert:
'' OWOUT DQ,%001,[$CC, $44] ' Skip ROM search & do temp conversion

''Wait_Convert:
'' OWIN DQ,%100,[Busy] ' Read busy-bit
'' IF Busy = 0 THEN Wait_Convert ' Still busy..?, Wait_Convert..!
'' OWOUT DQ,%001,[$CC, $BE] ' Skip ROM search & read scratchpad memory
'' OWIN DQ,%010,[Raw.byte0, Raw.byte1]' Read two bytes / end comms

'' '-------------- Convert_Temp: -----------------------
'' Sign="+"
'' IF Cold_Bit = 1 THEN 'it's below zero Celsius
'' C=(ABS Raw>>4)*-10 'so shift the ABS value right and mult X -10
'' ELSE
'' C=(Raw>>4)*10 'else shift value right and mult X 10
'' ENDIF

''@ CtoF _C, _F ; Convert Celsius to Fahrenheit
'' 'converted value will be X 10, ie. 756=75.6 deg F
'' 'so devide by 10 to get whole degrees
'' IF f.15=1 THEN Sign="-" 'if converted value is below zero F then sign is "-"
'' TempF = (ABS f)/10 'take tha ABS value and /10
'' IF f//10 >4 THEN TempF=TempF+1 'check remainder, if >4 then round up
'' PIR1.0 = 0 ' clear timer1 overflow flag
''return 'with TempF containing current temperature
'================================================
'--- DST Calc (dec1 dow,dec2 mth,dec2 date) ---
'================================================
dstcalc:
' if dayschanged = 1 then
' dayschanged = 0
' dow = dow+1
' if dow >7 then dow=0
' endif
dst = 1 'covers Apr, May, Jun, Jul, Aug, Sep, Oct
If mth=01 then dst = 0 'Jan
If mth=02 then dst = 0 'Feb
If mth=12 then dst = 0 'Dec

March:
if mth=03 then 'March
if date <8 then
dst=0
elseif (date>7 and date<15) and dow=1 and hours<2 then
dst=0
elseif (date=8 and dow>1) then
dst=0
elseif (date=9 and dow>2) then
dst=0
elseif (date=10 and dow>3) then
dst=0
elseif (date=11 and dow>4) then
dst=0
elseif (date=12 and dow>5) then
dst=0
elseif (date=13 and dow>6) then
dst=0
endif
endif

November:
if mth=11 then 'November
if date >7 then
dst=0
elseif (date <8 and dow=1) and hours>1 then
dst=0
elseif (date=2 and dow<3) then
dst=0
elseif (date=3 and dow<4) then
dst=0
elseif (date=4 and dow<5) then
dst=0
elseif (date=5 and dow<6) then
dst=0
elseif (date=6 and dow<7) then
dst=0
endif
endif

return

'===========================================
end


'================================================= ==========
'--- This is the code running on the ESP8266-01 module ---
'================================================= ==========
'''memclear
'''cls
'''timesetup(-7,0)
'''baudrate 9600
'''serialtimeout 2000
'''delay 1000
'''button "Exit" [Exit]
'''timer 100 [PicSer]
'''wait
''''
'''[PicSer]
'''serialflush
'''input picin
'''picin = mid(picin,1,5)
'''if picin == "Time?" then gosub [gettime]
'''wait
''''
'''[gettime]
'''bla = time()
'''dy = mid(bla,1,3) 'dow
'''mh = mid(bla,5,3) 'month
'''dd = mid(bla,9,2) 'date
'''hh = mid(bla,12,2) 'hour
'''mm = mid(bla,15,2) 'min
'''ss = mid(bla,18,2) 'sec
'''yr = mid(bla,21,4) 'year
''''
'''if dy == "Sun" then dow = "1/"
'''if dy == "Mon" then dow = "2/"
'''if dy == "Tue" then dow = "3/"
'''if dy == "Wed" then dow = "4/"
'''if dy == "Thu" then dow = "5/"
'''if dy == "Fri" then dow = "6/"
'''if dy == "Sat" then dow = "7/"
''''
'''if mh == "Jan" then mth = "01/"
'''if mh == "Feb" then mth = "02/"
'''if mh == "Mar" then mth = "03/"
'''if mh == "Apr" then mth = "04/"
'''if mh == "May" then mth = "05/"
'''if mh == "Jun" then mth = "06/"
'''if mh == "Jul" then mth = "07/"
'''if mh == "Aug" then mth = "08/"
'''if mh == "Sep" then mth = "09/"
'''if mh == "Oct" then mth = "10/"
'''if mh == "Nov" then mth = "11/"
'''if mh == "Dec" then mth = "12/"
''''
'''picout = dow & mth
'''picout = picout & dd
'''picout = picout & "/"
'''picout = picout & hh
'''picout = picout & mm
'''picout = picout & ss
''''
'''serialprintln picout
'''return
''''
'''[Exit]
'''end

Heckler
- 16th March 2016, 17:47
I forgot to mention that the new enhanced code that needs to be loaded on the ESP module is located at the bottom of the above posted PIC listing. It is commented out so it doesn't interfere with the PIC code.
This new ESP code provides more NTP time data to the PIC. It now sends day of week, month and day of month, along with the HH:MM:SS

The pic code used the date information to determine if daylight saving time needs to be in effect.

Due to drift in the internal osc in the 16f1828 you may want to check NTP time more than once a day.
It seems to drift about 2 minutes in 24 hours so checking the time 2-3 times a day (or even once an hour) would insure your clock is more accurate.

cheers
dwight

PS if you decide to build one of these please let me know before you order your boards from oshpark as I would be willing to upload a new board design that incorporates a couple of improvements. The boards work fine as is but I found that I overdesigned it to try and turn off the high voltage to blank the display and it is much easier to do that in software by just not turning on any digits.

Ioannis
- 16th March 2016, 20:39
Well done Dwight!

A very interesting project, combining old tech with the latest IoT.

Ioannis

Heckler
- 21st March 2016, 23:13
Thanks Ioannis!!

It really is a good looking clock and nice to look at sitting on the book shelf.
And the fact that it sets itself and I can modify the code to my hearts content is all the better.

My wife commented that she missed it while I was developing the code.
It really is, in my opinion, a good value for the $50 USD including the case.

Dave
- 1st January 2017, 15:28
Dwight, I took your DST segment from the PIC code and incorporated it into the ESP8266-01. I am running the version 3.0 ESPBASIC on the ESP8266 and it works flawlessly. I have incorporated it into my version of the Nixie Clock build. I made a few and gave the kits to 2 of my kids for Xmas. Attached are the pics and ESP code.

Heckler
- 5th January 2017, 04:50
That's awesome Dave!!

I am glad you could use the code. It was fun (mental challenge) to figure out how to determine DST.
Although I did notice that this past Nov my clock did not change to Std Time until the day after it should have (as I recall) I was busy at the time and did not (have not) investigated why. I still need to look into the code and see if I missed something by a day. It did get it right the next day so I did not get too concerned.

I chose to do all the DST calcs in my PIC code as I am much more familiar with PIC BASIC. But the espBASIC has come a long way since then. I am still running version 1.65 on my esp module so I'll have to update the code to be compatible with the newer 3.xx versions.

It is amazing how powerful the little esp-01 modules are!!

73
dwight
N7KBC

Art
- 7th January 2017, 10:20
Hi, Nice idea to get rid of the chip that you don’t want and replace with your own board :)
If the ESP module getting the time, then the DT elapsed timer is really just cycling through the tubes?

On EEVblog, a YouTube channel if you watch it, Dave is in the middle of a nixie project now I’ve been watching.

Heckler
- 12th March 2017, 18:27
Hi Dave,

go check out the thread over on espbasic... http://www.esp8266.com/viewtopic.php?f=41&t=11518

and check out his code... he does a better job (simpler code) of determining DST yes/no for the ESP8266
Note: the following bit of code is not PICBASIC it's espBASIC


[calculate_DST]
dow = time("dow")
day = time("day")
month = time("month")
hour = time("hour")

if ((DST = 1) and (dow = "Sun") and (month = "Nov") and (day >= 1) and (day < 8)) then
DST = 0
write(DaylightSavings,str(DST))
endif

if ((DST = 0) and (dow = "Sun") and (month = "Mar") and (day >=8) and (day < 15)) then
DST = 1
write(DaylightSavings,str(DST))
endif

return

and to others... if you haven't checked out and played with mike's awesome espBASIC you are missing out :D

esp8266basic.com


regards
dwight

Heckler
- 13th March 2017, 00:52
Here is the webpage that his code creates for the analog meter clock...
8388

cheers
dwight

MrTeaTime
- 7th April 2020, 16:23
IF anyone would like to build one let me know and I'd be glad to help you out with parts procurement, etc for the little adapter board.

I know this is an old-ish thread, so being a little late to the game I'm hoping I can re-ignite the conversation here.

I came across this thread whilst searching for some way to automate the time setting of this clock. Great Job! This is a very interesting addition to this already really great Nixie clock.

Dwight, I'd be interested in the offer of support for helping to procure parts and the newer board design if that's still something you're willing to help with?

TIA
Dave

CuriousOne
- 8th April 2020, 05:45
I have complete Nixie clock project, written in Picbasic pro, you can find it on instructables "Mid century modern nixie clock". I've updated it to DS3231, added alarm and some other functions (updated code not yet uploaded to instructables), so if anyone can help with hooking ESP to it, I'd be very glad.

Heckler
- 15th April 2020, 19:19
Hi Curious One,

WOW! that clock on Instructables is an absolute work of art! I'm jealous.

So what do you need help with as far as connecting an ESP8266??

If you look at the beginning of this thread you will find the schematic and code for both the esp module and the PIC.
(Although today, I would highly recommend you use ANNEX RDS as the language for the esp module so you would need to change my espBASIC code.)
I'd be happy to help you with that code when you are ready.

It really is just as simple as setting up a serial comm channel between the PIC and the esp module.

I'd suggest, if you haven't already, that you join the ANNEX RDS group found here...
https://sites.google.com/site/annexwifi/home
where you will find a load of information on the ANNEX operating system. (it is very similar to the older espBASIC but much more advanced and development is very active)

how can I help?

dwight

Heckler
- 15th April 2020, 19:36
MrTeaTime,

Do you have the same nixie clock as shown in the original post in this thread?
If so then it is an easy conversion.

So the boards are available to order on OSHPARK here...
https://oshpark.com/shared_projects/7fvrYPyd

you would only need a few extra parts to complete the project.

what can I help you with?

dwight

CuriousOne
- 16th April 2020, 07:58
Thanks for reply.

There issues are as follows - I'm not a stellar in programing, all what I know is 80s style BASIC and unfortunately have no time or type of mind to learn C++ or some other things. Regarding the ESPbasic, I downloaded it, but was not able to run even a line of code, because it does nothing in browser.

Regarding hooking the ESP to picbasic, in my clock code I have routine getting time from DS3231. So if anyone can help with same routine but for ESP, that would be cool. Also, by my understanding, ESP is not just plug and go type thing. I mean, if I even add it to my code, say I gave complete clock to friend, he'll need to connect to ESP wifi, to make it work with his access point, manually assign NNTP server and so on. Right? From my point of understanding, GPS or DCF77 looks maybe more complicated, but much more straightforward and easy to use.

Ioannis
- 16th April 2020, 09:35
Well, GPS needs clear sky and DCF77 is not available everywhere. I am in Greece and do not receive it or at least not all hours of a day. Maybe if I relocate to a more open area with big antenna... That is not practical...

I am very interested in ways to use ESP to PBP projects. Have never used that little modules and am a bit afraid to touch them without a step-by-step tutorial. Especially on uploading new firmware and connecting to router and internet.

Ioannis

richard
- 16th April 2020, 12:22
I am very interested in ways to use ESP to PBP projects.

get a few wemos d1 minis, a copy of arduino ide
start here
https://tttapa.github.io/ESP8266/Chap01%20-%20ESP8266.html

you may never use a pic again

Ioannis
- 16th April 2020, 13:00
Incredible link Richard! Thanks a ton for that link. Exactly what a beginner needs.

Currently I have a couple of the attached modules. Are these any good for experimenting?

88368837

Ioannis

richard
- 16th April 2020, 13:36
yes , the software is the same for any of them ,inc esp8285
you just need to chk the pinouts

Ioannis
- 16th April 2020, 13:43
Nice. Have homework to do...!

Thanks again,
Ioannis

richard
- 16th April 2020, 13:52
once you go nuts putting web interfaces on your projects you look at a lcd or a tft screen and

say why bother with that limited old junk, all this on one nodemu 12f

8838 8839
8840

Ioannis
- 16th April 2020, 14:00
It is my wish but don't feel very confident right now...

Exciting on your images you posted! I want it!

Ioannis

richard
- 16th April 2020, 14:07
the link i posted got me to this point along with google
i'm no html expert and my code probably tortures things but who cares it works.

MrTeaTime
- 16th April 2020, 14:59
MrTeaTime,

Do you have the same nixie clock as shown in the original post in this thread?
If so then it is an easy conversion.

So the boards are available to order on OSHPARK here...
https://oshpark.com/shared_projects/7fvrYPyd

you would only need a few extra parts to complete the project.

what can I help you with?

dwight

Thanks for the response and the link to the board.

Just to give you the background, I'm completely new to this, so please forgive the very newbie questions that are bound to come.

I got the clock from RobG pre-assembled when I was last over in the states about 1.5 years ago, and would certainly class myself as a novice at electronics and I've never touched anything related to espbasic. Saying that, I do come from a software background so am more than happy to give this mod a go :)

Having done some research on programming PIC devices, I've been looking at PICKit which I think I'll need to get the chip flashed? In terms of the other components that are required to complete the build, I'd really appreciate if you could list out what they are? I know you included you schematic digram in the original posts, but like I said, I'm very new to this so would appreicate the basics.

Also, in regards to the wifi chip (ESP01), was there anything that needed to be done to that? I see they come prebuilt, but do they just work?

Looking forward to getting my head into this some more!

Thanks in advance

CuriousOne
- 18th April 2020, 08:12
All that is of course somehow good, but not exactly what is needed for PIC Nixie clock. It's like someone was asking about how to use transistor, but he'd being taught first what is Epitaxy, Czochralski method or Gallium nitride doping. We don't need that.

All what we need for clock is something like this:

1. flash this firmware.hex into ESP
2. Connect it's pin #4 (or whatever), to your PIC port X
3. Use SERIN X,Y,Z statement to get the current time


That's all.

Ioannis
- 18th April 2020, 12:28
I am afraid it is not that simple. You have to write that firmware.hex and then upload it to the ESP.

In what IDE you will do this? In Arduino C or Annex Basic?

If it is going to be #4 or #7 it is up to you. I mean what you did in the previous step.

The serin is the easy part...

Ioannis

richard
- 18th April 2020, 13:37
if you need an esp8266 time server
https://forum.arduino.cc/index.php?topic=631472.msg4276004#msg4276004

could not get much easier , dst timezone the lot. with serial output in various formats
with explanations

tz explained here

https://github.com/G6EJD/ESP32-Time-Services-and-SETENV-variable/blob/master/README.md

CuriousOne
- 19th April 2020, 06:33
Yes, need firmware which just delivers time.

Heckler
- 20th April 2020, 03:33
Hi CuriousOne,
So to help you get a simple time server up and running on an ESP8266 I have a few questions...

What are your size constraints?
Do you have 3.3v available or just 5v?
If you would be willing to use a larger module like one of these...
https://www.aliexpress.com/wholesale?catId=0&initiative_id=AS_20200419181546&SearchText=lolin+esp8266.

my favorite is this one...
https://www.aliexpress.com/item/32724692514.html?spm=a2g0o.productlist.0.0.204c5f8 6qPb50y&algo_pvid=55e23e6b-e4e1-450c-89a9-0ed1bc19f675&algo_expid=55e23e6b-e4e1-450c-89a9-0ed1bc19f675-2&btsid=0ab6fa7b15873489553786130e517b&ws_ab_test=searchweb0_0,searchweb201602_,searchweb 201603_

But it really does not matter too much which module you choose.

You also note that you have experience with old school BASIC.
I will tell you it is trivial to flash ANNEX RDS onto one of these modules and then code development is drop dead simple.
The IDE (Integrated Development Environment) is hosted right on the module.
You only need a micro USB cable to flash ANNEX and then you simply log onto the webpage of the module and you are in the IDE.

If you get this far I'd be happy to help you get the few (and I do mean few like <20) lines of code up and running.
Annex makes it very easy to set your time zone and it handles DST/ST for you.
You would be able to have the module send you serial time out to one of the pins and have your PIC recieve that time.

It really is that simple!

Now there are certainly other ways of doing this (like the arduino environment and C-like code) but this Annex is amazing and very easy!
Oh yeah... and it is very similar to PIC basic and old school basic from the 80's
But do not think for a moment it is not powerful.

It is actively developed and very powerful.

So do you have any ESP8266 modules on hand??

If you need the small size of the ESP-01 module then it is just a bit more complex.
Where the other modules have an onboard USB serial channel for flashing, the ESP-01 does not.
Therefore you would need an USB-serial cable to flash Annex (or any other OS like Arduino).
Also the ESP-01 does not have an 5v to 3.3 regulator so you have to feed it with 3.3.
So if you have a bit more room the larger modules are the way to go.

Let me know what you have or need.
Join the discussion over on the ANNEX RDS home page and forum.

Dwight

Heckler
- 20th April 2020, 03:43
To anyone who wants to try ANNEX there are several tutorials over on the home page here...
https://sites.google.com/site/annexwifi/home

Id be more than happy to get on a SKYPE to help you get familiar with how to flash annex or understand the features of the IDE.
Just drop me a direct message through the forum.

dwight

CuriousOne
- 20th April 2020, 19:55
For the ESP, I bought them all - big, small, nodemcu or whatever are available.
I even flashed some wifi clock project, but using LED matrix displays and it works fine, but that does not helps me.
I can get 3.3 or 5 volt or whatever is needed, that is not a problem.