tag:blogger.com,1999:blog-72323660514864802862024-02-01T21:36:20.792-08:00JURNAL ARDUINOUnknownnoreply@blogger.comBlogger191125tag:blogger.com,1999:blog-7232366051486480286.post-73638745387662333892016-03-13T20:44:00.000-07:002016-03-19T11:06:12.053-07:00Driving the #Bolt at #ilightsmarinabay using I2C protocol<div dir="ltr" style="text-align: left;" trbidi="on"><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQFPmCZUI9fZSBmSYGQYnx6IcRX2nhlFCKf-TNWb1Dv2j6Wq82WlgutBizUprV1FKRDP-TVMMqfRBnXJ3Nj25kzP05S0Nxa8Wp1ST6biKKMNwDafTR9u_YHMmxY4yqORMODHnapntnPuPh/s1600/Bolt+cover.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="282" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQFPmCZUI9fZSBmSYGQYnx6IcRX2nhlFCKf-TNWb1Dv2j6Wq82WlgutBizUprV1FKRDP-TVMMqfRBnXJ3Nj25kzP05S0Nxa8Wp1ST6biKKMNwDafTR9u_YHMmxY4yqORMODHnapntnPuPh/s400/Bolt+cover.jpg" width="400" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">#Bolt #SVTmaker</td></tr></tbody></table><br /><br />In this article, I would like to share my experience in planning, testing, making, building, and driving the #Bolt at #ilightsmarinabay that happened on 4th March 2016 at Marina Bay, Singapore iLights festival.<br /><br />A local artists that built a <a href="http://urbanxchange2015.com/2015/11/19/massive-led-star-lights-up-malaysia/">massive LED star</a> in Butterworth, Penang called Jun Hao engaged two local makers, WeMaker and <a href="https://www.facebook.com/SVTmaker/">SVTmaker</a> to do another project in Singapore called the Bolt, simulating lightning bolt when a button was pressed. The below images was taken from his proposal to the festival.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdoEopoc_ddwSYdJi53bCXfE-uY32EC1446K8sf0rHz9VVG-RT9CrnUki_P6Cx9dOSXUieq0CNjw-lOSYos51Oo8B35duahpXURlgHKzU2TXWavaLXxCOYIm4FT_Rrkjsf-_k5Eh9RaQ5Z/s1600/Initial+idea+from+Jun.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="306" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdoEopoc_ddwSYdJi53bCXfE-uY32EC1446K8sf0rHz9VVG-RT9CrnUki_P6Cx9dOSXUieq0CNjw-lOSYos51Oo8B35duahpXURlgHKzU2TXWavaLXxCOYIm4FT_Rrkjsf-_k5Eh9RaQ5Z/s400/Initial+idea+from+Jun.png" width="400" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Bolt idea and concept</td></tr></tbody></table><br />After understanding the requirements from the artists, we started exploring various way to drive the LED strips, from simple relays with delays to wireless options. After a few weeks of searches, I finally found an ideal method to drive so many LEDs using <a href="https://en.wikipedia.org/wiki/I%C2%B2C">I<span style="background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;">nter-Integrated Circuit</span></a> (I2C) protocol with 1 I2C master driving 8 I2C slaves. The idea was to use the delay() to turn on and off the LED strips.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkiyiEDmGwPH8B2cAIR2O2ijFk279VbPeSkttvPvvXuQEdGYE9sf6jwQuKnVSOzGGwDWY3vjbmkkWpm0X9eOZrZ5quQs6SWqGCnqmNfm-lv6NSjMnEmIHtYfoOouGWgNKrI-WHZViVJUCy/s1600/I%25C2%25B2C_bus_logo.svg.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkiyiEDmGwPH8B2cAIR2O2ijFk279VbPeSkttvPvvXuQEdGYE9sf6jwQuKnVSOzGGwDWY3vjbmkkWpm0X9eOZrZ5quQs6SWqGCnqmNfm-lv6NSjMnEmIHtYfoOouGWgNKrI-WHZViVJUCy/s1600/I%25C2%25B2C_bus_logo.svg.png" /></a></div>The idea was to have eight passive I2C slaves just receiving commands from the I2C master and all my coding would be centralized in the I2C master. This makes controlling the code version easily and any changes does not need to re-flash all the 8 I2C slaves. This was my first time writing my own protocols on top of I2C and I probably would exceed the maximum length of the I2C wiring distance.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYYu2-dep8oxDWNhHoE5fSQClpf2wY386KVqXczCEZalkL4UEPgcM52PWU_iL2rBOCJ5EzO4nrNpxfutGVqVK2GBiaO0l2luSy2j3XoNxa45a-Vva_hANmy733GD4Y07D_phPW6DDVF6Rq/s1600/2016-01-08+19.41.00.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYYu2-dep8oxDWNhHoE5fSQClpf2wY386KVqXczCEZalkL4UEPgcM52PWU_iL2rBOCJ5EzO4nrNpxfutGVqVK2GBiaO0l2luSy2j3XoNxa45a-Vva_hANmy733GD4Y07D_phPW6DDVF6Rq/s320/2016-01-08+19.41.00.jpg" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">MOSFET on breadboard</td></tr></tbody></table><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxEFHUVo9EOLujVI9oPO41s5PNRCRYua725UNrb11BwkhMMXq2wa-raKd-vCS7er-6GFMr_L3tqutAxrdo3ulqc4SQGv6DNvFORHcd6onSXeIvVDuGV-8bMVXgdv8VR7Kj8E6KLj_Dxx2c/s1600/2016-01-09+17.05.54.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxEFHUVo9EOLujVI9oPO41s5PNRCRYua725UNrb11BwkhMMXq2wa-raKd-vCS7er-6GFMr_L3tqutAxrdo3ulqc4SQGv6DNvFORHcd6onSXeIvVDuGV-8bMVXgdv8VR7Kj8E6KLj_Dxx2c/s320/2016-01-09+17.05.54.jpg" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Driving 2 Arduino via I2C </td></tr></tbody></table><br /><br />The next task was finding a way to drive the 1 meter 12V LED strips and we decided on using MOSFET for this purpose. This was my first time using MOSFET and lots of it, around 80 pieces of MOSFET to drive around 80 pieces of 1m LED strips.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipZAR5m-xP0sOpriOS0uUSv2HVBqH7cKTFgUmwUrgkt6XSlB3WUNxe91iUSesFqZIfcVLwc3XJOtbyGv_aloJkPQUGVxkZmzTbUmlX4gpM2vdHW_NG-LZyDY2WakusMvzSDQODoE5M4yoO/s1600/IMG-20160116-WA0004.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="137" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipZAR5m-xP0sOpriOS0uUSv2HVBqH7cKTFgUmwUrgkt6XSlB3WUNxe91iUSesFqZIfcVLwc3XJOtbyGv_aloJkPQUGVxkZmzTbUmlX4gpM2vdHW_NG-LZyDY2WakusMvzSDQODoE5M4yoO/s200/IMG-20160116-WA0004.jpg" width="200" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Bolt PCB circuit</td></tr></tbody></table><br />Once this test was done, the next step was making a custom PCB for this purpose as soldering 12 LED strips to 8 I2C slaves on a prefboard is not fun at all. With my very limited skills in EagleCAD, I started drawing up the schematic diagram and board drawing using 12 MOSFET driven by 12 pins on the Arduino Nano.<br /><br />I usually take weeks and many many revisions to correct many errors before I make them into an actual PCB but this time around, time was not on my side and after 3 revisions within 2 days, I send it to Uncle Chow, 9M2CF to get the PCB done. Just in case the I2C does not work, I added a circuit to use nRF wireless options into the circuit as a backup plan. Always have backup plans.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIvGyjiBSfX73UlGPCYFbj2Cb89ONnTTfs0UZcJiSsECiDJx0ALwFJAwEPJuIGdKBkV30FlhMNYJz2d0ADjLzaOPlYHRKYoFO9BfW79vHZDqpL1ang_-vpPQGBlxe_yC7Xph2YDIbQVD6b/s1600/IMG-20160118-WA0015.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="220" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIvGyjiBSfX73UlGPCYFbj2Cb89ONnTTfs0UZcJiSsECiDJx0ALwFJAwEPJuIGdKBkV30FlhMNYJz2d0ADjLzaOPlYHRKYoFO9BfW79vHZDqpL1ang_-vpPQGBlxe_yC7Xph2YDIbQVD6b/s320/IMG-20160118-WA0015.jpg" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Film of PCB drawing<span style="text-align: left;"> </span></td></tr></tbody></table><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQdcU9ovNphG0V3pxh4RivdNRjGwHWMSTluFcnqtPAMbGB8HgRRuA8moJiPmM14IZYL4uTQPdZuFNNf3VuidjHuDr5Qm8s3bIxOBElt5qnXPjHpCUAyx9FObhpa7ioXSMulJT3uMDtvKWe/s1600/Bolt+PCBs.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="248" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQdcU9ovNphG0V3pxh4RivdNRjGwHWMSTluFcnqtPAMbGB8HgRRuA8moJiPmM14IZYL4uTQPdZuFNNf3VuidjHuDr5Qm8s3bIxOBElt5qnXPjHpCUAyx9FObhpa7ioXSMulJT3uMDtvKWe/s320/Bolt+PCBs.jpg" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Bolt PCB done in 2 days</td></tr></tbody></table> To improve the quality of the PCB traces, uncle Chow 9M2CF, made a film instead of printing the drawing on tracing paper with laser printer. <br /><div class="separator" style="clear: both; text-align: center;"></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqYLcuVKUjWCJMlTtfO868JHo_H22Hl8tPW0qK3lj3Fg-3_5hNghyphenhyphen2IQ5rdoJW5rGlOaCXxMltNCTyJmWx8F297MlLjhg4FDVbO0klz5un0rlzsgsWQhh4EWw-2jZeGWcagc0fDU8T1BhN/s1600/IMG-20160114-WA0010.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqYLcuVKUjWCJMlTtfO868JHo_H22Hl8tPW0qK3lj3Fg-3_5hNghyphenhyphen2IQ5rdoJW5rGlOaCXxMltNCTyJmWx8F297MlLjhg4FDVbO0klz5un0rlzsgsWQhh4EWw-2jZeGWcagc0fDU8T1BhN/s320/IMG-20160114-WA0010.jpg" width="240" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifGv1RmvJ6EYXfaDGJb6u38UR6j5pXp9n3qDFsVbQ2rsszBXMiE9sWMdmx4vhUSY2JVFaWvAEeP-HphvwqSa4EiGJM2eHDtYjvJA_x1DjTHzvnD6G14qmEv5TbXmhxbvrtXPBa-8Qyq8oE/s1600/IMG-20160114-WA0011.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifGv1RmvJ6EYXfaDGJb6u38UR6j5pXp9n3qDFsVbQ2rsszBXMiE9sWMdmx4vhUSY2JVFaWvAEeP-HphvwqSa4EiGJM2eHDtYjvJA_x1DjTHzvnD6G14qmEv5TbXmhxbvrtXPBa-8Qyq8oE/s320/IMG-20160114-WA0011.jpg" width="240" /></a></div><br /><br /><br />Meanwhile doing the PCB, the architecture students from Taylors quickly did a model of the structure using lollipop sticks and lots of hot glue. A lot of work was put into making the frosted tubes while cut and soldered long wires to the 1 meter LED strips.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6BOeF19TUmQhazvoPOfGNv4WcsehyphenhyphenKOcVSz0vxOFW9VGVUY5TzU4gJ5PDDEDyfQ_a1krySOV24Y23BgeCxiRuk8iw89ikoKSbRmygYAq_ELL9w2iTkUsi6oFkj0Ef9VLTyw9qU4FLDpwe/s1600/2016-01-18+18.57.51.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6BOeF19TUmQhazvoPOfGNv4WcsehyphenhyphenKOcVSz0vxOFW9VGVUY5TzU4gJ5PDDEDyfQ_a1krySOV24Y23BgeCxiRuk8iw89ikoKSbRmygYAq_ELL9w2iTkUsi6oFkj0Ef9VLTyw9qU4FLDpwe/s320/2016-01-18+18.57.51.jpg" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Driving the Led with Eduboard</td></tr></tbody></table><br /><br />After fixing many circuit errors on the PCB, it was time to hook it up to the model structure to test the lightning patterns. Referring to the first picture of the actual structure, the model accurately show how it will actually going to look like at night with the LED turned on.<br /><br />I find that we actually did this project twice, once on the model and again on the actual structure as we had mini 3 LED strips hook up to the 8 I2C slaves.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLEQ0WWMnUaCBPrwToZiOe-we9JSc_kJHjlPPvsfM27ipmVtEU5_Ki26NBNaZglbaJvBX6yi67HaIJtygPR-f5hya_xkNIW0uP3in5NiMNxpFE47fYOrMGRTGevPD8kdnGvtUcWu2J7t-5/s1600/2016-01-27+22.06.03.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLEQ0WWMnUaCBPrwToZiOe-we9JSc_kJHjlPPvsfM27ipmVtEU5_Ki26NBNaZglbaJvBX6yi67HaIJtygPR-f5hya_xkNIW0uP3in5NiMNxpFE47fYOrMGRTGevPD8kdnGvtUcWu2J7t-5/s320/2016-01-27+22.06.03.jpg" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">8 I2C slaves fully soldered</td></tr></tbody></table><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-7zGwNzE0J1kO1q769DYebdgKca_C8M1wdYKCbij7W-_LbsWLfGvO4j-PwxXT1qEpHEhd_qWrry4LO67Rklvnn6i8dc3SqQHsfIZIyyuwY4-soOMGb72uDvytUpjdZOUz6DMK6DVjqJp_/s1600/2016-01-28+21.43.26.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-7zGwNzE0J1kO1q769DYebdgKca_C8M1wdYKCbij7W-_LbsWLfGvO4j-PwxXT1qEpHEhd_qWrry4LO67Rklvnn6i8dc3SqQHsfIZIyyuwY4-soOMGb72uDvytUpjdZOUz6DMK6DVjqJp_/s320/2016-01-28+21.43.26.jpg" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">8 I2C slaves hook up to the model structure</td></tr></tbody></table><br />Continue on the next article where I talk more on how to drive the LED using a master I2C ....<br /><br />Summary Links :-<br /><br /><ul style="text-align: left;"><li><a href="http://www.ilightmarinabay.sg/">http://www.ilightmarinabay.sg/</a></li><li><a href="http://www.techbitar.com/how-to-network-many-arduinos-with-sensors-using-i2c.html">Using I2C on Arduino</a></li><li><a href="https://www.facebook.com/SVTmaker/">https://www.facebook.com/SVTmaker/</a></li><li><a href="https://www.facebook.com/ArduinoEduboard/">https://www.facebook.com/ArduinoEduboard/</a></li><li><a href="https://www.facebook.com/wemaker.asia/">https://www.facebook.com/wemaker.asia/</a></li></ul><div><br /></div><br /><br /><br /><br /><br /><br /><br /></div>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-7232366051486480286.post-1596624263635894762015-12-15T23:49:00.000-08:002016-03-19T10:53:40.638-07:00Circuit DiagramI just came across this site today (<a href="http://www.schematics.com">www.schematics.com</a>).It looks pretty impressive !! <br>Schematics.com allows you to "build, share and view schematics from you browser" <br>You can also embed your schematic creations on your website - which is neat.<P><br> <iframe width='500' height='300' frameborder='0' scrolling='no' src='http://www.schematics.com/embed/led-with-switch-25024'></iframe><br> <br> <br> <a href="http://www.schematics.com">Circuit Diagram</a> - Schematics is the language of electronics. It provides a concise and comprehensive diagrammatic description of a circuit. Schematics.com allows users to connect and share designs and ideas in a like-minded community. <br> <br> <br> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-10463317491785767542015-11-16T07:31:00.000-08:002016-03-19T10:53:40.657-07:00Get Arduino Data over the internet using jQuery and AJAX<g:plusone></g:plusone> <div style="text-align: justify;"> <P> <div style="text-align: center;"> <iframe width="640" height="360" src="https://www.youtube.com/embed/gF41GRUzFyA?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe> </div> </P> <div> <P> <H4>Description</H4> </P> <P> Have you ever wanted to transmit Arduino data over the internet? <br /> <br> In this tutorial, we will design a web page that will retrieve Analog readings from the Arduino's Analog Pins and display them on a bar chart within the web page. <br> <br> The web page will use jQuery and AJAX to request the data from the Arduino Web Server, allowing us to update the bar chart dynamically, without having to refresh the entire web page. The Arduino Web Server will send the Analog readings to the web page in JSON format where it will be processed and displayed accordingly. <br> <br> In this tutorial, I will not have anything connected to the Arduino's Analog pins, which means the data retrieved will be that of randomly floating analog pins. Feel free to connect a potentiometer, temperature sensor or any other analog sensor to these pins if you want to create a more "useful" project. <br> <br> The main aim here was to show you how to transmit the data in JSON format, and to update only a portion of the web page using asynchronous communication (using AJAX), to improve the performance of data retrieval and visualisation. </P> </div> </div><br><div> <P> <h4>Parts Required:</h4> </P> <P> <ul> <li><a href="https://store.arduino.cc/product/GBX00066">Arduino UNO (or compatible board)</a></li> <li><a href="http://www.shopwiznet.com/ioshield-a">WIZnet ioShield-A ver 1.1</a></li> <li><a href="http://www.shopwiznet.com/wiz550io">WIZnet WIZ550io shield ver 1.1</a></li> </ul> </P> <P><span style="color:red">Please note:</span> The WIZnet ioShield-A ver1.1 actually comes with the WIZ550io board. So if you buy the ioShield-A, you will receive both boards. I have provided the link to the WIZ550io shield because you can buy that shield on its own. Regardless, you will need to use both boards for this tutorial.</P></div><br><div> <P> <h4>Arduino Libraries and IDE</h4> </P> <P> To program the Arduino you will need to download the Arduino IDE, and install the WIZnet Ethernet Library. The Arduino IDE version used in this tutorial was version 1.6.4. <br> You may want to read the WIZnet wiki information for each WIZnet shield before use. </P> <P> <ul> <li><a href="https://www.arduino.cc/en/Main/Software">Arduino IDE</a></li> <li><a href="https://github.com/Wiznet/WIZ_Ethernet_Library">WIZnet Ethernet Library</a></li> <li><a href="http://wizwiki.net/wiki/doku.php?id=osh:ioshield-a:singlepage">ioShield-A setup instructions</a></li> <li><a href="http://wizwiki.net/">WIZnet Wiki page</a> - for more information about the ioShield-A and the WIZ550io shield</li> </ul> </P></div><br> <br><div id="Arduino Code"> <P> <h4>ARDUINO CODE:</h4> </P> <P> <iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/sketch:186084" frameborder="0"></iframe> </P></div><div id="Arduino Code Description"> <P> Full description of the Arduino code is included in the <a href="http://www.youtube.com/watch?v=gF41GRUzFyA&t=7m41s">YouTube video</a> above. Once you have set up your Arduino Web Server, you should be able to ping it. Look at this website, if you don't know how to use the windows ping feature. </P></div><br><div id="Hooking it up"> <P> <h4>Getting the Arduino Board onto the internet:</h4> </P> <P> There isn't anything really to hook up for this project. You just have to align the pins for each board and stack them. You can power the Arduino via the USB cable. This will also be useful for debugging and printing to the Serial monitor. An ethernet cable needs to connect the WIZ550io board's ethernet port to your internet/network router<br> <ul> <li>The WIZ550io board goes on the top</li> </ul> <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEif2t8XNq78E9Ch8wqmigrW09mlejTfXa5_Ys4ukOojd88lQ9hcw6QNugTFmwliRn8YwIZycZ-L3zlCJpAsRTdtLNQ6hcS5IcDQLbi2NxW_Hp8YTCCe5ImzdgYOVbL7vzL_5PUO13gCKnA/s1600/WIZ2550io_Pic1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="WIZ550io Shield" title="WIZ550io Shield" style="border:2px solid white;" height="432" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEif2t8XNq78E9Ch8wqmigrW09mlejTfXa5_Ys4ukOojd88lQ9hcw6QNugTFmwliRn8YwIZycZ-L3zlCJpAsRTdtLNQ6hcS5IcDQLbi2NxW_Hp8YTCCe5ImzdgYOVbL7vzL_5PUO13gCKnA/s640/WIZ2550io_Pic1.jpg" width="640" /></a></div><br /> <ul> <li>The ioShield-A is in the middle </li> </ul> <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9I8Ez0IUfGo17h6BVs72EuD6altC-jPIxYK5dfEKqWQ2rdANES4816GnmyHj7CwSr8FdZJrYbtyPp2bxvA76DWbRSQ7scnlv_JyMujETjClOsULKNQj47yWDwoW0XgKzP7IMgiJbjvy8/s1600/ioShieldA_Pic2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="WIZnet ioShield-A ver 1.1" title="WIZnet ioShield-A ver 1.1" style="border:2px solid white;" height="470" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9I8Ez0IUfGo17h6BVs72EuD6altC-jPIxYK5dfEKqWQ2rdANES4816GnmyHj7CwSr8FdZJrYbtyPp2bxvA76DWbRSQ7scnlv_JyMujETjClOsULKNQj47yWDwoW0XgKzP7IMgiJbjvy8/s640/ioShieldA_Pic2.jpg" width="640" /></a></div><br /> <ul> <li> The Arduino UNO is on the bottom </li> </ul> <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihPbialYym0x3M3B01jpht2xKCObicypoYMOtHVxWxgItiyKzvLUrL2aPUw3MDniPwEyYc-0HpySttid6-kSoZ6FsGO2B_Y8WwAvwDpmQVmum661WrCevWFBBPu8zwrcAeOQz1ZYfCld8/s1600/Arduino+UNO.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Arduino UNO" style="border:2px solid white;" height="410" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihPbialYym0x3M3B01jpht2xKCObicypoYMOtHVxWxgItiyKzvLUrL2aPUw3MDniPwEyYc-0HpySttid6-kSoZ6FsGO2B_Y8WwAvwDpmQVmum661WrCevWFBBPu8zwrcAeOQz1ZYfCld8/s640/Arduino+UNO.jpg" title="Arduino UNO" width="640" /></a></div><br /> <ul> <li> This is what it looks like when they are stacked together </li> </ul> <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3SIW1QUmwGNLGN6RQNl4ToYegC-4PMJn2k8jQdDLKo1ek5NtpbndwkoDAbm0270AyKRLtg9fDp90Tg-bKiczV8wtl3JunvzkbTuyfFUOina3oa2SKWzO3YLPZQgHiH_qLXi7IceKVvcE/s1600/Arduino+and+Shields+stacked+together+and+cables+connected.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Arduino UNO plus ioShield-A plus WIZ550io shield" style="border:2px solid white;" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3SIW1QUmwGNLGN6RQNl4ToYegC-4PMJn2k8jQdDLKo1ek5NtpbndwkoDAbm0270AyKRLtg9fDp90Tg-bKiczV8wtl3JunvzkbTuyfFUOina3oa2SKWzO3YLPZQgHiH_qLXi7IceKVvcE/s640/Arduino+and+Shields+stacked+together+and+cables+connected.jpg" title="Arduino UNO plus ioShield-A plus WIZ550io shield" width="640" /></a></div><br /> <ul> <li>If you want to gain easy access to the Analog or digital pins without de-soldering the ioShield-A, you can introduce some female headers like this:</li> </ul> <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhva2rwi7sTsuBPiDJXblaQvnnPJ6daa8x6TiijDdLKhmujf_wBsz0CpyWQUR4zZurU40OgaVA1_e9Q8You8dCsOtqaVScW-2w_MpY_wcYXGidBzXQGsfVEsiIb8-jtZA8jT_7Aam-vfMg/s1600/Arduino+UNO+with+female+headers.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Arduino UNO with some extra Female headers" style="border:2px solid white;" height="428" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhva2rwi7sTsuBPiDJXblaQvnnPJ6daa8x6TiijDdLKhmujf_wBsz0CpyWQUR4zZurU40OgaVA1_e9Q8You8dCsOtqaVScW-2w_MpY_wcYXGidBzXQGsfVEsiIb8-jtZA8jT_7Aam-vfMg/s640/Arduino+UNO+with+female+headers.jpg" title="Arduino UNO with some extra Female headers" width="640" /></a></div><br /> <ul> <li>Please note that the <a href="http://wizwiki.net/wiki/doku.php?id=osh:ioshield-a:start">ioShield-A</a> utilises a number of pins on the Arduino UNO - including: D2, D4, D7, D10, GND, and IOREF, RESET, 5V, GND, GND and ICSP pins </li> <li>All Analog pins are available for use </li> </ul> </P> <br> <br> <P><H4>Set the Arduino Web Server on your local network</h4></P> <P> You can test this project on your local network. You just have to choose an available IP address and PORT within your router's IP range. If you don't know your local IP address range - you can have a look at <a href="http://portforward.com/networking/routers_ip_address.htm">this site </a> to give you a helping hand. </P> <br> <P><h4>Set the Arduino Web Server to be accessed from anywhere in the world</h4></P> <P>If you want to access your Arduino from anywhere in the world, you need to set up Port Forwarding on your internet network router. The following useful guides will hopefully get you on the right track, if you have never set up Port forwarding. <ul> <li><a href="http://portforward.com/help/portforwarding.htm">What is Port Forwarding</a></li> <li><a href="http://portforward.com/english/routers/port_forwarding/routerindex.htm">portforward.com</a></li> <li><a href="http://portforward.com/english/routers/port_forwarding/iiNet/BoB2/defaultguide.htm">Example of how to port forward on the iiNet BOB2 router</a></li> <li><a href="http://www.pcworld.com/article/244314/how_to_forward_ports_on_your_router.html">PC World instructions on how to port forward</a></li> <li><a href="https://www.youtube.com/watch?v=Kp-R-eHiQco">YouTube video on how to set up port forwarding</a></li> </ul> </P> <br> <P> In my case, I programmed the Arduino UNO Web Server to take the following ip address on my internal network: <b>10.1.1.99 </b><br> <br> I programmed the Arduino Web Server to listen for Web Browsers on <b>port 8081</b>. <br> So if I wanted to connect to the Arduino Web Server through my home network, I just had to type in this web address into my web browser: <a href="http://10.1.1.99:8081">http://10.1.1.99:8081</a><br> <br> If you plan to connect to the Arduino using port 80 (which is the default port for web browsers), you can just type the IP address without specifying the port (eg. http://10.1.1.99/ ) <br> <br> The web browser should display the Arduino data in JSON format (the <a href="http://www.youtube.com/watch?v=gF41GRUzFyA&t=23m20s">YouTube video above</a> will show you what that looks like).<br> <br> Once I knew I could connect to the Arduino in my internal network, I then set up port forwarding on my router so that I could type in my external IP address and special port to tunnel my way into my Arduino Web Server on my internal network. This is what I had to do on my router, but you may need to do something different.<br> <ol> <li> My first step was to find out my public/external IP address by typing "what is my IP address" into google. If you want to know your external IP address <a href="http://lmgtfy.com/?q=What+is+my+IP+address">click here</a>.</li> <li> I then typed my router's ip address into a web browser, and logged into my router. </li> <li> I went to the advanced settings tab </li> <li> Selected "Port Forwarding" from the side menu </li> <li> Filled out all of the details on the first line of the Ports list <br> <ul> <li>Enable box = ticked </li> <li>Description = Arduino</li> <li>WAN interface = pppoe_atm0/ppp0</li> <li>Inbound port = 8082</li> <li>Type = TCP</li> <li>Private IP address = 10.1.1.99</li> <li>Private port = 8081</li> </ul></li> <li>Saved the settings</li> </ol> <br> Now that I had port forwarding enabled, I could type the ip address (that I obtained in step 1) into my browser and specified port 8082 (instead of 8081) - eg. http://190.11.70.253:8082/<br> <br> And now I can access my Arduino Web server from anywhere in the world. I can even access it from my smart phone. Once again, this will only return the Analog data in JSON format. </P></div><br><div><P><h4>The Web Page GUI</h4></P><P>The Arduino is now on the internet, so there are two options. You can either <br> <ul> <li>go to this web page: <a href="http://arduinobasics.blogspot.com.au/p/arduinobasics.html">ArduinoBasics Webserver Data Viewer</a></li> <li>or create the web page yourself (with a little help from the HTML code below) </ul></P><P>Instructions on how to use these web pages, are listed below the HTML code.</P></div><br><div id="Web page code"><script src="https://gist.github.com/ArduinoBasics/bcc517e4e5493654d947.js"></script></div><br><div><P> To retrieve data from your Arduino Web Server, please make sure that it is connected and visible from outside of you local network. You will need to have port forwarding enabled. Information on port forwarding is described above. <ol> <li>Find what your external IP address is. </li> <li>Enter this address using the IP address drop-down boxes within the <a href="http://arduinobasics.blogspot.com.au/p/arduinobasics.html">"ArduinoBasics Webserver Data viewer"</a> web page</li> <li>Enter the port forwarding port number (eg. 8082) into the box labelled "Port"</li> <li>Then click on the "Click here to start getting data" button - you should start to see the bar charts moving and status should be OK</li> <li>If the bar charts do not move, and the status message says "Failed to get DATA!!" - then the web page was unable to connect to the Arduino for some reason. </li> </ol></P><br><div class="separator" style="clear: both; text-align: center;"><a href="http://arduinobasics.blogspot.com.au/p/arduinobasics.html" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="ArduinoBasics Web Data Viewer Web Page Example" style="border:2px solid white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDaf59qE1ssoXRM_UKEYEHUsPhfIGnm3wMZWY2SdY6X8H7y56v2COwH7PAHB0-d4hfD1B-gUx1csUKcEOtFJZL1kT5TIv8YbWHtyOPZy0KdWk2-5HP8rrkrMlYn-Tjt1xcm1ZAwFMdi3o/s640/ArduinoBasics+Web+Data+Viewer.jpg" title="ArduinoBasics Web Data Viewer Web Page Example" /></a></div><br><h4>Troubleshooting</h4><ul><li>You may want to type in the web address into your web browser, to make sure that data is being retrieved. </li><li>You can also open the Serial monitor in the Arduino IDE to make sure that an IP address is being displayed</li><li>Ensure that you have enabled the port forwarding option on your router</li><li>Have a look at <a href="http://www.youtube.com/watch?v=gF41GRUzFyA&t=21m45s">Developer Tools within Google Chrome</a> to help diagnose web page related issues. <li>The web page will not work properly if you use Internet Explorer or if you have javascript disabled within your browser. </li></ul></div><br><div id="Concluding comments"> <P> <h4>Concluding comments</h4> </P> <P> This tutorial showed you how to connect to your Arduino UNO over the internet, and retrieve data in JSON format using jQuery and AJAX. The web page can be modified to suit your own needs, plus it would be more useful if the Arduino was actually monitoring something, rather than logging data from floating pins. It would also be useful if the Arduino could be controlled to blink an LED, or to turn a motor... but I will leave that project for another day. I hope you enjoyed this tutorial - if it helped you in any way, please consider donating a small "tip" into my <a href="https://www.generosity.com/fundraisers/digital-storage-oscilloscope/">money jar</a>. Thank you. </P></div> <br><div id="Social Engagement" align="center"> <P> If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br> <BR /> <BR /> Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br> Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br> I can also be found on <a href="https://www.pinterest.com/ArduinoBasics/">Pinterest</a> and <a href="https://instagram.com/arduinobasics">Instagram</a>. <br> Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.<br> </P></div> <div id="ArduinoBasics Project Page Link" class="separator" style="clear: both; text-align: center;"> <P> <a href="http://arduinobasics.blogspot.com.au/p/arduino-basics-projects-page.html" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="145" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg1dds9EFMC242irm1Ncc1lQvFUd5g3E4oQ-lOwud94W_wcLtuLVZBbGCHvkN1-ktvfz6RW9fNKOC83ZyvvGT5ojvBnfobn8vBzShWLyffe34GiOEkGpXiZeZODOtofj104zmC01GQJWg/s320/ArduinoBasics_OpenLogo+on+Black.png" width="320" /></a> </P></div> <div id="OpenLab Link" class="separator" style="clear: both; text-align: center;"> <P> This project would not have been possible without <a href="http://www.wiznet.co.kr/">WIZnet's</a> collaborative effort.<br> Please visit their site for more cool Ethernet products. </P></div> <div id="Separator2"> <P> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P></div> <div id="Final social hint"> <P> However, if you do not have a google profile... <br>Feel free to share this page with your friends in any way you see fit. </P></div> <br /><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" -->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-38405687312943482512015-11-11T00:15:00.000-08:002016-03-19T10:53:40.700-07:00Two Million ViewsMy blog hit Two million views today !! Hooray !<br /><div><br /></div><div>And while I would love to celebrate this achievement, I think it is more important to remember that today is remembrance day.<br /><br />Each year on this day Australians observe one minute's silence at 11am, in memory of those who died or suffered in all wars and armed conflicts.<br /><br />Please stand for a minute silence - and remember those who have fallen before us.<br /><br />#RemembranceDay</div><div><br /></div><div><span style="background-color: white; color: #333333; font-family: "helvetica neue" , "helvetica" , "arial" , sans-serif; font-size: 14px; line-height: 20px;"><br /></span></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-56324774009214884172015-10-25T06:54:00.000-07:002016-03-19T10:53:40.711-07:00Generosity Campaign Update - Day 3<span style="font-size: large;">Day 3:</span><br /><span style="font-size: large;"><br /></span>Ok - I have now hit the 3rd day in the<a href="https://www.generosity.com/fundraisers/digital-storage-oscilloscope/"> Generosity campaign</a>.<br />This will be my last update of the campaign, unless something exciting happens.<br /><br /><div style="text-align: center;"><span style="font-size: large;">It has been both a very interesting and lonely experience.</span></div><br />The bit that caught me off-guard and surprised me somewhat was the fact that there are opportunistic companies/people out there looking to make money from those not making money... does that make sense?<br /><br />Let me give you an example.... after day1, there were $0 donations.<br />But my campaign did not go un-noticed.... I got a message telling me that my campaign could get a boost !!<br /><br />How ?<br /><br />Well, all I have to do is pay someone some money, and they will either generate some traffic, or market my campaign for me on various social media sites.... it will cost me $50 per tweet !!!!<br /><br /><div style="text-align: center;"><span style="font-size: large;">No thanks !!!</span></div><br />Then I got another message, which told me that I could pay someone to donate a lesser amount to my campaign.... what the ???<br /><br />The idea is that once people see that someone has already donated, they are more likely to donate. Like a restaurant... once you see other people enjoying a restaurant, you are more likely to choose that one, over the one that has no one in it.<br /><br />I just couldn't do something like that... I find that deceptive.<br />If people want to donate, they will, and if they don't want to donate, well that is ok too.....<br /><br />My blog has been active for a few years now - and my goal is simple.<br /><br /><br /><div style="text-align: center;"><span style="color: cyan; font-size: x-large;">Make Arduino tutorials </span></div><div style="text-align: center;"><span style="color: cyan;">- so that others don't have to go through the arduous process that I go through. </span></div><div style="text-align: center;"><span style="color: cyan;">Make them easy to read, easy to understand, and freely available,</span></div><div style="text-align: center;"><span style="color: cyan;">for everyone to enjoy.</span></div><div style="text-align: center;"><br /></div><div style="text-align: center;"><br /><br /><br /></div><div style="text-align: center;"><a href="https://www.generosity.com/fundraisers/digital-storage-oscilloscope/">My money jar is here for anyone looking to find it.</a><br />Minimum donation = $1 USD<br /><br /><span style="font-size: x-small;">Am sorry - it defaults to $50, </span><br /><span style="font-size: x-small;">But you can change it to $1</span><br /><span style="font-size: x-small;">The donation to Generosity.com is not compulsory - you can change that to $0</span></div><div style="text-align: center;"><br /></div><hr />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-66604622800138417582015-10-23T19:16:00.000-07:002016-03-19T10:53:40.754-07:00Generosity Campaign Update - Day 2<span style="font-size: x-large;">Well what a day it has been !! </span><br /><br /><br /><div style="text-align: center;"><span style="font-size: large;">24 hours</span> since the personal campaign to acquire </div><div style="text-align: center;">a <span style="font-size: large;"><a href="https://www.generosity.com/fundraisers/digital-storage-oscilloscope/">Digital Storage Oscilloscope</a> </span>was launched... </div><div style="text-align: center;">and it looks like everything is on track. </div><br /><br /><br />Ok, maybe a bit slower than anticipated, but I think the idea to "spend money to support a content creator" is still sinking in... or maybe it is just sinking......Haha !!<br /><br /><br />Here are the stats so far...<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh69_1nQtV8HOLSkPRs4-fE1iOnLAYtZ4hOglQcO673SU7Gc3l1Cpxqo3whkJ_bcj57c8wLy1QaSYU2npNWXMtwunSqvCg_qHblezzK4xbd-Q-Fl3eDcQKLDdbbPGf696WfyR6DpBy2BB8/s1600/24+hour+chart+of+community+support.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="244" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh69_1nQtV8HOLSkPRs4-fE1iOnLAYtZ4hOglQcO673SU7Gc3l1Cpxqo3whkJ_bcj57c8wLy1QaSYU2npNWXMtwunSqvCg_qHblezzK4xbd-Q-Fl3eDcQKLDdbbPGf696WfyR6DpBy2BB8/s640/24+hour+chart+of+community+support.jpg" width="640" /></a></div><br /><br /><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7dK0Jkz8LGGdzhCL3UTOQoUZJE9bupeA_2xwy7vSaMf8Ig7L5HZblyapY-K_SsrPmE8s5eq2-XBZm9S-Sg3MpmFAFE8E0i3jf1I4pq7dTZotdMqO_SEG2J6kdPoWgtjE9mgT765lxlUc/s1600/Number+of+times+checked.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7dK0Jkz8LGGdzhCL3UTOQoUZJE9bupeA_2xwy7vSaMf8Ig7L5HZblyapY-K_SsrPmE8s5eq2-XBZm9S-Sg3MpmFAFE8E0i3jf1I4pq7dTZotdMqO_SEG2J6kdPoWgtjE9mgT765lxlUc/s640/Number+of+times+checked.jpg" width="640" /></a></div><br /><br />After 24 hours, there were 43 people who paid a visit to see what this campaign was about, and I am pretty sure they ran out the virtual door to get their check books.... I eagerly await their return :)<br /><br />Ok - so in total, after counting all the bills and all the change,<br /><br /><br /><br /><div style="text-align: center;"><span style="font-size: large;">I have received a total contribution of </span></div><div style="text-align: center;"><b><span style="font-size: x-large;">$0 USD</span></b>.</div><br /><br /><br />My total earnings for my entire site for that day when you include advertisements was: <span style="font-size: large;">$0.02</span><br /><br /><br /><br />So from my calculations, the number of days until I will be able to afford an Oscilloscope, not accounting for inflation, and also assuming the price of the Oscilloscope will remain the same is:<br /><br /><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgMqOJCAwuI56bi98ztHBQA6ukGEuYaJ6tpL6hs29m0gYOZE1Cmo1PafHDbwDAjfiRAdjWhELkp315qVTBq37GdIh9K82U76HaWuHzeKYSszQmvdETr8yExjdQBPbOEwtbX74TOJy-sfw/s1600/Days+til+end+of+campaign.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="59" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgMqOJCAwuI56bi98ztHBQA6ukGEuYaJ6tpL6hs29m0gYOZE1Cmo1PafHDbwDAjfiRAdjWhELkp315qVTBq37GdIh9K82U76HaWuHzeKYSszQmvdETr8yExjdQBPbOEwtbX74TOJy-sfw/s320/Days+til+end+of+campaign.jpg" width="320" /></a></div><br /><br /><br />That time-frame is a bit hard to comprehend, so re-adjusting the calculation to years, I get this:<br /><br /><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUq4nqAVKspROfOaIRqv07omtQ0lGPA9NVY1cdV5SeucjsubeTW74Uhe73WDFk7SM1-4X8Ush3YWgw4_QqLDWceTNMajJbHz62_G8NAeYuaw5OWrJP24a2o72XmYP-qb1CHkraPK1gnj4/s1600/Years+til+end+of+campaign.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="58" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUq4nqAVKspROfOaIRqv07omtQ0lGPA9NVY1cdV5SeucjsubeTW74Uhe73WDFk7SM1-4X8Ush3YWgw4_QqLDWceTNMajJbHz62_G8NAeYuaw5OWrJP24a2o72XmYP-qb1CHkraPK1gnj4/s320/Years+til+end+of+campaign.jpg" width="320" /></a></div><br /><br /><br /><br /><br />Ok - this is a bit slow... but the campaign is just warming up :)<br /><br /><br /><div style="text-align: center;"><span style="font-size: large;">I still believe that somewhere in the world </span></div><div style="text-align: center;"><span style="font-size: large;">someone will appreciate my work enough to </span></div><div style="text-align: center;"><span style="font-size: large;"><a href="https://www.generosity.com/fundraisers/digital-storage-oscilloscope/">donate one dollar</a> (or more).... </span></div><div style="text-align: center;"><br /></div><div style="text-align: center;"><br /></div><br />But what if no-one does???<br />That is ok...<br /><br /><br /><div style="text-align: center;"><span style="font-size: large;">I will still provide Arduino tutorials for FREE. </span></div><div style="text-align: center;"><span style="font-size: large;"><br /></span></div><div style="text-align: center;"><span style="font-size: large;"><br /></span></div><br />I will just have to keep working harder to improve the quality of my tutorials, and have confidence in myself.<br />In fact I was very hesitant to put this campaign up. I did not know how well it would be received.<br /><br /><br />However, I wanted to go through the experience, to understand how the Generosity.com system worked.<br />And now if people feel inclined to provide a tip for my work, they are FREE to do so.<br /><br />And you know what that tip will be spent on... yes - you guessed it..<br /><br /><div style="text-align: center;"><span style="font-family: '';">a</span></div><div style="text-align: center;"><span style="font-family: '';"> </span><span style="font-family: ''; font-size: large;"><a href="https://www.generosity.com/fundraisers/digital-storage-oscilloscope/">Digital Storage Oscilloscope</a></span></div><br /><br />I am not sure if anyone will read this page... or will even get down to this line on this page... but if you do... feel free to say hello in the comments - or recommend a good DSO to buy....Bear in mind though, it has to be a good brand/product -<br /><br /><div style="text-align: center;">the company still needs to be there in <span style="font-size: large;">63 years</span> ... Haha !!</div><br />Hope you have a great day !!<br /><br /><br /><br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-47066642318842840032015-10-22T19:28:00.000-07:002016-03-19T10:53:40.767-07:00Generosity campaign - Day 1How do you ask for support from the community without asking for money ?<br />I have no idea...........<br /><br />But if you are feeling generous today, feel free to visit my <span style="font-size: large;"><a href="https://www.generosity.com/fundraisers/digital-storage-oscilloscope/" target="_blank">generosity campaign</a> </span><br /><br /><div style="text-align: center;">... my long term quest to get a Digital Storage Oscilloscope :)</div><br /><div style="text-align: justify;">Indigogo has just launched their new site - <a href="http://generosity.com/">Generosity.com</a> for personal fundraising purposes.</div><div style="text-align: justify;">There is no platform fee, however all processing charges will be deducted before any funds are paid out.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">This new platform allows content creators like myself to do what they do best .... ie. create content.</div><div style="text-align: justify;">And allows content consumers to support content creators and help them to become more "creative".</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"> Did I mention I had a long term quest to get a <a href="https://www.generosity.com/fundraisers/digital-storage-oscilloscope/" target="_blank">Digital Storage Oscilloscope</a> ?</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">A while back, I started a Patreon page... but I didn't like the idea that people had to pledge per tutorial or per duration of time.... I mean, what if you did not like the tutorial or did not like the content in that month? Why should people have to pay for that? <span style="font-family: '';">I guess one good thing about Patreon, is that it does encourage content creators to push out content on a more regular basis...</span><span style="font-family: '';"> </span></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><span style="font-family: '';">Generosity.com on the other hand allows you to make a ONE TIME payment and walk away. And if you happen to like more content, you are free to walk up to that money jar as many times as YOU want... </span></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">I know my campaign will go viral... and everyone will want to chip in to help me get an Oscilloscope :) .... Ok maybe not everyone...and I did say a "<b>long term</b>" quest didn't I ??<br /><br />Hey, you could be the <b><span style="font-size: large;">first </span></b>one.... the person who donated first !!!<br />Everyone <span style="font-size: large;">loves</span> that person... the person who donated first !<br />And <span style="font-size: large;">YOU</span> could be that person!<br /><br />But don't get too crazy... just do it quickly... you <b>don't want to be the second person</b>.<br />The second person is still loved, just not as much :)</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Thank you for your generosity.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://www.generosity.com/fundraisers/digital-storage-oscilloscope/"><img border="0" height="236" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzgfJZwixXfnjTwOk_UTNWrIJhf-A9eZzz8R2jsFcYxyk0y4whrgml-_ZOEDvzYuGCSevRX11YipugPGnOlZO7vI7amZ2tZhsWKLfTxHc_wdwcPkLJvAIYmAKYxUslCYg9uJFOiDc1fRE/s320/Donate+button.jpg" width="320" /></a></div></div><div style="text-align: justify;"><br /></div><br /><br /> <br /> <br /> <br /> <br /> <iframe src="https://docs.google.com/forms/d/1wqv366pXQBqfzdpwTSisPm_wrmYv_XXbgsar02WIW8c/viewform?embedded=true" width="650" height="500" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-86314188183629526492015-10-12T17:43:00.000-07:002016-03-19T10:53:40.810-07:00Arduino LED Light Box<g:plusone></g:plusone> <div id="YouTube" style="text-align: justify;"> <P> <div style="text-align: center;"> <iframe width="640" height="360" src="https://www.youtube.com/embed/c2Q7lFYFGFY?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe> </div> </P> </div> <div id="Description" style="text-align: justify;"> <P> <H4>Description</H4> </P> <P> Long straight lines of LED luminescence is nice, but sometimes you may want to light up something that has an unusual shape, or is not so linear. This is where the <a href="http://openlab.com.au/shop/12mm-diffused-flat-digital-rgb-led-pixels-strand-of-25/">12mm diffused flat digital RGB LED Pixels</a> can come into play. This cool strand of 25 RGB LED pixels fit nicely into 12mm pre-drilled holes of any material you like. </P> <P> This tutorial is dedicated to making a LED Light Box. I wanted the box to be equally as interesting during the day as it was at night. If you decide you make your own, feel free to be as creative as you want !! However, if you lack artistic acumen, you may need to source a minion or two. </P></div> <div id="Parts Required" style="text-align: justify;"> <P> <h4>Parts Required:</h4> </P> <P> <ul> LED Circuit: <li><a href="http://openlab.com.au/shop/arduino-uno-rev3/">Arduino UNO (or compatible board)</a></li> <li><a href="http://openlab.com.au/shop/12mm-diffused-flat-digital-rgb-led-pixels-strand-of-25/">12mm Diffused Flat Digital RGB LED Pixels (Strand of 25)</a></li> <li><a href="http://www.altronics.com.au/p/m8911a-powertran-5v-dc-4a-fixed-2.1mm-tip-appliance-plugpack/">PowerTran 5V DC 4A Plugpack with 2.1mm tip</a></li> <li><a href="http://www.altronics.com.au/p/p0610-2.1mm-screw-terminal-male-dc-power-line-socket/">2.1mm Screw Terminal, DC Power Line socket</a></li> <li><a href="http://openlab.com.au/shop/half-size-breadboard/">Breadboard</a></li> <li><a href="http://openlab.com.au/shop/breadboard-jumper-wire-set-140-pcs-pack/">Breadboard jumper wire</a></li> <li><a href="http://openlab.com.au/shop/resk-resistor-kit/">330 ohm resitor</a></li> <li><a href="http://www.jaycar.com.au/Passive-Components/Capacitors/Electrolytic/4700uF-16V-RB-Electrolytic-Capacitor---105oC/p/RE6243">4700uF 16V Electrolytic Capacitor (Jaycar Cat No. RE6243)</a></li> <li><a href="http://www.jaycar.com.au/Interconnect/Terminals-%26-Headers/Pluggable-Terminal-Blocks/6-Pole-PC-Mount-Pluggable-Header---5-08mm---Horizontal/p/HM3106">6 Pole PC Mount Pluggable Header (Jaycar Cat No. HM3106)</a></li> <li><a href="http://www.jaycar.com.au/Interconnect/Terminals-%26-Headers/Pluggable-Terminal-Blocks/6-Pole-PC-Mount-Pluggable-Terminal-Block-Socket---5-08mm/p/HM3126">6 Pole PC Mount Pluggable Terminal Block Socket (Jaycar Cat No. HM3126)</a></li> <br> Project Box: <li><a href="http://www.bunnings.com.au/boyle-medium-craft-timber-box-with-catch_p1660859">Boyle Medium Craft Timber Box With Catch</a></li> <li><a href="http://www.bunnings.com.au/irwin-12mm-speedbor-spade-drill-bit-_p6354271">12mm drill bit (and drill)</a></li> <li><a href="http://www.officeworks.com.au/shop/officeworks/p/elc-acrylic-paint-antique-white-100ml-el0831?searchTerm=ELC%20acrylic%20paint">ELC Acrylic Paint Antique White 100mL</a></li> <li><a href="http://micador.com.au/Product/779/Micador-Acrylic-Paint-Sets">Micador Acrylic Paint Sets</a></li> <li><a href="http://www.officeworks.com.au/shop/officeworks/p/j-burrows-acrylic-paint-200ml-glitter-sugar-cube-ja401070">J.Burrows Acrylic Paint 200mL Glitter Sugar Cube</a></li> <li><a href="http://www.officeworks.com.au/shop/officeworks/p/elc-rhinestone-assorted-500-pack-el0875?searchTerm=rhinestone%20mix">ELC Rhinestone Assorted 500 Pack</a></li> </ul> </P></div> <br> <br> <div id="Arduino Libraries and IDE" style="text-align: justify;"> <P> <h4>Arduino Libraries and IDE</h4> </P> <P> <!--Write Arduino Library and IDE information below--> <P> Before you start to hook up any components, upload the following sketch to the Arduino microcontroller. I am assuming that you already have the <a href="http://www.arduino.cc/en/Main/Software">Arduino IDE</a> installed on your computer. If not, the IDE can be downloaded from <a href="http://www.arduino.cc/en/Main/Software">here</a>. </P> <P> The <a href="http://fastled.io/">FastLED library</a> is useful for simplifying the code for programming the RGB LED pixels. The latest "FastLED library" can be downloaded from <a href="https://github.com/FastLED/FastLED/releases">here</a>. I used FastLED library version <a href="https://github.com/FastLED/FastLED/tree/3.0.3">3.0.3</a> in this project. </P> <P> If you have a different LED strip or your RGB LED pixels have a different chipset, make sure to change the relevant lines of code to accomodate your hardware. I would suggest you try out a few of the <a href="https://github.com/FastLED/FastLED/tree/3.0.3/examples"> FastLED library examples</a> before using the code below, so that you become more familiar with the library, and will be better equipped to make the necessary changes. </P> <P> If you have a single strand of 25 RGB LED pixels with the WS8201 chipset, then you will not have to make any modification below. </P> </P></div> <br> <br><div id="Arduino Code" style="text-align: justify;"> <P> <h4>ARDUINO CODE:</h4> </P> <P> <!--Paste CodeBender Embed code below--> <iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/sketch:142738" frameborder="0"></iframe> </P></div> <div id="Arduino Code Description" style="text-align: justify;"> <P> <!--Write your comments about the code below--> <h4>Arduino Code Description</h4> </P> <P> The code above will generate a randomised raindrop pattern on the Arduino LED Light box, however I have written code for a few more LED animations. These animations were written specifically for this light-box setup. In other words, once you have hooked everything up, you will be able to upload these other LED animations to the Arduino board without any further modification to the hardware/wiring, and yet experience a totally different light effect. You can find the code for the other animation effects by clicking on the links below: <br> </P> <P> <ol> <li><a href="https://codebender.cc/sketch:142678">Breathing effect</a></li> <li><a href="https://codebender.cc/sketch:143025">Ripple effect</a></li> <li><a href="https://codebender.cc/sketch:143276">Clock effect</a></li> <li><a href="https://codebender.cc/sketch:150716">Rotation effect</a></li> <li><a href="https://codebender.cc/sketch:151166">Sweep effect</a></li> <li><a href="https://codebender.cc/sketch:151176">Spiral effect</a></li> <li><a href="https://codebender.cc/sketch:151201">Lightning effect</a></li> <li><a href="https://codebender.cc/sketch:151204">Paparazzi in the Rain effect</a></li> </ol> </P></div> <div id="Hooking it up" style="text-align: justify;"> <P> <h4>Hooking it up:</h4> </P> <P> <P> <h3 style="color:#62AEB2">Power requirements</h3> </P> <P> Each LED pixel can draw up to 60 milliamps at maximum brightness (white). ie. 20 mA for each colour (red, green and blue). Therefore you should not try to power the LED strand directly from the Arduino, because the strand will draw too much current and damage the microcontroller(and possibly your USB port too). The LED strand will therefore need to be powered by a separate power supply. The power supply must supply the correct voltage (5V DC) and must also be able to supply sufficient current (1.5A or greater per strand of 25 LEDs). </P> <P>Excessive voltage will damage or destroy your LED pixel strand. The LEDs will only draw as much current as they need, however your power supply must provide at least 1.5A or greater for each strand. If you chain two strands together, you will need a 5V 3A power supply. </P> <P> <h3 style="color:#62AEB2">RGB LED pixel strand connection</h3> </P> <P> There are 25 LED pixels per strand. Four of the wires at each end of the strand are terminated with a JST connector. The red wire is for power (VCC), blue wire for ground (GND), yellow wire is for Data, and green wire for Clock. A spare red wire (VCC) and a spare blue wire (GND) are attached to the ends of each strand for convenience, however, I did not use either. Please double check the colour of your wires... they may be different. </P> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUvzIAX3pQunS7W39TfPrCaqz9fjMKvJWw81se3MBj5YdHNFhZXFl67DBSFoPzQzoiqTI0qKRtnf4PMAXBIjr2b4aq7uwRWThvcOO1k6owiyWR747DI9eH1jyvEp7Fhs7NUT2IwalXzwk/s1600/NeoPixel+Top2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:2px solid #8C7E6F;" height="352" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUvzIAX3pQunS7W39TfPrCaqz9fjMKvJWw81se3MBj5YdHNFhZXFl67DBSFoPzQzoiqTI0qKRtnf4PMAXBIjr2b4aq7uwRWThvcOO1k6owiyWR747DI9eH1jyvEp7Fhs7NUT2IwalXzwk/s640/NeoPixel+Top2.jpg" width="640" /> </a> </div> </P> <P> If you want to attach the LED strand to a breadboard, you can cut the JST connector off and use the LED pixel strand wires. Alternatively, if you would prefer to preserve the JST connector, you can simply insert jumper wires (or some male header pins) into the JST connector, and then plug them into the breadboard as required. </P> </P> <P> Each LED pixel is individually controllable using two pins on your Arduino. The strand is directional. i.e. There is an INPUT side and an OUTPUT side. The strand should be connected such that wires from the microcontroller are attached to the INPUT side of the first LED pixel. The arrows on each LED show the direction of data flow from INPUT to OUTPUT. The arrow on the first LED pixel should be pointing towards the second LED pixel, NOT towards the breadboard. </P> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWNCBasldGGMtRkHYZk2ut0NWygA9s0g3JdjBdbZIh6S5xY2188HZukRhmCHuHj8rIvMdLPh6ScVAe0sfjigsyC7fppsWPrNvPh0SAIZbj4SYWm7tx4nCK5Ts-AkWoyv2S-ww3TZaWcmY/s1600/NeoPixel+Side+Arrow+Plain2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:2px solid #8C7E6F;" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWNCBasldGGMtRkHYZk2ut0NWygA9s0g3JdjBdbZIh6S5xY2188HZukRhmCHuHj8rIvMdLPh6ScVAe0sfjigsyC7fppsWPrNvPh0SAIZbj4SYWm7tx4nCK5Ts-AkWoyv2S-ww3TZaWcmY/s640/NeoPixel+Side+Arrow+Plain2.jpg" width="640" onmouseover="this.src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJPGCNhG4LKR-FUEWXJ6uEZwJ7pAQE_Fz8bW0TvAnbzH9OEaXTIEHu-FsqwKI8VP3XPfysMMJoPzzVCPhKLxcyLHKip3ewwDqQjOVTGGag9-NQYnThErUMEuAtigx0BCtDxz65Gt48LHQ/s640/NeoPixel+Side+Arrow+Plain2_Magnified2.jpg'" onmouseout="this.src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWNCBasldGGMtRkHYZk2ut0NWygA9s0g3JdjBdbZIh6S5xY2188HZukRhmCHuHj8rIvMdLPh6ScVAe0sfjigsyC7fppsWPrNvPh0SAIZbj4SYWm7tx4nCK5Ts-AkWoyv2S-ww3TZaWcmY/s640/NeoPixel+Side+Arrow+Plain2.jpg'" /> </a> </div> </P> <P> <h3 style="color:#62AEB2">Other considerations</h3> </P> <P> As a precaution, you should use a large capacitor across the + and - terminals of the power supply to prevent the initial onrush of current from damaging the RGB LED pixels. I used a 4700uF 16V Electrolytic capacitor for this purpose. According to Adafruit, a 1000uF 6.3V capacitor (or higher) will also do the trick. You may also want to consider a 330 ohm resistor between the Arduino Digital pin and the strand's DATA pin. </P> <P>If you want to power the Arduino using the regulated 5V external power supply. Disconnect the USB cable from the Arduino, and then connect the positive terminal of the power supply to the 5V pin on the Arduino. Be warned however, that excess voltage at this pin could damage your Arduino, because the 5V regulator will be bypassed. <br> <br> Providing the USB cable is NOT connected to the Arduino, it should now be safe to plug the power supply into the wall. This setup will allow you to power the RGB LED pixel strand and the Arduino using the same power supply. <BR> <br> WARNING: Never change any connections while the circuit is powered. <br> <br> For more information about these RGB LED pixel strands, you may want to visit the <a href="https://learn.adafruit.com/12mm-led-pixels/">Adafruit site</a>. Adafruit was the source for most of these RGB LED pixel Strand precautions. </P> <P> <br> <h4>Fritzing diagram</h4> </P> <P>The following diagram demonstrates how to connect the RGB LED pixel Strand to the Arduino and to the External 5V power supply.</P> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgijloJssrFdv4aNGwduMnJoxavOSAq4UZ6m-xVUDO5VKBqShxhpZI947jKuarI1ARkek-beYmntdYvdplb4UBHOGuvRkQ-f4x3BWVQkZspwhHkuLwTM-dMZ_ZgylpgoPYfbgRyJMgrZzU/s1600/Fritzing_LightBox_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:2px solid #8C7E6F;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgijloJssrFdv4aNGwduMnJoxavOSAq4UZ6m-xVUDO5VKBqShxhpZI947jKuarI1ARkek-beYmntdYvdplb4UBHOGuvRkQ-f4x3BWVQkZspwhHkuLwTM-dMZ_ZgylpgoPYfbgRyJMgrZzU/s640/Fritzing_LightBox_3.jpg" /> </a> </div><br /><P> This diagram was created using <a href="http://fritzing.org/">Fritzing</a></P> </P> <br> <P> <h4>Connection Instructions</h4> </P> These instructions will help to guide you through the process of connecting your RGB LED pixel strand to the Arduino, and to the external power supply. The instructions assume that you will be powering the Arduino via a USB cable. <P> </P> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnjTO6bgrNsi8aVBmYIwayaUpyH5Hu5qupteneqvP7-QdIqH-JDOgadNF4ngbycQN18Nq4wyvf0g6gC1txnn875j7YvE3EhqbIrtavXb6GrZRKWTD28L-_-Vbqz9m6rJjOWjjL2vlK-2w/s1600/Connection+Instructions.png" imageanchor="1" > <img style="border:2px solid #8C7E6F;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnjTO6bgrNsi8aVBmYIwayaUpyH5Hu5qupteneqvP7-QdIqH-JDOgadNF4ngbycQN18Nq4wyvf0g6gC1txnn875j7YvE3EhqbIrtavXb6GrZRKWTD28L-_-Vbqz9m6rJjOWjjL2vlK-2w/s640/Connection+Instructions.png" /> </a> </div> <br> </P> <br> <P> <h4>LightBox assembly</h4> </P> <P> You will need to drill a 12mm hole into the craft timber box for each LED on the strand. It is worth taking the time to make accurate measurements before drilling the holes. <br> <br> I made 12 holes for the outside circle pattern (12cm diameter), 6 holes for the inside circle pattern (8cm diameter), and a hole in the centre. I also made two holes at the front of the box, two on the left side, and two on the right side. I made one last hole at the back of the box for the 2.1mm DC power line socket. <br> <br> Therefore you should have a total of 26 holes in the box. 25 of the holes are for the RGB LED pixel LEDs and one for the external power supply socket. <br> </P> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVrxmHblImr4Pm1ZOlPWPPJWrmzcxEylwrG72WNUy5K1zmabpcWz7UUYxIUAmRLwUpHIKDKrgo5TRcF4lyxUOS8A4oY7F7t0BcKXKqN-oHciyHLyYFZW4nYJfXmhk5QRn4CEX0D0v1r5U/s1600/Drill+LightBox+Without+Numbers+Lid+Closed.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:2px solid #8C7E6F;" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVrxmHblImr4Pm1ZOlPWPPJWrmzcxEylwrG72WNUy5K1zmabpcWz7UUYxIUAmRLwUpHIKDKrgo5TRcF4lyxUOS8A4oY7F7t0BcKXKqN-oHciyHLyYFZW4nYJfXmhk5QRn4CEX0D0v1r5U/s320/Drill+LightBox+Without+Numbers+Lid+Closed.jpg" width="640" onmouseover="this.src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRNBq-pie3Atn_5XR9S0ysiMM8gVm-Gu8DZpSXhu9Gob9PxE4iAdWZnbOvt8Ch-d2h73lidcaOfvi5OWan6iuw19pm6pPrvKhD2MNhiZMVBnppH3GnmNBWERk4BTnEoll8W72Xq1FuD9U/s320/Drill+LightBox+With+Numbers+Lid+Closed.jpg'" onmouseout="this.src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVrxmHblImr4Pm1ZOlPWPPJWrmzcxEylwrG72WNUy5K1zmabpcWz7UUYxIUAmRLwUpHIKDKrgo5TRcF4lyxUOS8A4oY7F7t0BcKXKqN-oHciyHLyYFZW4nYJfXmhk5QRn4CEX0D0v1r5U/s320/Drill+LightBox+Without+Numbers+Lid+Closed.jpg'" /> </a> </div> </P> <P> The lid of the box is about 19.5cm x 14.5cm long, which makes for a very tight squeeze. Probably too tight, because you have to account for the inner dimensions of the box. The inside of the box is used to house the Arduino, breadboard, the chipset side of the LEDs and cables/components. The inner dimensions of the box are 18cm x 13cm. Therefore, the housing for the LED chipset PCB (1.8cm x 2.5cm) prevented the box from closing. I used a Dremel to carve out the space required to close the lid. </P> <P> </P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio2g5OzgpPdeZDa2mSfIi7fXGXqUDoeRBWHBZXZkMjVv2dXxhzasbnA1Ah4WhFdHqbA-CBwYdBzNl5gZ432YVafiwfL95Z3rwpx7I0U5Ww5MbCnoWpo8RoeEo3sWdEW58UwUDUlhc_Iio/s1600/Drill+LightBox+Without+Numbers.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:2px solid #8C7E6F;" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio2g5OzgpPdeZDa2mSfIi7fXGXqUDoeRBWHBZXZkMjVv2dXxhzasbnA1Ah4WhFdHqbA-CBwYdBzNl5gZ432YVafiwfL95Z3rwpx7I0U5Ww5MbCnoWpo8RoeEo3sWdEW58UwUDUlhc_Iio/s320/Drill+LightBox+Without+Numbers.jpg" width="640" onmouseover="this.src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR7ifcHJQ9bVHwntFqe_hrRJUrfb2JRhWxzMVXn1VviX_XTsUcsZJVTrud4aAf1RnWl1lxvYPsHp9jJAxYlkFG6tfq2EriUAV29kuOLdWgggjxuKJxlCepKhqNcLxqVECua1l86hACzic/s320/Drill+LightBox+With+Numbers2.jpg'" onmouseout="this.src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio2g5OzgpPdeZDa2mSfIi7fXGXqUDoeRBWHBZXZkMjVv2dXxhzasbnA1Ah4WhFdHqbA-CBwYdBzNl5gZ432YVafiwfL95Z3rwpx7I0U5Ww5MbCnoWpo8RoeEo3sWdEW58UwUDUlhc_Iio/s320/Drill+LightBox+Without+Numbers.jpg'" /> </a> </div> <P>Each LED is approximately 8cm apart on the strand, however, if you are really keen, you could cut the wires and extend them to any distance you require. But keep in mind that each LED is mounted on a small PCB (with a WS2801 chipset).You will therefore need to leave a minimum of 2cm between each 12mm hole to accomodate the size of the PCB+LED. If you plan carefully, you can probably squeeze a couple of LEDs within a distance of 1cm... but I would recommend that you give yourself a bit more room, because the PCBs are not square, and there is a good chance that you will have to start all over again.</P> <P> <P> In hindsight, I could have made the circle patterns a bit smaller, however I don't know if I could have packed these LEDs any closer. The diameter of the inner circle pattern must be at least 2cm smaller than the outer circle pattern. So I think "a bigger box" would have been the best option. </P> Once all of the holes have been drilled, paint and decorate the box to suit your style. </P> <P> When the paint is dry, insert the LEDs into the drilled holes in number order. <br> You can see the end result below. </P> <P> <!-- Picture of the underside of the lid (showing how tight the LEDs are packed together) --> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtewbZh51pQ2FbFc9ZYE6MNbEoKmNxcw05kAbMEVFG54GGB49KrmvZXRwRF0fiElARhpuB1NQP2rWvxA5UNtTvSHb3RHhAtkB1Bo6Kp1sJROFtL0RLdxMZgbUmi5Yzi6wniazXzOGp0_c/s1600/Lid+Underside.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:2px solid #8C7E6F;" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtewbZh51pQ2FbFc9ZYE6MNbEoKmNxcw05kAbMEVFG54GGB49KrmvZXRwRF0fiElARhpuB1NQP2rWvxA5UNtTvSHb3RHhAtkB1Bo6Kp1sJROFtL0RLdxMZgbUmi5Yzi6wniazXzOGp0_c/s640/Lid+Underside.JPG" width="640" /> </a> </div><br /> </P> <br> <P><h4>Project Pictures</h4> </P> <P>These pictures show the Light box after it has been drilled and painted. The LEDs have been inserted into their respective holes, and all wires + Arduino + breadboard are hidden within the box. </P> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKDm1QcJF_8-wiPG5mv9oalYB9vY6u7pqboJ9h611Zwg5KPmUlhKqTwYulbs_hBtfidDOI2zf8naA1ClBtjkPcQR7MrKrdp4fe6DDx1iYbYSLFC-XYe1MEFrmLBXKawlKgKUahKKqPHl8/s1600/LightBox_Day1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:2px solid #8C7E6F;" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKDm1QcJF_8-wiPG5mv9oalYB9vY6u7pqboJ9h611Zwg5KPmUlhKqTwYulbs_hBtfidDOI2zf8naA1ClBtjkPcQR7MrKrdp4fe6DDx1iYbYSLFC-XYe1MEFrmLBXKawlKgKUahKKqPHl8/s640/LightBox_Day1.jpg" width="640" /> </a> </div><br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_CG_VDMVY_0-4yZjP378WaEMY-KtbFWRlk-32oj4yz-R8jSFW__cYjkinAW38NzJuFKtUKc8dq6dhbmoGbMBRvrprffcek-rNZVVdGejrwh_1bLl9ko5R9_4P277jw1DgaueerlY5xA8/s1600/LightBox_Day2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:2px solid #8C7E6F;" height="408" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_CG_VDMVY_0-4yZjP378WaEMY-KtbFWRlk-32oj4yz-R8jSFW__cYjkinAW38NzJuFKtUKc8dq6dhbmoGbMBRvrprffcek-rNZVVdGejrwh_1bLl9ko5R9_4P277jw1DgaueerlY5xA8/s640/LightBox_Day2.jpg" width="640" /> </a> </div><br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyAI_uBq_gsr1FWNraq0dhiKdAcAN6yekeWTahihEw-2XPZamVk4GGQqfbuB7axinBJK4IUy1B2U81oTzSaogj5LCVCk0oOeJSD3JQ96SaD9BqqUFYD6bniYBiNkY8kJhFP0m9tm-EeXg/s1600/LightBox+lit+up.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:2px solid #8C7E6F;" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyAI_uBq_gsr1FWNraq0dhiKdAcAN6yekeWTahihEw-2XPZamVk4GGQqfbuB7axinBJK4IUy1B2U81oTzSaogj5LCVCk0oOeJSD3JQ96SaD9BqqUFYD6bniYBiNkY8kJhFP0m9tm-EeXg/s640/LightBox+lit+up.JPG" width="640" /> </a> </div> <br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj50lo8PBI31wFH4yhdPRYkhsDhxKalsbULB5_HSHPhJ5hF9qzE7SnkwRdNGJNdnUFMXDb8QH_4MbikOPkS_O41r0Vpk_-ff7_w3I0OpJSTPCVEzWq46qVXteMHhj_YsiTF8ujnuPs276U/s1600/LightBox+lit+up2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:2px solid #8C7E6F;" height="450" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj50lo8PBI31wFH4yhdPRYkhsDhxKalsbULB5_HSHPhJ5hF9qzE7SnkwRdNGJNdnUFMXDb8QH_4MbikOPkS_O41r0Vpk_-ff7_w3I0OpJSTPCVEzWq46qVXteMHhj_YsiTF8ujnuPs276U/s640/LightBox+lit+up2.JPG" width="640" /> </a> </div><br /> </P></div> <div id="Concluding comments" style="text-align: justify;"> <P> <h4>Concluding comments</h4> </P> <P> <!--Write concluding comments below--> Once you start writing LED animations for the RGB LED pixel Lightbox, it is very hard to stop. The colour combinations </P></div> <div id="Separator"> <P> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P></div> <div id="Social Engagement" align="center"> <P> If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br> <BR /> <BR /> Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br> Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br> I can also be found on <a href="https://www.pinterest.com/ArduinoBasics/">Pinterest</a> and <a href="https://instagram.com/arduinobasics">Instagram</a>. <br> Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.<br> </P></div> <div id="ArduinoBasics Project Page Link" class="separator" style="clear: both; text-align: center;"> <P> <a href="http://arduinobasics.blogspot.com.au/p/arduino-basics-projects-page.html" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="145" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg1dds9EFMC242irm1Ncc1lQvFUd5g3E4oQ-lOwud94W_wcLtuLVZBbGCHvkN1-ktvfz6RW9fNKOC83ZyvvGT5ojvBnfobn8vBzShWLyffe34GiOEkGpXiZeZODOtofj104zmC01GQJWg/s320/ArduinoBasics_OpenLogo+on+Black.png" width="320" /></a> </P></div> <div id="OpenLab Link" class="separator" style="clear: both; text-align: center;"> <P> This project would not have been possible without <a href="http://openlab.com.au/">OpenLab's</a> collaborative effort.<br> Please visit their site for more cool projects. </P></div> <div id="Separator2"> <P> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P></div> <div id="Final social hint"> <P> However, if you do not have a google profile... <br>Feel free to share this page with your friends in any way you see fit. </P></div> <br /><br /><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" -->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-20204758789157188902015-10-06T23:53:00.000-07:002016-03-19T11:06:12.085-07:00Uploaded Arduino blink example to a STM32 board - M3S STM32F103ZET6<div dir="ltr" style="text-align: left;" trbidi="on"><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPeDQwb3u3bNJBOS8Yx10k4K0M2nIzwb5XStpL1hkcC9ImoWLe3pB-sGNaA_L6AyNlDVlkHwX3G83bJ-TbRipvQLo1XJWkRLkzIJjL891wNTQLiPrdJNexro9-xIOPzdzs5EyFxastH4YL/s1600/2015-10-04+13.40.29.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPeDQwb3u3bNJBOS8Yx10k4K0M2nIzwb5XStpL1hkcC9ImoWLe3pB-sGNaA_L6AyNlDVlkHwX3G83bJ-TbRipvQLo1XJWkRLkzIJjL891wNTQLiPrdJNexro9-xIOPzdzs5EyFxastH4YL/s400/2015-10-04+13.40.29.jpg" width="400" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">M3S STM32F103ZET6</td></tr></tbody></table><br /><br />In my quest for higher speed, more pins, more flash and more RAM for my SVTrackR and yet keeping the cost low, I started exploring other ARM 32-bit boards.<br /><br />Before this, I'm already using <a href="http://digistump.com/products/50">DigiX</a> from Digistump, an Arduino DUE compatible board but they are in Mega form factor, kinda big and most important factor for me, high price. The DigiX are 32bit ARM Cortex-M3 microcontroller running at 84Mhz.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://digistump.com/wiki/_media/digix/comparison.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://digistump.com/wiki/_media/digix/comparison.png" height="640" width="508" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">DigiX Comparison Table</td></tr></tbody></table><br />While shopping at taobao, the development boards from STM32 really stand out as they are low cost, lots of pins and similar form factors as Arduino Nano. My most important criteria is that I should not have to port my codes to another platform or learn another new development environment. As a hobbyists, the development software must also be free.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYXWK02vrL7iyXIUZVtk8glao-Sb0cmkBSpujWxc_KzJmUBPIKHxOB0k1gdsaeR8LGTf5TNqi4KV0NsQ0hID7qBb0PEf4yV3Puz1tgFvAUk1nrtJ-dNPj_V-U7Ksd1VheoO_mGtZiTfWGl/s1600/STM32.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYXWK02vrL7iyXIUZVtk8glao-Sb0cmkBSpujWxc_KzJmUBPIKHxOB0k1gdsaeR8LGTf5TNqi4KV0NsQ0hID7qBb0PEf4yV3Puz1tgFvAUk1nrtJ-dNPj_V-U7Ksd1VheoO_mGtZiTfWGl/s640/STM32.png" width="418" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">STM32 dev board</td></tr></tbody></table>A search for STM32 will results in so many STM32 development boards from any shapes, colours and sizes with price range from RMB25.70 to thousands of RMB. Compared to the above chart for DigiX, the lowest price are 59 in US Dollars.<br /><br />All these cheap and powerful boards are no good to me unless they runs on Arduino IDE as my SVTrackR codes uses a lot of open source libraries from GPS, OLED and SoftSerial.<br /><br />Some background and history on STM32 on the Arduino platform. It was started very early by leaflabs producing the Maple and Maple Mini back in 2008. You can read all the details are the links provided below. Good thing it was an open source projects so all the work done by them can be taken up some others to continue the development. If this were a closed sourced project, all these would be gone.<br /><a href="http://www.leaflabs.com/device-details/">http://www.leaflabs.com/device-details/</a><br /><br /><br />Arduino Forum :-<br /><a href="http://forum.arduino.cc/index.php?topic=265904.0">http://forum.arduino.cc/index.php?topic=265904.0</a> with 2625 messages.<br /><br />New STM32duino home :-<br /><a href="http://www.stm32duino.com/index.php">http://www.stm32duino.com/</a><br /><br />Roger Clarke from Melbourne did a great job to continue the developement.<br /><a href="https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/Credits-and-history">https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/Credits-and-history</a><br /><br />If you are a newbie and just want to make some STM32 board purchases without reading all the histories, click on <a href="http://www.stm32duino.com/viewtopic.php?f=2&t=94">Guide: "I'm new here - which board should I buy?"</a><br /><br /><br />More pictures of the M3S STM32 development board I purchased. I've also purchased the 3.2" touchscreen TFT that can attached to this board. It also comes in a nice looking plastic box.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtiyAsloko34QzYYpzXXQ6iwSaovniuydrNnh7Fd-qkKJuzxMstJHmEl1iCJKQzGZgARjKeZxawky80CwtG-Q4akjrQTL2Cuz4cDl9CZu9pB6G8jwJ1a3RNwECsxFYVs36opDnWOwCDQLK/s1600/2015-10-07+14.37.28.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtiyAsloko34QzYYpzXXQ6iwSaovniuydrNnh7Fd-qkKJuzxMstJHmEl1iCJKQzGZgARjKeZxawky80CwtG-Q4akjrQTL2Cuz4cDl9CZu9pB6G8jwJ1a3RNwECsxFYVs36opDnWOwCDQLK/s320/2015-10-07+14.37.28.jpg" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">M3S with box</td></tr></tbody></table><br /><br /><div class="separator" style="clear: both; text-align: center;"></div><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMWcigP4cEvynSMlHaoCAtb_hxYVfEFmI8TVywL5vgQOb5ddb8fE1-O9VQmReeG0nolq1TcSNyvABn9aJVtXBRWrgWmYOCT8GtqmeBDSDOEkPtfFSah0s6NpwsLORI9PMU93TXsqdpOmdd/s1600/M3S+Rotated.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMWcigP4cEvynSMlHaoCAtb_hxYVfEFmI8TVywL5vgQOb5ddb8fE1-O9VQmReeG0nolq1TcSNyvABn9aJVtXBRWrgWmYOCT8GtqmeBDSDOEkPtfFSah0s6NpwsLORI9PMU93TXsqdpOmdd/s320/M3S+Rotated.jpg" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">M3S with 3.2" TFT</td></tr></tbody></table><br /><br /><div class="separator" style="clear: both; text-align: center;"></div><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-aVbRieR4lcX1oW5C2IHN1dxGu1CnTO45LIguocZaP75FlvwlWtG0bbfNoCLMH3I-7NSUJlvKeKHwQtt-ii1AssmMTcKB-_SWjNgP9oc3ltQxAc3rrotcfwcpQEHgapfRAhpiVLVIenOL/s1600/2015-10-04+13.41.11-2.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-aVbRieR4lcX1oW5C2IHN1dxGu1CnTO45LIguocZaP75FlvwlWtG0bbfNoCLMH3I-7NSUJlvKeKHwQtt-ii1AssmMTcKB-_SWjNgP9oc3ltQxAc3rrotcfwcpQEHgapfRAhpiVLVIenOL/s320/2015-10-04+13.41.11-2.jpg" width="271" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">M3S STM32F103ZET6 with 3.2" TFT</td></tr></tbody></table><br /><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtfZLPWNrYDK4-z45uWX36qq23ZODs7HrzzefYFbeeZkg9QDzqEkuViw_7iqXDdbABmXYc84YxOHVeNxXm47tABw1aivkV_hpJ6ZwpAYa0L3AL647hYSmj2uNWDDGLmuvTz9eutbUowHuA/s1600/21978670621_d8a221e2ac_o.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="442" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtfZLPWNrYDK4-z45uWX36qq23ZODs7HrzzefYFbeeZkg9QDzqEkuViw_7iqXDdbABmXYc84YxOHVeNxXm47tABw1aivkV_hpJ6ZwpAYa0L3AL647hYSmj2uNWDDGLmuvTz9eutbUowHuA/s640/21978670621_d8a221e2ac_o.jpg" width="640" /></a></div><br />From the image the seller posted, this board have a lot of items on board like 2 USB port (mine comes with Micro-USB ), DB9 on MAX3232, JTAG, SWD, DS18B20 slots, mini buzzer, nRF24L01 slots, SPI flash on SD, SDIO, 2 LEDs, 4 buttons, BOOT0/BOOT1 jumpers, EEPROM 24C02, OV7670 camera module and other that I could not translate the chinese.<br /><br /><br /><u><b>Summary Links</b></u><br /><br /><br /><ul style="text-align: left;"><li>STM32duino Forum <a href="http://www.stm32duino.com/index.php">http://www.stm32duino.com/</a></li><li> Github <a href="https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki">https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki</a></li><li>Arduino Forum <a href="http://forum.arduino.cc/index.php?topic=265904.0">http://forum.arduino.cc/index.php?topic=265904.0</a> </li></ul><div><br /></div><br /><br /><br /><br /><br /><br /><br /></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-63535381498486743632015-08-04T08:51:00.000-07:002016-03-19T10:53:40.835-07:00MT8870 DTMF - Dual Tone Multi Frequency Decoder<div style="text-align: justify;"> <P> <div class="separator" style="clear: both; text-align: center;"> <iframe width="640" height="420" src="https://www.youtube.com/embed/QIWRuIFFkD8?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe> </div> </P> <div align="right"> <g:plusone></g:plusone> </div> <P> <h4>Project Description</h4> We will be using an MT8870 DTMF module with an Arduino UNO to control a small servo motor in this project. The DTMF module gives the Arduino super-powers and allows you to control the Servo motor in so many ways. For example, this tutorial will show you how to control the servo motor using: <ul> <li>a YouTube Video</li> <li>a voice recorder</li> <li>A web application (Online tone generator)</li> <li>A smart phone app (DTMF Pad)</li> <li>A touch-tone phone to cell-phone call</li> </ul> All of these control methods will take advantage of the same exact Arduino code/sketch. But how???<br> The MT8870 DTMF decoder is quite a neat little module that allows you incorporate DTMF technology into your arduino projects. DTMF stands for <b>D</b>ual-<b>T</b>one <b>M</b>ulti-<b>F</b>requency. DTMF tones are commonly associated with touch-tone phones and other telecommunication systems. When you press the number "1" on a touch-tone phone, two sine waves with frequencies: 697Hz and 1209Hz are combined to produce a unique DTMF signal which can be transmitted through the phone line. The MT8870 DTMF module can take this signal as an input, and decode it to produce a binary output.<br> <br clear="all"> <br> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_GBHPNqNAROuYD8mJxjIadmPZOZlSZIG_HgCqq0QuRLf4wG3cb6d1ng6nh-zxFy58BOo9e79xZ-YJbxVYp6uP63mhdOUiyNSGcG_y26VVpZQ82C0zoMUlK0amn8w-uQD3soNRnJTeV8E/s1600/DTMF+Frequency+Table.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_GBHPNqNAROuYD8mJxjIadmPZOZlSZIG_HgCqq0QuRLf4wG3cb6d1ng6nh-zxFy58BOo9e79xZ-YJbxVYp6uP63mhdOUiyNSGcG_y26VVpZQ82C0zoMUlK0amn8w-uQD3soNRnJTeV8E/s1600/DTMF+Frequency+Table.jpg" /> </a> </div> <br clear="all"> <br> The DTMF module does not care how you produce the DTMF tone. However, if it receives this tone, it will decode it. We can take advantage of this feature to supply the module with tones from different sources. The module has a 3.5mm port for line input. Providing you can connect your DTMF source to this line input in some way, it should work. I must warn you, however that this is a line input and NOT a microphone input. If you wanted to use a microphone, you will need to boost or amplify the signal before sending it to the DTMF module.<br> <br> You will need the following parts for this project<br> <br> </P> <P> <h4>Parts Required:</h4> <P> <ul> <li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=3746" target="_blank">Arduino Uno or compatible board</a></li> <li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=5259" target="_blank">ICStation MT8870 DTMF decoding module</a></li> <li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=3193" target="_blank">Jumper Cable (Male to Female)</a></li> <li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=1603" target="_blank">Hobby Servo Motor</a></li> <li>A cable to connect DTMF source with MT8870 DTMF Module's 3.5mm port</li> <li>A voice recorder (optional)</li> <li>2 x touch-tone phones / smart phones (optional)</li> <br /> </ul> </P> </P> <P> <h4>Software/Apps Required</h4> <P> <ul> <li><a href="https://www.arduino.cc/en/main/software">Arduino IDE</a></li> <li><a href="https://itunes.apple.com/gb/app/dtmf-pad/id312536578?mt=8">DTMF Pad by IEIRISOFTWARE LAB. (for iOS devices)</a></li> <li><a href="https://play.google.com/store/apps/details?id=com.amknott.ToneGen">DTMF Tone Generator by Andrew M. Knott (for android devices)</a></li> <li><a href="http://onlinetonegenerator.com/dtmf.html">Online Tone Generator</a></li> <li><a href="https://www.youtube.com/watch?v=fpDa7a42SJE">A YouTube video with DTMF tones</a></li> <br /> </ul> </P> </P> <P> <h4>Arduino Sketch</h4><br> Upload the following sketch to the Arduino. <br> <br> <style type="text/css">span { } .sc0 { } .sc1 { font-family: 'Courier New'; font-size: 10pt; color: #808080; } .sc2 { font-family: 'Courier New'; font-size: 10pt; color: #808080; } .sc4 { font-family: 'Courier New'; font-size: 10pt; color: #000000; } .sc5 { font-family: 'Courier New'; font-size: 10pt; font-weight: bold; color: #D35400; } .sc9 { font-family: 'Courier New'; font-size: 10pt; color: #000000; } .sc10 { font-family: 'Courier New'; font-size: 10pt; font-weight: bold; color: #000040; } .sc11 { } .sc16 { font-family: 'Courier New'; font-size: 10pt; color: #00979C; } </style><div style="background: #ffffff; color: #000000; overflow:auto;width:auto;border:solid rgb(24,186,183);border-width: .6em .3em .3em .3em;padding: 0em 0em;"> <table> <tr> <td> <pre style="margin: 0; line-height: 125%; background: rgb(24,186,183); width: 1.9em"><span class="sc4"><br />1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62</span></pre> </td> <td> <div style="float: left; white-space: pre; line-height: 125%; background: #FFFFFF; "><span class="sc4"><span class="sc1">/* ================================================================================================================================================== Project: MT8870 DTMF Servo sketch Author: Scott C Created: 4th August 2015 Arduino IDE: 1.6.4 Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html Description: This project will allow you to control a Servo motor using an Arduino UNO and a MT8870 DTMF Module. The DTMF signal is received through the 3.5mm port of the DTMF module and is decoded. We will use the decoded output to control the position of the Servo. A SG-5010 Servo motor was used in this project. ===================================================================================================================================================== */</span><span class="sc0"></span><span class="sc2">//This sketch uses the Servo library that comes with the Arduino IDE </span><span class="sc9">#include <Servo.h> </span><span class="sc0"> </span><span class="sc2">//Global variables----------------------------------------------------------------------------------------- </span><span class="sc5">Servo</span><span class="sc0"> </span><span class="sc11">SG5010</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc2">// The SG5010 variable provides Servo functionality </span><span class="sc16">int</span><span class="sc0"> </span><span class="sc11">servoPosition</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">0</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc2">// The servoPosition variable will be used to set the position of the servo </span><span class="sc16">byte</span><span class="sc0"> </span><span class="sc11">DTMFread</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc2">// The DTMFread variable will be used to interpret the output of the DTMF module. </span><span class="sc16">const</span><span class="sc0"> </span><span class="sc16">int</span><span class="sc0"> </span><span class="sc11">STQ</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">3</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc2">// Attach DTMF Module STQ Pin to Arduino Digital Pin 3 </span><span class="sc0"> </span><span class="sc16">const</span><span class="sc0"> </span><span class="sc16">int</span><span class="sc0"> </span><span class="sc11">Q4</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">4</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc2">// Attach DTMF Module Q4 Pin to Arduino Digital Pin 4 </span><span class="sc0"> </span><span class="sc16">const</span><span class="sc0"> </span><span class="sc16">int</span><span class="sc0"> </span><span class="sc11">Q3</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">5</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc2">// Attach DTMF Module Q3 Pin to Arduino Digital Pin 5 </span><span class="sc0"> </span><span class="sc16">const</span><span class="sc0"> </span><span class="sc16">int</span><span class="sc0"> </span><span class="sc11">Q2</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">6</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc2">// Attach DTMF Module Q2 Pin to Arduino Digital Pin 6 </span><span class="sc0"> </span><span class="sc16">const</span><span class="sc0"> </span><span class="sc16">int</span><span class="sc0"> </span><span class="sc11">Q1</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">7</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc2">// Attach DTMF Module Q1 Pin to Arduino Digital Pin 7 </span><span class="sc0"> </span><span class="sc1">/*========================================================================================================= setup() : will setup the Servo, and prepare the Arduino to receive the MT8700 DTMF module's output. ========================================================================================================== */</span><span class="sc0"></span><span class="sc16">void</span><span class="sc0"> </span><span class="sc11">setup</span><span class="sc10">()</span><span class="sc0"> </span><span class="sc10">{</span><span class="sc0"> </span><span class="sc11">SG5010</span><span class="sc10">.</span><span class="sc5">attach</span><span class="sc10">(</span><span class="sc4">9</span><span class="sc10">);</span><span class="sc0"> </span><span class="sc2">// The Servo signal cable will be attached to Arduino Digital Pin 9 </span><span class="sc0"> </span><span class="sc11">SG5010</span><span class="sc10">.</span><span class="sc5">write</span><span class="sc10">(</span><span class="sc11">servoPosition</span><span class="sc10">);</span><span class="sc0"> </span><span class="sc2">// Set the servo position to zero. </span><span class="sc0"> </span><span class="sc2">//Setup the INPUT pins on the Arduino </span><span class="sc0"> </span><span class="sc5">pinMode</span><span class="sc10">(</span><span class="sc11">STQ</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc16">INPUT</span><span class="sc10">);</span><span class="sc0"> </span><span class="sc5">pinMode</span><span class="sc10">(</span><span class="sc11">Q4</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc16">INPUT</span><span class="sc10">);</span><span class="sc0"> </span><span class="sc5">pinMode</span><span class="sc10">(</span><span class="sc11">Q3</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc16">INPUT</span><span class="sc10">);</span><span class="sc0"> </span><span class="sc5">pinMode</span><span class="sc10">(</span><span class="sc11">Q2</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc16">INPUT</span><span class="sc10">);</span><span class="sc0"> </span><span class="sc5">pinMode</span><span class="sc10">(</span><span class="sc11">Q1</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc16">INPUT</span><span class="sc10">);</span><span class="sc0"></span><span class="sc10">}</span><span class="sc0"> </span><span class="sc1">/*========================================================================================================= loop() : Arduino will interpret the DTMF module output and position the Servo accordingly ========================================================================================================== */</span><span class="sc0"></span><span class="sc16">void</span><span class="sc0"> </span><span class="sc11">loop</span><span class="sc10">()</span><span class="sc0"> </span><span class="sc10">{</span><span class="sc0"> </span><span class="sc5">if</span><span class="sc10">(</span><span class="sc5">digitalRead</span><span class="sc10">(</span><span class="sc11">STQ</span><span class="sc10">)==</span><span class="sc16">HIGH</span><span class="sc10">){</span><span class="sc0"> </span><span class="sc2">//When a DTMF tone is detected, STQ will read HIGH for the duration of the tone. </span><span class="sc0"> </span><span class="sc11">DTMFread</span><span class="sc10">=</span><span class="sc4">0</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc5">if</span><span class="sc10">(</span><span class="sc5">digitalRead</span><span class="sc10">(</span><span class="sc11">Q1</span><span class="sc10">)==</span><span class="sc16">HIGH</span><span class="sc10">){</span><span class="sc0"> </span><span class="sc2">//If Q1 reads HIGH, then add 1 to the DTMFread variable </span><span class="sc0"> </span><span class="sc11">DTMFread</span><span class="sc10">=</span><span class="sc11">DTMFread</span><span class="sc10">+</span><span class="sc4">1</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc5">if</span><span class="sc10">(</span><span class="sc5">digitalRead</span><span class="sc10">(</span><span class="sc11">Q2</span><span class="sc10">)==</span><span class="sc16">HIGH</span><span class="sc10">){</span><span class="sc0"> </span><span class="sc2">//If Q2 reads HIGH, then add 2 to the DTMFread variable </span><span class="sc0"> </span><span class="sc11">DTMFread</span><span class="sc10">=</span><span class="sc11">DTMFread</span><span class="sc10">+</span><span class="sc4">2</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc5">if</span><span class="sc10">(</span><span class="sc5">digitalRead</span><span class="sc10">(</span><span class="sc11">Q3</span><span class="sc10">)==</span><span class="sc16">HIGH</span><span class="sc10">){</span><span class="sc0"> </span><span class="sc2">//If Q3 reads HIGH, then add 4 to the DTMFread variable </span><span class="sc0"> </span><span class="sc11">DTMFread</span><span class="sc10">=</span><span class="sc11">DTMFread</span><span class="sc10">+</span><span class="sc4">4</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc5">if</span><span class="sc10">(</span><span class="sc5">digitalRead</span><span class="sc10">(</span><span class="sc11">Q4</span><span class="sc10">)==</span><span class="sc16">HIGH</span><span class="sc10">){</span><span class="sc0"> </span><span class="sc2">//If Q4 reads HIGH, then add 8 to the DTMFread variable </span><span class="sc0"> </span><span class="sc11">DTMFread</span><span class="sc10">=</span><span class="sc11">DTMFread</span><span class="sc10">+</span><span class="sc4">8</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc11">servoPosition</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc11">DTMFread</span><span class="sc0"> </span><span class="sc10">*</span><span class="sc0"> </span><span class="sc4">8.5</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc2">//Set the servoPosition varaible to the combined total of all the Q1 to Q4 readings. Multiply by 8.5 to amplify the servo rotation. </span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc11">SG5010</span><span class="sc10">.</span><span class="sc5">write</span><span class="sc10">(</span><span class="sc11">servoPosition</span><span class="sc10">);</span><span class="sc0"> </span><span class="sc2">//Set the servo's position according to the "servoPosition" variable. </span><span class="sc10">}</span></span></div></td> </tr></table></div> </P> <br> <br> <br> <br> <P> <h4>Fritzing Sketch</h4><br> Connect the Arduino to the MT8870 DTMF module, and to a Servo.<br> Use the following Fritzing sketch as a guide.<br> <br> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEii1x1pB-Y5nfuqjEwZo9fqp9RXK-m_1Lbym26xi5f93hh4TpsTalAneSq1mMNS7-2PafsTx16x2gNBWVGa0pcpDNifc-jGshmYmdbMUQYYgBDuEv4oqkkEl5wK1moJt6TlJZh-3wdRqnE/s1600/DTMF+Fritzing+2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" height="552" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEii1x1pB-Y5nfuqjEwZo9fqp9RXK-m_1Lbym26xi5f93hh4TpsTalAneSq1mMNS7-2PafsTx16x2gNBWVGa0pcpDNifc-jGshmYmdbMUQYYgBDuEv4oqkkEl5wK1moJt6TlJZh-3wdRqnE/s640/DTMF+Fritzing+2.jpg" width="640" /> </a> </div> <div class="separator" style="clear: both; text-align: center;"> (Click the image above to enlarge it) </div> </P> <!--separator --><img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /><br><h4>Discussion </h4><br>You will need to connect a cable from the DTMF module's 3.5mm port to that of your smart phone, computer, voice recorder or any other DTMF source of your choice.<br> <br><div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiwySNEpQkc5MisAYLSu0zpnxiN9Ri0adqkFqPJ5X0ln6UgecXzyxIiZmDbhAjjtgyk111v7Yl-9gP8gyS4J_TQNeDuxSdhLKv8kYDBlGn7knLvPExVxA_RQbO0R4hZ6cB0yBVUBlDv9U/s1600/3_5mm+jack.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiwySNEpQkc5MisAYLSu0zpnxiN9Ri0adqkFqPJ5X0ln6UgecXzyxIiZmDbhAjjtgyk111v7Yl-9gP8gyS4J_TQNeDuxSdhLKv8kYDBlGn7knLvPExVxA_RQbO0R4hZ6cB0yBVUBlDv9U/s400/3_5mm+jack.jpg" /> </a></div> <br> <br><P>When you power up your Arduino, the Servo motor should turn all the way to the left to it's zero position. Once the DTMF module receives a DTMF signal, it will identify the relevant frequecies as described in the table at the beginning of this tutorial, and produce a binary like output. You will notice the DTMF module's onboard LEDs light up when a tone is detected. Onboard LED (D5) will turn on for the length of the DTMF tone it just received, and turn off when the tone has stopped. On the other hand, the onboard LEDs (D1 to D4) will light up depending on the tone received, and will remain lit until the module receives another tone. The onboard LEDs are a visual representation of the voltages applied to the DTMF module's pins (Q1 to Q4, and STQ). Q1 matches D1, Q2 matches D2 etc etc. and STQ matches D5. <br> <br>You will notice that there are two STQ pins on the DTMF module. The STQ pin that is closest to Q4 will only go high when a DTMF tone is detected, and will remain high for the duration of the tone. The other STQ pin is the exact opposite. It will switch LOW when a tone is received and remain LOW for the duration of the tone. When there is no tone, this STQ pin will remain HIGH. The table below provides a summary of the DTMF module outputs, with a blue box representing a voltage applied to that pin (HIGH), whereas a black box indicates no voltage applied (LOW).<br> </P><P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg-VFGxSA1vbXkwo5d3v8dbO-I4Fvl-xETX4-5iIbqozd7UHZ2A4XBvS-1wDMgEn2eCD9eXyJinxyEVgJekSQOT9wJdPHucM8Zhjcu0KPZWurflX7fud7HzcbwCnMN6yqTgLDIqHlWZyY/s1600/DTMF+Module+Output.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg-VFGxSA1vbXkwo5d3v8dbO-I4Fvl-xETX4-5iIbqozd7UHZ2A4XBvS-1wDMgEn2eCD9eXyJinxyEVgJekSQOT9wJdPHucM8Zhjcu0KPZWurflX7fud7HzcbwCnMN6yqTgLDIqHlWZyY/s1600/DTMF+Module+Output.jpg" /> </a> </div></P><br> <br>In order to follow this project, you need a source of DTMF tones. You can produce DTMF tones using a touch-tone phone, or through the use of a DTMF Pad app. If you are feeling creative, you can create a DTMF song/tune like the one I posted on YouTube. You can see the video below:<br> <br><div class="separator" style="clear: both; text-align: center;"> <iframe width="640" height="420" src="https://www.youtube.com/embed/fpDa7a42SJE?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe></div><br> <br>As you can see from the video, I also recorded the DTMF tune onto a voice recorder, and was able to control the servo that way. If you are not feeling creative, you can visit <a href="http://onlinetonegenerator.com/dtmf.html">this website</a> to create DTMF tones from your browser. <!--separator --><img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <P> <h4>Concluding comments</h4><br> This project was very fun, and shows some novel ways to control your Arduino. After completing the project, I realised that I could use this module to alert me when new emails or messages arrive on my phone or computer. If you have the ability to change the email or message notification sound to a DTMF tone, you should be able to get the module and Arduino to respond accordingly. Oh well, maybe I'll save that project for another day. <br> <br> If this project helped you in anyway or if you use my code within your project, please let me know in the comments below. I would be interested to see what you did. </P> <!--separator --><img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <P> <div align="center"> If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br> <BR /> <BR /> Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br> Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br> I can also be found on <a href="https://www.pinterest.com/ArduinoBasics/">Pinterest</a> and <a href="https://instagram.com/arduinobasics">Instagram</a>. <br> Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.<br> </div></P><BR /> <BR /> <div class="separator" style="clear: both; text-align: center;"> <a href="http://arduinobasics.blogspot.com.au/p/arduino-basics-projects-page.html" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="145" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg1dds9EFMC242irm1Ncc1lQvFUd5g3E4oQ-lOwud94W_wcLtuLVZBbGCHvkN1-ktvfz6RW9fNKOC83ZyvvGT5ojvBnfobn8vBzShWLyffe34GiOEkGpXiZeZODOtofj104zmC01GQJWg/s320/ArduinoBasics_OpenLogo+on+Black.png" width="320" /></a></div> <br> <br><div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P><P> However, if you do not have a google profile... <br>Feel free to share this page with your friends in any way you see fit. </P></div></div><br /><br /><br /><br /><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" -->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-35798368408674197682015-07-17T11:11:00.000-07:002016-03-19T10:53:40.878-07:00NeoPixel Heart Beat Display<g:plusone></g:plusone><div style="text-align: justify;"> <P> <div class="separator" style="clear: both; text-align: center;"> <img style="border:3px double white;" height="139" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxHbDEjIZHlqJrLht7KG_SKTyhyy2wyV4WbPAf66QxSEX5VYck4megrwSDbEaQvQewOjfKmOOre41Si65ZhoNYx0d-0FmtAsZSmH_06Wyr0WslyndhXi3satBdYKGkrJpuRSpASAo0qvM/s400/Neopixel+Heart+Beat+Display+Title+image.jpg" width="640" /> </div><br /> </P> <P> <div> <P><h4>Project Description</h4> <br> In this project, your heart will control a mesmerising LED sequence on a <a href="http://openlab.com.au/shop/neopixel-digital-rgb-led-weatherproof-strip-60-led-1m/">5 metre Neopixel LED strip with a ws2812B chipset</a>. Every heart beat will trigger a LED animation that will keep you captivated and attached to your Arduino for ages. The good thing about this project is that it is relatively easy to set up, and requires no soldering. The hardest part is downloading and installing the FastLED library into the Arduino IDE, but that in itself is not too difficult. The inspiration and idea behind this project came from <a href="http://be.net/alimurtaza">Ali Murtaza</a>, who wanted to know how to get an LED strip to pulse to his heart beat. <br>  <br> Have a look at the video below to see this project in action. <br> <br> <br> <br> <H4>The Video</H4> <BR /> <div style="text-align: center;"> <iframe width="640" height="360" src="https://www.youtube.com/embed/KEqQTcDHwEw?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe> </div> </P> </div> </P> <br> <br> <P> <H4>Parts Required:</H4> <P> <ul> <li><a href="http://openlab.com.au/shop/arduino-uno-rev3/">Arduino UNO (or compatible board)</a></li> <li><a href="http://openlab.com.au/shop/neopixel-digital-rgb-led-weatherproof-strip-60-led-1m/">NeoPixel Digital RGB LED Weatherproof Strip 30 LED/m <b>(5m length)</b></a></li> <li><a href="https://www.adafruit.com/products/658">Adafruit 5V 10A switching power supply (PRODUCT ID: 658)</a></li> <li><a href="http://www.seeedstudio.com/depot/Grove-Earclip-Heart-Rate-Sensor-p-1116.html?cPath=25_29">Grove Ear-clip Heart Rate Sensor</a></li> <li><a href="http://www.seeedstudio.com/depot/Grove-Base-Shield-p-754.html">Grove Base Shield</a></li> <li><a href="http://openlab.com.au/shop/half-size-breadboard/">Breadboard</a></li> <li><a href="http://openlab.com.au/shop/breadboard-jumper-wire-set-140-pcs-pack/">Breadboard jumper wire</a></li> <li><a href="http://openlab.com.au/shop/resk-resistor-kit/">330 ohm resitor</a></li> <li><a href="http://www.jaycar.com.au/Passive-Components/Capacitors/Electrolytic/4700uF-16V-RB-Electrolytic-Capacitor---105oC/p/RE6243">4700uF 16V Electrolytic Capacitor (Jaycar Cat No. RE6243)</a></li> <li><a href="http://www.jaycar.com.au/Interconnect/Terminals-%26-Headers/Pluggable-Terminal-Blocks/6-Pole-PC-Mount-Pluggable-Header---5-08mm---Horizontal/p/HM3106">6 Pole PC Mount Pluggable Header (Jaycar Cat No. HM3106)</a></li> <li><a href="http://www.jaycar.com.au/Interconnect/Terminals-%26-Headers/Pluggable-Terminal-Blocks/6-Pole-PC-Mount-Pluggable-Terminal-Block-Socket---5-08mm/p/HM3126">6 Pole PC Mount Pluggable Terminal Block Socket (Jaycar Cat No. HM3126)</a></li> <br /> </ul> </P> </P> <br> <H4>Power Requirements</H4> <P> Before you start any LED strip project, the first thing you will need to think about is POWER. According to the <a href="https://learn.adafruit.com/adafruit-neopixel-uberguide/power">Adafruit website</a>, each individual NeoPixel LED can draw up to 60 milliamps at maximum brightness - white. Therefore the amount of current required for the entire strip will be way more than your Arduino can handle. If you try to power this LED strip directly from your Arduino, you run the risk of damaging not only your Arduino, but your USB port as well. The Arduino will be used to control the LED strip, but the LED strip will need to be powered by a separate power supply. The power supply you choose to use is important. It must provide the correct voltage, and must able to supply sufficient current.<br> <br> <h3 style="color: #7FD4FF;">Operating Voltage (5V)</h3> The operating voltage of the NeoPixel strip is 5 volts DC. Excessive voltage will damage/destroy your NeoPixels. <br> <br> <h3 style="color: #7FD4FF;">Current requirements (9.0 Amps)</h3> OpenLab recommend the use of a 5V 10A power supply. Having more Amps is OK, providing the output voltage is 5V DC. The LEDs will only draw as much current as they need. To calculate the amount of current this 5m strip can draw with all LEDs turned on at full brightness - white: <br> <br> <span style="color: #7FD4FF; font-size: large;">30 </span><span style="color: #7FD4FF;">NeoPixel LEDs</span> x <span style="color: #7FD4FF; font-size: large;">60</span><span style="color: #7FD4FF;">mA</span> x <span style="color: #7FD4FF; font-size: large;">5</span><span style="color: #7FD4FF;">m</span> = <span style="color: #7FD4FF; font-size: large;">9000</span><span style="color: #7FD4FF;">mA</span> = <span style="color: #7FD4FF; font-size: large;">9.0 </span><span style="color: #7FD4FF;">Amps for a 5 metre strip.</span><br> <br> Therefore a 5V 10A power supply would be able to handle the maximum current (9.0 Amps) demanded by a 5m NeoPixel strip containing a total of 150 LEDs. <br> <br>   </P> <br> <P> <H4>Arduino Libraries and IDE</H4> <BR /> Before you start to hook up any components, upload the following sketch to the Arduino microcontroller. I am assuming that you already have the <a href="http://www.arduino.cc/en/Main/Software">Arduino IDE</a> installed on your computer. If not, the IDE can be downloaded from <a href="http://www.arduino.cc/en/Main/Software">here</a>. <br> <br> The <a href="http://fastled.io/">FastLED library</a> is useful for simplifying the code for programming the NeoPixels. The latest "FastLED library" can be downloaded from <a href="https://github.com/FastLED/FastLED/releases">here</a>. I used FastLED library version <a href="https://github.com/FastLED/FastLED/tree/3.0.3">3.0.3</a> in this project.<br> <br> If you have a different LED strip or your NeoPixels have a different chipset, make sure to change the relevant lines of code to accomodate your hardware. I would suggest you try out a few of the <a href="https://github.com/FastLED/FastLED/tree/3.0.3/examples">FastLED library examples</a> before using the code below, so that you become more familiar with the library, and will be better equipped to make the necessary changes. If you have a 5 metre length of the NeoPixel 30 LED/m strip with the ws2812B chipset, then you will not have to make any modification below.<br> <br> <h4>ARDUINO CODE:</h4><br> <style type="text/css">span { } .sc0 { } .sc1 { font-family: 'Courier New'; font-size: 10pt; color: #808080; } .sc2 { font-family: 'Courier New'; font-size: 10pt; color: #808080; } .sc4 { font-family: 'Courier New'; font-size: 10pt; color: #000000; } .sc5 { font-family: 'Courier New'; font-size: 10pt; font-weight: bold; color: #D35400; } .sc9 { font-family: 'Courier New'; font-size: 10pt; color: #000000; } .sc10 { font-family: 'Courier New'; font-size: 10pt; font-weight: bold; color: #000040; } .sc11 { } .sc16 { font-family: 'Courier New'; font-size: 10pt; color: #00979C; } </style><div style="background: #ffffff; color: #000000; overflow:auto;width:auto;border:solid rgb(24,186,183);border-width: .6em .3em .3em .3em;padding: 0em 0em;"> <table> <tr> <td> <pre style="margin: 0; line-height: 125%; background: rgb(24,186,183); width: 1.9em"><span class="sc4">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140</span></pre> </td> <td> <div style="float: left; white-space: pre; line-height: 125%; background: #FFFFFF; "><span class="sc4"><span class="sc1">/* ================================================================================================ Project: NeoPixel Heart Beat Display Neopixel chipset: ws2812B (30 LED/m strip) Author: Scott C Created: 8th July 2015 Arduino IDE: 1.6.4 Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html Description: This sketch will display a heart beat on a 5m Neopixel LED strip. Requires a Grove Ear-clip heart rate sensor and a Neopixel strip. This project makes use of the FastLED library: http://fastled.io/ You may need to modify the code below to accomodate your specific LED strip. See the FastLED library site for more details. ================================================================================================== */</span><span class="sc0"> </span><span class="sc2">//This project needs the FastLED library - link in the description. </span><span class="sc9">#include "FastLED.h" </span><span class="sc0"></span><span class="sc2">//The total number of LEDs being used is 150 </span><span class="sc9">#define NUM_LEDS 150 </span><span class="sc0"></span><span class="sc2">// The data pin for the NeoPixel strip is connected to digital Pin 6 on the Arduino </span><span class="sc9">#define DATA_PIN 6 </span><span class="sc0"></span><span class="sc2">//Attach the Grove Ear-clip heart rate sensor to digital pin 2 on the Arduino. </span><span class="sc9">#define EAR_CLIP 2 </span><span class="sc0"></span><span class="sc2">//Initialise the LED array </span><span class="sc5">CRGB</span><span class="sc0"> </span><span class="sc11">leds</span><span class="sc10">[</span><span class="sc11">NUM_LEDS</span><span class="sc10">];</span><span class="sc0"> </span><span class="sc2">//Initialise the global variables used to control the LED animation </span><span class="sc16">int</span><span class="sc0"> </span><span class="sc11">ledNum</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">0</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc2">//Keep track of the LEDs </span><span class="sc16">boolean</span><span class="sc0"> </span><span class="sc11">beated</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc5">false</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc2">//Used to identify when the heart has beated </span><span class="sc16">int</span><span class="sc0"> </span><span class="sc11">randomR</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">0</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc2">//randomR used to randomise the fade-out of the LEDs </span><span class="sc0"> </span><span class="sc2">//================================================================================================ // setup() : Is used to initialise the LED strip //================================================================================================ </span><span class="sc16">void</span><span class="sc0"> </span><span class="sc11">setup</span><span class="sc10">()</span><span class="sc0"> </span><span class="sc10">{</span><span class="sc0"> </span><span class="sc5">FastLED</span><span class="sc10">.</span><span class="sc5">addLeds</span><span class="sc10"><</span><span class="sc16">NEOPIXEL</span><span class="sc10">,</span><span class="sc11">DATA_PIN</span><span class="sc10">>(</span><span class="sc11">leds</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">NUM_LEDS</span><span class="sc10">);</span><span class="sc0"> </span><span class="sc2">//Set digital pin 2 (Ear-clip heart rate sensor) as an INPUT </span><span class="sc0"> </span><span class="sc5">pinMode</span><span class="sc10">(</span><span class="sc11">EAR_CLIP</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc16">INPUT</span><span class="sc10">);</span><span class="sc0"></span><span class="sc10">}</span><span class="sc0"> </span><span class="sc2">//================================================================================================ // loop() : Take readings from the Ear-clip sensor, and display the animation on the LED strip //================================================================================================ </span><span class="sc16">void</span><span class="sc0"> </span><span class="sc11">loop</span><span class="sc10">()</span><span class="sc0"> </span><span class="sc10">{</span><span class="sc0"> </span><span class="sc2">//If the Ear-clip sensor moves from LOW to HIGH, call the beatTriggered method </span><span class="sc0"> </span><span class="sc5">if</span><span class="sc10">(</span><span class="sc11">digitalRead</span><span class="sc10">(</span><span class="sc11">EAR_CLIP</span><span class="sc10">)></span><span class="sc4">0</span><span class="sc10">){</span><span class="sc0"> </span><span class="sc2">//beatTriggered() is only called if the 'beated' variable is false. </span><span class="sc0"> </span><span class="sc2">//This prevents multiple triggers from the same beat. </span><span class="sc0"> </span><span class="sc5">if</span><span class="sc10">(!</span><span class="sc11">beated</span><span class="sc10">){</span><span class="sc0"> </span><span class="sc11">beatTriggered</span><span class="sc10">();</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc5">else</span><span class="sc0"> </span><span class="sc10">{</span><span class="sc0"> </span><span class="sc11">beated</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc5">false</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc2">//Change the 'beated' variable to false when the Ear-clip heart rate sensor is reading LOW. </span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc2">//Fade the LEDs by 1 unit/cycle, when the heart is at 'rest' (i.e. between beats) </span><span class="sc0"> </span><span class="sc11">fadeLEDs</span><span class="sc10">(</span><span class="sc4">5</span><span class="sc10">);</span><span class="sc0"></span><span class="sc10">}</span><span class="sc0"> </span><span class="sc2">//================================================================================================ // beatTriggered() : This is the LED animation sequence when the heart beats //================================================================================================ </span><span class="sc16">void</span><span class="sc0"> </span><span class="sc11">beatTriggered</span><span class="sc10">(){</span><span class="sc0"> </span><span class="sc2">//Ignite 30 LEDs with a red value between 0 to 255 </span><span class="sc0"> </span><span class="sc5">for</span><span class="sc10">(</span><span class="sc16">int</span><span class="sc0"> </span><span class="sc11">i</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">0</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc11">i</span><span class="sc10"><</span><span class="sc4">30</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc11">i</span><span class="sc10">++){</span><span class="sc0"> </span><span class="sc2">//The red channel is randomised to a value between 0 to 255 </span><span class="sc0"> </span><span class="sc11">leds</span><span class="sc10">[</span><span class="sc11">ledNum</span><span class="sc10">].</span><span class="sc11">r</span><span class="sc10">=</span><span class="sc11">random8</span><span class="sc10">();</span><span class="sc0"> </span><span class="sc5">FastLED</span><span class="sc10">.</span><span class="sc5">show</span><span class="sc10">();</span><span class="sc0"> </span><span class="sc2">//Call the fadeLEDs method after every 3rd LED is lit. </span><span class="sc0"> </span><span class="sc5">if</span><span class="sc10">(</span><span class="sc11">ledNum</span><span class="sc10">%</span><span class="sc4">3</span><span class="sc10">==</span><span class="sc4">0</span><span class="sc10">){</span><span class="sc0"> </span><span class="sc11">fadeLEDs</span><span class="sc10">(</span><span class="sc4">5</span><span class="sc10">);</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc2">//Move to the next LED </span><span class="sc0"> </span><span class="sc11">ledNum</span><span class="sc10">++;</span><span class="sc0"> </span><span class="sc2">//Make sure to move back to the beginning if the animation falls off the end of the strip </span><span class="sc0"> </span><span class="sc5">if</span><span class="sc10">(</span><span class="sc11">ledNum</span><span class="sc10">>(</span><span class="sc11">NUM_LEDS</span><span class="sc10">-</span><span class="sc4">1</span><span class="sc10">)){</span><span class="sc0"> </span><span class="sc11">ledNum</span><span class="sc10">=</span><span class="sc4">0</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc2">//Ignite 20 LEDS with a blue value between 0 to 120 </span><span class="sc0"> </span><span class="sc5">for</span><span class="sc10">(</span><span class="sc16">int</span><span class="sc0"> </span><span class="sc11">i</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">0</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc11">i</span><span class="sc10"><</span><span class="sc4">20</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc11">i</span><span class="sc10">++){</span><span class="sc0"> </span><span class="sc2">//The blue channel is randomised to a value between 0 to 120 </span><span class="sc0"> </span><span class="sc11">leds</span><span class="sc10">[</span><span class="sc11">ledNum</span><span class="sc10">].</span><span class="sc11">b</span><span class="sc10">=</span><span class="sc11">random8</span><span class="sc10">(</span><span class="sc4">120</span><span class="sc10">);</span><span class="sc0"> </span><span class="sc5">FastLED</span><span class="sc10">.</span><span class="sc5">show</span><span class="sc10">();</span><span class="sc0"> </span><span class="sc2">//Call the fadeLEDs method after every 3rd LED is lit. </span><span class="sc0"> </span><span class="sc5">if</span><span class="sc10">(</span><span class="sc11">ledNum</span><span class="sc10">%</span><span class="sc4">3</span><span class="sc10">==</span><span class="sc4">0</span><span class="sc10">){</span><span class="sc0"> </span><span class="sc11">fadeLEDs</span><span class="sc10">(</span><span class="sc4">5</span><span class="sc10">);</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc2">//Move to the next LED </span><span class="sc0"> </span><span class="sc11">ledNum</span><span class="sc10">++;</span><span class="sc0"> </span><span class="sc2">//Make sure to move back to the beginning if the animation falls off the end of the strip </span><span class="sc0"> </span><span class="sc5">if</span><span class="sc10">(</span><span class="sc11">ledNum</span><span class="sc10">>(</span><span class="sc11">NUM_LEDS</span><span class="sc10">-</span><span class="sc4">1</span><span class="sc10">)){</span><span class="sc0"> </span><span class="sc11">ledNum</span><span class="sc10">=</span><span class="sc4">0</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc2">//Change the 'beated' variable to true, until the Ear-Clip sensor reads LOW. </span><span class="sc0"> </span><span class="sc11">beated</span><span class="sc10">=</span><span class="sc5">true</span><span class="sc10">;</span><span class="sc0"></span><span class="sc10">}</span><span class="sc0"> </span><span class="sc2">//================================================================================================ // fadeLEDs() : The fading effect of the LEDs when the Heart is resting (Ear-clip reads LOW) //================================================================================================ </span><span class="sc16">void</span><span class="sc0"> </span><span class="sc11">fadeLEDs</span><span class="sc10">(</span><span class="sc16">int</span><span class="sc0"> </span><span class="sc11">fadeVal</span><span class="sc10">){</span><span class="sc0"> </span><span class="sc5">for</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc16">int</span><span class="sc0"> </span><span class="sc11">i</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc4">0</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc11">i</span><span class="sc10"><</span><span class="sc11">NUM_LEDS</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc11">i</span><span class="sc10">++){</span><span class="sc0"> </span><span class="sc2">//Fade every LED by the fadeVal amount </span><span class="sc0"> </span><span class="sc11">leds</span><span class="sc10">[</span><span class="sc11">i</span><span class="sc10">].</span><span class="sc5">fadeToBlackBy</span><span class="sc10">(</span><span class="sc0"> </span><span class="sc11">fadeVal</span><span class="sc0"> </span><span class="sc10">);</span><span class="sc0"> </span><span class="sc2">//Randomly re-fuel some of the LEDs that are currently lit (1% chance per cycle) </span><span class="sc0"> </span><span class="sc2">//This enhances the twinkling effect. </span><span class="sc0"> </span><span class="sc5">if</span><span class="sc10">(</span><span class="sc11">leds</span><span class="sc10">[</span><span class="sc11">i</span><span class="sc10">].</span><span class="sc11">r</span><span class="sc10">></span><span class="sc4">10</span><span class="sc10">){</span><span class="sc0"> </span><span class="sc11">randomR</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc11">random8</span><span class="sc10">(</span><span class="sc4">100</span><span class="sc10">);</span><span class="sc0"> </span><span class="sc5">if</span><span class="sc10">(</span><span class="sc11">randomR</span><span class="sc10"><</span><span class="sc4">1</span><span class="sc10">){</span><span class="sc0"> </span><span class="sc2">//Set the red channel to a value of 80 </span><span class="sc0"> </span><span class="sc11">leds</span><span class="sc10">[</span><span class="sc11">i</span><span class="sc10">].</span><span class="sc11">r</span><span class="sc10">=</span><span class="sc4">80</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc2">//Increase the green channel to 20 - to add to the effect </span><span class="sc0"> </span><span class="sc11">leds</span><span class="sc10">[</span><span class="sc11">i</span><span class="sc10">].</span><span class="sc11">g</span><span class="sc10">=</span><span class="sc4">20</span><span class="sc10">;</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc10">}</span><span class="sc0"> </span><span class="sc5">FastLED</span><span class="sc10">.</span><span class="sc5">show</span><span class="sc10">();</span><span class="sc0"></span><span class="sc10">}</span></span></div> </td> </tr> </table></div></div> </P> <br> <br> <h4>NeoPixel Strip connection </h4> <P> The NeoPixel strip is rolled up when you first get it. You will notice that there are wires on both sides of the strip. This allows you to chain LED strips together to make longer strips. The more LEDs you have, the more current you will need. Connect your Arduino and power supply to the left side of the strip, with the arrows pointing to the right. (i.e. the side with the "female" jst connector). <br clear="all"> <div class="separator" style="clear: both; text-align: left;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYVsgcpympMR5okz36o3O3lTEtpAek4lk6UYf3qGlLR06NqjO0-RXgqTpdKBTsBzlV-3GM1K9VmDz_5qvqxp7R0JYP6UXHEl7JHoF7O3qOPPT_uxySRmPrXMksAZqf8XU6kJQqzscRVWs/s1600/Neopixel+strip+left+side.jpg" width="640" /></div> <br /> <br> </P> <P><h3 style="color: #7FD4FF;">NeoPixel Strip Wires</h3> There are 5 wires that come pre-attached to either side of the LED strip. <br> <br> <div class="separator" style="clear: both; text-align: left;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgJ33Ca42Ei1wl8YCqxlOA_g-CYldahwclIvRcXpXrYU-PNwT-56HYNDJszJDsqprvT3Jj-ShcOZe6N0UMtDUxT_5-4RMYVpNAhTpSPnrkInsFMaqVmzv2dev4g_PLSsLTFSS_ReWG8Wk/s640/NeoPixel+Wires.jpg" width="400" /> </div><br> <br> You don't have to use ALL FIVE wires, however you will need at least one of each colour: red, white & green.<br> <br> <div class="separator" style="clear: both; text-align: left;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiC2Ry50AfXm9Dm7ZHqr_8CuwdEW8v-rzx_j1zjX5iG2LJP6m9lV5ujwoNM5KQ5jm4oeWUnq2au1nWysug6q-0mBTbDXf0g8hgLcxJo3IxGgjFsL8Pg6S4D6q6FDBUmDgMLYOdQ8iuAYSg/s400/Terminal+connection3.jpg" width="400" /> </div><br> <br> <h3 style="color: #7FD4FF";>Fritzing sketch</h3> The following diagram will show you how to wire everything together <br> <br> <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_3zFxpjX2lv2LU_mkIbIbSYSgGEHUdcMNdiSqckPvBDFuZiGE-Sh0BXLjeCrQsF1d5N6L8kNbdiIBH3CwLUUR_DcnmET6lOt7_L38-qlUaqhBCBsWGl-M65B0Z3lnPQCYd8ou6e211TI/s1600/NeoPixel+Heart+Beat+Fritzing+sketch.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img style="border:3px double white;" height="398" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_3zFxpjX2lv2LU_mkIbIbSYSgGEHUdcMNdiSqckPvBDFuZiGE-Sh0BXLjeCrQsF1d5N6L8kNbdiIBH3CwLUUR_DcnmET6lOt7_L38-qlUaqhBCBsWGl-M65B0Z3lnPQCYd8ou6e211TI/s640/NeoPixel+Heart+Beat+Fritzing+sketch.jpg" width="640" /></a>(click to enlarge)</div> <br> <P> <h3 style="color: #7FD4FF;">Arduino Power considerations</h3> Please note that the Arduino is powered by a USB cable. <br> If you plan to power the Arduino from your power supply, you will need to disconnect the USB cable from the Arduino FIRST, then connect a wire from the 5V line on the Power supply to the 5V pin on the Arduino. Do NOT connect the USB cable to the Arduino while the 5V wire is connected to the Arduino.<br> <br> <br> <br> <h3 style="color: #7FD4FF;">Large Capacitor</h3> <a href="https://learn.adafruit.com/adafruit-neopixel-uberguide/power">Adafruit</a> also recommend the use of a large capacitor across the + and - terminals of the LED strip to "prevent the initial onrush of current from damaging the pixels". Adafruit recommends a capacitor that is 1000uF, 6.3V or higher. I used a 4700uF 16V Electrolytic Capacitor. <br> <br> <div class="separator" style="clear: both; text-align: left;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHfICzvPQrq2eQzX1LVpBjvnx0jgd7lZ7ARfFDKB4HDsyho0dKgw0z8qWcoUCcRiDhyDEp-5MlzRfldUtIZRshe3nW_yPye2KTSajhsC9uzv3jp7OfiRJJ9cbQXVW5A1TJwExn4sQc5uI/s400/Capacitor.jpg" width="400" /> </div> <br> <br> <h3 style="color: #7FD4FF;">Resistor on Data Pin</h3> Another recommendation from <a href="https://learn.adafruit.com/adafruit-neopixel-uberguide/power">Adafruit</a> is to place a "300 to 500 Ohm resistor" between the Arduino's data pin and the data input on the first NeoPixel to prevent voltage spikes that can damage the first pixel. I used a 330 Ohm resistor. <br> <br> <div class="separator" style="clear: both; text-align: left;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3L5JGo-Vmm0NfQiqw45j9IBZjSb3jAZ17ch_kSrFKZjl0eM7yMRU9sK7T9mR2kFxZTwciSNcBDm6twXnBoqH0mKQtjH1yicJfNktFoGAWYwj85AvDsPBl47cYDpnqdylRh96-gqijNOs/s400/330+ohm+resistor.jpg" width="400" /> </div> <br> <br> <h3 style="color: #7FD4FF;">Grove Ear-clip heart rate sensor connection</h3> The Grove Base shield makes it easy to connect Grove modules to the Arduino. If you have a Grove Base shield, you will need to connect the Ear-clip heart rate sensor to Digital pin 2 as per the diagram below. <br> <br> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxTVvTviO_sYFlVeBokf16tHk3XCOiHMG8MesTWk9wf-co0pXbeBIbdhBOsDJHNl5tRnbm3OXmmCTA-vr6DIki1C_jJzf7zySin_Ds0I5a6mT-9N1SAJuxuDdoLRzuA-I0yw-JKLs3AhQ/s1600/Heart+Beat+Sensor+to+Grove+Base+Shield.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" height="155" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxTVvTviO_sYFlVeBokf16tHk3XCOiHMG8MesTWk9wf-co0pXbeBIbdhBOsDJHNl5tRnbm3OXmmCTA-vr6DIki1C_jJzf7zySin_Ds0I5a6mT-9N1SAJuxuDdoLRzuA-I0yw-JKLs3AhQ/s640/Heart+Beat+Sensor+to+Grove+Base+Shield.jpg" width="640" /></a> </div><br> <br> <h3 style="color: #7FD4FF;">Completed construction</h3> Once you have everything connected, you can plug the USB cable into the Arduino, and turn on the LED power supply. Attach the ear-clip to your ear (or to your finger) and allow a few seconds to allow the sensor to register your pulse. The LED strip will light up with every heart beat with an animation that moves from one end of the strip to the other in just three heart beats. When the ear-clip is not connected to your ear or finger, the LEDs should remain off. However, the ear clip may "trigger" a heart beat when opening or closing the clip.<br> <br> Here is a picture of all the components (fully assembled).<br> <br> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqQyDWV-GGTo6gLuU08dQg6P1rLPUuRWXjK-nSL6CfkR9uyZDXDSDJiVd2S9L8LriL9CXzrg4ZY1yZ5t8vxv2YlACxj6Zwgwt1X24dMEdfD8i-RTE5N_AwbT60Ip_Elg4uVI_Vl1P2b6A/s1600/Neopixel+circuit+real.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqQyDWV-GGTo6gLuU08dQg6P1rLPUuRWXjK-nSL6CfkR9uyZDXDSDJiVd2S9L8LriL9CXzrg4ZY1yZ5t8vxv2YlACxj6Zwgwt1X24dMEdfD8i-RTE5N_AwbT60Ip_Elg4uVI_Vl1P2b6A/s640/Neopixel+circuit+real.jpg" /></a> </div> </P> <!--separator --><img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /><P> <div style="text-align: justify;"> <H4>Concluding comments</H4> <br> This very affordable LED strip allows you to create amazing animations over a greater distance. I thought that having less LEDs per metre would make the animations look "jittery", but I was wrong, they look amazing. One of the good things about this strip is the amount of space between each Neopixel, allowing you to easily cut and join the strip to the size and shape you need. <br> <br> This LED strip is compatible with the FastLED library, which makes for easy LED animation programming. While I used this LED strip to display my heart beat, you could just as easily use it to display the output of any other sensor attached to the Arduino.<br> <br> </div> <div class="separator" style="clear: both; text-align: center;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3LH3uflc5yvSr0XX2mnTmnPHUhygPDOBlNZux8CUjc4gQUukRz7NXYeZvjh9JsdQwK-N7PxOAJl7ZRnMh_c0_-4l1tAyIuqeG3Hz8sFq7hr72yifFNNuW1kpmP81-w_20nDGLeXkTn4s/s400/NeoPixel+Heart+Beat+Reel.jpg" width="640" /> </div> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> <div align="center"> If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br> <BR /> <BR /> Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br> Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br> I can also be found on <a href="https://www.pinterest.com/ArduinoBasics/">Pinterest</a> and <a href="https://instagram.com/arduinobasics">Instagram</a>. <br> Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.<br> </div> </P> <BR /> <BR /> <div class="separator" style="clear: both; text-align: center;"> <a href="http://arduinobasics.blogspot.com.au/p/arduino-basics-projects-page.html" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="145" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg1dds9EFMC242irm1Ncc1lQvFUd5g3E4oQ-lOwud94W_wcLtuLVZBbGCHvkN1-ktvfz6RW9fNKOC83ZyvvGT5ojvBnfobn8vBzShWLyffe34GiOEkGpXiZeZODOtofj104zmC01GQJWg/s320/ArduinoBasics_OpenLogo+on+Black.png" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;"></div> <br> <br><div class="separator" style="clear: both; text-align: center;">This project would not have been possible without <a href="http://openlab.com.au/">OpenLab's</a> collaborative effort.<br>Please visit their site for more cool projects. </div> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> However, if you do not have a google profile... <br>Feel free to share this page with your friends in any way you see fit. </P></P><br /><br /><br /><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" -->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-82002451240540686972015-07-01T19:00:00.000-07:002016-03-19T10:53:40.913-07:00NeoPixel Playground<g:plusone></g:plusone><div style="text-align: justify;"> <P> <div style="text-align: center;"> <iframe width="640" height="360" src="https://www.youtube.com/embed/POV-qvEx1ws?rel=0" frameborder="0" allowfullscreen></iframe> </div><br /> </P> <P> <div> <P> The NeoPixel Digital RGB LED Strip (144 LED/m) is a really impressive product that will have you lighting up your room in next to no time. The 144 individually addressable LEDs packed onto a 1 metre flexible water resistant strip, enables a world of luminescent creativity that will blow your blinking Arduino friends away. The following tutorial will show you how to create an immersive and interactive LED display using an Arduino UNO, a potentiometer and an accelerometer. There will be a total of FIVE LED sequences to keep you entertained or you can create your own ! <br> <br> This tutorial was specifically designed to work with the <a href="http://openlab.com.au/shop/neopixel-digital-rgb-led-strip-144-led/">144 Neopixel Digital RGB LED strip</a> with the ws2812B chipset. <br> <BR /> </P> </div> </P> <P> <H4>Parts Required:</H4> <P> <ul> <li><a href="http://openlab.com.au/shop/arduino-uno-rev3/">Arduino UNO (or compatible board)</a></li> <li><a href="https://www.adafruit.com/products/658">Adafruit 5V 10A switching power supply (PRODUCT ID: 658)</a></li> <li><a href="http://openlab.com.au/shop/neopixel-digital-rgb-led-strip-144-led/">NeoPixel Digital RGB LED Strip (144 LED/m)</a></li> <li><a href="http://openlab.com.au/shop/sensor-assortment-pack/">Potentiometer </a></li> <li><a href="http://www.freetronics.com.au/products/3-axis-accelerometer-module#.VXR-1uaferg">3-Axis Accelerometer Module</a></li> <li><a href="http://openlab.com.au/shop/half-size-breadboard/">Breadboard</a></li> <li><a href="http://openlab.com.au/shop/breadboard-jumper-wire-set-140-pcs-pack/">Breadboard jumper wire</a></li> <li><a href="http://openlab.com.au/shop/resk-resistor-kit/">300 ohm resitor</a></li> <li><a href="http://www.jaycar.com.au/Passive-Components/Capacitors/Electrolytic/4700uF-16V-RB-Electrolytic-Capacitor---105oC/p/RE6243">4700uF 16V Electrolytic Capacitor (Jaycar Cat No. RE6243)</a></li> <li><a href="http://www.jaycar.com.au/Interconnect/Terminals-%26-Headers/Pluggable-Terminal-Blocks/6-Pole-PC-Mount-Pluggable-Header---5-08mm---Horizontal/p/HM3106">6 Pole PC Mount Pluggable Header (Jaycar Cat No. HM3106)</a></li> <li><a href="http://www.jaycar.com.au/Interconnect/Terminals-%26-Headers/Pluggable-Terminal-Blocks/6-Pole-PC-Mount-Pluggable-Terminal-Block-Socket---5-08mm/p/HM3126">6 Pole PC Mount Pluggable Terminal Block Socket (Jaycar Cat No. HM3126)</a></li> <li><a href="http://www.jaycar.com.au/Service-Aids/Tapes/Other/Double-sided-Mounting-Tape---10m/p/NM2821">Double Sided mounting tape - 10m (Jaycar Cat No. NM2821) - optional</a></li> <br /> </ul> </P> </P> <H4>Power Requirements</H4> <P> Before you start any LED strip project, the first thing you will need to think about is POWER. According to the <a href="https://learn.adafruit.com/adafruit-neopixel-uberguide/power">Adafruit website</a>, each individual NeoPixel LED can draw up to 60 milliamps at maximum brightness - white. Therefore the amount of current required for the entire strip will be way more than your Arduino can handle. If you try to power this LED strip directly from your Arduino, you run the risk of damaging not only your Arduino, but your USB port as well. The Arduino will be used to control the LED strip, but the LED strip will need to be powered by a separate power supply. The power supply you choose to use is important. It must provide the correct voltage, and must able to supply sufficient current.<br> <br> <h3><span style="color: #7FD4FF;">Operating Voltage(5V)</span></h3> The operating voltage of the NeoPixel strip is 5 volts DC. Excessive voltage will damage/destroy your NeoPixels. <br> <br> <span style="color: #7FD4FF;"><h3>Current requirements (8.6 Amps)</h3></span> OpenLab recommend the use of a 5V 10A power supply. Having more Amps is OK, providing the output voltage is 5V DC. The LEDs will only draw as much current as they need. To calculate the amount of current this 1m strip can draw with all LEDs turned on at full brightness - white: <br> <br> <span style="color: #7FD4FF;"><span style="font-size: large;">144</span> NeoPixel LEDs</span> x <span style="color: #7FD4FF;"><span style="font-size: large;">60</span> mA</span> x <span style="color: #7FD4FF;"><span style="font-size: large;">1</span> m</span> = <span style="color: #7FD4FF;"><span style="font-size: large;">8640</span> mA</span> = <span style="color: #7FD4FF;"><span style="font-size: large;">8.64</span> Amps for a 1 metre strip.</span><br> <br> Therefore a 5V 10A power supply would be able to handle the maximum current (8.6 Amps) demanded by a single 1m NeoPixel strip of 144 LEDs. <br> <br>   <br> </P> <P> <H4>Arduino Libraries and IDE</H4> <BR /> Before you start to hook up any components, upload the following sketch to the Arduino microcontroller. I am assuming that you already have the <a href="http://www.arduino.cc/en/Main/Software">Arduino IDE</a> installed on your computer. If not, the IDE can be downloaded from <a href="http://www.arduino.cc/en/Main/Software">here</a>. <br> <br> The <a href="http://fastled.io/">FastLED library</a> is useful for simplifying the code for programming the NeoPixels. The latest "FastLED library" can be downloaded from <a href="https://github.com/FastLED/FastLED/releases">here</a>. I used FastLED library version <a href="https://github.com/FastLED/FastLED/tree/3.0.3">3.0.3</a> in this project.<br> <br> If you have a different LED strip or your NeoPixels have a different chipset, make sure to change the relevant lines of code to accomodate your hardware. I would suggest you try out a few of the <a href="https://github.com/FastLED/FastLED/tree/3.0.3/examples">FastLED library examples</a> before using the code below, so that you become more familiar with the library, and will be better equipped to make the necessary changes. If you have a single 144 NeoPixel LED/m strip with the ws2812B chipset, then you will not have to make any modifications below (unless you want to).<br> <br> <h4>ARDUINO CODE:</h4><br> <div style="background: #ffffff; color: #000000; overflow:auto;width:auto;border:solid rgb(24,186,183);border-width: .6em .3em .3em .3em;padding: 0em 0em;"> <table> <tr> <td> <pre style="margin: 0; line-height: 125%; background: rgb(24,186,183); width: 1.9em"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br />282<br />283<br />284<br />285<br />286<br />287<br />288<br />289<br />290<br />291<br />292<br />293<br />294<br />295<br />296<br />297<br />298<br />299<br />300<br />301<br />302<br />303<br />304<br />305<br />306<br />307<br />308<br />309<br />310<br />311<br />312<br />313<br />314<br />315<br />316<br />317<br />318 </pre> </td> <td> <pre style="margin: 0; line-height: 126%"><br /> <!-- INSERT ARDUINO CODE HERE --><br /><pre><br /><span style="color: #434F54;">/* ==================================================================================================================================================</span><br /><span style="color: #434F54;"> Project: NeoPixel Playground</span><br /><span style="color: #434F54;">Neopixel chipset: ws2812B (144 LED/m strip)</span><br /><span style="color: #434F54;"> Author: Scott C</span><br /><span style="color: #434F54;"> Created: 12th June 2015</span><br /><span style="color: #434F54;"> Arduino IDE: 1.6.4</span><br /><span style="color: #434F54;"> Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html</span><br /><span style="color: #434F54;"> Description: This project will allow you to cycle through and control five LED</span><br /><span style="color: #434F54;"> animation sequences using a potentiometer and an accelerometer</span><br /><span style="color: #434F54;"> Sequence 1: Cylon with Hue Control Control: Potentiometer only</span><br /><span style="color: #434F54;"> Sequence 2: Cylon with Brightness Control Control: Potentiometer only</span><br /><span style="color: #434F54;"> Sequence 3: Comet effect with Hue and direction control Control: Potentiometer and Accelerometer (Y axis only)</span><br /><span style="color: #434F54;"> Sequence 4: FireStarter / Rainbow effect with Hue and Direction control Control: Potentiometer and Accelerometer (Y axis only)</span><br /><span style="color: #434F54;"> Sequence 5: Digital Spirit Level Control: Accelerometer only (Y axis)</span><br /><span style="color: #434F54;"> </span><br /><span style="color: #434F54;"> This project makes use of the FastLED library. Some of the code below was adapted from the FastLED library examples (eg. Cylon routine).</span><br /><span style="color: #434F54;"> The Comet, FireStarter and Digital Spirit Level sequence was designed by ScottC.</span><br /><span style="color: #434F54;"> The FastLED library can be found here: http://fastled.io/</span><br /><span style="color: #434F54;"> You may need to modify the code below to accomodate your specific LED strip. See the FastLED library site for more details.</span><br /><span style="color: #434F54;">===================================================================================================================================================== */</span><br /><br /><span style="color: #434F54;">//This project needs the FastLED library - link in the description.</span><br />#include <span style="color: #006699;">"FastLED.h"</span><br /><br /><span style="color: #434F54;">//The total number of LEDs being used is 144</span><br />#define NUM_LEDS 144<br /><br /><span style="color: #434F54;">// The data pin for the NeoPixel strip is connected to digital Pin 6 on the Arduino</span><br />#define DATA_PIN 6<br /><br /><span style="color: #434F54;">//Initialise the LED array, the LED Hue (ledh) array, and the LED Brightness (ledb) array.</span><br /><span style="color: #D35400;"><b>CRGB</b></span> leds[NUM_LEDS];<br /><span style="color: #00979C;">byte</span> ledh[NUM_LEDS];<br /><span style="color: #00979C;">byte</span> ledb[NUM_LEDS];<br /><br /><span style="color: #434F54;">//Pin connections</span><br /><span style="color: #00979C;">const</span> <span style="color: #00979C;">int</span> potPin = A0; <span style="color: #434F54;">// The potentiometer signal pin is connected to Arduino's Analog Pin 0</span><br /><span style="color: #00979C;">const</span> <span style="color: #00979C;">int</span> yPin = A4; <span style="color: #434F54;">// Y pin on accelerometer is connected to Arduino's Analog Pin 4</span><br /> <span style="color: #434F54;">// The accelerometer's X Pin and the Z Pin were not used in this sketch</span><br /><br /><span style="color: #434F54;">//Global Variables ---------------------------------------------------------------------------------</span><br /><span style="color: #00979C;">byte</span> potVal; <span style="color: #434F54;">// potVal: stores the potentiometer signal value</span><br /><span style="color: #00979C;">byte</span> prevPotVal=0; <span style="color: #434F54;">// prevPotVal: stores the previous potentiometer value</span><br /><span style="color: #00979C;">int</span> LEDSpeed=1; <span style="color: #434F54;">// LEDSpeed: stores the "speed" of the LED animation sequence</span><br /><span style="color: #00979C;">int</span> maxLEDSpeed = 50; <span style="color: #434F54;">// maxLEDSpeed: identifies the maximum speed of the LED animation sequence</span><br /><span style="color: #00979C;">int</span> LEDAccel=0; <span style="color: #434F54;">// LEDAccel: stores the acceleration value of the LED animation sequence (to speed it up or slow it down)</span><br /><span style="color: #00979C;">int</span> LEDPosition=72; <span style="color: #434F54;">// LEDPosition: identifies the LED within the strip to modify (leading LED). The number will be between 0-143. (Zero to NUM_LEDS-1)</span><br /><span style="color: #00979C;">int</span> oldPos=0; <span style="color: #434F54;">// oldPos: holds the previous position of the leading LED</span><br /><span style="color: #00979C;">byte</span> hue = 0; <span style="color: #434F54;">// hue: stores the leading LED's hue value</span><br /><span style="color: #00979C;">byte</span> intensity = 150; <span style="color: #434F54;">// intensity: the default brightness of the leading LED</span><br /><span style="color: #00979C;">byte</span> bright = 80; <span style="color: #434F54;">// bright: this variable is used to modify the brightness of the trailing LEDs</span><br /><span style="color: #00979C;">int</span> animationDelay = 0; <span style="color: #434F54;">// animationDelay: is used in the animation Speed calculation. The greater the animationDelay, the slower the LED sequence.</span><br /><span style="color: #00979C;">int</span> effect = 0; <span style="color: #434F54;">// effect: is used to differentiate and select one out of the four effects</span><br /><span style="color: #00979C;">int</span> sparkTest = 0; <span style="color: #434F54;">// sparkTest: variable used in the "sparkle" LED animation sequence </span><br /><span style="color: #00979C;">boolean</span> constSpeed = <span style="color: #00979C;">false</span>; <span style="color: #434F54;">// constSpeed: toggle between constant and variable speed.</span><br /><br /><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #434F54;">// setup() : Is used to initialise the LED strip</span><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #00979C;">void</span> <span style="color: #5E6D03;">setup</span>() {<br /> <span style="color: #D35400;">delay</span>(2000); <span style="color: #434F54;">//Delay for two seconds to power the LEDS before starting the data signal on the Arduino</span><br /> <span style="color: #D35400;"><b>FastLED</b></span>.<span style="color: #D35400;">addLeds</span><<span style="color: #006699;">WS2812B</span>, DATA_PIN, <span style="color: #006699;">GRB</span>>(leds, NUM_LEDS); <span style="color: #434F54;">//initialise the LED strip </span><br />}<br /><br /><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #434F54;">// loop() : The Arduino will take readings from the potentiometer and accelerometer to control the LED strip</span><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #00979C;">void</span> <span style="color: #5E6D03;">loop</span>(){<br /> readPotentiometer(); <br /> adjustSpeed();<br /> constrainLEDs();<br /> <br /> <span style="color: #5E6D03;">switch</span>(effect){<br /> <span style="color: #5E6D03;">case</span> 0: <span style="color: #434F54;">// 1st effect : Cylon with Hue control - using Potentiometer </span><br /> cylonWithHueControl();<br /> <span style="color: #5E6D03;">break</span>;<br /> <br /> <span style="color: #5E6D03;">case</span> 1: <span style="color: #434F54;">// 2nd effect : Cylon with Brightness control - using Potentiometer</span><br /> cylonWithBrightnessControl();<br /> <span style="color: #5E6D03;">break</span>;<br /> <br /> <span style="color: #5E6D03;">case</span> 2: <span style="color: #434F54;">// 3rd effect : Comet effect. Hue controlled by potentiometer, direction by accelerometer</span><br /> cometEffect();<br /> <span style="color: #5E6D03;">break</span>;<br /> <br /> <span style="color: #5E6D03;">case</span> 3: <span style="color: #434F54;">// 4th effect : FireStarter / Rainbow Sparkle effect. Direction controlled by accelerometer, sparkle by potentiometer.</span><br /> fireStarter(); <br /> <span style="color: #5E6D03;">break</span>;<br /> <br /> <span style="color: #5E6D03;">case</span> 4:<br /> levelSense(); <span style="color: #434F54;">// 5th effect : LevelSense - uses the accelerometer to create a digital "spirit" level.</span><br /> <span style="color: #5E6D03;">break</span>;<br /> }<br />}<br /><br /><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #434F54;">// readPotentiometer() : Take a potentiometer reading. This value will be used to control various LED animations, and to choose the animation sequence to display.</span><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #00979C;">void</span> readPotentiometer(){<br /> <span style="color: #434F54;">//Take a reading from the potentiometer and convert the value into a number between 0 and 255</span><br /> potVal = <span style="color: #D35400;">map</span>(<span style="color: #D35400;">analogRead</span>(potPin), 0, 1023 , 0, 255);<br /> <br /> <span style="color: #434F54;">// If the potentiometer reading is equal to zero, then move to the next effect in the list.</span><br /> <span style="color: #5E6D03;">if</span>(potVal==0){<br /> <span style="color: #5E6D03;">if</span>(prevPotVal>0){ <span style="color: #434F54;">// This allows us to switch effects only when the potentiometer reading has changed to zero (from a positive number). Multiple zero readings will be ignored.</span><br /> prevPotVal = 0; <span style="color: #434F54;">// Set the prev pot value to zero in order to ignore replicate zero readings.</span><br /> effect++; <span style="color: #434F54;">// Go to the next effect.</span><br /> <span style="color: #5E6D03;">if</span>(effect>4){<br /> effect=0; <span style="color: #434F54;">// Go back to the first effect after the fifth effect.</span><br /> }<br /> }<br /> }<br /> prevPotVal=potVal; <span style="color: #434F54;">// Keep track of the previous potentiometer reading</span><br />}<br /><br /><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #434F54;">// adjustSpeed() : use the Y axis value of the accelerometer to adjust the speed and the direction of the LED animation sequence</span><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #00979C;">void</span> adjustSpeed(){<br /> <span style="color: #434F54;">// Take a reading from the Y Pin of the accelerometer and adjust the value so that </span><br /> <span style="color: #434F54;">// positive numbers move in one direction, and negative numbers move in the opposite diraction. </span><br /> <span style="color: #434F54;">// We use the map function to convert the accelerometer readings, and the constrain function to ensure that it stays within the desired limits</span><br /> <span style="color: #434F54;">// The values of 230 and 640 were determined by trial and error and are specific to my accelerometer. You will need to adjust these numbers to suit your module.</span><br /> <br /> LEDAccel = <span style="color: #D35400;">constrain</span>(<span style="color: #D35400;">map</span>(<span style="color: #D35400;">analogRead</span>(yPin), 230, 640 , maxLEDSpeed, -maxLEDSpeed),-maxLEDSpeed, maxLEDSpeed);<br /> <br /> <br /> <span style="color: #434F54;">// If the constSpeed variable is "true", then make sure that the speed of the animation is constant by modifying the LEDSpeed and LEDAccel variables.</span><br /> <span style="color: #5E6D03;">if</span>(constSpeed){<br /> LEDAccel=0; <br /> <span style="color: #5E6D03;">if</span>(LEDSpeed>0){<br /> LEDSpeed = maxLEDSpeed/1.1; <span style="color: #434F54;">// Adjust the LEDSpeed to half the maximum speed in the positive direction</span><br /> } <br /> <span style="color: #5E6D03;">if</span> (LEDSpeed<0){<br /> LEDSpeed = -maxLEDSpeed/1.1; <span style="color: #434F54;">// Adjust the LEDSpeed to half the maximum speed in the negative direction</span><br /> }<br /> } <br /> <br /> <span style="color: #434F54;">// The Speed of the LED animation sequence can increase (accelerate), decrease (decelerate) or stay the same (constant speed)</span><br /> LEDSpeed = LEDSpeed + LEDAccel; <br /> <br /> <span style="color: #434F54;">//The following lines of code are used to control the direction of the LED animation sequence, and limit the speed of that animation. </span><br /> <span style="color: #5E6D03;">if</span> (LEDSpeed>0){<br /> LEDPosition++; <span style="color: #434F54;">// Illuminate the LED in the Next position</span><br /> <span style="color: #5E6D03;">if</span> (LEDSpeed>maxLEDSpeed){<br /> LEDSpeed=maxLEDSpeed; <span style="color: #434F54;">// Ensure that the speed does not go beyond the maximum speed in the positive direction</span><br /> }<br /> }<br /> <br /> <span style="color: #5E6D03;">if</span> (LEDSpeed<0){<br /> LEDPosition--; <span style="color: #434F54;">// Illuminate the LED in the Prior position</span><br /> <span style="color: #5E6D03;">if</span> (LEDSpeed<-maxLEDSpeed){<br /> LEDSpeed = -maxLEDSpeed; <span style="color: #434F54;">// Ensure that the speed does not go beyond the maximum speed in the negative direction</span><br /> }<br /> }<br />}<br /><br /><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #434F54;">// constrainLEDs() : This ensures that the LED animation sequence remains within the boundaries of the various arrays (and the LED strip)</span><br /><span style="color: #434F54;">// and it also creates a "bouncing" effect at both ends of the LED strip.</span><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #00979C;">void</span> constrainLEDs(){<br /> LEDPosition = <span style="color: #D35400;">constrain</span>(LEDPosition, 0, NUM_LEDS-1); <span style="color: #434F54;">// Make sure that the LEDs stay within the boundaries of the LED strip</span><br /> <span style="color: #5E6D03;">if</span>(LEDPosition == 0 || LEDPosition == NUM_LEDS-1) {<br /> LEDSpeed = (LEDSpeed * -0.9); <span style="color: #434F54;">// Reverse the direction of movement when LED gets to end of strip. This creates a bouncing ball effect.</span><br /> }<br />}<br /><br /><br /><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #434F54;">// cylonWithHueControl() : This is the 1st LED effect. The cylon colour is controlled by the potentiometer. The speed is constant.</span><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #00979C;">void</span> cylonWithHueControl(){<br /> constSpeed = <span style="color: #00979C;">true</span>; <span style="color: #434F54;">// Make the LED animation speed constant</span><br /> showLED(LEDPosition, potVal, 255, intensity); <span style="color: #434F54;">// Illuminate the LED</span><br /> fadeLEDs(8); <span style="color: #434F54;">// Fade LEDs by a value of 8. Higher numbers will create a shorter tail.</span><br /> setDelay(LEDSpeed); <span style="color: #434F54;">// The LEDSpeed is constant, so the delay is constant</span><br />}<br /><br /><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #434F54;">// cylonWithBrightnessControl() : This is the 2nd LED effect. The cylon colour is red (hue=0), and the brightness is controlled by the potentiometer</span><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #00979C;">void</span> cylonWithBrightnessControl(){<br /> constSpeed = <span style="color: #00979C;">true</span>; <span style="color: #434F54;">// Make speed constant</span><br /> showLED(LEDPosition, 0, 255, potVal); <span style="color: #434F54;">// Brightness is controlled by potentiometer.</span><br /> fadeLEDs(16); <span style="color: #434F54;">// Fade LEDs by a value of 16</span><br /> setDelay(LEDSpeed); <span style="color: #434F54;">// The LEDSpeed is constant, so the delay is constant</span><br />}<br /><br /><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #434F54;">// cometEffect() : This is the 3rd LED effect. The random brightness of the trailing LEDs produces an interesting comet-like effect.</span><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #00979C;">void</span> cometEffect(){<br /> constSpeed = <span style="color: #00979C;">false</span>; <span style="color: #434F54;">// The speed will be controlled by the slope of the accelerometer (y-Axis)</span><br /> showLED(LEDPosition, potVal, 255, intensity); <span style="color: #434F54;">// Hue will change with potentiometer.</span><br /> <br /> <span style="color: #434F54;">//The following lines create the comet effect </span><br /> bright = <span style="color: #D35400;">random</span>(50, 100); <span style="color: #434F54;">// Randomly select a brightness between 50 and 100</span><br /> leds[LEDPosition] = <span style="color: #D35400;"><b>CHSV</b></span>((potVal+40),255, bright); <span style="color: #434F54;">// The trailing LEDs will have a different hue to the leading LED, and will have a random brightness</span><br /> fadeLEDs(8); <span style="color: #434F54;">// This will affect the length of the Trailing LEDs</span><br /> setDelay(LEDSpeed); <span style="color: #434F54;">// The LEDSpeed will be affected by the slope of the Accelerometer's y-Axis</span><br />}<br /><br /><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #434F54;">// fireStarter() : This is the 4th LED effect. It starts off looking like a ball of fire, leaving a trail of little fires. But as you</span><br /><span style="color: #434F54;">// turn the potentiometer, it becomes more like a shooting star with a rainbow-sparkle trail.</span><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #00979C;">void</span> fireStarter(){<br /> constSpeed = <span style="color: #00979C;">false</span>; <span style="color: #434F54;">// The speed will be controlled by the slope of the accelerometer (y-Axis)</span><br /> ledh[LEDPosition] = potVal; <span style="color: #434F54;">// Hue is controlled by potentiometer</span><br /> showLED(LEDPosition, ledh[LEDPosition], 255, intensity); <br /> <br /> <span style="color: #434F54;">//The following lines create the fire starter effect</span><br /> bright = <span style="color: #D35400;">random</span>(50, 100); <span style="color: #434F54;">// Randomly select a brightness between 50 and 100</span><br /> ledb[LEDPosition] = bright; <span style="color: #434F54;">// Assign this random brightness value to the trailing LEDs</span><br /> sparkle(potVal/5); <span style="color: #434F54;">// Call the sparkle routine to create that sparkling effect. The potentiometer controls the difference in hue from LED to LED.</span><br /> fadeLEDs(1); <span style="color: #434F54;">// A low number creates a longer tail</span><br /> setDelay(LEDSpeed); <span style="color: #434F54;">// The LEDSpeed will be affected by the slope of the Accelerometer's y-Axis</span><br />}<br /><br /><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #434F54;">// levelSense() : This is the 5th and final LED effect. The accelerometer is used in conjunction with the LED strip to create a digital "Spirit" Level.</span><br /><span style="color: #434F54;">// You can use the illuminated LEDs to identify the angle of the LED strip</span><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #00979C;">void</span> levelSense(){<br /> constSpeed = <span style="color: #00979C;">true</span>;<br /> LEDPosition = <span style="color: #D35400;">constrain</span>(<span style="color: #D35400;">map</span>(<span style="color: #D35400;">analogRead</span>(yPin), 230, 640, 1, NUM_LEDS-1), 0 , NUM_LEDS-1);<br /> <br /> <span style="color: #434F54;">//Jitter correction: this will reduce the amount of jitter caused by the accelerometer reading variability</span><br /> <span style="color: #5E6D03;">if</span>(<span style="color: #D35400;">abs</span>(LEDPosition-oldPos) < 2){<br /> LEDPosition = oldPos;<br /> }<br /> <br /> <span style="color: #434F54;">//The following lines of code will ensure the colours remain within the red to green range, with green in the middle and red at the ends.</span><br /> hue = <span style="color: #D35400;">map</span>(LEDPosition, 0, NUM_LEDS-1, 0, 200);<br /> <span style="color: #5E6D03;">if</span> (hue>100){<br /> hue = 200 - hue;<br /> }<br /> <br /> <span style="color: #434F54;">//Illuminate 2 LEDs next to each other</span><br /> showLED(LEDPosition, hue, 255, intensity); <br /> showLED(LEDPosition-1, hue, 255, intensity); <br /> <br /> <span style="color: #434F54;">//If the position moves, then fade the old LED positions by a factor of 25 (high numbers mean shorter tail)</span><br /> fadeLEDs(25); <br /> oldPos = LEDPosition; <br />}<br /><br /><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #434F54;">// fadeLEDs(): This function is used to fade the LEDs back to black (OFF) </span><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #00979C;">void</span> fadeLEDs(<span style="color: #00979C;">int</span> fadeVal){<br /> <span style="color: #5E6D03;">for</span> (<span style="color: #00979C;">int</span> i = 0; i<NUM_LEDS; i++){<br /> leds[i].<span style="color: #D35400;">fadeToBlackBy</span>( fadeVal );<br /> }<br />}<br /><br /><br /><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #434F54;">// showLED() : is used to illuminate the LEDs </span><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #00979C;">void</span> showLED(<span style="color: #00979C;">int</span> pos, <span style="color: #00979C;">byte</span> LEDhue, <span style="color: #00979C;">byte</span> LEDsat, <span style="color: #00979C;">byte</span> LEDbright){<br /> leds[pos] = <span style="color: #D35400;"><b>CHSV</b></span>(LEDhue,LEDsat,LEDbright);<br /> <span style="color: #D35400;"><b>FastLED</b></span>.<span style="color: #D35400;">show</span>();<br />}<br /><br /><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #434F54;">// setDelay() : is where the speed of the LED animation sequence is controlled. The speed of the animation is controlled by the LEDSpeed variable.</span><br /><span style="color: #434F54;">// and cannot go faster than the maxLEDSpeed variable.</span><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #00979C;">void</span> setDelay(<span style="color: #00979C;">int</span> LSpeed){<br /> animationDelay = maxLEDSpeed - <span style="color: #D35400;">abs</span>(LSpeed);<br /> <span style="color: #D35400;">delay</span>(animationDelay);<br />}<br /><br /><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #434F54;">// sparkle() : is used by the fireStarter routine to create a sparkling/fire-like effect</span><br /><span style="color: #434F54;">// Each LED hue and brightness is monitored and modified using arrays (ledh[] and ledb[])</span><br /><span style="color: #434F54;">//===================================================================================================================================================</span><br /><span style="color: #00979C;">void</span> sparkle(<span style="color: #00979C;">byte</span> hDiff){<br /> <span style="color: #5E6D03;">for</span>(<span style="color: #00979C;">int</span> i = 0; i < NUM_LEDS; i++) {<br /> ledh[i] = ledh[i] + hDiff; <span style="color: #434F54;">// hDiff controls the extent to which the hue changes along the trailing LEDs</span><br /> <br /> <span style="color: #434F54;">// This will prevent "negative" brightness.</span><br /> <span style="color: #5E6D03;">if</span>(ledb[i]<3){<br /> ledb[i]=0;<br /> }<br /> <br /> <span style="color: #434F54;">// The probability of "re-igniting" an LED will decrease as you move along the tail</span><br /> <span style="color: #434F54;">// Once the brightness reaches zero, it cannot be re-ignited unless the leading LED passes over it again.</span><br /> <span style="color: #5E6D03;">if</span>(ledb[i]>0){<br /> ledb[i]=ledb[i]-2;<br /> sparkTest = <span style="color: #D35400;">random</span>(0,bright);<br /> <span style="color: #5E6D03;">if</span>(sparkTest>(bright-(ledb[i]/1.1))){<br /> ledb[i] = bright;<br /> } <span style="color: #5E6D03;">else</span> {<br /> ledb[i] = ledb[i] / 2; <br /> }<br /> }<br /> leds[i] = <span style="color: #D35400;"><b>CHSV</b></span>(ledh[i],255,ledb[i]);<br /> }<br />}<br /><br /></pre> <!-- End of Arduino Code --> </pre> </td> </tr> </table></div></P> <br> <br> <P> <h4>NeoPixel Strip connection </h4> <P> The NeoPixel strip is rolled up when you first get it. You will notice that there are wires on both sides of the strip. This allows you to chain LED strips together to make longer strips. The more LEDs you have, the more current you will need. Connect your Arduino and power supply to the left side of the strip, with the arrows pointing to the right side of the strip. <br clear="all"> <br> </P> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHDj8-eu2-SBrUYil8A6sj4zFFm6-XvM5STrhnaaS5gzgwNEKvT9bXF0P_To4ZMGcmr_Ef2zY-YjomjeCuk37WqjPLk2p93CmzmBitCLkRZNlCrB-pe6SdFKiivI7WHYS8DMgxBduh-yA/s1600/Rolled+up+Neopixels.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHDj8-eu2-SBrUYil8A6sj4zFFm6-XvM5STrhnaaS5gzgwNEKvT9bXF0P_To4ZMGcmr_Ef2zY-YjomjeCuk37WqjPLk2p93CmzmBitCLkRZNlCrB-pe6SdFKiivI7WHYS8DMgxBduh-yA/s320/Rolled+up+Neopixels.jpg" width="300" align="top" /> </a> </div> </P> <P> <h3><span style="color: #7FD4FF;">Follow the Arrows</span></h3> The arrows are quite hard to see on this particular LED strip because they are so small, plus they are located right under the thicker part of the NeoPixel weatherproof sheath. I have circled the arrows in RED so that you know where to look:<br> <br clear="all"> <br> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdAaIRQXC3jnxVBRTSV19C68qrpAFE4k9kpZzyFzSM0LwfLA8Ve5wMnh_gOCW2JhfWgYoN3bY-I9zCLIWmQ6UAg9euP8cqmJ30VB5yShEG-oqu15_VWH2b2uE9_VcNKOcD6UxA_p8n62M/s1600/NeoPixel+Arrows.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" height="232" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdAaIRQXC3jnxVBRTSV19C68qrpAFE4k9kpZzyFzSM0LwfLA8Ve5wMnh_gOCW2JhfWgYoN3bY-I9zCLIWmQ6UAg9euP8cqmJ30VB5yShEG-oqu15_VWH2b2uE9_VcNKOcD6UxA_p8n62M/s400/NeoPixel+Arrows.jpg" width="400" /> </a> </div> <br /> </P> </P> <br clear="all"> <span style="color: #7FD4FF;"><P><h3>NeoPixel Strip Wires</h3></span> There are 4 wires coming from either side of the NeoPixel LED strip: <br> <br> One red wire, one white wire, and two black wires.<br> <br> It doesn't matter which Black wire you use to connect to the power supply (or Arduino) GND. Both black wires appear to be going to the same pin on the LED strip anyway. Use the table below to make the necessary NeoPixel Strip connections to the Arduino and power supply.<br> <br clear="all"> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzTXhJ5bLhRa67N7aWw5g87llFX67-DZovNbj-dAoIAAzx7IKpu24e1fEgctZBOkhP_AdKrBVhF5NZvn_xvSKWYQ6ZPqLILDuGWNRKpPcAH5dMJvCmloG9VlKfpatbUE1dczj7_Liw5TY/s1600/NeoPixel+Table3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img border="0" height="448" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzTXhJ5bLhRa67N7aWw5g87llFX67-DZovNbj-dAoIAAzx7IKpu24e1fEgctZBOkhP_AdKrBVhF5NZvn_xvSKWYQ6ZPqLILDuGWNRKpPcAH5dMJvCmloG9VlKfpatbUE1dczj7_Liw5TY/s640/NeoPixel+Table3.jpg" width="640" /> </a> </div><br /> </P> <P> <h3><span style="color: #7FD4FF;">Large Capacitor</span></h3> <a href="https://learn.adafruit.com/adafruit-neopixel-uberguide/power">Adafruit</a> also recommend the use of a large capacitor across the + and - terminals of the LED strip to "prevent the initial onrush of current from damaging the pixels". Adafruit recommends a capacitor that is 1000uF, 6.3V or higher. I used a 4700uF 16V Electrolytic Capacitor. <br> <br> <span style="color: #7FD4FF;"><h3>Resistor on Data Pin</h3></span> Another recommendation from <a href="https://learn.adafruit.com/adafruit-neopixel-uberguide/power">Adafruit</a> is to place a "300 to 500 Ohm resistor" between the Arduino's data pin and the data input on the first NeoPixel to prevent voltage spikes that can damage the first pixel. I used a 330 Ohm resistor. <br> <br> <span style="color: #7FD4FF;"><h3>Powering your Arduino (USB vs Power supply)</h3></span> You can power your Arduino board via USB cable or via the LED strip power supply.<br> <span style="color: #7FD4FF;">*** Please note:</span> different power supplies will yield different accelerometer readings. I noticed this when changing the Arduino's power source from USB to LED power supply. My final sketch was designed to eliminate the USB/computer connection, hence I have chosen to power the Arduino via the power supply. The fritzing sketch below shows the Arduino being powered by a power supply only. <br> <br> <span style="color: #FF0000;"><b>**WARNING:</b></span> If you decide to power your Arduino UNO via a USB cable, please make sure to remove (or disconnect) the wire that goes to the the Arduino VIN pin. The GND connections remain unchanged. </P> <br> <P><H4>Fritzing Sketch - NeoPixel strip connection</H4> </P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8D3_-Eva_IT3Pj7GKnv7oLpM718JfpH8r1c1Y3VJHykbYs2xL241wzRc1Rnaqp2h3oufAnN3zQQXlDhAFeLddFCJdkoGEaEIKDOCuZCM2XElXtLQ4twyLazYjBWCNgfAQZFrrzITJ6qQ/s1600/NeoPixel+Fritzing+Sketch1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" height="478" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8D3_-Eva_IT3Pj7GKnv7oLpM718JfpH8r1c1Y3VJHykbYs2xL241wzRc1Rnaqp2h3oufAnN3zQQXlDhAFeLddFCJdkoGEaEIKDOCuZCM2XElXtLQ4twyLazYjBWCNgfAQZFrrzITJ6qQ/s640/NeoPixel+Fritzing+Sketch1.jpg" width="640" /> </a> </div> <br /> <br> <h4>Potentiometer connection</h4> <P>The potentiometer will be used to switch between the different LED sequences. When it reads zero, it will switch to the next sequence in the list. It will jump right back to the beginning after the last sequence. The potentiometer is also used to interact with the LEDs (e.g. controlling hue, brightness etc etc). <br> See the fritzing sketch below to add the potentiometer to this project.</P> <br> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4g-y_dovuhxzJrVeXhE4c9vIltVoR3pn7kEGtLCMzNFsG49KEJGl2vV0G2adsIELQkDVhU6gIuHRkpYW_FGeMZYNb3nh2lRHkWvS6RJPjBu01i-y6nMUpILatEIM27uC-cZ11AZmRPxs/s1600/Potentiometer+Fritzing.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" height="512" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4g-y_dovuhxzJrVeXhE4c9vIltVoR3pn7kEGtLCMzNFsG49KEJGl2vV0G2adsIELQkDVhU6gIuHRkpYW_FGeMZYNb3nh2lRHkWvS6RJPjBu01i-y6nMUpILatEIM27uC-cZ11AZmRPxs/s640/Potentiometer+Fritzing.jpg" width="640" /> </a> </div> <br /> <br> <h4>Accelerometer connection (Y-axis)</h4> <P>The accelerometer makes the LEDs much more fun and interactive. We will only be using the Y-axis of the accelerometer in this sketch. By tilting the accelerometer from one side to the other, the LEDs react and respond accordingly. The accelerometer is an essential component of the digital spirit level sequence. That's right ! You can use this sketch to create your own spirit level. This digital version can also be used to measure angles ! <br> <br> Have a look below to see how to hook up the accelerometer to the Arduino. The Y-axis is connected to the Arduino analog pin 4. If you wanted to use the X and Z axis, connect them to one of the other available analog pins (eg. A3 and A5). </P> <br> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhc7g7P1EWlB62AKrdgppbp2TqRQrfXTqnIpSaF_rQHbLOv5ub8JYI_9a3q5UV9A78jPF-ScW1sXrxD_NS-uYDvUceVv8VUd4U22ccmXj2xB8rAiK9FEmHTVTyMJt_oF8ruu2DraTONp34/s1600/Accelerometer+Fritzing.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhc7g7P1EWlB62AKrdgppbp2TqRQrfXTqnIpSaF_rQHbLOv5ub8JYI_9a3q5UV9A78jPF-ScW1sXrxD_NS-uYDvUceVv8VUd4U22ccmXj2xB8rAiK9FEmHTVTyMJt_oF8ruu2DraTONp34/s640/Accelerometer+Fritzing.jpg" width="630" /> </a> </div> <br /> </P> <BR /> <P> <h4>Let the fun begin !!</h4> Now that you have the Arduino code uploaded to the Arduino, and have made all of the necessary wire/component connections, it is time to turn on the power supply. <br> <br> <span style="color: #7FD4FF;"><h3>Sequence 1: Cylon with Hue control</h3></span> The LEDs will move from one end of the strip to the other. It should start off as a RED cylon effect. As you turn the potentiometer clockwise, the colour of the LEDs will change and move through the various colours of the rainbow. If the potentiometer reading gets back to zero (fully anti-clockwise), it will move to sequence 2.<br> <br> <span style="color: #7FD4FF;"><h3>Sequence 2: Cylon with brightness control</h3></span> You will see that the LEDs have turned off. The potentiometer readings correlate with the LED brightness. At the start of this sequence, the potentiometer readings will be zero, therefore the brightness will be zero (LEDs turned off). As you turn the potentiometer clockwise, the readings increase, and so will the brightness of the LEDs. <br> <br> <span style="color: #7FD4FF;"><h3>Sequence 3: Comet effect with Hue and direction control</h3></span> This is where the real fun begins. You control the hue of the leading LED with the potentiometer, however the LED will move along the LED strip as though it were affected by gravity. As it hits the end of the LED strip, it will bounce for a while and eventually come to a stop. The more you tilt the accelerometer, the greater the acceleration of the leading LED. The trailing LEDs have an interesting randomised glow, which creates the "comet" effect.<br> <br> <span style="color: #7FD4FF;"><h3>Sequence 4: FireStarter / Rainbow effect : Hue and direction control</h3></span> The initial colours of LEDs in this sequence creates a fire-like animation. As the leading LED moves along the LED strip, it appears to ignite the LEDs in its path, leaving a fire trail behind it. The fire effect is best when you turn the potentiometer clockwise slightly to introduce a small amount of yellow into the mix of colours. As you turn the potentiometer further clockwise, the fire trail turns into a pretty rainbow trail. The accelerometer affects the leading LED in the same way as the previous sequence. <br> <br> <span style="color: #7FD4FF;"><h3>Sequence 5: Digital spirit level</h3></span> This sequence was my original idea for this project, however I thought it would be nice to share some of the other cool effects I created on my journey of discovery. The idea was to make a digital version of a spirit level. I originally wanted the LEDs to represent a spirit level bubble that would "float" according to the vertical/horizontal position of the LED strip. However, as I played around with this sketch, I discovered that it could potentially be used to measure the angle of the strip relative to the horizon. The angle can be determined by the illuminated LED. If the strip is horizontal, the illuminated LEDs will be close to the middle of the strip, and their colour will be green. If the strip is vertical, the illuminated LEDs will be close to end of the strip, and their colour will be red. The colour is just an additional visual indicator. <br> </P> </P></div><!--separator --><img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /><P> <div style="text-align: justify;"> <h3><span style="color: #7FD4FF;">Concluding Comments</span></h3> The NeoPixel Digital RGB LED strip is a lot of fun. The FastLED library makes for easy programming, and allows you to get up and running really quickly. 144 LEDs on a single strip means you have plenty of room for creative algorithms and lighting effects. Add a few sensors, and "pretty" quickly turns into "awesome" !!<br> <br> This tutorial shows you how to control a <a href="http://openlab.com.au/shop/neopixel-digital-rgb-led-strip-144-led/">"144 NeoPixel per metre Digital RGB LED strip"</a> with an Arduino UNO. Feel free to share your own LED creations in the comments below.<br> </div> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> <div align="center"> If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br> <BR /> <BR /> Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br> Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br> I can also be found on <a href="https://www.pinterest.com/ArduinoBasics/">Pinterest</a> and <a href="https://instagram.com/arduinobasics">Instagram</a>. <br> Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.<br> </div> </P> <BR /> <BR /> <div class="separator" style="clear: both; text-align: center;"> <a href="http://arduinobasics.blogspot.com.au/p/arduino-basics-projects-page.html" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="145" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg1dds9EFMC242irm1Ncc1lQvFUd5g3E4oQ-lOwud94W_wcLtuLVZBbGCHvkN1-ktvfz6RW9fNKOC83ZyvvGT5ojvBnfobn8vBzShWLyffe34GiOEkGpXiZeZODOtofj104zmC01GQJWg/s320/ArduinoBasics_OpenLogo+on+Black.png" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;"></div> <br><div align="center">This project would not have been possible without the collaborative effort from <a href="http://openlab.com.au/">OpenLab</a>.<br> Please visit their site for more cool projects.</div> <br> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> However, if you do not have a google profile... <br>Feel free to share this page with your friends in any way you see fit. </P></P></P><br /><br /><br /><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" -->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-89837646895006052852015-06-21T23:52:00.000-07:002016-03-19T10:53:40.956-07:00Send HEX values to Arduino <div style="text-align: justify;"> <P> <div class="separator" style="clear: both; text-align: center;"> <img style="border:2px solid #8C7E6F;" height="116" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3-tT61sdRM1ocDK7FbwJpjKlo1xno7pQglsz173n8iKoUMI5f91lvFBW5Zh5z0POnOU0A3x6ivhW7ShQnD3kAABLvAj4bmIArLUmnFyCGSPkKc_hGfuzHX43NaMWhxLEg6VacSQ-HDmM/s640/Hex_TitleBar.jpg" width="650" /> </div> </P> <div align="right"> <g:plusone></g:plusone> </div> <P> <div> <P> <h4>FIVE MINUTE TUTORIAL</h4> <h3><span style="color: #62AEB2">Project Description: Sending Hex values to an Arduino UNO</span></h3> <br> This simple tutorial will show you how to send Hexadecimal values from a computer to an Arduino Uno. The "Processing" programming language will be used to send the HEX values from the computer when a mouse button is pressed. The Arduino will use these values to adjust the brightness of an LED. </P> <br> <P> <div class="separator" style="clear: both; text-align: center;"> <img style="border:2px solid #8C7E6F;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTHhyitz6ZX_hFd6nNlBfcexTSZQWWRwBHFZlaWfspv9Xs8F8j39EYsx8tDSq_ZVsjHjLzKZ1p_D0Mv-Mz62Rjnd_oaCnYivRGgnGmw63BA2FV16NjFC8-2iB5IHbRMtRi6a14sR4-wpI/s640/Hexapod+Diagram1.jpg" /> </div> </P> <br> <br> <P><h4>Learning Objectives</h4> <br> <ul> <li>To Send Hexadecimal (Hex) values from a computer to the Arduino</li> <li>Trigger an action based on the press of a mouse button</li> <li>Learn to create a simple Computer to Arduino interface</li> <li>Use Arduino's PWM capabilities to adjust brightness of an LED </li> <li>Learn to use Arduino's analogWrite() function</li> <li>Create a simple LED circuit</li> </ul> </P> </div> </P> <BR /> <P> <H4>Parts Required:</H4> <P> <ul> <li>Arduino Uno or compatible board</li> <li>LED</li> <li>Breadboard</li> <li>330 Ohm Resistor</li> <li>Computer - with <a href="http://www.arduino.cc/en/Main/Software">Arduino IDE</a> and <a href="https://processing.org/download/?processing">Processing IDE</a> installed</li> <br /> </ul> </P> </P> <br> <P> <H4>Fritzing Sketch</H4> <br> The diagram below will show you how to connect an LED to Digital Pin 10 on the Arduino. <br> Don't forget the 330 ohm resistor ! <BR /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig8KASbzLDqKhott57leEted03yXVekQsm_W2KxJoLSiep9jDtosoRzTiwsW1jaBsf06YeywpmQlhzF5Z7YsiGd2S9RqI_IBjl9plXym2SWG9KMvs5g1FKlpigzU0srnaXHvoK252N1Ug/s1600/Simple+LED+Circuit.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:2px solid #8C7E6F;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig8KASbzLDqKhott57leEted03yXVekQsm_W2KxJoLSiep9jDtosoRzTiwsW1jaBsf06YeywpmQlhzF5Z7YsiGd2S9RqI_IBjl9plXym2SWG9KMvs5g1FKlpigzU0srnaXHvoK252N1Ug/s640/Simple+LED+Circuit.jpg" /> </a> </div> </P> <BR /> <BR /> <P> <H4>Arduino Sketch</H4> <BR /> The latest version of Arduino IDE can be downloaded <a href="http://www.arduino.cc/en/Main/Software">here. </a> <br> <br> <div style="background: #ffffff; color: #000000; overflow:auto;width:auto;border:solid rgb(24,186,183);border-width: .6em .3em .3em .3em;padding: 0em 0em;"> <table> <tr> <td> <pre style="margin: 0; line-height: 125%; background: rgb(24,186,183); width: 1.9em"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br /> 10<br /> 11<br /> 12<br /> 13<br /> 14<br /> 15<br /> 16<br /> 17<br /> 18<br /> 19<br /> 20<br /> 21<br /> 22<br /> 23<br /> 24<br /> 25<br /> 26<br /> 27<br /> 28<br /> 29<br /> 30<br /> 31<br /> </pre> </td> <td> <pre style="margin: 0; line-height: 125%"><span style="color: #434F54;">/* ==================================================================================================================================================</span><br /><span style="color: #434F54;"> Project: 5 min tutorial: Send Hex from computer to Arduino</span><br /><span style="color: #434F54;"> Author: Scott C</span><br /><span style="color: #434F54;"> Created: 21th June 2015</span><br /><span style="color: #434F54;"> Arduino IDE: 1.6.4</span><br /><span style="color: #434F54;"> Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html</span><br /><span style="color: #434F54;"> Description: Arduino Sketch used to adjust the brightness of an LED based on the values received</span><br /><span style="color: #434F54;"> on the serial port. The LED needs to be connected to a PWM pin. In this sketch</span><br /><span style="color: #434F54;"> Pin 10 is used, however you could use Pin 3, 5, 6, 9, or 11 - if you are using an Arduino Uno.</span><br /><span style="color: #434F54;">===================================================================================================================================================== */</span><br /><br /><span style="color: #00979C;">byte</span> byteRead; <span style="color: #434F54;">//Variable used to store the byte received on the Serial Port</span><br /><span style="color: #00979C;">int</span> ledPin = 10; <span style="color: #434F54;">//LED is connected to Arduino Pin 10. This pin must be PWM capable. </span><br /><br /><span style="color: #00979C;">void</span> <span style="color: #5E6D03;">setup</span>() {<br /> <span style="color: #D35400;"><b>Serial</b></span>.<span style="color: #D35400;">begin</span>(9600); <span style="color: #434F54;">//Initialise Serial communication with the computer</span><br /> <span style="color: #D35400;">pinMode</span>(ledPin, <span style="color: #00979C;">OUTPUT</span>); <span style="color: #434F54;">//Set Pin 10 as an Output pin</span><br /> byteRead = 0; <span style="color: #434F54;">//Initialise the byteRead variable to zero.</span><br />}<br /><br /><span style="color: #00979C;">void</span> <span style="color: #5E6D03;">loop</span>() {<br /> <span style="color: #5E6D03;">if</span>(<span style="color: #D35400;"><b>Serial</b></span>.<span style="color: #D35400;">available</span>()) {<br /> byteRead = <span style="color: #D35400;"><b>Serial</b></span>.<span style="color: #D35400;">read</span>(); <span style="color: #434F54;">//Update the byteRead variable with the Hex value received on the Serial COM port.</span><br /> }<br /> <br /> <span style="color: #D35400;">analogWrite</span>(ledPin, byteRead); <span style="color: #434F54;">//Use PWM to adjust the brightness of the LED. Brightness is determined by the "byteRead" variable.</span><br />} </pre> </td> </tr> </table></div></P> <BR /> <BR /> <P> <!-- Arduino Code Discussion --> <P> <p> <BR /> <BR /> <P> <H4>Processing Sketch</H4> <BR /> The latest version of the Processing IDE can be downloaded <a href="https://processing.org/download/?processing">here. </a> <br> <br> <div style="background: #ffffff; color: #000000; overflow:auto;width:auto;border:solid #A2AFBA; border-width: .6em .3em .3em .3em;padding: 0em 0em;"> <table> <tr> <td> <pre style="margin: 0; line-height: 125%; background: #A2AFBA; width: 1.9em"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br /> 10<br /> 11<br /> 12<br /> 13<br /> 14<br /> 15<br /> 16<br /> 17<br /> 18<br /> 19<br /> 20<br /> 21<br /> 22<br /> 23<br /> 24<br /> 25<br /> 26<br /> 27<br /> 28<br /> 29<br /> 30<br /> 31<br /> 32<br /> 33<br /> 34<br /> 35<br /> 36<br /> 37<br /> 38<br /> 39<br /> 40<br /> 41<br /> 42<br /> 43<br /> </pre> </td> <td> <pre style="margin: 0; line-height: 125%"><span style="color: #666666;">/* ==================================================================================================================================================</span><br /><span style="color: #666666;"> Project: 5 min tutorial: Send Hex from computer to Arduino</span><br /><span style="color: #666666;"> Author: Scott C</span><br /><span style="color: #666666;"> Created: 21th June 2015</span><br /><span style="color: #666666;"> Processing IDE: 2.2.1</span><br /><span style="color: #666666;"> Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html</span><br /><span style="color: #666666;"> Description: Processing Sketch used to send HEX values from computer to Arduino when the mouse is pressed.</span><br /><span style="color: #666666;"> The alternating values 0xFF and 0x00 are sent to the Arduino Uno to turn an LED on and off.</span><br /><span style="color: #666666;"> You can send any HEX value from 0x00 to 0xFF. This sketch also shows how to convert Hex strings</span><br /><span style="color: #666666;"> to Hex numbers.</span><br /><span style="color: #666666;">===================================================================================================================================================== */</span><br /><br /><span style="color: #33997E;">import</span> processing.serial.*; <span style="color: #666666;">//This import statement is required for Serial communication</span><br /><br />Serial comPort; <span style="color: #666666;">//comPort is used to write Hex values to the Arduino</span><br /><span style="color: #E2661A;">boolean</span> toggle = <span style="color: #33997E;">false</span>; <span style="color: #666666;">//toggle variable is used to control which hex variable to send </span><br /><span style="color: #E2661A;">String</span> zeroHex = <span style="color: #7D4793;">"00"</span>; <span style="color: #666666;">//This "00" string will be converted to 0x00 and sent to Arduino to turn LED off.</span><br /><span style="color: #E2661A;">String</span> FFHex = <span style="color: #7D4793;">"FF"</span>; <span style="color: #666666;">//This "FF" string will be converted to 0xFF and sent to Arduino to turn LED on.</span><br /><br /><span style="color: #33997E;">void</span> <span style="color: #006699;"><b>setup</b></span>(){<br /> comPort = <span style="color: #33997E;">new</span> Serial(<span style="color: #33997E;">this</span>, Serial.<span style="color: #006699;">list</span>()[0], 9600); <span style="color: #666666;">//initialise the COM port for serial communication at a baud rate of 9600.</span><br /> delay(2000); <span style="color: #666666;">//this delay allows the com port to initialise properly before initiating any communication.</span><br /> <span style="color: #006699;">background</span>(0); <span style="color: #666666;">//Start with a black background.</span><br /> <br />}<br /><br /><br /><span style="color: #33997E;">void</span> <span style="color: #006699;"><b>draw</b></span>(){ <span style="color: #666666;">//the draw() function is necessary for the sketch to compile </span><br /> <span style="color: #666666;">//do nothing here //even though it does nothing.</span><br />}<br /><br /><br /><span style="color: #33997E;">void</span> <span style="color: #006699;"><b>mousePressed</b></span>(){ <span style="color: #666666;">//This function is called when the mouse is pressed within the Processing window.</span><br /> toggle = ! toggle; <span style="color: #666666;">//The toggle variable will change back and forth between "true" and "false"</span><br /> <span style="color: #669900;">if</span>(toggle){ <span style="color: #666666;">//If the toggle variable is TRUE, then send 0xFF to the Arduino</span><br /> comPort.write(<span style="color: #006699;">unhex</span>(FFHex)); <span style="color: #666666;">//The unhex() function converts the "FF" string to 0xFF</span><br /> <span style="color: #006699;">background</span>(0,0,255); <span style="color: #666666;">//Change the background colour to blue as a visual indication of a button press.</span><br /> } <span style="color: #669900;">else</span> {<br /> comPort.write(<span style="color: #006699;">unhex</span>(zeroHex)); <span style="color: #666666;">//If the toggle variable is FALSE, then send 0x00 to the Arduino</span><br /> <span style="color: #006699;">background</span>(0); <span style="color: #666666;">//Change the background colour to black as a visual indication of a button press.</span><br /> }<br />}<br /> </pre> </td> </tr> </table></div></P> <BR /> <BR /> <P> <!-- Processing Code Discussion --> <P></p> <H4>The Video</H4> <BR /> <div style="text-align: center;"> <iframe width="480" height="360" src="https://www.youtube.com/embed/-AvB9wP8dFw" frameborder="0" allowfullscreen></iframe> </div> </P></div><!--separator --><img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /><P> <div style="text-align: justify;"> The tutorial above is a quick demonstration of how to convert Hex strings on your computer and send them to an Arduino. The Arduino can use the values to change the brightness of an LED as shown in this tutorial, however you could use it to modify the speed of a motor, or to pass on commands to another module. Hopefully this short tutorial will help you with your project. Please let me know how it helped you in the comments below. </div> <BR /> <BR /> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> <div align="center"> If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br> <BR /> <BR /> Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br> Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br> I can also be found on <a href="https://www.pinterest.com/ArduinoBasics/">Pinterest</a> and <a href="https://instagram.com/arduinobasics">Instagram</a>. <br> Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.<br> </div> </P> <BR /> <BR /> <div class="separator" style="clear: both; text-align: center;"> <a href="http://arduinobasics.blogspot.com.au/p/arduino-basics-projects-page.html" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="145" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg1dds9EFMC242irm1Ncc1lQvFUd5g3E4oQ-lOwud94W_wcLtuLVZBbGCHvkN1-ktvfz6RW9fNKOC83ZyvvGT5ojvBnfobn8vBzShWLyffe34GiOEkGpXiZeZODOtofj104zmC01GQJWg/s320/ArduinoBasics_OpenLogo+on+Black.png" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><BR /> <BR /> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> However, if you do not have a google profile... <br>Feel free to share this page with your friends in any way you see fit. </P></P></P><br /><br /><br /><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" -->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-65166046591734980502015-05-07T07:07:00.000-07:002016-03-19T10:53:40.972-07:00CH376S USB Read/Write module<g:plusone></g:plusone><div style="text-align: justify;"> <P> <iframe width="640" height="400" src="https://www.youtube.com/embed/yK3631kMKBU?rel=0&showinfo=0" frameborder="2" allowfullscreen></iframe> </P> <P> <div> <P> <!-- Description and Introduction of project --> Have you ever wondered if there was a way to store and retrieve data from a USB stick with an Arduino UNO? Most people choose SD cards to store their project data, but you may be surprised there IS a way! <br> IC Station have a nice little module which allows you store and retrieve your Arduino (or other MCU) project data to a USB stick. <br> <br> I am not too sure why USB storage is not widely used in Arduino projects? These modules are not expensive, they have been around for quite a while, and are relatively simple to use. You do not need any libraries to get them to work, however, I must say that documentation for this module is not that easy to find. This <a href="http://microembebidos.com/2013/12/15/modulo-extremo-ch376-conversor-usb-fat-file-para-uart-serial/">site</a> and this <a href="http://www.mpja.com/download/ch376ds1.pdf">document</a> proved to be very useful in my endevour to get this module working, and I hope my tutorial below will help you get started and bridge some of the information gaps. <br> <br> The "CH376S USB read/write module" has a CH376S chip onboard which does most of the hard work for you. All you have to do is send the module some commands from the Arduino and the CH376S chip will do the rest. You can communicate with the module in three different ways: <ul> <li> Parallel communication </li> <li> SPI communication</li> <li> and Serial (UART) communication.</li> </ul> <br> This project will show you the connections and code for the Serial (UART) communication method only. </P> </div> </P> <BR /> <P> <H4>Parts Required:</H4> <P> <ul> <li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=3516">Arduino UNO or compatible board</a></li> <li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=5271">CH376S USB Read Write Module</a></li> <li><a href="https://www.adafruit.com/products/826">Female to Male jumper wires</a></li> <li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=1495">Breadboard (optional)</a></li> <li>USB stick</li> <li>LED + 330 ohm resistor (optional)</li><br /> </ul> </P> </P> <P> <H4>Remove the Jumper</H4> <P> When the CH376S USB module arrives in it's package, it will have a jumper between the TXD pin and GND. You will need to remove this jumper to make the necessary connections between the Arduino UNO and the CH376S USB module. </P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiNqv3cc_BJn5mmgy1Hmvk6xktQR9GsM6Sl3dT4tnQ06NHY-N1YF4CR-gqW-WUxiArAcdMeSVioSvyFlk5ImOsWY2Ea1V1rqldJono2Pc0IMnDFsMCgBLciD3JFic-vonNvm1J2MXEJdc/s1600/Slide5.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" width="640" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiNqv3cc_BJn5mmgy1Hmvk6xktQR9GsM6Sl3dT4tnQ06NHY-N1YF4CR-gqW-WUxiArAcdMeSVioSvyFlk5ImOsWY2Ea1V1rqldJono2Pc0IMnDFsMCgBLciD3JFic-vonNvm1J2MXEJdc/s400/Slide5.JPG" /> </a> </div> <BR> <BR> <H4>Fritzing Sketch</H4> Please note, that the Arduino Sketch makes use of the Arduino UNO's onboard LED on digital pin 13. The Fritzing sketch below shows an LED + 300 ohm resistor on a breadboard. This is optional. The LED is not a necessary component of CH376S module communication.</P> <P> Also be aware that the CH376S USB module has an onboard LED just above the TXD and GND pins near the USB port. This LED will only turn on providing the CH376S module is in USB mode AND a USB device has been inserted into the USB port. Both conditions must be met before the module's onboard LED will illuminate. You will not see the LED turn on just by powering the board. <br> <br> The wire diagram below is the correct setup for Serial communication between an Arduino UNO and the CH376S module. If you wish to use SPI or Parallel communication, you will need to refer to the datasheet. </P> <!-- Fritzing Sketch here --> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1p11a8ejkCALFqQGfKyeYe4GPh0nuk8LzYD9MYq4K_pOlg5r2taCv0buBXLRzGle2KRccjK1c2UX0aWpvm8yen-o2NpvYvxkeN6gFKRGHdEBaLOtvJ2-nN-NeyC1t7GiyJsd7LHe629s/s1600/Slide6.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" width="640" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1p11a8ejkCALFqQGfKyeYe4GPh0nuk8LzYD9MYq4K_pOlg5r2taCv0buBXLRzGle2KRccjK1c2UX0aWpvm8yen-o2NpvYvxkeN6gFKRGHdEBaLOtvJ2-nN-NeyC1t7GiyJsd7LHe629s/s400/Slide6.JPG" /> </a> </div> </P> <BR /> <BR /> <P> <H4>Arduino Sketch</H4> <BR /> <div style="background: #ffffff; color: #000000; overflow:auto;width:auto;border:solid rgb(24,186,183);border-width: .6em .3em .3em .3em;padding: 0em 0em;"> <table> <tr> <td> <pre style="margin: 0; line-height: 125%; background: rgb(24,186,183); width: 1.9em"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br /> 10<br /> 11<br /> 12<br /> 13<br /> 14<br /> 15<br /> 16<br /> 17<br /> 18<br /> 19<br /> 20<br /> 21<br /> 22<br /> 23<br /> 24<br /> 25<br /> 26<br /> 27<br /> 28<br /> 29<br /> 30<br /> 31<br /> 32<br /> 33<br /> 34<br /> 35<br /> 36<br /> 37<br /> 38<br /> 39<br /> 40<br /> 41<br /> 42<br /> 43<br /> 44<br /> 45<br /> 46<br /> 47<br /> 48<br /> 49<br /> 50<br /> 51<br /> 52<br /> 53<br /> 54<br /> 55<br /> 56<br /> 57<br /> 58<br /> 59<br /> 60<br /> 61<br /> 62<br /> 63<br /> 64<br /> 65<br /> 66<br /> 67<br /> 68<br /> 69<br /> 70<br /> 71<br /> 72<br /> 73<br /> 74<br /> 75<br /> 76<br /> 77<br /> 78<br /> 79<br /> 80<br /> 81<br /> 82<br /> 83<br /> 84<br /> 85<br /> 86<br /> 87<br /> 88<br /> 89<br /> 90<br /> 91<br /> 92<br /> 93<br /> 94<br /> 95<br /> 96<br /> 97<br /> 98<br /> 99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br />282<br />283<br />284<br />285<br />286<br />287<br />288<br />289<br />290<br />291<br />292<br />293<br />294<br />295<br />296<br />297<br />298<br />299<br />300<br />301<br />302<br />303<br />304<br />305<br />306<br />307<br />308<br />309<br />310<br />311<br />312<br />313<br />314<br />315<br />316<br />317<br />318<br />319<br />320<br />321<br />322<br />323<br />324<br />325<br />326<br />327<br />328<br />329<br />330<br />331<br />332<br />333<br />334<br />335<br />336<br />337<br />338<br />339<br />340<br />341<br />342<br />343<br />344<br />345<br />346<br />347<br />348<br />349<br />350<br />351<br />352<br />353<br />354<br />355<br />356<br />357<br />358<br />359<br />360<br />361<br />362<br />363<br />364<br />365<br />366<br />367<br />368<br />369<br />370<br />371<br />372<br />373<br />374<br />375<br />376<br />377<br />378<br />379<br />380<br />381<br />382<br />383<br />384<br />385<br />386<br />387<br />388<br />389<br />390<br />391<br />392<br />393<br />394<br />395<br />396<br />397<br />398<br />399<br />400<br />401<br />402<br />403<br />404<br />405<br />406<br />407<br />408<br />409<br />410<br />411<br />412<br />413<br />414<br />415<br />416<br />417<br />418<br />419<br />420<br />421<br />422<br />423<br />424<br />425<br />426<br />427<br />428<br />429<br />430<br />431<br />432<br />433<br />434<br />435<br />436<br />437<br />438<br />439<br />440<br />441<br />442<br />443<br />444<br />445<br />446<br />447<br />448<br />449<br />450<br />451<br />452<br />453<br />454<br />455<br />456<br />457<br />458<br />459<br />460<br />461<br />462<br />463<br />464<br />465<br />466<br />467<br />468<br />469<br />470<br />471<br />472<br />473<br />474<br />475<br />476<br />477<br />478<br />479<br />480<br />481<br />482<br />483<br />484<br />485<br />486<br />487<br />488<br />489<br />490<br />491<br />492<br />493<br />494<br />495<br />496<br />497<br />498<br />499<br />500<br />501<br />502<br />503<br />504<br />505</pre> </td> <td> <pre style="margin: 0; line-height: 125%"><br /><span style="color: #7E7E7E;">/* ===============================================================</span><br /><span style="color: #7E7E7E;"> Project: CH376S USB Read/Write Module testing ground</span><br /><span style="color: #7E7E7E;"> Author: Scott C</span><br /><span style="color: #7E7E7E;"> Created: 1st May 2015</span><br /><span style="color: #7E7E7E;"> Arduino IDE: 1.6.2</span><br /><span style="color: #7E7E7E;"> Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html</span><br /><span style="color: #7E7E7E;"> Description: This project will allow you to perform many of the functions available on the CH376S module.</span><br /><span style="color: #7E7E7E;"> Checking connection to the module, putting the module into USB mode, resetting the module, </span><br /><span style="color: #7E7E7E;"> reading, writing, appending text to files on the USB stick. This is very useful alternative to</span><br /><span style="color: #7E7E7E;"> SD card modules, plus it doesn't need any libraries.</span><br /><span style="color: #7E7E7E;">================================================================== */</span><br /><br />#include <<span style="color: #CC6600;">SoftwareSerial</span>.h><br /><br /><span style="color: #CC6600;">byte</span> computerByte; <span style="color: #7E7E7E;">//used to store data coming from the computer</span><br /><span style="color: #CC6600;">byte</span> USB_Byte; <span style="color: #7E7E7E;">//used to store data coming from the USB stick</span><br /><span style="color: #CC6600;">int</span> LED = 13; <span style="color: #7E7E7E;">//the LED is connected to digital pin 13 </span><br /><span style="color: #CC6600;">int</span> timeOut = 2000; <span style="color: #7E7E7E;">//TimeOut is 2 seconds. This is the amount of time you wish to wait for a response from the CH376S module.</span><br /><span style="color: #CC6600;">String</span> wrData = <span style="color: #006699;">"What is the meaning of life ?"</span>; <span style="color: #7E7E7E;">//We will write this data to a newly created file.</span><br /><span style="color: #CC6600;">String</span> wrData2 = <span style="color: #006699;">"42"</span>; <span style="color: #7E7E7E;">//We will append this data to an already existing file.</span><br /><br /><span style="color: #CC6600;">SoftwareSerial</span> USB(10, 11); <span style="color: #7E7E7E;">// Digital pin 10 on Arduino (RX) connects to TXD on the CH376S module</span><br /> <span style="color: #7E7E7E;">// Digital pin 11 on Arduino (TX) connects to RXD on the CH376S module</span><br /> <span style="color: #7E7E7E;">// GND on Arduino to GND on CH376S module</span><br /> <span style="color: #7E7E7E;">// 5V on Arduino to 5V on CH376S module</span><br /><span style="color: #7E7E7E;">//==============================================================================================================================================</span><br /><span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>setup</b></span>() {<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">begin</span>(9600); <span style="color: #7E7E7E;">// Setup serial communication with the computer (using a baud rate of 9600 on serial monitor)</span><br /> USB.<span style="color: #CC6600;">begin</span>(9600); <span style="color: #7E7E7E;">// Setup serial communication with the CH376S module (using the default baud rate of 9600)</span><br /> <span style="color: #CC6600;">pinMode</span>(LED,<span style="color: #006699;">OUTPUT</span>); <span style="color: #7E7E7E;">// Define digital pin 13 as an OUTPUT pin - so that we can use it with an LED</span><br /> <span style="color: #CC6600;">digitalWrite</span>(LED,<span style="color: #006699;">LOW</span>); <span style="color: #7E7E7E;">// Turn off the LED</span><br />}<br /><br /><span style="color: #7E7E7E;">//================================================================================================================================================</span><br /><span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>loop</b></span>() {<br /> <span style="color: #CC6600;">if</span>(<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">available</span>()){<br /> computerByte = <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">read</span>(); <span style="color: #7E7E7E;">//read any incoming bytes from the Serial monitor, and store this byte in the variable called computerByte</span><br /> <span style="color: #CC6600;">if</span>(computerByte==49){ <span style="color: #7E7E7E;">//1 //If you send the number 1 from the serial monitor, the arduino will read it as digital number 49. Google "ascii table" for more info.</span><br /> printCommandHeader(<span style="color: #006699;">"COMMAND1: CHECK CONNECTION"</span>);<br /> checkConnection(0x01); <span style="color: #7E7E7E;">// Check for successful connection and communication with the CH376S module.</span><br /> } <br /> <span style="color: #CC6600;">if</span>(computerByte==50){ <span style="color: #7E7E7E;">//2</span><br /> printCommandHeader(<span style="color: #006699;">"COMMAND2: set_USB_Mode"</span>);<br /> set_USB_Mode(0x06); <span style="color: #7E7E7E;">// Code used to enable read/write communication and monitoring of the USB stick</span><br /> }<br /> <span style="color: #CC6600;">if</span>(computerByte==51){ <span style="color: #7E7E7E;">//3</span><br /> printCommandHeader(<span style="color: #006699;">"COMMAND3: resetALL"</span>);<br /> resetALL(); <span style="color: #7E7E7E;">// Reset the USB device</span><br /> }<br /> <span style="color: #CC6600;">if</span>(computerByte==52){ <span style="color: #7E7E7E;">//4</span><br /> printCommandHeader(<span style="color: #006699;">"COMMAND4: Create and Write to File : TEST4.TXT"</span>);<br /> writeFile(<span style="color: #006699;">"TEST4.TXT"</span>, wrData); <span style="color: #7E7E7E;">// Create a file called TEST4.TXT and then Write the contents of wrData to this file</span><br /> }<br /> <span style="color: #CC6600;">if</span>(computerByte==53){ <span style="color: #7E7E7E;">//5</span><br /> printCommandHeader(<span style="color: #006699;">"COMMAND5: Read File: TEST4.TXT"</span>);<br /> readFile(<span style="color: #006699;">"TEST4.TXT"</span>); <span style="color: #7E7E7E;">// Read the contents of this file on the USB disk, and display contents in the Serial Monitor</span><br /> }<br /> <span style="color: #CC6600;">if</span>(computerByte==54){ <span style="color: #7E7E7E;">//6</span><br /> printCommandHeader(<span style="color: #006699;">"COMMAND6: Append data to file: TEST4.TXT"</span>);<br /> appendFile(<span style="color: #006699;">"TEST4.TXT"</span>, wrData2); <span style="color: #7E7E7E;">// Append data to the end of the file.</span><br /> }<br /> <span style="color: #CC6600;">if</span>(computerByte==55){ <span style="color: #7E7E7E;">//7</span><br /> printCommandHeader(<span style="color: #006699;">"COMMAND7: Delete File: TEST4.TXT"</span>);<br /> fileDelete(<span style="color: #006699;">"TEST4.TXT"</span>); <span style="color: #7E7E7E;">// Delete the file named TEST4.TXT</span><br /> }<br /> <span style="color: #CC6600;">if</span>(computerByte==56){ <span style="color: #7E7E7E;">//8</span><br /> printCommandHeader(<span style="color: #006699;">"COMMAND8: Read File: TEST2.TXT"</span>);<br /> readFile(<span style="color: #006699;">"TEST2.TXT"</span>); <span style="color: #7E7E7E;">// Read the contents of the TEST2.TXT file on the USB disk, and display contents in the Serial Monitor</span><br /> }<br /> <span style="color: #CC6600;">if</span>(computerByte==57){ <span style="color: #7E7E7E;">//9</span><br /> printCommandHeader(<span style="color: #006699;">"COMMAND9: Read File: TEST3.TXT"</span>);<br /> readFile(<span style="color: #006699;">"TEST3.TXT"</span>); <span style="color: #7E7E7E;">// Read the contents of the TEST3.TXT file on the USB disk, and display contents in the Serial Monitor</span><br /> }<br /> }<br /> <br /> <span style="color: #CC6600;">if</span>(USB.<span style="color: #CC6600;">available</span>()){ <span style="color: #7E7E7E;">// This is here to capture any unexpected data transmitted by the CH376S module</span><br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"CH376S has just sent this code:"</span>);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(USB.<span style="color: #CC6600;">read</span>(), <span style="color: #006699;">HEX</span>);<br /> }<br />}<br /><br /><span style="color: #7E7E7E;">//END OF LOOP FUNCTION ========================================================================================================================================</span><br /><br /><span style="color: #7E7E7E;">//print Command header</span><br /><span style="color: #CC6600;">void</span> printCommandHeader(<span style="color: #CC6600;">String</span> header){<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"======================"</span>);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">""</span>);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(header);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"----------------------"</span>);<br />}<br /><br /><span style="color: #7E7E7E;">//checkConnection==================================================================================</span><br /><span style="color: #7E7E7E;">//This function is used to check for successful communication with the CH376S module. This is not dependant of the presence of a USB stick.</span><br /><span style="color: #7E7E7E;">//Send any value between 0 to 255, and the CH376S module will return a number = 255 - value. </span><br /><span style="color: #CC6600;">void</span> checkConnection(<span style="color: #CC6600;">byte</span> value){<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x06);<br /> USB.<span style="color: #CC6600;">write</span>(value);<br /> <br /> <span style="color: #CC6600;">if</span>(waitForResponse(<span style="color: #006699;">"checking connection"</span>)){ <span style="color: #7E7E7E;">//wait for a response from the CH376S. If CH376S responds, it will be true. If it times out, it will be false.</span><br /> <span style="color: #CC6600;">if</span>(getResponseFromUSB()==(255-value)){<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">">Connection to CH376S was successful."</span>);<br /> blinkLED(); <span style="color: #7E7E7E;">//blink the LED for 1 second if the connection was successful</span><br /> } <span style="color: #CC6600;">else</span> {<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">">Connection to CH376S - FAILED."</span>);<br /> }<br /> }<br />}<br /><br /><span style="color: #7E7E7E;">//set_USB_Mode=====================================================================================</span><br /><span style="color: #7E7E7E;">//Make sure that the USB is inserted when using 0x06 as the value in this specific code sequence</span><br /><span style="color: #CC6600;">void</span> set_USB_Mode (<span style="color: #CC6600;">byte</span> value){<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x15);<br /> USB.<span style="color: #CC6600;">write</span>(value);<br /> <br /> <span style="color: #CC6600;">delay</span>(20);<br /> <br /> <span style="color: #CC6600;">if</span>(USB.<span style="color: #CC6600;">available</span>()){<br /> USB_Byte=USB.<span style="color: #CC6600;">read</span>();<br /> <span style="color: #7E7E7E;">//Check to see if the command has been successfully transmitted and acknowledged.</span><br /> <span style="color: #CC6600;">if</span>(USB_Byte==0x51){ <span style="color: #7E7E7E;">// If true - the CH376S has acknowledged the command.</span><br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"set_USB_Mode command acknowledged"</span>); <span style="color: #7E7E7E;">//The CH376S will now check and monitor the USB port</span><br /> USB_Byte = USB.<span style="color: #CC6600;">read</span>();<br /> <br /> <span style="color: #7E7E7E;">//Check to see if the USB stick is connected or not.</span><br /> <span style="color: #CC6600;">if</span>(USB_Byte==0x15){ <span style="color: #7E7E7E;">// If true - there is a USB stick connected</span><br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"USB is present"</span>);<br /> blinkLED(); <span style="color: #7E7E7E;">// If the process was successful, then turn the LED on for 1 second </span><br /> } <span style="color: #CC6600;">else</span> {<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"USB Not present. Error code:"</span>); <span style="color: #7E7E7E;">// If the USB is not connected - it should return an Error code = FFH</span><br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(USB_Byte, <span style="color: #006699;">HEX</span>);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"H"</span>);<br /> }<br /> <br /> } <span style="color: #CC6600;">else</span> {<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"CH3765 error! Error code:"</span>);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(USB_Byte, <span style="color: #006699;">HEX</span>);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"H"</span>);<br /> } <br /> }<br /> <span style="color: #CC6600;">delay</span>(20);<br />}<br /><br /><span style="color: #7E7E7E;">//resetALL=========================================================================================</span><br /><span style="color: #7E7E7E;">//This will perform a hardware reset of the CH376S module - which usually takes about 35 msecs =====</span><br /><span style="color: #CC6600;">void</span> resetALL(){<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x05);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"The CH376S module has been reset !"</span>);<br /> <span style="color: #CC6600;">delay</span>(200);<br />}<br /><br /><span style="color: #7E7E7E;">//readFile=====================================================================================</span><br /><span style="color: #7E7E7E;">//This will send a series of commands to read data from a specific file (defined by fileName)</span><br /><span style="color: #CC6600;">void</span> readFile(<span style="color: #CC6600;">String</span> fileName){<br /> resetALL(); <span style="color: #7E7E7E;">//Reset the module</span><br /> set_USB_Mode(0x06); <span style="color: #7E7E7E;">//Set to USB Mode</span><br /> diskConnectionStatus(); <span style="color: #7E7E7E;">//Check that communication with the USB device is possible</span><br /> USBdiskMount(); <span style="color: #7E7E7E;">//Prepare the USB for reading/writing - you need to mount the USB disk for proper read/write operations.</span><br /> setFileName(fileName); <span style="color: #7E7E7E;">//Set File name</span><br /> fileOpen(); <span style="color: #7E7E7E;">//Open the file for reading</span><br /> <span style="color: #CC6600;">int</span> fs = getFileSize(); <span style="color: #7E7E7E;">//Get the size of the file</span><br /> fileRead(); <span style="color: #7E7E7E;">//***** Send the command to read the file ***</span><br /> fileClose(0x00); <span style="color: #7E7E7E;">//Close the file</span><br />}<br /><br /><span style="color: #7E7E7E;">//writeFile========================================================================================</span><br /><span style="color: #7E7E7E;">//is used to create a new file and then write data to that file. "fileName" is a variable used to hold the name of the file (e.g TEST.TXT). "data" should not be greater than 255 bytes long. </span><br /><span style="color: #CC6600;">void</span> writeFile(<span style="color: #CC6600;">String</span> fileName, <span style="color: #CC6600;">String</span> data){<br /> resetALL(); <span style="color: #7E7E7E;">//Reset the module</span><br /> set_USB_Mode(0x06); <span style="color: #7E7E7E;">//Set to USB Mode</span><br /> diskConnectionStatus(); <span style="color: #7E7E7E;">//Check that communication with the USB device is possible</span><br /> USBdiskMount(); <span style="color: #7E7E7E;">//Prepare the USB for reading/writing - you need to mount the USB disk for proper read/write operations.</span><br /> setFileName(fileName); <span style="color: #7E7E7E;">//Set File name</span><br /> <span style="color: #CC6600;">if</span>(fileCreate()){ <span style="color: #7E7E7E;">//Try to create a new file. If file creation is successful</span><br /> fileWrite(data); <span style="color: #7E7E7E;">//write data to the file.</span><br /> } <span style="color: #CC6600;">else</span> {<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"File could not be created, or it already exists"</span>);<br /> }<br /> fileClose(0x01);<br />}<br /><br /><span style="color: #7E7E7E;">//appendFile()====================================================================================</span><br /><span style="color: #7E7E7E;">//is used to write data to the end of the file, without erasing the contents of the file.</span><br /><span style="color: #CC6600;">void</span> appendFile(<span style="color: #CC6600;">String</span> fileName, <span style="color: #CC6600;">String</span> data){<br /> resetALL(); <span style="color: #7E7E7E;">//Reset the module</span><br /> set_USB_Mode(0x06); <span style="color: #7E7E7E;">//Set to USB Mode</span><br /> diskConnectionStatus(); <span style="color: #7E7E7E;">//Check that communication with the USB device is possible</span><br /> USBdiskMount(); <span style="color: #7E7E7E;">//Prepare the USB for reading/writing - you need to mount the USB disk for proper read/write operations.</span><br /> setFileName(fileName); <span style="color: #7E7E7E;">//Set File name</span><br /> fileOpen(); <span style="color: #7E7E7E;">//Open the file</span><br /> filePointer(<span style="color: #CC6600;">false</span>); <span style="color: #7E7E7E;">//filePointer(false) is to set the pointer at the end of the file. filePointer(true) will set the pointer to the beginning.</span><br /> fileWrite(data); <span style="color: #7E7E7E;">//Write data to the end of the file</span><br /> fileClose(0x01); <span style="color: #7E7E7E;">//Close the file using 0x01 - which means to update the size of the file on close. </span><br />}<br /> <br /><span style="color: #7E7E7E;">//setFileName======================================================================================</span><br /><span style="color: #7E7E7E;">//This sets the name of the file to work with</span><br /><span style="color: #CC6600;">void</span> setFileName(<span style="color: #CC6600;">String</span> fileName){<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"Setting filename to:"</span>);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(fileName);<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x2F);<br /> USB.<span style="color: #CC6600;">write</span>(0x2F); <span style="color: #7E7E7E;">// Every filename must have this byte to indicate the start of the file name.</span><br /> USB.<span style="color: #CC6600;">print</span>(fileName); <span style="color: #7E7E7E;">// "fileName" is a variable that holds the name of the file. eg. TEST.TXT</span><br /> USB.<span style="color: #CC6600;">write</span>((<span style="color: #CC6600;">byte</span>)0x00); <span style="color: #7E7E7E;">// you need to cast as a byte - otherwise it will not compile. The null byte indicates the end of the file name.</span><br /> <span style="color: #CC6600;">delay</span>(20);<br />}<br /><br /><span style="color: #7E7E7E;">//diskConnectionStatus================================================================================</span><br /><span style="color: #7E7E7E;">//Check the disk connection status</span><br /><span style="color: #CC6600;">void</span> diskConnectionStatus(){<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"Checking USB disk connection status"</span>);<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x30);<br /><br /> <span style="color: #CC6600;">if</span>(waitForResponse(<span style="color: #006699;">"Connecting to USB disk"</span>)){ <span style="color: #7E7E7E;">//wait for a response from the CH376S. If CH376S responds, it will be true. If it times out, it will be false.</span><br /> <span style="color: #CC6600;">if</span>(getResponseFromUSB()==0x14){ <span style="color: #7E7E7E;">//CH376S will send 0x14 if this command was successful</span><br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">">Connection to USB OK"</span>);<br /> } <span style="color: #CC6600;">else</span> {<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">">Connection to USB - FAILED."</span>);<br /> }<br /> }<br />}<br /><br /><span style="color: #7E7E7E;">//USBdiskMount========================================================================================</span><br /><span style="color: #7E7E7E;">//initialise the USB disk and check that it is ready - this process is required if you want to find the manufacturing information of the USB disk</span><br /><span style="color: #CC6600;">void</span> USBdiskMount(){<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"Mounting USB disk"</span>);<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x31);<br /><br /> <span style="color: #CC6600;">if</span>(waitForResponse(<span style="color: #006699;">"mounting USB disk"</span>)){ <span style="color: #7E7E7E;">//wait for a response from the CH376S. If CH376S responds, it will be true. If it times out, it will be false.</span><br /> <span style="color: #CC6600;">if</span>(getResponseFromUSB()==0x14){ <span style="color: #7E7E7E;">//CH376S will send 0x14 if this command was successful</span><br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">">USB Mounted - OK"</span>);<br /> } <span style="color: #CC6600;">else</span> {<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">">Failed to Mount USB disk."</span>);<br /> }<br /> }<br />}<br /><br /><span style="color: #7E7E7E;">//fileOpen========================================================================================</span><br /><span style="color: #7E7E7E;">//opens the file for reading or writing</span><br /><span style="color: #CC6600;">void</span> fileOpen(){<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"Opening file."</span>);<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x32);<br /> <span style="color: #CC6600;">if</span>(waitForResponse(<span style="color: #006699;">"file Open"</span>)){ <span style="color: #7E7E7E;">//wait for a response from the CH376S. If CH376S responds, it will be true. If it times out, it will be false.</span><br /> <span style="color: #CC6600;">if</span>(getResponseFromUSB()==0x14){ <span style="color: #7E7E7E;">//CH376S will send 0x14 if this command was successful </span><br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">">File opened successfully."</span>);<br /> } <span style="color: #CC6600;">else</span> {<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">">Failed to open file."</span>);<br /> }<br /> }<br />}<br /><br /><span style="color: #7E7E7E;">//setByteRead=====================================================================================</span><br /><span style="color: #7E7E7E;">//This function is required if you want to read data from the file. </span><br /><span style="color: #CC6600;">boolean</span> setByteRead(<span style="color: #CC6600;">byte</span> numBytes){<br /> <span style="color: #CC6600;">boolean</span> bytesToRead=<span style="color: #CC6600;">false</span>;<br /> <span style="color: #CC6600;">int</span> timeCounter = 0;<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x3A);<br /> USB.<span style="color: #CC6600;">write</span>((<span style="color: #CC6600;">byte</span>)numBytes); <span style="color: #7E7E7E;">//tells the CH376S how many bytes to read at a time</span><br /> USB.<span style="color: #CC6600;">write</span>((<span style="color: #CC6600;">byte</span>)0x00);<br /> <span style="color: #CC6600;">if</span>(waitForResponse(<span style="color: #006699;">"setByteRead"</span>)){ <span style="color: #7E7E7E;">//wait for a response from the CH376S. If CH376S responds, it will be true. If it times out, it will be false.</span><br /> <span style="color: #CC6600;">if</span>(getResponseFromUSB()==0x1D){ <span style="color: #7E7E7E;">//read the CH376S message. If equal to 0x1D, data is present, so return true. Will return 0x14 if no data is present.</span><br /> bytesToRead=<span style="color: #CC6600;">true</span>;<br /> }<br /> }<br /> <span style="color: #CC6600;">return</span>(bytesToRead);<br />} <br /><br /><span style="color: #7E7E7E;">//getFileSize()===================================================================================</span><br /><span style="color: #7E7E7E;">//writes the file size to the serial Monitor.</span><br /><span style="color: #CC6600;">int</span> getFileSize(){<br /> <span style="color: #CC6600;">int</span> fileSize=0;<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"Getting File Size"</span>);<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x0C);<br /> USB.<span style="color: #CC6600;">write</span>(0x68);<br /> <span style="color: #CC6600;">delay</span>(100);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"FileSize ="</span>);<br /> <span style="color: #CC6600;">if</span>(USB.<span style="color: #CC6600;">available</span>()){<br /> fileSize = fileSize + USB.<span style="color: #CC6600;">read</span>();<br /> } <br /> <span style="color: #CC6600;">if</span>(USB.<span style="color: #CC6600;">available</span>()){<br /> fileSize = fileSize + (USB.<span style="color: #CC6600;">read</span>()*255);<br /> } <br /> <span style="color: #CC6600;">if</span>(USB.<span style="color: #CC6600;">available</span>()){<br /> fileSize = fileSize + (USB.<span style="color: #CC6600;">read</span>()*255*255);<br /> } <br /> <span style="color: #CC6600;">if</span>(USB.<span style="color: #CC6600;">available</span>()){<br /> fileSize = fileSize + (USB.<span style="color: #CC6600;">read</span>()*255*255*255);<br /> } <br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(fileSize);<br /> <span style="color: #CC6600;">delay</span>(10);<br /> <span style="color: #CC6600;">return</span>(fileSize);<br />}<br /><br /><br /><span style="color: #7E7E7E;">//fileRead========================================================================================</span><br /><span style="color: #7E7E7E;">//read the contents of the file</span><br /><span style="color: #CC6600;">void</span> fileRead(){<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"Reading file:"</span>);<br /> <span style="color: #CC6600;">byte</span> firstByte = 0x00; <span style="color: #7E7E7E;">//Variable to hold the firstByte from every transmission. Can be used as a checkSum if required.</span><br /> <span style="color: #CC6600;">byte</span> numBytes = 0x40; <span style="color: #7E7E7E;">//The maximum value is 0x40 = 64 bytes</span><br /> <br /> <span style="color: #CC6600;">while</span>(setByteRead(numBytes)){ <span style="color: #7E7E7E;">//This tells the CH376S module how many bytes to read on the next reading step. In this example, we will read 0x10 bytes at a time. Returns true if there are bytes to read, false if there are no more bytes to read.</span><br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x27); <span style="color: #7E7E7E;">//Command to read ALL of the bytes (allocated by setByteRead(x))</span><br /> <span style="color: #CC6600;">if</span>(waitForResponse(<span style="color: #006699;">"reading data"</span>)){ <span style="color: #7E7E7E;">//Wait for the CH376S module to return data. TimeOut will return false. If data is being transmitted, it will return true.</span><br /> firstByte=USB.<span style="color: #CC6600;">read</span>(); <span style="color: #7E7E7E;">//Read the first byte</span><br /> <span style="color: #CC6600;">while</span>(USB.<span style="color: #CC6600;">available</span>()){<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">write</span>(USB.<span style="color: #CC6600;">read</span>()); <span style="color: #7E7E7E;">//Send the data from the USB disk to the Serial monitor</span><br /> <span style="color: #CC6600;">delay</span>(1); <span style="color: #7E7E7E;">//This delay is necessary for successful Serial transmission</span><br /> }<br /> }<br /> <span style="color: #CC6600;">if</span>(!continueRead()){ <span style="color: #7E7E7E;">//prepares the module for further reading. If false, stop reading.</span><br /> <span style="color: #CC6600;">break</span>; <span style="color: #7E7E7E;">//You need the continueRead() method if the data to be read from the USB device is greater than numBytes.</span><br /> }<br /> }<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>();<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"NO MORE DATA"</span>);<br />}<br /><br /><span style="color: #7E7E7E;">//fileWrite=======================================================================================</span><br /><span style="color: #7E7E7E;">//are the commands used to write to the file</span><br /><span style="color: #CC6600;">void</span> fileWrite(<span style="color: #CC6600;">String</span> data){<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"Writing to file:"</span>);<br /> <span style="color: #CC6600;">byte</span> dataLength = (<span style="color: #CC6600;">byte</span>) data.<span style="color: #CC6600;">length</span>(); <span style="color: #7E7E7E;">// This variable holds the length of the data to be written (in bytes)</span><br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(data);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"Data Length:"</span>);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(dataLength);<br /> <span style="color: #CC6600;">delay</span>(100);<br /> <span style="color: #7E7E7E;">// This set of commands tells the CH376S module how many bytes to expect from the Arduino. (defined by the "dataLength" variable)</span><br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x3C);<br /> USB.<span style="color: #CC6600;">write</span>((<span style="color: #CC6600;">byte</span>) dataLength);<br /> USB.<span style="color: #CC6600;">write</span>((<span style="color: #CC6600;">byte</span>) 0x00);<br /> <span style="color: #CC6600;">if</span>(waitForResponse(<span style="color: #006699;">"setting data Length"</span>)){ <span style="color: #7E7E7E;">// Wait for an acknowledgement from the CH376S module before trying to send data to it</span><br /> <span style="color: #CC6600;">if</span>(getResponseFromUSB()==0x1E){ <span style="color: #7E7E7E;">// 0x1E indicates that the USB device is in write mode.</span><br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x2D);<br /> USB.<span style="color: #CC6600;">print</span>(data); <span style="color: #7E7E7E;">// write the data to the file</span><br /> <br /> <span style="color: #CC6600;">if</span>(waitForResponse(<span style="color: #006699;">"writing data to file"</span>)){ <span style="color: #7E7E7E;">// wait for an acknowledgement from the CH376S module</span><br /> }<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"Write code (normally FF and 14): "</span>);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(USB.<span style="color: #CC6600;">read</span>(),<span style="color: #006699;">HEX</span>); <span style="color: #7E7E7E;">// code is normally 0xFF</span><br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">","</span>);<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x3D); <span style="color: #7E7E7E;">// This is used to update the file size. Not sure if this is necessary for successful writing.</span><br /> <span style="color: #CC6600;">if</span>(waitForResponse(<span style="color: #006699;">"updating file size"</span>)){ <span style="color: #7E7E7E;">// wait for an acknowledgement from the CH376S module</span><br /> }<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(USB.<span style="color: #CC6600;">read</span>(),<span style="color: #006699;">HEX</span>); <span style="color: #7E7E7E;">//code is normally 0x14</span><br /> }<br /> }<br />}<br /><br /><span style="color: #7E7E7E;">//continueRead()==================================================================================</span><br /><span style="color: #7E7E7E;">//continue to read the file : I could not get this function to work as intended.</span><br /><span style="color: #CC6600;">boolean</span> continueRead(){<br /> <span style="color: #CC6600;">boolean</span> readAgain = <span style="color: #CC6600;">false</span>;<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x3B);<br /> <span style="color: #CC6600;">if</span>(waitForResponse(<span style="color: #006699;">"continueRead"</span>)){ <span style="color: #7E7E7E;">//wait for a response from the CH376S. If CH376S responds, it will be true. If it times out, it will be false.</span><br /> <span style="color: #CC6600;">if</span>(getResponseFromUSB()==0x14){ <span style="color: #7E7E7E;">//CH376S will send 0x14 if this command was successful</span><br /> readAgain=<span style="color: #CC6600;">true</span>;<br /> }<br /> }<br /> <span style="color: #CC6600;">return</span>(readAgain);<br />} <br /><br /><span style="color: #7E7E7E;">//fileCreate()========================================================================================</span><br /><span style="color: #7E7E7E;">//the command sequence to create a file</span><br /><span style="color: #CC6600;">boolean</span> fileCreate(){<br /> <span style="color: #CC6600;">boolean</span> createdFile = <span style="color: #CC6600;">false</span>;<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x34);<br /> <span style="color: #CC6600;">if</span>(waitForResponse(<span style="color: #006699;">"creating file"</span>)){ <span style="color: #7E7E7E;">//wait for a response from the CH376S. If file has been created successfully, it will return true.</span><br /> <span style="color: #CC6600;">if</span>(getResponseFromUSB()==0x14){ <span style="color: #7E7E7E;">//CH376S will send 0x14 if this command was successful</span><br /> createdFile=<span style="color: #CC6600;">true</span>;<br /> }<br /> }<br /> <span style="color: #CC6600;">return</span>(createdFile);<br />}<br /><br /><br /><span style="color: #7E7E7E;">//fileDelete()========================================================================================</span><br /><span style="color: #7E7E7E;">//the command sequence to delete a file</span><br /><span style="color: #CC6600;">void</span> fileDelete(<span style="color: #CC6600;">String</span> fileName){<br /> setFileName(fileName);<br /> <span style="color: #CC6600;">delay</span>(20);<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x35);<br /> <span style="color: #CC6600;">if</span>(waitForResponse(<span style="color: #006699;">"deleting file"</span>)){ <span style="color: #7E7E7E;">//wait for a response from the CH376S. If file has been created successfully, it will return true.</span><br /> <span style="color: #CC6600;">if</span>(getResponseFromUSB()==0x14){ <span style="color: #7E7E7E;">//CH376S will send 0x14 if this command was successful</span><br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"Successfully deleted file"</span>);<br /> }<br /> }<br />}<br /> <br /><br /><span style="color: #7E7E7E;">//filePointer========================================================================================</span><br /><span style="color: #7E7E7E;">//is used to set the file pointer position. true for beginning of file, false for the end of the file.</span><br /><span style="color: #CC6600;">void</span> filePointer(<span style="color: #CC6600;">boolean</span> fileBeginning){<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x39);<br /> <span style="color: #CC6600;">if</span>(fileBeginning){<br /> USB.<span style="color: #CC6600;">write</span>((<span style="color: #CC6600;">byte</span>)0x00); <span style="color: #7E7E7E;">//beginning of file</span><br /> USB.<span style="color: #CC6600;">write</span>((<span style="color: #CC6600;">byte</span>)0x00);<br /> USB.<span style="color: #CC6600;">write</span>((<span style="color: #CC6600;">byte</span>)0x00);<br /> USB.<span style="color: #CC6600;">write</span>((<span style="color: #CC6600;">byte</span>)0x00);<br /> } <span style="color: #CC6600;">else</span> {<br /> USB.<span style="color: #CC6600;">write</span>((<span style="color: #CC6600;">byte</span>)0xFF); <span style="color: #7E7E7E;">//end of file</span><br /> USB.<span style="color: #CC6600;">write</span>((<span style="color: #CC6600;">byte</span>)0xFF);<br /> USB.<span style="color: #CC6600;">write</span>((<span style="color: #CC6600;">byte</span>)0xFF);<br /> USB.<span style="color: #CC6600;">write</span>((<span style="color: #CC6600;">byte</span>)0xFF);<br /> }<br /> <span style="color: #CC6600;">if</span>(waitForResponse(<span style="color: #006699;">"setting file pointer"</span>)){ <span style="color: #7E7E7E;">//wait for a response from the CH376S. </span><br /> <span style="color: #CC6600;">if</span>(getResponseFromUSB()==0x14){ <span style="color: #7E7E7E;">//CH376S will send 0x14 if this command was successful</span><br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"Pointer successfully applied"</span>);<br /> }<br /> }<br />}<br /><br /><br /><span style="color: #7E7E7E;">//fileClose=======================================================================================</span><br /><span style="color: #7E7E7E;">//closes the file</span><br /><span style="color: #CC6600;">void</span> fileClose(<span style="color: #CC6600;">byte</span> closeCmd){<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"Closing file:"</span>);<br /> USB.<span style="color: #CC6600;">write</span>(0x57);<br /> USB.<span style="color: #CC6600;">write</span>(0xAB);<br /> USB.<span style="color: #CC6600;">write</span>(0x36);<br /> USB.<span style="color: #CC6600;">write</span>((<span style="color: #CC6600;">byte</span>)closeCmd); <span style="color: #7E7E7E;">// closeCmd = 0x00 = close without updating file Size, 0x01 = close and update file Size</span><br /><br /> <span style="color: #CC6600;">if</span>(waitForResponse(<span style="color: #006699;">"closing file"</span>)){ <span style="color: #7E7E7E;">// wait for a response from the CH376S. </span><br /> <span style="color: #CC6600;">byte</span> resp = getResponseFromUSB();<br /> <span style="color: #CC6600;">if</span>(resp==0x14){ <span style="color: #7E7E7E;">// CH376S will send 0x14 if this command was successful</span><br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">">File closed successfully."</span>);<br /> } <span style="color: #CC6600;">else</span> {<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">">Failed to close file. Error code:"</span>);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(resp, <span style="color: #006699;">HEX</span>);<br /> } <br /> }<br />}<br /><br /><span style="color: #7E7E7E;">//waitForResponse===================================================================================</span><br /><span style="color: #7E7E7E;">//is used to wait for a response from USB. Returns true when bytes become available, false if it times out.</span><br /><span style="color: #CC6600;">boolean</span> waitForResponse(<span style="color: #CC6600;">String</span> errorMsg){<br /> <span style="color: #CC6600;">boolean</span> bytesAvailable = <span style="color: #CC6600;">true</span>;<br /> <span style="color: #CC6600;">int</span> counter=0;<br /> <span style="color: #CC6600;">while</span>(!USB.<span style="color: #CC6600;">available</span>()){ <span style="color: #7E7E7E;">//wait for CH376S to verify command</span><br /> <span style="color: #CC6600;">delay</span>(1);<br /> counter++;<br /> <span style="color: #CC6600;">if</span>(counter>timeOut){<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"TimeOut waiting for response: Error while: "</span>);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(errorMsg);<br /> bytesAvailable = <span style="color: #CC6600;">false</span>;<br /> <span style="color: #CC6600;">break</span>;<br /> }<br /> }<br /> <span style="color: #CC6600;">delay</span>(1);<br /> <span style="color: #CC6600;">return</span>(bytesAvailable);<br />}<br /><br /><span style="color: #7E7E7E;">//getResponseFromUSB================================================================================</span><br /><span style="color: #7E7E7E;">//is used to get any error codes or messages from the CH376S module (in response to certain commands)</span><br /><span style="color: #CC6600;">byte</span> getResponseFromUSB(){<br /> <span style="color: #CC6600;">byte</span> response = <span style="color: #CC6600;">byte</span>(0x00);<br /> <span style="color: #CC6600;">if</span> (USB.<span style="color: #CC6600;">available</span>()){<br /> response = USB.<span style="color: #CC6600;">read</span>();<br /> }<br /> <span style="color: #CC6600;">return</span>(response);<br />}<br /><br /><br /><br /><span style="color: #7E7E7E;">//blinkLED==========================================================================================</span><br /><span style="color: #7E7E7E;">//Turn an LED on for 1 second</span><br /><span style="color: #CC6600;">void</span> blinkLED(){<br /> <span style="color: #CC6600;">digitalWrite</span>(LED, <span style="color: #006699;">HIGH</span>);<br /> <span style="color: #CC6600;">delay</span>(1000);<br /> <span style="color: #CC6600;">digitalWrite</span>(LED,<span style="color: #006699;">LOW</span>);<br />}<br /><br /></pre> </td> </tr> </table></div></P> <BR /> <P> If you copy and paste this code directly into the Arduino IDE; you may get a warning like this when you compile the code:<br> <br> "Low memory available, stability problems may occur". <br> <br> I managed to run the sketch without any issues, however, I did experience problems with some of the methods when I had made further memory hungry modifications. If you do encounter problems, I would recommend that you eliminate any methods which you do not plan to use, and perhaps reduce the number of Serial.print statements throughout the code. However, please note that some of the methods will not work unless the module is in the correct state, so be careful which methods you delete. For example, I found that I could get some simple functionality without the "USBdiskMount()" method. However, I could not read/write data beyond a certain length without this method.<br> <br> Also please note, that some of the methods called within the reading and writing sequence do not need to be called every time. They can be called once in setup, while other methods within the sequence will need to be called every time. I grouped them all together for simplicity. </P> <!--separator --><img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <P><h4>Serial Commands</h4> Have a look at the following presentation for a summary of the Serial commands used in this tutorial: <br> <br> <div align="left"> <iframe src="https://docs.google.com/presentation/d/1t-jgM9xnAGvfuTMGv3GuY0CxSmXZHLwYTnU_DO3SzwA/embed?start=false&loop=false&delayms=15000" frameborder="0" width="640" height="509" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe> </div> </P> </div><P> <div style="text-align: justify;"> <!-- Concluding Comments --> </div> <BR /> <BR /> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> <div align="center"> If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br> <BR /> <BR /> Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br> Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br> I can also be found on <a href="https://www.pinterest.com/ArduinoBasics/">Pinterest</a> and <a href="https://instagram.com/arduinobasics">Instagram</a>. <br> Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.<br> </div> </P> <br> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> However, if you do not have a google profile... <br>Feel free to share this page with your friends in any way you see fit. </P></P></P><br /><br /><br /><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" -->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-75403195035668437652015-04-24T01:32:00.000-07:002016-03-19T10:53:41.015-07:00Arduino Heart Rate Monitor <g:plusone></g:plusone><div style="text-align: justify;"> <P> <div style="text-align: center;"> <iframe width="640" height="400" src="https://www.youtube.com/embed/jXKNWb1esoc?rel=0&showinfo=0" frameborder="1" allowfullscreen></iframe> </div> </P> <br> <P> <div> <P> <H4>Project Description</H4><br> Heart Rate Monitors are very popular at the moment. <br> There is something very appealing about watching the pattern of your own heart beat. And once you see it, there is an unstoppable urge to try and control it. This simple project will allow you to visualize your heart beat, and will calculate your heart rate. Keep reading to learn how to create your very own heart rate monitor. </P> </div> </P> <BR /> <P> <H4>Parts Required:</H4> <P> <ul> <li><a href="http://www.epictinker.com/Freetronics-Eleven-100-Arduino-Uno-Compatible-p/ard-1002.htm">Arduino UNO or compatible board</a></li> <li><a href="http://www.epictinker.com/Grove-Base-Shield-v1-3-p/sld01099p.htm">Grove Base Shield</a></li> <li><a href="http://www.epictinker.com/Grove-Ear-clip-Heart-Rate-Sensor-p/med03212p.htm">Grove Ear-clip Heart Rate Sensor</a></li> <li><a href="http://www.epictinker.com/Grove-Universal-4-Pin-20cm-Cable-5pk-p/acc11317o.htm">Grove Universal 4 pin cables</a></li> <li><a href="http://www.epictinker.com/Grove-Blue-LED-p/com04051p.htm">LED and 330 ohm resistor</a></li> <br /> </ul> </P> </P> <BR /> <P> <H4><a href="http://fritzing.org/download/">Fritzing Sketch</a></H4> <BR /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxZ_IN49eG8UckUOcvpRnO9j7TRxbrGk5PbIULpCQ-5hwVU4jNkNNf-utbejlPD8felZWft4qY1NfzFwN2CxYL0MG52NmxbtV1t4GrFeR5xC-mWiYb7ci57b3aerCtd0Q60cLDk6g5Obg/s1600/Slide6.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxZ_IN49eG8UckUOcvpRnO9j7TRxbrGk5PbIULpCQ-5hwVU4jNkNNf-utbejlPD8felZWft4qY1NfzFwN2CxYL0MG52NmxbtV1t4GrFeR5xC-mWiYb7ci57b3aerCtd0Q60cLDk6g5Obg/s1600/Slide6.JPG" height="480" width="640" /></a></div> <BR /> <BR /> <BR /> <BR /> <H4>Grove Base Shield to Module Connections</H4> <BR /> <br> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVp8-yeVZqFZ5RTM2jDHQIpkwfasWw0sSD5i-LC0dQA7YAAt2Mxb22IAYyC4DKbVXALILqCh_2CqpgXHScW7xyVxAM4fglM43CMY-u_JIxbHk6UIA7sJUlBzl5ED7kLeCMwMTKSZnlyeg/s1600/Slide7.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVp8-yeVZqFZ5RTM2jDHQIpkwfasWw0sSD5i-LC0dQA7YAAt2Mxb22IAYyC4DKbVXALILqCh_2CqpgXHScW7xyVxAM4fglM43CMY-u_JIxbHk6UIA7sJUlBzl5ED7kLeCMwMTKSZnlyeg/s1600/Slide7.JPG" height="480" width="640" /></a></div> <br /> </P> <BR /> <P> <H4><a href="http://www.arduino.cc/en/main/Software">Arduino Sketch</a></H4> <BR /> <div style="background: #ffffff; color: #000000; overflow:auto;width:auto;border:solid rgb(24,186,183);border-width: .6em .3em .3em .3em;padding: 0em 0em;"> <table> <tr> <td> <pre style="margin: 0; line-height: 125%; background: rgb(24,186,183); width: 1.9em"><br /> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br /> 10<br /> 11<br /> 12<br /> 13<br /> 14<br /> 15<br /> 16<br /> 17<br /> 18<br /> 19<br /> 20<br /> 21<br /> 22<br /> 23<br /> 24<br /> 25<br /> 26<br /> 27<br /> 28<br /> 29<br /> 30<br /> 31<br /> 32<br /> 33<br /> 34<br /> 35<br /> 36<br /> 37<br /> 38<br /> 39<br /> 40<br /> 41<br /> 42<br /> 43<br /> 44<br /> 45</pre> </td> <td> <pre style="margin: 0; line-height: 125%"><span style="color: #7E7E7E;">/* =================================================================================================</span><br /><span style="color: #7E7E7E;"> Project: Arduino Heart rate monitor</span><br /><span style="color: #7E7E7E;"> Author: Scott C</span><br /><span style="color: #7E7E7E;"> Created: 21st April 2015</span><br /><span style="color: #7E7E7E;"> Arduino IDE: 1.6.2</span><br /><span style="color: #7E7E7E;"> Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html</span><br /><span style="color: #7E7E7E;"> Description: This is a simple sketch that uses a Grove Ear-clip Heart Rate sensor attached to an Arduino UNO,</span><br /><span style="color: #7E7E7E;"> which sends heart rate data to the computer via Serial communication. You can see the raw data</span><br /><span style="color: #7E7E7E;"> using the Serial monitor on the Arduino IDE, however, this sketch was specifically</span><br /><span style="color: #7E7E7E;"> designed to interface with the matching Processing sketch for a much nicer graphical display.</span><br /><span style="color: #7E7E7E;"> NO LIBRARIES REQUIRED.</span><br /><span style="color: #7E7E7E;">=================================================================================================== */</span><br /><br />#define Heart 2 <span style="color: #7E7E7E;">//Attach the Grove Ear-clip sensor to digital pin 2.</span><br />#define LED 4 <span style="color: #7E7E7E;">//Attach an LED to digital pin 4</span><br /><br /><span style="color: #CC6600;">boolean</span> beat = <span style="color: #CC6600;">false</span>; <span style="color: #7E7E7E;">/* This "beat" variable is used to control the timing of the Serial communication</span><br /><span style="color: #7E7E7E;"> so that data is only sent when there is a "change" in digital readings. */</span><br /><br /><span style="color: #7E7E7E;">//==SETUP==========================================================================================</span><br /><span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>setup</b></span>() {<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">begin</span>(9600); <span style="color: #7E7E7E;">//Initialise serial communication</span><br /> <span style="color: #CC6600;">pinMode</span>(Heart, <span style="color: #006699;">INPUT</span>); <span style="color: #7E7E7E;">//Set digital pin 2 (heart rate sensor pin) as an INPUT</span><br /> <span style="color: #CC6600;">pinMode</span>(LED, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7E7E7E;">//Set digital pin 4 (LED) to an OUTPUT</span><br />}<br /><br /><br /><span style="color: #7E7E7E;">//==LOOP============================================================================================</span><br /><span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>loop</b></span>() {<br /> <span style="color: #CC6600;">if</span>(<span style="color: #CC6600;">digitalRead</span>(Heart)>0){ <span style="color: #7E7E7E;">//The heart rate sensor will trigger HIGH when there is a heart beat</span><br /> <span style="color: #CC6600;">if</span>(!beat){ <span style="color: #7E7E7E;">//Only send data when it first discovers a heart beat - otherwise it will send a high value multiple times</span><br /> beat=<span style="color: #CC6600;">true</span>; <span style="color: #7E7E7E;">//By changing the beat variable to true, it stops further transmissions of the high signal</span><br /> <span style="color: #CC6600;">digitalWrite</span>(LED, <span style="color: #006699;">HIGH</span>); <span style="color: #7E7E7E;">//Turn the LED on </span><br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(1023); <span style="color: #7E7E7E;">//Send the high value to the computer via Serial communication.</span><br /> }<br /> } <span style="color: #CC6600;">else</span> { <span style="color: #7E7E7E;">//If the reading is LOW, </span><br /> <span style="color: #CC6600;">if</span>(beat){ <span style="color: #7E7E7E;">//and if this has just changed from HIGH to LOW (first low reading)</span><br /> beat=<span style="color: #CC6600;">false</span>; <span style="color: #7E7E7E;">//change the beat variable to false (to stop multiple transmissions)</span><br /> <span style="color: #CC6600;">digitalWrite</span>(LED, <span style="color: #006699;">LOW</span>); <span style="color: #7E7E7E;">//Turn the LED off.</span><br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(0); <span style="color: #7E7E7E;">//then send a low value to the computer via Serial communication.</span><br /> }<br /> }<br />}</pre> </td> </tr> </table></div></P> <BR /> <BR /> <BR /> <BR /> <P> <H4><a href="https://processing.org/download/?processing">Processing Sketch</a></H4> <BR /> <div style="background: #ffffff; color: #000000; overflow:auto;width:auto;border:solid rgb(192,192,192);border-width: .6em .3em .3em .3em;padding: 0em 0em;"> <table> <tr> <td> <pre style="margin: 0; line-height: 125%; background: rgb(192,192,192); width: 1.9em"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br /> 10<br /> 11<br /> 12<br /> 13<br /> 14<br /> 15<br /> 16<br /> 17<br /> 18<br /> 19<br /> 20<br /> 21<br /> 22<br /> 23<br /> 24<br /> 25<br /> 26<br /> 27<br /> 28<br /> 29<br /> 30<br /> 31<br /> 32<br /> 33<br /> 34<br /> 35<br /> 36<br /> 37<br /> 38<br /> 39<br /> 40<br /> 41<br /> 42<br /> 43<br /> 44<br /> 45<br /> 46<br /> 47<br /> 48<br /> 49<br /> 50<br /> 51<br /> 52<br /> 53<br /> 54<br /> 55<br /> 56<br /> 57<br /> 58<br /> 59<br /> 60<br /> 61<br /> 62<br /> 63<br /> 64<br /> 65<br /> 66<br /> 67<br /> 68<br /> 69<br /> 70<br /> 71<br /> 72<br /> 73<br /> 74<br /> 75<br /> 76<br /> 77<br /> 78<br /> 79<br /> 80<br /> 81<br /> 82<br /> 83<br /> 84<br /> 85<br /> 86<br /> 87<br /> 88<br /> 89<br /> 90<br /> 91<br /> 92<br /> 93<br /> 94<br /> 95<br /> 96<br /> 97<br /> 98<br /> 99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br /></pre> </td> <td> <pre style="margin: 0; line-height: 125%"><br /><span style="color: #666666;">/* =================================================================================================</span><br /><span style="color: #666666;"> Project: Arduino Heart rate monitor</span><br /><span style="color: #666666;"> Author: Scott C</span><br /><span style="color: #666666;"> Created: 21st April 2015</span><br /><span style="color: #666666;">Processing IDE: 2.2.1</span><br /><span style="color: #666666;"> Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html</span><br /><span style="color: #666666;"> Description: A Grove Ear-clip heart rate sensor allows an Arduino UNO to sense your pulse.</span><br /><span style="color: #666666;"> The data obtained by the Arduino can then be sent to the computer via Serial communication</span><br /><span style="color: #666666;"> which is then displayed graphically using this Processing sketch.</span><br /><span style="color: #666666;"> </span><br /><span style="color: #666666;">=================================================================================================== */</span><br /><br /><span style="color: #33997E;">import</span> processing.serial.*; <span style="color: #666666;">// Import the serial library to allow Serial communication with the Arduino</span><br /><br /><span style="color: #E2661A;">int</span> numOfRecs = 45; <span style="color: #666666;">// numOfRecs: The number of rectangles to display across the screen</span><br />Rectangle[] myRecs = <span style="color: #33997E;">new</span> Rectangle[numOfRecs]; <span style="color: #666666;">// myRecs[]: Is the array of Rectangles. Rectangle is a custom class (programmed within this sketch)</span><br /><br />Serial myPort; <br /><span style="color: #E2661A;">String</span> comPortString=<span style="color: #7D4793;">"0"</span>; <span style="color: #666666;">//comPortString: Is used to hold the string received from the Arduino</span><br /><span style="color: #E2661A;">float</span> arduinoValue = 0; <span style="color: #666666;">//arduinoValue: Is the float variable converted from comPortString</span><br /><span style="color: #E2661A;">boolean</span> beat = <span style="color: #33997E;">false</span>; <span style="color: #666666;">// beat: Used to control for multiple high/low signals coming from the Arduino</span><br /><br /><span style="color: #E2661A;">int</span> totalTime = 0; <span style="color: #666666;">// totalTime: Is the variable used to identify the total time between beats</span><br /><span style="color: #E2661A;">int</span> lastTime = 0; <span style="color: #666666;">// lastTime: Is the variable used to remember when the last beat took place</span><br /><span style="color: #E2661A;">int</span> beatCounter = 0; <span style="color: #666666;">// beatCounter: Is used to keep track of the number of beats (in order to calculate the average BPM)</span><br /><span style="color: #E2661A;">int</span> totalBeats = 10; <span style="color: #666666;">// totalBeats: Tells the computer that we want to calculate the average BPM using 10 beats.</span><br /><span style="color: #E2661A;">int</span>[] BPM = <span style="color: #33997E;">new</span> <span style="color: #E2661A;">int</span>[totalBeats]; <span style="color: #666666;">// BPM[]: Is the Beat Per Minute (BPM) array - to hold 10 BPM calculations</span><br /><span style="color: #E2661A;">int</span> sumBPM = 0; <span style="color: #666666;">// sumBPM: Is used to sum the BPM[] array values, and is then used to calculate the average BPM.</span><br /><span style="color: #E2661A;">int</span> avgBPM = 0; <span style="color: #666666;">// avgBPM: Is the variable used to hold the average BPM calculated value.</span><br /><br /><span style="color: #E2661A;">PFont</span> f, f2; <span style="color: #666666;">// f & f2 : Are font related variables. Used to store font properties. </span><br /><br /><br /><span style="color: #666666;">//==SETUP==============================================================================================</span><br /><span style="color: #33997E;">void</span> <span style="color: #006699;"><b>setup</b></span>(){<br /> <span style="color: #006699;">size</span>(<span style="color: #D94A7A;">displayWidth</span>,<span style="color: #D94A7A;">displayHeight</span>); <span style="color: #666666;">// Set the size of the display to match the monitor width and height</span><br /> <span style="color: #006699;">smooth</span>(); <span style="color: #666666;">// Draw all shapes with smooth edges.</span><br /> f = <span style="color: #006699;">createFont</span>(<span style="color: #7D4793;">"Arial"</span>,24); <span style="color: #666666;">// Initialise the "f" font variable - used for the "calibrating" text displayed at the beginning</span><br /> f2 = <span style="color: #006699;">createFont</span>(<span style="color: #7D4793;">"Arial"</span>,96); <span style="color: #666666;">// Initialise the "f2" font variable - used for the avgBPM display on screen</span><br /> <br /> <span style="color: #669900;">for</span>(<span style="color: #E2661A;">int</span> i=0; i<numOfRecs; i++){ <span style="color: #666666;">// Initialise the array of rectangles</span><br /> myRecs[i] = <span style="color: #33997E;">new</span> Rectangle(i, numOfRecs);<br /> }<br /> <br /> <span style="color: #669900;">for</span>(<span style="color: #E2661A;">int</span> i=0; i<totalBeats; i++){ <span style="color: #666666;">// Initialise the BPM array</span><br /> BPM[i] = 0;<br /> }<br /> <br /> myPort = <span style="color: #33997E;">new</span> Serial(<span style="color: #33997E;">this</span>, Serial.<span style="color: #006699;">list</span>()[0], 9600); <span style="color: #666666;">// Start Serial communication with the Arduino using a baud rate of 9600</span><br /> myPort.bufferUntil(<span style="color: #7D4793;">'\n'</span>); <span style="color: #666666;">// Trigger a SerialEvent on new line</span><br />}<br /><br /><br /><span style="color: #666666;">//==DRAW==============================================================================================</span><br /><span style="color: #33997E;">void</span> <span style="color: #006699;"><b>draw</b></span>(){<br /> <span style="color: #006699;">background</span>(0); <span style="color: #666666;">// Set the background to BLACK (this clears the screen each time)</span><br /> drawRecs(); <span style="color: #666666;">// Method call to draw the rectangles on the screen</span><br /> drawBPM(); <span style="color: #666666;">// Method call to draw the avgBPM value to the top right of the screen</span><br />}<br /><br /><br /><span style="color: #666666;">//==drawRecs==========================================================================================</span><br /><span style="color: #33997E;">void</span> drawRecs(){ <span style="color: #666666;">// This custom method will draw the rectangles on the screen </span><br /> myRecs[0].setSize(arduinoValue); <span style="color: #666666;">// Set the first rectangle to match arduinoValue; any positive value will start the animation.</span><br /> <span style="color: #669900;">for</span>(<span style="color: #E2661A;">int</span> i=numOfRecs-1; i>0; i--){ <span style="color: #666666;">// The loop counts backwards for coding efficiency - and is used to draw all of the rectangles to screen</span><br /> myRecs[i].setMult(i); <span style="color: #666666;">// setMulti creates the specific curve pattern. </span><br /> myRecs[i].setRed(avgBPM); <span style="color: #666666;">// The rectangles become more "Red" with higher avgBPM values</span><br /> myRecs[i].setSize(myRecs[i-1].getH()); <span style="color: #666666;">// The current rectangle size is determined by the height of the rectangle immediately to it's left</span><br /> <span style="color: #006699;">fill</span>(myRecs[i].getR(),myRecs[i].getG(), myRecs[i].getB()); <span style="color: #666666;">// Set the colour of this rectangle</span><br /> <span style="color: #006699;">rect</span>(myRecs[i].getX(), myRecs[i].getY(), myRecs[i].getW(), myRecs[i].getH()); <span style="color: #666666;">// Draw this rectangle</span><br /> }<br />}<br /><br /><br /><span style="color: #666666;">//==drawBPM===========================================================================================</span><br /><span style="color: #33997E;">void</span> drawBPM(){ <span style="color: #666666;">// This custom method is used to calculate the avgBPM and draw it to screen.</span><br /> sumBPM = 0; <span style="color: #666666;">// Reset the sumBPM variable</span><br /> avgBPM = 0; <span style="color: #666666;">// Reset the avgBPM variable</span><br /> <span style="color: #E2661A;">boolean</span> calibrating = <span style="color: #33997E;">false</span>; <span style="color: #666666;">// calibrating: this boolean variable is used to control when the avgBPM is displayed to screen</span><br /> <br /> <span style="color: #669900;">for</span>(<span style="color: #E2661A;">int</span> i=1; i<totalBeats; i++){<br /> sumBPM = sumBPM + BPM[i-1]; <span style="color: #666666;">// Sum all of the BPM values in the BPM array.</span><br /> <span style="color: #669900;">if</span>(BPM[i-1]<1){ <span style="color: #666666;">// If any BPM values are equal to 0, then set the calibrating variable to true. </span><br /> calibrating = <span style="color: #33997E;">true</span>; <span style="color: #666666;">// This will be used later to display "calibrating" on the screen.</span><br /> }<br /> }<br /> avgBPM = sumBPM/(totalBeats-1); <span style="color: #666666;">// Calculate the average BPM from all BPM values</span><br /> <br /> <span style="color: #006699;">fill</span>(255); <span style="color: #666666;">// The text will be displayed as WHITE text</span><br /> <span style="color: #669900;">if</span>(calibrating){<br /> <span style="color: #006699;">textFont</span>(f);<br /> <span style="color: #006699;">text</span>(<span style="color: #7D4793;">"Calibrating"</span>, (4*<span style="color: #D94A7A;">width</span>)/5, (<span style="color: #D94A7A;">height</span>/5)); <span style="color: #666666;">// If the calibrating variable is TRUE, then display the word "Calibrating" on screen</span><br /> <span style="color: #006699;">fill</span>(0); <span style="color: #666666;">// Change the fill and stroke to black (0) so that other text is "hidden" while calibrating variable is TRUE</span><br /> <span style="color: #006699;">stroke</span>(0);<br /> } <span style="color: #669900;">else</span> {<br /> <span style="color: #006699;">textFont</span>(f2);<br /> <span style="color: #006699;">text</span>(avgBPM, (4*<span style="color: #D94A7A;">width</span>)/5, (<span style="color: #D94A7A;">height</span>/5)); <span style="color: #666666;">// If the calibrating variable is FALSE, then display the avgBPM variable on screen</span><br /> <span style="color: #006699;">stroke</span>(255); <span style="color: #666666;">// Change the stroke to white (255) to show the white line underlying the word BPM.</span><br /> }<br /> <br /> <span style="color: #006699;">textFont</span>(f);<br /> <span style="color: #006699;">text</span>(<span style="color: #7D4793;">"BPM"</span>, (82*<span style="color: #D94A7A;">width</span>)/100, (<span style="color: #D94A7A;">height</span>/11)); <span style="color: #666666;">// This will display the underlined word "BPM" when calibrating variable is FALSE.</span><br /> <span style="color: #006699;">line</span>((80*<span style="color: #D94A7A;">width</span>)/100, (<span style="color: #D94A7A;">height</span>/10),(88*<span style="color: #D94A7A;">width</span>)/100, (<span style="color: #D94A7A;">height</span>/10));<br /> <span style="color: #006699;">stroke</span>(0);<br />}<br /><br /><br /><span style="color: #666666;">//==serialEvent===========================================================================================</span><br /><span style="color: #33997E;">void</span> serialEvent(Serial cPort){ <span style="color: #666666;">// This will be triggered every time a "new line" of data is received from the Arduino</span><br /> comPortString = cPort.readStringUntil(<span style="color: #7D4793;">'\n'</span>); <span style="color: #666666;">// Read this data into the comPortString variable.</span><br /> <span style="color: #669900;">if</span>(comPortString != <span style="color: #33997E;">null</span>) { <span style="color: #666666;">// If the comPortString variable is not NULL then</span><br /> comPortString=<span style="color: #006699;">trim</span>(comPortString); <span style="color: #666666;">// trim any white space around the text.</span><br /> <span style="color: #E2661A;">int</span> i = <span style="color: #006699;">int</span>(<span style="color: #006699;">map</span>(<span style="color: #E2661A;">Integer</span>.<span style="color: #006699;">parseInt</span>(comPortString),1,1023,1,<span style="color: #D94A7A;">height</span>)); <span style="color: #666666;">// convert the string to an integer, and map the value so that the rectangle will fit within the screen.</span><br /> arduinoValue = <span style="color: #006699;">float</span>(i); <span style="color: #666666;">// Convert the integer into a float value.</span><br /> <span style="color: #669900;">if</span> (!beat){<br /> <span style="color: #669900;">if</span>(arduinoValue>0){ <span style="color: #666666;">// When a beat is detected, the "trigger" method is called.</span><br /> trigger(<span style="color: #006699;">millis</span>()); <span style="color: #666666;">// millis() creates a timeStamp of when the beat occured.</span><br /> beat=<span style="color: #33997E;">true</span>; <span style="color: #666666;">// The beat variable is changed to TRUE to register that a beat has been detected.</span><br /> }<br /> }<br /> <span style="color: #669900;">if</span> (arduinoValue<1){ <span style="color: #666666;">// When the Arduino value returns back to zero, we will need to change the beat status to FALSE.</span><br /> beat = <span style="color: #33997E;">false</span>;<br /> }<br /> }<br />} <br /><br /><br /><span style="color: #666666;">//==trigger===========================================================================================</span><br /><span style="color: #33997E;">void</span> trigger(<span style="color: #E2661A;">int</span> time){ <span style="color: #666666;">// This method is used to calculate the Beats per Minute (BPM) and to store the last 10 BPMs into the BPM[] array.</span><br /> totalTime = time - lastTime; <span style="color: #666666;">// totalTime = the current beat time minus the last time there was a beat.</span><br /> lastTime = time; <span style="color: #666666;">// Set the lastTime variable to the current "time" for the next round of calculations.</span><br /> BPM[beatCounter] = 60000/totalTime; <span style="color: #666666;">// Calculate BPM from the totalTime. 60000 = 1 minute.</span><br /> beatCounter++; <span style="color: #666666;">// Increment the beatCounter </span><br /> <span style="color: #669900;">if</span> (beatCounter>totalBeats-1){ <span style="color: #666666;">// Reset the beatCounter when the total number of BPMs have been stored into the BPM[] array.</span><br /> beatCounter=0; <span style="color: #666666;">// This allows us to keep the last 10 BPM calculations at all times.</span><br /> }<br />}<br /><br /><br /><span style="color: #666666;">//==sketchFullScreen==========================================================================================</span><br /><span style="color: #E2661A;">boolean</span> sketchFullScreen() { <span style="color: #666666;">// This puts Processing into Full Screen Mode</span><br /> <span style="color: #33997E;">return</span> <span style="color: #33997E;">true</span>;<br />}<br /><br /><br /><span style="color: #666666;">//==Rectangle CLASS==================================================================================*********</span><br /><span style="color: #33997E;">class</span> Rectangle{<br /> <span style="color: #E2661A;">float</span> xPos, defaultY, yPos, myWidth, myHeight, myMultiplier; <span style="color: #666666;">// Variables used for drawing rectangles</span><br /> <span style="color: #E2661A;">int</span> blueVal, greenVal, redVal; <span style="color: #666666;">// Variables used for the rectangle colour</span><br /> <br /> Rectangle(<span style="color: #E2661A;">int</span> recNum, <span style="color: #E2661A;">int</span> nRecs){ <span style="color: #666666;">// The rectangles are constructed using two variables. The total number of rectangles to be displayed, and the identification of this rectangle (recNum)</span><br /> myWidth = <span style="color: #D94A7A;">displayWidth</span>/nRecs; <span style="color: #666666;">// The width of the rectangle is determined by the screen width and the total number of rectangles.</span><br /> xPos = recNum * myWidth; <span style="color: #666666;">// The x Position of this rectangle is determined by the width of the rectangles (all same) and the rectangle identifier.</span><br /> defaultY=<span style="color: #D94A7A;">displayHeight</span>/2; <span style="color: #666666;">// The default Y position of the rectangle is half way down the screen.</span><br /> yPos = defaultY; <span style="color: #666666;">// yPos is used to adjust the position of the rectangle as the size changes.</span><br /> myHeight = 1; <span style="color: #666666;">// The height of the rectangle starts at 1 pixel</span><br /> myMultiplier = 1; <span style="color: #666666;">// The myMultiplier variable will be used to create the funnel shaped path for the rectangles.</span><br /> redVal = 0; <span style="color: #666666;">// The red Value starts off being 0 - but changes with avgBPM. Higher avgBPM means higher redVal</span><br /> <br /> <span style="color: #669900;">if</span> (recNum>0){ <span style="color: #666666;">// The blue Value progressively increases with every rectangle (moving to the right of the screen)</span><br /> blueVal = (recNum*255)/nRecs;<br /> } <span style="color: #669900;">else</span> {<br /> blueVal = 0;<br /> }<br /> greenVal = 255-blueVal; <span style="color: #666666;">// Initially, the green value is at the opposite end of the spectrum to the blue value.</span><br /> }<br /> <br /> <span style="color: #33997E;">void</span> setSize(<span style="color: #E2661A;">float</span> newSize){ <span style="color: #666666;">// This is used to set the new size of each rectangle </span><br /> myHeight=newSize*myMultiplier;<br /> yPos=defaultY-(newSize/2);<br /> }<br /> <br /> <span style="color: #33997E;">void</span> setMult(<span style="color: #E2661A;">int</span> i){ <span style="color: #666666;">// The multiplier is a function of COS, which means that it varies from 1 to 0.</span><br /> myMultiplier = <span style="color: #006699;">cos</span>(<span style="color: #006699;">radians</span>(i)); <span style="color: #666666;">// You can try other functions to experience different effects.</span><br /> }<br /> <br /> <span style="color: #33997E;">void</span> setRed(<span style="color: #E2661A;">int</span> r){<br /> redVal = <span style="color: #006699;">int</span>(<span style="color: #006699;">constrain</span>(<span style="color: #006699;">map</span>(<span style="color: #006699;">float</span>(r), 60, 100, 0, 255),0,255)); <span style="color: #666666;">// setRed is used to change the redValue based on the "normal" value for resting BPM (60-100). </span><br /> greenVal = 255 - redVal; <span style="color: #666666;">// When the avgBPM > 100, redVal will equal 255, and the greenVal will equal 0.</span><br /> } <span style="color: #666666;">// When the avgBPM < 60, redVal will equal 0, and greenVal will equal 255.</span><br /> <br /> <span style="color: #E2661A;">float</span> getX(){ <span style="color: #666666;">// get the x Position of the rectangle</span><br /> <span style="color: #33997E;">return</span> xPos;<br /> }<br /> <br /> <span style="color: #E2661A;">float</span> getY(){ <span style="color: #666666;">// get the y Position of the rectangle</span><br /> <span style="color: #33997E;">return</span> yPos;<br /> }<br /> <br /> <span style="color: #E2661A;">float</span> getW(){ <span style="color: #666666;">// get the width of the rectangle</span><br /> <span style="color: #33997E;">return</span> myWidth;<br /> }<br /> <br /> <span style="color: #E2661A;">float</span> getH(){ <span style="color: #666666;">// get the height of the rectangle</span><br /> <span style="color: #33997E;">return</span> myHeight;<br /> }<br /> <br /> <span style="color: #E2661A;">float</span> getM(){ <span style="color: #666666;">// get the Multiplier of the rectangle</span><br /> <span style="color: #33997E;">return</span> myMultiplier;<br /> }<br /> <br /> <span style="color: #E2661A;">int</span> getB(){ <span style="color: #666666;">// get the "blue" component of the rectangle colour</span><br /> <span style="color: #33997E;">return</span> blueVal;<br /> }<br /> <br /> <span style="color: #E2661A;">int</span> getR(){ <span style="color: #666666;">// get the "red" component of the rectangle colour</span><br /> <span style="color: #33997E;">return</span> redVal;<br /> }<br /> <br /> <span style="color: #E2661A;">int</span> getG(){ <span style="color: #666666;">// get the "green" component of the rectangle colour</span><br /> <span style="color: #33997E;">return</span> greenVal;<br /> }<br />}<br /><br /></pre> </td> </tr> </table></div></P> <BR /> <BR /> <P> <h4>Processing Code Discussion:</h4><br> <P> The Rectangle class was created to store relevant information about each rectangle. By using a custom class, we were able to design our rectangles any way we wanted. These rectangles have properties and methods which allow us to easily control their position, size and colour. By adding some smart functionality to each rectangle, we were able to get the rectangle to automatically position and colour itself based on key values. </P> <P> The Serial library is used to allow communication with the Arduino. In this Processing sketch, the values obtained from the Arduino were converted to floats to allow easy calulations of the beats per minute (BPM). I am aware that I have over-engineered the serialEvent method somewhat, because the Arduino is only really sending two values. I didn't really need to convert the String. But I am happy with the end result, and it does the job I needed it to... </P> <div style="text-align: center;"> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZDfO9lu23JGRo8duAOywh3O88FNVagPWVlPWbO9FhrPYBIgxT_9FGv3UPyWuZnbkwbwAN1_lsO71agK4XUjfqoUpDFGY5Jkaav-9BYja7ZxTyOg9hZWzhBbEjHOIQ94IpM9R9NnmZKDA/s1600/Complete+Workstation2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZDfO9lu23JGRo8duAOywh3O88FNVagPWVlPWbO9FhrPYBIgxT_9FGv3UPyWuZnbkwbwAN1_lsO71agK4XUjfqoUpDFGY5Jkaav-9BYja7ZxTyOg9hZWzhBbEjHOIQ94IpM9R9NnmZKDA/s1600/Complete+Workstation2.jpg" height="526" width="640" /> </a> </div> </P> </div> </P></div><!--separator --><img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /><P> <div style="text-align: justify;"> This project is quite simple. I designed it so that you could omit the Processing code if you wanted to. In that scenario, you would only be left with a blinking LED that blinks in time with your pulse. The Processing code takes this project to the next level. It provides a nice animation and calculates the beats per minute (BPM). <br> <br> I hope you liked this tutorial. Please feel free to share it, comment or give it a plus one. If you didn't like it, I would still appreciate your constructive feedback. </div> <BR /> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> <div align="center"> If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br> <BR /> <BR /> Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br> Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br> I can also be found on <a href="https://www.pinterest.com/ArduinoBasics/">Pinterest</a> and <a href="https://instagram.com/arduinobasics">Instagram</a>. <br> Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.<br> </div> </P> <BR /> <BR /> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho63iZRcKyYatSaDs7B3gkv0tGy8Tag9BBlxtimfd0zS8Lp1zpoQEapoX0eskO0IOiXD1ZCEN1x5W5ls3mY5ID1JJcKV9VN0_Oq_ln2Psl4i9AGeVXLwnWEAJiN9JSegZxRZdbIfnLlnA/s1600/Slide1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho63iZRcKyYatSaDs7B3gkv0tGy8Tag9BBlxtimfd0zS8Lp1zpoQEapoX0eskO0IOiXD1ZCEN1x5W5ls3mY5ID1JJcKV9VN0_Oq_ln2Psl4i9AGeVXLwnWEAJiN9JSegZxRZdbIfnLlnA/s1600/Slide1.JPG" height="150" width="200" /></a></div><br /> </P> <BR /> <BR /> <BR /> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> However, if you do not have a google profile... <br>Feel free to share this page with your friends in any way you see fit. </P></P></P><br /><br /><br /><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" -->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-52316722037624638242015-04-13T18:21:00.000-07:002016-03-19T10:53:41.034-07:00One Arduino<g:plusone></g:plusone><div style="text-align: justify;"> <P> <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNBsjH9QZFBtg1vCXFsprxxKtQfpLx8uMQyIN9r7WAo0z7shL86BKQ4mqCSpysXjuQPIWqfLqWQkPOKCJQr0cpNqkL1n3JvaYSIQtAc2p1b2i86R3NWGTXPiER_TDkcCBQRg90zSmSrJM/s1600/ONE+ARDUINO2c.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img style="border:3px solid white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNBsjH9QZFBtg1vCXFsprxxKtQfpLx8uMQyIN9r7WAo0z7shL86BKQ4mqCSpysXjuQPIWqfLqWQkPOKCJQr0cpNqkL1n3JvaYSIQtAc2p1b2i86R3NWGTXPiER_TDkcCBQRg90zSmSrJM/s640/ONE+ARDUINO2c.png" /></a></div> </P> <br> <P> <h3>Arduino</h3> is an "open source physical computing platform based on a simple microcontroller board". It is also a "development environment for writing software for the board" (Source: <a href="http://arduino.cc/en/guide/introduction">Arduino.cc</a>). The first Arduino was born in 2005 in the classrooms of Interactive Design Institute in Ivrea, Italy. A nice presentation which shows a timeline of "how Arduino came to be" can be found <a href="http://www.cs.colorado.edu/~kena/classes/5448/f11/presentation-materials/arduino_bradleycooper.pdf">here</a>.<br> <br> Arduino has been a very successful concept and creation. Ten years on, it has become one of, if not, the most popular prototyping and development platforms in the world. It has found it's way into the hearts of many makers, artists, programmers, developers and inventors. It has been used for millions of projects: from automatic garage door openers and tea makers to flamethrowers, robots, lighting displays and sound production. In fact, I cannot think of anything that the Arduino hasn't been used for.<br> <br> But as you are pretty well aware, there has been a recent rift between the original founders of Arduino.<BR> There is no need to go over the details here because it has been covered many times already on other sites. But if you would like to get up to speed on the Arduino Trademark dispute, I would suggest you read the following articles: <br> <br> 1) <a href="http://makezine.com/2015/03/19/massimo-banzi-fighting-for-arduino/">Massimo Banzi's interview on Make </a><br> 2) <a href="http://arduino.org/blog/1-the-new-blog/to-the-makers">Federico's letter to the makers on Arduino.org </a><br> 3) <a href="https://www.unitedstatescourts.org/federal/mad/167131/1-0.html">Court Transcripts from the United States Courts Archive</a><br> 4) <a href="http://www.zdnet.com/article/whats-in-a-name-the-battle-for-the-soul-of-arduino/">What's in a name: The battle for the soul of Arduino - on ZD Net</a><br> 5) <a href ="http://hackaday.com/2015/03/12/arduino-v-arduino-part-ii/">Arduino vs Arduino: Part II on Hackaday</a><br> </P> <br> <br> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> <P> <h4>My Letter to Arduino LLC/SRL</h4><br> Why can't you get along? Why the deception? Why the greed? <br> <br> Who does this benefit? It is a lose-lose battle, not only for Arduino SRL/LLC but for the whole Arduino community. We all love Arduino. We love the idea, the mission and the dream. We like to make things... We don't care who "the original" Arduino was or is. It doesn't matter. We just want... <h3> <ul> <li><a href="http://www.baldengineer.com/videos/open-letter-to-arduino-llc-and-arduino-srl">#OneArduino</a></li> <li><a href="http://brainwagon.org/2015/03/31/arduino-perhaps-we-need-ourduino/">#OurDuino</a></li> </ul> </h3> </P> <P> We don't want different versions of the Arduino IDE (<a href="http://arduino.cc/en/main/software">1.6.3</a> vs <a href="http://arduino.org/downloads">1.7.0</a>).<br> Some may say that you should redo the IDE altogether, but that is an entirely different topic :)<br> </P> <P> Can't you see what this is doing? <br> It is hard enough for tutorial makers and forum dwellers to keep up with the ever evolving IDE as it is. Making two different versions of the "same IDE" adds about 10 layers of confusion and complexity ! And for what ??? This will be confusing for the newbie, confusing for the helpers, the developers, for everyone. <br> </P> <P> I am guessing that my words will have no influence over your decisions. But I hope it does !<br> I plee with both of you to stand by your infinity symbol and work through your differences. Say what you need to say, but get back together and regroup - as ONE ARDUINO. </P> <P> Your rift is likely to reverberate through to the Arduino Community aswell. Some people will side with Arduino LLC, some with Arduino SRL. And while some people will take a stance of indifference, there will be some that just look elsewhere. <br> <br> I don't know if revealing the results of my poll will benefit the cause or add salt to the wounds, But I asked the question, and you probably want to know the answer. Who does the Arduino Community support right now? <br> <br> The infographic below shows the results of the poll I posted a week ago: </P> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheaZBghRIahZdJ0jb8bG9GN-sMbH9WAAyyL0N_x0uvxlPFppCZAZFaj7DPtLpEXfBkqZec5jBSSWSMSI_FeaQcUoRYn8tMTu3mnDxCfC9bC5w-pSE_7RElXbYviXzctBoVh490SSoH1CU/s1600/Arduino+Wars+PiktoChart.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px solid white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheaZBghRIahZdJ0jb8bG9GN-sMbH9WAAyyL0N_x0uvxlPFppCZAZFaj7DPtLpEXfBkqZec5jBSSWSMSI_FeaQcUoRYn8tMTu3mnDxCfC9bC5w-pSE_7RElXbYviXzctBoVh490SSoH1CU/s1600/Arduino+Wars+PiktoChart.png" width="640" /> </a> </div> </P> <P> <span style="font-size: xx-small;"> This poll was posted on the <a href="https://plus.google.com/u/0/b/107402020974762902161/communities/104815959638799239380">Arduino Tutorial Google+ community page </a>. I tried to be as unbiased as possible. People were only allowed to vote once (enforced by log in). Each voter would have been presented with the organisations in random order. And results were not published until now. The results above are accurate as of 14th April 2015 at 9am (in Australia) </span> <br> <br> </P> <P> As you can clearly see, Arduino LLC is highly favoured. <br> <br> My personal preference is not captured by that infographic. I agree with the <a href="http://www.baldengineer.com/videos/open-letter-to-arduino-llc-and-arduino-srl">bald engineer</a>, I would prefer #OneArduino. I would like the Arduino Community to stand united. I also want the Arduino founders to stand united! Please, work through your issues, stop being greedy and stop the deception. Arduino is more than a product. It is the heart of a greater movement. <br> <div style="text-align: center;"> <span style="font-size: large;"> This war is pointless - please STOP !</span></div> </P> Kind Regards<br> Scott C <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P></div><br /><br /><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" -->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-89039725338922434702015-04-09T11:01:00.000-07:002016-03-19T10:53:41.077-07:00Arduino BeatBox <g:plusone></g:plusone><div style="text-align: justify;"> <P> <div class="separator" style="clear: both; text-align: center;"> <img style="border:3px solid white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2cOZ1YJsZCJJOQm4CXIzagTOX6hNPQCJrlqoh1rxsC4IvyRgyzSnFlQyfOhkc4VQicZMTfc20hqfwRAorpWvB_aEhPZ74tBjT7jLKV0ruY8fRMy2ddVbDAwI9cDghXBZx534eyqsRXU4/s1600/Slide1.JPG" height="240" width="98%" /> </div> </P> <P> <div> <P> Create your very own Arduino BeatBox ! </P> <P> Home-made capacitive touch sensors are used to trigger the MP3 drum sounds stored on the Grove Serial MP3 player. I have used a number of tricks to get the most out of this module, and I was quite impressed on how well it did. Over 130 sounds were loaded onto the SDHC card. Most were drum sounds, but I added some farm animal noises to provide an extra element of surprise and entertainment. You can put any sounds you want on the module and play them back quickly. We'll put the Grove Serial MP3 module through it's paces and make it into a neat little BeatBox !! </P> <BR /> <P> <h4>Key learning objectives</h4> <ul> <li>How to make your own beatbox</li> <li>How to make capacitive drum pad sensors without using resistors</li> <li>How to speed up Arduino's Analog readings for better performance</li> <li>How to generate random numbers on your Arduino</li> </ul> </P> </div> </P> <BR /> <P> <H4>Parts Required:</H4> <P> <ul> <li><a href="http://www.epictinker.com/Freetronics-Eleven-100-Arduino-Uno-Compatible-p/ard-1002.htm">Arduino UNO or compatible board</a></li> <li><a href="http://www.epictinker.com/Grove-Base-Shield-v1-3-p/sld01099p.htm">Grove Base Shield</a></li> <li><a href="http://www.epictinker.com/Grove-Serial-MP3-Player-p/sen01300p.htm">Grove Serial MP3 Player</a></li> <li><a href="http://www.epictinker.com/Grove-Slide-Potentiometer-p/com05231p.htm">Grove Sliding Potentiometer</a></li> <li><a href="http://www.epictinker.com/Grove-Button-p/com22242p.htm">Grove Button</a> or <a href="http://www.epictinker.com/Grove-Button-P-p/com08211p.htm">Grove Button (P)</a></li> <li><a href="http://www.epictinker.com/Grove-Universal-4-Pin-20cm-Cable-5pk-p/acc11317o.htm">Grove Universal 4 pin cables</a></li> <li><a href="http://www.epictinker.com/6xAA-Battery-Holder-with-DC-2-1mm-Power-Jack-p/fit0141.htm">Battery Holder</a></li> <li><a href="http://bit.ly/1H4UHXa">SanDisk 8GB Ultra Micro SDHC Memory card</a></li> <li><a href="http://lmgtfy.com/?q=DOSS+DS+1158">Portable Powered Speaker</a> or Headphones</li> <li>4 LEDs - 1 x Green, 1 x Blue, 1 x Red and 1 x Yellow</li> <li>A shoe box, paper, aluminum foil, scissors, glue etc. etc.</li><br /> </ul> </P> </P> <P><H4>Making the drum pads</H4> </BR> <div class="separator" style="clear: both; text-align: center;"> <img style="border:3px solid white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnqjOvKfsOQOBW-vgviETTgYkue5zM6Cp2wGiGDAvCVEcbkBeFkWd5AUn1QgLKmueVC4X4sXkxRifZ_GsvSVsJk5OPMK4xP4M_Vz3uVAuMFQtVsnNtHVOYnQsO4I3uVvjGppSQzEgIxBg/s1600/Putting+it+together.gif" height="331" width="400" /> </div> </P> <BR /> <BR /> <P> <H4>Fritzing Sketch</H4> <BR /> <div class="separator" style="clear: both; text-align: center;"> <img style="border:3px solid white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZbuUSkWPNOkPrS_RQpar50MlS0TSsPmR5_czQcBSQWuDn_NoQbtoJ27BxaXXYtOr2W-FZEilIo2V8OziVcanHgNDOWmHEWAHmunFVRKEvFzcskVKcVLZFIX-5CFmH6VUY2aN6T0DJVKI/s1600/Slide12.JPG" height="480" width="640" /> </div> </P> <BR /> <BR /> <P> <H4>Grove Connections</H4> <BR /> <div class="separator" style="clear: both; text-align: center;"> <img style="border:3px solid white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSonrWf4wfrryapGLUMlC4_g-NRLlx7x-QdP95Qm8SdtiEGHeUuypA7a4qU87enIqp8HN2CQ_vqMj1y8ErFOiKDAtJuBJV_1gfYcRzCCxrkjvdYDy3OEJbz-U1QcMsIkjMSWD29wvQ8cE/s1600/Slide13.JPG" height="480" width="640" /> </div> </P> <BR /> <BR /> <P> <H4>Grove Connections (without base shield)</H4> <BR /> <div class="separator" style="clear: both; text-align: center;"> <img style="border:3px solid white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilnK72Kv4sbWAF4O-5yKf3MxPx6wTiOqQbL8GYHs6e-xp23s8pAYjpD4ktEtolmOglE_UdMgd1YBl1GOE2CidOo38R8tM0qvpFMllEJ0CPpLjVYT2b7X9mOBD3CoS0YuRcW14n5XWRbGs/s1600/Slide15.JPG" height="480" width="640" /> </div> </P> <BR /> <BR /> <P> <H4>Arduino Sketch</H4> <BR /> <div style="background: #ffffff; color: #000000; overflow:auto;width:auto;border:solid rgb(24,186,183);border-width: .6em .3em .3em .3em;padding: 0em 0em;"> <table> <tr> <td> <pre style="margin: 0; line-height: 125%; background: rgb(24,186,183); width: 1.9em"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br /> 10<br /> 11<br /> 12<br /> 13<br /> 14<br /> 15<br /> 16<br /> 17<br /> 18<br /> 19<br /> 20<br /> 21<br /> 22<br /> 23<br /> 24<br /> 25<br /> 26<br /> 27<br /> 28<br /> 29<br /> 30<br /> 31<br /> 32<br /> 33<br /> 34<br /> 35<br /> 36<br /> 37<br /> 38<br /> 39<br /> 40<br /> 41<br /> 42<br /> 43<br /> 44<br /> 45<br /> 46<br /> 47<br /> 48<br /> 49<br /> 50<br /> 51<br /> 52<br /> 53<br /> 54<br /> 55<br /> 56<br /> 57<br /> 58<br /> 59<br /> 60<br /> 61<br /> 62<br /> 63<br /> 64<br /> 65<br /> 66<br /> 67<br /> 68<br /> 69<br /> 70<br /> 71<br /> 72<br /> 73<br /> 74<br /> 75<br /> 76<br /> 77<br /> 78<br /> 79<br /> 80<br /> 81<br /> 82<br /> 83<br /> 84<br /> 85<br /> 86<br /> 87<br /> 88<br /> 89<br /> 90<br /> 91<br /> 92<br /> 93<br /> 94<br /> 95<br /> 96<br /> 97<br /> 98<br /> 99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br /> </pre> </td> <td> <pre style="margin: 0; line-height: 125%"><br /><span style="color: #7E7E7E;">/* =================================================================================================</span><br /><span style="color: #7E7E7E;"> Project: Arduino Beatbox</span><br /><span style="color: #7E7E7E;"> Author: Scott C</span><br /><span style="color: #7E7E7E;"> Created: 9th April 2015</span><br /><span style="color: #7E7E7E;"> Arduino IDE: 1.6.2</span><br /><span style="color: #7E7E7E;"> Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html</span><br /><span style="color: #7E7E7E;"> Description: This project uses home made capacitive sensors to trigger over 130 MP3 sounds</span><br /><span style="color: #7E7E7E;"> on the Grove Serial MP3 player. </span><br /><span style="color: #7E7E7E;"> </span><br /><span style="color: #7E7E7E;"> The ADCTouch library is used to eliminate the resistors from the Capacitive sensing circuit. </span><br /><span style="color: #7E7E7E;"> The code used for capacitive sensing was adapted from the ADCTouch library example sketches. </span><br /><span style="color: #7E7E7E;"> You can find the ADCTouch library and relevant example code here:</span><br /><span style="color: #7E7E7E;"> http://playground.arduino.cc/Code/ADCTouch</span><br /><span style="color: #7E7E7E;"> </span><br /><span style="color: #7E7E7E;"> "Advanced Arduino ADC" is used to improve the analogRead() speed, and enhance the</span><br /><span style="color: #7E7E7E;"> drum pad or capacitive sensor response time. The Advanced Arduino ADC code </span><br /><span style="color: #7E7E7E;"> was adapted from this site:</span><br /><span style="color: #7E7E7E;"> http://www.microsmart.co.za/technical/2014/03/01/advanced-arduino-adc/</span><br /><span style="color: #7E7E7E;"> </span><br /><span style="color: #7E7E7E;"> </span><br /><span style="color: #7E7E7E;">=================================================================================================== */</span><br /> #include <<span style="color: #CC6600;">ADCTouch</span>.h><br /> #include <<span style="color: #CC6600;">SoftwareSerial</span>.h><br /> <br /> <br /> <span style="color: #7E7E7E;">//Global variables</span><br /> <span style="color: #7E7E7E;">//===================================================================================================</span><br /> <span style="color: #CC6600;">int</span> potPin = A4; <span style="color: #7E7E7E;">//Grove Sliding potentiometer is connected to Analog Pin 4</span><br /> <span style="color: #CC6600;">int</span> potVal = 0;<br /> <span style="color: #CC6600;">byte</span> mp3Vol = 0; <span style="color: #7E7E7E;">//Variable used to control the volume of the MP3 player</span><br /> <span style="color: #CC6600;">byte</span> oldVol = 0;<br /> <br /> <span style="color: #CC6600;">int</span> buttonPin = 5; <span style="color: #7E7E7E;">//Grove Button is connected to Digital Pin 5</span><br /> <span style="color: #CC6600;">int</span> buttonStatus = 0;<br /> <br /> <span style="color: #CC6600;">byte</span> SongNum[4] = {0x01,0x02,0x03,0x04}; <span style="color: #7E7E7E;">//The first 4 songs will be assigned to the drum pads upon initialisation</span><br /> <span style="color: #CC6600;">byte</span> numOfSongs = 130; <span style="color: #7E7E7E;">//Total number of MP3 songs/sounds loaded onto the SDHC card</span><br /> <br /> <span style="color: #CC6600;">long</span> randNumber; <span style="color: #7E7E7E;">//Variable used to hold the random number - used to randomise the sounds.</span><br /> <br /> <span style="color: #CC6600;">int</span> ledState[4]; <span style="color: #7E7E7E;">//Used to keep track of the status of all LEDs (on or off)</span><br /> <span style="color: #CC6600;">int</span> counter = 0;<br /> <br /> <span style="color: #CC6600;">SoftwareSerial</span> mp3(3, 4); <span style="color: #7E7E7E;">// The Grove MP3 Player is connected to Arduino digital Pin 3 and 4 (Serial communication)</span><br /> <br /> <span style="color: #CC6600;">int</span> ref0, ref1, ref2, ref3; <span style="color: #7E7E7E;">//reference values to remove offset</span><br /> <span style="color: #CC6600;">int</span> threshold = 100;<br /> <br /> <span style="color: #7E7E7E;">// Define the ADC prescalers</span><br /> <span style="color: #CC6600;">const</span> <span style="color: #CC6600;">unsigned</span> <span style="color: #CC6600;">char</span> PS_64 = (1 << ADPS2) | (1 << ADPS1);<br /> <span style="color: #CC6600;">const</span> <span style="color: #CC6600;">unsigned</span> <span style="color: #CC6600;">char</span> PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);<br /> <br /> <br /> <br /> <span style="color: #7E7E7E;">//Setup()</span><br /> <span style="color: #7E7E7E;">//===================================================================================================</span><br /> <span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>setup</b></span>(){<br /> <span style="color: #7E7E7E;">//Initialise the Grove MP3 Module</span><br /> <span style="color: #CC6600;">delay</span>(2500); <span style="color: #7E7E7E;">//Allow the MP3 module to power up </span><br /> mp3.<span style="color: #CC6600;">begin</span>(9600); <span style="color: #7E7E7E;">//Begin Serial communication with the MP3 module</span><br /> setPlayMode(0x00); <span style="color: #7E7E7E;">//0x00 = Single song - played once ie. not repeated. (default)</span><br /> <br /> <span style="color: #7E7E7E;">//Define the Grove Button as an INPUT</span><br /> <span style="color: #CC6600;">pinMode</span>(buttonPin, <span style="color: #006699;">INPUT</span>);<br /> <br /> <span style="color: #7E7E7E;">//Define the 4 LED Pins as OUTPUTs</span><br /> <span style="color: #CC6600;">pinMode</span>(8, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7E7E7E;">//Green LED</span><br /> <span style="color: #CC6600;">pinMode</span>(9, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7E7E7E;">//Blue LED</span><br /> <span style="color: #CC6600;">pinMode</span>(10, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7E7E7E;">//Red LED</span><br /> <span style="color: #CC6600;">pinMode</span>(11, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7E7E7E;">//Yellow LED</span><br /> <br /> <span style="color: #7E7E7E;">//Make sure each LED is OFF, and store the state of the LED into a variable.</span><br /> <span style="color: #CC6600;">for</span>(<span style="color: #CC6600;">int</span> i=8;i<12;i++){<br /> <span style="color: #CC6600;">digitalWrite</span>(i, <span style="color: #006699;">LOW</span>);<br /> ledState[i-8]=0;<br /> } <br /> <br /> <span style="color: #7E7E7E;">//Double our clock speed from 125 kHz to 250 kHz</span><br /> ADCSRA &= ~PS_128; <span style="color: #7E7E7E;">// set up the ADC</span><br /> ADCSRA |= PS_64; <span style="color: #7E7E7E;">// set our own prescaler to 64 </span><br /> <br /> <span style="color: #7E7E7E;">//Create reference values to account for the capacitance of each pad.</span><br /> ref0 = <span style="color: #CC6600;">ADCTouch</span>.<span style="color: #CC6600;">read</span>(A0, 500);<br /> ref1 = <span style="color: #CC6600;">ADCTouch</span>.<span style="color: #CC6600;">read</span>(A1, 500); <span style="color: #7E7E7E;">//Take 500 readings</span><br /> ref2 = <span style="color: #CC6600;">ADCTouch</span>.<span style="color: #CC6600;">read</span>(A2, 500);<br /> ref3 = <span style="color: #CC6600;">ADCTouch</span>.<span style="color: #CC6600;">read</span>(A3, 500);<br /> <br /> <span style="color: #7E7E7E;">//This helps to randomise the drum pads.</span><br /> <span style="color: #CC6600;">randomSeed</span>(<span style="color: #CC6600;">analogRead</span>(0));<br /> }<br /> <br /> <br /> <br /> <span style="color: #7E7E7E;">// Loop()</span><br /> <span style="color: #7E7E7E;">//=================================================================================================== </span><br /> <span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>loop</b></span>(){<br /> <br /> <span style="color: #7E7E7E;">//Take a reading from the Grove Sliding Potentiometer, and set volume accordingly</span><br /> potVal = <span style="color: #CC6600;">analogRead</span>(potPin);<br /> mp3Vol = <span style="color: #CC6600;">map</span>(potVal, 0, 1023, 0,31); <span style="color: #7E7E7E;">// Convert the potentometer reading (0 - 1023) to fit within the MP3 player's Volume range (0 - 31)</span><br /> <span style="color: #CC6600;">if</span>((mp3Vol>(oldVol+1))|(mp3Vol<(oldVol-1))){ <span style="color: #7E7E7E;">// Only make a change to the Volume on the Grove MP3 player when the potentiometer value changes</span><br /> oldVol = mp3Vol;<br /> setVolume(mp3Vol);<br /> <span style="color: #CC6600;">delay</span>(10); <span style="color: #7E7E7E;">// This delay is necessary with Serial communication to MP3 player</span><br /> }<br /> <br /> <span style="color: #7E7E7E;">//Take a reading from the Pin attached to the Grove Button. If pressed, randomise the MP3 songs/sounds for each drum pad, and make the LEDs blink randomly.</span><br /> buttonStatus = <span style="color: #CC6600;">digitalRead</span>(buttonPin);<br /> <span style="color: #CC6600;">if</span>(buttonStatus==<span style="color: #006699;">HIGH</span>){<br /> SongNum[0]=randomSongChooser(1, 30);<br /> SongNum[1]=randomSongChooser(31, 60);<br /> SongNum[2]=randomSongChooser(61, 86);<br /> SongNum[3]=randomSongChooser(87, (<span style="color: #CC6600;">int</span>)numOfSongs);<br /> randomLEDBlink();<br /> }<br /> <br /> <span style="color: #7E7E7E;">//Get the capacitive readings from each drum pad: 50 readings are taken from each pad. (default is 100) </span><br /> <span style="color: #CC6600;">int</span> value0 = <span style="color: #CC6600;">ADCTouch</span>.<span style="color: #CC6600;">read</span>(A0,50); <span style="color: #7E7E7E;">// Green drum pad</span><br /> <span style="color: #CC6600;">int</span> value1 = <span style="color: #CC6600;">ADCTouch</span>.<span style="color: #CC6600;">read</span>(A1,50); <span style="color: #7E7E7E;">// Blue drum pad</span><br /> <span style="color: #CC6600;">int</span> value2 = <span style="color: #CC6600;">ADCTouch</span>.<span style="color: #CC6600;">read</span>(A2,50); <span style="color: #7E7E7E;">// Red drum pad</span><br /> <span style="color: #CC6600;">int</span> value3 = <span style="color: #CC6600;">ADCTouch</span>.<span style="color: #CC6600;">read</span>(A3,50); <span style="color: #7E7E7E;">// Yellow drum pad</span><br /> <br /> <span style="color: #7E7E7E;">//Remove the offset to account for the baseline capacitance of each pad.</span><br /> value0 -= ref0; <br /> value1 -= ref1;<br /> value2 -= ref2;<br /> value3 -= ref3;<br /> <br /> <br /> <span style="color: #7E7E7E;">//If any of the values exceed the designated threshold, then play the song/sound associated with that drum pad.</span><br /> <span style="color: #7E7E7E;">//The associated LED will stay on for the whole time the drum pad is pressed, providing the value remains above the threshold. </span><br /> <span style="color: #7E7E7E;">//The LED will turn off when the pad is not being touched or pressed.</span><br /> <span style="color: #CC6600;">if</span>(value0>threshold){<br /> <span style="color: #CC6600;">digitalWrite</span>(8, <span style="color: #006699;">HIGH</span>);<br /> playSong(00,SongNum[0]);<br /> }<span style="color: #CC6600;">else</span>{<br /> <span style="color: #CC6600;">digitalWrite</span>(8,<span style="color: #006699;">LOW</span>);<br /> }<br /> <br /> <span style="color: #CC6600;">if</span>(value1>threshold){<br /> <span style="color: #CC6600;">digitalWrite</span>(9, <span style="color: #006699;">HIGH</span>);<br /> playSong(00,SongNum[1]);<br /> }<span style="color: #CC6600;">else</span>{<br /> <span style="color: #CC6600;">digitalWrite</span>(9,<span style="color: #006699;">LOW</span>);<br /> }<br /> <br /> <span style="color: #CC6600;">if</span>(value2>threshold){<br /> <span style="color: #CC6600;">digitalWrite</span>(10, <span style="color: #006699;">HIGH</span>);<br /> playSong(00,SongNum[2]);<br /> }<span style="color: #CC6600;">else</span>{<br /> <span style="color: #CC6600;">digitalWrite</span>(10,<span style="color: #006699;">LOW</span>);<br /> }<br /> <br /> <span style="color: #CC6600;">if</span>(value3>threshold){<br /> <span style="color: #CC6600;">digitalWrite</span>(11, <span style="color: #006699;">HIGH</span>);<br /> playSong(00,SongNum[3]);<br /> }<span style="color: #CC6600;">else</span>{<br /> <span style="color: #CC6600;">digitalWrite</span>(11,<span style="color: #006699;">LOW</span>);<br /> }<br /> }<br /> <br /> <br /> <span style="color: #7E7E7E;">// writeToMP3: </span><br /> <span style="color: #7E7E7E;">// a generic function that simplifies each of the methods used to control the Grove MP3 Player</span><br /> <span style="color: #7E7E7E;">//===================================================================================================</span><br /> <span style="color: #CC6600;">void</span> writeToMP3(<span style="color: #CC6600;">byte</span> MsgLEN, <span style="color: #CC6600;">byte</span> A, <span style="color: #CC6600;">byte</span> B, <span style="color: #CC6600;">byte</span> C, <span style="color: #CC6600;">byte</span> D, <span style="color: #CC6600;">byte</span> E, <span style="color: #CC6600;">byte</span> F){<br /> <span style="color: #CC6600;">byte</span> codeMsg[] = {MsgLEN, A,B,C,D,E,F};<br /> mp3.<span style="color: #CC6600;">write</span>(0x7E); <span style="color: #7E7E7E;">//Start Code for every command = 0x7E</span><br /> <span style="color: #CC6600;">for</span>(<span style="color: #CC6600;">byte</span> i = 0; i<MsgLEN+1; i++){<br /> mp3.<span style="color: #CC6600;">write</span>(codeMsg[i]); <span style="color: #7E7E7E;">//Send the rest of the command to the GROVE MP3 player</span><br /> }<br /> }<br /> <br /> <br /> <span style="color: #7E7E7E;">//setPlayMode: defines how each song is to be played</span><br /> <span style="color: #7E7E7E;">//===================================================================================================</span><br /> <span style="color: #CC6600;">void</span> setPlayMode(<span style="color: #CC6600;">byte</span> playMode){<br /> <span style="color: #7E7E7E;">/* playMode options:</span><br /><span style="color: #7E7E7E;"> 0x00 = Single song - played only once ie. not repeated. (default)</span><br /><span style="color: #7E7E7E;"> 0x01 = Single song - cycled ie. repeats over and over.</span><br /><span style="color: #7E7E7E;"> 0x02 = All songs - cycled </span><br /><span style="color: #7E7E7E;"> 0x03 = play songs randomly */</span><br /> writeToMP3(0x03, 0xA9, playMode, 0x7E, 0x00, 0x00, 0x00); <br /> }<br /> <br /> <br /> <span style="color: #7E7E7E;">//playSong: tells the Grove MP3 player to play the song/sound, and also which song/sound to play</span><br /> <span style="color: #7E7E7E;">//===================================================================================================</span><br /> <span style="color: #CC6600;">void</span> playSong(<span style="color: #CC6600;">byte</span> songHbyte, <span style="color: #CC6600;">byte</span> songLbyte){<br /> writeToMP3(0x04, 0xA0, songHbyte, songLbyte, 0x7E, 0x00, 0x00); <br /> <span style="color: #CC6600;">delay</span>(100);<br /> }<br /> <br /> <br /> <span style="color: #7E7E7E;">//setVolume: changes the Grove MP3 player's volume to the designated level (0 to 31)</span><br /> <span style="color: #7E7E7E;">//===================================================================================================</span><br /> <span style="color: #CC6600;">void</span> setVolume(<span style="color: #CC6600;">byte</span> Volume){<br /> <span style="color: #CC6600;">byte</span> tempVol = <span style="color: #CC6600;">constrain</span>(Volume, 0, 31); <span style="color: #7E7E7E;">//Volume range = 00 (muted) to 31 (max volume)</span><br /> writeToMP3(0x03, 0xA7, tempVol, 0x7E, 0x00, 0x00, 0x00); <br /> }<br /> <br /> <br /> <span style="color: #7E7E7E;">//randomSongChooser: chooses a random song to play. The range of songs to choose from</span><br /> <span style="color: #7E7E7E;">//is limited and defined by the startSong and endSong parameters.</span><br /> <span style="color: #7E7E7E;">//===================================================================================================</span><br /> <span style="color: #CC6600;">byte</span> randomSongChooser(<span style="color: #CC6600;">int</span> startSong, <span style="color: #CC6600;">int</span> endSong){<br /> randNumber = <span style="color: #CC6600;">random</span>(startSong, endSong);<br /> <span style="color: #CC6600;">return</span>((<span style="color: #CC6600;">byte</span>) randNumber);<br /> }<br /> <br /> <br /> <span style="color: #7E7E7E;">//randomLEDBlink: makes each LED blink randomly. The LEDs are attached to digital pins 8 to 12.</span><br /> <span style="color: #7E7E7E;">//===================================================================================================</span><br /> <span style="color: #CC6600;">void</span> randomLEDBlink(){<br /> counter=8;<br /> <span style="color: #CC6600;">for</span>(<span style="color: #CC6600;">int</span> i=0; i<40; i++){<br /> <span style="color: #CC6600;">int</span> x = <span style="color: #CC6600;">constrain</span>((<span style="color: #CC6600;">int</span>)<span style="color: #CC6600;">random</span>(8,12),8,12);<br /> toggleLED(x);<br /> <span style="color: #CC6600;">delay</span>(<span style="color: #CC6600;">random</span>(50,100-i));<br /> }<br /> <br /> <span style="color: #CC6600;">for</span>(<span style="color: #CC6600;">int</span> i=8;i<12;i++){<br /> <span style="color: #CC6600;">digitalWrite</span>(i, <span style="color: #006699;">HIGH</span>);<br /> }<br /> <span style="color: #CC6600;">delay</span>(1000);<br /> <span style="color: #CC6600;">for</span>(<span style="color: #CC6600;">int</span> i=8;i<12;i++){<br /> <span style="color: #CC6600;">digitalWrite</span>(i, <span style="color: #006699;">LOW</span>);<br /> ledState[i-8]=0;<br /> }<br /> }<br /> <br /> <br /> <span style="color: #7E7E7E;">//toggleLED: is used by the randomLEDBlink method to turn each LED on and off (randomly).</span><br /> <span style="color: #7E7E7E;">//===================================================================================================</span><br /> <span style="color: #CC6600;">void</span> toggleLED(<span style="color: #CC6600;">int</span> pinNum){<br /> ledState[pinNum-8]= !ledState[pinNum-8];<br /> <span style="color: #CC6600;">digitalWrite</span>(pinNum, ledState[pinNum-8]);<br /> }<br /> </pre> </td> </tr> </table></div></P> <BR /> <BR /> <P> <h4>Arduino Code Discussion</h4> You can see from the Arduino code above, that it uses the <a href="http://playground.arduino.cc/Code/ADCTouch">ADCTouch library</a>. This library was chosen over the <a href="http://playground.arduino.cc/Main/CapacitiveSensor?from=Main.CapSense">Capacitive Sensing Library</a> to eliminate the need for a high value resistor which are commonly found in Capacitive Sensing projects). <BR /> <BR /> To increase the speed of the Analog readings, I utilised one of the "Advanced Arduino ADC" techniques described by <a href="http://www.microsmart.co.za/technical/2014/03/01/advanced-arduino-adc/">Guy van den Berg on this Microsmart website</a>. <BR /> <BR /> The readings are increased by modifying the Arduino's ADC clock speed from 125kHz to 250 kHz. I did notice an overall better response time with this modification. However, the Grove Serial MP3 player is limited by it's inability to play more than one song or sound at a time. This means that if you hit another drum pad while the current sound is playing, it will stop playing the current sound, and then play the selected sound. The speed at which it can perform this task was quite impressive. In fact it was much better than I thought it would be. But if you are looking for polyphonic playability, you will be dissapointed. <BR /> <BR /> This Serial MP3 module makes use of a high quality MP3 audio chip known as the "WT5001". Therefore, you should be able to get some additional features and functionality from <a href="http://goo.gl/ai6oQ9">this document</a>. Plus you may find some extra useful info from <a href="http://goo.gl/xOiSCl">the Seeedstudio wiki</a>. I have re-used some code from the <a href="http://arduinobasics.blogspot.com.au/2015/03/arduino-boombox.html">Arduino Boombox tutorial</a>... you will find extra Grove Serial MP3 functions on that page. <BR /> <BR /> I will warn you... the Grove Serial MP3 player can play WAV files, however for some reason it would not play many of the sound files in this format. Once the sounds were converted to the MP3 format, I did not look back. So if you decide to take on this project, make sure your sound files are in MP3 format, you'll have a much better outcome. <BR /> <BR /> I decided to introduce a random sound selection for each drum pad to extend the novelty of this instrument, which meant that I had to come up with a fancy way to illuminate the LEDs. I demonstrated some of my other LED sequences on my <a href="https://instagram.com/arduinobasics">instagram account</a>. I sometimes use instagram to show my work in progress. <BR /> <BR /> Have a look at the video below to see this project in action, and putting the Grove Serial MP3 player through it's paces. <BR /> <BR /> <P> <H4>The Video</H4> <BR /> <div style="text-align: center;"> <div class="separator" style="clear: both; text-align: center;"> <iframe width="640" height="480" src="https://www.youtube.com/embed/gdMAkTz4fy4" frameborder="1" allowfullscreen></iframe></br> </div> </div> </P></div><!--separator --><img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /><P> <div style="text-align: justify;"> First there was the <a href="http://arduinobasics.blogspot.com.au/2015/03/arduino-boombox.html">Arduino Boombox</a>, and now we have the Arduino Beatbox..... who knows what will come next ! <BR /> <BR /> Whenever I create a new project, I like to improve my Arduino knowledge. Sometimes it takes me into some rather complicated topics. There is a lot I do not know about Arduino, but I am enjoying the journey. I hope you are too !! Please Google plus one this post if it helped you in any way. These tutorials are free, which means I survive on feedback and plus ones... all you have to do is just scroll a little bit more and click that button :) </div> <BR /> <BR /> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> <div align="center"> If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br> <BR /> <BR /> Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br> Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br> I can also be found on <a href="https://www.pinterest.com/ArduinoBasics/">Pinterest</a> and <a href="https://instagram.com/arduinobasics">Instagram</a>. <br> Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.<br> </div> </P> <BR /> <BR /> <div align="center"> <div class="separator" style="clear: both; text-align: center;"> <a href="http://arduino.cc/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmuBeqll5_-ovWlmf5ncMAWNxQ05r_dYIb_ezswWonrTzqnBW1y3YiN4dFUImKVLrFfilGIPMMg5mMfHItxdei6Kqs4o9pvZsg3sucWXSUR5Lm-MDx3nhDHu_9oaZIKeFGLANQoz4Ge8c/s1600/ArduinoLogo.png" /></a> </div> </div> <BR /> <BR /> <BR /> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> However, if you do not have a google profile... <br>Feel free to share this page with your friends in any way you see fit. </P></P></P><br /><br /><br /><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" -->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-50562046679412422052015-04-08T03:31:00.000-07:002016-03-19T10:53:41.093-07:00Arduino vs Arduino<span style="font-size: large;">What side do you support?</span><br /><br />The form submission is anonymous.<br />I will post the results on Google+ around the 14th of April 2015.<br /><br />Make your choice below:<br /><iframe frameborder="0" height="700" marginheight="0" marginwidth="0" src="https://docs.google.com/forms/d/1Ab0weGaoDUFD-8Xnw2Cu7wmyMB-eTA-g-iutp7A1CxQ/viewform?embedded=true" width="100%">Loading...</iframe> <br /><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtO746AnHnn-2r131OBCBeBLXsCPmslKDCsZ8lAKpxprVYNnWwscHAWSlPLZaMivuy9gZwaGLbiIgmRPYV6kpCIFZj-EecAlKmaXTQmQdB85VUBFIrOyfoYR0sY2AWhDv77de-9zC2N9s/s1600/ArduinoSplit2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtO746AnHnn-2r131OBCBeBLXsCPmslKDCsZ8lAKpxprVYNnWwscHAWSlPLZaMivuy9gZwaGLbiIgmRPYV6kpCIFZj-EecAlKmaXTQmQdB85VUBFIrOyfoYR0sY2AWhDv77de-9zC2N9s/s1600/ArduinoSplit2.png" height="15" width="32" /></a></div><br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-6479145406474859322015-03-19T06:20:00.000-07:002016-03-19T10:53:41.136-07:00Arduino Boombox<g:plusone></g:plusone><div style="text-align: justify;"> <P> <!-- Title Page Graphic Arduino BoomBox Title Page Graphic--> <div class="separator" style="clear: both; text-align: center;"> <img style="border:3px solid white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZ-zMNQvEuVyxFqViv6jHMdNulxLfuiRkBUHuUiZf-y4YBgmckHsHxoeA_2ye_K6EiiePjaQ8ZT4AqqVwRy5_0TWKWR4RZyHXYrBWKWsISgr6S3y93JZTeFAHla7POLBj_xuEimcGKkbw/s1600/Arduino+BoomBox+Web+Title2.png" height="152" width="665" /> </div> </P> <P> <div style="text-align: justify;"> <P> <!-- Description and Introduction of project --> Add sound or music to your project using the "Grove Serial MP3 Player". </P> <P> An Arduino UNO will be used to control the Grove Serial MP3 player by sending it specific serial commands. The Grove Base Shield allows for the easy connection of Grove sensor modules to an Arduino UNO without the need for a breadboard. A sliding potentiometer, switch and button will be connected to the Base shield along with the Serial MP3 player. A specific function will be assigned to each of the connected sensor modules to provide a useful interface: <ul> <li><span style="color: yellow;">Sliding Potentiometer</span> – Volume control</li> <li><span style="color: yellow;">Button</span> – Next Song</li> <li><span style="color: yellow;">Switch</span> – On/Off (toggle)</li> </ul> Once the MP3 module is working the way we want, we can then build a simple enclosure for it. </br> Grab a shoe-box, print out your favourite design, and make your very own Arduino BOOMBOX! </P> </div> </P> <BR /> <P> <H4>Video</H4> Watch the following video to see the project in action <BR /> <BR /> <!-- VIDEO GOES HERE --> <div class="separator" style="clear: both; text-align: center;"> <iframe width="640" height="480" src="https://www.youtube.com/embed/VDRPnEpTKPk" frameborder="1" allowfullscreen></iframe></br> </div> </P> <BR /> <BR /> <P> <H4>Parts Required:</H4> <P> <ul> <li><a href="http://www.epictinker.com/Freetronics-Eleven-100-Arduino-Uno-Compatible-p/ard-1002.htm">Arduino UNO or compatible board</a></li> <li><a href="http://www.epictinker.com/Grove-Base-Shield-v1-3-p/sld01099p.htm">Grove Base Shield</a></li> <li><a href="http://www.epictinker.com/Grove-Serial-MP3-Player-p/sen01300p.htm">Grove Serial MP3 Player</a></li> <li><a href="http://www.epictinker.com/Grove-Switch-P-p/com08213p.htm">Grove Switch (P)</a></li> <li><a href="http://www.epictinker.com/Grove-Slide-Potentiometer-p/com05231p.htm">Grove Sliding Potentiometer</a></li> <li><a href="http://www.epictinker.com/Grove-Button-p/com22242p.htm">Grove Button</a> or <a href="http://www.epictinker.com/Grove-Button-P-p/com08211p.htm">Grove Button (P)</a></li> <li><a href="http://www.epictinker.com/Grove-Universal-4-Pin-20cm-Cable-5pk-p/acc11317o.htm">Grove Universal 4 pin cables</a></li> <li><a href="http://www.epictinker.com/6xAA-Battery-Holder-with-DC-2-1mm-Power-Jack-p/fit0141.htm">Battery Holder</a></li> <li><a href="http://bit.ly/1H4UHXa">SanDisk 8GB Ultra Micro SDHC Memory card</a></li> <li><a href="http://lmgtfy.com/?q=DOSS+DS+1158">Portable Powered Speaker</a> or Headphones</li><br /> </ul> Optional components (for the BoomBox Enclosure): <ul> <li>Empty Shoe Box</li> <li>Paper</li> <li>Printer</li> <li>Glue</li> </ul> If I had a 3D printer - I would have printed my own enclosure, but a shoebox seems to work just fine. </P> </P> <BR /> <P> <H4>Putting it Together</H4> <div style="text-align: justify;"> <P>Place the Grove Base shield onto the Arduino UNO,<br> and then connect each of the Grove Modules as per the table below. <BR /> <BR /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIloz-haa0S1Ii7oQFy3XMoEu4weus8iNnEgtfOny7UBDw7JOwDVvP3g-m-DluRdC6oK968TUn70AUDkKsmYYb-pbsji9S7zgSxutnBw90_habMzbhq3HwtMr5atExBC2kBlcoNwSFk6E/s1600/Slide19.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIloz-haa0S1Ii7oQFy3XMoEu4weus8iNnEgtfOny7UBDw7JOwDVvP3g-m-DluRdC6oK968TUn70AUDkKsmYYb-pbsji9S7zgSxutnBw90_habMzbhq3HwtMr5atExBC2kBlcoNwSFk6E/s1600/Slide19.PNG" height="480" width="640" /> </a> </div> </P> <BR /> <BR /> <P>If you do not have a Grove Base shield,<br> you can still connect the modules directly to the Arduino as per the table below: <BR /> <BR /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyLxDrbOtiKHTO8Wy177V4GR7g4g0aPx0TWmkcS8mfLUH2yt_CmUw8iJMOX9BYG36Gl5BFYfcPwlT37u1jwKFmFKOZGgYSO6LqajumHq7ucpih7OHhWuWlgbnyZQsNjjADQO5rYh1z4Ic/s1600/Slide24.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyLxDrbOtiKHTO8Wy177V4GR7g4g0aPx0TWmkcS8mfLUH2yt_CmUw8iJMOX9BYG36Gl5BFYfcPwlT37u1jwKFmFKOZGgYSO6LqajumHq7ucpih7OHhWuWlgbnyZQsNjjADQO5rYh1z4Ic/s1600/Slide24.PNG" height="480" width="640" /> </a> </div> </P> <BR /> <BR /> <P>When you are finished connecting the modules, it should look something like this:<br> (ignore the battery pack): <BR /> <BR /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRktJ-7Raf9rmzbDqmvcgR1ex-Ors_qtpPoQRIBobHBMB5PPpx1aIOT-3VhP0_bg00KCchX7LmBwhTYhlu8ARh8nFRqSmb0fG2tgBv7Fz1fbDCJGpw4bZQ48eFGXl4BOkZkIfSmzaA96g/s1600/IMG_4425.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRktJ-7Raf9rmzbDqmvcgR1ex-Ors_qtpPoQRIBobHBMB5PPpx1aIOT-3VhP0_bg00KCchX7LmBwhTYhlu8ARh8nFRqSmb0fG2tgBv7Fz1fbDCJGpw4bZQ48eFGXl4BOkZkIfSmzaA96g/s1600/IMG_4425.JPG" height="480" width="640" /> </a> </div> </P> <P>As you can see from the picture above. You can cut holes out of the shoebox and stick the modules in place. Please ignore the battery pack, because you won't use it until after you have uploaded the Arduino code. </P> </div> </P> <BR /> <BR /> <P> <H4>Arduino Sketch</H4> <BR /> <div style="background: #ffffff; color: #000000; overflow:auto;width:auto;border:solid rgb(24,186,183);border-width: .6em .3em .3em .3em;padding: 0em 0em;"> <table> <tr> <td> <pre style="margin: 0; line-height: 125%; background: rgb(24,186,183); width: 1.9em"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br /> 10<br /> 11<br /> 12<br /> 13<br /> 14<br /> 15<br /> 16<br /> 17<br /> 18<br /> 19<br /> 20<br /> 21<br /> 22<br /> 23<br /> 24<br /> 25<br /> 26<br /> 27<br /> 28<br /> 29<br /> 30<br /> 31<br /> 32<br /> 33<br /> 34<br /> 35<br /> 36<br /> 37<br /> 38<br /> 39<br /> 40<br /> 41<br /> 42<br /> 43<br /> 44<br /> 45<br /> 46<br /> 47<br /> 48<br /> 49<br /> 50<br /> 51<br /> 52<br /> 53<br /> 54<br /> 55<br /> 56<br /> 57<br /> 58<br /> 59<br /> 60<br /> 61<br /> 62<br /> 63<br /> 64<br /> 65<br /> 66<br /> 67<br /> 68<br /> 69<br /> 70<br /> 71<br /> 72<br /> 73<br /> 74<br /> 75<br /> 76<br /> 77<br /> 78<br /> 79<br /> 80<br /> 81<br /> 82<br /> 83<br /> 84<br /> 85<br /> 86<br /> 87<br /> 88<br /> 89<br /> 90<br /> 91<br /> 92<br /> 93<br /> 94<br /> 95<br /> 96<br /> 97<br /> 98<br /> 99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br /> </pre> </td> <td> <pre style="margin: 0; line-height: 125%"><br /> <!-- INSERT ARDUINO CODE HERE --><br /><span style="color: #7E7E7E;">/* ===============================================================================</span><br /><span style="color: #7E7E7E;"> Project: Grove Serial MP3 Player overview</span><br /><span style="color: #7E7E7E;"> Author: Scott C</span><br /><span style="color: #7E7E7E;"> Created: 9th March 2015</span><br /><span style="color: #7E7E7E;"> Arduino IDE: 1.6.0</span><br /><span style="color: #7E7E7E;"> Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html</span><br /><br /><span style="color: #7E7E7E;"> Description: The following Arduino sketch will allow you to control a Grove Serial MP3 player</span><br /><span style="color: #7E7E7E;"> with a Grove Sliding Potentiometer (volume), a Grove button (next song), </span><br /><span style="color: #7E7E7E;"> and a Grove Switch (on/off). It will also show you how to retrieve some useful information from the player. </span><br /><span style="color: #7E7E7E;"> Some functions are not used in this sketch,but have been included for your benefit. </span><br /><span style="color: #7E7E7E;"> </span><br /><span style="color: #7E7E7E;"> Additional features and functionality can be found on the WT5001 voice chip datasheet </span><br /><span style="color: #7E7E7E;"> which I retrieved from here: http://goo.gl/ai6oQ9</span><br /><span style="color: #7E7E7E;"> </span><br /><span style="color: #7E7E7E;"> The Seeedstudio wiki was a very useful resource for getting started with the various Grove modules:</span><br /><span style="color: #7E7E7E;"> http://goo.gl/xOiSCl</span><br /><span style="color: #7E7E7E;">=============================================================================== */</span><br /><br />#include <<span style="color: #CC6600;">SoftwareSerial</span>.h><br /><span style="color: #CC6600;">SoftwareSerial</span> mp3(2, 3); <span style="color: #7E7E7E;">// The Grove MP3 Player is connected to Arduino digital Pin 2 and 3 (Serial communication)</span><br /><span style="color: #CC6600;">int</span> potPin = A0; <span style="color: #7E7E7E;">// The Sliding Potentiometer is connected to AnalogPin 0</span><br /><span style="color: #CC6600;">int</span> potVal = 0; <span style="color: #7E7E7E;">// This is used to hold the value of the Sliding Potentiometer</span><br /><span style="color: #CC6600;">byte</span> mp3Vol = 0; <span style="color: #7E7E7E;">// mp3Vol is used to calculate the Current volume of the Grove MP3 player</span><br /><span style="color: #CC6600;">byte</span> oldVol = 0; <span style="color: #7E7E7E;">// oldVol is used to remember the previous volume level</span><br /><span style="color: #CC6600;">int</span> ledPin = A1; <span style="color: #7E7E7E;">// The Grove sliding potentiometer has an onboard LED attached to Analog pin 1.</span><br /><br /><span style="color: #CC6600;">int</span> switchPin = 12; <span style="color: #7E7E7E;">// The Grove Switch(P) is connected to digital Pin 12</span><br /><span style="color: #CC6600;">int</span> switchStatus = 0; <span style="color: #7E7E7E;">// This is used to hold the status of the switch </span><br /><span style="color: #CC6600;">int</span> switchChangeStatus = 0; <span style="color: #7E7E7E;">// Used to identify when the switch status has changed</span><br /><br /><span style="color: #CC6600;">int</span> buttonPin = 5; <span style="color: #7E7E7E;">// The Grove Button is connected to digital pin 5</span><br /><span style="color: #CC6600;">int</span> buttonStatus = 0; <span style="color: #7E7E7E;">// This is used to hold the status of the button </span><br /><br /><br /><br /><span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>setup</b></span>(){<br /> <span style="color: #7E7E7E;">//Initialise the Grove MP3 Module</span><br /> <span style="color: #CC6600;">delay</span>(2500);<br /> mp3.<span style="color: #CC6600;">begin</span>(9600);<br /> <br /> <br /> <span style="color: #7E7E7E;">// initialize the pushbutton and switch pin as an input:</span><br /> <span style="color: #CC6600;">pinMode</span>(buttonPin, <span style="color: #006699;">INPUT</span>);<br /> <span style="color: #CC6600;">pinMode</span>(switchPin, <span style="color: #006699;">INPUT</span>);<br /> <br /> <span style="color: #7E7E7E;">// set ledPin on the sliding potentiometer to OUTPUT</span><br /> <span style="color: #CC6600;">pinMode</span>(ledPin, <span style="color: #006699;">OUTPUT</span>);<br /> <br /> <span style="color: #7E7E7E;">//You can view the following demostration output in the Serial Monitor</span><br /> demonstrate_GET_FUNCTIONS(); <br />}<br /><br /><br /><span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>loop</b></span>(){<br /> switchStatus = <span style="color: #CC6600;">digitalRead</span>(switchPin);<br /> <span style="color: #CC6600;">if</span>(switchStatus==<span style="color: #006699;">HIGH</span>){<br /> <span style="color: #CC6600;">if</span>(switchChangeStatus==<span style="color: #006699;">LOW</span>){ <span style="color: #7E7E7E;">// When Arduino detects a change in the switchStatus (from LOW to HIGH) - play song </span><br /> setPlayMode(0x02); <span style="color: #7E7E7E;">// Automatically cycle to the next song when the current song ends</span><br /> playSong(00,01); <span style="color: #7E7E7E;">// Play the 1st song when you switch it on</span><br /> switchChangeStatus=<span style="color: #006699;">HIGH</span>;<br /> }<br /> <br /> potVal = <span style="color: #CC6600;">analogRead</span>(potPin); <span style="color: #7E7E7E;">// Analog read values from the sliding potentiometer range from 0 to 1023</span><br /> <span style="color: #CC6600;">analogWrite</span>(ledPin, potVal/4); <span style="color: #7E7E7E;">// Analog write values range from 0 to 255, and will turn LED ON once potentiometer reaches about half way (or more).</span><br /> mp3Vol = <span style="color: #CC6600;">map</span>(potVal, 0, 1023, 0,31); <span style="color: #7E7E7E;">// Convert the potentometer reading (0 - 1023) to fit within the MP3 player's Volume range (0 - 31)</span><br /> <span style="color: #CC6600;">if</span>((mp3Vol>(oldVol+1))|(mp3Vol<(oldVol-1))){ <span style="color: #7E7E7E;">// Only make a change to the Volume on the Grove MP3 player when the potentiometer value changes</span><br /> oldVol = mp3Vol;<br /> setVolume(mp3Vol);<br /> <span style="color: #CC6600;">delay</span>(10); <span style="color: #7E7E7E;">// This delay is necessary with Serial communication to MP3 player</span><br /> }<br /><br /> buttonStatus = <span style="color: #CC6600;">digitalRead</span>(buttonPin);<br /> <span style="color: #CC6600;">if</span>(buttonStatus==<span style="color: #006699;">HIGH</span>){ <span style="color: #7E7E7E;">// When a button press is detected - play the next song</span><br /> playNextSong();<br /> <span style="color: #CC6600;">delay</span>(200); <span style="color: #7E7E7E;">// This delay aims to prevent a "skipped" song due to slow button presses - can modify to suit.</span><br /> }<br /> } <span style="color: #CC6600;">else</span> {<br /> <span style="color: #CC6600;">if</span>(switchChangeStatus==<span style="color: #006699;">HIGH</span>){ <span style="color: #7E7E7E;">// When switchStatus changes from HIGH to LOW - stop Song.</span><br /> stopSong();<br /> switchChangeStatus=<span style="color: #006699;">LOW</span>;<br /> }<br /> } <br />}<br /><br /><br /><span style="color: #7E7E7E;">// demonstrate_GET_FUNCTIONS will show you how to retrieve some useful information from the Grove MP3 Player (using the Serial Monitor).</span><br /><span style="color: #CC6600;">void</span> demonstrate_GET_FUNCTIONS(){<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">begin</span>(9600);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"Volume: "</span>);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(getVolume());<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"Playing State: "</span>);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(getPlayingState());<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"# of Files in SD Card:"</span>);<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(getNumberOfFiles());<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"------------------------------"</span>);<br />}<br /><br /><br /><span style="color: #7E7E7E;">// writeToMP3: is a generic function that aims to simplify all of the methods that control the Grove MP3 Player</span><br /><br /><span style="color: #CC6600;">void</span> writeToMP3(<span style="color: #CC6600;">byte</span> MsgLEN, <span style="color: #CC6600;">byte</span> A, <span style="color: #CC6600;">byte</span> B, <span style="color: #CC6600;">byte</span> C, <span style="color: #CC6600;">byte</span> D, <span style="color: #CC6600;">byte</span> E, <span style="color: #CC6600;">byte</span> F){<br /> <span style="color: #CC6600;">byte</span> codeMsg[] = {MsgLEN, A,B,C,D,E,F};<br /> mp3.<span style="color: #CC6600;">write</span>(0x7E); <span style="color: #7E7E7E;">//Start Code for every command = 0x7E</span><br /> <span style="color: #CC6600;">for</span>(<span style="color: #CC6600;">byte</span> i = 0; i<MsgLEN+1; i++){<br /> mp3.<span style="color: #CC6600;">write</span>(codeMsg[i]); <span style="color: #7E7E7E;">//Send the rest of the command to the GROVE MP3 player</span><br /> }<br />}<br /><br /><br /><span style="color: #7E7E7E;">/* The Following functions control the Grove MP3 Player : see datasheet for additional functions--------------------------------------------*/</span><br /><br /><span style="color: #CC6600;">void</span> setPlayMode(<span style="color: #CC6600;">byte</span> playMode){<br /> <span style="color: #7E7E7E;">/* playMode options:</span><br /><span style="color: #7E7E7E;"> 0x00 = Single song - played only once ie. not repeated. (default)</span><br /><span style="color: #7E7E7E;"> 0x01 = Single song - cycled ie. repeats over and over.</span><br /><span style="color: #7E7E7E;"> 0x02 = All songs - cycled </span><br /><span style="color: #7E7E7E;"> 0x03 = play songs randomly */</span><br /> <br /> writeToMP3(0x03, 0xA9, playMode, 0x7E, 0x00, 0x00, 0x00); <br />}<br /><br /><br /><span style="color: #CC6600;">void</span> playSong(<span style="color: #CC6600;">byte</span> songHbyte, <span style="color: #CC6600;">byte</span> songLbyte){ <span style="color: #7E7E7E;">// Plays the selected song</span><br /> writeToMP3(0x04, 0xA0, songHbyte, songLbyte, 0x7E, 0x00, 0x00); <br />}<br /><br /><br /><span style="color: #CC6600;">void</span> pauseSong(){ <span style="color: #7E7E7E;">// Pauses the current song</span><br /> writeToMP3(0x02, 0xA3, 0x7E, 0x00, 0x00, 0x00, 0x00);<br />}<br /><br /><br /><span style="color: #CC6600;">void</span> stopSong(){ <span style="color: #7E7E7E;">// Stops the current song</span><br /> writeToMP3(0x02, 0xA4, 0x7E, 0x00, 0x00, 0x00, 0x00);<br />}<br /><br /><br /><span style="color: #CC6600;">void</span> playNextSong(){ <span style="color: #7E7E7E;">// Play the next song</span><br /> writeToMP3(0x02, 0xA5, 0x7E, 0x00, 0x00, 0x00, 0x00);<br />}<br /><br /><br /><span style="color: #CC6600;">void</span> playPreviousSong(){ <span style="color: #7E7E7E;">// Play the previous song</span><br /> writeToMP3(0x02, 0xA6, 0x7E, 0x00, 0x00, 0x00, 0x00);<br />}<br /><br /><br /><span style="color: #CC6600;">void</span> addSongToPlayList(<span style="color: #CC6600;">byte</span> songHbyte, <span style="color: #CC6600;">byte</span> songLbyte){<br /> <span style="color: #7E7E7E;">//Repeat this function for every song you wish to stack onto the playlist (max = 10 songs)</span><br /> writeToMP3(0x04, 0xA8, songHbyte, songLbyte, 0x7E, 0x00, 0x00);<br />}<br /><br /><br /><span style="color: #CC6600;">void</span> setVolume(<span style="color: #CC6600;">byte</span> Volume){ <span style="color: #7E7E7E;">// Set the volume</span><br /> <span style="color: #CC6600;">byte</span> tempVol = <span style="color: #CC6600;">constrain</span>(Volume, 0, 31);<br /> <span style="color: #7E7E7E;">//Volume range = 00 (muted) to 31 (max volume)</span><br /> writeToMP3(0x03, 0xA7, tempVol, 0x7E, 0x00, 0x00, 0x00); <br />}<br /><br /><br /><br /><span style="color: #7E7E7E;">/* The following functions retrieve information from the Grove MP3 player : see data sheet for additional functions--------------*/</span><br /><br /><span style="color: #7E7E7E;">// getData: is a generic function to simplifly the other functions for retieving information from the Grove Serial MP3 player</span><br /><span style="color: #CC6600;">byte</span> getData(<span style="color: #CC6600;">byte</span> queryVal, <span style="color: #CC6600;">int</span> dataPosition){<br /> <span style="color: #CC6600;">byte</span> returnVal = 0x00;<br /> writeToMP3(0x02, queryVal, 0x7E, 0x00, 0x00, 0x00, 0x00);<br /> <span style="color: #CC6600;">delay</span>(50);<br /> <span style="color: #CC6600;">for</span>(<span style="color: #CC6600;">int</span> x = 0; x<dataPosition; x++){<br /> <span style="color: #CC6600;">if</span>(mp3.<span style="color: #CC6600;">available</span>()){<br /> returnVal = mp3.<span style="color: #CC6600;">read</span>();<br /> <span style="color: #CC6600;">delay</span>(50);<br /> }<br /> }<br /> <span style="color: #CC6600;">return</span>(returnVal);<br />}<br /><br /><span style="color: #CC6600;">byte</span> getVolume(){ <span style="color: #7E7E7E;">//Get the volume of the Grove Serial MP3 player</span><br /> <span style="color: #7E7E7E;">//returns value from 0 - 31</span><br /> <span style="color: #CC6600;">return</span>(getData(0xC1, 4));<br />}<br /><br /><span style="color: #CC6600;">byte</span> getPlayingState(){ <span style="color: #7E7E7E;">//Get the playing state : Play / Stopped / Paused</span><br /> <span style="color: #7E7E7E;">//returns 1: Play, 2: Stop, 3:Paused</span><br /> <span style="color: #CC6600;">return</span>(getData(0xC2, 2));<br />}<br /><br /><br /><span style="color: #CC6600;">byte</span> getNumberOfFiles(){ <span style="color: #7E7E7E;">//Find out how many songs are on the SD card</span><br /> <span style="color: #7E7E7E;">//returns the number of MP3 files on SD card</span><br /> <span style="color: #CC6600;">return</span>(getData(0xC4, 3));<br />}<br /> <!-- End of Arduino Code --><br /> </pre> </td> </tr> </table></div></P> <P> <!-- Arduino Code Discussion --> <div style="text-align: justify;"> You will notice from the code, that I did not utilise every function. I decided to include them for your benifit. This Serial MP3 module makes use of a high quality MP3 audio chip known as the "WT5001". Therefore, you should be able to get some additional features and functionality from <a href="http://goo.gl/ai6oQ9">this document</a>. Plus you may find some extra useful info from <a href="http://goo.gl/xOiSCl">the Seeedstudio wiki</a>. <BR /> <BR> <span style="color: red;">IMPORTANT:</span> You need to load your MP3 sounds or songs onto the SDHC card before you install it onto the Serial MP3 player. <BR /> <BR> Once the SDHC card is installed, and your code is uploaded to the Arduino, all you have to do now is connect the MP3 player to some headphones or a powered speaker. You can then power the Arduino and modules with a battery pack or some other portable power supply. <BR /> <BR> You can design and decorate the shoebox in any way you like. Just print out your picture, glue them on, and before you know it, you will have your very own Arduino Boombox. <BR /> <BR> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOcK652zdFApfU3G7HZua5h-YQK0pxCm-qsH99i0Uooxyww5Ih3_CxEqROgFTdM2EN6HC-6QQACDo-Wv4VAB2xWL8ThDf5CSzFjXfJJHI4f5UkRN-0y7uGqLYRFUlQ3rO9sJQYe0F5LWU/s1600/BoomBox.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOcK652zdFApfU3G7HZua5h-YQK0pxCm-qsH99i0Uooxyww5Ih3_CxEqROgFTdM2EN6HC-6QQACDo-Wv4VAB2xWL8ThDf5CSzFjXfJJHI4f5UkRN-0y7uGqLYRFUlQ3rO9sJQYe0F5LWU/s1600/BoomBox.png" height="226" width="400" /> </a> </div> </div> </P></div><!--separator --><img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /><P> <div style="text-align: justify;"> <!-- Concluding Comments --> <h4>Comments</h4> <P>I was very surprised by the quality of the sound that came from the MP3 module. It is actually quite good. </P> <P> This tutorial was an introduction to the Grove Serial MP3 module in it's most basic form. You could just as easily use some other sensor to trigger the MP3 module. For example, you could get it to play an alert if a water leak was detected, or if a door was opened, or if the temperature got too high or too low. You could get it to play a reminder when you walk into your room. The possibilities are endless.</P> <P>I really liked this module, and I am sure it will appear in a future tutorial. </P> <BR /> <BR> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh211j7YFt1LoG5_9Eoqcd3UL9QDvCyz8avTnYpjM2x3xZykWeE9P2SkC6biBOW6jIHJXcD8vIpdz88AabqHfWpe9gFsaMoLzWld252T4Bhk73mC7Ej7EaAqbbr1y54qG5YPpPSazd3Tv0/s1600/Bear+Boombox.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh211j7YFt1LoG5_9Eoqcd3UL9QDvCyz8avTnYpjM2x3xZykWeE9P2SkC6biBOW6jIHJXcD8vIpdz88AabqHfWpe9gFsaMoLzWld252T4Bhk73mC7Ej7EaAqbbr1y54qG5YPpPSazd3Tv0/s1600/Bear+Boombox.jpg" height="300" width="400" /> </a> </div><br /> </div> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> <div align="center"> If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br> <BR /> <BR /> Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br> Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br> I can also be found on <a href="https://www.pinterest.com/ArduinoBasics/">Pinterest</a> and <a href="https://instagram.com/arduinobasics">Instagram</a>. <br> Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.<br> </div> </P> <BR /> <BR /> <div align="center"> <div class="separator" style="clear: both; text-align: center;"> <a href="http://arduino.cc/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmuBeqll5_-ovWlmf5ncMAWNxQ05r_dYIb_ezswWonrTzqnBW1y3YiN4dFUImKVLrFfilGIPMMg5mMfHItxdei6Kqs4o9pvZsg3sucWXSUR5Lm-MDx3nhDHu_9oaZIKeFGLANQoz4Ge8c/s1600/ArduinoLogo.png" /></a> </div> </div> <BR /> <BR /> <BR /> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> However, if you do not have a google profile... <br>Feel free to share this page with your friends in any way you see fit. </P></P></P><br /><br /><br /><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" -->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-1467512340238682192015-02-27T23:10:00.000-08:002016-03-19T10:53:41.154-07:00Weather Reporter - Temboo, Ethernet and Arduino<P style="clear:both;"><div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFUvGEcWSy5hGEN8DM9eS05U3rWL0waP_jnr3MLnm_ry-cap-iPUYu9udq_QuZEJ4qpu8vcoL4qlxYhbuie5lnCoZ37ge7-wfFUeEejd4aaat18feWXhv9_5gRBIQzBwc3ivOdlQfdjag/s1600/Header_Image.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFUvGEcWSy5hGEN8DM9eS05U3rWL0waP_jnr3MLnm_ry-cap-iPUYu9udq_QuZEJ4qpu8vcoL4qlxYhbuie5lnCoZ37ge7-wfFUeEejd4aaat18feWXhv9_5gRBIQzBwc3ivOdlQfdjag/s640/Header_Image.jpg" /> </a></div> </P><br> <P style="clear:both;"> <div style="text-align: justify;"> Arduino is well known for the large variety of sensors / modules that can be connected. It is quite easy to hook up a temperature or humidity sensor to get instant feedback about the surrounding environmental conditions. However, sometimes you do not have a temperature sensor. Sometimes you have a sensor, but would like to know the temperature in other cities ! Or you would like to know what the temperature will be tomorrow? </div></P><P> <div style="text-align: center;"> <span style="font-size: large;">Well now you can !!</span></BR> </div></P><P> <div style="text-align: justify;"> All you need is a Temboo account, an internet connection and the following components: </div></P><P> <h4>Parts Required</h4> <ul> <li><a href="http://www.epictinker.com/Freetronics-Eleven-100-Arduino-Uno-Compatible-p/ard-1002.htm">2 x Arduino UNO (or compatible board)</a></li> <li><a href="http://www.epictinker.com/W5200-Ethernet-Shield-p/sld91000p.htm">Ethernet Shield</a></li> <li><a href="http://www.epictinker.com/1-8-inch-TFT-LCD-Module-p/it-db021.8sp.htm">ITDB02-1.8SP TFT LCD Module</a></li> <li><a href="http://www.epictinker.com/Solderless-Breadboard-Jumper-Wire-Kit-p/cab-1008.htm">Solderless Breadboard Jumper wires</a></li> <li><a href="http://www.epictinker.com/Mini-Breadboard-4-5cmx3-5cm-p/str122c2m.htm">Mini Breadboard 4.5cm x 3.5cm</a></li> <li><a href="http://www.epictinker.com/Freetronics-ProtoShield-Basic-for-Arduino-p/ard-1011.htm">Protoshield </a></li> </ul></P><br> <br> <P> <h4>Project Description</h4> <br> <div style="text-align: justify;"> An Arduino UNO (and Ethernet Shield) queries Yahoo using a Temboo account, and retrieves weather information. The data is filtered and processed, and then passed on to another Arduino UNO to be displayed on a TFT LCD module. Two Arduino UNOs are used because the Ethernet library and the UTFT library are both memory hungry, and together consume more memory than one Arduino UNO can handle. </br> Yes - I could have used a different board such as the Arduino MEGA, but where is the fun in that ??</br> This project will teach you many things: <ul> <li>How to use an Ethernet Shield with a Temboo account to retrieve internet data</li> <li>How to use a TFT LCD module (ITDB02-1.8SP)</li> <li>How to reduce memory consumption when using the UTFT library</li> <li>How to power two Arduinos with a single USB cable</li> <li>How to transmit data from one Arduino to another (via jumper wires)</li> </ul> All of this and a whole lot more !! </div></P><br> <br> <P style="clear:both;"> <h4>Video</h4> <div style="text-align: justify;"> Have a look at the following video to see the project in action. <br> <br> <iframe width="640" height="480" src="https://www.youtube.com/embed/tyAj9Z0fr1U" frameborder="0" allowfullscreen></iframe></br> </div></P><P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /></P><br>You will need to create a Temboo account to run this project: <P> <div style="text-align: justify;"> <P style="clear:both;"> <h4>Temboo Account Creation</h4></br> <h3>Step 1:</h3> Visit the Temboo website : <a href="https://www.temboo.com/">https://www.temboo.com/ </a></br> Create an account by entering a valid email address. </br> Then click on the Sign Up button.</BR> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://www.temboo.com/" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJ9tkUovtn9yBSlNRJRoQyn-RUGtdYlSIlygDlQiuMeaEUVQTLLquvw4I1yGs-ogVl7TUAIWwXEdkidceViQiBwXYmfIucvVKj_s5hDpnsGJt3BJhGL7Kl4wm0DlG1LPnd8wT_A40T2k0/s1600/1_Sign_up.jpg" height="121" width="320" /></a> </div> </P> </P> <br> <P style="clear:both;"> </br> <h3>Step 2:</h3> Verify your email address by clicking on the link provided in the email sent by Temboo.</br> </P> <br> <P style="clear:both;"> <h3>Step 3:</h3> You will be directed to the account setup page:</br> Create an Account Name, and Password for future access to your Temboo Account </br> Check the terms of service and if you agree, then tick the box </br> Press the Go! button <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh56DBW58eX20Y-SfRzvISZpkSCb0j46CWamWVG3-VuTUKsWnMQFqgwZEBkgIm4p_A89LlBsWPxoC5crnmiruLhdLC2oaKjc67C02wOIppxEngamRExdwDrS1DCrYP4jsEgYZDibwZ2jGU/s1600/3_Account_Details.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh56DBW58eX20Y-SfRzvISZpkSCb0j46CWamWVG3-VuTUKsWnMQFqgwZEBkgIm4p_A89LlBsWPxoC5crnmiruLhdLC2oaKjc67C02wOIppxEngamRExdwDrS1DCrYP4jsEgYZDibwZ2jGU/s1600/3_Account_Details.jpg" height="320" width="255" /> </a> </div> </P> </P> <br> <P style="clear:both;"> <br> <h3>Step 4:</h3> You will then encounter the "Welcome!" screen: </br> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpHD80ao44i3XUV8H3ZMq4Yj4wXKQojH_aAWC7CtlTGLFmRSwGoNEFO_Mny1b1axOC6WL5Wn0U0h4CVXraiuFTpshZ1SbIvfdGVNNE8DTTKlNlV12TDPnKEnKjeY5eV6OeXv6KLez4A4E/s1600/4_Welcome_page.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpHD80ao44i3XUV8H3ZMq4Yj4wXKQojH_aAWC7CtlTGLFmRSwGoNEFO_Mny1b1axOC6WL5Wn0U0h4CVXraiuFTpshZ1SbIvfdGVNNE8DTTKlNlV12TDPnKEnKjeY5eV6OeXv6KLez4A4E/s400/4_Welcome_page.jpg" /> </a> </div> </P> </P> <br> <P style="clear:both;"> <br> <h3>Step 5:</h3> Navigate to the top right of the screen and select the <a href="https://temboo.com/library/">LIBRARY tab </a> </br> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://temboo.com/library/" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJBhg3GWujmPz-6FxvZbT62Yx1foWjL_A2BKTDKRsaG5KpRXlERwkEAEi4UxL8wVImLHPXLVhymw0k5KrW45uWIkhF6F5OSUKEAvnFFXxnh34P8Q7cNFhO0LFLXjbBVlvdFTT1jH1gYfA/s1600/8_Choreo+LIBRARY+Tab.jpg" /> </a> </div> </P> </P> <br> <P style="clear:both;"> <br> <h3>Step 6:</h3> On the left hand side you will see a list of choreos.</br> Type Yahoo into the search box on the top left of the screen.</br> Navigate to the <a href="https://temboo.com/library/Library/Yahoo/Weather/GetWeatherByAddress/">GetWeatherByAddress Choreo</a> by clicking on...</br> Yahoo _ Weather _ GetWeatherByAddress </br> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://temboo.com/library/Library/Yahoo/Weather/GetWeatherByAddress/" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsZe9Ej041XZmnTlHzTeBTxk7kYEoekrOo2SmpYN2NLu4coP0K4vL1mceLqjrGx-qdyLZrhZR8ajOcESXD3YnJDL3_UAvX01Jtb05X0_0AKz23ihbnEdJLS63ubhbrVBAr3YO74DnNZOM/s1600/11_Temboo+Choreo+Yahoo+Weather+Options2.jpg" /> </a> </div> </P> </P> <br> <P style="clear:both;"> <br> <h3>Step 7:</h3> Turn the IoT Mode to ON (in the top right of screen) </br> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixKjwd8HOjCQh0-BUykI0PTERezoZUi1rkWl4hCsK6BRcePH3l9mHKL1EMAY_q3LGoaIKc1JcYOMzttliDJAiImXKEYmobmRKO_Ro4BNjEp8LgmggXqShzNpfOD0wuJYwOL8h_cJu6T5c/s1600/Temboo+Turn+IoT+ON.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixKjwd8HOjCQh0-BUykI0PTERezoZUi1rkWl4hCsK6BRcePH3l9mHKL1EMAY_q3LGoaIKc1JcYOMzttliDJAiImXKEYmobmRKO_Ro4BNjEp8LgmggXqShzNpfOD0wuJYwOL8h_cJu6T5c/s400/Temboo+Turn+IoT+ON.jpg" /> </a> </div> </P> </P> <br> <P style="clear:both;"> <br> <h3>Step 8:</h3> <b>What's your platform / device? :</b> Arduino </br> <b>How is it connected? :</b> Arduino Ethernet </br> </br> The following popup box will appear: </br> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKCcbR5NpHALIDdSC93IkaaWHAL_igkQ97xbShDWjSA66y79SX_uWZFQDsSR8Sm1EFPZkIrzGdXGeSlnxJHnmpkdmFiWuvd8HtknTZQBUAobI1r79HwI8Os9BcHZmGMswEtCaSZQsqw5o/s1600/12_How+is+it+connected+dialog+box+for+Ethernet+shield.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKCcbR5NpHALIDdSC93IkaaWHAL_igkQ97xbShDWjSA66y79SX_uWZFQDsSR8Sm1EFPZkIrzGdXGeSlnxJHnmpkdmFiWuvd8HtknTZQBUAobI1r79HwI8Os9BcHZmGMswEtCaSZQsqw5o/s1600/12_How+is+it+connected+dialog+box+for+Ethernet+shield.jpg" /> </a> </div> </P> </P> <br> <P style="clear:both;"> <br> <h3>Step 9:</h3> <b>Name:</b> EthernetShield - you can choose any name. Letters and numbers only. No spaces. </br> <b>Shield Type:</b> Arduino Ethernet </br> <b>MAC Address :</b> You can normally find the MAC address of the Ethernet shield on the underside. </br> Enter the MAC address without the hyphens. Then click SAVE. </br> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBgKKXc_MbKlu2RdNUKH6Sq2UfiqsmR1pOciLDuWbvcWWIpjsaP4Dn9-bs0TAWr14QvcsDB6Af1rMhUv_Mgq1EbVcr8xUB9xlr99YR5iBqknFk2Ay5pYnzT5iVt7VTTTVTu5hUuPyYYWs/s1600/Ethernet+MAC.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBgKKXc_MbKlu2RdNUKH6Sq2UfiqsmR1pOciLDuWbvcWWIpjsaP4Dn9-bs0TAWr14QvcsDB6Af1rMhUv_Mgq1EbVcr8xUB9xlr99YR5iBqknFk2Ay5pYnzT5iVt7VTTTVTu5hUuPyYYWs/s400/Ethernet+MAC.JPG" /> </a> </div> </P> </P> <br> <P style="clear:both;"> <br> <h3>Step 10:</h3> Move to the INPUT section. </br> Enter the Address of the place you want the Temperature for. </br> <b>Address</b> = Perth, Western Australia </br> Expand the Optional INPUT for extra functionality </br> <b>Units</b> = c - If you want the temperature in Celcius. </br> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF36T3FyT4AWokTsjyEGDY4R1TeQJzqztO00Eh47KbBSSd1K6zPKx29keLn4BqRh9DnQ3GgzlL4_xgrX_r0Mfz77tVlDFAmick1DWIkYuaydQVZ0qN5HtzDJ6LDym8G1WUPR_YrLeObOI/s1600/14_Choreo+INPUT+expanded+for+Celcius.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF36T3FyT4AWokTsjyEGDY4R1TeQJzqztO00Eh47KbBSSd1K6zPKx29keLn4BqRh9DnQ3GgzlL4_xgrX_r0Mfz77tVlDFAmick1DWIkYuaydQVZ0qN5HtzDJ6LDym8G1WUPR_YrLeObOI/s400/14_Choreo+INPUT+expanded+for+Celcius.jpg" /> </a> </div> </P> </P> <br> <P style="clear:both;"> <br> <h3>Step 11:</h3> This will automatically generate some Arduino CODE and a HEADER FILE. </br> Don't worry about the Arduino code for now... because I will provide that for you. </br> However, you will need the automatically generated HEADER file. I will show you what to do with that soon. </br> So don't lose it !' </br> <P> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6JTOMH2dHZQZ7zZaUCgD_g0C61okUd75RuVV-IfnR3w5-11PEkf3Ojp67_fHe7T9yiERj6jnZ8990nWiazbFeOp8WcJLX9QStR_cfj7PmNoyjwMAbyjWR8jQK52pYTkpL1zRN0U34Hyo/s1600/17_Header+File+provided.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6JTOMH2dHZQZ7zZaUCgD_g0C61okUd75RuVV-IfnR3w5-11PEkf3Ojp67_fHe7T9yiERj6jnZ8990nWiazbFeOp8WcJLX9QStR_cfj7PmNoyjwMAbyjWR8jQK52pYTkpL1zRN0U34Hyo/s1600/17_Header+File+provided.jpg" /> </a> </div> </P> </P> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> <P> <h4>Temboo Library Install</h4> The Temboo library will need to be installed before you copy the Arduino code in the sections below. </br> To install the Temboo library into your Arduino IDE, please follow the link to their instructions: </br> <a href="https://temboo.com/arduino/others/library-installation">Installing the Temboo Arduino Library</a></br> </P> </br> </br> <P> <h4>UTFT Library Install</h4> Download the UTFT library from this site: <a href="http://www.henningkarlsen.com/electronics/library.php?id=51"> http://www.henningkarlsen.com/electronics/library.php?id=51</a> </br> Once downloaded and extracted. Go into the UTFT folder and look for the <b>memorysaver.h</b> file. Open this file in a text editor, and "uncomment" all of the TFT modules that are not relevant to this project. I disabled all of the TFT modules except the last 3 (which made reference to ST7735) - see picture below. The TFT module we are using in this project is the ITDB02-1.8SP from ITEAD Studio. </br> Save the memorysaver.h file, and then IMPORT the library into the Arduino IDE as per the normal library import procedure. </br> </br> <b>If you do not modify the memorysaver.h file, the Arduino SLAVE sketch will not compile.</b> </P> <P style="clear:both;"> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfqWg-kdMacdZocAnOkule8Htmd_Ng2anA6waBGdXLkEsF4hLQGJl0R2bpFsxq3M5_Nf7XCueQYt40RRg4e_pa8Z4-2DuC2PtvkIo1RrwIGB41SXYCg4IeseOTGOITpc7X6nhGteKpplE/s1600/MemorySaver.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfqWg-kdMacdZocAnOkule8Htmd_Ng2anA6waBGdXLkEsF4hLQGJl0R2bpFsxq3M5_Nf7XCueQYt40RRg4e_pa8Z4-2DuC2PtvkIo1RrwIGB41SXYCg4IeseOTGOITpc7X6nhGteKpplE/s640/MemorySaver.jpg" /> </a> </div> </P> <P style="clear:both;"> </br> </br> <h4>Arduino Code (MASTER)</h4> </br> This project uses 2 Arduino UNOs.</br> One will be the Master, and one will be the Slave. </br> The following code is for the Arduino MASTER. </br> </br> Open up the Arduino IDE. </br> (I am using Arduino IDE version 1.6) </br> Paste the following code into the Arduino IDE code window. </br> </br> <b>PLEASE NOTE:</b> You may need to change some of the lines to accomodate your INPUTS from step 10. </br> Have a look around line 36 and 37.</br> <br> <div style="background: #ffffff; color: #000000; overflow:auto;width:auto;border:solid rgb(24,186,183);border-width: .6em .3em .3em .3em;padding: 0em 0em;"> <table> <tr> <td> <pre style="margin: 0; line-height: 125%; background: rgb(24,186,183); width: 1.9em"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br /> 10<br /> 11<br /> 12<br /> 13<br /> 14<br /> 15<br /> 16<br /> 17<br /> 18<br /> 19<br /> 20<br /> 21<br /> 22<br /> 23<br /> 24<br /> 25<br /> 26<br /> 27<br /> 28<br /> 29<br /> 30<br /> 31<br /> 32<br /> 33<br /> 34<br /> 35<br /> 36<br /> 37<br /> 38<br /> 39<br /> 40<br /> 41<br /> 42<br /> 43<br /> 44<br /> 45<br /> 46<br /> 47<br /> 48<br /> 49<br /> 50<br /> 51<br /> 52<br /> 53<br /> 54<br /> 55<br /> 56<br /> 57<br /> 58<br /> 59<br /> 60<br /> 61<br /> 62<br /> 63<br /> 64<br /> 65<br /> 66<br /> 67<br /> 68<br /> 69<br /> 70<br /> 71<br /> 72<br /> 73<br /> 74<br /> 75<br /> 76<br /> 77<br /> 78<br /> 79<br /> 80<br /> 81<br /> 82<br /> 83<br /> 84<br /> 85<br /> 86<br /> 87<br /> 88<br /> 89<br /> 90<br /> 91<br /> 92<br /> 93<br /> 94<br /> 95<br /> 96<br /> 97<br /> 98<br /> 99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br /> </pre> </td> <td> <pre style="margin: 0; line-height: 125%"><br /> <!-- INSERT ARDUINO CODE HERE --><br /><span style="color: #7E7E7E;">/* ===============================================================================</span><br /><span style="color: #7E7E7E;"> Project: Weather Reporter: Temboo, Ethernet, Arduino</span><br /><span style="color: #7E7E7E;"> Title: ARDUINO MASTER: Get temperature from Yahoo using Temboo</span><br /><span style="color: #7E7E7E;"> Author: Scott C</span><br /><span style="color: #7E7E7E;"> Created: 27th February 2015</span><br /><span style="color: #7E7E7E;"> Arduino IDE: 1.6.0</span><br /><span style="color: #7E7E7E;"> Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html</span><br /><span style="color: #7E7E7E;"> Description: The following sketch was designed for the Arduino MASTER device. </span><br /><span style="color: #7E7E7E;"> It will retrieve temperature/weather information from Yahoo using your</span><br /><span style="color: #7E7E7E;"> Temboo account (https://www.temboo.com/), which will then be sent to the</span><br /><span style="color: #7E7E7E;"> Arduino Slave device to be displayed on a TFT LCD module.</span><br /><span style="color: #7E7E7E;"> </span><br /><span style="color: #7E7E7E;"> Libraries : Ethernet Library (that comes with Arduino IDE)</span><br /><span style="color: #7E7E7E;"> Temboo Arduino Library - https://www.temboo.com/sdk/arduino</span><br /><span style="color: #7E7E7E;"> </span><br /><span style="color: #7E7E7E;"> Temboo Library installation instructions for Arduino: </span><br /><span style="color: #7E7E7E;"> https://www.temboo.com/arduino/others/library-installation</span><br /><br /><span style="color: #7E7E7E;"> You will also need to copy your Temboo Account information into a new tab and call it TembooAccount.h.</span><br /><span style="color: #7E7E7E;"> Please follow the instructions on the ArduinoBasics blog for more information.</span><br /><span style="color: #7E7E7E;">---------------------------------------------------------------------------------- */</span><br /><br />#include <<span style="color: #CC6600;">SPI</span>.h><br />#include <Dhcp.h><br />#include <Dns.h><br />#include <<span style="color: #CC6600;">Ethernet</span>.h><br />#include <<span style="color: #CC6600;">EthernetClient</span>.h><br />#include <<span style="color: #CC6600;"><b>Temboo</b></span>.h><br />#include <span style="color: #006699;">"TembooAccount.h"</span> <span style="color: #7E7E7E;">// Contains Temboo account information - in a new tab.</span><br />#include <<span style="color: #CC6600;">Wire</span>.h><br /><br /><span style="color: #CC6600;">byte</span> ethernetMACAddress[] = ETHERNET_SHIELD_MAC; <span style="color: #7E7E7E;">//ETHERNET_SHIELD_MAC variable located in TembooAccount.h</span><br /><span style="color: #CC6600;">EthernetClient</span> client;<br /><br /><span style="color: #CC6600;">String</span> Address = <span style="color: #006699;">"Perth, Western Australia"</span>; <span style="color: #7E7E7E;">// Find temperature for Perth, Western Australia</span><br /><span style="color: #CC6600;">String</span> Units = <span style="color: #006699;">"c"</span>; <span style="color: #7E7E7E;">// Display the temperature in degrees Celcius</span><br /><br /><span style="color: #CC6600;">String</span> ForeCastDay[7]; <span style="color: #7E7E7E;">//String Array to hold the day of the week </span><br /><span style="color: #CC6600;">String</span> ForeCastTemp[7]; <span style="color: #7E7E7E;">//String Array to hold the temperature for that day of week.</span><br /><br /><span style="color: #CC6600;">int</span> counter1=0; <span style="color: #7E7E7E;">//Counters used in FOR-LOOPS.</span><br /><span style="color: #CC6600;">int</span> counter2=0;<br /><br /><span style="color: #CC6600;">boolean</span> downloadTemp = <span style="color: #CC6600;">true</span>; <span style="color: #7E7E7E;">// A boolean variable which controls when to query Yahoo for Temperature information.</span><br /><br /><br /><br /><span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>setup</b></span>() {<br /> <span style="color: #CC6600;">Wire</span>.<span style="color: #CC6600;">begin</span>(); <span style="color: #7E7E7E;">// join i2c bus : Used to communicate to the Arduino SLAVE device. </span><br /> <br /> <span style="color: #7E7E7E;">// Ethernet shield must initialise properly to continue with sketch.</span><br /> <span style="color: #CC6600;">if</span> (<span style="color: #CC6600;">Ethernet</span>.<span style="color: #CC6600;">begin</span>(ethernetMACAddress) == 0) {<br /> <span style="color: #CC6600;">while</span>(<span style="color: #CC6600;">true</span>);<br /> }<br /> <br /> <span style="color: #7E7E7E;">//Provide some time to get both Arduino's ready for Temperature Query.</span><br /> <span style="color: #CC6600;">delay</span>(2000);<br />}<br /><br /><br /><br /><br /><span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>loop</b></span>() {<br /> <span style="color: #CC6600;">if</span> (downloadTemp) {<br /> downloadTemp=<span style="color: #CC6600;">false</span>; <span style="color: #7E7E7E;">//Stop Arduino from Querying Temboo repeatedly</span><br /> getTemperature(); <span style="color: #7E7E7E;">//Retrieve Temperature data from Yahoo</span><br /> transmitResults(); <span style="color: #7E7E7E;">//Transmit the temperature results to the Slave Arduino</span><br /> }<br />}<br /><br /><br /><br /><br /><span style="color: #7E7E7E;">/* This function will Query Yahoo for Temperature information (using a Temboo account) */</span><br /><br /><span style="color: #CC6600;">void</span> getTemperature(){<br /> <span style="color: #CC6600;">TembooChoreo</span> GetWeatherByAddressChoreo(client);<br /><br /> <span style="color: #7E7E7E;">// Invoke the Temboo client</span><br /> GetWeatherByAddressChoreo.<span style="color: #CC6600;">begin</span>();<br /><br /> <span style="color: #7E7E7E;">// Set Temboo account credentials</span><br /> GetWeatherByAddressChoreo.<span style="color: #CC6600;">setAccountName</span>(TEMBOO_ACCOUNT); <span style="color: #7E7E7E;">//TEMBOO_ACCOUNT variable can be found in TembooAccount.h file or tab</span><br /> GetWeatherByAddressChoreo.<span style="color: #CC6600;">setAppKeyName</span>(TEMBOO_APP_KEY_NAME); <span style="color: #7E7E7E;">//TEMBOO_APP_KEY_NAME variable can be found in TembooAccount.h file or tab</span><br /> GetWeatherByAddressChoreo.<span style="color: #CC6600;">setAppKey</span>(TEMBOO_APP_KEY); <span style="color: #7E7E7E;">//TEMBOO_APP_KEY variable can be found in TembooAccount.h file or tab</span><br /><br /> <span style="color: #7E7E7E;">// Set Choreo inputs</span><br /> GetWeatherByAddressChoreo.<span style="color: #CC6600;">addInput</span>(<span style="color: #006699;">"Units"</span>, Units); <span style="color: #7E7E7E;">// Set the Units to Celcius</span><br /> GetWeatherByAddressChoreo.<span style="color: #CC6600;">addInput</span>(<span style="color: #006699;">"Address"</span>, Address); <span style="color: #7E7E7E;">// Set the Weather Location to Perth, Western Australia</span><br /><br /> <span style="color: #7E7E7E;">// Identify the Choreo to run</span><br /> GetWeatherByAddressChoreo.<span style="color: #CC6600;">setChoreo</span>(<span style="color: #006699;">"/Library/Yahoo/Weather/GetWeatherByAddress"</span>);<br /><br /> <span style="color: #7E7E7E;">// This output filter will extract the expected temperature for today</span><br /> GetWeatherByAddressChoreo.<span style="color: #CC6600;">addOutputFilter</span>(<span style="color: #006699;">"Temperature"</span>, <span style="color: #006699;">"/rss/channel/item/yweather:condition/@temp"</span>, <span style="color: #006699;">"Response"</span>);<br /> <br /> <span style="color: #7E7E7E;">// These output filters will extract the forecasted temperatures (we need to know the day and temperature for that day)</span><br /> GetWeatherByAddressChoreo.<span style="color: #CC6600;">addOutputFilter</span>(<span style="color: #006699;">"ForeCastDay"</span>, <span style="color: #006699;">"/rss/channel/item/yweather:forecast/@day"</span>, <span style="color: #006699;">"Response"</span>);<br /> GetWeatherByAddressChoreo.<span style="color: #CC6600;">addOutputFilter</span>(<span style="color: #006699;">"ForeCastHigh"</span>, <span style="color: #006699;">"/rss/channel/item/yweather:forecast/@high"</span>, <span style="color: #006699;">"Response"</span>);<br /><br /> <span style="color: #7E7E7E;">// Run the Choreo; </span><br /> GetWeatherByAddressChoreo.<span style="color: #CC6600;">run</span>();<br /><br /> <span style="color: #7E7E7E;">//Reset our counters before proceeding</span><br /> counter1 = 0;<br /> counter2 = 0;<br /> <br /> <span style="color: #CC6600;">while</span>(GetWeatherByAddressChoreo.<span style="color: #CC6600;">available</span>()) {<br /> <span style="color: #7E7E7E;">// This will get the first part of the output</span><br /> <span style="color: #CC6600;">String</span> <span style="color: #CC6600;">name</span> = GetWeatherByAddressChoreo.<span style="color: #CC6600;">readStringUntil</span>(<span style="color: #006699;">'\x1F'</span>);<br /> <span style="color: #CC6600;">name</span>.<span style="color: #CC6600;">trim</span>(); <span style="color: #7E7E7E;">// get rid of newlines</span><br /><br /> <span style="color: #7E7E7E;">// This will get the second part of the output</span><br /> <span style="color: #CC6600;">String</span> data = GetWeatherByAddressChoreo.<span style="color: #CC6600;">readStringUntil</span>(<span style="color: #006699;">'\x1E'</span>);<br /> data.<span style="color: #CC6600;">trim</span>(); <span style="color: #7E7E7E;">// get rid of newlines</span><br /><br /> <span style="color: #7E7E7E;">//Fill the String Arrays with the Temperature/Weather data</span><br /> <span style="color: #CC6600;">if</span> (<span style="color: #CC6600;">name</span> == <span style="color: #006699;">"Temperature"</span>) {<br /> ForeCastDay[counter1] = <span style="color: #006699;">"Today"</span>;<br /> ForeCastTemp[counter2] = data;<br /> counter1++;<br /> counter2++;<br /> }<br /> <br /> <span style="color: #CC6600;">if</span>(<span style="color: #CC6600;">name</span>==<span style="color: #006699;">"ForeCastDay"</span>){<br /> ForeCastDay[counter1] = data;<br /> counter1++;<br /> }<br /> <br /> <span style="color: #CC6600;">if</span>(<span style="color: #CC6600;">name</span>==<span style="color: #006699;">"ForeCastHigh"</span>){<br /> ForeCastTemp[counter2] = data;<br /> counter2++;<br /> }<br /> }<br /> <br /> <span style="color: #7E7E7E;">//Close the connection to Temboo website</span><br /> GetWeatherByAddressChoreo.<span style="color: #CC6600;">close</span>();<br /> }<br /> <br /> <br /> <br /> <br /> <span style="color: #7E7E7E;">/* This function is used to transmit the temperature data to the Slave Arduino */</span><br /> <br /> <span style="color: #CC6600;">void</span> transmitResults(){<br /> <span style="color: #CC6600;">char</span> tempData[10];<br /> <span style="color: #CC6600;">int</span> tempStringLength = 0;<br /> <br /> <span style="color: #7E7E7E;">//Modify the current temp to "Now"</span><br /> ForeCastDay[0] = <span style="color: #006699;">"Now"</span>;<br /> <br /> <span style="color: #7E7E7E;">//Send * to Slave Arduino to prepare for Temperature Transmission</span><br /> <span style="color: #CC6600;">Wire</span>.<span style="color: #CC6600;">beginTransmission</span>(4); <span style="color: #7E7E7E;">// Transmit to device #4 (Slave Arduino)</span><br /> <span style="color: #CC6600;">Wire</span>.<span style="color: #CC6600;">write</span>(<span style="color: #006699;">"*"</span>);<br /> <span style="color: #CC6600;">delay</span>(500);<br /> <span style="color: #CC6600;">Wire</span>.<span style="color: #CC6600;">endTransmission</span>();<br /> <span style="color: #CC6600;">delay</span>(500);<br /> <br /> <span style="color: #7E7E7E;">//Send the temperatures on the Slave Arduino to be displayed on the TFT module.</span><br /> <span style="color: #CC6600;">for</span> (<span style="color: #CC6600;">int</span> j=0; j<20; j++){<br /> <span style="color: #CC6600;">for</span> (<span style="color: #CC6600;">int</span> i=0; i<6; i++){<br /> memset(tempData,0,sizeof(tempData)); <span style="color: #7E7E7E;">//Clear the character array</span><br /> <span style="color: #CC6600;">String</span> tempString = <span style="color: #CC6600;">String</span>(ForeCastDay[i] + <span style="color: #006699;">","</span> + ForeCastTemp[i] + <span style="color: #006699;">"."</span>);<br /> tempStringLength = tempString.<span style="color: #CC6600;">length</span>();<br /> tempString.<span style="color: #CC6600;">toCharArray</span>(tempData, tempStringLength+1);<br /> <span style="color: #CC6600;">Wire</span>.<span style="color: #CC6600;">beginTransmission</span>(4); <span style="color: #7E7E7E;">// Transmit to device #4 (Slave Arduino)</span><br /> <span style="color: #CC6600;">Wire</span>.<span style="color: #CC6600;">write</span>(tempData);<br /> <span style="color: #CC6600;">delay</span>(1000);<br /> <span style="color: #CC6600;">Wire</span>.<span style="color: #CC6600;">endTransmission</span>();<br /> <span style="color: #CC6600;">delay</span>(4000);<br /> }<br /> }<br /> <br /> <span style="color: #7E7E7E;">/* ----------------------------------------------------------------------</span><br /><span style="color: #7E7E7E;"> // You can use this to send temperature results to the Serial Monitor.</span><br /><span style="color: #7E7E7E;"> // However, you will need a Serial.begin(9600); statement in setup().</span><br /><span style="color: #7E7E7E;"> </span><br /><span style="color: #7E7E7E;"> Serial.println("The Current Temperature is " + ForeCastTemp[5] + " C");</span><br /><span style="color: #7E7E7E;"> Serial.println();</span><br /><span style="color: #7E7E7E;"> Serial.println("The Expected Temperature for");</span><br /><span style="color: #7E7E7E;"> for (int i=0; i<5; i++){</span><br /><span style="color: #7E7E7E;"> Serial.println(ForeCastDay[i] + " : " + ForeCastTemp[i] + " C");</span><br /><span style="color: #7E7E7E;"> }</span><br /><span style="color: #7E7E7E;"> ---------------------------------------------------------- */</span><br /> }<br /> <br /> <!-- End of Arduino Code --><br /> </pre> </td> </tr> </table></div> <br> <br> <br> Select "New Tab" from the drop-down menu on the top right of the IDE. </br> <b>Name the file:</b> TembooAccount.h <P style="clear:both;"> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMtizat3rc0HkaFGwN3OR2sLY9colv1AtUtyFv-Ldk8JStvVtgbT6TXjf_UjhWe9jCXC1LL8TnKnecox17qYJDWDa1ajFcHbDY7p_8FmNfHaj0IJIIvizTB9fbaxKLco1NFD5-H70uL1w/s1600/ArduinoIDE_NewTab.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMtizat3rc0HkaFGwN3OR2sLY9colv1AtUtyFv-Ldk8JStvVtgbT6TXjf_UjhWe9jCXC1LL8TnKnecox17qYJDWDa1ajFcHbDY7p_8FmNfHaj0IJIIvizTB9fbaxKLco1NFD5-H70uL1w/s1600/ArduinoIDE_NewTab.jpg" /> </a> </div> </P> <P style="clear:both;"> Paste the contents of the HEADER file from the Temboo webpage (Step 11 above) into the TembooAccount.h tab. If you do not have the TembooAccount.h tab with the contents of this HEADER file next to your Arduino Master sketch, then it will NOT work.</br> <br> Make sure to SAVE the Arduino Sketch and upload the code to the Arduino (MASTER) </P> </br> </br> <P> <h4>Arduino Code (SLAVE)</h4> </br> This project uses 2 Arduino UNOs.</br> One will be the Master, and one will be the Slave. </br> The following code is for the Arduino SLAVE. </br> </br> Make sure to disconnect the Arduino MASTER from your computer, and keep it to one side. Connect the Arduino SLAVE to your computer, and upload the following code to it. Make sure to create a new sketch for this code (File _ New). </br> <br> <div style="background: #ffffff; color: #000000; overflow:auto;width:auto;border:solid rgb(24,100,100);border-width: .6em .3em .3em .3em;padding: 0em 0em;"> <table> <tr> <td> <pre style="margin: 0; line-height: 125%; background: rgb(24,100,100); width: 1.9em"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br /> 10<br /> 11<br /> 12<br /> 13<br /> 14<br /> 15<br /> 16<br /> 17<br /> 18<br /> 19<br /> 20<br /> 21<br /> 22<br /> 23<br /> 24<br /> 25<br /> 26<br /> 27<br /> 28<br /> 29<br /> 30<br /> 31<br /> 32<br /> 33<br /> 34<br /> 35<br /> 36<br /> 37<br /> 38<br /> 39<br /> 40<br /> 41<br /> 42<br /> 43<br /> 44<br /> 45<br /> 46<br /> 47<br /> 48<br /> 49<br /> 50<br /> 51<br /> 52<br /> 53<br /> 54<br /> 55<br /> 56<br /> 57<br /> 58<br /> 59<br /> 60<br /> 61<br /> 62<br /> 63<br /> 64<br /> 65<br /> 66<br /> 67<br /> 68<br /> 69<br /> 70<br /> 71<br /> 72<br /> 73<br /> 74<br /> 75<br /> 76<br /> 77<br /> 78<br /> 79<br /> 80<br /> 81<br /> 82<br /> 83<br /> 84<br /> 85<br /> 86<br /> 87<br /> 88<br /> 89<br /> 90<br /> 91<br /> 92<br /> 93<br /> 94<br /> 95<br /> 96<br /> 97<br /> 98<br /> 99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br /> </pre> </td> <td> <pre style="margin: 0; line-height: 125%"><br /> <!-- INSERT ARDUINO CODE HERE --><br /><span style="color: #7E7E7E;">/* ===============================================================================</span><br /><span style="color: #7E7E7E;"> Project: Weather Reporter: Temboo, Ethernet, Arduino</span><br /><span style="color: #7E7E7E;"> Title: ARDUINO SLAVE: Display temperature on TFT LCD Module</span><br /><span style="color: #7E7E7E;"> Author: Scott C</span><br /><span style="color: #7E7E7E;"> Created: 27th February 2015</span><br /><span style="color: #7E7E7E;"> Arduino IDE: 1.6.0</span><br /><span style="color: #7E7E7E;"> Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html</span><br /><span style="color: #7E7E7E;"> Description: The following sketch was designed for the Arduino SLAVE device. </span><br /><span style="color: #7E7E7E;"> It will receive temperature information from the Arduino MASTER</span><br /><span style="color: #7E7E7E;"> and then display this information on the ITDB02-1.8SP TFT LCD </span><br /><span style="color: #7E7E7E;"> Module. Please read the important notes below.</span><br /><br /><span style="color: #7E7E7E;">----------------------------------------------------------------------------------</span><br /><span style="color: #7E7E7E;">NOTES:</span><br /><span style="color: #7E7E7E;">This sketch makes use of the UTFT.h library from : </span><br /><span style="color: #7E7E7E;">http://www.henningkarlsen.com/electronics/library.php?id=51</span><br /><span style="color: #7E7E7E;">Please note: You will need to modify the memorysaver.h file in the UTFT folder </span><br /><span style="color: #7E7E7E;">with a text editor to disable any unused TFT modules. This will save memory, </span><br /><span style="color: #7E7E7E;">and allow you to run this sketch on an Arduino UNO. I disabled all TFT modules in</span><br /><span style="color: #7E7E7E;">that file except the last 3 (which made reference to ST7735).</span><br /><span style="color: #7E7E7E;">I used a ITDB02-1.8SP TFT LCD Module from ITEAD Studio.</span><br /><span style="color: #7E7E7E;">PinOut:</span><br /><br /><span style="color: #7E7E7E;">Arduino SLAVE ITDB02-1.8SP TFT</span><br /><span style="color: #7E7E7E;"> 3.3V ---- VDD33</span><br /><span style="color: #7E7E7E;"> Digital9 (D9)---- CS</span><br /><span style="color: #7E7E7E;"> Digital8 (D8)---- SCL</span><br /><span style="color: #7E7E7E;"> Digital7 (D7)---- SDA</span><br /><span style="color: #7E7E7E;"> Digital6 (D6)---- RS</span><br /><span style="color: #7E7E7E;"> Digital5 (D5)---- RST</span><br /><span style="color: #7E7E7E;"> GND ---- GND</span><br /><span style="color: #7E7E7E;"> 5V ---- VIN</span><br /><br /><span style="color: #7E7E7E;">Usage: UTFT myGLCD(<model code>, SDA, SCL, CS, RST, RS);</span><br /><span style="color: #7E7E7E;">Example: UTFT myGLCD(ITDB18SP,7,8,9,5,6);</span><br /><br /><span style="color: #7E7E7E;">-----------------------------------------------------------------------------------</span><br /><span style="color: #7E7E7E;">This sketch also makes use of the Wire.h library. </span><br /><span style="color: #7E7E7E;">The Wire.h library comes with the Arduino IDE.</span><br /><span style="color: #7E7E7E;">This enables communication between Arduino Master and Arduino Slave.</span><br /><span style="color: #7E7E7E;">PinOut:</span><br /><br /><span style="color: #7E7E7E;">Arduino MASTER Arduino SLAVE</span><br /><span style="color: #7E7E7E;"> Analog4(A4) ---- Analog4 (A4) </span><br /><span style="color: #7E7E7E;"> Analog5(A5) ---- Analog5 (A5) </span><br /><span style="color: #7E7E7E;"> GND ---- GND</span><br /><br /><span style="color: #7E7E7E;">-----------------------------------------------------------------------------------</span><br /><span style="color: #7E7E7E;">The Arduino Slave is powered by the Arduino Master:</span><br /><span style="color: #7E7E7E;">PinOut:</span><br /><br /><span style="color: #7E7E7E;">Arduino MASTER Arduino SLAVE</span><br /><span style="color: #7E7E7E;"> 5V ---- VIN</span><br /><br /><span style="color: #7E7E7E;">==================================================================================</span><br /><span style="color: #7E7E7E;">*/</span><br /><br />#include <<span style="color: #CC6600;">UTFT</span>.h><br />#include <<span style="color: #CC6600;">Wire</span>.h><br /><br /><span style="color: #7E7E7E;">//Declare all of the fonts</span><br />extern uint8_t SmallFont[];<br />extern uint8_t BigFont[];<br />extern uint8_t SevenSegNumFont[];<br /><br /><span style="color: #7E7E7E;">// Usage: UTFT myGLCD(<model code>, SDA, SCL, CS, RST, RS);</span><br /><span style="color: #CC6600;">UTFT</span> myGLCD(<span style="color: #006699;">ITDB18SP</span>,7,8,9,5,6);<br /><br /><span style="color: #CC6600;">boolean</span> tempDisplay = <span style="color: #CC6600;">false</span>; <span style="color: #7E7E7E;">//Helps with processing the data from the Arduino MASTER</span><br /><span style="color: #CC6600;">boolean</span> readTemp = <span style="color: #CC6600;">false</span>; <span style="color: #7E7E7E;">//Helps to differentiate the day from the temperature values</span><br /><span style="color: #CC6600;">String</span> dayOfWeek=<span style="color: #006699;">""</span>; <span style="color: #7E7E7E;">//Variable used to hold the Day of the Week</span><br /><span style="color: #CC6600;">String</span> tempReading=<span style="color: #006699;">""</span>; <span style="color: #7E7E7E;">//Variable used to hold the Temperature for that day</span><br /><br /><span style="color: #CC6600;">String</span> Units = <span style="color: #006699;">"'C "</span>; <span style="color: #7E7E7E;">//Display Temperature in Celcius</span><br /><span style="color: #CC6600;">String</span> Address = <span style="color: #006699;">"Perth, WA"</span>; <span style="color: #7E7E7E;">//Address to show at top of Display</span><br /><br /><br /><span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>setup</b></span>(){<br /> <span style="color: #7E7E7E;">// Initialise the TFT LCD</span><br /> myGLCD.<span style="color: #CC6600;">InitLCD</span>();<br /> initialiseLCD();<br /> <span style="color: #CC6600;">delay</span>(5000);<br /> <br /> <span style="color: #7E7E7E;">//Setup the Serial communication between the Arduino MASTER and SLAVE</span><br /> <span style="color: #CC6600;">Wire</span>.<span style="color: #CC6600;">begin</span>(4); <span style="color: #7E7E7E;">// join i2c bus with address #4</span><br /> <span style="color: #CC6600;">Wire</span>.<span style="color: #CC6600;">onReceive</span>(receiveEvent); <span style="color: #7E7E7E;">// register event</span><br />}<br /><br /><br /><br /><span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>loop</b></span>(){<br /> <span style="color: #CC6600;">delay</span>(50);<br />}<br /><br /><br /><span style="color: #7E7E7E;">/*</span><br /><span style="color: #7E7E7E;"> This function initialises the TFT LCD, and draws the initial screen.</span><br /><span style="color: #7E7E7E;">*/</span><br /><span style="color: #CC6600;">void</span> initialiseLCD(){<br /> <span style="color: #7E7E7E;">//Clear the screen</span><br /> myGLCD.<span style="color: #CC6600;">clrScr</span>();<br /> <br /> <span style="color: #7E7E7E;">//Draw the borders (top and bottom)</span><br /> myGLCD.<span style="color: #CC6600;">setColor</span>(25, 35, 4);<br /> myGLCD.<span style="color: #CC6600;">fillRect</span>(0, 0, 159, 13);<br /> myGLCD.<span style="color: #CC6600;">fillRect</span>(0, 114, 159, 127);<br /> myGLCD.<span style="color: #CC6600;">drawLine</span>(0,18,159,18);<br /> myGLCD.<span style="color: #CC6600;">drawLine</span>(0,109,159,109);<br /> <br /> <span style="color: #7E7E7E;">//Header and Footer Writing</span><br /> myGLCD.<span style="color: #CC6600;">setColor</span>(255, 255, 255);<br /> myGLCD.<span style="color: #CC6600;">setBackColor</span>(25, 35, 4);<br /> myGLCD.<span style="color: #CC6600;">setFont</span>(SmallFont);<br /> myGLCD.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"arduinobasics"</span>, <span style="color: #006699;">CENTER</span>, 1);<br /> myGLCD.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"blogspot.com"</span>, <span style="color: #006699;">CENTER</span>, 114);<br />}<br /><br /><br /><br /><br /><span style="color: #7E7E7E;">/* This function executes whenever data is received from Arduino master</span><br /><span style="color: #7E7E7E;"> It will ignore all data from the Master until it receives a '*' character.</span><br /><span style="color: #7E7E7E;"> Once this character is received, it will call the receiveTemp() function</span><br /><span style="color: #7E7E7E;"> in order to receive Temperature data from the Arduino Master.</span><br /><span style="color: #7E7E7E;">*/</span><br /><span style="color: #CC6600;">void</span> receiveEvent(<span style="color: #CC6600;">int</span> howMany){<br /> <span style="color: #CC6600;">if</span>(tempDisplay){<br /> receiveTemp();<br /> }<span style="color: #CC6600;">else</span>{<br /> <span style="color: #CC6600;">while</span>(0 < <span style="color: #CC6600;">Wire</span>.<span style="color: #CC6600;">available</span>()){<br /> <span style="color: #CC6600;">char</span> c = <span style="color: #CC6600;">Wire</span>.<span style="color: #CC6600;">read</span>(); <span style="color: #7E7E7E;">// receive byte as a character</span><br /> <span style="color: #CC6600;">if</span>(c==<span style="color: #006699;">'*'</span>){ <span style="color: #7E7E7E;">// Searching for a '*' character</span><br /> tempDisplay=<span style="color: #CC6600;">true</span>; <span style="color: #7E7E7E;">// If '*' received, then call receiveTemp() function</span><br /> }<br /> }<br /> }<br />}<br /><br /><br /><br /><span style="color: #7E7E7E;">/* This function is used to receive and process the Temperature data </span><br /><span style="color: #7E7E7E;"> from the Arduino Master and pass it on to the displayTemp() funtion.</span><br /><span style="color: #7E7E7E;">*/</span><br /><span style="color: #CC6600;">void</span> receiveTemp(){<br /> tempReading=<span style="color: #006699;">""</span>;<br /> dayOfWeek = <span style="color: #006699;">""</span>;<br /> <br /> <span style="color: #CC6600;">while</span>(0 < <span style="color: #CC6600;">Wire</span>.<span style="color: #CC6600;">available</span>()){<br /> <span style="color: #CC6600;">char</span> c = <span style="color: #CC6600;">Wire</span>.<span style="color: #CC6600;">read</span>(); <span style="color: #7E7E7E;">// receive byte as a character</span><br /> <span style="color: #CC6600;">if</span>(readTemp){<br /> <span style="color: #CC6600;">if</span>(c==<span style="color: #006699;">'.'</span>){ <span style="color: #7E7E7E;">// If a . is detected. It is the end of the line.</span><br /> readTemp=<span style="color: #CC6600;">false</span>;<br /> }<span style="color: #CC6600;">else</span>{<br /> tempReading=tempReading+c;<br /> }<br /> }<span style="color: #CC6600;">else</span>{<br /> <span style="color: #CC6600;">if</span>(c==<span style="color: #006699;">','</span>){<br /> } <span style="color: #CC6600;">else</span> {<br /> dayOfWeek=dayOfWeek+c;<br /> }<br /> }<br /> <span style="color: #CC6600;">if</span>(c==<span style="color: #006699;">','</span>){<br /> readTemp=<span style="color: #CC6600;">true</span>;<br /> }<br /> }<br /> displayTemp();<br />}<br /><br /><br /><br /><span style="color: #7E7E7E;">/*</span><br /><span style="color: #7E7E7E;"> Display the Temperature readings on the TFT LCD screen.</span><br /><span style="color: #7E7E7E;">*/</span><br /><span style="color: #CC6600;">void</span> displayTemp(){<br /> <span style="color: #7E7E7E;">//Clear the writing on top and bottom of screen</span><br /> myGLCD.<span style="color: #CC6600;">setColor</span>(25, 35, 4);<br /> myGLCD.<span style="color: #CC6600;">fillRect</span>(0, 0, 159, 13);<br /> myGLCD.<span style="color: #CC6600;">fillRect</span>(0, 114, 159, 127);<br /> <br /> <span style="color: #7E7E7E;">//Small writing on top and bottom of screen</span><br /> myGLCD.<span style="color: #CC6600;">setColor</span>(255, 255, 255);<br /> myGLCD.<span style="color: #CC6600;">setBackColor</span>(25, 35, 4);<br /> myGLCD.<span style="color: #CC6600;">setFont</span>(SmallFont);<br /> myGLCD.<span style="color: #CC6600;">print</span>(Address, <span style="color: #006699;">CENTER</span>, 1);<br /> myGLCD.<span style="color: #CC6600;">print</span>(dayOfWeek, <span style="color: #006699;">CENTER</span>, 114);<br /> <br /> <span style="color: #7E7E7E;">//Write the big temperature reading in middle of screen</span><br /> myGLCD.<span style="color: #CC6600;">setBackColor</span>(0, 0, 0);<br /> myGLCD.<span style="color: #CC6600;">setFont</span>(SevenSegNumFont);<br /> myGLCD.<span style="color: #CC6600;">print</span>(tempReading, <span style="color: #006699;">CENTER</span>, 40);<br /> <br /> <span style="color: #7E7E7E;">//Write the Units next to the temperature reading</span><br /> myGLCD.<span style="color: #CC6600;">setFont</span>(BigFont);<br /> myGLCD.<span style="color: #CC6600;">print</span>(Units, <span style="color: #006699;">RIGHT</span>, 40);<br />}<br /> <!-- End of Arduino Code --><br /> </pre> </td> </tr> </table></div> <br> <br> <br> </P> </div></P><P> <div style="text-align: justify;"> <h4>Wiring it up</h4> <P>Once the code has been uploaded to both Arduinos (Master and Slave), I tend to label each Arduino so that I don't mix them up. You will notice an 'S' marked on the SLAVE in some of the photos/videos. Then it is time to piggy-back the shields onto the Arduinos and wire them up. Make sure you disconnect the USB cable from the Arduinos before you start doing this.</P> <br> <h3>Step 1: Ethernet Shield</h3> <P> Place the Ethernet shield onto the Arduino MASTER. </br> Connect an Ethernet cable (RJ45) to the Ethernet shield. The other end will connect to your internet router. </P> <P style="clear:both;"> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb_o79UtSZBf3ooXFu8cF4ld5Lz4wWO1XfzRsHdiHYrtUjOD6ILUQIg8wu9CfLXbFrvuwInrX0yhT1JOs3Bsz3I4YK6pJQm86tsv6BRa2MxESIIFPF6fRVEH3g_nxa9SRi4PbKOVJdyK4/s1600/IMG_4331.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb_o79UtSZBf3ooXFu8cF4ld5Lz4wWO1XfzRsHdiHYrtUjOD6ILUQIg8wu9CfLXbFrvuwInrX0yhT1JOs3Bsz3I4YK6pJQm86tsv6BRa2MxESIIFPF6fRVEH3g_nxa9SRi4PbKOVJdyK4/s400/IMG_4331.JPG" /> </a> </div> </P> <br> <br> <P style="clear:both;"> <h3>Step 2: Arduino SLAVE and TFT LCD module</h3> <br> You can either wire up the TFT LCD module on a breadboard, or you can use a ProtoShield with mini-breadboard. It doesn't really matter how you hook it up, but make sure you double check the connections and the TFT specifications before you power it up. I have powered the Arduino Slave by connecting it to the Arduino Master (see fritzing sketch below). </br> <br> There is no reason why you couldn't just power the slave seperately. In fact this is probably the safer option. But I read that this power-sharing setup was ok, so I wanted to give it a go. I have no idea whether it would be suitable for a long term power project... so use it at your own risk. I tried using 4 x AA batteries to power this circuit, but found that the LCD screen would flicker. So then I tried a 9V battery, and noticed that the 5V voltage regulator was heating up more than I felt comfortable with. In the end, I settled with the USB option, and had no further issues. I am sure there are other possible options, and feel free to mention them in the comments below. </br> <br> Use the following fritzing sketch and tables to help you wire this circuit up. </P> <br> <h4>Fritzing sketch</h4> <br> <P style="clear:both;"> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLP6ZNQXv8xMSiAq_CUSGpzVOlItGWllJYxl8R8k0-Bq6HuWSn4bfM1tP4Uq4F5NvP2pm-gJzCq7Inch3OngfJYw7Y1Kk13_6a_rcLOyseI7zzhhaOZYQP8Ts8hBZiRCwFSsLrJ8l3Auk/s1600/Temboo+Weather_with+TFT2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLP6ZNQXv8xMSiAq_CUSGpzVOlItGWllJYxl8R8k0-Bq6HuWSn4bfM1tP4Uq4F5NvP2pm-gJzCq7Inch3OngfJYw7Y1Kk13_6a_rcLOyseI7zzhhaOZYQP8Ts8hBZiRCwFSsLrJ8l3Auk/s640/Temboo+Weather_with+TFT2.png" /> </a> </div> </P> <br> <br> <P style="clear:both;"> <br> <h4>Arduino MASTER to SLAVE connection table</h4> <br> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYSHFdnkny39FnvlsN1F5Q-Juoy_VTEIOTTLAfBWF3_A5cs4IJjzblF2UaWCKn97RdOkKLVQE7RgKtcM-MbI3GSa5Cz5eMDdlzBVQSJOw8yPQHFUEYQdITouFV5WzqxdnUnDDZIT0iRo0/s1600/Arduino+Master+to+Slave+Connection+Table.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYSHFdnkny39FnvlsN1F5Q-Juoy_VTEIOTTLAfBWF3_A5cs4IJjzblF2UaWCKn97RdOkKLVQE7RgKtcM-MbI3GSa5Cz5eMDdlzBVQSJOw8yPQHFUEYQdITouFV5WzqxdnUnDDZIT0iRo0/s1600/Arduino+Master+to+Slave+Connection+Table.jpg" width="400" /> </a> </div> </P> <br> <br> <P style="clear:both;"> <br> <h4>Arduino SLAVE to ITDB02-1.8SP TFT LCD</h4> <br> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3KFWgj5UJwnnlNvh8EACvTrcd1yaRNchOC2p-nEDPL4l9J6-0zBYJt77az6fbH3Z0z4yHuViZBQ_oxp784HF4QkY0XD9do97nigSFUdOC_d3hTQD0tNIW5uNE6ogLJzs79Y4rpx86-uo/s1600/Arduino+Slave+to+ITDB02_18SP+Connection+Table.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3KFWgj5UJwnnlNvh8EACvTrcd1yaRNchOC2p-nEDPL4l9J6-0zBYJt77az6fbH3Z0z4yHuViZBQ_oxp784HF4QkY0XD9do97nigSFUdOC_d3hTQD0tNIW5uNE6ogLJzs79Y4rpx86-uo/s1600/Arduino+Slave+to+ITDB02_18SP+Connection+Table.jpg" width="400" /> </a> </div> </P> <P style="clear:both;"> <br> <br> <h4>ITDB02-1.8SP TFT LCD Module Pictures</h4> <br> <P style="clear:both;"> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9nSf1s2aPn8ZXnkB2eTHGoP05f3qQpidwzNBuhKr4PADf-cU1vgIq4s04bO4Hciu8Wx6T5jniwK3SDEvHYMLSUB8GJDc84iRxSm6ASErXQJQpI-_q4ogb86LAybf1ryZ4YVpvDSVyIgY/s1600/IMG_4371.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9nSf1s2aPn8ZXnkB2eTHGoP05f3qQpidwzNBuhKr4PADf-cU1vgIq4s04bO4Hciu8Wx6T5jniwK3SDEvHYMLSUB8GJDc84iRxSm6ASErXQJQpI-_q4ogb86LAybf1ryZ4YVpvDSVyIgY/s320/IMG_4371.JPG" /> </a> </div> </P> <br> <P style="clear:both;"> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo9Y4RJHUm50Rz5MAAbhborMoMNz1nZcaR8yBpvGwv1Uie3rgU7O0KdqNxLSwSbSCvDw1-YUw62TlWqSGweNKjMO5V0T7W0KHv0QGF_3misrSmOsJvmdxRLbb3QngG8WXkvV0Mgpjdq60/s1600/TFT+Module+With+Labels.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo9Y4RJHUm50Rz5MAAbhborMoMNz1nZcaR8yBpvGwv1Uie3rgU7O0KdqNxLSwSbSCvDw1-YUw62TlWqSGweNKjMO5V0T7W0KHv0QGF_3misrSmOsJvmdxRLbb3QngG8WXkvV0Mgpjdq60/s320/TFT+Module+With+Labels.jpg" /> </a> </div> </P> </P> <P style="clear:both;"> <br> <br> <h4>Project Pictures</h4> <br> <P style="clear:both;"> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIfdFaDjV94TibHv5nCEB-y0URN-88oKlUrtN9rJ730Z2Yk51z6FitmO-WDNxOhXaBQKf5gvUJxWfqqGjgdHNNo6GBcwKUwPgmA3ZBRFK8a72AT3bzECg3sHTeaabWG9oRoTUodilJfZk/s1600/1_WireConnections.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIfdFaDjV94TibHv5nCEB-y0URN-88oKlUrtN9rJ730Z2Yk51z6FitmO-WDNxOhXaBQKf5gvUJxWfqqGjgdHNNo6GBcwKUwPgmA3ZBRFK8a72AT3bzECg3sHTeaabWG9oRoTUodilJfZk/s400/1_WireConnections.jpg" /> </a> </div> </P> <br> <P style="clear:both;"> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1c4pdC8wD9szmawAYTOzpLgOVQLYNNnHr9VpSFAB6ygLLaC23iLNLR0am8qto0NNfbJyh9hrwIaXDVZfkaIRVVU2Py3H0zaqzYr7HyRwfWLxudM3hPmi_8SPPfx1qAjq1aibolSXADgI/s1600/2_WireConnectionsTFT.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1c4pdC8wD9szmawAYTOzpLgOVQLYNNnHr9VpSFAB6ygLLaC23iLNLR0am8qto0NNfbJyh9hrwIaXDVZfkaIRVVU2Py3H0zaqzYr7HyRwfWLxudM3hPmi_8SPPfx1qAjq1aibolSXADgI/s400/2_WireConnectionsTFT.jpg" /> </a> </div> </P> <br> <P style="clear:both;"> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgacjJaSIR4AKqLfbXkEm_oylbLd5kUXxw8AZS2nZQhUgUBweE7QFFeHyE_c37ShPETZLhWtcLt-Q15YP4u_TvEe57UWIowLBgnlEPOCrreV75jfjxwBbvlN6OabbG7Nv56BLCeFGu09L0/s1600/3_RunningCircuit.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgacjJaSIR4AKqLfbXkEm_oylbLd5kUXxw8AZS2nZQhUgUBweE7QFFeHyE_c37ShPETZLhWtcLt-Q15YP4u_TvEe57UWIowLBgnlEPOCrreV75jfjxwBbvlN6OabbG7Nv56BLCeFGu09L0/s400/3_RunningCircuit.jpg" /> </a> </div> </P> <br> <P style="clear:both;"> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn41sJg0_9SINHw4Lb0JQT6w09Ce0E0SOja_PygV-dAUzy_bGMdny8U_9FTEip3bG6MpyWeE6zcB77xLU2YfPVo6NI9AHPPYtVz9QS5Ft018Cr_EVyojWGZVxGqGJ_po-vGUmQE_FYGIg/s1600/ProjectInAction.gif" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"> <img style="border:3px double white;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn41sJg0_9SINHw4Lb0JQT6w09Ce0E0SOja_PygV-dAUzy_bGMdny8U_9FTEip3bG6MpyWeE6zcB77xLU2YfPVo6NI9AHPPYtVz9QS5Ft018Cr_EVyojWGZVxGqGJ_po-vGUmQE_FYGIg/s400/ProjectInAction.gif" /> </a> </div> </P> </P> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> <P> <div align="center"> If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br> <BR /> <BR /> Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br> Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br> Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.<br> </div> </P> <BR /> <BR /> <div align="center"> <div class="separator" style="clear: both; text-align: center;"> <a href="http://arduino.cc/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmuBeqll5_-ovWlmf5ncMAWNxQ05r_dYIb_ezswWonrTzqnBW1y3YiN4dFUImKVLrFfilGIPMMg5mMfHItxdei6Kqs4o9pvZsg3sucWXSUR5Lm-MDx3nhDHu_9oaZIKeFGLANQoz4Ge8c/s1600/ArduinoLogo.png" /></a> </div> </div> <BR /> <BR /> <BR /> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> However, if you do not have a google profile... <br>Feel free to share this page with your friends in any way you see fit. </P> </div></P><br /><br /><br /><br /><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" -->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-31156429466563157012015-02-02T00:49:00.000-08:002016-03-19T10:53:41.196-07:00New forumHi everyone, I am trying something new. I have put a new forum page on this blog to help with project related questions. Sometimes the comments section of a project is not adequate for these queries, so I am trying out a <a href="http://arduinobasics.blogspot.com.au/p/forum-trial.html">new forum page</a> to see if this helps or not. Let me know what you think, and if you have any suggestions, please let me know in the comments. ScottC Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-19495794910895101292015-01-29T23:32:00.000-08:002016-03-19T11:06:12.128-07:00Product review of CT-UNO by Cytron<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div>I received my <a href="http://cytron.com.my/p-ct-uno">CT-UNO</a>, an UNO board made by Cytron and I'm doing a short review on this board.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9Il1Xcy6t_8fKF4QcIMR3U0ZRC1q6RV-nIGpx1oNAVUmVviDDLs3A8dZBDziex99az2TyLIb6mj5uHaHPmIzq6GJJwBcYE_O7KSyVYen_c_cyJDHhypSHInEawDjQBh3SjvDKnVo6vVNa/s1600/CT-UNO.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9Il1Xcy6t_8fKF4QcIMR3U0ZRC1q6RV-nIGpx1oNAVUmVviDDLs3A8dZBDziex99az2TyLIb6mj5uHaHPmIzq6GJJwBcYE_O7KSyVYen_c_cyJDHhypSHInEawDjQBh3SjvDKnVo6vVNa/s1600/CT-UNO.jpg" height="248" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">CT-UNO</td></tr></tbody></table><br />The first question is, why another UNO board ? The answer would be answered in my short review below.<br /><br />This CT-UNO was used as part of the starter kit during my Penang Mini Maker Faire Arduino workshop in November.<br /><br />The main factor I really like about this is the <b>Micro-USB</b> port instead of the gigantic USB B plug used by regular Arduino UNO boards. With so many USB micro cables all around, having a USB micro is a good decision made by Cytron.<br /><br />Secondly, I always like the FTDI USB Serial chip. I'm still using the FTDI Breakout board on a regular basis to program the Arduino Mini Pro ...<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFyTqAqXqo7hm5ZmUpK5HIjFroRvnkC0HDXQt94b5NYiVznj1MLjZ8N1Ke15I6jP7tJRluLyT62NAYNbIhoKGHYAHnxYikJ9krUxFjotva1lPo5Pg62EFIUeQ21Ks1973xjZfVF5qWomaP/s1600/2015-01-23+00.45.43-1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFyTqAqXqo7hm5ZmUpK5HIjFroRvnkC0HDXQt94b5NYiVznj1MLjZ8N1Ke15I6jP7tJRluLyT62NAYNbIhoKGHYAHnxYikJ9krUxFjotva1lPo5Pg62EFIUeQ21Ks1973xjZfVF5qWomaP/s1600/2015-01-23+00.45.43-1.jpg" height="237" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">FTDI FT23x</td></tr></tbody></table><br />On the subject of FTDI board, there is an Android app called <b><a href="https://play.google.com/store/apps/details?id=com.ftdi.j2xx.hyperterm&hl=en">FTDI UART Terminal</a></b> that can accept a FTDI USB-Serial device so that you can plug in the CT-UNO directly to the Android Smatphone and view the Serial Monitor using this app with an USB OTG cable.<br /><br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfVHMeKqt-aX2CwM4tExI43yKmy1Zple4aK3OOIMY4QbB_wtP3RrlIeATJOn0UrATyvPu1x08IO8kbhc0n7UjWcQE_BIv3RV_scwUpH1EPa5Sw6hcpweqcA0fFIJphidWEGrJLvdDKIn3U/s1600/2015-01-30+15.19.32.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto; text-align: center;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfVHMeKqt-aX2CwM4tExI43yKmy1Zple4aK3OOIMY4QbB_wtP3RrlIeATJOn0UrATyvPu1x08IO8kbhc0n7UjWcQE_BIv3RV_scwUpH1EPa5Sw6hcpweqcA0fFIJphidWEGrJLvdDKIn3U/s1600/2015-01-30+15.19.32.jpg" height="308" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">CT-UNO with FTDI connected to Android Smarthphone</td></tr></tbody></table><br />As per most of the newer UNO board, this is a SMD version of the atmega328P, so you cannot remove the IC.<br /><div><br /></div><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj06PivZkdTmRg2n9ct8sdswVDhKpBy97liiCHr6NN0ILb8rrPFlv1-H3XQF5Yjd4QnCmzycHRUftlxsx5PfdLE1tmxCvUZK5cNdYIQaJ4oi7ZS8i-f4Onr0RnvCFM58M8QFmi7Mwg-scvj/s1600/2015-01-23+00.46.52-1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj06PivZkdTmRg2n9ct8sdswVDhKpBy97liiCHr6NN0ILb8rrPFlv1-H3XQF5Yjd4QnCmzycHRUftlxsx5PfdLE1tmxCvUZK5cNdYIQaJ4oi7ZS8i-f4Onr0RnvCFM58M8QFmi7Mwg-scvj/s1600/2015-01-23+00.46.52-1.jpg" height="273" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">ATMEGA328 SMD</td></tr></tbody></table><div><br />Another thing I really like about this board is that you can directly solder wires to the pins below the board for permanent connections. Here are some pictures of the CT-UNO on the sides and below the board.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmbtb4JLjBVydHJqVMJH8CnZpcy3jFSmMRM30PRTbsLP0sR0zwECDzRrb9U8E9kg9PF3aAXMyHfDoVK6dIpubuaQmGZsftOWDmoOwaC_zSuFPNr4OJLf52wA_7zAVL2l0_SSmgrsNgUgpn/s1600/2015-01-23+00.48.44.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmbtb4JLjBVydHJqVMJH8CnZpcy3jFSmMRM30PRTbsLP0sR0zwECDzRrb9U8E9kg9PF3aAXMyHfDoVK6dIpubuaQmGZsftOWDmoOwaC_zSuFPNr4OJLf52wA_7zAVL2l0_SSmgrsNgUgpn/s1600/2015-01-23+00.48.44.jpg" height="237" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Sides holes</td></tr></tbody></table><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizR0FCq-B7a7WMDgPensj3J-Fn0ZMFQ7v3TrFzlqYnaIfQApAeCw1f0FWPpVf__ENCxRUwi_V-pt185WnDZoQFBuclNldYmqIzkNuM2fUgrUDtluDdorZDFi4F61hB-KT8GqgEyBN7lLvT/s1600/2015-01-23+00.48.52.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizR0FCq-B7a7WMDgPensj3J-Fn0ZMFQ7v3TrFzlqYnaIfQApAeCw1f0FWPpVf__ENCxRUwi_V-pt185WnDZoQFBuclNldYmqIzkNuM2fUgrUDtluDdorZDFi4F61hB-KT8GqgEyBN7lLvT/s1600/2015-01-23+00.48.52.jpg" height="123" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Sie holes</td></tr></tbody></table><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzGqQSPeZ6WzgzRJBsUGOI3stnw0OXyeGInrd1NjnluStDDU9x-6ISAIkwCtSns0RpcOIq8M9AuFiGh_1Ajwo1VZGHDM_RqUvDounuWsBkgV4ULH8V_6KGM3pwLeErjJmzh_IUqTTHNZuz/s1600/2015-01-30+15.12.15.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzGqQSPeZ6WzgzRJBsUGOI3stnw0OXyeGInrd1NjnluStDDU9x-6ISAIkwCtSns0RpcOIq8M9AuFiGh_1Ajwo1VZGHDM_RqUvDounuWsBkgV4ULH8V_6KGM3pwLeErjJmzh_IUqTTHNZuz/s1600/2015-01-30+15.12.15.jpg" height="320" width="237" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">CT-UNO back</td></tr></tbody></table>Last but not least, this board is "Made in Malaysia", so please support Malaysian made products.</div><div>The only thing I didn't like about this board is the white colour of the PCB silkscreen but this is my personal opinion.<br /><br />Overall, it is a very usable UNO board and very good to view Serial Monitor on Android Smartphone that support USB OTG cable.<br /><br />It cost RM56 on <a href="http://cytron.com.my/p-ct-uno">Cytron online store</a> and RM62 on retail stores.</div><div><br /></div><div>A special thanks to <a href="http://vinduino.blogspot.com/">Vincent Kok</a> for sending me this CT-UNO for review.</div><div><br /></div><div>Summary Links :-</div><div><br /></div><div><ul style="text-align: left;"><li><a href="http://tutorial.cytron.com.my/2014/11/04/introducing-ct-uno/">Cytron CT-UNO tutorial site</a></li><li><a href="http://cytron.com.my/p-ct-uno">Cytron CT-UNO online store</a></li><li><a href="https://play.google.com/store/apps/details?id=com.ftdi.j2xx.hyperterm&hl=en">FTDI UART Terminal on Google Play</a> </li></ul><div><br /></div></div><div><br /><br /></div></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-90400969083001896702015-01-12T10:27:00.000-08:002016-03-19T10:53:41.207-07:00E-Paper Barcode 39<div style="text-align: right;"><g:plusone></g:plusone></div><div style="text-align: justify;"> <P> <img border="0" src="http://3.bp.blogspot.com/-tNxJCWmSMXA/VKoMYW7qDBI/AAAAAAAABME/Z5jMxrdY8pM/s1600/EPAPER.jpg" height="213" width="640" /> </P> <P> <div> <P> <!-- Description and Introduction of project --> <P> E-Paper (or Electronic paper) is a display technology that mimics the appearance of ordinary ink on paper. E-paper displays do not emit light, rather they reflect light, thus making them much more comfortable to read and provide a wider viewing angle than most light emitting displays (<a href="http://en.wikipedia.org/wiki/Electronic_paper">source: Wikipedia</a>).</P> <P> I printed something to an E-paper display, unplugged it, and could still read the message clearly months later. These E-paper displays are great for showing information that is static for long periods. You only need to provide power when the data or information needs updating. </P> <P>Barcodes are used everywhere, and one of the simplest Barcodes to generate is the Code 39 format (also known as Code 3 of 9). I used an E-paper shield and E-paper module to display a number in this barcode format. I then tested it with a Barcode reader and it worked perfectly. <BR> This tutorial will show you how to send a number to the Arduino from the Serial Monitor, and display the Barcode on the E-paper module.</P> </P> </div> Note: If you are using an Arduino UNO (or compatible), you will also need to get a micro SDHC card. </P> <BR /> <P> <H4>The Video</H4> <BR /> <P>The video will show you how to assemble the shield and the module onto the Arduino, and also how to install the SDHC card.</P> <div style="text-align: center;"> <!-- Video Code --> <iframe allowfullscreen="" frameborder="0" height="480" src="//www.youtube.com/embed/dE6OuwLTIKo?rel=0" width="640"></iframe> </div> </P> <BR /> <BR /> <P> <H4>Parts Required:</H4> <P> <ul> <li><a href="http://www.epictinker.com/Freetronics-Eleven-100-Arduino-Uno-Compatible-p/ard-1002.htm">Arduino UNO (or compatible)</a></li> <li><a href="http://www.officeworks.com.au/shop/m20ProductDisplayView?catalogId=10551&langId=-1&productId=106530&storeId=10151">Micro SDHC card</a></li> <li><a href="http://www.epictinker.com/2-0-inch-e-Paper-Panel-p/ss-lcd00300b.htm">2.0 inch e-Paper Panel</a></li> <li><a href="http://www.epictinker.com/Small-e-paper-Shield-p/sld00200p.htm">Small e-paper Shield</a></li><br /> </ul> </P> </P> <P> <H4>Library Download</H4> <BR /> To use the e-paper shield, you will need to download the <a href="https://github.com/Seeed-Studio/Small_ePaper_Shield">Small e-paper Shield library</a>.<br> This library will allow you to use the following functions on the e-paper shield: <br> <ul> <li> <b>begin</b> : to set up the size of the e-paper panel </li> <li> <b>setDirection</b> : to set up the display direction</li> <li> <b>drawChar</b> : to display a Character at a specified position</li> <li> <b>drawString</b> : to display a String of characters at a specified position</li> <li> <b>drawNumber</b> and <b>drawFloat</b> : to display a number</li> <li> <b>drawLine</b> : to draw a line</li> <li> <b>drawHorizontalLine</b> : to draw a horizontal line</li> <li> <b>drawVerticalLine</b> : to draw a vertical line</li> <li> <b>drawCircle</b> : to draw a circle</li> <li> <b>fillCircle</b> : to draw and fill a circle</li> <li> <b>drawRectangle</b> : to draw a rectangle</li> <li> <b>fillRectangle</b> : to draw and fill a rectangle</li> <li> <b>drawTriangle</b> : to draw a triangle</li> </ul> You can also draw an image to the e-paper shield. </P> <P> For more information on how to use these functions, please visit the <a href="http://www.seeedstudio.com/wiki/Small_e-Paper_Shield">seeedstudio wiki</a>. If you are unfamiliar with installing libraries - then have a look at the following sites: <ul> <li><a href="http://arduino.cc/en/Guide/Libraries">Arduino Library Installation</a></li> <li><a href="https://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use/how-to-install-a-library">Adafruit Library Installation guide</a></li> <li><a href="https://learn.sparkfun.com/tutorials/installing-an-arduino-library">Sparkfun Library Installation guide</a></li> </ul> </P> <P> <H4>Barcode 39 Info</H4> <div style="text-align: justify;"> <P> Barcode 39 (or Code 3 of 9) is a barcode that consists of black and white vertical lines. These lines can be thick or thin. Each character can be coded using 9 alternating black and white bars. The barcode always starts with a black bar, and ends with a black bar. </P> <P> If you code using thin lines only, then each character can be coded using a total of 12 bars. A wide black line is essentially two thin black lines next to each other. Same goes for a wide white line. Because there are now only 2 options (black or white), you can create a binary code. I used a 1 for black bars, and 0 for white bars. If there was a thick black bar, then this would be represented with a 11. A thick white bar would be 00. </P> <P>Each barcode sequence starts and ends with a hidden * character. Therefore if you were to display just the number 1, you would have to provide the code for *1*. </P> <P> <ul> <li>* = 100101101101</li> <li>1 = 110100101011</li> <li>* = 100101101101</li> </ul> Notice that each character starts with a 1 and ends with a 1. <br> Something also to take note of: is that each character is separated by a thin white line (and not represented in the binary code). </P> <P> All of these 0's and 1's can get a bit confusing, so I decided to represent these binary numbers as decimals. For example, the picture below shows how a 0 and an 8 would be coded (without the *): <br /> <BR /> <div class="separator" style="clear: both; text-align: justify;"><a href="http://3.bp.blogspot.com/-VlNWpAaofhw/VLPmXlF-UfI/AAAAAAAABMo/ccdJ6s4_m_4/s1600/Barcode39%2BSymbology2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-VlNWpAaofhw/VLPmXlF-UfI/AAAAAAAABMo/ccdJ6s4_m_4/s1600/Barcode39%2BSymbology2.png" /></a></div><br /><br />The table below provides the binary and decimal codes for each number used in this tutorial. I have also included for your own reference, each letter of the alphabet, however I did not use these in this tutorial.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-Z4RHoV_xNwo/VLPl0OhsRqI/AAAAAAAABMg/QLmm6YZLQX0/s1600/Barcode39%2BSymbology.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-Z4RHoV_xNwo/VLPl0OhsRqI/AAAAAAAABMg/QLmm6YZLQX0/s1600/Barcode39%2BSymbology.png" /></a></div> </P> <P>The binary representation of each character in this table was obtained from <a href="http://www.barcodeisland.com/code39.phtml">this site</a>. <br> www.barcodeisland.com is a great resource of information about barcodes.</P> I adapted their binary code into a decimal equivalent, and therefore had to create my own table. </div> <BR /> <BR /> </P> <P> <H4>Arduino Sketch</H4> <BR /> <div style="background: #ffffff; color: #000000; overflow:auto;width:auto;border:solid rgb(24,186,183);border-width: .6em .3em .3em .3em;padding: 0em 0em;"> <table> <tr> <td> <pre style="margin: 0; line-height: 125%; background: rgb(24,186,183); width: 1.9em"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br /> 10<br /> 11<br /> 12<br /> 13<br /> 14<br /> 15<br /> 16<br /> 17<br /> 18<br /> 19<br /> 20<br /> 21<br /> 22<br /> 23<br /> 24<br /> 25<br /> 26<br /> 27<br /> 28<br /> 29<br /> 30<br /> 31<br /> 32<br /> 33<br /> 34<br /> 35<br /> 36<br /> 37<br /> 38<br /> 39<br /> 40<br /> 41<br /> 42<br /> 43<br /> 44<br /> 45<br /> 46<br /> 47<br /> 48<br /> 49<br /> 50<br /> 51<br /> 52<br /> 53<br /> 54<br /> 55<br /> 56<br /> 57<br /> 58<br /> 59<br /> 60<br /> 61<br /> 62<br /> 63<br /> 64<br /> 65<br /> 66<br /> 67<br /> 68<br /> 69<br /> 70<br /> 71<br /> 72<br /> 73<br /> 74<br /> 75<br /> 76<br /> 77<br /> 78<br /> 79<br /> 80<br /> 81<br /> 82<br /> 83<br /> 84<br /> 85<br /> 86<br /> 87<br /> 88<br /> 89<br /> 90<br /> 91<br /> 92<br /> 93<br /> 94<br /> 95<br /> 96<br /> 97<br /> 98<br /> 99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br /> </pre> </td> <td> <pre style="margin: 0; line-height: 125%"><br /> <!-- INSERT ARDUINO CODE HERE --><br /><span style="color: #7E7E7E;">/* ===============================================================</span><br /><span style="color: #7E7E7E;"> Project: Display Barcodes on an e-Paper Panel</span><br /><span style="color: #7E7E7E;"> Author: Scott C</span><br /><span style="color: #7E7E7E;"> Created: 6th January 2015</span><br /><span style="color: #7E7E7E;"> Arduino IDE: 1.0.5</span><br /><span style="color: #7E7E7E;"> Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html</span><br /><span style="color: #7E7E7E;"> Description: This project will allow you to send a number from the Serial </span><br /><span style="color: #7E7E7E;"> Monitor to the Arduino. The number will then be displayed on </span><br /><span style="color: #7E7E7E;"> the e-Paper panel as a Code-39 barcode (and text).</span><br /><span style="color: #7E7E7E;">================================================================== */</span><br /><br />#include <<span style="color: #CC6600;">ePaper</span>.h><br />#include <<span style="color: #CC6600;">SPI</span>.h><br />#include <<span style="color: #CC6600;">SD</span>.h><br />#include <span style="color: #006699;">"GT20L16_drive.h"</span><br /><br /><span style="color: #CC6600;">const</span> <span style="color: #CC6600;">int</span> maxBarcodeSize = 10; <span style="color: #7E7E7E;">// set the maximum barcode size to 10 digits</span><br /><span style="color: #CC6600;">int</span> barcode[maxBarcodeSize]; <span style="color: #7E7E7E;">// initialise the barcode array to the maximum 10 digits</span><br /><span style="color: #CC6600;">int</span> barcodeText[maxBarcodeSize]; <span style="color: #7E7E7E;">// initialise the barcodeText array to the maximum 10 digits</span><br /><span style="color: #CC6600;">int</span> barcodePos; <span style="color: #7E7E7E;">// Used to identify each digit within the barcode</span><br /><span style="color: #CC6600;">int</span> barcodeLength; <span style="color: #7E7E7E;">// Used to identify the actual length of the barcode</span><br /><br /><span style="color: #7E7E7E;">/* The following array holds the decimal code for each digit (0-9). </span><br /><span style="color: #7E7E7E;"> Each digit can be converted to binary and then drawn as a barcode.</span><br /><span style="color: #7E7E7E;"> 0 1 2 3 4 5 6 7 8 9 */</span><br /><span style="color: #CC6600;">int</span> barcodeDecimal[] = {2669, 3371, 2859, 3477, 2667, 3381, 2869, 2651, 3373, 2861};<br /><br /><span style="color: #CC6600;">int</span> astrix = 2413; <span style="color: #7E7E7E;">// "*" character decimal code used at beginning and end of barcode sequence</span><br /><br /><br /><span style="color: #7E7E7E;">/* When drawBarcode = "no", the program will not draw the barcode on the e-paper panel</span><br /><span style="color: #7E7E7E;"> When drawBarcode = "yes", the command to draw the barcode on the e-paper panel will be triggered. */</span><br /><span style="color: #CC6600;">String</span> drawBarcode = <span style="color: #006699;">"no"</span>;<br /><br /><br /><span style="color: #7E7E7E;">/* This variable is the x Position on the e-Paper panel screen */</span><br /><span style="color: #CC6600;">int</span> xPosition;<br /><br /><br /><span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>setup</b></span>(){<br /> <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">begin</span>(9600); <span style="color: #7E7E7E;">// Initialise Serial communication</span><br /> <span style="color: #CC6600;">EPAPER</span>.<span style="color: #CC6600;">begin</span>(<span style="color: #006699;">EPD_2_0</span>); <span style="color: #7E7E7E;">// Set the e-Paper panel size to 2 inches </span><br /> <span style="color: #CC6600;">EPAPER</span>.<span style="color: #CC6600;">setDirection</span>(<span style="color: #006699;">DIRNORMAL</span>); <span style="color: #7E7E7E;">// Set the e-Paper panel display direction (to Normal)</span><br /> <span style="color: #CC6600;">eSD</span>.<span style="color: #CC6600;">begin</span>(<span style="color: #006699;">EPD_2_0</span>); <span style="color: #7E7E7E;">// Prepares the SD card</span><br /> <span style="color: #CC6600;">GT20L16</span>.<span style="color: #CC6600;">begin</span>(); <span style="color: #7E7E7E;">// Initialise the GT20L16 font chip on the e-Paper panel</span><br /> barcodePos = 0; <span style="color: #7E7E7E;">// Set the barcode digit to the first digit in the barcode</span><br /> <span style="color: #CC6600;">EPAPER</span>.<span style="color: #CC6600;">clear_sd</span>(); <span style="color: #7E7E7E;">// Clear the screen when starting sketch</span><br /> <br /> <span style="color: #CC6600;">EPAPER</span>.<span style="color: #CC6600;">drawString</span>(<span style="color: #006699;">"http://arduinobasics"</span>, 10, 20); <span style="color: #7E7E7E;">//splash screen text</span><br /> <span style="color: #CC6600;">EPAPER</span>.<span style="color: #CC6600;">drawString</span>(<span style="color: #006699;">".blogspot.com"</span>, 60, 40);<br /> <br /> <span style="color: #CC6600;">EPAPER</span>.<span style="color: #CC6600;">display</span>(); <span style="color: #7E7E7E;">// Display the splash screen</span><br />}<br /><br /><br /><span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>loop</b></span>(){<br /> <br /> <span style="color: #7E7E7E;">// The Arduino will wait until it receives data from the Serial COM port</span><br /> <br /> <span style="color: #CC6600;">while</span> (<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">available</span>()>0){<br /> barcodeText[barcodePos] = <span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">read</span>();<br /> <br /> <span style="color: #CC6600;">if</span>(barcodeText[barcodePos]>47 && barcodeText[barcodePos]<58){ <span style="color: #7E7E7E;">// A number was sent</span><br /> barcode[barcodePos] = barcodeText[barcodePos]-48; <span style="color: #7E7E7E;">// Convert the decimal value from the serial monitor to a Number</span><br /> } <br /> <br /> <span style="color: #CC6600;">if</span>(barcodeText[barcodePos]==46){ <span style="color: #7E7E7E;">// If a "." is detected, then barcode is complete</span><br /> barcodeLength = barcodePos; <span style="color: #7E7E7E;">// Set the length of the barcode (used later)</span><br /> drawBarcode = <span style="color: #006699;">"yes"</span>; <span style="color: #7E7E7E;">// We can now draw the barcode</span><br /> <br /> }<br /> <br /> <span style="color: #CC6600;">if</span>(barcodePos>(maxBarcodeSize-1)){ <span style="color: #7E7E7E;">// Check if maximum barcode length has been reached</span><br /> barcodeLength = barcodePos; <span style="color: #7E7E7E;">// Set the length of the barcode (used later)</span><br /> drawBarcode = <span style="color: #006699;">"yes"</span>; <span style="color: #7E7E7E;">// We can now draw the barcode</span><br /> }<br /> <br /> barcodePos++; <span style="color: #7E7E7E;">// Move to the next barcode digit </span><br /> }<br /> <br /> <span style="color: #CC6600;">if</span>(drawBarcode == <span style="color: #006699;">"yes"</span>){ <span style="color: #7E7E7E;">// Only draw the barcode when drawBarcode = "yes"</span><br /> <br /> <span style="color: #CC6600;">EPAPER</span>.<span style="color: #CC6600;">clear_sd</span>(); <span style="color: #7E7E7E;">// Clear the e-Paper panel in preparation for barcode</span><br /> xPosition = 15; <span style="color: #7E7E7E;">// Set the initial white-space on the left</span><br /> drawBCode(astrix, <span style="color: #006699;">' '</span>); <span style="color: #7E7E7E;">// Each barcode starts with an invisible *</span><br /> <br /> <span style="color: #CC6600;">for</span>(<span style="color: #CC6600;">int</span> digit=0; digit<barcodeLength; digit++){ <span style="color: #7E7E7E;">// Start drawing the barcode numbers</span><br /> drawBCode(barcodeDecimal[barcode[digit]], barcodeText[digit]); <span style="color: #7E7E7E;">// Call the drawBCode method (see below)</span><br /> }<br /> <br /> drawBCode(astrix, <span style="color: #006699;">' '</span>); <span style="color: #7E7E7E;">// Each barcode ends with an invisible *</span><br /> <span style="color: #CC6600;">EPAPER</span>.<span style="color: #CC6600;">display</span>(); <span style="color: #7E7E7E;">// Show the barcode image and text</span><br /> <br /> drawBarcode = <span style="color: #006699;">"no"</span>; <span style="color: #7E7E7E;">// Stop it from drawing again until next barcode sequence sent</span><br /> barcodePos=0; <span style="color: #7E7E7E;">// Re-initialise the position back to first digit (in preparation for the next barcode)</span><br /> }<br />}<br /><br /><br /><span style="color: #7E7E7E;">//The drawBCode method is the key method for drawing the barcode on the e-paper panel</span><br /><span style="color: #CC6600;">void</span> drawBCode(<span style="color: #CC6600;">int</span> bCode, <span style="color: #CC6600;">char</span> bCodeText){<br /> xPosition++; <span style="color: #7E7E7E;">// There is a white space between each digit</span><br /> <span style="color: #CC6600;">for</span> (<span style="color: #CC6600;">int</span> barPos = 11; barPos > -1; barPos--){ <span style="color: #7E7E7E;">// Cycle through the binary code for each digit. Each digit is made up of 11 bars</span><br /> xPosition++; <span style="color: #7E7E7E;">// Advance the xPosition to draw the next bar (white or black)</span><br /> <span style="color: #CC6600;">if</span>(<span style="color: #CC6600;">bitRead</span>(bCode, barPos)==1){ <span style="color: #7E7E7E;">// If the binary digit at this position is a 1, then draw a black line</span><br /> <span style="color: #CC6600;">EPAPER</span>.<span style="color: #CC6600;">drawVerticalLine</span>(xPosition, 10, 60); <span style="color: #7E7E7E;">// This draws the individual Bar (black - only)</span><br /> } <span style="color: #7E7E7E;">// If the binary digit is a 0, then it is left blank (or white).</span><br /> }<br /> <span style="color: #CC6600;">EPAPER</span>.<span style="color: #CC6600;">drawChar</span>(bCodeText, xPosition-9, 75); <span style="color: #7E7E7E;">// Draw the human readable (text) portion of the barcode</span><br />}<br /><br /><br /> <br /> <!-- End of Arduino Code --><br /> </pre> </td> </tr> </table></div></P> <BR /> <BR /> <P> <!-- Arduino Code Discussion --> There is something weird about the E-paper shield library which tends to display the word "temperature:" in the Serial monitor when opened, and with each serial transmission. Don't worry about this. Just ignore it.' </P> </div><!--separator --><img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /><P> <div style="text-align: justify;"> <!-- Concluding Comments --> This tutorial shows you how to create your own renewable barcodes. While this only handles numbers at this stage, it could just as easily be upgraded to handle text as well. If you liked this tutorial, please give it a google+ thumbs up, share it with your friends, or just write a comment. Thankyou for visiting my blog. </div> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> <div align="center"> If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br> <BR /> <BR /> Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br> Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br> Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.<br> </div> </P> <BR /> <BR /> <div align="center"> <div class="separator" style="clear: both; text-align: center;"> <a href="http://arduino.cc/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmuBeqll5_-ovWlmf5ncMAWNxQ05r_dYIb_ezswWonrTzqnBW1y3YiN4dFUImKVLrFfilGIPMMg5mMfHItxdei6Kqs4o9pvZsg3sucWXSUR5Lm-MDx3nhDHu_9oaZIKeFGLANQoz4Ge8c/s1600/ArduinoLogo.png" /></a> </div> </div> <BR /> <BR /> <BR /> <div> <P> <!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </P> </div> <P> However, if you do not have a google profile... <br>Feel free to share this page with your friends in any way you see fit. </P></P></P><br /><br /><br /><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" -->Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-67582527788882981862014-11-24T09:19:00.000-08:002016-03-19T10:53:41.250-07:00One in a millionJust quietly - I am really happy that this blog has reached over <span style="font-size: large;"><b><span style="font-size: small;">1 million page views</span></b> </span>!<br />I don't know what to say, but I feel like I should say something.<br /><br /><span style="font-size: x-large;">Thank you for visiting my blog.</span><br /><br />Here are the blog posts that have received most attention to date:<br />1. <a href="http://arduinobasics.blogspot.com/2012/11/arduinobasics-hc-sr04-ultrasonic-sensor.html" target="_blank">Ultrasonic sensor</a><br />2. <a href="http://arduinobasics.blogspot.com/2012/07/arduino-basics-simple-arduino-serial.html" target="_blank">Simple Arduino Serial Communication</a><br />3. <a href="http://arduinobasics.blogspot.com/2013/01/arduino-basics-bluetooth-tutorial.html" target="_blank">Bluetooth tutorial 1 </a><br />4. <a href="http://arduinobasics.blogspot.com/2013/03/arduino-basics-bluetooth-android.html" target="_blank">Bluetooth Android Processing</a><br />5. <a href="http://arduinobasics.blogspot.com/2013/05/sound-sensor.html" target="_blank">Sound Sensor</a><br />6. <a href="http://arduinobasics.blogspot.com/2014/06/433-mhz-rf-module-with-arduino-tutorial.html" target="_blank">433 MHz RF Module with Arduino : this one is rising FAST !</a><br />7. <a href="http://arduinobasics.blogspot.com/2012/05/reading-from-text-file-and-sending-to.html" target="_blank">Reading from a text file and sending to Arduino</a><br />8. <a href="http://arduinobasics.blogspot.com/2011/05/arduino-uno-flex-sensor-and-leds.html" target="_blank">Flex sensor and LEDs</a><br />9. <a href="http://arduinobasics.blogspot.com/2011/06/arduino-uno-photocell-sensing-light.html" target="_blank">PhotoCell - sensing light</a><br />10. <a href="http://arduinobasics.blogspot.com/2012/07/arduino-basics-simple-arduino-serial_09.html" target="_blank">Simple Arduino Serial Communication (Part 2) </a><br /><br /><br />For a list of all my projects - please visit my projects page:<br /><a href="http://arduinobasics.blogspot.com.au/p/arduino-basics-projects-page.html" target="_blank">ArduinoBasics Project Page</a><br /><br />If that is not enough, then perhaps you should visit the <a href="https://plus.google.com/u/0/b/107402020974762902161/communities/104815959638799239380" target="_blank">Arduino Tutorials Community</a> on Google+.<br />You are bound to find a project that sparks your interest, or perhaps you could even share your own !<br /><br />Feel free to leave your thoughts, suggestions or messages in the comments.<br />Or if you wish to send a confidential message to me - then I would advise to use the form on my <a href="http://arduinobasics.blogspot.com.au/p/feedback.html" target="_blank">Feedback page</a>. <br /><br />Thanks again for visiting, and good luck with your project and/or Arduino journey !!<br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7232366051486480286.post-52465259086254396122014-10-09T08:07:00.000-07:002016-03-19T10:53:41.260-07:00DIY Canon Intervalometer using Arduino<g:plusone></g:plusone> <div style="text-align: justify;"><img src="http://3.bp.blogspot.com/-CLXYtp2z5kY/VDeuBtFTIEI/AAAAAAAABKc/QCAd5jI9Tis/s1600/Arduino_Intervalomter.gif" height="360" style="border: 3px double white;" width="640" /> <br /><br /><div>An intervalometer allows you to take photos at set intervals to view a slow process in super fast speed. Watching paint dry is just as boring in fast motion as it is at normal speed, however, when you point your camera to the clouds in the sky, you can get some amazing effects.<br /> <br /> By taking a picture every 3 seconds, and then playing the sequence back at 30 frames a second, you will get to see a 10 minute event in just 7 seconds.To get a nice flowing motion picture, you need to get a good balance between the recording frame rate, and the play-back frame rate. <br /> <br /> <br /><div align="center"><img alt="Clouds moving over city" src="http://3.bp.blogspot.com/-wszniHJTV-A/VDFmzfEJYZI/AAAAAAAABIw/8FaTHqXF8uQ/s1600/PerthSkyAnimated.gif" height="222" style="border: 3px double white;" title="" width="400" /> </div><br /> <br /> The recording frame rate is limited by the amount of memory you have in your camera, the length of the captured event, battery charge, and the camera's general capabilities. The playback frame rate needs to be fast enough to prevent jittering, but not so fast that you lose the event in a blink of an eye. The more you practice with different subject matters, the more you get a feel for how long you need to keep the camera running and how long to leave between shots.<br /> <br /> When taking pictures of the clouds, you can generally use a 3-5 second frame rate, depending on their speed across the sky. To capture the flow of traffic, I would recommend a picture every 1-2 seconds. However, for really slow events like a plant growing, you may need to extend the frame capture rate significantly. You will get a better idea once you try it for yourself.<br /> <br /> <br /> <div align="center"><img alt="City Traffic" src="http://1.bp.blogspot.com/-YgGNOIcyK8M/VDFqmWNAT7I/AAAAAAAABI8/QSZjdrZD8bo/s1600/FreewayTraffic.gif" height="222" style="border: 3px double white;" title="" width="400" /> </div><br /> <br /> This tutorial follows on from the <a href="http://arduinobasics.blogspot.com/2014/09/arduino-selfie.html">Arduino selfie</a> tutorial, so you might notice some similarities. However, in this tutorial, we will have more control over the intervalometer by using a sliding potentiometer and an LED bar. The pin layout is slightly different from the Arduino Selfie tutorial - so best to start from scratch to avoid pin misconfigurations.<br /> </div><br /><span style="color: red;">Warning : Any circuit you build for your camera (including this one) is at your own risk. I will not take responsibility for any damage caused to any of your equipment. </span> <br /> <br />I found out that my <a href="https://www.canon.com.au/en-AU/Personal/Products/Cameras-and-Accessories/Digital-Cameras/PowerShot-SX50-HS">Canon Powershot SX50 HS</a> camera has a port on the side for a remote switch. In the "Optional Accessories" section of the <a href="https://www.canon.com.au/~/media/Product%20Brochures/Camera/Digital%20Compact%20Cameras/Powershot/DSC-PowerShot-SX50-HS-Brochure.ashx">camera brochure</a>, it identifies the remote switch model as <a href="https://www.canon.com.au/en-AU/Personal/Products/Cameras-and-Accessories/Accessories/DSLR-Camera-Accessories/Remote%20Control/RS60E3">RS-60E3</a>. I then looked up the model number on <a href="http://www.camerahacker.com/RS60-E3_pin-out/pin-out.php">this website</a> to find out the size of the jack (3 core, 2.5mm), and the pinout (Ground, focus and shutter) required to emulate the remote switch. Once I had this information, I was able to solder some really long wires to the jack and connect up the circuit (as described below). <br /> <br />I use <a href="http://timelapsetool.com/">Time-Lapse tool </a> to stitch all of the pictures together to create a movie/animation. <br /> <br />You will need to download and install the <a href="https://github.com/Seeed-Studio/Grove_LED_Bar">LED_Bar library</a> from Seeedstudio into your Arduino IDE libraries folder in order to use the LED Bar in this tutorial. For more information about the LED Bar - visit the <a href="http://www.seeedstudio.com/wiki/Grove_-_LED_Bar">LED Bar Seeed-Studio wiki.</a> <br /> <br /><br /><h4>Parts Required:</h4><br /><ul><li><a href="http://www.epictinker.com/Freetronics-Eleven-100-Arduino-Uno-Compatible-p/ard-1002.htm">Freetronics Eleven or (Arduino UNO compatible board)</a></li><li><a href="http://www.epictinker.com/Grove-Base-Shield-v1-3-p/sld01099p.htm">Grove Base Shield</a></li><li><a href="http://www.epictinker.com/Grove-Slide-Potentiometer-p/com05231p.htm">Grove Sliding Potentiometer</a></li><li><a href="http://www.epictinker.com/Grove-LED-Bar-p/led05031p.htm">Grove LED Bar</a></li><li><a href="http://www.epictinker.com/Grove-Universal-4-Pin-20cm-Cable-5pk-p/acc11317o.htm">Grove Universal 4 Pin 20cm Cable</a></li><li><a href="http://www.epictinker.com/4-Channel-5V-Relay-Module-p/it-pwr-4ch.htm">4 Channel Relay Module</a></li><li><a href="http://www.epictinker.com/RESK-Resistor-Kit-p/pro05242p.htm">2x 330 ohm resistors</a></li><li><a href="http://www.epictinker.com/Diode-Kit-p/com-dio1.htm">2 x diodes</a></li><li><a href="http://www.epictinker.com/Mini-Breadboard-4-5cmx3-5cm-p/str122c2m.htm">breadboard</a></li><li><a href="http://www.epictinker.com/Solderless-Breadboard-Jumper-Wire-Kit-p/cab-1008.htm">Jumper Wires (male to male)</a></li><li><a href="http://www.epictinker.com/40-Pin-Male-to-Female-Splittable-Jumpers-p/40pinmfjump.htm">Jumper Wires (female to male)</a></li><br /><li><a href="https://www.canon.com.au/en-AU/Personal/Products/Cameras-and-Accessories/Digital-Cameras/PowerShot-SX50-HS">Canon Powershot SX50 HS</a> - (<a href="https://www.canon.com.au/~/media/Product%20Brochures/Camera/Digital%20Compact%20Cameras/Powershot/DSC-PowerShot-SX50-HS-Brochure.ashx">here is the brochure</a>)</li><li><a href="http://www.jaycar.com.au/productView.asp?ID=PP0103">Three core, 2.5 mm Jack</a></li><br /> </ul><br /> <br /><br /> <br /><br /><h4>Fritzing Sketch</h4><br /> <!-- Fritzing Sketch here --> <div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-uEW4ABWtqoI/VDSOnv4ZfdI/AAAAAAAABJI/xR1H9q-QGjw/s1600/Intervalometer%2BFritzing%2Bsketch.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img src="http://1.bp.blogspot.com/-uEW4ABWtqoI/VDSOnv4ZfdI/AAAAAAAABJI/xR1H9q-QGjw/s1600/Intervalometer%2BFritzing%2Bsketch.png" style="border: 3px double white;" width="640" /></a> </div><br /> <br /> <div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-VMqzpGMyu4U/VBgpiDTLa8I/AAAAAAAABFw/83Dum50mKPg/s1600/Diode%2BRelay%2BSchematic2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img src="http://2.bp.blogspot.com/-VMqzpGMyu4U/VBgpiDTLa8I/AAAAAAAABFw/83Dum50mKPg/s1600/Diode%2BRelay%2BSchematic2.png" height="470" style="border: 3px double white;" width="640" /></a> </div><br /> <br /> <div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/--4SuVfTtn5c/VBgprPHHDsI/AAAAAAAABGM/X3yccReDq_c/s1600/Camera%2BConnections.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img src="http://1.bp.blogspot.com/--4SuVfTtn5c/VBgprPHHDsI/AAAAAAAABGM/X3yccReDq_c/s1600/Camera%2BConnections.png" height="478" style="border: 3px double white;" width="640" /></a> </div><br /> <br /> <div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-JgxaGXwjCS0/VDaa-KfYMPI/AAAAAAAABKE/an9RLPmLycI/s1600/2_5mm%2BJack%2Bon%2Bgrey.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img src="http://4.bp.blogspot.com/-JgxaGXwjCS0/VDaa-KfYMPI/AAAAAAAABKE/an9RLPmLycI/s1600/2_5mm%2BJack%2Bon%2Bgrey.png" height="284" style="border: 3px double white;" width="640" /></a> </div><br /><br /> <br /> <br /><br /><h4>Connection Tables</h4><br /> <br /> <!-- Connection Tables here --> Arduino to Relay Module:<br /> <br /> <div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-TOAwLyOhfbQ/VDaR1isV78I/AAAAAAAABJg/yOEX6qFmqV4/s1600/Arduino%2Bto%2BRelay%2BModule%2BConnections.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img src="http://2.bp.blogspot.com/-TOAwLyOhfbQ/VDaR1isV78I/AAAAAAAABJg/yOEX6qFmqV4/s1600/Arduino%2Bto%2BRelay%2BModule%2BConnections.png" height="262" style="border: 3px double white;" width="400" /></a> </div><br /> <br /> <br /> Relay Module to Camera:<br /> <br /> <div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-fDLjCDBmweY/VDaR2HlCdnI/AAAAAAAABJo/AwGLeZTjabA/s1600/Relay%2BModule%2Bto%2BCamera%2BConnections.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img src="http://4.bp.blogspot.com/-fDLjCDBmweY/VDaR2HlCdnI/AAAAAAAABJo/AwGLeZTjabA/s1600/Relay%2BModule%2Bto%2BCamera%2BConnections.png" height="228" style="border: 3px double white;" width="400" /></a> </div><br /> <br /> <br /> Arduino to Slide Potentiometer:<br /> <br /> <div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-DWjXlOBVik8/VDaR3Nzz3MI/AAAAAAAABJ0/7skf3qJ27JM/s1600/Arduino%2Bto%2BSlide%2BPotentiometer%2BConnections.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img src="http://2.bp.blogspot.com/-DWjXlOBVik8/VDaR3Nzz3MI/AAAAAAAABJ0/7skf3qJ27JM/s1600/Arduino%2Bto%2BSlide%2BPotentiometer%2BConnections.png" height="311" style="border: 3px double white;" width="400" /> </a> </div><br /> <br /> <br /> Arduino to LED Bar:<br /> <br /> <div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-1bL8GZOZ5og/VDaR2iGH3AI/AAAAAAAABJw/6neMkx7n2Ik/s1600/Arduino%2Bto%2BLED%2BBar%2BConnections.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img src="http://3.bp.blogspot.com/-1bL8GZOZ5og/VDaR2iGH3AI/AAAAAAAABJw/6neMkx7n2Ik/s1600/Arduino%2Bto%2BLED%2BBar%2BConnections.png" height="262" style="border: 3px double white;" width="400" /></a> </div><br /><br /> <br /> <br /><br /><h4>Arduino Sketch</h4><br /> <div style="background: #ffffff; border-width: .6em .3em .3em .3em; border: solid rgb(24,186,183); color: black; overflow: auto; padding: 0em 0em; width: auto;"><table> <tbody><tr> <td><pre style="background: rgb(24,186,183); line-height: 125%; margin: 0; width: 1.9em;"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br /> 10<br /> 11<br /> 12<br /> 13<br /> 14<br /> 15<br /> 16<br /> 17<br /> 18<br /> 19<br /> 20<br /> 21<br /> 22<br /> 23<br /> 24<br /> 25<br /> 26<br /> 27<br /> 28<br /> 29<br /> 30<br /> 31<br /> 32<br /> 33<br /> 34<br /> 35<br /> 36<br /> 37<br /> 38<br /> 39<br /> 40<br /> 41<br /> 42<br /> 43<br /> 44<br /> 45<br /> 46<br /> 47<br /> 48<br /> 49<br /> 50<br /> 51<br /> 52<br /> 53<br /> 54<br /> 55<br /> 56<br /> 57<br /> 58<br /> 59<br /> 60<br /> 61<br /> 62<br /> 63<br /> 64<br /> 65<br /> 66<br /> </pre></td> <td><pre style="line-height: 125%; margin: 0;"> <!-- INSERT ARDUINO CODE HERE --><br /><span style="color: #7e7e7e;">/* ===============================================================</span><br /><span style="color: #7e7e7e;"> Project: DIY Canon Intervalometer using Arduino</span><br /><span style="color: #7e7e7e;"> Author: Scott C</span><br /><span style="color: #7e7e7e;"> Created: 9th October 2014</span><br /><span style="color: #7e7e7e;"> Arduino IDE: 1.0.5</span><br /><span style="color: #7e7e7e;"> Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html</span><br /><span style="color: #7e7e7e;"> Description: Use Arduino as an intervalometer for Canon PowerShot SX50 HS</span><br /><span style="color: #7e7e7e;"> A slide potentiometer is used to control the time between photos.</span><br /><span style="color: #7e7e7e;"> The LED Bar is used to display the delay between photos.</span><br /><span style="color: #7e7e7e;"> A 3 core 2.5mm jack is used to connect the Arduino and Relay module to the Camera.</span><br /><span style="color: #7e7e7e;">================================================================== */</span><br /><br /> <span style="color: #7e7e7e;">/* You will need to download and install the LED_Bar library from here: https://github.com/Seeed-Studio/Grove_LED_Bar */</span><br /> #include <LED_Bar.h><br /><br /> <span style="color: #7e7e7e;">/* Connect 5V on Arduino to VCC on Relay Module</span><br /><span style="color: #7e7e7e;"> Connect GND on Arduino to GND on Relay Module */</span><br /><br /> #define CH1 7 <span style="color: #7e7e7e;">// Connect Digital Pin 7 on Arduino to CH1 on Relay Module</span><br /> #define CH3 6 <span style="color: #7e7e7e;">// Connect Digital Pin 6 on Arduino to CH3 on Relay Module</span><br /> <br /> <span style="color: #cc6600;">int</span> potPin=A0; <span style="color: #7e7e7e;">//Connect Slide potentiometer to Analog Pin 0 on Grove Base Shield</span><br /> <span style="color: #cc6600;">int</span> potValue=0; <span style="color: #7e7e7e;">//The variable used to hold the value of the potentiometer</span><br /><br /> LED_Bar bar1(9,8); <span style="color: #7e7e7e;">//Connect LED Bar to Digital I/O 8 on Grove base shield.</span><br /> <span style="color: #7e7e7e;">//The LED Bar actually uses digital pin 8 and 9.</span><br /><br /> <span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>(){ <br /> <span style="color: #cc6600;">pinMode</span>(CH1, <span style="color: #006699;">OUTPUT</span>);<br /> <span style="color: #cc6600;">pinMode</span>(CH3, <span style="color: #006699;">OUTPUT</span>);<br /> <br /> <span style="color: #7e7e7e;">//Turn OFF any power to the Relay channels</span><br /> <span style="color: #cc6600;">digitalWrite</span>(CH1,<span style="color: #006699;">LOW</span>);<br /> <span style="color: #cc6600;">digitalWrite</span>(CH3,<span style="color: #006699;">LOW</span>);<br /> <span style="color: #cc6600;">delay</span>(2000); <span style="color: #7e7e7e;">//Wait 2 seconds before starting sequence</span><br /> <br /> <span style="color: #7e7e7e;">//Focus camera by switching Relay 1</span><br /> <span style="color: #cc6600;">digitalWrite</span>(CH1, <span style="color: #006699;">HIGH</span>); <br /> <span style="color: #cc6600;">delay</span>(2000);<br /> <span style="color: #cc6600;">digitalWrite</span>(CH1, <span style="color: #006699;">LOW</span>); <span style="color: #7e7e7e;">//Stop focus</span><br /> <span style="color: #cc6600;">delay</span>(3000);<br /> }<br /><br /> <span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>(){<br /> <span style="color: #7e7e7e;">// Read the slide potentiometer and convert the reading to a value between 0 and 10. </span><br /> potValue=<span style="color: #cc6600;">constrain</span>(<span style="color: #cc6600;">map</span>(<span style="color: #cc6600;">analogRead</span>(potPin),0,1000,0,10),0,10);<br /> <br /> <span style="color: #7e7e7e;">//Use the pot value to create a visual count-down display on the LED bar.</span><br /> <span style="color: #cc6600;">for</span>(<span style="color: #cc6600;">int</span> i = potValue; i>0; i--){<br /> bar1.setLevel(i);<br /> <span style="color: #cc6600;">delay</span>(1000);<br /> }<br /> <br /> <span style="color: #7e7e7e;">//If the pot value is less than 1, then delay for 30 seconds.</span><br /> <span style="color: #cc6600;">if</span>(potValue<1){<br /> <span style="color: #cc6600;">delay</span>(30000); <br /> }<br /> <br /> <span style="color: #7e7e7e;">//Turn LED Bar off when taking photo</span><br /> bar1.setLevelReverse(0);<br /> <br /> <span style="color: #7e7e7e;">//Press shutter button for 0.1 seconds. Modify delay if required.</span><br /> <span style="color: #cc6600;">digitalWrite</span>(CH3, <span style="color: #006699;">HIGH</span>); <br /> <span style="color: #cc6600;">delay</span>(100);<br /> <span style="color: #cc6600;">digitalWrite</span>(CH3,<span style="color: #006699;">LOW</span>); <span style="color: #7e7e7e;">//Release shutter button </span><br /> }<br /> <!-- End of Arduino Code --><br /> </pre></td> </tr></tbody></table></div><br /><br /> <br /><!-- Arduino Code Discussion --> <br /><br /><h4>The Video</h4><br /> <div style="text-align: center;"><!-- Video Code --> <iframe allowfullscreen="" frameborder="0" height="480" src="//www.youtube.com/embed/2T02lamOhCo?rel=0" width="640"></iframe> </div><br /> </div><!--separator --><img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /><br /><div style="text-align: justify;"><!-- Concluding Comments --> This project shows how to make your Canon Powershot SX50 HS a whole lot smarter using an Arduino. There are so many things that look so different with an intervalometer. While I connected a slide potentiometer to the Arduino to provide extra flexibility, and an LED Bar for visual feedback, there are many other sensors out there that can be combined with the camera. For example, you could use a PIR sensor to take a picture when movement is detected. Or take a picture when a laser trip-wire is broken. What about sound activation, light activation, leak detection.... the options are limitless. <br /> <br />This has been one of my favorite projects, it was a lot of fun, and very interesting. <br />I highly recommend that you try it out! </div><div><!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </div><br /><div align="center">If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br /><br /> <br /> <br />Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br />Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br />Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.</div><br /> <br /> <br /> <div align="center"><div class="separator" style="clear: both; text-align: center;"><a href="http://arduino.cc/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmuBeqll5_-ovWlmf5ncMAWNxQ05r_dYIb_ezswWonrTzqnBW1y3YiN4dFUImKVLrFfilGIPMMg5mMfHItxdei6Kqs4o9pvZsg3sucWXSUR5Lm-MDx3nhDHu_9oaZIKeFGLANQoz4Ge8c/s1600/ArduinoLogo.png" /></a> </div></div><br /> <br /> <br /> <div><!--separator --> <img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" width="98%" /><br /> <br /> </div>However, if you do not have a google profile... <br />Feel free to share this page with your friends in any way you see fit. <br /> <br /><br /><br /><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8CIvl2tNAOib_tk_C2l0IzSCwiJdR_Twj41Gfa5RZDs3BTejN08lsq30_iei6fdcqoyA_XJWp2N9T2XD6Bm76FNIuzsbbf-cPySYd1MWhOxPxuxIyAG8EFIotWvf3Xv8dJ5TbyaEaxjM/s1600/Separator.jpg" -->Unknownnoreply@blogger.com0