![]() |
Forum Index : Microcontroller and PC projects : Not another Clock!
Author | Message | ||||
MikeO Senior Member ![]() Joined: 11/09/2011 Location: AustraliaPosts: 275 |
Well yes but with a few differences. Its an adaptation of Geoff's excellent backpack uMite 170 but with a couple of differences, it has a ESP8266 on board it uses a SOIC version of the MCU but lastly the board was cut by CNC! (Useful when you don't want 10 prototypes) The Clock is synced from the Internet by NCP and it fetches your local weather from OpenWeatherMap.org The project was really just to test out the board but it could be useful! Some Photos Cheers Mike Codenquilts |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2934 |
Hi Mike, That looks like it was fun to build ![]() Will you be willing to share the code for others to learn from? And out of interest - are you using the 2.4 or 2.8 there? Brilliant job ![]() |
||||
MikeO Senior Member ![]() Joined: 11/09/2011 Location: AustraliaPosts: 275 |
Hi WW, the display used was the 2.4 Here is the Micromite and ESP8266 code. If anyone is into PCBs by CNC I can post the NC files. 'http://www.codenquilts.com.au
'Michael Ogden March 2016 'uM Wifi Clock Weather 'Code Portions Geoff Graham Option Explicit Option Default Integer Option autorun On 'Constants 'Define I/O 'Global variables Dim string IDPdata(100) length 50 Dim Secs,r dim esp$,buff$,lastwind$ dim Queue$(20) length 80 'transmit queue to ESP8266 'intialise modules 'Initialise Arrays idpdata(0)="uM Wifi Clock ver 1.1" 'software version number idpdata(48)="no weather conditions to display" idpdata(49)="Town" idpdata(51)="Min" idpdata(52)="Max" 'time array values idpdata(01)=left$(time$,2) idpdata(02)=mid$(time$,4,2) idpdata(03)=mid$(time$,7,2) idpdata(6)="NTP Date" 'init ESP8266 communications Open "com2:9600,1024" As #2 'initialise commS 'interupts Settick 1000 ,T1,1 'establish seconds "Tick Timer" ' now draw the display CLS 'GUI Interrupt TouchDown, TouchUp text 80,0,idpdata$(6),,1,2,rgb(green) box 0,30, mm.hres-1,60,3,rgb(red), rgb(blue) weatherupdate 'queue initial requests r=espQueue("time:") 'try to get NTP time data r=espQueue("owm:") 'get weather data '*** start main program loop Do 'StartTime = Timer Watchdog 8000 esp$=Input$(1,#2) Print esp$; 'data from ESP8266 buff$=buff$+esp$ if esp$=chr$(10) or esp$=chr$(62) or esp$=chr$(125) then if esp$=chr$(10) then 'terminator is line feed if instr(buff$,"NTP:") then idpdata(6)= mid$(buff$,5,10) + " " + right$(buff$,5) text 80,0,idpdata$(6),,1,2,rgb(green) time$=parseb$(buff$,4," ") 'set the clock from NTP endif elseif esp$=chr$(62) then 'terminator is > if instr(buff$,"getdata:>") then 'print "Queue items:";r SendEsp 'send next item in the queue, success is in r endif ' else 'terminator is } 'json 'print buff$ parseJson endif buff$="" 'clear string endif 'Print "Loop elapsed time"; Timer-StartTime Loop '***** End main program loop End '**************** sub routines ********************* 'T1 - 1second Tick interrupt 'set up some time flags Sub T1 secs=secs+1 'update seconds timer text mm.hres/2,60,time$,cm,1,4,rgb(cyan),rgb(blue) 'if touch(x)<>-1 then end if secs mod 15 =0 then 'every 15 secs weatherupdate endif if secs mod 30 =0 then 'every 15 secs r=espQueue("owm:") 'try to get weather data endif if secs mod 60 =0 then 'every 60 secs endif if secs mod 1800 =0 then 'every 30 minutes endif if secs mod 43200 =0 then 'every 12 hours r=espQueue("time:") 'try to get NTP time data endif if secs => 86400 then '24 hrs reached secs = 0 'reset counter endif End Sub sub WeatherUpdate text 0,95,idpdata(49) + " Forecast",,1,2,rgb(green) text 0,125,"Weather:",,1,1,rgb(white) text 80,125,left$(idpdata(48)+space$(30),30),,1,1,rgb(white) text 0,145,"Temp Deg C",,1,1,rgb(white) text 95,145,idpdata(51) + " to " + idpdata(52),,1,1,rgb(white) text 0,165,"Curr Temp: " + idpdata(34) + " 'C",,1,2,rgb(green) text 0,195,"Wind: " + idpdata(38) + " at "+ idpdata(37) + " km/h " text 0,215,"Pressure: "+ idpdata(36) + "hPa Humidity "+ idpdata(35) + "% " end sub sub parseJson local temp! 'print buff$ if instr(buff$,"temp") then temp!=val(jsonValue$(buff$,"temp",6)) idpdata(34)= str$(temp!,0,1) endif if instr(buff$,"temp_min") then temp!=val(jsonValue$(buff$,"temp_min",10)) idpdata(51)= str$(temp!,0,1) 'print "OWM Temp Min";idpdata(51) endif if instr(buff$,"temp_max") then temp!=val(jsonValue$(buff$,"temp_max",10,chr$(125))) idpdata(52)= str$(temp!,0,1) 'print "OWM Temp Max";idpdata(52) endif if instr(buff$,"humidity") then idpdata(35)= jsonValue$(buff$,"humidity",10) endif if instr(buff$,"pressure") then idpdata(36)=jsonValue$(buff$,"pressure",10) endif if instr(buff$,"speed") then temp!=val(jsonValue$(buff$,"speed",7))*3.6 idpdata(37)=str$(temp!,0,1) endif if instr(buff$,"deg") then temp!=val(jsonValue$(buff$,"deg",5,chr$(125))) idpdata(38)=wheading$(temp!) print "OWM Wind direction";idpdata(38) endif if instr(buff$,"description") then idpdata(48)=jsonValue$(buff$,"description",14,chr$(34)) ' print "OWM Rain";idpdata(48) endif if instr(buff$,"name") then idpdata(49)=jsonValue$(buff$,"name",7,chr$(34)) ' print "OWM City Name";idpdata(49) endif if instr(buff$,"icon") then idpdata(50)= jsonValue$(buff$,"icon",7,chr$(34)) + ".bmp" endif end sub function jsonValue$(json$,jsonParam$,b,d$) local a,c 'print "json$:";json$ 'print "jsonparam$:";jsonparam$ 'print b if d$="" then d$="," 'locate parameter a=instr(json$,jsonparam$) 'print "A is:";a if a>0 then 'retrieve value c=instr(a+b,json$,d$) if c>0 then jsonvalue$=mid$(json$,a+b,c-(a+b)) endif endif end function function espQueue(store$) local e espqueue=0 for e=1 to 20 if queue$(e)="" then queue$(e)=store$ espqueue=e exit for endif next e 'if the store failed then espQueue will be 0 end function sub SendESP local e 'send from top of queue if its not empty if queue$(1)<>"" then print #2,queue$(1) print queue$(1) endif 'move up items is queue for e=2 to 20 queue$(e-1)=queue$(e) next e queue$(20)="" 'make the last item empty end sub sub SendESPNow(strout$) 'send immediately to ESP8266) print #2,strout$ print queue$(1) end sub 'Wind Direction data process Function wHeading$(adc!) select case adc! case 101.25 to 123.75 wHeading$ = "ESE" case 56.25 to 78.75 wHeading$ = "ENE" case 78.75 to 101.25 wHeading$ = "E" case 146.25 to 168.75 wHeading$ = "SSE" case 123.75 to 146.25 wHeading$ = "SE" case 168.75 to 191.25 wHeading$ = "S" case 10 to 33.75 wHeading$ = "NNE" case 33.75 to 56.25 wHeading$ = "NE" case 191.25 to 213.75 wHeading$ = "SSW" case 213.75 to 236.25 wHeading$ = "SW" case 326.25 to 348.75 wHeading$ = "NNW" case 348.75 to 10 wHeading$ = "N" case 281.25 to 303.75 wHeading$ = "WNW" case 303.75 to 326.25 wHeading$ = "NW" case 258.75 to 281.25 wHeading$ = "W" case else wHeading$=lastwind$ end select lastwind$=wHeading$ End Function '********************* Library Code ************************** Function Parse$(s$,FieldNumber,d$) Local String stringArg$ Local Integer intOldY,intY,intX if d$="" then d$="," endif StringArg$ = S$ + d$ intOldY = 1:intX=0:intY=0 Parse$ = "" do While intY < Len(StringArg$) And intX < FieldNumber intY = Instr(intOldY, StringArg$, d$) intX = intX + 1 If intX = FieldNumber Then parse$ = Mid$(StringArg$, intOldY, intY - intOldY) Endif intOldY = intY + 1 loop 'print s$; intx; inty; intoldy End Function Function Parseb$(sb$,FieldNumberb,db$) Local String stringArgb$ Local Integer intOldYb,intYb,intXb if db$="" then db$="," endif StringArgb$ = Sb$ + db$ intOldYb = 1:intXb=0:intYb=0 Parseb$ = "" do While intYb < Len(StringArgb$) And intXb < FieldNumberb intYb = Instr(intOldYb, StringArgb$, db$) intXb = intXb + 1 If intXb = FieldNumberb Then parseb$ = Mid$(StringArgb$, intOldYb, intYb - intOldYb) Endif intOldYb = intYb + 1 loop End Function Function Ltrim(sString As String)As String ltrim=Str$(Val(sString)) End Function ESP8266 Basic code memclear
serialprintln "" serialprintln "Esp8266-Mcu Initialising......" ver$ = "ESP8266-Mcu 1.3" 'connect "SSID" "yr Password" "Yr Local IP" "Yr Gateway IP" "255.255.255.0" prompt$ = "getdata:" serialflush serialtimeout 2000 timesetup(11,0) 'setupemail "mail.smtp2go.com" 2525 "Youremail" "yourpassword" f1 = 23.3 f2 = 78 f3 = 10 f4 = 1008 f5 = 23.3 f6 = 78 f7 = 12.6 f8 = 18.6 f9 = 120 f10 = 90 f11 = "0" f12 = "0" f13 = "0" f14 = "0" f15 = "0" 'default town and parameters for OWMap 'owmparam = "&units=metric&mode=json&appid=yourAPI" owmtown = "Melbourne,AU" & owmparam 'Yr WEB Page here cls wprint "<br>" wprint "<br>" button "Exit" [quit] timer 1000 [update] wait [update] 'goto [exitupdate] input prompt$ str$ 'serialprintln "length of Input:" 'serialprintln len(str$) if len(str$) = 0 then goto [exitupdate] if instr(str$,"sync:") > 0 then goto [parsedata] gosub [parse] cmd = field$ goto [command] [parsedata] gosub [parse] sstatus = field$ gosub [parse] f1 = field$ gosub [parse] f2 = field$ gosub [parse] f3 = field$ gosub [parse] f4 = field$ gosub [parse] f5 = field$ gosub [parse] f6 = field$ gosub [parse] f7 = field$ gosub [parse] f8 = field$ gosub [parse] f9 = field$ gosub [parse] f10 = field$ gosub [parse] f11 = field$ gosub [parse] f12 = field$ goto [exitupdate] [command] if cmd == "time" then gosub [gettime] if cmd == "email" then gosub [sendemail] if cmd == "info" then gosub [getinfo] if cmd == "quit" then goto [quit] if cmd == "reboot" then reboot if cmd == "net" then gosub [setnet] if cmd == "ts" then gosub [thingspeak] if cmd == "owm" then gosub [weather] if cmd == "town" then gosub [changetown] [exitupdate] wait [thingspeak] input "gettsdata:" str$ gosub [parse] sstatus = field$ gosub [parse] ts.key$ = field$ gosub [parse] ts.fieldnum$ = field$ gosub [parse] ts.fielddata$ = field$ sendts(ts.key$,ts.fieldnum$,ts.fielddata$) return [setnet] input "getnetwork:" str$ gosub [parse] sstatus = field$ gosub [parse] net.name$ = field$ gosub [parse] net.password$ = field$ gosub [parse] net.ip$ = field$ gosub [parse] net.gateway$ = field$ gosub [parse] net.mask$ = field$ if net.ip$ == "" then [auto] else [static] [static] connect net.name$ net.password$ net.ip$ net.gateway$ net.mask$ goto [exitsetnet] [auto] connect net.name$ net.password$ [exitsetnet] gosub [getinfo] return [sendemail] input "getemail:" str$ gosub [parse] sstatus = field$ gosub [parse] address$ = field$ gosub [parse] reply$ = field$ gosub [parse] subject$ = field$ gosub [parse] body$ = field$ email address$ reply$ subject$ body$ return [getinfo] serialprintln "" serialprint "Version:" serialprintln ver$ serialprint "IP:" serialprintln ip() read "WIFIname" blaWIFIssid serialprint "SSID:" serialprintln blaWIFIssid serialprint "FlashFree:" serialprintln flashfree() serialprint "RamFree:" serialprintln ramfree() return [gettime] ntp$ = time() ntp$ = "NTP:" & ntp$ serialprintln ntp$ return [parse] field$ = "" delim = instr(str$,":") field = delim - 1 rest = len(str$) - delim field$ = left(str$,field) str$ = right(str$,rest) 'serialprintln "Parse" 'serialprintln field$ 'serialprintln str$ 'serialprintln return [changetown] input "gettown:" str$ gosub [parse] owmtown = field$ & owmparam return [weather] owmbla = "api.openweathermap.org/data/2.5/weather?q=" & owmtown serialprint wget(owmbla) return [quit] timer 0 wprint "<a href='/'>Menu</a>" end Codenquilts |
||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
Hey Mike O, Very nice project, and THANKS for posting your code!!! I don't know if you saw this, but the esp8266 basic port now has json parsing that works very easily like this... query = "api.openweathermap.org/data/2.5/weather q=London,uk&lang=en&units=metric&appid=YOUR_APP_ID" let ret = wget(query) let desc = json(ret,"weather.description") let temp = json(ret,"main.temp") let press = json(ret,"main.pressure") let humid = json(ret,"main.humidity") let tim = json(ret,"dt") let tim = unixtime(tim) A cool little examples can be found HERE. I really like the CNC pcb. What CNC and bit did you use to do that? |
||||
HankR Senior Member ![]() Joined: 02/01/2015 Location: United StatesPosts: 209 |
Mike, Would like to see a picture or two of your CNC rig if possible. Have you used it to machine panels or enclosures or similar light weight project parts, or is it made specifically for just PCB milling? |
||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
Now we just have to figure out how to make cool little icons like these... ![]() Maybe using the font editor tool from TassyJim and make a special "font" with icons. Putting two or three characters together to form a cool icon... Thinking out loud (thats dangerous...) |
||||
MikeO Senior Member ![]() Joined: 11/09/2011 Location: AustraliaPosts: 275 |
Hi Jim, Yes I had noticed just recently something about Json on the ESPbasic site but I didn't go into it, I probably should! I have to say I find the ESPbasic site mighty frustrating to read and the documentation is woeful but non the less I should spend some time and get up to date again. CNC, Its a Carving 6040, I used a 20degree V cutter. Codenquilts |
||||
MikeO Senior Member ![]() Joined: 11/09/2011 Location: AustraliaPosts: 275 |
HankR, yes I do use it to make enclosures and front panels particularly as well as PCBs. The enclosure in my project was made on the CNC. Codenquilts |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2934 |
@Mike Slightly off topic - but concerns your CNC & enclosure. Would a CNC machine be ok to cut holes (round and square) in an ABS enclosure without it 'melting' the plastic. I am after very clean cuts in various ABS enclosures that vary between 1mm and 3mm in thickness. I assume that rotation speed of the bit has to be set correctly, but wanted to understand if ABS is a 'workable' material to give a 'pro looking' finish from a CNC. I think your enclosure was acrylic from memory (maybe wrong there though) - but with acrylic I use a Laser cutter to give perfect results. However, the CO2 laser does not work with ABS and hence this post. Apologies for being off topic -- butyou have mentioned CNC here ![]() |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2934 |
Not dangerous at all! I have been making 'large' fonts for this very reason (some fonts as big as my screen resolution!!). No need to join several characters together, just set a picture/icon size and create a font with TassyJim's EXCELLENT font editor 'app'. This would be a fantastic addition to the next version of a MicroMite Clock ![]() And even better if Geoff/Jim allows for multi-coloured fonts ![]() ![]() ![]() ![]() If I get time I will create some 'clouds' symbols for us folk here in UK; and some sunny symbols for you guys on the opposite side of the planet ![]() WW |
||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
I guess its time to get TassyJims font editor. I did not know you could make "big" fonts. But, then why wouldn't it. Making icons sound like fun. So, basically, you create an icon and give it a character? Like a cloud would be "A" and the big sun would be "B" or something like that. And then you would just use the text command? |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6270 |
Correct. On my to do list, (but it's a long list), is the ability to turn any image into a font character. My insurance company is making slow progress but I should have a useable computer again soon. Then I can get back to work. Jim VK7JH MMedit |
||||
MikeO Senior Member ![]() Joined: 11/09/2011 Location: AustraliaPosts: 275 |
@WW No problems at all, the way i see it is that it may be of interest/help to anyone the makes their own projects which only furthers the use of Micromite etc. Yes the enclosure I constructed was Acrylic but I have done cutouts in ABS instrument enclosures. Most project boxes are ABS (injection mouldings) or some are Polystyrene. Yes you do have to use a suitable rotational speed and feed rate, also the tool used has to be appropriate but for thin cuts there should be few problems. It only usually melts if the tools heats up because the chips/swarf can't get away for various reasons. If you had something in mind in a small instrument case size for instance I don't mind getting one and giving it a go for you as a test. If you can give me some drawings or sketch I can make the cad drawing and then the gcode (NC) files for the machine. The biggest problems can be holding the workpiece particularly if its more than a one-off, needs a jig. Cheers Mike. Codenquilts |
||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
Maybe we should start a new topic, but while we are at it, I use a cnc router to machine abs boxes for projects. Using a nice upcut spiral carbide bit at 20,000 rpm makes the boxes cut like butter and extremely clean cuts to boot. Like Mike O says, holding the workpiece is the catch. When I have to do more that 5 or so, I build a jig that can screw down to the surface of the router table. This way every unit is placed the same and everything lines up perfectly. Here is an example of a jig used to machine some little abs cases... ![]() ![]() |
||||
HankR Senior Member ![]() Joined: 02/01/2015 Location: United StatesPosts: 209 |
So moved, starting now, to a new thread I've already started at "CNC machining for lightweight projects." See you there. Hank |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |