Enrico Casti
Published © Apache-2.0

Santa Claus phototrap

A fun project requested by my daughter, She wants to take a picture of Santa when he comes to bring presents.

BeginnerFull instructions provided372
Santa Claus phototrap

Things used in this project

Story

Read more

Custom parts and enclosures

Custom shell

Custom shell with Lego Pins, allow fixing the units on the M5stack

Code

UIFlow code

Scratch
{"components":[{"id":"____screen","createTime":1583843090864,"name":"screen","x":0,"y":0,"width":320,"height":240,"backgroundColor":"#222222","backgroundImage":"","type":"screen"},{"id":"____buttonA","createTime":1583843090864,"name":"ButtonA","buttonIndex":0,"x":35,"y":216,"width":64,"height":24,"text":"ButtonA","visibility":false,"type":"button"},{"id":"____buttonB","createTime":1583843090864,"name":"ButtonB","buttonIndex":1,"x":125,"y":216,"width":64,"height":24,"text":"ButtonB","visibility":false,"type":"button"},{"id":"____buttonC","createTime":1583843090864,"name":"ButtonC","buttonIndex":2,"x":215,"y":216,"width":64,"height":24,"text":"ButtonC","visibility":false,"type":"button"},{"id":"J20=ZW9ugWH-oCt4","createTime":1583843125843,"isCoreTwo":false,"isPaper":false,"name":"label0","x":181,"y":155,"color":"#FFFFFF","text":"Text","font":"lcd.FONT_DejaVu24","rotation":0,"type":"label","layer":4},{"id":"xifb!4cb7-!!lObM","createTime":1583843830090,"isCoreTwo":false,"isPaper":false,"name":"label1","x":181,"y":202,"color":"#FFFFFF","text":"Text","font":"lcd.FONT_Default","rotation":0,"type":"label","layer":5},{"id":"-=9PJMX_0I2VfRUA","createTime":1639763603217,"isCoreInk":false,"isPaper":false,"name":"PhotoTrap","x":0,"y":0,"width":320,"height":20,"color":"#FFFFFF","backgroundColor":"#0000FF","text":"Title","textOffset":3,"font":"lcd.FONT_Default","type":"title","layer":10,"radius":null},{"id":"MkehoGZS4gc=dReP","createTime":1639763665126,"isCoreTwo":false,"isPaper":false,"name":"Photo_Nr","x":6,"y":54,"color":"#FFFFFF","text":"Text","font":"lcd.FONT_Default","rotation":0,"type":"label","layer":11,"width":null,"height":null,"radius":null},{"id":"j3P3y@WFEQt!gnH+","createTime":1639763665126,"isCoreTwo":false,"isPaper":false,"name":"label3","x":146,"y":54,"color":"#FFFFFF","text":"Text","font":"lcd.FONT_Default","rotation":0,"type":"label","layer":12,"width":null,"height":null,"radius":null},{"id":"F$PkJlVPT!n*J$V-","createTime":1639778927853,"isCoreTwo":false,"isPaper":false,"name":"label2","x":0,"y":157,"color":"#FFFFFF","text":"Text","font":"lcd.FONT_UNICODE","rotation":0,"type":"label","layer":14,"width":null,"height":null,"radius":null},{"id":"DkaAdw4ua@AgT$xu","createTime":1639778988211,"isCoreTwo":false,"isPaper":false,"name":"label4","x":0,"y":202,"color":"#FFFFFF","text":"Text","font":"lcd.FONT_Default","rotation":0,"type":"label","layer":15,"width":null,"height":null,"radius":null}],"type":"core","versions":"Beta","units":[{"id":"9bGqmfASJxLTUldo","createTime":1639763260239,"type":"pir","name":"pir_0","port":"B","default":["A","B","C","E","Custom"],"user_port":["21","22"],"icon":"pir.png"}],"hats":[],"blockly":"<variables><variable id=\"R}fUm|{LQyjG?e9[~uA8\">np</variable><variable id=\"M^Rg!7*hzx:x?k+uW?nu\">timestamp</variable><variable id=\"h{j[zW|+d^w^BwqtBTu=\">name</variable></variables><block type=\"basic_on_setup\" id=\"setup_block\" deletable=\"false\" x=\"-2650\" y=\"-630\"><next><block type=\"variables_set\" id=\"A]LC)l[LAe/A6I$3@#qS\"><field name=\"VAR\" id=\"R}fUm|{LQyjG?e9[~uA8\">np</field><value name=\"VALUE\"><block type=\"math_number\" id=\"qj{bw`CxW-EiKgb$xKhd\"><field name=\"NUM\">0</field></block></value><next><block type=\"title_set_text\" id=\"~?UlH{X=K65Jj$F5/H~E\"><field name=\"COMPONENT\">PhotoTrap</field><value name=\"TEXT\"><shadow type=\"text\" id=\"mi6@lGn6bx@8JvMS@Hr1\"><field name=\"TEXT\">Santa Claus Phototrap</field></shadow></value><next><block type=\"label_set_text\" id=\"dD+Sy}_)%)C+Lb2CnUn#\"><field name=\"COMPONENT\">Photo_Nr</field><value name=\"TEXT\"><shadow type=\"text\" id=\",I)S]s%:y[ZYUO!SL.Uk\"><field name=\"TEXT\">Number of Photo</field></shadow></value><next><block type=\"label_set_text\" id=\"wwdG~-u%Yld-|FtI-Zm?\"><field name=\"COMPONENT\">label2</field><value name=\"TEXT\"><shadow type=\"text\" id=\"#!xY5S8(eu2,Iq2AWj(R\"><field name=\"TEXT\">Status</field></shadow></value><next><block type=\"label_set_text\" id=\"4wjd,jppPgn)S[ptGySm\"><field name=\"COMPONENT\">label4</field><value name=\"TEXT\"><shadow type=\"text\" id=\"%ecIfPh[0fbfNnzttBm_\"><field name=\"TEXT\">Last Image</field></shadow></value><next><block type=\"ntp_init\" id=\"Ho[$b{yq%IcR7{}wA5k_\"><value name=\"host\"><shadow type=\"text\" id=\"u*a{2}y;nBZN-}[Nf3vu\"><field name=\"TEXT\">europe.pool.ntp.org</field></shadow></value><value name=\"timezone\"><shadow type=\"math_number\" id=\"{PmiFzz^~q%3tN}/%zcY\"><field name=\"NUM\">-1</field></shadow></value><next><block type=\"timer_delay\" id=\"D}xe8F4}!gd=QzUs/*u}\"><value name=\"DELAY\"><shadow type=\"math_number\" id=\"QA=!+]}Dq|;qr,t#(,Ev\"><field name=\"NUM\">10</field></shadow></value><next><block type=\"variables_set\" id=\"_tb?wb}BA.#dAD?QTR9n\"><field name=\"VAR\" id=\"M^Rg!7*hzx:x?k+uW?nu\">timestamp</field><value name=\"VALUE\"><block type=\"convent_str\" id=\"k~vD9./{`_g4:DNrW~Qb\"><value name=\"VALUE\"><block type=\"ntp_get_timestamp\" id=\"cFwn{p;y*;s72[%Jgerf\"></block></value></block></value><next><block type=\"basic_on_loop\" id=\"U~`Vzm,n._*xRAn]w_8v\"><statement name=\"LOOP\"><block type=\"controls_if\" id=\"L%aLXd=7BKNrm!T]f9LL\"><value name=\"IF0\"><block type=\"pir_read\" id=\"OPBYpFq?OnB~wAUay-Ih\"><field name=\"VARNAME\">pir_0</field></block></value><statement name=\"DO0\"><block type=\"http_request\" id=\"Oc.g(sn0-yQY~-`[RqAG\"><field name=\"method\">GET</field><value name=\"url\"><shadow type=\"text\" id=\"I^Y9xk:{^r(q^jxH}|ki\"><field name=\"TEXT\">http://192.168.2.113/jpg</field></shadow></value><value name=\"headers\"><block type=\"map_on_loop\" id=\"3iZRos8Mrbp4f4y~tuD2\"><statement name=\"LOOP\"><block type=\"create_map_key\" id=\"J=R;MMF8;Ho+/A7NuZfD\"><value name=\"key\"><block type=\"text\" id=\"]Ftv1w/b^To)dAMUcB2Z\"><field name=\"TEXT\">Content-Type</field></block></value><value name=\"value\"><block type=\"text\" id=\"ZR7:4,X9JVj1oMSL!YDb\"><field name=\"TEXT\">image/jpeg</field></block></value></block></statement></block></value><statement name=\"success\"><block type=\"label_set_text\" id=\"_3=]iNrmO[Wg:s,fWXR?\"><field name=\"COMPONENT\">label0</field><value name=\"TEXT\"><shadow type=\"text\" id=\"RsJ/SVci!*o3zMv$qrQW\"><field name=\"TEXT\">Ok</field></shadow></value><next><block type=\"variables_set\" id=\"}0E;!+Xlt$WhFb|H/vx*\"><field name=\"VAR\" id=\"h{j[zW|+d^w^BwqtBTu=\">name</field><value name=\"VALUE\"><block type=\"text_add\" id=\"Xu2:p-P1#pZ0P?i1mKE,\"><value name=\"arg0\"><shadow type=\"text\" id=\"]TuTrd7i)O31VCXA7V.s\" disabled=\"true\"><field name=\"TEXT\"></field></shadow><block type=\"text_add\" id=\"1JF?g;I6@a[|{J50tCgH\"><value name=\"arg0\"><shadow type=\"text\" id=\"V2)f]Vf$w323;|%`FKRI\"><field name=\"TEXT\">IMG_</field></shadow></value><value name=\"arg1\"><block type=\"variables_get\" id=\"Gw`5;`m{KiUXJ9,b|^H#\"><field name=\"VAR\" id=\"M^Rg!7*hzx:x?k+uW?nu\">timestamp</field></block></value></block></value><value name=\"arg1\"><block type=\"text\" id=\"}1c]Cxl#o8nWFj~I;p%S\"><field name=\"TEXT\">.jpg</field></block></value></block></value><next><block type=\"label_set_text\" id=\";uv2Azlxv`?OVW6^s;[w\"><field name=\"COMPONENT\">label1</field><value name=\"TEXT\"><shadow type=\"text\"><field name=\"TEXT\">Fail</field></shadow><block type=\"variables_get\" id=\"4UanLy%0:TT[ZHfqAPyx\"><field name=\"VAR\" id=\"h{j[zW|+d^w^BwqtBTu=\">name</field></block></value><next><block type=\"controls_ifelse\" id=\"T%H*!_XTYJlN[0DA?_|Y\"><value name=\"IF0\"><block type=\"logic_compare\" id=\".@~/.qHUH[7i8Ty-i/lT\"><field name=\"OP\">EQ</field><value name=\"A\"><block type=\"get_status_code\" id=\"cdM^siru*v6^Q)D~P]=G\"></block></value><value name=\"B\"><block type=\"math_number\" id=\"%xs[fjuVhNOLNvcMM?eR\"><field name=\"NUM\">200</field></block></value></block></value><statement name=\"DO0\"><block type=\"open_sdcard_file\" id=\"+xP?gJD@ZHyqzS=h(/mD\"><field name=\"mode\">w</field><value name=\"open\"><shadow type=\"text\" id=\"tw#LKC+)vgx25Mg9,N(2\"><field name=\"TEXT\"></field></shadow><block type=\"variables_get\" id=\"lyYlB^_=#Pfo$RwNjOtx\"><field name=\"VAR\" id=\"h{j[zW|+d^w^BwqtBTu=\">name</field></block></value><statement name=\"do\"><block type=\"execute\" id=\"naNDc6k?cQ=|g`HB{V8K\"><field name=\"CODE\">try:&amp;#10;  fs.write(bytearray(req.content)) &amp;#10;  fs.close()&amp;#10;except Exception as e:&amp;#10;  # print to serial console&amp;#10;  print(str(e))&amp;#10;  # or store in variable</field><next><block type=\"math_change\" id=\"BNa3LfDtkM0Njv^yElt9\"><field name=\"VAR\" id=\"R}fUm|{LQyjG?e9[~uA8\">np</field><value name=\"DELTA\"><shadow type=\"math_number\" id=\"bKw+*U$w,0DEh$Y}IB|Z\"><field name=\"NUM\">1</field></shadow></value></block></next></block></statement><next><block type=\"label_set_text\" id=\"YTfrRCHYC|ojnEcTXnGj\"><field name=\"COMPONENT\">label1</field><value name=\"TEXT\"><shadow type=\"text\" id=\"L-KYnv$~~%V*g{1hmNnq\"><field name=\"TEXT\">Fail</field></shadow><block type=\"variables_get\" id=\"iluE~ZY+JAJY.B|7N#~Q\"><field name=\"VAR\" id=\"h{j[zW|+d^w^BwqtBTu=\">name</field></block></value></block></next></block></statement><statement name=\"ELSE\"><block type=\"label_set_text\" id=\"$;ey86sZg]sZbMf=:s44\"><field name=\"COMPONENT\">label0</field><value name=\"TEXT\"><shadow type=\"text\" id=\"?p@5L`p[}#`r{47E^I_o\"><field name=\"TEXT\">Fail</field></shadow><block type=\"get_status_code\" id=\"}%(Fd?qUBe:^Q2(/m`3u\"></block></value></block></statement></block></next></block></next></block></next></block></statement><statement name=\"fail\"><block type=\"label_set_text\" id=\"K54K0snWTZ8.Tb(71#j=\"><field name=\"COMPONENT\">label0</field><value name=\"TEXT\"><shadow type=\"text\" id=\"QbIeuA|;9;CaWD1U;]aJ\"><field name=\"TEXT\">Fail</field></shadow></value></block></statement><next><block type=\"execute\" id=\"vk{o[el{q$`tI@XM)x_q\"><field name=\"CODE\">req.close()&amp;#10;gc.collect() </field></block></next></block></statement><next><block type=\"label_set_text\" id=\"KN`=F)b8~lQC}w%#TaDG\"><field name=\"COMPONENT\">label3</field><value name=\"TEXT\"><shadow type=\"text\" id=\"r(D|wic2-=9.,kNyMMy.\"><field name=\"TEXT\">Hello M5</field></shadow><block type=\"variables_get\" id=\"qggqb7#GE(NW*fjE=lT2\"><field name=\"VAR\" id=\"R}fUm|{LQyjG?e9[~uA8\">np</field></block></value><next><block type=\"math_change\" id=\"utxBwIiiR[es2A;S3Sh$\"><field name=\"VAR\" id=\"M^Rg!7*hzx:x?k+uW?nu\">timestamp</field><value name=\"DELTA\"><shadow type=\"math_number\" id=\"RFx]VW9ZH=2|3UJiM#qA\"><field name=\"NUM\">1</field></shadow></value><next><block type=\"timer_delay\" id=\"s!*n~u8;n!PuRmpasa)a\"><value name=\"DELAY\"><shadow type=\"math_number\" id=\"A%KjWn*sP:6:u%`FF:d]\"><field name=\"NUM\">1</field></shadow></value></block></next></block></next></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block>","Blockly.Remotes":[],"Blockly.RemotePlus":[{"id":"__title","blockId":"","createTime":1639601183324,"name":"M5RemoteTitle","dragAndDrop":false,"resizable":false,"options":{"minWidth":1,"minHeight":1,"maxWidth":6,"maxHeight":10,"defaultWidth":2,"defaultHeight":1},"w":2,"h":1,"bgColor":"#0080FF","color":"#fff","fontsize":"M","label":"M5Remote","interval":3000,"code":"","event":"","dataSource":"none","ezdataToken":"crljewU5vRsk1Kvyaf2RKdGYpeggh4DX","topic":"","type":"title","x":null,"y":null}],"modules":["remotePlus"]}

Credits

Enrico Casti

Enrico Casti

10 projects • 13 followers
My name is Enrico, I work in the IT sector but I have a great passion for electronics and microcontrollers

Comments