Post about your Basic project here

Moderator: Mmiscool

User avatar
By viscomjim
#37113 Image

Just to get a better handle on the I2C thing, I put together a little digital clock using this display...

https://www.adafruit.com/products/1268

I am using a ESP-01 so this project can be very small.

My I2C struggle is documented here...

viewtopic.php?f=45&t=7115

and I learned that a logic analyzer is invaluable when playing with this stuff.

I am sure this code could be better, but it works for now. I will update it as I progress, like getting the colon to flash and am/pm indicator, etc. As you can see, the time is checked every 5 seconds and the display is updated. More to come...

Code: Select allmemclear
cls
'initialize display
address = 112 
i2c.begin(address)
i2c.write(33)
i2c.end()
i2c.begin(address)   
i2c.write(129)
i2c.end()
i2c.begin(address) 
i2c.write(239) 
i2c.end()
delay 10

timesetup(-5,0)
delay 750

timer 5000 [refresh]


wait

[refresh]
cls
button "Exit " [Exit]
print time()
disp = time()
z = mid(disp,13,1) 'hour ones
gosub [conv]
b = x

z = mid(disp,12,1) 'hour tens
gosub [conv]
a = x

z = mid(disp,16,1) 'minutes ones
gosub [conv]
d = x

z = mid(disp,15,1) 'minutes tens
gosub [conv]
c = x

gosub [wdisp]

wait

[wdisp]
i2c.begin(address)
i2c.write(0)
i2c.write(a)
i2c.end()
delay 10
i2c.begin(address) 
i2c.write(2)
i2c.write(b)
i2c.end()
delay 10
i2c.begin(address) 
i2c.write(6)
i2c.write(c)
i2c.end()
delay 10
i2c.begin(address) 
i2c.write(8)
i2c.write(d)
i2c.end()
return

[Exit]
timer 0
wprint "<a href='/'>Menu</a>"
end

[conv]
if z = 0 then x = 63
if z = 1 then x = 6
if z = 2 then x = 91
if z = 3 then x = 79
if z = 4 then x = 102
if z = 5 then x = 109
if z = 6 then x = 125
if z = 7 then x = 7
if z = 8 then x = 127
if z = 9 then x = 111 
return
User avatar
By forlotto
#37134 Hrmmm... No way! Now this is cool.

Sweet job man love it now you just need a poject box of some sort to throw it all in and a bezel.

I'd say you pretty much nailed it .

Any further plans like adding an alarm etc....?

Any issues with keeping time that are observed thus far as far as accuracy goes?

THANK YOU FOR SHARING EXCELLENT CHRISTMAS PRESENT!
User avatar
By viscomjim
#37137 Hi, thanks for the kind words. I do plan a few different things for this later, like you said, add an alarm, maybe have it email me something, who knows, this was just to wrap my head around the I2C issues I was having.

As far as the accuracy, it checks the time using the function that Mike provided, so as far as I know, it gets the time from the www, so it should be accurate to about the five seconds I use for the refresh.