tag:blogger.com,1999:blog-91207553434921641852024-03-05T16:30:05.826-06:00Matthew McMillanTech stuff, Sys Admin, Linux and whatever else I find of interest.Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.comBlogger51125tag:blogger.com,1999:blog-9120755343492164185.post-59570680352197166432016-06-06T21:45:00.001-05:002016-06-06T21:54:10.859-05:003D Printed Lamp Shade<div class="separator" style="clear: both; text-align: left;">
After I upgraded my Printrbot with the <a href="http://www.matrix-precision.com/collections/all" target="_blank">Matrix Precision</a> X,Y and Z upgrades I now have a build volume of 8"x8"x10" (203mm x 203mm x 250mm). The first thing I tried printing with the expanded print volume was a couple vases.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
First out of some junk PLA I'm trying to get rid of:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span id="goog_2038467443"></span><span id="goog_2038467444"></span><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/AVvXsEhQDqRPeqEJwIJaasgXUF03z2WwXX_yVEO_YrTYvUnCkk6HC8je5RG37ZJ13DUNmxgPk770YbbEFTN2QCYRPTVejc4RURzfUzJAd5z2xMCC75crE3bFApoJgE-fJqvuubHP58olKtIDVu8/s1600/IMG_7618.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQDqRPeqEJwIJaasgXUF03z2WwXX_yVEO_YrTYvUnCkk6HC8je5RG37ZJ13DUNmxgPk770YbbEFTN2QCYRPTVejc4RURzfUzJAd5z2xMCC75crE3bFApoJgE-fJqvuubHP58olKtIDVu8/s640/IMG_7618.JPG" width="480" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Blue PLA filament</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: left;">
Then I printed a bigger vase out of E3D's EDGE filament:</div>
<div class="separator" style="clear: both; text-align: left;">
<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/AVvXsEiIuSOUjrYRJVdNdjlIAIDVwiSAZ5ziqBtlfdVXLHsDG-fb29N_5xn8-0HTrpFO83AnZvKWWQAFL9ZoKZE4Z968lEwKRxJgGjXGd0rcuka7dPkSomEjy7hbubx9VLk-71NKxmHPoNx74Bo/s1600/IMG_7692.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIuSOUjrYRJVdNdjlIAIDVwiSAZ5ziqBtlfdVXLHsDG-fb29N_5xn8-0HTrpFO83AnZvKWWQAFL9ZoKZE4Z968lEwKRxJgGjXGd0rcuka7dPkSomEjy7hbubx9VLk-71NKxmHPoNx74Bo/s640/IMG_7692.JPG" width="480" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">E3D EDGE filament in green</td></tr>
</tbody></table>
I love the way the light shines through it and how the geometric shapes create interesting light and dark areas. I thought these vases might make a neat lamp so I decided as a test to make the blue PLA vase into a lamp to see how it would look.<br />
<br />
I had a couple of these IKEA lamp sockets laying around. They looked perfect for this.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhG7yY4roeaiMUeqsFfVLmd6IwP61dgvef8Ql5aaJH_jrCISdQA_9PBWVhLDHjrBaDQ9_HyRpFtRN1NBOj7K-4omTnGO0Q4hGoqS-T12SPpz9Dainv3xETb4cYbxI9d3oAx3CUcLmyFVCw/s1600/IMG_7731.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhG7yY4roeaiMUeqsFfVLmd6IwP61dgvef8Ql5aaJH_jrCISdQA_9PBWVhLDHjrBaDQ9_HyRpFtRN1NBOj7K-4omTnGO0Q4hGoqS-T12SPpz9Dainv3xETb4cYbxI9d3oAx3CUcLmyFVCw/s400/IMG_7731.JPG" width="400" /></a></div>
<br />
I drew lines from corner to corner to find the center. Then I used a stepped drill bit to drill a big hole. I used a half round file to take the hole out to the final size.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibH4qL1oR4GAI17WS3KVaMuQd0JdHZtSASJTKQzCqz9d7bPxVdJL9RAMwPL6A8BJmnZrr9OmQtgubOyD2816jgV9H0D2-dTLf8EIlD8xnaRADX1qjH2nO7iFLlbJ84LgvlmZ0fL6eGZxs/s1600/IMG_7730.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibH4qL1oR4GAI17WS3KVaMuQd0JdHZtSASJTKQzCqz9d7bPxVdJL9RAMwPL6A8BJmnZrr9OmQtgubOyD2816jgV9H0D2-dTLf8EIlD8xnaRADX1qjH2nO7iFLlbJ84LgvlmZ0fL6eGZxs/s400/IMG_7730.JPG" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
It was a bit of a tight fit getting my hand down in there to tighten the ring on to the lamp base.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhonzsV7QMoc4fQgOfuphouWRhLScW06Lp9udCGmhA9f6dzmEaWWJuhWws4Lq8HqMmIfyKgIDRCLH69qRXOyj44_8HpBZtC8WgIuqfdeHP7ZpEL1FQ2wR8sxBqgAOJsf2wo8GHTQjnI6kI/s1600/IMG_7732.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhonzsV7QMoc4fQgOfuphouWRhLScW06Lp9udCGmhA9f6dzmEaWWJuhWws4Lq8HqMmIfyKgIDRCLH69qRXOyj44_8HpBZtC8WgIuqfdeHP7ZpEL1FQ2wR8sxBqgAOJsf2wo8GHTQjnI6kI/s400/IMG_7732.JPG" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2UBDv6WMix_mVJHKW-gKo6u3xPNsCqLKYo5_zQ_NZen-bBnFMj0Fv3KyordfPWmBg33w-mUQ6fD02pfzHvIrPwQlKeWs35wWXYNxu2qms44qi5oC47c1C5WJVnXicZeAtU8VjxWIFBHE/s1600/IMG_7733.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2UBDv6WMix_mVJHKW-gKo6u3xPNsCqLKYo5_zQ_NZen-bBnFMj0Fv3KyordfPWmBg33w-mUQ6fD02pfzHvIrPwQlKeWs35wWXYNxu2qms44qi5oC47c1C5WJVnXicZeAtU8VjxWIFBHE/s400/IMG_7733.JPG" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
I hung it up in the garage just to test. Turn on the lamp and turned off the rest of the garage lights. Amazing!!</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxtc9IA3Qz3JuHk7TIZqPapDIGZbNTmLE_sclGGC5Ryp5SQwLLkqBbXNIFPgYKHxLvG__Rh5L07f4CnAE-ekx7WYF1y61tNsNLKBib5krwqm_2pGUv9z6icKaYSvAQp76xJb0EkfF72wE/s1600/IMG_7734.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxtc9IA3Qz3JuHk7TIZqPapDIGZbNTmLE_sclGGC5Ryp5SQwLLkqBbXNIFPgYKHxLvG__Rh5L07f4CnAE-ekx7WYF1y61tNsNLKBib5krwqm_2pGUv9z6icKaYSvAQp76xJb0EkfF72wE/s640/IMG_7734.JPG" width="480" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Here it is with the garage lights on</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaAS8oB8NkxDle6ayQF0-qOAPACjSwnGNh9FccPjoLxJaB8cWe6nkW6IEBXrVqUJpWUJl1iO5ux1DibG-OvFmQq7cJi5fsdVNk0TR8wLHr2_P60g8XAQO1FvBeA6coE7wUiDBz-xtSWIo/s1600/IMG_7735.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaAS8oB8NkxDle6ayQF0-qOAPACjSwnGNh9FccPjoLxJaB8cWe6nkW6IEBXrVqUJpWUJl1iO5ux1DibG-OvFmQq7cJi5fsdVNk0TR8wLHr2_P60g8XAQO1FvBeA6coE7wUiDBz-xtSWIo/s640/IMG_7735.JPG" width="480" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br />
I think I'm going to make three similar to this and hang them over the bar in my kitchen. I've been wanting to add more light there and I think something like this would look great.<br />
<br />
<br />Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com1tag:blogger.com,1999:blog-9120755343492164185.post-58517056436670265402015-12-20T21:14:00.000-06:002015-12-20T21:26:47.918-06:00Product Review: Itead Studio wifi controlled smart home electrical switches<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjYJBTwBAwkAoxJsMYNCLqUWMc6sWSZb_kGDmmhR12p9Yee3Bc-_LU9JJoaJUyReddt_iQl_UXIduV45NJeUc-ls3kHVahzs0E-mqcJfrHB2VRQX3CrzMVPOM7QZo6m7mWD4T1pGaaI2w/s1600/lteadLogo1sm.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjYJBTwBAwkAoxJsMYNCLqUWMc6sWSZb_kGDmmhR12p9Yee3Bc-_LU9JJoaJUyReddt_iQl_UXIduV45NJeUc-ls3kHVahzs0E-mqcJfrHB2VRQX3CrzMVPOM7QZo6m7mWD4T1pGaaI2w/s400/lteadLogo1sm.png" /></a><br />
<br />
The guys at <a href="https://www.itead.cc/" target="_blank">Itead Studios</a> are running an <a href="https://www.indiegogo.com/projects/sonoff-slampher-low-cost-smart-home-solution/" target="_blank">Indiegogo campaign</a> for a couple new smart home products they developed called the Sonoff and the Slampher. Itead asked me to write up a review in exchange for some free samples. I received the samples a few weeks back and they sat on my desk for a few days while I thought about what exactly I would do with them.<br />
<br />
<br />
<h4>
</h4>
<h4>
What are they?</h4>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiGhxiQ4JHrOhs5vC2cJBxyS1FbOCjIeYDsajUXeAQ_b_PHAjZ8fDKpjMU6ZwK8ZbVHouTxhLha0V5h_6mMrceXAvPW0LVD1KLQdCvtNZBsHF_wyBj0K4gDNslfTNTmtPJgPObk0JxM7U/s1600/FullSizeRender+3.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="278" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiGhxiQ4JHrOhs5vC2cJBxyS1FbOCjIeYDsajUXeAQ_b_PHAjZ8fDKpjMU6ZwK8ZbVHouTxhLha0V5h_6mMrceXAvPW0LVD1KLQdCvtNZBsHF_wyBj0K4gDNslfTNTmtPJgPObk0JxM7U/s320/FullSizeRender+3.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption"><div style="text-align: center;">
<span style="font-size: 12.8px;">Parts I received from Itead</span></div>
<div style="text-align: center;">
<br /></div>
</td></tr>
</tbody></table>
<div>
<br /></div>
<div>
When Itead was first talking with me about doing a review they kept calling the devices 'wifi switches' which really confused me. I thought they were talking about some sort of networking equipment. Once they sent me a link to the <a href="https://www.indiegogo.com/projects/sonoff-slampher-low-cost-smart-home-solution/" target="_blank">Indiegogo campaign</a> I finally understood. They are smart home switches for controlling lights and appliances. They reminded me a bit of the <a href="https://en.wikipedia.org/wiki/X10_(industry_standard)" target="_blank">old X10 systems</a> but the difference with the Itead devices is they connect to your wifi network. They also have the ability to be controlled and show you current state of the device on your smart phone even when you are away from the house. The devices check in with Itead's cloud service to update their state and check for commands. The devices respond to smart phone commands nearly instantly which is pretty impressive.</div>
<div>
<br /></div>
<div>
<br />
<h4>
<br />Smartphone app</h4>
<div>
Itead has an <a href="https://itunes.apple.com/us/app/ewelink/id1035163158" target="_blank">iPhone</a> and <a href="https://play.google.com/store/apps/details?id=com.coolkit&hl=en" target="_blank">Android</a> application called eWeLink for controlling and configuring the devices so I had to install that before I could setup either of them. Installing the app was easy enough but I ran into trouble trying to create an account. Elsie from Itead said the iOS app was very new and had a few bugs to be worked out. To create an account all you have to do is enter your mobile number, a password for your new account and touch 'Send verify code'. Itead is then supposed to send an SMS message with a verification code. I got an error when trying to do this. After a few e-mails back and forth with Itead they fixed some things and I was finally able to create an account. I believe they have these problems worked out now so it shouldn't be a problem for anyone else.</div>
</div>
<div>
<br /></div>
<table><tbody>
<tr><td><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/AVvXsEgJEioaxwU2SDIkFAYaH8MiJ9Y205nE9wqVGBE6s6W-fMd6GTCSqUk6MqhHNcp3jRug54-JMSNwwyOjAL-mzzFyJpslHr5inRTSl3d7cj2BGP-onYh4kUm6p_8f0SsBhczdYhRUswAAtfQ/s1600/IMG_6785.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJEioaxwU2SDIkFAYaH8MiJ9Y205nE9wqVGBE6s6W-fMd6GTCSqUk6MqhHNcp3jRug54-JMSNwwyOjAL-mzzFyJpslHr5inRTSl3d7cj2BGP-onYh4kUm6p_8f0SsBhczdYhRUswAAtfQ/s320/IMG_6785.PNG" width="180" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">eWeLink in the app store</td></tr>
</tbody></table>
</td><td><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/AVvXsEjJVM8fuZWHAwlme4i-_stWksY7j2C7SlSNFAi0QRFzlaVZjRi2GfGzIqxGiUJ0JVmFHlD8haevW1DEH-m9vy37nuZ_PcrgQnF0vAU1Fefx_ygGVGsFmfvzs13ZVF_q31HQVutUHF9Nau8/s1600/IMG_6813.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJVM8fuZWHAwlme4i-_stWksY7j2C7SlSNFAi0QRFzlaVZjRi2GfGzIqxGiUJ0JVmFHlD8haevW1DEH-m9vy37nuZ_PcrgQnF0vAU1Fefx_ygGVGsFmfvzs13ZVF_q31HQVutUHF9Nau8/s320/IMG_6813.PNG" width="180" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Creating an account</td></tr>
</tbody></table>
</td><td><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/AVvXsEgRq3WTcf5GtcQ1d1hEHQKbX4q62SCkvqZBh5V0tleZxFTRNyfxIZudts-t_B-d02C4TX7serlpKfLHLOyKGfgY8qXtfHcUus9gN-hwaYCIARQcP0xrYmrAJ4DU9NsCOr4gCaB_6WD7Q68/s1600/IMG_6812.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRq3WTcf5GtcQ1d1hEHQKbX4q62SCkvqZBh5V0tleZxFTRNyfxIZudts-t_B-d02C4TX7serlpKfLHLOyKGfgY8qXtfHcUus9gN-hwaYCIARQcP0xrYmrAJ4DU9NsCOr4gCaB_6WD7Q68/s320/IMG_6812.PNG" width="180" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Error :(</td></tr>
</tbody></table>
</td></tr>
</tbody></table>
<div>
<br />
<h4>
Adding devices</h4>
<br />
Initially I had a little trouble adding devices. This was due partially to the instructions in the iPhone app being a bit sparse and partially because I had this thought in my head that I was trying to connect to a bluetooth device. I e-mailed Elsie again and she replied with some better instructions. I now realized the devices are strictly wifi. In pairing mode the device creates a temporary wifi network. You connect your phone to this temporary wifi network and then use the app to configure the device.<br />
<br />
<table align="center"><tbody>
<tr><td><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/AVvXsEhArRBvYt8O1LHqIj11lOxHNBH-In7608M-swpoPsti2_9VIngTYcOy7TaUTFkSng90oKdzHjy8qMMdtunugV_bPkQ92uVZpSmugaNSxDUUQ0YkU3ENKnQJbg2zRd9ggQkNQMSXNmfGSgQ/s1600/IMG_6872.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhArRBvYt8O1LHqIj11lOxHNBH-In7608M-swpoPsti2_9VIngTYcOy7TaUTFkSng90oKdzHjy8qMMdtunugV_bPkQ92uVZpSmugaNSxDUUQ0YkU3ENKnQJbg2zRd9ggQkNQMSXNmfGSgQ/s200/IMG_6872.JPG" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Control button and Status LED locations</td></tr>
</tbody></table>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiJ9NhvV2HE-sTepI8CU0xbj-7fQfk23Y5SKQscMuel5z1SUOyPS8jKL_KsAaygsJQG1xRT9tRHDcml7gkIpTpKKcmBm0dTLpeCkbgG-G6mFKaomhOyFpk31jED706uZHNmjqTFfs9RQE/s1600/IMG_6871.JPG" imageanchor="1"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiJ9NhvV2HE-sTepI8CU0xbj-7fQfk23Y5SKQscMuel5z1SUOyPS8jKL_KsAaygsJQG1xRT9tRHDcml7gkIpTpKKcmBm0dTLpeCkbgG-G6mFKaomhOyFpk31jED706uZHNmjqTFfs9RQE/s320/IMG_6871.JPG" width="320" /></a>
</td></tr>
</tbody></table>
<br />
To put the device into pairing mode (and create the temp wifi network) press down on the control button for several seconds and release. The status LED will begin blinking rapidly indicating it is in pairing mode. Then join the wifi network named 'ITEAD-xxxxxxxx'. After that you go to the eWeLink app and add the device. The pairing process is just giving the device your wifi network SSID and password so it can join your network.<br />
<br />
<table align="center"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjoPP6fKn5qgLCzZokLC8IT_lxrN8OSegfNsat0J9o3Bh5gGJzp-HEFftbi_-GpRIiof1BhfRvDz7QpDxdoXU_0elRQjECljDFC7pqznN8DQ5wOUmcWmaurOBrxy6HIURL2wLmK9ddBs0/s1600/IMG_6869.PNG" imageanchor="1"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjoPP6fKn5qgLCzZokLC8IT_lxrN8OSegfNsat0J9o3Bh5gGJzp-HEFftbi_-GpRIiof1BhfRvDz7QpDxdoXU_0elRQjECljDFC7pqznN8DQ5wOUmcWmaurOBrxy6HIURL2wLmK9ddBs0/s320/IMG_6869.PNG" width="180" /></a>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKSUp3NKVnUV68LQNkHtGQ1LjowmxBck0pLvz3rcH2h0WL08PhC3FsO5b3YMySQxucdPrQAcfx2-gkJAcrpIgxQG7_4z6RMT5gvdPtDlCAnoCoO_qmyaiFmdXaiLrfpfTHgfwElWxtiVQ/s1600/IMG_6870.PNG" imageanchor="1"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKSUp3NKVnUV68LQNkHtGQ1LjowmxBck0pLvz3rcH2h0WL08PhC3FsO5b3YMySQxucdPrQAcfx2-gkJAcrpIgxQG7_4z6RMT5gvdPtDlCAnoCoO_qmyaiFmdXaiLrfpfTHgfwElWxtiVQ/s320/IMG_6870.PNG" width="180" /></a>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQbRshSAqi68t_TpuH_5dTuhspLBrKfS_upDFDSZ-DcrCTRQK77SaZiiZwShQLbEMdBvpiwkOxt838LKuv70_dThqEZ3Zs2wQjYMojttCZF-BKPbnLWmq2cHqqlywLDFqXgxYTKdME6UY/s1600/IMG_6868.PNG" imageanchor="1"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQbRshSAqi68t_TpuH_5dTuhspLBrKfS_upDFDSZ-DcrCTRQK77SaZiiZwShQLbEMdBvpiwkOxt838LKuv70_dThqEZ3Zs2wQjYMojttCZF-BKPbnLWmq2cHqqlywLDFqXgxYTKdME6UY/s320/IMG_6868.PNG" width="180" /></a>
</td></tr>
</tbody></table>
<br />
<br />
<h4>
Using the Slampher</h4>
<br />
I decided to try out the Slampher first since all I had to do was screw it into a light socket. I installed it in my bedside lamp. One issue with the Slampher is the height. I suppose it would will work fine with some lamps and not so great with others. Lamps with tall shades will probably work best. Once you install the Slampher you have to stop using the normal power switch on the lamp and start using the control button on the device instead (or the smartphone app). It is convenient they still give you the option to control the lamp locally in addition to the smart functionality.<br />
<br />
<table align="center"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiocbWECCkDsuq6VQORzkVQ-8pEHdnti5aDKp_NXougb5tmMWFF5c1KrYDazTnsBn92EDHaDJgOVjhwpg344t4p3xJKo9RVNp_USm6vS7rFwNq752sVRPxqMgExDD8X96e5xJ8jID-iYmw/s1600/IMG_6864.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiocbWECCkDsuq6VQORzkVQ-8pEHdnti5aDKp_NXougb5tmMWFF5c1KrYDazTnsBn92EDHaDJgOVjhwpg344t4p3xJKo9RVNp_USm6vS7rFwNq752sVRPxqMgExDD8X96e5xJ8jID-iYmw/s320/IMG_6864.JPG" width="240" /></a>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgpCMa8H7Mv-5nnDN0xAmqKWUpZSeCBLNZgQn0MCYDspCKixy8dTi7wGsl4do_agO3KwqOID32YUJCn9s5OG5hrIdvY7DZ3a2nNGbawaAcC8bdb8Xm5afBfxZJBSthp4zzlQKEg8NyFLc/s1600/IMG_6862.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgpCMa8H7Mv-5nnDN0xAmqKWUpZSeCBLNZgQn0MCYDspCKixy8dTi7wGsl4do_agO3KwqOID32YUJCn9s5OG5hrIdvY7DZ3a2nNGbawaAcC8bdb8Xm5afBfxZJBSthp4zzlQKEg8NyFLc/s320/IMG_6862.JPG" width="240" /></a>
</td></tr>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbcAQENA8pfDLZysu5A-t-eczMhGIxOqE5JvlQQZjbxay_L2-lfGkVYo95Geyg4oO3zgRrldnh1ietlXdu7aw3DEaUc6a9L6bTGfuwX4E1HXZhYxG_m6m8K1rUzAamVJ6WIcRXzqOm3gc/s1600/IMG_6861.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbcAQENA8pfDLZysu5A-t-eczMhGIxOqE5JvlQQZjbxay_L2-lfGkVYo95Geyg4oO3zgRrldnh1ietlXdu7aw3DEaUc6a9L6bTGfuwX4E1HXZhYxG_m6m8K1rUzAamVJ6WIcRXzqOm3gc/s320/IMG_6861.JPG" width="240" /></a>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihb3DtvuQlgBTau6cmzR-eo-GFLIovCt_2QetSBp7BoHgm0-bGE6Aj2SNR8rsjd1WH8yYsf9SY4rt3f1q1lAWE2uq3PHNJ2sSgljqCccOzPfWhYIaD-9xRzJdlK2_faPgJWZUaXLx2y3s/s1600/IMG_6865.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihb3DtvuQlgBTau6cmzR-eo-GFLIovCt_2QetSBp7BoHgm0-bGE6Aj2SNR8rsjd1WH8yYsf9SY4rt3f1q1lAWE2uq3PHNJ2sSgljqCccOzPfWhYIaD-9xRzJdlK2_faPgJWZUaXLx2y3s/s320/IMG_6865.JPG" width="240" /></a>
</td></tr>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIz64m138mT6NsK1cah43WexwzgHSQgMx48A2qD0C3LpOpxNTSLzQha7_JIbJNVEi0obISkkCzQ5AWpSYemVBk2vQZlGZuTM6q2XR8tTEYvpxuvWPzsvDBeW-aE_jx1DGTL9dwxsCC8ME/s1600/IMG_6866.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIz64m138mT6NsK1cah43WexwzgHSQgMx48A2qD0C3LpOpxNTSLzQha7_JIbJNVEi0obISkkCzQ5AWpSYemVBk2vQZlGZuTM6q2XR8tTEYvpxuvWPzsvDBeW-aE_jx1DGTL9dwxsCC8ME/s320/IMG_6866.JPG" width="240" /></a>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxdTA0dKL_miJ4SWRfVGDSJewWKiUkYJp83oNtKUWBlQFQKvI-OL2bu9VDs8-YE01Mxj2Lt4884RFVhPv_xRYF0UB5XXbTFKMQy1sQpei7MPshCTzVSnbCvQxxxw4AXdcZGUMs4g5gSOQ/s1600/IMG_6873.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxdTA0dKL_miJ4SWRfVGDSJewWKiUkYJp83oNtKUWBlQFQKvI-OL2bu9VDs8-YE01Mxj2Lt4884RFVhPv_xRYF0UB5XXbTFKMQy1sQpei7MPshCTzVSnbCvQxxxw4AXdcZGUMs4g5gSOQ/s320/IMG_6873.JPG" width="240" /></a>
</td></tr>
</tbody></table>
<br />
After adding the Slampher to my device list in the smartphone app I configured two timers. One that corresponds with my weekday alarm clock at 6am and another at 8pm every night. Timers are easy to configure and have flexible options that allow everyday, weekday, weekend or custom timers.<br />
<br />
<table align="left"><tbody>
<tr><td><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/AVvXsEjrlzEhrJT9hRY1TSoyJ2s0PRajL2PxlQ9_5IJzKqrTsArfUIqGut4auCF1hqNouaNhFLUJIFAHMtModScZ_S69NAZfrH8apVG_8LPdtwMPeWowtu8z6zrAj3M6OsiePZ2IWrz_FjNvFr4/s1600/IMG_6882.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrlzEhrJT9hRY1TSoyJ2s0PRajL2PxlQ9_5IJzKqrTsArfUIqGut4auCF1hqNouaNhFLUJIFAHMtModScZ_S69NAZfrH8apVG_8LPdtwMPeWowtu8z6zrAj3M6OsiePZ2IWrz_FjNvFr4/s320/IMG_6882.PNG" width="180" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Custom Timer</td></tr>
</tbody></table>
</td><td><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/AVvXsEhp6qERfJlglXGMUgVE0-bzmqd9kkmE3Zqg_0fx_aN4L70lnYoTF9l2zrT9oWwQ4hz6M0ywwTffIB8r-oI6F-vRLUV1qV2NLFSVmf9HiprojB5xlsjzOWjQj-sl7Xo7QhkakmMLhxfE93Q/s1600/IMG_6880.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhp6qERfJlglXGMUgVE0-bzmqd9kkmE3Zqg_0fx_aN4L70lnYoTF9l2zrT9oWwQ4hz6M0ywwTffIB8r-oI6F-vRLUV1qV2NLFSVmf9HiprojB5xlsjzOWjQj-sl7Xo7QhkakmMLhxfE93Q/s320/IMG_6880.PNG" width="180" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Lamp Off</td></tr>
</tbody></table>
</td><td><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/AVvXsEh3z8u_YmbooEz8El0sljZjsVIAvsjSUF358PGFlmC2rozhFaCDATkxCCIc7OvV8SD38ha7lGt3S7zJTM8jeSVD7uURr3KgVjCN_d2QMedpK3yS62EgvRqVgWzUPGuczLOxv0wSIQcgn-U/s1600/IMG_6881.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3z8u_YmbooEz8El0sljZjsVIAvsjSUF358PGFlmC2rozhFaCDATkxCCIc7OvV8SD38ha7lGt3S7zJTM8jeSVD7uURr3KgVjCN_d2QMedpK3yS62EgvRqVgWzUPGuczLOxv0wSIQcgn-U/s320/IMG_6881.PNG" width="180" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Lamp On</td></tr>
</tbody></table>
</td></tr>
</tbody></table>
The weekday morning timer is very effective at getting me up. Every morning I yell at my lamp "OK I'm up already!".<br />
<br />
<h4>
Using the Sonoff</h4>
<br />
The Sonoff is design to be used with an appliance of your choosing unlike the Slampher which is specifically for a light socket. It's a little more difficult to use because you have to do some wiring to utilize it. I didn't want to cut into the cord of any of my devices so I settled on cutting up an extra extension cord making it into a 'smart' extension cord :-). Make sure everything is unplugged before you go cutting into wires. K thx.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgObFyqctGarmawFprVQeLVGrxLSCrqEY2fVJhcVOUXEJvJ1wb83GdXVcznXnVUGCs3EJ1_Gl6gYUNsloEznqH4NilvW4Ct-2oehGBiFJZR2ewKrwbeWbyoAcWP6oYy9RxwxIAUSZ3ALc0/s1600/IMG_6851.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgObFyqctGarmawFprVQeLVGrxLSCrqEY2fVJhcVOUXEJvJ1wb83GdXVcznXnVUGCs3EJ1_Gl6gYUNsloEznqH4NilvW4Ct-2oehGBiFJZR2ewKrwbeWbyoAcWP6oYy9RxwxIAUSZ3ALc0/s320/IMG_6851.JPG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
I cut the extension cord in half and stripped the ends of the wires.</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF3FLiyTwBWd0jnNOqLbSeB3qCio8HwSDb6k40sDYU92IvwA9-l7MjLwf4s9bK234jB_NDhQYZ9NSqGD8m-OqdEw5ER9kv1OHXQcvng59_KGISNyn5ilwo7gLC0K1b1RthsbbcLhUjHBo/s1600/IMG_6852.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF3FLiyTwBWd0jnNOqLbSeB3qCio8HwSDb6k40sDYU92IvwA9-l7MjLwf4s9bK234jB_NDhQYZ9NSqGD8m-OqdEw5ER9kv1OHXQcvng59_KGISNyn5ilwo7gLC0K1b1RthsbbcLhUjHBo/s320/IMG_6852.JPG" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
I tinned the ends of the wires with my soldering iron to make sure I didn't have any stray strands that could short out.</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5ImlZddYLrFCfx8qf2EzehpACAuif8r1OnmK0sFdmgmn97ec1zUYcUdhGkDskysVmJeQOpLEBr1JDC1hRTZVBjfvu8ORj2tECXCZ4ZnqOpDpyfDl-MXSAJi_MuoNhrPDZG50LqRY7zvo/s1600/IMG_6854.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5ImlZddYLrFCfx8qf2EzehpACAuif8r1OnmK0sFdmgmn97ec1zUYcUdhGkDskysVmJeQOpLEBr1JDC1hRTZVBjfvu8ORj2tECXCZ4ZnqOpDpyfDl-MXSAJi_MuoNhrPDZG50LqRY7zvo/s320/IMG_6854.JPG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
The wires slide into terminal blocks and are tightened down with small flat blade screwdriver.</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTBNc-9fy1WAAGVFFFoX7lrZozHjPX5qTV1gUNIPD0c7hZYFr78MuwevvKRfuXj8w7UkRVSM0jvTuX38eV6O3Q2xxu_hJ2800NeC0YQlqHDVFrgrEkri_F2VGEk-dHABeu_LN5nhK59To/s1600/IMG_6855.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTBNc-9fy1WAAGVFFFoX7lrZozHjPX5qTV1gUNIPD0c7hZYFr78MuwevvKRfuXj8w7UkRVSM0jvTuX38eV6O3Q2xxu_hJ2800NeC0YQlqHDVFrgrEkri_F2VGEk-dHABeu_LN5nhK59To/s320/IMG_6855.JPG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
The samples I received didn't come with screws for the green cover plates. I think the covers are fairly important because you don't want exposed mains voltage! I had some screws on hand to attach the covers. I imagine the final product will come with screws. </div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgE3YX0CYFpTDwvrFdW74ZeuPqnMYeCBrSpxNCpeMQgoHDrYXV6Y9DS6DCjOHhptYszWtyLhHoJHm6UXVaEoPxtTao6G9ZGc9zITYIrhFJklaB_VKzRFm0l4ZZpaDiaKhCrhjnZyHALXI4/s1600/IMG_6856.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgE3YX0CYFpTDwvrFdW74ZeuPqnMYeCBrSpxNCpeMQgoHDrYXV6Y9DS6DCjOHhptYszWtyLhHoJHm6UXVaEoPxtTao6G9ZGc9zITYIrhFJklaB_VKzRFm0l4ZZpaDiaKhCrhjnZyHALXI4/s320/IMG_6856.JPG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
Finished. My 'smart' extension cord.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5etLe1YXb7TaL6kWr33g2GUM5RnrHuMaqn2cR752J6s7vWJMpZTNBWkurEVFZSoWD7wWRdyBN8qefJmoJv_VCP_8JX9BQVoHrxVufxaEuPIKbUeHEy2TVaiGrC5kYJyu24QVOa8w6NGA/s1600/IMG_6857.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5etLe1YXb7TaL6kWr33g2GUM5RnrHuMaqn2cR752J6s7vWJMpZTNBWkurEVFZSoWD7wWRdyBN8qefJmoJv_VCP_8JX9BQVoHrxVufxaEuPIKbUeHEy2TVaiGrC5kYJyu24QVOa8w6NGA/s320/IMG_6857.JPG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
I decided to use my new smart extension cord to control the lights on my fish tank. I set a timer to turn off the lights at 10:30pm and back on at 6am.<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/AVvXsEgp-v3wIHd0wmzQtN0bt9iLfnWU11XuMGUAhtC8g_Rvs7yGcT_mrBRhXvxuDRJ_knegjUIwbJkU9CSEqtceDBEfB_7ELpxTeJFu8l5GdXf-Oc8RLK-HjkQg0vUWDAcC1Up5hX0xFQICR5g/s1600/FullSizeRender+5.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp-v3wIHd0wmzQtN0bt9iLfnWU11XuMGUAhtC8g_Rvs7yGcT_mrBRhXvxuDRJ_knegjUIwbJkU9CSEqtceDBEfB_7ELpxTeJFu8l5GdXf-Oc8RLK-HjkQg0vUWDAcC1Up5hX0xFQICR5g/s400/FullSizeRender+5.jpg" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Happy fish</td></tr>
</tbody></table>
</div>
<h4>
Overall Impression</h4>
<div>
The devices work as advertised but the iOS app needs some work. Like I mentioned earlier I had trouble creating an account and the english translations for some things are awkward. The 1.0.5 version has improved the translations dramatically. The first version of the app I used still had Chinese characters for some items. I've been using the timers for a little over a week now and they have consistently worked. I really like the convenience of being able to turn off my bedside lamp from my phone at the breakfast table if I forget to do it before heading downstairs. The pricing in their <a href="https://www.indiegogo.com/projects/sonoff-slampher-low-cost-smart-home-solution/" target="_blank">Indiegogo campaign</a> is significantly cheaper than comparable devices from other manufacturers.</div>
<div>
<br /></div>
<div>
A downside to these devices is that they only work when you have an internet connection but I think for most people who would want to use a 'smart' device that wouldn't be problem. A bigger concern I have is that these devices are completely reliant on Itead's cloud service for smartphone control and the timers. If that service is shutdown these devices become bricks.</div>
<div>
<br /></div>
<div>
The Sonoff and Slampher are a good start but I think a device that could replace a wall switch would be the most useful to me. Something like this:</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV-SwH4gwylSC-Yc2x_EQ_WElpwG2vcS9WrAObJkYx8o6mnDYfUJpEIURHljd-rLwbzZsHqoiNSaLcH1Mw8YCa6YQeLAFouGq56I-7exYaltzag8xfEFBG-EZuS8nywpLt_47P9ALaq8A/s1600/Screenshot+2015-12-20+21.01.22.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV-SwH4gwylSC-Yc2x_EQ_WElpwG2vcS9WrAObJkYx8o6mnDYfUJpEIURHljd-rLwbzZsHqoiNSaLcH1Mw8YCa6YQeLAFouGq56I-7exYaltzag8xfEFBG-EZuS8nywpLt_47P9ALaq8A/s320/Screenshot+2015-12-20+21.01.22.png" width="282" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<b>Useful links</b></div>
<div>
<a href="https://www.itead.cc/">https://www.itead.cc/</a></div>
<div>
<a href="https://www.indiegogo.com/projects/sonoff-slampher-low-cost-smart-home-solution/">https://www.indiegogo.com/projects/sonoff-slampher-low-cost-smart-home-solution/</a></div>
<div>
<a href="http://www.smarthome.com/lights-appliances/plug-in-modules/plug-in-on-off-modules.html">http://www.smarthome.com/lights-appliances/plug-in-modules/plug-in-on-off-modules.html</a></div>
<div>
<a href="http://www.smarthome.com/lights-appliances/switches/on-off-switches.html">http://www.smarthome.com/lights-appliances/switches/on-off-switches.html</a></div>
Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com2tag:blogger.com,1999:blog-9120755343492164185.post-73653032919513751412015-09-27T19:16:00.001-05:002015-09-29T09:28:40.895-05:00BLE controlled Minecraft nightlight <div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" /></a></div>
A few months ago my daughter asked me to print something for her on my 3D printer. I asked her what she wanted and she said "something Minecraft". We started looking at designs on <a href="http://www.thingiverse.com/" target="_blank">thingiverse</a> and came across a <a href="http://www.thingiverse.com/thing:524925" target="_blank">design for a Mincraft ore block</a>. I thought it might be cool to make a night light out of it using <a href="http://www.adafruit.com/categories/168" target="_blank">Adafruit Neopixel</a> LED strips and an <a href="https://www.adafruit.com/products/2000" target="_blank">Adafruit Pro Trinket</a> microcontroller to change the colors. I ended up having a bit of <a href="https://en.wikipedia.org/wiki/Scope_creep" target="_blank">scope creep</a> on this project and it took way longer than I expected but the end result was pretty neat and I learned some new things. Originally I was just going to program the Arduino to cycle through colors but then I came across the <a href="http://www.adafruit.com/products/1697" target="_blank">Adafruit Bluefruit LE breakout board</a> and realized it would be fairly easy to add BLE control to the project. In the end this was the most involved Arduino coding project I've done so far. At the bottom of this post there are links to download the 3D models and Arduino code if you want to build one yourself.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTFaB-gPw0z0_RWfE1aznttboTIhL6DDfQiztYrx6UBS0u_MAhZUj7FxqL_g2TlscSLhewFfcIxbBY8IUGt_ujFlb9Ffgp-ioQ6N92BB_-4BQWtP9T6w2T0VoZjdz23auxsbf8NItOahw/s1600/IMG_6448.GIF" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTFaB-gPw0z0_RWfE1aznttboTIhL6DDfQiztYrx6UBS0u_MAhZUj7FxqL_g2TlscSLhewFfcIxbBY8IUGt_ujFlb9Ffgp-ioQ6N92BB_-4BQWtP9T6w2T0VoZjdz23auxsbf8NItOahw/s400/IMG_6448.GIF" width="400" /></a></div>
<br />
<br />
<br />
<h4>
<span style="font-weight: normal;">
3D Printing</span></h4>
<br />
The first step in this project was to 3D print the plastic parts. I printed the cube at 1.5 times the original size which made the final dimensions 105mm on each side. I had to print it with supports for the holes and a brim to minimize lifting from the print bed. It took almost 18 hours to print it. After it was done printing I realized there wasn't good way to attach a base to the cube (other than glue) so I used OpenSCAD to add recessed corner posts with screw holes and reprinted it.<br />
<br />
<table align="center"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgT0AQsc8zOyjlRguWL9XazAxk8j_9YzQuP7s0NBpQthTywKyF_ZTPJPN3Jj6QiQyEt8zPyqFua4afzm_qwlmVCJG-5uUpcGibJxWVXWstJXVQjlV7huAVJI0QzoNd1uOARqxMlctI-5E/s1600/IMG_6472.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgT0AQsc8zOyjlRguWL9XazAxk8j_9YzQuP7s0NBpQthTywKyF_ZTPJPN3Jj6QiQyEt8zPyqFua4afzm_qwlmVCJG-5uUpcGibJxWVXWstJXVQjlV7huAVJI0QzoNd1uOARqxMlctI-5E/s200/IMG_6472.JPG" width="150" /></a>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8_0HFkOhoPlXh79OL4kKmJ-xUOc5FZ-nhzOQAaQZSFBdUl6Kikv_UjvGpfgl8Qg6_AiKBGV4Twl1RGct3lxspwIVHV3yr0jhrsgsO1TA90tW-8n7wuQsCIc2U2No_p2lq-fiVeLwyVyY/s1600/Screenshot+2015-09-18+16.27.44.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8_0HFkOhoPlXh79OL4kKmJ-xUOc5FZ-nhzOQAaQZSFBdUl6Kikv_UjvGpfgl8Qg6_AiKBGV4Twl1RGct3lxspwIVHV3yr0jhrsgsO1TA90tW-8n7wuQsCIc2U2No_p2lq-fiVeLwyVyY/s200/Screenshot+2015-09-18+16.27.44.png" width="200" /></a></td></tr>
</tbody></table>
<br />
I used FreeCAD to design an insert that fits inside the cube. The LED strips sit in the channels and the electronics go in the square opening on the bottom.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBLK03g61wcNVRqXbQHkXRWz5AYQVdd8VPr-whdwCnSiDiJYW5X1tQN2c5FwdjF2waRKz5Q30eU6C3McCam7_VaE3v5lbtdB0B1gHt9SSuwrTd13FlEtyFGR2x6E-nIh7ttNo0WQJjfng/s1600/Screenshot+2015-09-19+12.49.13.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="323" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBLK03g61wcNVRqXbQHkXRWz5AYQVdd8VPr-whdwCnSiDiJYW5X1tQN2c5FwdjF2waRKz5Q30eU6C3McCam7_VaE3v5lbtdB0B1gHt9SSuwrTd13FlEtyFGR2x6E-nIh7ttNo0WQJjfng/s400/Screenshot+2015-09-19+12.49.13.png" width="400" /></a></div>
<br />
<br />
<table align="center" border="0">
<tbody>
<tr>
<td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuuK12HwYSZb3EMLKFdFDhX_N2x52M4BjzNbabWJGDbQQsoXJ2b9AneE0KjRJbrfOHqjTgYWyCHR-rYiZwaHlf9HAPfUTXNcRO5uPwccqmR8v-eiIPZ9v_xYWarRwUvEViR0pa56tio3k/s1600/IMG_6323.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuuK12HwYSZb3EMLKFdFDhX_N2x52M4BjzNbabWJGDbQQsoXJ2b9AneE0KjRJbrfOHqjTgYWyCHR-rYiZwaHlf9HAPfUTXNcRO5uPwccqmR8v-eiIPZ9v_xYWarRwUvEViR0pa56tio3k/s320/IMG_6323.JPG" width="240" /></a>
</td>
<td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS0AhmR2Y4RDVJF9tpHdusAFwEiihyLUP85izup6XZGJQEQnPIYg_2TVej3RVNSu8lLyH_Bsa34WJhVtEKCewgPxo6bTx2apPCtEM-nwsJ1kRLK6Z5huVAGRebz5TvjE2ZGVDIixJFvao/s1600/IMG_6324.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS0AhmR2Y4RDVJF9tpHdusAFwEiihyLUP85izup6XZGJQEQnPIYg_2TVej3RVNSu8lLyH_Bsa34WJhVtEKCewgPxo6bTx2apPCtEM-nwsJ1kRLK6Z5huVAGRebz5TvjE2ZGVDIixJFvao/s320/IMG_6324.JPG" width="240" /></a>
</td></tr>
</tbody></table>
<br />
<br />
<br />
<h4>
<span style="font-weight: normal;">Diffuser panels</span></h4>
<br />
With the 3D printing done the next step was to make some diffuser panels to go on the inside of the cube so you don't see the individual LEDs. I considered 3D printing the diffusers out of natural filament but that would have taken several hours. I had some scrap plexiglass in the garage so I cut out pieces to fit the top and four sides. I sanded both sides of the plexi with 80 grit sandpaper to make them opaque. I tested the diffusers with the LED flash light on my iPhone and they seemed to work pretty well.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXwNJq0qrCfhIPRpE-IfyRDFecp1HndoMm744b6rfo4tQxBjwqz6cvgLIzV93mHIEZjDHwvjimenkJ2lrBnKFimyVO5nCk27LtfksbKEImwLtJ-dA_YjOec-0rOw8e7jxH7J8eedW4Cg8/s1600/IMG_6160.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXwNJq0qrCfhIPRpE-IfyRDFecp1HndoMm744b6rfo4tQxBjwqz6cvgLIzV93mHIEZjDHwvjimenkJ2lrBnKFimyVO5nCk27LtfksbKEImwLtJ-dA_YjOec-0rOw8e7jxH7J8eedW4Cg8/s400/IMG_6160.JPG" width="400" /></a></div>
<br />
<table align="center"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2oOivDxT644S2k4SDsbKgyD7JsprUhR1xXDdQG0cSttZPNoxx4LXfzBpT7OxVir6QX1TvXHs7hDZkh_V42Gj8TEqq04vJx-OzOBMzwPDtuL8l5vlvgV_1mvGcBPEhUOuzemiJaTOpj-Y/s1600/IMG_6162.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2oOivDxT644S2k4SDsbKgyD7JsprUhR1xXDdQG0cSttZPNoxx4LXfzBpT7OxVir6QX1TvXHs7hDZkh_V42Gj8TEqq04vJx-OzOBMzwPDtuL8l5vlvgV_1mvGcBPEhUOuzemiJaTOpj-Y/s200/IMG_6162.JPG" width="200" /></a>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDZyQtsdffXyg0kQb3UmyhM9ugej0jLpjj7zvhY1xrUq2-sFKhMNxe_rsmMpKAYR7Z257hyphenhyphenND5GO7UzlmigtLHt4h_RUyEE-xjGCRqh7yiLS0Z3GwP5YBwEfw109sDohyphenhyphenyGV2xIudhM2Q/s1600/IMG_6163.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDZyQtsdffXyg0kQb3UmyhM9ugej0jLpjj7zvhY1xrUq2-sFKhMNxe_rsmMpKAYR7Z257hyphenhyphenND5GO7UzlmigtLHt4h_RUyEE-xjGCRqh7yiLS0Z3GwP5YBwEfw109sDohyphenhyphenyGV2xIudhM2Q/s200/IMG_6163.JPG" width="200" /></a>
</td></tr>
</tbody></table>
<br />
<br />
<br />
<h4>
<span style="font-weight: normal;">Assembling and wiring the insert</span></h4>
<br />
The first step in assembling the insert was to cut and solder the LED strips. Adafruit Neopixel LED strips can be cut with scissors. There are cut lines printed on the strip between each LED. I designed the insert to fit three LEDs on each side and five on top. To minimize the number of jump wires I would need to solder I cut three strips and bent them around the edges.<br />
<br />
<table align="center"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB_9CsNJH33HQzYt2H82qOJIjGdBf_cIpQPvqNEL5HEY4P7J6CcigAmU_3Hd07_lkbQqJaxlaBhSltlgFVvde5j_jQDhiLWJbF-fjyps5Nu_73EZAhOuD6WFabRF5osJzdFqTpV7LWN7M/s1600/IMG_6476.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB_9CsNJH33HQzYt2H82qOJIjGdBf_cIpQPvqNEL5HEY4P7J6CcigAmU_3Hd07_lkbQqJaxlaBhSltlgFVvde5j_jQDhiLWJbF-fjyps5Nu_73EZAhOuD6WFabRF5osJzdFqTpV7LWN7M/s320/IMG_6476.JPG" width="240" /></a>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiSo9i4jwc3ETYDFFAMo-MnPp47zns1x-K4lVbJfqerir3P2KCJLs7RgGVA1M0Skaz88w7irM_nKRlD5JNEVbLJa8TebX9EhTg7Uu9-5B6gJMt0L8t1JISctZmVgkKcsUWmuOwPsMPeE4/s1600/IMG_6325.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiSo9i4jwc3ETYDFFAMo-MnPp47zns1x-K4lVbJfqerir3P2KCJLs7RgGVA1M0Skaz88w7irM_nKRlD5JNEVbLJa8TebX9EhTg7Uu9-5B6gJMt0L8t1JISctZmVgkKcsUWmuOwPsMPeE4/s320/IMG_6325.JPG" width="240" /></a>
</td></tr>
</tbody></table>
<br />
I used the tip of my soldering iron to melt holes for the wiring to pass through to the center of the insert. With the strips set in place I soldered jumper wires onto the end of the LED strips, passing the wires through the holes so the wires were on the inside of the insert and not getting in the way of the LEDs. Then I used hot glue to attach the LED strips to the insert. The Neopixels are addressed by numbers starting with zero for the first LED on the strip so they need to be wired back up as a continuous strip. The strips are also directional so you need to pay attention to the arrows on the strips, wiring them so the arrows all face the same direction. I put a female header on the end of the of the strip wiring so I could plug it into the circuit board.<br />
<br />
<table align="center"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4i60T0-Yomu7bxkfc5U_2EtWL-JSU1GTqsxgofLDAy1PkNfm-qkRfuEK_BizRijwPqT3jVJuz94PGLlLMeNX6U-NFyK4YQ_EvjbXbMhNk6f1rwfNw_emXvLGkHs1mSpFNBQRafLd9ZQg/s1600/IMG_6327.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4i60T0-Yomu7bxkfc5U_2EtWL-JSU1GTqsxgofLDAy1PkNfm-qkRfuEK_BizRijwPqT3jVJuz94PGLlLMeNX6U-NFyK4YQ_EvjbXbMhNk6f1rwfNw_emXvLGkHs1mSpFNBQRafLd9ZQg/s320/IMG_6327.JPG" width="240" /></a>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFwaS2dyihq7lXkX6JzjWzh3DHN_g5a0tXY5yhjDAMpFhZd9IVvkvy-R1iCCTNym71OawcdBkC0Gxzhpcnz4ocSGK5neveJFW9rp5AGiYgCoOTq5wVxliCF2DjI3Wq128t8XR6mWK3C4g/s1600/IMG_6328.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFwaS2dyihq7lXkX6JzjWzh3DHN_g5a0tXY5yhjDAMpFhZd9IVvkvy-R1iCCTNym71OawcdBkC0Gxzhpcnz4ocSGK5neveJFW9rp5AGiYgCoOTq5wVxliCF2DjI3Wq128t8XR6mWK3C4g/s320/IMG_6328.JPG" width="240" /></a>
</td></tr>
</tbody></table>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2NpFzqnH84LwrhRr8EmeFmfo8gMzDYbhV8qoSCLd6faAHFZRSINtTHV4qcfl4TT_t8qt8uPr9QP_Mao2X_ILsEeRDrvtqz-xdEa0ZvM3ZGoadeM1NJb71ioQEytV9k9-20b8hWGT8lw/s1600/IMG_6326.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2NpFzqnH84LwrhRr8EmeFmfo8gMzDYbhV8qoSCLd6faAHFZRSINtTHV4qcfl4TT_t8qt8uPr9QP_Mao2X_ILsEeRDrvtqz-xdEa0ZvM3ZGoadeM1NJb71ioQEytV9k9-20b8hWGT8lw/s640/IMG_6326.JPG" width="480" /></a></div>
<br />
<br />
<br />
<br />
<h4>
<span style="font-weight: normal;">Breadboarding the control circuit</span></h4>
<br />
I hooked up the circuit on a breadboard to test it out before soldering. Controlling the LEDs only requires one digital pin. The BLE breakout board communicates over SPI.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0Rmh4qX4A_IqbTrZMHLUzxSoeJTdZpjqyUbJ6M4wPaZO8O2XGALB7AXQA9mVNy5R105c1cRdEZ6mrzOIdtbraP9Jf0BOUvzGCOEtYWNnqAN1IGAuyq2deNE1Gx2AvBV2geE1svmUCOLM/s1600/Minecraft_Cube_bb.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="397" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0Rmh4qX4A_IqbTrZMHLUzxSoeJTdZpjqyUbJ6M4wPaZO8O2XGALB7AXQA9mVNy5R105c1cRdEZ6mrzOIdtbraP9Jf0BOUvzGCOEtYWNnqAN1IGAuyq2deNE1Gx2AvBV2geE1svmUCOLM/s400/Minecraft_Cube_bb.png" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjguPI9hKyogd07pf8_bL7CFibL2hYYfNK_7Rkm9llrYMH0_AHV217fZBfoqDWR_s_CcJ6k4-xs-HWEc_zHG0zjvLO3Fs7b_stiMs6PGJbsRyBeOYgMjbIVcH-W9Mgx97tqFeOzyfrFLFc/s1600/IMG_6339.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjguPI9hKyogd07pf8_bL7CFibL2hYYfNK_7Rkm9llrYMH0_AHV217fZBfoqDWR_s_CcJ6k4-xs-HWEc_zHG0zjvLO3Fs7b_stiMs6PGJbsRyBeOYgMjbIVcH-W9Mgx97tqFeOzyfrFLFc/s400/IMG_6339.JPG" width="400" /></a></div>
<br />
Once I had everything wired up I loaded the Adafruit_NeoPixel strandtest example code to make sure all my LEDs were working correctly.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifwSEm6r7nzM_VS_YNySNSWyYGXVmKPgSbxAclNcFlRNQX_uK0-YIfX-bhJd69izljBfR0IRG9K2Whyphenhyphen7VgQTcWQ0QCa0D6O7LUACp7fQW7n6Te1ZpmEcGgePGJQPxMq0LIYfZwPVWlfms/s1600/IMG_6329.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifwSEm6r7nzM_VS_YNySNSWyYGXVmKPgSbxAclNcFlRNQX_uK0-YIfX-bhJd69izljBfR0IRG9K2Whyphenhyphen7VgQTcWQ0QCa0D6O7LUACp7fQW7n6Te1ZpmEcGgePGJQPxMq0LIYfZwPVWlfms/s400/IMG_6329.JPG" width="300" /></a></div>
<br />
<br />
<h4>
<span style="font-weight: normal;">Soldering the control board</span></h4>
<br />
The two main components of the control board are the Pro Trinket microcontroller and the Bluefruit BLE breakout board. I decided to use headers so the microcontroller and BLE chip can be easily replaced if needed. I started with a <a href="http://www.adafruit.com/product/1609" target="_blank">half-size Adafruit Perma-Proto broad</a>. To make the control circuit as compact as possible I placed the Pro Trinket on one side and the BLE board on the other. To do this I needed to cut the traces for a few holes. I used an X-ACTO to cut and scrape the traces. I used my multimeter to verify there was no continuity.<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/AVvXsEhLCzbSedUZV5FbXJc8Cm6whTl8MmcrTIJ9tE_NezlkH1aabevQUD9OEn13nm9lpJnJg8WNwaDxQ_DtzXGtKTRkn4IH2rN1sKPy2iF57L883gudCXGaI_sjCwc7-7rzKisbZgDDrAoED4s/s1600/IMG_6340.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLCzbSedUZV5FbXJc8Cm6whTl8MmcrTIJ9tE_NezlkH1aabevQUD9OEn13nm9lpJnJg8WNwaDxQ_DtzXGtKTRkn4IH2rN1sKPy2iF57L883gudCXGaI_sjCwc7-7rzKisbZgDDrAoED4s/s320/IMG_6340.JPG" width="240" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Cutting the traces on the Perma-Proto board</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
</div>
After cutting the traces I soldered on the headers for the Pro Trinket and the BLE breakout.<br />
<br />
<table align="center"><tbody>
<tr><td><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/AVvXsEhaUhGxzT1AlQVsQwFquc2MsMBQjTdRxrcsX_89duXl977c8gROUpvrvSRZnWRr8SrIjexIf8UH-fnm3w7ZAqGsKTZPkPOyG0A3VyPDqVmOCyhBloDK1-DDoAqymzdRoyZfQMjcPLorNPk/s1600/IMG_6341.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaUhGxzT1AlQVsQwFquc2MsMBQjTdRxrcsX_89duXl977c8gROUpvrvSRZnWRr8SrIjexIf8UH-fnm3w7ZAqGsKTZPkPOyG0A3VyPDqVmOCyhBloDK1-DDoAqymzdRoyZfQMjcPLorNPk/s320/IMG_6341.JPG" width="240" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Pro Trinket plugged into its headers</td></tr>
</tbody></table>
</td><td><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/AVvXsEj_cOy4QaQonzFYFDssM3X_m63jHlcTpDviDmBlcVj_p9VPzdXVx0FuZZsm9GnrYA3unKwgIsZA6ZrsSlIYQeERodeODmmz6zpC6hW3WFmhCKAxytSCclAlgCmu2cy9TVZ80Xmo2Dj1uwY/s1600/IMG_6342.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_cOy4QaQonzFYFDssM3X_m63jHlcTpDviDmBlcVj_p9VPzdXVx0FuZZsm9GnrYA3unKwgIsZA6ZrsSlIYQeERodeODmmz6zpC6hW3WFmhCKAxytSCclAlgCmu2cy9TVZ80Xmo2Dj1uwY/s320/IMG_6342.JPG" width="240" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">BLE board plugged into its header</td></tr>
</tbody></table>
</td></tr>
</tbody></table>
<br />
I finished up the wiring between the microcontroller and BLE board and added some male headers for connecting the LEDs and power input. After that I used a Dremel to cut down the proto-board as small as possible.<br />
<br />
<table align="center"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaeflnWfoe_h125a5sx6W2m7Zjuwp9EdKsWwDsOpA90I_yKz6R6cCBlLAyU-EKVVVgB75WuL8dBT5RM2JhUVG7LLYLWVXpP4SHap60E4zgEiWOdhfM-eGH85audapH1T6RLdYeAdkKFic/s1600/IMG_6347.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaeflnWfoe_h125a5sx6W2m7Zjuwp9EdKsWwDsOpA90I_yKz6R6cCBlLAyU-EKVVVgB75WuL8dBT5RM2JhUVG7LLYLWVXpP4SHap60E4zgEiWOdhfM-eGH85audapH1T6RLdYeAdkKFic/s320/IMG_6347.JPG" width="240" /></a>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPtj1X9QNtQGCLABU3E90pJxaEBmfaPZDwNoAoWXVHuqXk7CPNlij1wfSe1USP1kOv9MEVB4jfl4TFRaPPVOIKvy2UmnEf9bHbK0lKrzSFxCXdnKXYLgwvsE4YOkkh8IORXuibQDupo6c/s1600/IMG_6349.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPtj1X9QNtQGCLABU3E90pJxaEBmfaPZDwNoAoWXVHuqXk7CPNlij1wfSe1USP1kOv9MEVB4jfl4TFRaPPVOIKvy2UmnEf9bHbK0lKrzSFxCXdnKXYLgwvsE4YOkkh8IORXuibQDupo6c/s320/IMG_6349.JPG" width="240" /></a>
</td></tr>
</tbody></table>
<br />
Here is the finished control circuit.<br />
<br />
<table align="center"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinnWQCsyLTphmfM_KjcKvKNIku9By83tkoMVyR0gvMTQvjN5F0aP3TcmXS8Y2bXvWPxV3z1uL8M64Low4x9EbQHnI4l_E4Z8R6Mx1qTgwBl4vUiLGnOIrrO7RtywvNmfliTfAS2SQ-jKc/s1600/IMG_6345.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinnWQCsyLTphmfM_KjcKvKNIku9By83tkoMVyR0gvMTQvjN5F0aP3TcmXS8Y2bXvWPxV3z1uL8M64Low4x9EbQHnI4l_E4Z8R6Mx1qTgwBl4vUiLGnOIrrO7RtywvNmfliTfAS2SQ-jKc/s320/IMG_6345.JPG" width="240" /></a>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitmUAfq8td42dpTz-dfhyV5FvKwVwhCymJ2bEFqN46hcVgarbWqq0ooPZ4VN-5lDH-P5QmLOwoINWUQmz-pK_nvzytHYOYYJ8XfqxgVM2m9xS0_1mrro9j-MV3PPi1D1CwWtmr6x_HkSo/s1600/IMG_6346.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitmUAfq8td42dpTz-dfhyV5FvKwVwhCymJ2bEFqN46hcVgarbWqq0ooPZ4VN-5lDH-P5QmLOwoINWUQmz-pK_nvzytHYOYYJ8XfqxgVM2m9xS0_1mrro9j-MV3PPi1D1CwWtmr6x_HkSo/s320/IMG_6346.JPG" width="240" /></a>
</td></tr>
</tbody></table>
<br />
<br />
<h4>
<span style="font-weight: normal;">Power switch and power input</span></h4>
<div>
<span style="font-weight: normal;"><br /></span></div>
On the back of the cube I added a barrel connector for power and a small toggle switch. The toggle switch controls the power to the microcontroller and the LEDs. The power cable is routed through a small hole in the white insert.<br />
<br />
<table align="center"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRSQ7ZedZoboQHFZqP0j2FDF-hePA98buxUF-fqYZomb49NWHU24oLMFLbYSd-punkuR1L0CQ1lb9LYzXcBYU7QGsy7iXzS4aMv_ACQdcqnP7hCTOTC8zMIxzgkoYpr93XoVMDKL2-8kw/s1600/IMG_6351.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRSQ7ZedZoboQHFZqP0j2FDF-hePA98buxUF-fqYZomb49NWHU24oLMFLbYSd-punkuR1L0CQ1lb9LYzXcBYU7QGsy7iXzS4aMv_ACQdcqnP7hCTOTC8zMIxzgkoYpr93XoVMDKL2-8kw/s320/IMG_6351.JPG" width="240" /></a>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihG_5fctfqqlOVytcsG9HYzmTAS3Odl-GhuAYIegcO3X9Y9IUQ0s-_zsAfy14oIiOhnQdGq9XPTzChuEpUhdan03qt1CB2_2U_who9sdNEJBxRFNY19vuCODwJXuNhX8ZrxzXZXBxoJRw/s1600/IMG_6352.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihG_5fctfqqlOVytcsG9HYzmTAS3Odl-GhuAYIegcO3X9Y9IUQ0s-_zsAfy14oIiOhnQdGq9XPTzChuEpUhdan03qt1CB2_2U_who9sdNEJBxRFNY19vuCODwJXuNhX8ZrxzXZXBxoJRw/s320/IMG_6352.JPG" width="240" /></a>
</td></tr>
</tbody></table>
<br />
<br />
<br />
<h4>
<span style="font-weight: normal;">Assembling all the parts</span></h4>
<br />
The insert was secured to the cube with countersunk head 4-40 screws. I added some stick on rubber feet and stuffed the control board in the square opening.<br />
<br />
<table align="center"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi30ev4e8ghUOHWMyHUk8PR7BUgq28Q460J3EL8wcc_DfJzhQlnZUQlhRwQovMSPfA5ADNmmFUmFMUKDsrSxZlUyFviJiCgnm0AAojLe5BWZ_aPi4bgh_R29YrwIW3hDm4PcuoYtA2WUJ4/s1600/IMG_6356.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi30ev4e8ghUOHWMyHUk8PR7BUgq28Q460J3EL8wcc_DfJzhQlnZUQlhRwQovMSPfA5ADNmmFUmFMUKDsrSxZlUyFviJiCgnm0AAojLe5BWZ_aPi4bgh_R29YrwIW3hDm4PcuoYtA2WUJ4/s320/IMG_6356.JPG" width="240" /></a>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxiBzfFPQpS2E_c3139KPG9DDEkIqwJYPPCKP0Ydtv3SlrtA6AZIWacvRfks4B6fj73vuOf7plrlwE72em1huE5dMKGBXy_mnZM72gp45eZv6ATbnzyRB0i0Fh99I3iZb_v_Y6A58QX1k/s1600/IMG_6353.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxiBzfFPQpS2E_c3139KPG9DDEkIqwJYPPCKP0Ydtv3SlrtA6AZIWacvRfks4B6fj73vuOf7plrlwE72em1huE5dMKGBXy_mnZM72gp45eZv6ATbnzyRB0i0Fh99I3iZb_v_Y6A58QX1k/s320/IMG_6353.JPG" width="240" /></a>
</td></tr>
</tbody></table>
<br />
One mistake I made was using too much hot glue to attach the LED wiring inside the square hole of the insert. The extra glue caused the control board to protrude a couple millimeters. Not a huge deal but I would have liked the bottom to be completely flat. I had planned to put a cover on the bottom so I just designed it to account for the protrusion. I fired up FreeCAD again and whipped something up.<br />
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRdOPyuBHYGR2txjMCZpkI74Zo3PlLdwnXrxTP5fZ-ZFp38AhP1ps7UYtFam1g-fpb-J5cnlK2ERvd90Rxu7slPhHqibr12sE2S8AJ-ud5s88qwpY7ZkPcdaEJaBit1N6gNhuBFsP6MU8/s1600/Screenshot+2015-09-27+09.56.05.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="286" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRdOPyuBHYGR2txjMCZpkI74Zo3PlLdwnXrxTP5fZ-ZFp38AhP1ps7UYtFam1g-fpb-J5cnlK2ERvd90Rxu7slPhHqibr12sE2S8AJ-ud5s88qwpY7ZkPcdaEJaBit1N6gNhuBFsP6MU8/s400/Screenshot+2015-09-27+09.56.05.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The cover was attached with pan head 4-40 screws.</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr2Q2BSqnJegi_c0K1hWYr8KwGZ-olZu6cyASGXyq_K0z5Qr4eEO1n6MIG2WdvCZKpfru7XRAFHJkUkK_8YCDyjGwHI3w1XwYaFXiipD1XHf0-LiZ9qOw6krwr0kYfUpPIZG79GuFRw98/s1600/IMG_6473.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr2Q2BSqnJegi_c0K1hWYr8KwGZ-olZu6cyASGXyq_K0z5Qr4eEO1n6MIG2WdvCZKpfru7XRAFHJkUkK_8YCDyjGwHI3w1XwYaFXiipD1XHf0-LiZ9qOw6krwr0kYfUpPIZG79GuFRw98/s400/IMG_6473.JPG" width="400" /></a></div>
<div>
<br />
<br />
<br />
<h4>
<span style="font-weight: normal;">Writing the code</span></h4>
<br />
For the Arduino code I started with Adafruit's nRF8001 echoDemo example. It basically does serial communication between the Arduino and an iPhone app.<br />
<br />
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNTAgpLxJIzF7wkwSGqF7SkYyKglYROPaMYILs2_s0XYAyZWFqs55AoXopLMq2dfJ9KYJG0h-H8NIsUG41suixTmr9MMCSmpXb2x702Bcf_DgRW4pY5bC5giA0RkN7vF_eJLMTvFsoNdE/s1600/Screenshot+2015-09-27+10.14.32.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="185" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNTAgpLxJIzF7wkwSGqF7SkYyKglYROPaMYILs2_s0XYAyZWFqs55AoXopLMq2dfJ9KYJG0h-H8NIsUG41suixTmr9MMCSmpXb2x702Bcf_DgRW4pY5bC5giA0RkN7vF_eJLMTvFsoNdE/s400/Screenshot+2015-09-27+10.14.32.png" width="400" /></a></div>
<br />
Adafruit also provides a demo iPhone app called <a href="https://itunes.apple.com/us/app/adafruit-bluefruit-le-connect/id830125974" target="_blank">Bluefruit LE Connect</a>. The app lets you interact with the BLE breakout board without having to do any iOS development.
<br />
<br />
<table align="center" border="0">
<tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9u8AY59OHVRfjlf1vXyiHkk1w1APcxEkWS2mOdSw04ci0Vqxy9oZl7BbQt9mSpFSmhXgpT6eNx7XQMOSSQPkHiWYvGSkxMFeYOr7ks7PH_vrnfSA1ZgioXcf13KjOwI5XMbPtJmpeDK8/s1600/IMG_6500.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9u8AY59OHVRfjlf1vXyiHkk1w1APcxEkWS2mOdSw04ci0Vqxy9oZl7BbQt9mSpFSmhXgpT6eNx7XQMOSSQPkHiWYvGSkxMFeYOr7ks7PH_vrnfSA1ZgioXcf13KjOwI5XMbPtJmpeDK8/s200/IMG_6500.PNG" width="111" /></a>
</td>
<td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgY5zFeA9dVT1_rYpArgyjBDLQo-g1f9sAUWVVWeG1kbUBJ8EM2aCoqj7-99CqY5K1x0YmbzOqg-DkDm0UH961ZGMClZXKFNQ_GKxNpv8NLor2TjuqfBuxp8sZAvHTkTUuxqadhRGvI6zg/s1600/IMG_6501.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgY5zFeA9dVT1_rYpArgyjBDLQo-g1f9sAUWVVWeG1kbUBJ8EM2aCoqj7-99CqY5K1x0YmbzOqg-DkDm0UH961ZGMClZXKFNQ_GKxNpv8NLor2TjuqfBuxp8sZAvHTkTUuxqadhRGvI6zg/s200/IMG_6501.PNG" width="111" /></a>
</td>
<td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtrMSh-vxWOZPR6kzweisczUB5gtuHyQhEST4XBKIHOC9prtaspzHf9hJ5IO3VXd-ggXHlQvwlZbH401ovNXVxWJhZo5IFvEL7Yuvz0zwn14q4Vct7vyR0z2UM7BKrJ61WN84EXHGe_A8/s1600/IMG_6502.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtrMSh-vxWOZPR6kzweisczUB5gtuHyQhEST4XBKIHOC9prtaspzHf9hJ5IO3VXd-ggXHlQvwlZbH401ovNXVxWJhZo5IFvEL7Yuvz0zwn14q4Vct7vyR0z2UM7BKrJ61WN84EXHGe_A8/s200/IMG_6502.PNG" width="111" /></a>
</td></tr>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-tDVfYCf-pcobyL1yOJAL1mphhF1GNT1jgODEbrW65i8gDe8fGupB8pgzKTTx0mOp29D_EecbX02mi8WJseMCGHDOLQ57fA8YHiYFAVaLv5HHBgbSr6cHweECk8xLIiU1IYdIYaJ4Ffg/s1600/IMG_6503.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-tDVfYCf-pcobyL1yOJAL1mphhF1GNT1jgODEbrW65i8gDe8fGupB8pgzKTTx0mOp29D_EecbX02mi8WJseMCGHDOLQ57fA8YHiYFAVaLv5HHBgbSr6cHweECk8xLIiU1IYdIYaJ4Ffg/s200/IMG_6503.PNG" width="112" /></a>
</td><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7Gh253YBpN_6a0goUR3s-Mp4z5qfkzOpcqon-HK1jnNOrYn_oZ_jTrMZ9hJCXRtoeug4GHYnOXq_Cx4UJ_gNyyOC5kNng-UbrprNMdO_aJuSWyCf6Ez72MY61iO8GprQQGFeyG4eHATg/s1600/IMG_6504.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7Gh253YBpN_6a0goUR3s-Mp4z5qfkzOpcqon-HK1jnNOrYn_oZ_jTrMZ9hJCXRtoeug4GHYnOXq_Cx4UJ_gNyyOC5kNng-UbrprNMdO_aJuSWyCf6Ez72MY61iO8GprQQGFeyG4eHATg/s200/IMG_6504.PNG" width="112" /></a>
</td></tr>
</tbody></table>
</div>
<div>
<br />
After playing around with the color picker in the iOS app I saw it was sending RGB values formatted like this: <span style="font-family: Courier New, Courier, monospace;">!C180255</span></div>
<div>
The exclamation point indicates a command, the next character indicates what kind of command, followed by red/green/blue values. This seemed like a good format for all of the commands I planned to send to the cube. I started planning out all the commands on my whiteboard.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjY5XJ_NEEPGZ9NgDA731V-9hgehAHQ84-xVUU7lVdSfCIoRjN9XcZs_-XaGP3CqrndSfLtn3wWRHWNQBk_phGz3IcVXo71HyxvHnm79GA3g2wZu5nTGz3r1-8bGaOE_fMeY8uMXg9Qr6M/s1600/IMG_6499.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjY5XJ_NEEPGZ9NgDA731V-9hgehAHQ84-xVUU7lVdSfCIoRjN9XcZs_-XaGP3CqrndSfLtn3wWRHWNQBk_phGz3IcVXo71HyxvHnm79GA3g2wZu5nTGz3r1-8bGaOE_fMeY8uMXg9Qr6M/s400/IMG_6499.JPG" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both;">
One thing I hadn't worked with before on Arduino boards was EEPROM memory. I understood basically how it worked but hadn't actually used it in a project yet. Turn out to be very straight forward. On the Atmega328P chip there are 1024 possible EEPROM memory locations and you can store one byte of info in each location.</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
Here are the major features of my Arduino code on the cube:</div>
<div class="separator" style="clear: both;">
</div>
<ul>
<li>Set the whole cube to a single color</li>
<li>Set the color of each side individually</li>
<li>Activate animations (Pulse, Rainbow, and Cycle)</li>
<li>Set a new BLE name on the cube and save it to EEPROM</li>
<li>Save the current colors and animation settings to EEPROM</li>
<li>Read settings from EEPROM on start up</li>
<li>Set base values in EEPROM for new boards</li>
<li>Flash green to confirm commands</li>
</ul>
<br />
<div class="separator" style="clear: both;">
I won't go into great detail about the code itself. You can read through it <a href="https://github.com/matt448/MinecraftNightLight/blob/master/BLEcube/BLEcube.ino" target="_blank">here</a> if you would like. I tried to comment it well. I'm sure it can be improved quite a bit so feel free to send suggestions or pull requests.</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<br /></div>
<h4 style="clear: both;">
<span style="font-weight: normal;">Demo</span></h4>
<div class="separator" style="clear: both;">
Here is a (long) video showing most of the functions of the cube</div>
<div class="separator" style="clear: both;">
<br /></div>
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/ey7WwtKxpGk?rel=0" width="560"></iframe><br />
<br />
<br />
<br />
<h4 style="clear: both;">
<span style="font-weight: normal;">Download links</span></h4>
<div class="separator" style="clear: both;">
As promised here are links to download everything if you want to make one of these yourself. The Fritzing diagram lists all the parts needed.</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
Arduino Code: <a href="https://github.com/matt448/MinecraftNightLight">https://github.com/matt448/MinecraftNightLight</a></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
Adafruit BLE Library: <a href="https://github.com/adafruit/Adafruit_nRF8001">https://github.com/adafruit/Adafruit_nRF8001</a></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
3D Models: <a href="http://www.thingiverse.com/thing:1023004">http://www.thingiverse.com/thing:1023004</a></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
iOS App: <a href="https://itunes.apple.com/us/app/adafruit-bluefruit-le-connect/id830125974">https://itunes.apple.com/us/app/adafruit-bluefruit-le-connect/id830125974</a></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<br /></div>
Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com14tag:blogger.com,1999:blog-9120755343492164185.post-52078564806133889492015-05-22T16:16:00.002-05:002015-09-11T14:32:54.472-05:00Cabinet for my Printrbot Simple Metal 3D Printer<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT6zTb06MeanAZAWSOoC-7YXGMpObpddMYTb82rC8OySJtzFarrcGrO_RVvVrH7sbvnC2M7ioc_Xc9IiBcf0pqW9knFCXP3Mq2IrwoZS4ZYjUo-6oErUKB3KpIJi_WqwdmsUC3Kq5CoxE/s1600/logo-design.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT6zTb06MeanAZAWSOoC-7YXGMpObpddMYTb82rC8OySJtzFarrcGrO_RVvVrH7sbvnC2M7ioc_Xc9IiBcf0pqW9knFCXP3Mq2IrwoZS4ZYjUo-6oErUKB3KpIJi_WqwdmsUC3Kq5CoxE/s1600/logo-design.png" /></a></div>
ABS plastic can be sensitive to air currents while printing. A cool gust of air from an A/C vent, open window or ceiling fan can cause a part to warp or lift from the bed. Living in Texas we have the ceiling fan running in our home office all the time so it was a must for me to build an enclosure for my Printrbot Simple Metal printer. I also wanted to keep my 3D printer from getting dust build up on it. I've read that dust can get in the hot end and cause clogs.<br />
<br />
I started with a wooden platform made out thin hardboard on top of MDF. Then I built the upper part of the enclosure out of plexiglass and aluminum channel. I purchased the plexi and aluminum channel from Lowes. The aluminum channel is 1/16" x 3/4" x 3/4". I bolted the whole thing together with #8-32 screws. The build chamber dimensions are 15"H x 20"W x 22"D.<br />
<br />
I 3D printed some screw down feet for my Printrbot so it doesn't move around inside the cabinet. You can download the design for the feet here: <a href="http://www.thingiverse.com/thing:724909">http://www.thingiverse.com/thing:724909</a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVxZOoldE21lG6azs2gqyMpYTOfIf2ZlpbVQhQhS0ZyzDxJmXRdDCP9OqzrcMcKp3RQEUhJFheBTyPphxpq7F-Ry55EvalOCcYkOnGIg7cjamGtX2D1vME5i-rg5ZS7HMDgMJYeZDk8O4/s1600/Photo+May+11%252C+10+07+05+PM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVxZOoldE21lG6azs2gqyMpYTOfIf2ZlpbVQhQhS0ZyzDxJmXRdDCP9OqzrcMcKp3RQEUhJFheBTyPphxpq7F-Ry55EvalOCcYkOnGIg7cjamGtX2D1vME5i-rg5ZS7HMDgMJYeZDk8O4/s400/Photo+May+11%252C+10+07+05+PM.jpg" width="400" /></a></div>
<br />
The whole front of the enclosure is a hinged door. Magnetic door catches keep the door closed.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmfsV8Uzd3AqDxpQjRG-JnvX305anAtghrIIsZCBBufTfjez2XVUDA4lYJKJAFJiRPhkv_0YMBTO4XNV7hk2sbTR47tqcGXHBeMw3ifoiUmMzXbLx2m0YZtOxnIxUDGdqg2GZKx-1QxyI/s1600/Photo+May+11%252C+10+09+51+PM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmfsV8Uzd3AqDxpQjRG-JnvX305anAtghrIIsZCBBufTfjez2XVUDA4lYJKJAFJiRPhkv_0YMBTO4XNV7hk2sbTR47tqcGXHBeMw3ifoiUmMzXbLx2m0YZtOxnIxUDGdqg2GZKx-1QxyI/s400/Photo+May+11%252C+10+09+51+PM.jpg" width="300" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The top of the cabinet is also hinged and can be opened. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3NCNm9e22L_i1dqWYdBoxvDs-MLtfL4N3-58vL-Ro1ztPeT9e8LoJaiXmzvcuDCyggrq5yhLnr049qIE2MRfP9Cu7SHvapRmG6U2E4TSSw3sAfsUzdJm293RvLUPZVEljS-R1ZKkvVfQ/s1600/Photo+May+23%252C+10+34+08+AM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3NCNm9e22L_i1dqWYdBoxvDs-MLtfL4N3-58vL-Ro1ztPeT9e8LoJaiXmzvcuDCyggrq5yhLnr049qIE2MRfP9Cu7SHvapRmG6U2E4TSSw3sAfsUzdJm293RvLUPZVEljS-R1ZKkvVfQ/s400/Photo+May+23%252C+10+34+08+AM.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
My Printrbot has a heated print bed so it uses an ATX power supply from a computer. It has a bunch of extra wires that aren't used by the printer so I made a hollow area underneath to hide all the extra wires.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGCLRz5ilvaXkaJZLecOlcANPgyQkWOHvFrvbKSzLdjVcmU_RnI12xfQ6fqg7PmrOeyk0ukV5DdYg8u3dDIYEUeBgurkchMPEJDL1I9ZKurtiU3l7f115dW0oksAcnD_nn6dxul8Qt7Gs/s1600/Photo+May+23%252C+11+03+49+AM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGCLRz5ilvaXkaJZLecOlcANPgyQkWOHvFrvbKSzLdjVcmU_RnI12xfQ6fqg7PmrOeyk0ukV5DdYg8u3dDIYEUeBgurkchMPEJDL1I9ZKurtiU3l7f115dW0oksAcnD_nn6dxul8Qt7Gs/s400/Photo+May+23%252C+11+03+49+AM.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
The power supply is mounted in the corner so it takes in and vents air outside of the enclosure so it doesn't overheat.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBOqeNT4qcY62XzQx1prImKM0TLRSORYMKTyK0QdtJJdxZHmp0j6lG5A7O2ooiCLjpVjXOApIjFzq0WibtkSqQEOzB2Ucew_k9VX3LHNhdJTzgfJ196V_DPZwIyxiDkrJ5wUXF8LYJcy0/s1600/Photo+May+23%252C+10+37+09+AM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBOqeNT4qcY62XzQx1prImKM0TLRSORYMKTyK0QdtJJdxZHmp0j6lG5A7O2ooiCLjpVjXOApIjFzq0WibtkSqQEOzB2Ucew_k9VX3LHNhdJTzgfJ196V_DPZwIyxiDkrJ5wUXF8LYJcy0/s400/Photo+May+23%252C+10+37+09+AM.jpg" width="400" /></a></div>
<br />
<br />
I made a spool holder out of a 6" Lazy Susan bearing and a piece of plywood. I put a 3/8" carriage bolt in the center of the spool holder turnable which is used to secure the filament spool to the holder. I used some #6-32 stand-offs and #6-32 screws with the heads cutoff to allow the turntable to sit an inch above the lid so it can rotate. This also allows the turntable to be lifted off when the top lid needs to be opened.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghhhmIX0d3RDrhkQhIzmXDEAFso4pplEi1ELdVqqekn4cRl0uozSzGESnQmOoVGqjRZeeGhVPgJG58gLh6l62BQhF-5U6rRpDmeNCssGYW_q3_djAA3JmwemWgBhjWCto2Ecv0cvLah1Q/s1600/Photo+May+23%252C+10+35+08+AM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghhhmIX0d3RDrhkQhIzmXDEAFso4pplEi1ELdVqqekn4cRl0uozSzGESnQmOoVGqjRZeeGhVPgJG58gLh6l62BQhF-5U6rRpDmeNCssGYW_q3_djAA3JmwemWgBhjWCto2Ecv0cvLah1Q/s400/Photo+May+23%252C+10+35+08+AM.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGGAx84zsAMtKNrpEOWtGKGmH2qs_ANUrNN1VBoJ8VGD85p39mvP_OG6arZ8g60kKRGDXTIxvSgZgNZ2mFBTx9K7t5dXp09IZ2OZ0u6Wb7_Bf7QFE2CM_mwSxiCHOga-rCBguT8yCbeq4/s1600/Photo+May+23%252C+10+35+42+AM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGGAx84zsAMtKNrpEOWtGKGmH2qs_ANUrNN1VBoJ8VGD85p39mvP_OG6arZ8g60kKRGDXTIxvSgZgNZ2mFBTx9K7t5dXp09IZ2OZ0u6Wb7_Bf7QFE2CM_mwSxiCHOga-rCBguT8yCbeq4/s400/Photo+May+23%252C+10+35+42+AM.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvOwsV7FDjQOYulVZEDSeG_CgSyepstlxkgWBRFY_g6aLqW5JeShyphenhyphenGQ9tHuPWtFosYtfRW6gaTam8BL_5_9v1KqWvxGeHS7iDVFeht9R7zyfNz-MS9uMkigC9ECzRH0xBAIfCSmr6061Q/s1600/Photo+May+23%252C+10+35+48+AM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvOwsV7FDjQOYulVZEDSeG_CgSyepstlxkgWBRFY_g6aLqW5JeShyphenhyphenGQ9tHuPWtFosYtfRW6gaTam8BL_5_9v1KqWvxGeHS7iDVFeht9R7zyfNz-MS9uMkigC9ECzRH0xBAIfCSmr6061Q/s400/Photo+May+23%252C+10+35+48+AM.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Then I designed a knob and cone that secures the filament spool to the turntable. You can download the design here: <a href="http://www.thingiverse.com/thing:829930">http://www.thingiverse.com/thing:829930</a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRQ8FW-Mt6FZQg9CeEmSeVYQ6wgQRAgjkach48D6MixofE7vqdzc2Szwr2YGRTYy4yZTr6Cz0hG3qGnTCyp43h18WEDqpaMyCOI0XjCvcVy7qSFc39_DJR_OonW-D1saYscM8LUTqtHNE/s1600/Photo+May+15%252C+6+38+30+AM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="250" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRQ8FW-Mt6FZQg9CeEmSeVYQ6wgQRAgjkach48D6MixofE7vqdzc2Szwr2YGRTYy4yZTr6Cz0hG3qGnTCyp43h18WEDqpaMyCOI0XjCvcVy7qSFc39_DJR_OonW-D1saYscM8LUTqtHNE/s320/Photo+May+15%252C+6+38+30+AM.jpg" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh76hnWDWiqQf5QaK_Ebn9EHneL_DPakpa4JsZhoLzhleRcrx92e2kHiLkV7gGRpz0uNI15gzTejp4B2_KoESzmScTxmZPxpB7ezDqHqLMngvoA4odG3ZiiWzXXMY9Vg9IvvwjbFoVB8yA/s1600/Photo+May+15%252C+6+39+26+AM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh76hnWDWiqQf5QaK_Ebn9EHneL_DPakpa4JsZhoLzhleRcrx92e2kHiLkV7gGRpz0uNI15gzTejp4B2_KoESzmScTxmZPxpB7ezDqHqLMngvoA4odG3ZiiWzXXMY9Vg9IvvwjbFoVB8yA/s320/Photo+May+15%252C+6+39+26+AM.jpg" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwzRvT2eDIqv_YbJ1tTi2N7xcCUGZLVOXSGOiSQBZrPHS7FKsv99dmLGSxSTv12t3XndhZzoSITF3zXW-Qd5qyml7LFsF2w0ctomlRUfuST_gLsDb1QVDAeD9Dp03Qc4zGHf_GuVAgCjM/s1600/Photo+May+15%252C+6+38+50+AM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwzRvT2eDIqv_YbJ1tTi2N7xcCUGZLVOXSGOiSQBZrPHS7FKsv99dmLGSxSTv12t3XndhZzoSITF3zXW-Qd5qyml7LFsF2w0ctomlRUfuST_gLsDb1QVDAeD9Dp03Qc4zGHf_GuVAgCjM/s320/Photo+May+15%252C+6+38+50+AM.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
Here is a more detailed shot showing the path of the filament into the cabinet. I drilled a .25" hole in the top panel.</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLByrPIg2ixQ4gUcD6wGYQDKLtLvhZGViEd4qpnFjm59TfdYZ3y0g97ZRj4e-CfaLGW0UsI6HLssFvRY_36FllTK0vaARX2gBhIKDz4yHF_rZMm4ckhhA0DK5r28z-LiFtE5nAQlYQbWM/s1600/IMG_6378.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLByrPIg2ixQ4gUcD6wGYQDKLtLvhZGViEd4qpnFjm59TfdYZ3y0g97ZRj4e-CfaLGW0UsI6HLssFvRY_36FllTK0vaARX2gBhIKDz4yHF_rZMm4ckhhA0DK5r28z-LiFtE5nAQlYQbWM/s400/IMG_6378.JPG" width="300" /></a></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
Next I added LED light strips around the top of the cabinet to light up the inside. The strips are power by +12vdc so I was able to hook them up to the Printrbot ATX power supply. The lights turn on when the printer is powered up.</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcl4WFUXCoRKjsf2ugFHhXQC3T1-v6nNqqq4aJUAx0c0ixKvBABpWtzK9niwR3rAuCq23d0y2bTYcucBNHf1s2rdZNahPs0IGeZ0ittGktqc7xpnopOtoX-dxkqocQzDFQgTAYPgonMGo/s1600/Photo+May+12%252C+10+25+46+PM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcl4WFUXCoRKjsf2ugFHhXQC3T1-v6nNqqq4aJUAx0c0ixKvBABpWtzK9niwR3rAuCq23d0y2bTYcucBNHf1s2rdZNahPs0IGeZ0ittGktqc7xpnopOtoX-dxkqocQzDFQgTAYPgonMGo/s400/Photo+May+12%252C+10+25+46+PM.jpg" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPeGFOAc1BnpGR5SZi2TNfkchejR9KbHARDi-SVJzxC3Jd7GFdyxz7ErFZCQMWNE8JJwVu_OuXy6xjmQzPDVC7cEkfGSgx9Gcl7uts4lp8W_em0SywyAAlyGkL9U-W__ufaJLYxr0JKWc/s1600/Photo+May+12%252C+10+35+14+PM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPeGFOAc1BnpGR5SZi2TNfkchejR9KbHARDi-SVJzxC3Jd7GFdyxz7ErFZCQMWNE8JJwVu_OuXy6xjmQzPDVC7cEkfGSgx9Gcl7uts4lp8W_em0SywyAAlyGkL9U-W__ufaJLYxr0JKWc/s400/Photo+May+12%252C+10+35+14+PM.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Here is the printer in action inside the cabinet:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/vMPQqFDTM98" width="560"></iframe><br />
<br />
There one thing I'm still working on. I put an exhaust fan in the upper right corner of the back wall of the cabinet. I don't want the cabinet to get too hot inside but I also don't want the fan to run all the time or run at full speed so I'm designing a small circuit that controls the fan speed based on the temperature inside the cabinet.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3QZag-RZpfnJDXMchcppp0XAslXKOjJBIlLYqKg10Gd6a9G480yDtCjJmf7sonjdinK-fGSEqyAKU40aL9opIThl6ZC_NAM4upV-e9KqcCzlNj0AkPtpKS7L8DnXKdjBXX50KV3ppoDo/s1600/Photo+May+23%252C+10+34+32+AM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3QZag-RZpfnJDXMchcppp0XAslXKOjJBIlLYqKg10Gd6a9G480yDtCjJmf7sonjdinK-fGSEqyAKU40aL9opIThl6ZC_NAM4upV-e9KqcCzlNj0AkPtpKS7L8DnXKdjBXX50KV3ppoDo/s320/Photo+May+23%252C+10+34+32+AM.jpg" width="320" /></a></div>
<br />
<br />
UPDATE 2015-08-18<br />
<br />
I mounted my OctoPrint print server running on a Raspberry Pi to the side of the cabinet. I also added a 20x4 character LCD display that shows useful info about the printer.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZOwR0fDxXK2HDPb2OtihdBrPF30UdqmToELIZiucfarFr6Za0eAvBjr8jY8HTBsmzN_q8prETlhx_XjZwIC5EC986EHcuThMnJ1XTIjTwBWXeTA_Pw43TzdjZ2vSVi5wDquq6pzSeIqI/s1600/IMG_6379.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZOwR0fDxXK2HDPb2OtihdBrPF30UdqmToELIZiucfarFr6Za0eAvBjr8jY8HTBsmzN_q8prETlhx_XjZwIC5EC986EHcuThMnJ1XTIjTwBWXeTA_Pw43TzdjZ2vSVi5wDquq6pzSeIqI/s640/IMG_6379.JPG" width="480" /></a></div>
<br />
<br />
<br />Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com10tag:blogger.com,1999:blog-9120755343492164185.post-52448255458459519212015-05-21T22:59:00.001-05:002015-05-21T22:59:32.962-05:00Awesome tool for getting 3D prints off a heated bed<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0dBnGQXxu0VfyOalGMRnAS3LwJZ9ukidKxw24oEzWrXZwsuSCBYHJDFA4G1HD4t-Zv6_KK1Qp4ko-6Ru7rMMquMsrzw-SBJFkk9lqr9aDNUVvwIuWviTklrC7jSKC-NzdOHVHtDWSspA/s1600/logo-design.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0dBnGQXxu0VfyOalGMRnAS3LwJZ9ukidKxw24oEzWrXZwsuSCBYHJDFA4G1HD4t-Zv6_KK1Qp4ko-6Ru7rMMquMsrzw-SBJFkk9lqr9aDNUVvwIuWviTklrC7jSKC-NzdOHVHtDWSspA/s1600/logo-design.png" /></a></div>
I have a Printrbot Simple Metal 3D printer with a heated bed. Lately I have been printing with ABS plastic which requires hairspray to get the prints to stick to the bed without warping. While this works great it to keep the print stuck to the bed it can be difficult to get the prints off the bed without damaging the print or the Kapton tape. I've tried an X-Acto knife but it digs into the Kapton tape. Paint scrapers are usually too thick and have a blunt edge that can't get under the print. Some people use pliers to grasp the part and pull it off but I've found the pliers makes marks on the part when you grab it. My wife recommended a tool that we use with our Silhouette Cameo vinyl cutter:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih_GGxvbf0V0Tyoudm0u-FWhE_eN1-keR6tGUKSq25pt0eYMwE0neR0NnCQ07o7MX78WMFP0Tv4kqr4nkEBMwXGnlgOL3BuIZMLv08qJwmfumC919PeqaAbE1_rL36NKqfxctM1MhtRbo/s1600/IMG_6023.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih_GGxvbf0V0Tyoudm0u-FWhE_eN1-keR6tGUKSq25pt0eYMwE0neR0NnCQ07o7MX78WMFP0Tv4kqr4nkEBMwXGnlgOL3BuIZMLv08qJwmfumC919PeqaAbE1_rL36NKqfxctM1MhtRbo/s400/IMG_6023.JPG" width="400" /></a></div>
<br />It's made by Cricut and they call it a Spatula Tool. It has a very thin front edge that is good for getting under prints and then it tapers up a little bit to make it stronger.<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOe92mJmhU_Ub6ZmVde1_niCz-HJHFkFgll4mnzayCxfxkr8V4otVeXVR1HC5FNKzC56M21z4B9P1bhbRuNuwwJ1hNFvdl82bZA1nVW39vGWdL6JFQf-PPmSuaNn2mssYJSmZTlmSESz4/s1600/IMG_6024.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOe92mJmhU_Ub6ZmVde1_niCz-HJHFkFgll4mnzayCxfxkr8V4otVeXVR1HC5FNKzC56M21z4B9P1bhbRuNuwwJ1hNFvdl82bZA1nVW39vGWdL6JFQf-PPmSuaNn2mssYJSmZTlmSESz4/s320/IMG_6024.JPG" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtSES2AA_BYLFc7Gk13ewhU-umCva2bU_jfFEF_nY34P3g9i7lGY9lHezsRhUvxb_dWT8rkSSdwdxnJCSHoYOSHkE_Yydce1zQI5twaP70NEherZiybqlDzZnB1O_uKjbfTkqN3mso31c/s1600/IMG_6025.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtSES2AA_BYLFc7Gk13ewhU-umCva2bU_jfFEF_nY34P3g9i7lGY9lHezsRhUvxb_dWT8rkSSdwdxnJCSHoYOSHkE_Yydce1zQI5twaP70NEherZiybqlDzZnB1O_uKjbfTkqN3mso31c/s320/IMG_6025.JPG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
I slide it in under a corner and work it around the print and then lift up a bit and the print pops off. It looks like the spatula we have is an old model but I did a search on E-bay and there are a several of them for sale for less than $10 bucks. Just search for 'Cricut Spatula Tool' and look for one with a green handle. Cricut's has a new spatula design but is a little smaller and I don't know if it works as well. I might buy one just to try it out.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg25FTSZesp1frRwLBAitoE3ve0e23DINKoF3N37f3o6H_X-8rwS8YZqEuzTH5GI9TeFh3PMf1O1y0jv2iDvH7810wYsiB7zRksuaLe3q31q4yYY10-hsvGsmbRI_CYUv6NA7mrtttUxqY/s1600/IMG_6026.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg25FTSZesp1frRwLBAitoE3ve0e23DINKoF3N37f3o6H_X-8rwS8YZqEuzTH5GI9TeFh3PMf1O1y0jv2iDvH7810wYsiB7zRksuaLe3q31q4yYY10-hsvGsmbRI_CYUv6NA7mrtttUxqY/s400/IMG_6026.JPG" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div>
<br /></div>
Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com0tag:blogger.com,1999:blog-9120755343492164185.post-23042675851055850952015-02-09T22:10:00.000-06:002015-09-11T08:33:23.641-05:00Arduino, CAN Bus and 29 bit extended IDs<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" /></a></div>
I noticed in my blog traffic stats that people are searching for information about 29 bit CAN IDs and I have been curious about this topic myself. I haven't come across 29 bit CAN IDs in a vehicle until recently and seeing these extended IDs in use in a car made want to understand how to use them with Arduino boards and MCP2515 CAN controllers. I wrote a <a href="http://matthewcmcmillan.blogspot.com/2013/10/arduino-sending-data-over-can-bus.html" target="_blank">blog post</a> back in October 2013 that covers how to send data between two Arduino boards using a CAN bus so you may want to check that out if you aren't familiar with how a CAN bus works. That post is <a href="http://matthewcmcmillan.blogspot.com/2013/10/arduino-sending-data-over-can-bus.html" target="_blank">available here</a>. This post is specifically about using 29 bit CAN IDs with an Arduino and the MCP2515 CAN controller chip.<br />
<br />
<h2>
CAN Bus IDs</h2>
<br />
There are two types of CAN Bus IDs. In the first version of the CAN Bus spec (2.0A) the IDs were made up of 11 bits. These are also known as base frame format messages. This allows for message IDs between 0x000 and 0x7FF. Which works out to be 2048 possible CAN IDs.<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/AVvXsEhFBiMSiMzCA40GcilCm7dBf8ok-WAOKglxo4q7xiK-PpPMOMqWxVWHitWZDY5wtQwQhkuSQPWR96W_ovWfKtMmmHqMeu6R8QXWjgCWkmc3ZgCM10TLzUX7v8ImrcCoemU_ZkQCeBty6jY/s1600/Screenshot+2015-02-09+19.32.51.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="135" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFBiMSiMzCA40GcilCm7dBf8ok-WAOKglxo4q7xiK-PpPMOMqWxVWHitWZDY5wtQwQhkuSQPWR96W_ovWfKtMmmHqMeu6R8QXWjgCWkmc3ZgCM10TLzUX7v8ImrcCoemU_ZkQCeBty6jY/s1600/Screenshot+2015-02-09+19.32.51.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Binary, Decimal and Hex representation of the max 11 bit ID</td></tr>
</tbody></table>
As CAN Busses were added to heavy equipment and as vehicles became more complex those 2048 possible IDs were not enough to handle the increased number of sensors. CAN 2.0B was created which increased the size of IDs from 11 bits to 29 bits. CAN 2.0B allows for over 536 million different IDs. 29 bit messages are also known as extended frame format messages. 18 bits were added to the original 11 bits in an separate field in a CAN message. There is a flag in the message that signals if a message is an 11 bit or 29 bit message. 11 bit and 29 bit messages can coexist on the same CAN bus.<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/AVvXsEhg7XSyCL5vXxd98WCujhIwOEOcluqpgnl2paNsstt5U405RRFXyetn1oKoH6JoIxdozFbvF9j1L6pw9KwO7fDkYEK5BIT_bbomp4GfSudLDSN4WuN0jd-PM4zru_4rnl8oaDreneAxx-s/s1600/Screenshot+2015-02-09+19.40.03.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="135" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg7XSyCL5vXxd98WCujhIwOEOcluqpgnl2paNsstt5U405RRFXyetn1oKoH6JoIxdozFbvF9j1L6pw9KwO7fDkYEK5BIT_bbomp4GfSudLDSN4WuN0jd-PM4zru_4rnl8oaDreneAxx-s/s1600/Screenshot+2015-02-09+19.40.03.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: 12.8000001907349px;">Binary, Decimal and Hex representation of the max 29 bit ID</span></td></tr>
</tbody></table>
There are some trade-offs with 29 bit CAN IDs though. The latency is increased, the messages use more bandwidth and error detection performance is decreased. But if you have run out of IDs I suppose these are worthwhile trade-offs.<br />
<br />
<br />
<h2>
11 bit code example</h2>
<br />
Let's take a look at a very simple example of using an MCP2515 CAN controller with an Arduino and 11 bit CAN IDs. I am using a <a href="http://www.seeedstudio.com/depot/CANBUS-Shield-p-2256.html" target="_blank">Seeed Studio CAN-BUS Shield</a> but the MCP2515 is just an SPI chip that can be wired up with minimal external components.<br />
In this 11 bit example I am using a CAN ID of 0x07B in hex (123 in decimal).<br />
<br />
<script src="https://gist.github.com/matt448/dfe563623ef277a86d57.js"></script>
<br />
Here you can see my receiver Arduino is receiving CAN messages with an ID of 123.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmqrSYbPnHIh9Y6Fa4xInZu9vKxnX84xBl_8qY0IKQoxhLcNQrhzcik0RA4YJg9ZqlgZ6uUbXKp90dWhLRGnFy56y1pUusc0thYyGR8Om872Sfb3D0E17N77HU47vqH28TanrciDMTgf8/s1600/IMG_5412+copy.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="263" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmqrSYbPnHIh9Y6Fa4xInZu9vKxnX84xBl_8qY0IKQoxhLcNQrhzcik0RA4YJg9ZqlgZ6uUbXKp90dWhLRGnFy56y1pUusc0thYyGR8Om872Sfb3D0E17N77HU47vqH28TanrciDMTgf8/s1600/IMG_5412+copy.JPG" width="400" /></a></div>
<br />
<br />
<h2>
29 bit code example</h2>
<br />
Next let's look at an example of sending 29 bit CAN IDs. In this example I am using a CAN ID of 0x17F8140E in hex (or 402134030 in decimal).<br />
<br />
<script src="https://gist.github.com/matt448/80b962b8fa7d714f3afc.js"></script>
<br />
Here you can see my receiver Arduino is receiving CAN messages with an ID of 402134030.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiomYRK5iW1xbDGniR_Cy9uSSVoR2kaZNyOiz-xNxLKmGXv7Ml_kiQTfyFSqatrJRUMC5Vs8QDYV4xeH3iGteVP-ahQrnJBfoseeX1rbRQsPAtOSPntqa7Bkw4cUyR1fHmPPjPZ3bBOBOk/s1600/IMG_5413+copy.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="256" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiomYRK5iW1xbDGniR_Cy9uSSVoR2kaZNyOiz-xNxLKmGXv7Ml_kiQTfyFSqatrJRUMC5Vs8QDYV4xeH3iGteVP-ahQrnJBfoseeX1rbRQsPAtOSPntqa7Bkw4cUyR1fHmPPjPZ3bBOBOk/s1600/IMG_5413+copy.JPG" width="400" /></a></div>
<br />
<br />
<h2>
sendMsgBuf format</h2>
The key piece of this example code is the sendMsgBuf function. This function is part of the <br />
<a href="https://github.com/coryjfowler/MCP_CAN_lib">MCP_CAN_lib</a>. This is where messages are flagged as 11 bit or 29 bit.<br />
<div>
<br /></div>
<div>
11 bit: <span style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 16.7999992370605px; white-space: pre;">CAN.</span><span class="pl-s3" style="background-color: white; box-sizing: border-box; color: #0086b3; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 16.7999992370605px; white-space: pre;">sendMsgBuf</span><span style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 16.7999992370605px; white-space: pre;">(0x07B, </span><span class="pl-c1" style="background-color: white; box-sizing: border-box; color: #0086b3; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 16.7999992370605px; white-space: pre;">0</span><span style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 16.7999992370605px; white-space: pre;">, </span><span class="pl-c1" style="background-color: white; box-sizing: border-box; color: #0086b3; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 16.7999992370605px; white-space: pre;">8</span><span style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 16.7999992370605px; white-space: pre;">, canMsg);</span></div>
<div>
<span style="color: #333333; font-family: Consolas, Liberation Mono, Menlo, Courier, monospace;"><span style="font-size: 12px; line-height: 16.7999992370605px; white-space: pre;"><br /></span></span></div>
<div>
29 bit: <span style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 16.7999992370605px; white-space: pre;">CAN.</span><span class="pl-s3" style="background-color: white; box-sizing: border-box; color: #0086b3; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 16.7999992370605px; white-space: pre;">sendMsgBuf</span><span style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 16.7999992370605px; white-space: pre;">(0x17F8140E, </span><span class="pl-c1" style="background-color: white; box-sizing: border-box; color: #0086b3; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 16.7999992370605px; white-space: pre;">1</span><span style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 16.7999992370605px; white-space: pre;">, </span><span class="pl-c1" style="background-color: white; box-sizing: border-box; color: #0086b3; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 16.7999992370605px; white-space: pre;">8</span><span style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 16.7999992370605px; white-space: pre;">, canMsg);</span></div>
<div>
<span style="color: #333333; font-family: Consolas, Liberation Mono, Menlo, Courier, monospace;"><span style="font-size: 12px; line-height: 16.7999992370605px; white-space: pre;"><br /></span></span></div>
<div>
<br />
The format for this function is sendMsgBuf(can_id, id_type, dlc, data_buf)<br />
<br /></div>
<div>
<b>can_id -</b> id number for your message in hex or decimal.<br />
<br /></div>
<div>
<b>id_type -</b> flag for 11 or 29 bit message id. 0=11bit, 1=29bit<br />
<br /></div>
<div>
<b>dlc -</b> Number of bytes in the message data<br />
<br /></div>
<div>
<b>data_buf -</b> The data transmitted in the message.<br />
<br />
<br />
If you are going to try out these examples you should download<a href="https://github.com/coryjfowler/MCP_CAN_lib" target="_blank"> Cory Fowler's fork of the MCP_CAN_lib</a>.<br />
<br />
<br />
Resources</div>
<div>
<a href="http://en.wikipedia.org/wiki/CAN_bus"><span style="font-size: x-small;">http://en.wikipedia.org/wiki/CAN_bus</span></a><br />
<a href="https://github.com/coryjfowler/MCP_CAN_lib"><span style="font-size: x-small;">https://github.com/coryjfowler/MCP_CAN_lib</span></a><br />
<a href="http://www.seeedstudio.com/wiki/CAN-BUS_Shield"><span style="font-size: x-small;">http://www.seeedstudio.com/wiki/CAN-BUS_Shield</span></a></div>
Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com32tag:blogger.com,1999:blog-9120755343492164185.post-53996634806379052432015-02-01T14:54:00.003-06:002015-02-21T15:22:30.974-06:00CAN Bus to UART using an Adafruit Pro Trinket<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" /></a></div>
I have been fighting with the onboard CAN controller on my BeagleBone Black trying to <br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRYmikxa0OnJi4YOH2FuI3LptY8sxuGIa_vx1mdJi6wqbMHQFZgBFG4kz2amWH1HUZdw_ZlzMcC0go2viQSQ2VNbHenAc8fzkdVUOneBJv3RISC2DLTo0oSrY0J-FWPr6U1Rwp20DZEPA/s1600/beagleboneLogo_small.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRYmikxa0OnJi4YOH2FuI3LptY8sxuGIa_vx1mdJi6wqbMHQFZgBFG4kz2amWH1HUZdw_ZlzMcC0go2viQSQ2VNbHenAc8fzkdVUOneBJv3RISC2DLTo0oSrY0J-FWPr6U1Rwp20DZEPA/s1600/beagleboneLogo_small.png" /></a>get it to work properly for months. In the process I learned about pin muxing, bone-capemgr and compiling overlays. I was able to bring up the can0 interface and receive can messages with candump but the interface was unstable. It would randomly hang and stop receiving messages. If I tried to send anything with cansend I would get a kernel stack traces in dmesg and the can0 interface would hang. I tried Angstrom, Ubuntu and the latest Debian images all with the same results. Maybe my BBB board has a hardware problem. It is one of the early Rev B boards. Or maybe I'm running into some sort of kernel driver bug. Whatever the issue I am done trying to figure out what the eff is wrong with it and I just want to move forward with my project. (and yes I was using a transceiver). I considered bypassing the onboard can controller and talking to a MCP2515 over SPI but that gets into compiling a custom kernel for the BBB and I don't want to use up a SPI port. I mention all of this because I know someone out there will say "why didn't you just use the onboard can controller". I tried and I am done fighting with it.<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/AVvXsEj0EyuFcu4LamdfDY9vdhGtCbkCKDGpjFRgky3WnfpwHeRB-4gXwImYhcPT90G7t2fvHtTWIXmx-e8JmfzEHbzeyJMqheWLyz9EVMIHEgeRupXz6uPBnCviOue-EH76QJnjLCC_XzF45DE/s1600/IMG_5368.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0EyuFcu4LamdfDY9vdhGtCbkCKDGpjFRgky3WnfpwHeRB-4gXwImYhcPT90G7t2fvHtTWIXmx-e8JmfzEHbzeyJMqheWLyz9EVMIHEgeRupXz6uPBnCviOue-EH76QJnjLCC_XzF45DE/s1600/IMG_5368.jpg" height="320" width="240" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">My attempt at using the CAN controller on<br />
the BBB with an MCP2562 transceiver</td></tr>
</tbody></table>
<br />
<h4>
What now?</h4>
Once I decided I wasn't going to get the onboard BBB can controller to work I started thinking about options. My first attempt at a workaround was an Arduino Uno with a Seeed CAN Bus shield connected to the BBB with a USB cable. I read the data from the serial port created over the USB connection. While this worked it was a bit bulky and fragile. The USB cable is much too big, the Uno with a shield is big and the Uno would reset when serial communication started (<a href="http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection" target="_blank">though there is a workaround for this</a>).<br />
<br />
I took a break from this project for a while and in the meantime I ordered a few Adafruit Trinkets and Pro Trinkets just to play around with. The Pro Trinket has the same microcontroller as the Uno but the board is much, much smaller.<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/AVvXsEgafvoDrambYBp4-xQl1TrCWMm7CSZEiiyhMQDVuoJUdJ7lx-nfasqM2z7Los6GyD4jCj1Iuqsh8QNthIdndS3N3kur_ATXBw7sP767igSk9gIW5xvqIp04zOoBZko9egomZNZi9G7uwOA/s1600/TrinketSizeCompare+copy.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgafvoDrambYBp4-xQl1TrCWMm7CSZEiiyhMQDVuoJUdJ7lx-nfasqM2z7Los6GyD4jCj1Iuqsh8QNthIdndS3N3kur_ATXBw7sP767igSk9gIW5xvqIp04zOoBZko9egomZNZi9G7uwOA/s1600/TrinketSizeCompare+copy.jpg" height="300" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Size comparison between Uno, Pro Trinket and Trinket.<br />
(Photo credit: Adafruit)</td></tr>
</tbody></table>
<h4>
</h4>
<h4>
</h4>
<h4>
Pro Trinket CAN to UART Converter</h4>
The Pro Trinket has SPI and UART plus a bunch of digital and analog pins. After playing around with the Trinket I realized I could build a CAN Bus to UART converter that would be able to push CAN data into the BBB over a UART. The BeagleBone is a 3.3volt device so I used the 3volt version of the Pro Trinket so I didn't have to use any level shifters. For the CAN Bus controller I used an <a href="http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010406" target="_blank">MCP2515</a> and for the CAN transceiver I used an <a href="http://www.microchip.com/wwwproducts/Devices.aspx?product=MCP2562" target="_blank">MCP2562</a>. The MCP2515 connects to the Arduino using a <a href="http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus" target="_blank">SPI connection</a>. Here is the circuit I came up with:<br />
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioPZ4DdSWgz5YjSGyH6TwECVYvaIOnwonu2p2fFL8ZstuU7vKpBeL2zUwPwl4tYg7IsTPcM4IOTJ_0XOyHmj2es8W7S0wMrShULUk8Qu21ReGqKz4FavNHXRj_iJNoHwOWl4NxjZ7dz6I/s1600/IMG_5367.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioPZ4DdSWgz5YjSGyH6TwECVYvaIOnwonu2p2fFL8ZstuU7vKpBeL2zUwPwl4tYg7IsTPcM4IOTJ_0XOyHmj2es8W7S0wMrShULUk8Qu21ReGqKz4FavNHXRj_iJNoHwOWl4NxjZ7dz6I/s1600/IMG_5367.JPG" height="300" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
Here is a Fritzing breadboard diagram of the circuit:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyp17BKVbOUsTjtZ6fsk3zqydwIXZVXU6eR-DJa-qPztqU0bJhfWt5BTYA95r4MXQRKBYO5fpy-WXO-LVvtfh4zwjZmKJWN98XK5o2k8eI8Q6DiDI8CyAkHQKl7wZZwl0bjIrQcpiWmlU/s1600/Trinket_CAN_to_UART_bb.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyp17BKVbOUsTjtZ6fsk3zqydwIXZVXU6eR-DJa-qPztqU0bJhfWt5BTYA95r4MXQRKBYO5fpy-WXO-LVvtfh4zwjZmKJWN98XK5o2k8eI8Q6DiDI8CyAkHQKl7wZZwl0bjIrQcpiWmlU/s1600/Trinket_CAN_to_UART_bb.png" height="376" width="400" /></a></div>
<div>
<br />
The UART serial connection between the Arduino and the BeagleBone runs at 115,200 bps so you might drop a few packets on a very busy CAN bus running at 500kbps. My Digital Dashboard project is only going to have a few devices broadcasting CAN packets so the UART speed will be more than enough for my purposes. The current version only transmits CAN data to the BBB. It should be fairly trivial to connect the BBB UART1 TX to the RX on the Arduino. It would also need a bit of code to parse the message received on the UART and write it to the CAN bus. I'm planning on adding the functionality soon and I'll write up another post when I have that done. I'm planning on changing the Arduino code to use an <a href="http://arduino.cc/en/Reference/attachInterrupt" target="_blank">External Interrupt</a> so the Trinket can perform a few other functions instead of just polling for incoming messages.</div>
<div>
<br /></div>
<h4>
The Arduino Code</h4>
<div>
The way this works is the MCP2515 has an INT (interrupt) pin that signals when a CAN message has been received. The INT pin drives Pin3 on the Arduino low and triggers it to read messages from the MCP2515 buffer. Once a message has been read from the MCP2515 buffer it is formatted into a <a href="http://en.wikipedia.org/wiki/NMEA_0183" target="_blank">NMEA</a>-ish string that is written to the serial port and transmitted to the BBB on UART1.<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/AVvXsEjlJ8aN5ijKNHW-nQs7rgeh63iWk-boLfrY-jfWgoUQ939uJTGQ-jXwpmIxy3AK7N4RGtEg6eKCcq7N62_NEnPpoX0k5I6WlTHISlAZYLItlSMnyLD-3ks8dM11Q5fYVnYSOEbFC3GVrG8/s1600/Screenshot+2015-02-01+12.22.56.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlJ8aN5ijKNHW-nQs7rgeh63iWk-boLfrY-jfWgoUQ939uJTGQ-jXwpmIxy3AK7N4RGtEg6eKCcq7N62_NEnPpoX0k5I6WlTHISlAZYLItlSMnyLD-3ks8dM11Q5fYVnYSOEbFC3GVrG8/s1600/Screenshot+2015-02-01+12.22.56.png" height="241" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Screenshot of CAN data coming in on UART1</td></tr>
</tbody></table>
<br />
Here is the Arduino code:</div>
<div>
<br /></div>
<div>
<br />
<script src="https://gist.github.com/matt448/f55eb943129247ff05ae.js"></script>
<br />
<h4>
Setting up the BeagleBone</h4>
The pins on the BeagleBone need to be configured to be used as a UART. I used <a href="https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black" target="_blank">Adafruit's python IO library</a> to do this. When you install their library it will create the overlays needed to configure the pins. Follow the instructions on their learn site here: <a href="https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black">https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black</a>. Here is the code to receive the CAN messages on BBB UART1:<br />
<br />
<script src="https://gist.github.com/matt448/65ca3fee006e0ae6596f.js"></script>
<br />
<h4>
Costs</h4>
The price for these parts wasn't bad at all<br />
<br />
Adafruit Pro Trinket 3v - $9.95<br />
16Mhz Crystal - $1.12<br />
Two 22pF ceramic capacitors - $0.66<br />
MCP2515 CAN controller - $2.18<br />
MCP2562 CAN transceiver - $1.12<br />
<br />
Total: $15.03<br />
<br />
<br />
Well that's it for now. Next I'm going to work on modifying the code to use External Interrupts and then see if I can get it setup to receive messages over the UART. I also need to get this thing moved from the breadboard and soldered on to some protoboard.<br />
<br />
<br />
<br />
<br />
Resources<br />
<span style="font-size: x-small;"><a href="http://www.embedded-things.com/bbb/enable-canbus-on-the-beaglebone-black/">http://www.embedded-things.com/bbb/enable-canbus-on-the-beaglebone-black/</a></span><br />
<span style="font-size: x-small;"><a href="http://www.adafruit.com/product/2010">http://www.adafruit.com/product/2010</a></span><br />
<span style="font-size: x-small;"><a href="https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/uart">https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/uart</a></span><br />
<span style="font-size: x-small;"><a href="http://ww1.microchip.com/downloads/en/DeviceDoc/21801d.pdf">http://ww1.microchip.com/downloads/en/DeviceDoc/21801d.pdf</a></span><br />
<span style="font-size: x-small;"><a href="http://ww1.microchip.com/downloads/en/DeviceDoc/25167B.pdf">http://ww1.microchip.com/downloads/en/DeviceDoc/25167B.pdf</a></span></div>
Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com0tag:blogger.com,1999:blog-9120755343492164185.post-42815528203794972972014-10-05T16:55:00.000-05:002015-03-11T11:12:57.822-05:00Speed up screen redraws with a BeagleBone Black and Adafruit TFT<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRYmikxa0OnJi4YOH2FuI3LptY8sxuGIa_vx1mdJi6wqbMHQFZgBFG4kz2amWH1HUZdw_ZlzMcC0go2viQSQ2VNbHenAc8fzkdVUOneBJv3RISC2DLTo0oSrY0J-FWPr6U1Rwp20DZEPA/s1600/beagleboneLogo_small.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRYmikxa0OnJi4YOH2FuI3LptY8sxuGIa_vx1mdJi6wqbMHQFZgBFG4kz2amWH1HUZdw_ZlzMcC0go2viQSQ2VNbHenAc8fzkdVUOneBJv3RISC2DLTo0oSrY0J-FWPr6U1Rwp20DZEPA/s1600/beagleboneLogo_small.png" /></a></div>
In a <a href="http://matthewcmcmillan.blogspot.com/2014/09/experimenting-with-beaglebone-black-and-tft.html" target="_blank">previous post</a> I wrote about experimenting with the <a href="http://beagleboard.org/black" target="_blank">BeagleBone Black</a> and an <a href="http://www.adafruit.com/products/1480" target="_blank">Adafruit 2.2" TFT screen</a>. The TFT screen communicates over SPI using a userspace library. Being a userspace library it is expected it will be slower than driver that is compiled into the kernel but something in the code seemed to be causing redraws to be unnecessarily slow.<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/AVvXsEjj75rbm6rYdtvdyW8CB1_BzSXBR4S3yHm70lx9YFUrbwWfIK7zO4hJQjalxoQB22HYfR9dLSRLP8pBWtsaYgNfKeYkMVmBbzlsO9r8j0mLcW9DtWxUwvrqUCrbv5rLvQDQbGNdMj_f57E/s1600/IMG_4886.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjj75rbm6rYdtvdyW8CB1_BzSXBR4S3yHm70lx9YFUrbwWfIK7zO4hJQjalxoQB22HYfR9dLSRLP8pBWtsaYgNfKeYkMVmBbzlsO9r8j0mLcW9DtWxUwvrqUCrbv5rLvQDQbGNdMj_f57E/s1600/IMG_4886.jpg" height="320" width="240" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Adafruit 2.2" TFT with a BeagleBone Black</td></tr>
</tbody></table>
To measure how long the screen draws were taking I modified the example image.py script to read the time right before and right after the screen draw function call. I also wrapped a while loop around it so it would redraw the screen repeatedly to give me an average of how long it took.<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/AVvXsEjnYM_D641A9YOs-X8WqkmmKojGptUINDDdEvtLEmki0NgQWRJ_kMaOyvMDMO_hTxVFYMgglD1V3V0woiwPeyRRz_JcFF6JkPFbP0voCzgBlM4Oj8MeB6Xwo4z4TAGi5EJB0zKfyE5wbwM/s1600/Screenshot+2014-10-05+13.49.46.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnYM_D641A9YOs-X8WqkmmKojGptUINDDdEvtLEmki0NgQWRJ_kMaOyvMDMO_hTxVFYMgglD1V3V0woiwPeyRRz_JcFF6JkPFbP0voCzgBlM4Oj8MeB6Xwo4z4TAGi5EJB0zKfyE5wbwM/s1600/Screenshot+2014-10-05+13.49.46.png" height="143" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Code to measure screen redraw time</td></tr>
</tbody></table>
<br />
Depending on how much of the screen was being redrawn and the load on the BBB it would take between 0.7 seconds to 0.9 seconds to execute the disp.display(image) function. The following output is for the example image.py that draws the cat.jpg file to the screen:<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/AVvXsEhoSg9K0KOghEnR9LsIQ4d0_sOzmbuHOHsBhBgLTJM5Fx6l4hPtmoz9epZQUq7Isysaj_HRkEAEm9EOkBqyubB_YLzOVFln55Zl8HDTDKP9ZAazPv4Q59Lb3Hdzuu8s59cZKH16ThnIl0M/s1600/Screenshot+2014-10-05+13.48.57.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoSg9K0KOghEnR9LsIQ4d0_sOzmbuHOHsBhBgLTJM5Fx6l4hPtmoz9epZQUq7Isysaj_HRkEAEm9EOkBqyubB_YLzOVFln55Zl8HDTDKP9ZAazPv4Q59Lb3Hdzuu8s59cZKH16ThnIl0M/s1600/Screenshot+2014-10-05+13.48.57.png" height="217" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Output measuring screen redraw time</td></tr>
</tbody></table>
<br />
One of the commenters on my <a href="http://matthewcmcmillan.blogspot.com/2014/09/experimenting-with-beaglebone-black-and-tft.html" target="_blank">previous post</a> tracked down the slowness to one specific function named 'image_to_data' in the file ILI9341.py. He also supplied a modification that reduced his screen redraw time dramatically by using NumPy. I tried it out and it reduced my screen redraw times dramatically. Screen redraws went from 0.85 seconds to 0.17 seconds. That is an 80% improvement!<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/AVvXsEhWNZv9zsP5s5DcDgw6HBJ65IOno92tAdbJrteiYBFyer2Rp5B2bIZ5lHpQ572qgxMwbE6SfbH0rKKb8wD1k6IgD9LhnU3Glb3M7rHd9ca9KT33d5cPccZB0c1nECuQbnDkZEpilumk-l4/s1600/Screenshot+2014-10-05+15.51.04.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWNZv9zsP5s5DcDgw6HBJ65IOno92tAdbJrteiYBFyer2Rp5B2bIZ5lHpQ572qgxMwbE6SfbH0rKKb8wD1k6IgD9LhnU3Glb3M7rHd9ca9KT33d5cPccZB0c1nECuQbnDkZEpilumk-l4/s1600/Screenshot+2014-10-05+15.51.04.png" height="200" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Screen redraw times when using NumPy</td></tr>
</tbody></table>
<br />
If you want to make this modification yourself here is what you need to do:<br />
<br />
1. Install PyNum. This is easy to install as it is available as a pkg.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</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/AVvXsEj6cLRmO5WzkdfNOpoiql3Db0BGyK0wOh8oLNJfzuOoh765hfiHDJpAvC4QXPfVZQQ6_F3dtmbxY4gcY0OsYTJGJUgQPTXTWiTfgqian23a85J3YOHp_aoLuaNVKfqHvZK_BRd70JTxaqw/s1600/Screenshot+2014-10-05+16.21.15.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6cLRmO5WzkdfNOpoiql3Db0BGyK0wOh8oLNJfzuOoh765hfiHDJpAvC4QXPfVZQQ6_F3dtmbxY4gcY0OsYTJGJUgQPTXTWiTfgqian23a85J3YOHp_aoLuaNVKfqHvZK_BRd70JTxaqw/s1600/Screenshot+2014-10-05+16.21.15.png" height="87" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Install the python-numpy package</td></tr>
</tbody></table>
<br />
<br />
2. Edit the file Adafruit_Python_ILI9341/Adafruit_ILI9341/ILI9341.py<br />
<br />
First add the import statement at the top<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/AVvXsEj1QLNzVj8UPlNh_FegpPZT3pkhuZvxtfhW6LVhdNRUjEGoBc9M-lDQDYn0mzyqYPwOf6aAP1qUpiyyYEhUfpFep7q_sBWq7ozw6XtsYUGJB0-NJ2svKR4sbTfbaplnadBqgMq1QOD3iP0/s1600/Screenshot+2014-10-05+16.16.22.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1QLNzVj8UPlNh_FegpPZT3pkhuZvxtfhW6LVhdNRUjEGoBc9M-lDQDYn0mzyqYPwOf6aAP1qUpiyyYEhUfpFep7q_sBWq7ozw6XtsYUGJB0-NJ2svKR4sbTfbaplnadBqgMq1QOD3iP0/s1600/Screenshot+2014-10-05+16.16.22.png" height="88" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Add import statement for numpy</td></tr>
</tbody></table>
<br />
Next modify the image_to_data function. Here is the original function<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/AVvXsEj8Mj3k7FLnaA4FC6GCGloOpdvLr6L3qGQmItC1d3Hg0us9Aa-RSAS4HxE2XGJzApYuEN-IMzHn95z6CfJGCT-ntq4NQggEGOeoaZJ6wRM9zhqo3Sug6leaQ77k7SayDtze-X4cwFcPXA0/s1600/Screenshot+2014-10-05+16.25.46.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8Mj3k7FLnaA4FC6GCGloOpdvLr6L3qGQmItC1d3Hg0us9Aa-RSAS4HxE2XGJzApYuEN-IMzHn95z6CfJGCT-ntq4NQggEGOeoaZJ6wRM9zhqo3Sug6leaQ77k7SayDtze-X4cwFcPXA0/s1600/Screenshot+2014-10-05+16.25.46.png" height="116" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Original image_to_data function</td></tr>
</tbody></table>
<br />
and here is the function after being modified to use NumPy<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/AVvXsEj4mqn9DiCbhwVFaFrkSWEMJbDPE628NmzoWlGTOzsfCc0GXqxSRea9PAfPCdu7srTbxIjRxCJ3Pat9DQHLdrZKS6H6zWV1O85zXQj3O6soWL2xWn2KlyDkXlxUIFbqtD3EH1HW8hyphenhyphenmMsw/s1600/Screenshot+2014-10-05+16.15.52.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4mqn9DiCbhwVFaFrkSWEMJbDPE628NmzoWlGTOzsfCc0GXqxSRea9PAfPCdu7srTbxIjRxCJ3Pat9DQHLdrZKS6H6zWV1O85zXQj3O6soWL2xWn2KlyDkXlxUIFbqtD3EH1HW8hyphenhyphenmMsw/s1600/Screenshot+2014-10-05+16.15.52.png" height="87" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Modified image_to_data function</td></tr>
</tbody></table>
<br />
3. Save the file and then re-run the installation script.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizsZaLTWYW4PY-NbTmXAsWMipXIOal0R3AKjl18cXj2v9xErX_G5iP5k1-WpMKwT05XKe0tGyvplF5YzjtmKNMluyD7C3bmCZAYecCMnO6EG6UZpPli8r8YzDk6AePcceAqPIZuS-utYs/s1600/Screenshot+2014-10-05+16.31.07.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizsZaLTWYW4PY-NbTmXAsWMipXIOal0R3AKjl18cXj2v9xErX_G5iP5k1-WpMKwT05XKe0tGyvplF5YzjtmKNMluyD7C3bmCZAYecCMnO6EG6UZpPli8r8YzDk6AePcceAqPIZuS-utYs/s1600/Screenshot+2014-10-05+16.31.07.png" height="150" width="400" /></a></div>
<br />
<br />
If you don't want to manually make these modifications you can use my forked version of the library: <a href="https://github.com/matt448/Adafruit_Python_ILI9341">https://github.com/matt448/Adafruit_Python_ILI9341</a><br />
<br />
I have submitted a pull request to Adafruit for this change so maybe in the future this will be included there. [<b>UPDATE</b>: Adafruit has pulled these changes into the master branch of their library. If you download the latest version here <a href="https://github.com/adafruit/Adafruit_Python_ILI9341">https://github.com/adafruit/Adafruit_Python_ILI9341</a> you will get the improved screen drawing speed.]<br />
<br />
<br />
Here are videos before and after I made the change. It's quite noticeable when making quick changes. Before making the code changes the display would lag behind when adjustments were made to the pot.<br />
<table align="center" cellpadding="5"><tbody>
<tr>
<td align="center"><b>BEFORE</b></td><td align="center"><b>AFTER</b></td></tr>
<tr><td><iframe allowfullscreen="" frameborder="0" height="155" src="//www.youtube.com/embed/5VdBBJ_3QQ4" width="275"></iframe>
</td><td><iframe allowfullscreen="" frameborder="0" height="155" src="//www.youtube.com/embed/gOzzidE5tiI" width="275"></iframe>
</td></tr>
</tbody></table>
<br />
<br />
<br />
[Updated 2014-10-08: Added before and after videos.]<br />
[Updated 2015-03-11: Added note about my pull request being included in the main library.]<br />
<br />
<br />Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com0tag:blogger.com,1999:blog-9120755343492164185.post-8300174371639304402014-09-25T14:46:00.001-05:002015-03-03T09:05:02.188-06:00Using the Seeed CAN-BUS shield with an Arduino Mega<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" imageanchor="1" style="clear: left; display: inline !important; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"></a></div>
<div style="clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em; text-align: left;">
</div>
<br />
The <a href="http://www.seeedstudio.com/depot/CANBUS-Shield-p-1240.html" target="_blank">Seeed Studio CAN-BUS shield</a> is designed specifically to be used with an <a href="http://arduino.cc/en/Main/arduinoBoardUno" target="_blank">Arduino Uno</a> but with a simple modification you can use it with several other Arduino boards. I sourced this info from a few different forums and thought I would write up a complete post on exactly how to do this. The Seeed website had some info on how to use the shield with a Mega but their info was not complete and did not work for me. In this post I am going to show how to use the Seeed CAN-BUS shield with an <a href="http://arduino.cc/en/Main/arduinoBoardMega2560" target="_blank">Arduino Mega 2560</a>.<br />
<br />
The CAN-BUS shield incompatibility with Arduino boards other than the Uno arises from where Seeed chose to access the SPI pins. They used pins 11,12,13 to access SPI on the Uno. On the Mega the SPI pins are 50,51,52. A better design would have been to use the SPI pins on the ICSP header which is consistent on the Uno, Mega, Due and Leonardo but such is life and we have to work with what is available right now. Seeed's site does mention they are working on a 1.1 version of the board that moves SPI to the ICSP header.<br />
<br />
Here is an Arduino Uno with the SPI pins labeled<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/AVvXsEhmaXibEdD8U0d6ULpF5QS3AfgNadhW0dnDVbN2Nqhhp3g1_STNGD3P9RVwu3T27srn-BF7SsPBpznSrIDt9VhwKavNJBGW63eXWvB1RSToQouRpGKmhiAYh-JYYQzK5MNWCBUAuqTmgXU/s1600/ArduinoUno_R3_Front_edit.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmaXibEdD8U0d6ULpF5QS3AfgNadhW0dnDVbN2Nqhhp3g1_STNGD3P9RVwu3T27srn-BF7SsPBpznSrIDt9VhwKavNJBGW63eXWvB1RSToQouRpGKmhiAYh-JYYQzK5MNWCBUAuqTmgXU/s1600/ArduinoUno_R3_Front_edit.jpg" height="277" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Arduino Uno SPI pins</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
And here is an Arduino Mega 2560 with the SPI pins labeled</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/AVvXsEj55eW-aDy70Ho1oSNXCc0S6tOlQDb8Trz1oZ2Je7pD03J6ZCOIy2vBe4CNcDYDXILMnSQoLpzTWRCOZhDQP7ec18NZ1AO_-Cha3Omz6RPNxA8SbQ6RqKnp5s-63USsA5nwDFLHGi1Rcl8/s1600/ArduinoMega2560_R3_Front_edit.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj55eW-aDy70Ho1oSNXCc0S6tOlQDb8Trz1oZ2Je7pD03J6ZCOIy2vBe4CNcDYDXILMnSQoLpzTWRCOZhDQP7ec18NZ1AO_-Cha3Omz6RPNxA8SbQ6RqKnp5s-63USsA5nwDFLHGi1Rcl8/s1600/ArduinoMega2560_R3_Front_edit.jpg" height="247" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Arduino Mega 2560 SPI pins</td></tr>
</tbody></table>
<br />
<br />
Here is what the Seeed Studio CAN-BUS Shield looks like if you don't already own one<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/AVvXsEhH8zDB-i4wbSou5dYN29nGqTh6FuepUipgALampEKoNoSrirkcORPvorMarB-UY7RY4EhFGpi__wsJrtUyt3SbnrO4lP7VJjNYcVhdDFECfmerGAaXfI99J9OeCzqM5d8J3UXIxkhlSyg/s1600/canbus+shield.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH8zDB-i4wbSou5dYN29nGqTh6FuepUipgALampEKoNoSrirkcORPvorMarB-UY7RY4EhFGpi__wsJrtUyt3SbnrO4lP7VJjNYcVhdDFECfmerGAaXfI99J9OeCzqM5d8J3UXIxkhlSyg/s1600/canbus+shield.jpg" height="240" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Seeed Studio CAN-BUS Shield v1.0</td></tr>
</tbody></table>
<br />
<br />
<h4>
The mod</h4>
Here is how to modify the CAN-BUS Shield to work with a Mega. The basic overview of the mod is that we need to change the SPI pins that the CAN-BUS Shield is using. There are two ways to do this modification. One one is reversible and the other is more permanent. First the reversible method.</div>
<div>
<br /></div>
<div>
The reversible method is to bend three pins on the CAN-BUS Shield like this:</div>
<div>
<br /></div>
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjuCwEjAAeV2itlxkq4-1-4udK63Mg81fn000xyxFAfMtf3wUApdaRN6mZbwaxk1Z4R2bzKNuHlPUYT2AS1ctTF-p9n_LVb1vKUWFPWoFS9Vz9YIWHPCCZIthDeeNnS2FhADlmfoxeUE8/s1600/IMG_4843.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjuCwEjAAeV2itlxkq4-1-4udK63Mg81fn000xyxFAfMtf3wUApdaRN6mZbwaxk1Z4R2bzKNuHlPUYT2AS1ctTF-p9n_LVb1vKUWFPWoFS9Vz9YIWHPCCZIthDeeNnS2FhADlmfoxeUE8/s1600/IMG_4843.jpg" height="200" width="150" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5XxOqlpFZfij2aVifWCEEwhI7kQ68kCGpCE2YWaz_du1ldzsaWZVuldhiYF5UAi9th6HuzOjfv6Gsn8Q1gQ8l3kAFQaYNnwquTn25sfIVpvk8ojzpnQ4c77ynlETAVfQGLIJRDDN0-_I/s1600/IMG_4844.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5XxOqlpFZfij2aVifWCEEwhI7kQ68kCGpCE2YWaz_du1ldzsaWZVuldhiYF5UAi9th6HuzOjfv6Gsn8Q1gQ8l3kAFQaYNnwquTn25sfIVpvk8ojzpnQ4c77ynlETAVfQGLIJRDDN0-_I/s1600/IMG_4844.jpg" height="200" width="150" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijjVUdsr17r2QvNum56C9eomUfxkCNj3pAf9loHh2wBKvh5hCS-_7Q9wukgZ_0qRxv_TLloiSqOx_DMk_3Kioy_V1Oak8DNyqraUAWpNJAdlxxbogvBl304p6zk48Za7EAyjFtcV8o-IU/s1600/IMG_4846.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijjVUdsr17r2QvNum56C9eomUfxkCNj3pAf9loHh2wBKvh5hCS-_7Q9wukgZ_0qRxv_TLloiSqOx_DMk_3Kioy_V1Oak8DNyqraUAWpNJAdlxxbogvBl304p6zk48Za7EAyjFtcV8o-IU/s1600/IMG_4846.jpg" height="200" width="150" /></a></div>
</td></tr>
</tbody></table>
<div>
<br />
<div class="separator" style="clear: both; text-align: left;">
When you plug the shield into the Mega it will look like this:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY23e7PQSpTwCMPAAf9N1PfyWqx8UejbrPiDocaxduNvL_1YkKg3LOmK-Q0j0x9S4ZR2fswp88Bh8MiRN2TtyCko-l_fLEDaCYvuEdru1xe7AQq9UdaSJ2NQ_AQoQ64d0jcMRM-m3kQto/s1600/IMG_4839+copy.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY23e7PQSpTwCMPAAf9N1PfyWqx8UejbrPiDocaxduNvL_1YkKg3LOmK-Q0j0x9S4ZR2fswp88Bh8MiRN2TtyCko-l_fLEDaCYvuEdru1xe7AQq9UdaSJ2NQ_AQoQ64d0jcMRM-m3kQto/s1600/IMG_4839+copy.jpg" height="150" width="200" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8ujjGSKNJIdIIbAWJlR03widg8qaZN8Os8v7lXIYYmi3al108ecZbP2-LpZRoYna6YqQf-PHHE_12go62F-ULrgmDtpm3uOrWjrbbXb888mX46cD2vsnZb3V1zOxTKVGeHkzImLDJ6IQ/s1600/IMG_4840+copy.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8ujjGSKNJIdIIbAWJlR03widg8qaZN8Os8v7lXIYYmi3al108ecZbP2-LpZRoYna6YqQf-PHHE_12go62F-ULrgmDtpm3uOrWjrbbXb888mX46cD2vsnZb3V1zOxTKVGeHkzImLDJ6IQ/s1600/IMG_4840+copy.jpg" height="150" width="200" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
With bent pins I was able to bend them back use the shield with an Uno again.<br />
<br />
Now you need to use three <a href="https://www.adafruit.com/products/1957" target="_blank">jumper wires</a> to connect the SPI pins on the shield to the SPI pins on the Arduino board. In my example I connected the wires to pins 50,51,52 on the Arduino because I only had male-male jumper wires. If you have <a href="https://www.adafruit.com/products/1953" target="_blank">male-female jumper wires</a> you can connect to the ICSP header instead.<br />
<br />
<div style="text-align: center;">
Jumper wire connections
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg .tg-e3zv{font-weight:bold}
</style>
</div>
<table align="center" class="tg">
<tbody>
<tr>
<th class="tg-e3zv">Mega Pin</th>
<th class="tg-e3zv">Shield Pin</th>
<th class="tg-e3zv">SPI Desc</th>
</tr>
<tr>
<td class="tg-031e">50</td>
<td class="tg-031e">12</td>
<td class="tg-031e">MISO</td>
</tr>
<tr>
<td class="tg-031e">51</td>
<td class="tg-031e">11</td>
<td class="tg-031e">MOSI</td>
</tr>
<tr>
<td class="tg-031e">52</td>
<td class="tg-031e">13</td>
<td class="tg-031e">SCK</td>
</tr>
</tbody></table>
<br />
<br />
Here is what it looks like with the jumper wires installed<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhpT5VGlIKolmyQ4AiTeABH51NhqDPz4tb75zqd2sDeZMyiT8JkUKreV9JOhyiENqz0NwtOBLDNsoqyQtIqxYZRXz8HxlwvesJhhQEI2OPuDxp3EWF9o8gpQTtAVFTNpabw3ucu2e6kCs/s1600/IMG_4838.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhpT5VGlIKolmyQ4AiTeABH51NhqDPz4tb75zqd2sDeZMyiT8JkUKreV9JOhyiENqz0NwtOBLDNsoqyQtIqxYZRXz8HxlwvesJhhQEI2OPuDxp3EWF9o8gpQTtAVFTNpabw3ucu2e6kCs/s1600/IMG_4838.JPG" height="300" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4TbfIdmLlKKAPQR2W5-qm3pjADUDfY2aRLeBfB_2wo_WnBuBDxzcLbUxNM-c1P7JHblw5zLuqf59EW7X4lclFrybCTmSsqGw6_b9DnptHqkEfi2JtOauD40gk7t3l188iGNokRCZ2tWc/s1600/IMG_4841.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4TbfIdmLlKKAPQR2W5-qm3pjADUDfY2aRLeBfB_2wo_WnBuBDxzcLbUxNM-c1P7JHblw5zLuqf59EW7X4lclFrybCTmSsqGw6_b9DnptHqkEfi2JtOauD40gk7t3l188iGNokRCZ2tWc/s1600/IMG_4841.JPG" height="300" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfF9ODzqOdkh7Eedoz6N4l8Zy7WcRE54Z0rEX6TX3eSGsJ5LPQN49xx1mL5229-9XcGwr9ZyOzqU7Rktsm7hQhIzIEwTdnkITagvvpRrlrVEdHEFmHj-XmnfqbSFRyMPtCUxFVjnefMu0/s1600/IMG_4842.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfF9ODzqOdkh7Eedoz6N4l8Zy7WcRE54Z0rEX6TX3eSGsJ5LPQN49xx1mL5229-9XcGwr9ZyOzqU7Rktsm7hQhIzIEwTdnkITagvvpRrlrVEdHEFmHj-XmnfqbSFRyMPtCUxFVjnefMu0/s1600/IMG_4842.JPG" height="300" width="400" /></a></div>
<br />
I would recommend you use <a href="https://github.com/coryjfowler/MCP2515_lib" target="_blank">coryjfowler's MCP2515 library</a> instead of the Seeed's because his fork of the library has a configureable SS pin but Seeed's version will work with this mod because they hard coded the SS pin as digital pin 10.<br />
<br />
I then loaded up one of the examples and the shield started up correctly.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihQcs02JV1wq09aLf1uDdr4nUG5wF6MCuL8exdIRJPYMULscMq-5lx3Ph1p3BkLecFl-u9YJsA8gFgI8U1HBN7Z8O9NCeyrEavL1TIhNXFLeMz-pcefyQXTwk68RG-4Mmud6K8wWm2jfk/s1600/can_init.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihQcs02JV1wq09aLf1uDdr4nUG5wF6MCuL8exdIRJPYMULscMq-5lx3Ph1p3BkLecFl-u9YJsA8gFgI8U1HBN7Z8O9NCeyrEavL1TIhNXFLeMz-pcefyQXTwk68RG-4Mmud6K8wWm2jfk/s1600/can_init.jpg" height="140" width="320" /></a></div>
<br />
If you want to make this modification more permanent you can simply snip off the three pins instead of bending them.<br />
<br />
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibx9mfg9HFpS2JmRcMLzWixFz-g7b096-VYf86VhgbH1h3z5fxbXdFiCiMMAX55V9fS2BJODL86N343wS_9ggXfaNDEUrjw137I89r0sMJFAW0uHmgAXBBglL5USHtdTwcdtUVnAcB8SI/s1600/IMG_4865.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibx9mfg9HFpS2JmRcMLzWixFz-g7b096-VYf86VhgbH1h3z5fxbXdFiCiMMAX55V9fS2BJODL86N343wS_9ggXfaNDEUrjw137I89r0sMJFAW0uHmgAXBBglL5USHtdTwcdtUVnAcB8SI/s1600/IMG_4865.JPG" height="150" width="200" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0hLeQJAlavdBIjH8dcJgvTFWu-n25S3opaJqUSbyUbQnwU4cFGXhm3g-gszeIF2baAx0j-5POyd20DjfQY3e5I_ILA5UQuJ3SXOYpYOvQFQVpjgvbYHl9FhqKOX3TSuKbOtcAUql7WN4/s1600/IMG_4866.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0hLeQJAlavdBIjH8dcJgvTFWu-n25S3opaJqUSbyUbQnwU4cFGXhm3g-gszeIF2baAx0j-5POyd20DjfQY3e5I_ILA5UQuJ3SXOYpYOvQFQVpjgvbYHl9FhqKOX3TSuKbOtcAUql7WN4/s1600/IMG_4866.JPG" height="150" width="200" /></a></div>
</td></tr>
</tbody></table>
<br />
<br />
I found some male-female jumper wires at Fry's Electronics yesterday. Here is what it looks like when using the ICSP headers<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHn3dqUMQbysIebUSOC5kQh6Azi2sQvCd82odfsM7aKEWfJEIjiR7nSaG0dMTY9wHtU6RRCb4YSB6eoMr6XqYhQjOR-MqJ-BAxqjndaXcfbWMGIdNCk3DahhB7symHujT1r-iqaNxmoOo/s1600/IMG_4867.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHn3dqUMQbysIebUSOC5kQh6Azi2sQvCd82odfsM7aKEWfJEIjiR7nSaG0dMTY9wHtU6RRCb4YSB6eoMr6XqYhQjOR-MqJ-BAxqjndaXcfbWMGIdNCk3DahhB7symHujT1r-iqaNxmoOo/s1600/IMG_4867.JPG" height="300" width="400" /></a></div>
<br /></div>
<table align="center" class="tg">
<tbody>
<tr>
<th class="tg-e3zv">ICSP Pin</th>
<th class="tg-e3zv">Shield Pin</th>
<th class="tg-e3zv">SPI Desc</th>
</tr>
<tr>
<td class="tg-031e">1</td>
<td class="tg-031e">12</td>
<td class="tg-031e">MISO</td>
</tr>
<tr>
<td class="tg-031e">4</td>
<td class="tg-031e">11</td>
<td class="tg-031e">MOSI</td>
</tr>
<tr>
<td class="tg-031e">3</td>
<td class="tg-031e">13</td>
<td class="tg-031e">SCK</td>
</tr>
</tbody></table>
<br />
<br />
Sources<br />
<a href="http://arduino.cc/en/Reference/SPI"><span style="font-size: x-small;">http://arduino.cc/en/Reference/SPI</span></a><br />
<a href="http://forum.arduino.cc/index.php?topic=123367.0"><span style="font-size: x-small;">http://forum.arduino.cc/index.php?topic=123367.0</span></a><br />
<a href="http://www.seeedstudio.com/forum/viewtopic.php?f=23&t=5172"><span style="font-size: x-small;">http://www.seeedstudio.com/forum/viewtopic.php?f=23&t=5172</span></a><br />
<a href="http://www.seeedstudio.com/wiki/Talk:CAN-BUS_Shield"><span style="font-size: x-small;">http://www.seeedstudio.com/wiki/Talk:CAN-BUS_Shield</span></a><br />
<a href="http://www.seeedstudio.com/wiki/CAN-BUS_Shield"><span style="font-size: x-small;">http://www.seeedstudio.com/wiki/CAN-BUS_Shield</span></a><br />
<br />
<br />
[Updated 2014-09-29] - Added photos of shield with the pins snipped off. Also added photo showing the male-female jumpers with the ICSP header.<br />
<br />
[Updated 2014-10-23] - Added table with pinouts for connecting the shield to the ICSP header.<br />
<br />Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com8tag:blogger.com,1999:blog-9120755343492164185.post-31834593541946269182014-09-19T12:33:00.000-05:002014-09-19T12:33:41.935-05:00Trouble installing PyCrypto on Mac OSX 10.9<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUcfSzBZd3JOs8EqgWTKHgJW-Dp9QB-BpxvJ2HsK_5L_Q5GlTSxV0eYPo_zG0SqCFq6ibCAKhefgwnETf05AIYmzTCLblpUETTMw_IUXW9wktaekyK55v3W8xpMf_5_-BXUhEJ8DEtOrI/s1600/Python-logo-notext_75x75.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUcfSzBZd3JOs8EqgWTKHgJW-Dp9QB-BpxvJ2HsK_5L_Q5GlTSxV0eYPo_zG0SqCFq6ibCAKhefgwnETf05AIYmzTCLblpUETTMw_IUXW9wktaekyK55v3W8xpMf_5_-BXUhEJ8DEtOrI/s1600/Python-logo-notext_75x75.jpg" /></a></div>
<br />
This afternoon I was trying to install the PyCrypto Python library on my Mac running OSX 10.9.4 with the built in Python. To install the library I was using the command 'sudo pip install pycrypto' but it kept failing when trying to compile parts of the library with the C compiler. This is the error I was getting:<br />
<br />
<pre>checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/private/tmp/pip_build_root/pycrypto':
configure: error: C compiler cannot create executables
See `config.log' for more details
</pre>
<br />
Grrr... I searched around and read a bunch of <a href="http://stackoverflow.com/" target="_blank">stackoverflow</a> questions but it seemed like I had everything in place that I needed to compile this library. Xcode was installed, I have the <a href="https://developer.apple.com/downloads/index.action?=command%20line%20tools" target="_blank">Command Line Tools</a> installed, I have a recent version of pip installed. Why won't the C compiler work??<br />
<br />
Well the answer turned out to be something really dumb. I recently updated Xcode but I had not launched the Xcode application since it was updated. Turns out the command line C compiler won't compile anything until you accept the license agreement for the updated Xcode. I opened the Xcode gui and clicked Accept. After that I was able to install PyCrypto. I also found you can accept the agreement from the command line using the command '<span style="white-space: pre-wrap;">sudo xcodebuild -license' but you have to page through all the text and type agree.</span><br />
<span style="white-space: pre-wrap;"><br /></span>
<span style="white-space: pre-wrap;"><br /></span>
<span style="white-space: pre-wrap;"><br /></span>Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com3tag:blogger.com,1999:blog-9120755343492164185.post-67047001735546550692014-09-05T00:04:00.000-05:002015-02-17T22:07:31.015-06:00Experimenting with BeagleBone Black and a userspace TFT library<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRYmikxa0OnJi4YOH2FuI3LptY8sxuGIa_vx1mdJi6wqbMHQFZgBFG4kz2amWH1HUZdw_ZlzMcC0go2viQSQ2VNbHenAc8fzkdVUOneBJv3RISC2DLTo0oSrY0J-FWPr6U1Rwp20DZEPA/s1600/beagleboneLogo_small.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRYmikxa0OnJi4YOH2FuI3LptY8sxuGIa_vx1mdJi6wqbMHQFZgBFG4kz2amWH1HUZdw_ZlzMcC0go2viQSQ2VNbHenAc8fzkdVUOneBJv3RISC2DLTo0oSrY0J-FWPr6U1Rwp20DZEPA/s1600/beagleboneLogo_small.png" /></a></div>
This post is part of a series of posts I have done about the <a href="http://www.adafruit.com/products/1480" target="_blank">Adafruit 2.2" TFT display</a>. You can check out those previous posts <a href="http://matthewcmcmillan.blogspot.com/2014/01/arduino-improving-refresh-rate-of-tft.html" target="_blank">here</a> and <a href="http://matthewcmcmillan.blogspot.com/2014/08/arduino-tft-lcd-display-refresh-rate-part2.html" target="_blank">here</a>. In those previous posts I was using this display with an Arduino and ran into issues with the refresh rate. To get a decent refresh rate I had to do some extra coding to determine what data needed updating and then only redraw the sections of the screen that actually needed to change. In this post I am going to take a look at using this display with the <a href="http://beagleboard.org/black" target="_blank">BeagleBone Black single board computer</a>. My hope going into this is that the CPU horsepower of the BBB will allow quicker screen redraws which would eliminate the need to selectively redraw sections of the screen.<br />
<br />
Since the BBB is a full computer there is a Linux operating system sitting between the code and the hardware. This quite a bit different from an Arduino where you have direct access to the hardware. My BBB came with Angstrom Linux on it but I am more familiar with Ubuntu and the Adafruit tutorials were written assuming you have Ubuntu installed. So I swapped the OS to Ubuntu 14.04 following <a href="https://learn.adafruit.com/beaglebone-black-installing-operating-systems" target="_blank">Adafruit's tutorial</a>. To control the TFT display with a BBB Adafruit created a <a href="http://en.wikipedia.org/wiki/User_space" target="_blank">user space</a> library in Python. To install the library and wire up the display <a href="https://learn.adafruit.com/user-space-spi-tft-python-library-ili9341-2-8" target="_blank">I followed the instructions on learn.adafruit.com</a>. The instructions were written for the 2.8 inch display but they worked just fine for my 2.2 inch display. I think these instructions would probably work for most ILI9341 based TFT displays.<br />
<br />
The wiring for the 2.2" display is slightly different than the 2.8" display. Here is how I wired it up.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVRg062MdgHskQNmKYOKblcj9O_BDrUFLSg3C2nRK7RQeI5eomTA8OWbsFbVo5SkcCY-YE4lg7_vW_VOCNXPekseSGNn4fOIoZHnUDm_RImN94O2P2zU4CYBSC7nVu_r70bgo2kHiHq_Y/s1600/BBB+and+TFT_Fritzing+copy.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVRg062MdgHskQNmKYOKblcj9O_BDrUFLSg3C2nRK7RQeI5eomTA8OWbsFbVo5SkcCY-YE4lg7_vW_VOCNXPekseSGNn4fOIoZHnUDm_RImN94O2P2zU4CYBSC7nVu_r70bgo2kHiHq_Y/s1600/BBB+and+TFT_Fritzing+copy.png" height="267" width="400" /></a></div>
<ul>
<li>BeagleBone Black SCLK pin P9_22 to TFT SCK.</li>
<li>BeagleBone Black MOSI pin P9_18 to TFT MOSI.</li>
<li>BeagleBone Black CE0 pin P9_17 to TFT CS.</li>
<li>BeagleBone Black pin P9_12 to TFT RST.</li>
<li>BeagleBone Black pin P9_15 to TFT D/C.</li>
<li>BeagleBone Black 3.3V power pin P9_3 to TFT Vin.</li>
<li>BeagleBone Black ground pin P9_2 to TFT GND.</li>
</ul>
<br />
Then I ran the sample image.py application to make sure everything worked correctly<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRpN_Qup4Lb8se5IDgAkSKdzDaDj2F0ZRvg4gUuXLrzmRwfT5c6aO4ScTg0JvDK3_4n0s5ZO48FfbtwxWt_HVmlt2JFKK8QzMYq4GjM_0NXqILhtOQ_Hkm92cGJRnfhpD7ynZcraWO_ow/s1600/IMG_4886.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRpN_Qup4Lb8se5IDgAkSKdzDaDj2F0ZRvg4gUuXLrzmRwfT5c6aO4ScTg0JvDK3_4n0s5ZO48FfbtwxWt_HVmlt2JFKK8QzMYq4GjM_0NXqILhtOQ_Hkm92cGJRnfhpD7ynZcraWO_ow/s1600/IMG_4886.jpg" height="320" width="240" /></a></div>
<br />
<br />
Now that we have all that stuff out of the way let's get to the real point of this post, how fast can the BBB update this display! To test it I took one of Adafruit's example scripts that came with the library and modified it so it read the value of an analog pin (P9_40) and then display that value on the TFT screen with a custom font. I connected a 10k pot to the analog pin so I could adjust the value.<br />
<br />
The first time I ran the test script I ran into problem with the bottom the text being clipped off. Turns out it was a bug with a Python library. I detailed the fix for that <a href="http://matthewcmcmillan.blogspot.com/2014/08/font-issues-with-beaglebone-black-and-tft.html" target="_blank">here</a>.<br />
<br />
In the script I also recorded a time stamp before drawing the TFT screen and immediately after to measure how long it took to actually draw the screen.<br />
<br />
Here is a video of the testing<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/5VdBBJ_3QQ4" width="560"></iframe>
<br />
<br />
If you made it to the end of the video you saw that it was taking approximately 0.6 seconds for the draw command to complete but the screen itself appears to update nearly instantly. This is a huge improvement compared to when I tested this display with an Arduino. On the Arduino you could see the screen slowly painting the image onto the screen.<br />
<br />
Here is a video of the same exact test with an Arduino:<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/4ZVIlTC5bMs" width="560"></iframe>
<br />
<br />
I'm not sure what is taking 0.6 seconds with the BBB. The screen redraws seem to happen faster than that. Maybe it's the data transfer over SPI plus the screen redraw (Update: <a href="http://matthewcmcmillan.blogspot.com/2014/10/speed-up-screen-redraws-with-beaglebone-TFT.html" target="_blank">See this post to learn how to speed up the redraws</a>). In any case I am quite pleased with it. Another advantage of using the BBB is I'm able to use any TrueType font to display text. The library on the Arduino only had one font which became very blocky when using large characters. As you saw in the first video I used an Arial font which looked very smooth.<br />
<br />
I originally wanted to use this TFT display for my <a href="http://matthewcmcmillan.blogspot.com/2014/02/arduino-digital-speedometer.html" target="_blank">speedometer project</a> but abandoned it for a 7 segment display because the refresh rate was so slow with the Arduino. Based on these BBB results I think I'm going to make a v2.0 digital speedometer using both an Arduino and a BBB. The BBB isn't great at doing real time things like counting pulses so I think I will continue to use the Arduino to count the VSS pulses and then feed the speed data into the BBB over I2C or CAN. I'm already brainstorming other data to display on the screen...<br />
<br />
Oh here is the python code I used to test this display if you are interested:<br />
<br />
<br />
<script src="https://gist.github.com/matt448/f3dbace236d8a6483ebd.js"></script>
<br />
<br />
<br />
Helpful Links
<br />
<br />
<a href="https://learn.adafruit.com/user-space-spi-tft-python-library-ili9341-2-8/">https://learn.adafruit.com/user-space-spi-tft-python-library-ili9341-2-8/</a><br />
<a href="https://learn.adafruit.com/beaglebone-black-installing-operating-systems">https://learn.adafruit.com/beaglebone-black-installing-operating-systems</a><br />
<a href="http://elinux.org/Beagleboard:Ubuntu_On_BeagleBone_Black">http://elinux.org/Beagleboard:Ubuntu_On_BeagleBone_Black</a><br />
<br />
<br />
[Updated 2014-09-05]<br />
This is in reference to my statement about about the BBB not being great at real time tasks. I've been doing some reading and the BBB does have a hardware counter on it but it looks like you have to be a NASA engineer to get it to work. <a href="http://www.element14.com/community/community/designcenter/single-board-computers/next-gen_beaglebone/blog/2013/05/22/bbb--working-with-the-pru-icssprussv2" target="_blank">This post discusses the PRU on the BBB. When he started talking about having to write Assembly code I tuned out</a>. I'll just use an Arduino to do the accurate pulse counting, thanks.<br />
<br />
[Updated 2014-10-04]<br />
Added Fritzing wiring diagram and pin outs.<br />
<br />
[Updated 2014-10-08]<br />
Added link to <a href="http://matthewcmcmillan.blogspot.com/2014/10/speed-up-screen-redraws-with-beaglebone-TFT.html" target="_blank">post that shows how to speed up display redraws</a>.<br />
<br />
<br />
<br />Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com7tag:blogger.com,1999:blog-9120755343492164185.post-75596750289621083202014-08-25T22:13:00.000-05:002014-08-25T22:16:07.871-05:00Font issues with BeagleBone Black and ILI9341 TFT display<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH986s5FOk-D8BfJxYz_KKtMKUkqyzxLdCpUmjfbbqdf4HlIuOswEZFyjfELa7KtnXFApCv7WiSQJ_MhWRtfpY8F7JocVHrWlW0E73OcPYuaejYqr8-q_rwSgmDeuyvSx9bguDGyYTbEY/s1600/beagleboneLogo_small.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH986s5FOk-D8BfJxYz_KKtMKUkqyzxLdCpUmjfbbqdf4HlIuOswEZFyjfELa7KtnXFApCv7WiSQJ_MhWRtfpY8F7JocVHrWlW0E73OcPYuaejYqr8-q_rwSgmDeuyvSx9bguDGyYTbEY/s1600/beagleboneLogo_small.png" /></a></div>
In my continuing quest to build a really cool digital speedometer for my car I have been experimenting with an <a href="http://www.adafruit.com/products/1480" target="_blank">Adafruit 2.2" color TFT display</a>. This past weekend I loaded up Ubuntu 14.04 on my BeagleBone Black and wired up the TFT display to it. Adafruit has a <a href="https://github.com/adafruit/Adafruit_Python_ILI9341" target="_blank">python library that works on both the BeagleBone Black and a Raspberry Pi</a>. After trying out the example code I decided I wanted to try using a nicer font than the default one in the example code. The first font I tried seemed to look fine but the second font I tried had the bottom third of the characters not displayed. To figure out which fonts were affected I wrote a python script that cycled through displaying a bunch of fonts on the screen. Here is a video of the results:<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/FAjtuJKoCLo" width="560"></iframe>
<br />
As you can see some fonts are affected more than others. A few have over half the line cut off. I started digging into the code that displays the text. I figured out the code is determining the height and width of the text and then turning the text into an image to be displayed on the screen. This is done so text can easily be rotated on the display.<br />
<br />
Line number 17 in this snippet of code is where the height and width is determined before making the image.
<br />
<script src="https://gist.github.com/matt448/ba867228258a95bdbace.js"></script>
The Adafruit library is using PIL (Python Image Library) to create an image from the text. Ubuntu 14.04 actually uses a fork of PIL called <a href="https://github.com/python-pillow" target="_blank">Pillow</a>. I did some google searches and discovered that the <a href="https://github.com/python-pillow/Pillow/pull/784" target="_blank">textsize function has a bug</a> that does not account for the font offsets which causes the clipping on some fonts. The Ubuntu 14.04 I installed on my BBB came with Pillow 2.3.0 which was broken. I updated it to latest available package which was Pillow 2.5.3 and it was still broken. I looked at the bug fix on the master branch of Pillow and it was just a small change to one file, PIL/ImageFont.py, so I decided to apply that change to my 2.5.3 install of Pillow.<br />
<br />
Here is how I fixed it.<br />
<br />
<pre><span style="color: lime;">cd /usr/local/lib/python2.7/dist-packages/PIL</span></pre>
<pre><span style="color: lime;">sudo vi ImageFont.py</span></pre>
<br />
At about line 142 look for the getsize function. Here is what it looked like before the change.<br />
<br />
<table 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/AVvXsEj9P6jiOkAXmYdh17L5zurfRoP3zz0j5T7nkmW7HItMBAx8xTq9QjXqPqvBwqXJ_VHhdh0S3NjwrhxWtZGu1UsiU5339I8EeSv43Zp1zRLCbLKUexh-fWn3mSzMDaul9KhtyHTBCtHWhvk/s1600/Screenshot+2014-08-25+21.18.38.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto; text-align: left;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9P6jiOkAXmYdh17L5zurfRoP3zz0j5T7nkmW7HItMBAx8xTq9QjXqPqvBwqXJ_VHhdh0S3NjwrhxWtZGu1UsiU5339I8EeSv43Zp1zRLCbLKUexh-fWn3mSzMDaul9KhtyHTBCtHWhvk/s1600/Screenshot+2014-08-25+21.18.38.png" height="61" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>
<br />
<br />
And here it is after the change.<br />
<table 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/AVvXsEjk_gSlTmWnJJiqiBUEoyUcaBhsnqLomV92ghsk5SZodiT1iGtyu4FRsAJ91d8lW2Z5jMr2IK2nmExs-6Ah78TPeDZHSOZTKN6UOnkJE_XqMhQobSs5v_F4gFaz7OYlTa51EjKes5s5Ihs/s1600/Screenshot+2014-08-25+21.18.46.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto; text-align: left;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjk_gSlTmWnJJiqiBUEoyUcaBhsnqLomV92ghsk5SZodiT1iGtyu4FRsAJ91d8lW2Z5jMr2IK2nmExs-6Ah78TPeDZHSOZTKN6UOnkJE_XqMhQobSs5v_F4gFaz7OYlTa51EjKes5s5Ihs/s1600/Screenshot+2014-08-25+21.18.46.png" height="61" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small; text-align: start;"><br /></span></td></tr>
</tbody></table>
<br />
Save the file and then you need to compile it into python byte-code.<br />
<pre><span style="color: lime;">sudo pycompile ImageFont.py</span></pre>
<pre></pre>
This creates an ImageFont.pyc file. Now to test it again.<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/wUfPmYyU8v4" width="560"></iframe>
<br />
<br />
All fixed! I'm sure that fix to getsize will be pushed out soon so this won't be a problem in the future but until then this will let me continue my experimentation.<br />
<br />
<br />
<br />Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com1tag:blogger.com,1999:blog-9120755343492164185.post-51594291624477327862014-08-07T22:13:00.001-05:002014-08-26T09:58:56.174-05:00Arduino - TFT LCD display refresh rate part 2<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" /></a></div>
<a href="http://matthewcmcmillan.blogspot.com/2014/01/arduino-improving-refresh-rate-of-tft.html" target="_blank">Since January</a> I have been thinking about how to reduce the flashing effect of redrawing characters on the <a href="http://www.adafruit.com/products/1480" target="_blank">Adafruit 2.2" TFT display</a> running off of an Arduino. Initially I thought I was doing something wrong but then I <a href="https://www.youtube.com/watch?v=ZaEn8vhsrsg" target="_blank">saw that other projects experience the same slow screen redraw performance</a>. This post isn't about rewriting/optimizing the <a href="https://github.com/adafruit/Adafruit_ILI9340" target="_blank">ILI9340 library</a> that talks to the display. I'm not a good enough programmer to even think about digging into that code. Also I don't think it really is a problem with the library or the display itself. I've seen <a href="https://www.youtube.com/watch?v=06QqFrEPzuU" target="_blank">videos with this display hooked up to a Raspberry Pi smoothly playing video files</a>. I suspect the limitation is the CPU and/or RAM of the Arduino. For my speedometer project I wanted to use an Arduino because it starts up almost instantly and I don't have to worry about shutting it down which is not the case with a Raspberry Pi.<br />
<br />
So my goal was to optimize the refresh rate by reducing the amount of screen redraw to the smallest amount possible. To do this I first draw the static elements on the screen (the red box and the mph text). These are never redrawn. Redrawing static items causes a flashing effect. Then the speed value is only updated if it changes. When it does change only digits that have changed are redrawn. For example say the speed is 35 mph and then on the next loop the speed is 36 mph. The 5 would be drawn over with black and then the 6 is drawn in white. This performs the least amount of screen drawing possible.<br />
<br />
Here is a video of the progress so far. The code is below the video.<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/X0v2hnCS8xs?list=UUnDLOxa7-uURViF7sUAR7cw" width="560"></iframe><br />
<br />
Here is the code<br />
<br />
<br />
<script src="https://gist.github.com/matt448/12df872913ee64a4fe8c.js"></script>Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com6tag:blogger.com,1999:blog-9120755343492164185.post-70249652665635125032014-07-31T22:49:00.001-05:002015-04-06T14:06:10.549-05:00LED light up bicycle<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" /></a></div>
The city of Round Rock, Texas has an annual night time bike ride event at the end of July. It starts at 9pm with a ride through the downtown area to a city park where they have music, free hotdogs and free shaved ice. After the event everyone rides back to the starting point. It sounded like fun to me so I decided I wanted to participate along with my two older kids. As the event approached I started to think it would be fun to decorate my bike for the event. I didn't want to spend much money because this was going to be a pretty temporary thing. I started scrounging my plastic storage bins of electronics for parts. I found a 12 volt LED light strip that had originally been purchased to be used as under cabinet lighting (<a href="http://en.wikipedia.org/wiki/Procrastination" target="_blank">which I never installed</a>). I had an old unused UPS battery backup that came with our AT&T Uverse service. I tore that UPS open and found a nice 12 amp hour <a href="http://en.wikipedia.org/wiki/Lead%E2%80%93acid_battery#.22Maintenance_free.22.2C_.22sealed.22_and_.22VRLA.22" target="_blank">SLA battery</a>. I also had four extra <a href="http://www.adafruit.com/products/976" target="_blank">TIP120 transistors</a> and an <a href="http://www.adafruit.com/products/50" target="_blank">Arduino Uno</a>. Seemed like enough ingredients to make something cool.<br />
<br />
I started by measuring how many amps the full strip of LED's drew at full brightness. It measured 1.3 amps so the battery should give me about 9 hours of run time between charges which is obviously more than enough for a long night ride.<br />
<br />
The spool had just enough LED's to light up each of the tubes of the frame on both sides of the bike. The LED strips have a cut line every three LED's. I cut the LED strips into sections that would fit each of the tubes on the frame of my bike.<br />
<br />
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR2umnwmzZ-hgrlLspifavKLVrT1xK87K6Ngu8dvgD7MgphEiDjfYOwV_tkxpxz3oY-RAcX2dCJtJnsTxhUctuQo2c-aIaEnEp1CmPd0rBCxi4DkfJCiQyklt5W6Qq8uMpNZLT1pHPr7w/s1600/IMG_4643.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR2umnwmzZ-hgrlLspifavKLVrT1xK87K6Ngu8dvgD7MgphEiDjfYOwV_tkxpxz3oY-RAcX2dCJtJnsTxhUctuQo2c-aIaEnEp1CmPd0rBCxi4DkfJCiQyklt5W6Qq8uMpNZLT1pHPr7w/s1600/IMG_4643.jpg" height="320" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHLdhnXfEU83f0rOiSaVBduf6tHPJ51IZJ7sHPWVfIP4ySnuo4XdLJ31js7eFME0bFBK9HVzrCV9XtvA5yfuwAC3i09Tj0g-k8MEZaeEut666KttBuFnXUAAInR1lUwEFcs_P3ykYhxTY/s1600/IMG_4520.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHLdhnXfEU83f0rOiSaVBduf6tHPJ51IZJ7sHPWVfIP4ySnuo4XdLJ31js7eFME0bFBK9HVzrCV9XtvA5yfuwAC3i09Tj0g-k8MEZaeEut666KttBuFnXUAAInR1lUwEFcs_P3ykYhxTY/s1600/IMG_4520.jpg" height="320" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
</td></tr>
</tbody></table>
<br />
Then I soldered power and ground leads onto each of the strips and covered the connections with heat shrink.<br />
<br />
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhl-A6Sp7cIO_e5CJb-LFcglCkKPq6qsGoexyrfWFPhAhqkv6mXCHcLPLjHFtnReleQzINnK7DK5fNidKEc2ED1h9T532uqPN-AnWY2B71GyXwt-RA-JupoG3O0s397e8unUrbVOU0gOik/s1600/IMG_4519.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhl-A6Sp7cIO_e5CJb-LFcglCkKPq6qsGoexyrfWFPhAhqkv6mXCHcLPLjHFtnReleQzINnK7DK5fNidKEc2ED1h9T532uqPN-AnWY2B71GyXwt-RA-JupoG3O0s397e8unUrbVOU0gOik/s1600/IMG_4519.jpg" height="320" width="240" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpka0IeWkpsyYTThIS42D8-85PrjfOvO7baeFBuLzGL46mzHPPRXh2nRTPnBLHbmVcaxJA2mNp-4THtQoleJgByr3BWbu5ykjvYomp41j2kfuuOBUmUrO28Az8y_I_k8LtnMMgVN0grIM/s1600/IMG_4521.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpka0IeWkpsyYTThIS42D8-85PrjfOvO7baeFBuLzGL46mzHPPRXh2nRTPnBLHbmVcaxJA2mNp-4THtQoleJgByr3BWbu5ykjvYomp41j2kfuuOBUmUrO28Az8y_I_k8LtnMMgVN0grIM/s1600/IMG_4521.JPG" height="320" width="234" /></a></div>
</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
I attached the LED strips to my bike using zip ties and black electrical tape.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx7690RiiGTP9PuGFQmxtNN4yuMed0rUH2CxB8lOvr_FrZ19FJ4iaPyJmx6l3xviQGp0ksRGHY8isuOHyfPLgWYla_h_RVnS4BCqL4Jc62cOaBUxDgDiDrgIhzmu_58MXg0J0q_PppXL4/s1600/IMG_4644.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx7690RiiGTP9PuGFQmxtNN4yuMed0rUH2CxB8lOvr_FrZ19FJ4iaPyJmx6l3xviQGp0ksRGHY8isuOHyfPLgWYla_h_RVnS4BCqL4Jc62cOaBUxDgDiDrgIhzmu_58MXg0J0q_PppXL4/s1600/IMG_4644.jpg" height="320" width="240" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpzko-ZFZb3e2vvGTrIaUopIvGr1qGXPZoi0_GOFYGg0BXTZWgjEWpC_o2uIYS7SeLAUHnDnaZtkc9OrCvz5CBEW_UfhTUbmTPGXF9eSXKTWjkY5AeualbbmPr_QLOK7OgkCr8TqmBi2s/s1600/IMG_4645.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpzko-ZFZb3e2vvGTrIaUopIvGr1qGXPZoi0_GOFYGg0BXTZWgjEWpC_o2uIYS7SeLAUHnDnaZtkc9OrCvz5CBEW_UfhTUbmTPGXF9eSXKTWjkY5AeualbbmPr_QLOK7OgkCr8TqmBi2s/s1600/IMG_4645.jpg" height="320" width="240" /></a></div>
</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Next I wired up the TIP120 transistors on some scrap proto board. I soldered on a row of right angle headers so I could plug the Arduino right onto the board. Please keep in mind I was just throwing this together at the last minute so it isn't very pretty. The only real goal was to make it fit on top of the battery and stay out of my way while pedaling the bike. I used a scrap barrel connector pigtail for the main power to the board and another to power the Arduino. I added a 12 volt regulator to the Arduino power circuit because the battery was putting out a little over 13 volts and I didn't want to damage the voltage regulator on the Arduino. The transistors connect to four different LED segments and are controlled by four PWM digital pins on the Arduino. I used a different color wire for each transistor and LED segment so I could keep track of them when I wrote the software for animating the segments.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnVEqAxRJ0U5TSmfH4ITsu4X7PjycKp31crT20DGMirfDdCaBz4VVxmNLhpaKzopVSmWIv6htKa5qaLHO-yyo_4KejGxNE0CyfXKkNAtRPRkB_nPtiwxhcQq_Pyh5y2baUb2vrVD2dzZI/s1600/IMG_4649.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnVEqAxRJ0U5TSmfH4ITsu4X7PjycKp31crT20DGMirfDdCaBz4VVxmNLhpaKzopVSmWIv6htKa5qaLHO-yyo_4KejGxNE0CyfXKkNAtRPRkB_nPtiwxhcQq_Pyh5y2baUb2vrVD2dzZI/s1600/IMG_4649.jpg" height="320" width="240" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiahaeWqpAzB3LJm5rASrNs7Rw8Ij9WWE-COLJvffYBhrG1T3YNvUvq5OJj1OqvgPihVQkpd3n_o2cigl0RQkahHOvcLStPpBcTZCg_3KDkfSUbMIQ_QKy6c2oiNt1VHaMcpCz956WusPo/s1600/IMG_4650.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiahaeWqpAzB3LJm5rASrNs7Rw8Ij9WWE-COLJvffYBhrG1T3YNvUvq5OJj1OqvgPihVQkpd3n_o2cigl0RQkahHOvcLStPpBcTZCg_3KDkfSUbMIQ_QKy6c2oiNt1VHaMcpCz956WusPo/s1600/IMG_4650.jpg" height="320" width="240" /></a></div>
</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The transistor circuit is very simple. The TIP120 isn't the best way to do this but I had them laying around. A <a href="http://www.adafruit.com/partfinder/transistors#mosfet" target="_blank">N-channel Power MOSFET</a> is better for this because it can handle high amperage without generating heat. </div>
<div class="separator" style="clear: both; text-align: left;">
<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/AVvXsEgKIfQv5Vq3zOSXfWcwWm5VB7y7yVm63VU6D4VSuAj1GyySAiX1QFdwCSNOCYyDhlLUIKasx82X7bh67H0GeawFTBwAukl8RMU7A8O3r3Ol1YqTA0pIuFyZZoXgDlihPzOHvX_FeHPSWws/s1600/tip120_arduino_led.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKIfQv5Vq3zOSXfWcwWm5VB7y7yVm63VU6D4VSuAj1GyySAiX1QFdwCSNOCYyDhlLUIKasx82X7bh67H0GeawFTBwAukl8RMU7A8O3r3Ol1YqTA0pIuFyZZoXgDlihPzOHvX_FeHPSWws/s1600/tip120_arduino_led.png" height="263" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Example of TIP120 used with an Arduino.<br />
Image taken from <a href="http://electronics.stackexchange.com/questions/101340/controlling-7w-12-14v-power-led-with-arduino" target="_blank">here</a></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
I couldn't wait anymore to see what the bike looked like in action so I just taped the battery to the frame and took it out for a quick test ride. At this point the Arduino software just faded the LED's to full brightness and didn't do anything else.<br />
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/4l_IDoDGBYw?list=UUnDLOxa7-uURViF7sUAR7cw" width="560"></iframe>
</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: left;">
Now I turned my attention to making a proper mount for the battery. I wanted to make sure the battery was mounted solidly so it didn't fall off the bike when I hit a bump. I started with an old L bracket I had laying around the garage and drilled some holes in it so it matched up with the water bottle mounts on the seat post tube of the bike. I bent the L bracket down a bit so the battery would sit level on the bike. Next I took a piece of scrap sheet metal and created a short metal box for the battery to sit in. I made another tab out of sheet metal so the battery box could also bolt to the other water bottle mount on the down tube. I spot welded everything together and ground down the welds on the battery box so it didn't scratch or cut my legs while pedaling.<br />
<br />
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQPTbWal-BP_hY3-sQgwiJKtdVDTFbhaaW-XAeh9PGTwfdRVhd4udBpDOj7OaNOKz_ASpszbG-77FoqQ_el7PNdY1bdUHBurF8HBjdxQPzK_XJUxPocMZUZoopdVXBo2X9vx5XXkHfrY4/s1600/IMG_4583.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQPTbWal-BP_hY3-sQgwiJKtdVDTFbhaaW-XAeh9PGTwfdRVhd4udBpDOj7OaNOKz_ASpszbG-77FoqQ_el7PNdY1bdUHBurF8HBjdxQPzK_XJUxPocMZUZoopdVXBo2X9vx5XXkHfrY4/s1600/IMG_4583.jpg" height="320" width="240" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmgnwzTAzVgmdYKS1suSC6If1ZfsQR4DeLMV_H7gEcg6nR4OTdIn-qqXwKjqU0avkfKIrl5WVI7QRoEX6_DBUhoZIgSKTpy7E4aglX8jydoF2_1ScGaI3tw6pBneYWdvbC8fa_na6j4CM/s1600/IMG_4582.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmgnwzTAzVgmdYKS1suSC6If1ZfsQR4DeLMV_H7gEcg6nR4OTdIn-qqXwKjqU0avkfKIrl5WVI7QRoEX6_DBUhoZIgSKTpy7E4aglX8jydoF2_1ScGaI3tw6pBneYWdvbC8fa_na6j4CM/s1600/IMG_4582.JPG" height="320" width="240" /></a></div>
</td></tr>
</tbody></table>
<br />
After the welding and grinding was all done I mounted the battery box on the bike.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdb40k8os9mmfZ72OPL8GVGfxFHu_u0oO7Vcsqur7yFUXDHt0v3Yah-4XqDlIpC4tTIlCOXKHADSyHEBvzY_GKVXC35lfDjDaetxbY-CAokKoowOucfjMveqKMMvRsAfZEr56DlyqjdKA/s1600/IMG_4584.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdb40k8os9mmfZ72OPL8GVGfxFHu_u0oO7Vcsqur7yFUXDHt0v3Yah-4XqDlIpC4tTIlCOXKHADSyHEBvzY_GKVXC35lfDjDaetxbY-CAokKoowOucfjMveqKMMvRsAfZEr56DlyqjdKA/s1600/IMG_4584.JPG" height="240" width="320" /></a></div>
<br />
I did a test fit of the battery and it was a little loose in the box but I had planned on putting something on the top edge of the sheet metal to cover any sharp edges.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjF-JWPRCvlDNEW5Hmvn27i6rokNp99qJ8lGn_u5-OPZqU9QuAakADt2X9AJSGppE_AEp-BRGFA6AMdxGyq6GCw39j185Uv-NBWb0iwhxAZD2wgTfYdH9szR4WAeujrEjgoVvhYAAW0Hrk/s1600/IMG_4585.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjF-JWPRCvlDNEW5Hmvn27i6rokNp99qJ8lGn_u5-OPZqU9QuAakADt2X9AJSGppE_AEp-BRGFA6AMdxGyq6GCw39j185Uv-NBWb0iwhxAZD2wgTfYdH9szR4WAeujrEjgoVvhYAAW0Hrk/s1600/IMG_4585.JPG" height="240" width="320" /></a></div>
<br />
I scrounged around the garage a bit more and found some extra automotive vacuum tubing. I made a slit down the entire length of the vacuum tubing and then pushed it on the top edge of the battery box.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSje_4xFOQnfXSpNjpjoZpxkSRyqA99Tza6NsrE6jklrFymsIsMSwZy3k-Z8NOpZGG314rUgBAZeFhDZcC4eVAbkNQXLwbQjiZMo1n_LPVJMxiEk5N5dNY-KoV6qWy8eUHRsJOCZZmRno/s1600/IMG_4586.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSje_4xFOQnfXSpNjpjoZpxkSRyqA99Tza6NsrE6jklrFymsIsMSwZy3k-Z8NOpZGG314rUgBAZeFhDZcC4eVAbkNQXLwbQjiZMo1n_LPVJMxiEk5N5dNY-KoV6qWy8eUHRsJOCZZmRno/s1600/IMG_4586.JPG" height="240" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Now the battery fit very snug in the box.</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg297WlDD7zb6713SynrA20OJ7QdtEffB-U7qVouzS8hOoTmDPUSacsCERtNhfRKtHihC4C6GswyUS_f4MGqY29-CG7fjGCn7Xvc3jfbPcdKzBZ7U0IkMtcDICg18Fkww2yElZZSGQ3EMs/s1600/IMG_4587.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg297WlDD7zb6713SynrA20OJ7QdtEffB-U7qVouzS8hOoTmDPUSacsCERtNhfRKtHihC4C6GswyUS_f4MGqY29-CG7fjGCn7Xvc3jfbPcdKzBZ7U0IkMtcDICg18Fkww2yElZZSGQ3EMs/s1600/IMG_4587.JPG" height="240" width="320" /></a></div>
<br />
Next I made two velcro straps out of 1" webbing. I cut the webbing to length and sewed on some velcro with the sewing machine. These straps will hold the battery in box.<br />
<br />
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUj3uUcbEpcESDsGg9RaQQ2a0WnIvzcerpaJjvagQGXYnwgleaQHBiuNT4SZa_EN0Rihanog58whSLRRJPlWG1Iilr-FuJBadz_WLOnaWxPq3pbO5C2pw2J66WSNJc0GCrSR7mxBpwHZg/s1600/IMG_4648.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUj3uUcbEpcESDsGg9RaQQ2a0WnIvzcerpaJjvagQGXYnwgleaQHBiuNT4SZa_EN0Rihanog58whSLRRJPlWG1Iilr-FuJBadz_WLOnaWxPq3pbO5C2pw2J66WSNJc0GCrSR7mxBpwHZg/s1600/IMG_4648.jpg" height="320" width="240" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijXttr_8ckYEe_pIQgzSLSZCSHxmEHkgBP-BkMu9bk1iFHnAo0Il1QAnLDaeLZMeiqN-RPIE4PvOWTrs-C6VQ-0kf3JLPNuh8l_pm8NCc1aI-ilDRQlqgZlAisOOYbIjKlebQSoZvWZgc/s1600/IMG_4647.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijXttr_8ckYEe_pIQgzSLSZCSHxmEHkgBP-BkMu9bk1iFHnAo0Il1QAnLDaeLZMeiqN-RPIE4PvOWTrs-C6VQ-0kf3JLPNuh8l_pm8NCc1aI-ilDRQlqgZlAisOOYbIjKlebQSoZvWZgc/s1600/IMG_4647.jpg" height="320" width="240" /></a></div>
</td></tr>
</tbody></table>
<br />
Here is the battery with the straps in place and then the control board installed on top of the battery.<br />
<br />
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIWY7FtM7XZuGVRYjR8rdreQbfl8gZ-wQUJ2HtE3MXc5rHqSFXJpyL20cU5RBMUSQvl94aGze_1Lx9ba4u2OlGLGlQFfOCEuUAX6PEfkZpVb-ak2cvgQAEvu8_2nA4nIBgmSTq-wbuGFg/s1600/IMG_4653.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIWY7FtM7XZuGVRYjR8rdreQbfl8gZ-wQUJ2HtE3MXc5rHqSFXJpyL20cU5RBMUSQvl94aGze_1Lx9ba4u2OlGLGlQFfOCEuUAX6PEfkZpVb-ak2cvgQAEvu8_2nA4nIBgmSTq-wbuGFg/s1600/IMG_4653.jpg" height="320" width="240" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXttKWuDSLxvXEDNYdXw42QRvPq3wKA8oWVbdGQWTy4KfpkqsgZJOwPcyRrFm2gbyrm-MI6L2S_j2kcJQo1L3R-a-yvlR43QfVUomO5hLnGeBecdHHTserLWUZ3fTTT7RrTDRAz0MawI8/s1600/IMG_4654.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXttKWuDSLxvXEDNYdXw42QRvPq3wKA8oWVbdGQWTy4KfpkqsgZJOwPcyRrFm2gbyrm-MI6L2S_j2kcJQo1L3R-a-yvlR43QfVUomO5hLnGeBecdHHTserLWUZ3fTTT7RrTDRAz0MawI8/s1600/IMG_4654.jpg" height="320" width="240" /></a></div>
</td></tr>
</tbody></table>
<br />
Here is how the overall bike looks with everything installed.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMLbD7tn7vWVVYK25FyW4PiUgqbCY_Fk4mfhTe1tgb8FRxfAxaXxLNHGS7aVajgoVARkuFlnLjC3UvR4emqWJ9lYloZPK3KwH-cE_yUKuTKo1wowWCcOEwE0Xbh3b2-bgh9qRYYjioXnE/s1600/IMG_4655.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMLbD7tn7vWVVYK25FyW4PiUgqbCY_Fk4mfhTe1tgb8FRxfAxaXxLNHGS7aVajgoVARkuFlnLjC3UvR4emqWJ9lYloZPK3KwH-cE_yUKuTKo1wowWCcOEwE0Xbh3b2-bgh9qRYYjioXnE/s1600/IMG_4655.jpg" height="285" width="400" /></a></div>
<br />
The last thing I needed was some way to charge the battery. I searched around on Amazon and found <a href="http://www.amazon.com/UPG-D1761-Charger-Dual-Stage-Terminals/dp/B001G8DVS8/" target="_blank">this SLA battery charger</a>. I paid about $18 US dollars for it. It has an automatic shutoff once the charging is complete. It only comes with screw terminals so I had to make my own cable. I used yet another barrel connector and some 18 gauge wire to make a cable. (seriously how many barrel connectors can one person have? I may have used up my stockpile on this project.) I triple checked the polarity of the connecters on my charger and my battery with the voltmeter and then charged up the battery.<br />
<br />
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhARJu0SJWarDfOp3klOG4Bq8TU-vGgrqK8_zbXxT1_BHDQYAAawVkoZ7uL6zqfWkf3V7SCWRY4y6BDnb47qdIe2VHCuw1InbxzqvutCdYWLb3iLJ3EQ5gAdJlTCVaRgEGeHLDF5tkOxrg/s1600/IMG_4656.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhARJu0SJWarDfOp3klOG4Bq8TU-vGgrqK8_zbXxT1_BHDQYAAawVkoZ7uL6zqfWkf3V7SCWRY4y6BDnb47qdIe2VHCuw1InbxzqvutCdYWLb3iLJ3EQ5gAdJlTCVaRgEGeHLDF5tkOxrg/s1600/IMG_4656.jpg" height="320" width="240" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCcjAbaPfih9cQKqBRwb5i1eSz4wDUx_pnoi_tqNLlSlfT01c5Ewddyea8pzWpxtPwIB-Cr2H7a2K-pbtYGmvMW2upIN2bR_uTHijPBIoJixdGA5_nywhxgCxfe7ZKO6j5Dh7V-5DXYAM/s1600/IMG_4657.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCcjAbaPfih9cQKqBRwb5i1eSz4wDUx_pnoi_tqNLlSlfT01c5Ewddyea8pzWpxtPwIB-Cr2H7a2K-pbtYGmvMW2upIN2bR_uTHijPBIoJixdGA5_nywhxgCxfe7ZKO6j5Dh7V-5DXYAM/s1600/IMG_4657.jpg" height="320" width="240" /></a></div>
</td></tr>
</tbody></table>
<br />
I finished writing the code for the Arduino the night before the event. Here is a video showing the animations. Since I only had four TIP120 transistors I could only control four sections of the LED's. The fork and the seat tube just stay on full brightness.<br />
<br />
<div style="text-align: center;">
<br /></div>
</div>
<div style="text-align: center;">
<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/oEsSsCRik-w" width="560"></iframe>
</div>
<br />
<br />
Here are my kiddos at the starting line a few hours before the event.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-YXxzrLf1JWy33r8SShnyziFhR-4yIHuwQFVz9k65xeAdNKu6j8W11ARobog6jZhyphenhyphen1C9TssQ0xYZsPKlnjsQZNBDFYPECxjfCmcMQQoWl0D3AmfvfKgca4cQpcZL_vd0YZ49U9zVKGec/s1600/IMG_4622.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-YXxzrLf1JWy33r8SShnyziFhR-4yIHuwQFVz9k65xeAdNKu6j8W11ARobog6jZhyphenhyphen1C9TssQ0xYZsPKlnjsQZNBDFYPECxjfCmcMQQoWl0D3AmfvfKgca4cQpcZL_vd0YZ49U9zVKGec/s1600/IMG_4622.JPG" height="300" width="400" /></a></div>
<br />
The night ride event was really fun and my kids enjoyed the ride. I'll go ahead say I had the coolest bike at the night ride. This bike has inspired me to get some exercise and I have been riding about 4 miles every night since the event. Maybe for next year's event I will step up to some <a href="http://www.adafruit.com/products/1461" target="_blank">Adafruit NeoPixels</a>.<br />
<br />Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com4tag:blogger.com,1999:blog-9120755343492164185.post-19732716085888675142014-06-11T10:52:00.000-05:002014-06-11T12:54:03.798-05:00Ubuntu 14.04 init scripts fail and throw errors<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjh0QGPESprufjKqwSbMraPR5NgA-o5cmwAJG7WXHb1Jm3L17eYlUM_TSnl7B2oBzvdnd9PB2Lp3Z0Q6maVNUNu8_Qd1347m_ZSWB4_LPlg5fmQFqKsQRiTMz7Unpcj4G9s9oH2Feoppc/s1600/ubuntu_logo.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjh0QGPESprufjKqwSbMraPR5NgA-o5cmwAJG7WXHb1Jm3L17eYlUM_TSnl7B2oBzvdnd9PB2Lp3Z0Q6maVNUNu8_Qd1347m_ZSWB4_LPlg5fmQFqKsQRiTMz7Unpcj4G9s9oH2Feoppc/s1600/ubuntu_logo.png" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
I recently built out my first couple Ubuntu 14.04 servers at work and when my chef scripts tried to run they blew up all over the place. Chef was getting errors when trying to start or restart services like ssh and rsyslog. Looking a little deeper at the errors, Chef was executing init scripts directly and getting back an exit status of 1. For example when Chef tried to restart ssh it was running<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> '</span><span style="font-family: 'Courier New', Courier, monospace;">/etc/init.d/ssh restart'</span><br />
<div>
<br /></div>
<div>
That script on Ubuntu 14.04 has no output and exits with a status of 1. I attempted to run the same thing manually from the command line on one of the servers and had the same result, no output and an exit status of 1. I did some searching and found <a href="http://stackoverflow.com/questions/23464157/cant-start-or-stop-php-fpm-on-ubuntu" target="_blank">other</a> <a href="https://groups.google.com/forum/#!msg/ganeti/eijfVwTCWXw/YH6QVtJ9HjAJ" target="_blank">people</a> are running into this same issue with various other services. I did find the command '<span style="font-family: Courier New, Courier, monospace;">service ssh restart'</span> would do the right thing and not throw an error. Since it seemed like this is an Ubuntu or Debian bug with the start scripts I decided to just modify my Chef scripts to use the service command instead.</div>
<div>
<br /></div>
<div>
By default Chef attempts run the scripts in /etc/init.d when starting and stopping services. The <a href="http://docs.opscode.com/resource_service.html" target="_blank">service resource</a> in Chef has some attributes that let you modify how services are started. The attributes start_command, stop_command, restart_command and reload_command let you define an alternate command for these actions. Here are the changes I made to get my Chef scripts working again on Ubuntu 14.04.</div>
<div>
<br /></div>
<div>
Before</div>
<pre><span style="color: lime;">service "rsyslog" do
supports :restart => true
action [:enable,:start]
end
</span></pre>
<div>
<br />
After</div>
<pre><span style="color: lime;">service "rsyslog" do
restart_command "service rsyslog restart"
start_command "service rsyslog start"
supports :restart => true
action [:enable,:start]
end</span>
</pre>
<br />
This change is backwards compatible with older versions of Ubuntu so I don't have to worry about special casing this just for 14.04 boxes.<br />
<br />
<br />
<b>[Update 1]</b><br />
After reading a bit more I'm starting to suspect Ubuntu and/or Debian has purposely deprecated running the scripts in /etc/init.d to force people to use Upstart. Apparently these init scripts have been broken since Ubuntu 13.10.<br />
<br />
<br />
<b>[Update 2]</b><br />
<a href="https://twitter.com/retr0h">@retr0h</a> gave me a cleaner way of accomplishing this:<br />
<br />
<pre><span style="color: lime;">service "rsyslog" do
provider Chef::Provider::Service::Upstart
supports :restart => true
action [:enable,:start]
end
</span></pre>
<br />
This does the same thing without having to define each command individually.<br />
<br />
<br />
<b>[Update 3]</b><br /><a href="https://twitter.com/jtimberman">@jtimberman</a> informed me that this problem will be fixed in Chef 11.14. In that version Chef will automatically use Upstart for Ubuntu 13.10 and higher. (<a href="https://tickets.opscode.com/browse/CHEF-5276" target="_blank">Chef support ticket</a>) (<a href="https://github.com/jtimberman/chef/commit/6b2b1619596d32102a2548ba911a95cb98d2a866" target="_blank">Git commit</a>)<br />
<br />
<br />Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com4tag:blogger.com,1999:blog-9120755343492164185.post-68031085282874017382014-04-23T15:01:00.000-05:002014-04-23T15:57:13.303-05:00Gmail messages labeled as sent 'via eigbox.net'<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs5NBhML2mjh8ssOM6JIVRLl9kqfcHOEBwwKJZcycWodmg2jCABJLQvNC_mtO7D5_r-IvsFDf8epJymFctFPQJX7UbDhnHwGnhRVkYpRAd5G1kZblO57tNtU86X8zv4H8YGwRrJbIHD2s/s1600/gmail-logo.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs5NBhML2mjh8ssOM6JIVRLl9kqfcHOEBwwKJZcycWodmg2jCABJLQvNC_mtO7D5_r-IvsFDf8epJymFctFPQJX7UbDhnHwGnhRVkYpRAd5G1kZblO57tNtU86X8zv4H8YGwRrJbIHD2s/s1600/gmail-logo.jpg" /></a></div>
At work I had a user who suddenly started having all her outbound Gmail messages labeled as being sent 'via eigbox.net'. My thoughts immediately jumped to virus or malware. A google search of 'via eigbox.net' returned a bunch forum posts where people were having the exact same problem but I didn't find any info on what could be causing this to happen. The next thing I did was try and find info about the domain name eigbox.net. The whois information showed the owner of the domain name is a company called <a href="http://www.enduranceinternational.com/" target="_blank">Endurance International Group</a>. They are the parent company of several different hosting providers including HostGator. The domain eigbox.net doesn't have a website but it appeared the domain is used for a hosted e-mail service. At this point I couldn't rule out a virus but there wasn't anything necessarily suspicious about eigbox.net.<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/AVvXsEiwJ-HkbLlW-_n8VmiQIBUAMaIZOTc-jaU4FeBH5zgCR7twXeqozKTaa1e31UD_OkNPzrQlLq45xg9sQ6oGtu5LKAh8sKoYYxnCqnHnW4lFHnYOb_j8sFOiX72-p57Ovds9NcXBANY5EQU/s1600/Screenshot+2014-04-23+13.40.42.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwJ-HkbLlW-_n8VmiQIBUAMaIZOTc-jaU4FeBH5zgCR7twXeqozKTaa1e31UD_OkNPzrQlLq45xg9sQ6oGtu5LKAh8sKoYYxnCqnHnW4lFHnYOb_j8sFOiX72-p57Ovds9NcXBANY5EQU/s1600/Screenshot+2014-04-23+13.40.42.png" height="125" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Screenshot showing how messages appeared to recipients.</td></tr>
</tbody></table>
This person primarily used the native Mac Mail application so the next thing I tested was sending a test message from the Mail application and another test message using the Gmail web interface. I examined the message headers in both messages using the 'Show Original' option in Gmail.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkd_0okeVwXiqxNd2QVS6wLNjoCuUOTBZatVsKzjKmOvgrWLSKiwtz_gJeORdatiEmE55Q2bLHRwkktGM2UoPUpgsQ3LhbbPE2RUZZVoDgpNUq_Q-HHqwoHA_ysa9uzqaN_8klEbqCLSs/s1600/Screenshot+2014-04-23+14.05.34.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkd_0okeVwXiqxNd2QVS6wLNjoCuUOTBZatVsKzjKmOvgrWLSKiwtz_gJeORdatiEmE55Q2bLHRwkktGM2UoPUpgsQ3LhbbPE2RUZZVoDgpNUq_Q-HHqwoHA_ysa9uzqaN_8klEbqCLSs/s1600/Screenshot+2014-04-23+14.05.34.png" height="320" width="241" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
Examination of the headers showed that messages sent from the Mac Mail app were definitely being routed through smtp servers at eigbox.net. Messages sent through the Gmail web interface stayed within Google's network. This information let me focus on the Mail app as the source of the problem. I started combing through the settings in Mail.app. I discovered the user had two e-mail accounts configured. One personal account and another for the company Gmail. Under the Gmail settings (Mail > Preferences > Accounts) I noticed the Gmail smtp server said 'Offline' and the check box labeled 'Use only this server' was not checked.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUI3yF1SLKhKXPZceGa6UFBRmshLN31salaqZ7hXVIjE1PENvlJUFdEekxr5eO8Xenae9ObV2EG84wlQIVUTocGO94WlEfuxICNloJcVzlSl1S7iYPDxm6mrusDCpLSDYHuSWZHk6uoJY/s1600/Screenshot+2014-04-23+14.25.58.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUI3yF1SLKhKXPZceGa6UFBRmshLN31salaqZ7hXVIjE1PENvlJUFdEekxr5eO8Xenae9ObV2EG84wlQIVUTocGO94WlEfuxICNloJcVzlSl1S7iYPDxm6mrusDCpLSDYHuSWZHk6uoJY/s1600/Screenshot+2014-04-23+14.25.58.png" height="251" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
At this point I audibly exclaimed "Aha!". What I realized is going on is outbound Gmail messages can't reach Google's SMTP server for some reason and Mail.app is failing back to the SMTP server for the the user's personal e-mail account. Surprisingly the e-mail servers for the personal account allows sending of e-mail with any domain in the from address. Checking the 'Use only this server' box and saving the setting causes mail to get stuck in the outbox. In the end the reason the Gmail SMTP server was offline was because the user changed Gmail passwords. Having 'Use only this server' unchecked allowed Mail.app to seek out another SMTP server. It appears Mac Mail stores the IMAP and SMTP passwords separately. When she changed her Gmail password she updated the IMAP password which allowed her to continue to receive mail but it wasn't very obvious that the SMTP password also needed to be changed. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
To change the SMTP password go to Mail > Preferences > Accounts. Click on the 'Outgoing Mail Server (SMTP)' drop down and select 'Edit SMTP Server List...'</div>
<div class="separator" style="clear: both; text-align: left;">
<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/AVvXsEhFPvpDcFeU9zqTCHc81G9IKfnYveBJW8Kcsbrw7ayGN3lIrXz2CVfi3ffgdtjLHFH_oK-f-IqVecL1hmN0-bCUFaE-1Jtrg6PGIzIrzfmXAsbHMPJnB3Se9pqotdS58qb8Q4F0oPsS_tA/s1600/Screenshot+2014-04-23+14.41.21.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFPvpDcFeU9zqTCHc81G9IKfnYveBJW8Kcsbrw7ayGN3lIrXz2CVfi3ffgdtjLHFH_oK-f-IqVecL1hmN0-bCUFaE-1Jtrg6PGIzIrzfmXAsbHMPJnB3Se9pqotdS58qb8Q4F0oPsS_tA/s1600/Screenshot+2014-04-23+14.41.21.png" height="214" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Select 'Edit SMTP Server List...' from the drop down.</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<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/AVvXsEi8WrUyLkQEVasuQol0HeAApH4Bj6JaYB4jSpCztKoDgd5Jdarhc_5RwulMmLkn6WQ9r8FHXGu52WTBDqHdxPgtClT4WNqGZlCeoT-fwI1KrH6Y6oLKv6CE4xEhCagLxfL1iCkqg2y7oRQ/s1600/Screenshot+2014-04-23+14.41.51.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8WrUyLkQEVasuQol0HeAApH4Bj6JaYB4jSpCztKoDgd5Jdarhc_5RwulMmLkn6WQ9r8FHXGu52WTBDqHdxPgtClT4WNqGZlCeoT-fwI1KrH6Y6oLKv6CE4xEhCagLxfL1iCkqg2y7oRQ/s1600/Screenshot+2014-04-23+14.41.51.png" height="320" width="319" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Click on the 'Advanced' button and enter the password for the SMTP server.</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: left;">
The user's personal e-mail account is hosted by a company called <a href="http://www.ipage.com/" target="_blank">iPage</a> which does web page and e-mail hosting. <a href="http://www.ipage.com/" target="_blank">iPage</a> uses the eigbox.net domain for it's e-mail. iPage is also part of <a href="http://www.enduranceinternational.com/" target="_blank">Endurance International Group</a>. Mystery solved.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div>
<br />
<br /></div>
Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com9tag:blogger.com,1999:blog-9120755343492164185.post-76054997011366532182014-03-17T21:43:00.000-05:002014-03-20T09:19:13.075-05:00Arduino - Using digital potentiometers part 2 (MCP4251)<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" /></a></div>
This is part two in a series of posts about using digital potentiometers with Arduino boards. <a href="http://matthewcmcmillan.blogspot.com/2013/10/arduino-using-digital-potentiometers.html" target="_blank">Part one covered the AD8403 digital pot</a>. This post will go over the MCP4251 from <a href="http://www.microchip.com/" target="_blank">Microchip</a>. The MCP4251 is a dual pot chip with the capability to individually disconnect the terminals of each wiper through software and a hardware shutdown pin that shuts down both wipers simultaneously. Communication with the chip is done over SPI. The chip is available in DIP and surface mount configurations. I bought the DIP version so I could use them on a breadboard. The specific part number I bought is MCP4251-103E/P which is a 10k ohm model with an 8 bit resistor network. The 8 bit versions have 256 possible positions for the wiper which works out to approximately 39 ohms increase in resistance for each wiper position on a 10k ohm model.<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/AVvXsEgZqI1ATuTHGyrZROkrh97Ljsm4xvbNTbl6-5n4gAs2EzLu5D5jzoyEaxZxoAlHY8y2H6JqM-9sDoMDo7r-3ncZf4qM4GrlzaVV3zc4oUiBXoy0-hICcNQ54sqUxCgN9q79TZLU1FKsusg/s1600/IMG_4043.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZqI1ATuTHGyrZROkrh97Ljsm4xvbNTbl6-5n4gAs2EzLu5D5jzoyEaxZxoAlHY8y2H6JqM-9sDoMDo7r-3ncZf4qM4GrlzaVV3zc4oUiBXoy0-hICcNQ54sqUxCgN9q79TZLU1FKsusg/s1600/IMG_4043.JPG" height="240" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Two MCP4251 chips</td></tr>
</tbody></table>
I began searching for an Arduino software library for these pots. I found two but neither of them fit my needs. They didn't implement any of the TCON functionality which was the main reason I was interested in these pots. Here are links to those libraries if you are interested in trying them out:<br />
<a href="https://github.com/jmalloc/arduino-mcp4xxx">https://github.com/jmalloc/arduino-mcp4xxx</a> and <a href="https://github.com/teabot/McpDigitalPot">https://github.com/teabot/McpDigitalPot</a><br />
<div>
<br /></div>
<div>
Since there wasn't a preexisting library that would work for me I began figuring out how to talk to this chip. I started with the Arduino example in File > Examples > SPI > DigitalPotControl. The AD840x and AD520x series pots work right out of the box with this example but the MCP4xxx pots use different memory addresses so I started tweaking the example.<br />
<br />
<h3>
Understanding how to talk to the MCP4251</h3>
So lets start with the very basics of how to talk to these pots. Sending a command over SPI requires four steps:<br />
1. Take the slave select pin LOW. This tells the chip to listen for commands.<br />
2. Send the memory address for the item we want to change using SPI. This is the memory address for a wiper or terminal connections. This tells the chip what we want to change.<br />
3. Send the new value for the item we specified in step 2. Wipers on the MCP4251 have 256 possible positions so this would be a decimal number between 0-255 or binary B00000000 - B11111111.<br />
4. Take the slave select pin HIGH. This tells the chip to execute the changes.<br />
<br />
The AD8406 <a href="http://matthewcmcmillan.blogspot.com/2013/10/arduino-using-digital-potentiometers.html" target="_blank">covered in part 1</a> used decimal numbers 0-5 as memory addresses for each of the wipers which was very easy to understand. The MCP4251 doesn't use sequential values so I had to go digging in the data sheet to find the right values. Here is the memory map table from the data sheet:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKpnsbcDQVjVUr6eUS5-1mzmMj8CglxIqAdasq1B6i0zM-5RoBYbr9WHnkSOAelUSMuXu3TVbPdbA-IHYIPY4TJ-HENO17xsJage9rwkRdYNvAdMkEbhsiYBcuM8LrHHd2HHhl0i8CmAw/s1600/mcp4251+memory+map.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKpnsbcDQVjVUr6eUS5-1mzmMj8CglxIqAdasq1B6i0zM-5RoBYbr9WHnkSOAelUSMuXu3TVbPdbA-IHYIPY4TJ-HENO17xsJage9rwkRdYNvAdMkEbhsiYBcuM8LrHHd2HHhl0i8CmAw/s1600/mcp4251+memory+map.png" height="267" width="400" /></a></div>
<br />
Looking at the data sheet you can see the memory address and the data is made up of a total of 16 bits. The sheet says the data is 10 bits and the memory address is 6 bits but in practice you can send the data in two 8 bit chunks which allows you to use the 'B' binary formatter. The maximum possible value for a wiper is 255 which would be B11111111 in binary. So here is the list of memory addresses and tcon values I was able to determine:<br />
<br />
<pre>wiper0writeAddr = B00000000;
wiper1writeAddr = B00010000;
tconwriteAddr = B01000000;
tcon_0off_1on = B11110000;
tcon_0on_1off = B00001111;
tcon_0off_1off = B00000000;
tcon_0on_1on = B11111111;
</pre>
<h3>
The Wiring</h3>
Now that I had memory addresses figured out I wired up the digital pot on a breadboard with some LED's. I'm using LED's in this example because it's a good way to visualize the pots changing resistance values. I wired the shutdown pin to a 4.7k pull down resistor so the pot would go into shutdown mode if digital pin 7 wasn't HIGH. My example code also uses the software disconnects (TCON) to turn the LED's off and on.<br />
<br />
The connections are:<br />
* All A pins of MCP4251 connected to +5V
<br />
* All B pins of MCP4251 connected to ground
<br />
* An LED and a 220-ohm resistor in series connected from each W pin to ground
<br />
* VSS - to GND
<br />
* VDD - to +5v
<br />
* SHDN - to digital pin 7 and a 4.7k pull down resistor<br />
* CS - to digital pin 10 (SS pin)
<br />
* SDI - to digital pin 11 (MOSI pin)
<br />
* SDO - to digital pin 12 (MISO pin)
<br />
* CLK - to digital pin 13 (SCK pin)<br />
<pre style="box-sizing: border-box;"></pre>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZr9UIin2mcJ8MtAmUCBwHAQ4BHjaxXkzYZSpKGNDfAeOYMw7eu7fQXB6ZrRdKM_XKHlOwqc9Oe-M0CYRZix8Ot9m7V-aaE5L2sI7WGkSMAm2jXg622WhyK2iEwQYO258xDX1IQtQd3Vc/s1600/MCP4251_tcon_fritzing_diagram.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZr9UIin2mcJ8MtAmUCBwHAQ4BHjaxXkzYZSpKGNDfAeOYMw7eu7fQXB6ZrRdKM_XKHlOwqc9Oe-M0CYRZix8Ot9m7V-aaE5L2sI7WGkSMAm2jXg622WhyK2iEwQYO258xDX1IQtQd3Vc/s1600/MCP4251_tcon_fritzing_diagram.png" height="321" width="400" /></a></div>
<br />
You can download the fritzing file here:<br />
<a href="https://github.com/matt448/arduino/raw/master/MCP4251_tcon/MCP4251_tcon.fzz">https://github.com/matt448/arduino/raw/master/MCP4251_tcon/MCP4251_tcon.fzz</a><br />
<br />
and you can download the MCP4251 fritzing part I made here:<br />
<a href="https://github.com/matt448/arduino/raw/master/MCP4251_tcon/MCP4251.fzpz">https://github.com/matt448/arduino/raw/master/MCP4251_tcon/MCP4251.fzpz</a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbuR4V9000OEbnL-Vwe0oTqxvjuUFnhd88rofeT2UY1ECi_YNLQrsEp3IO-r2v0XkAZu-vDzruZDorRkCfXsntFm1knbc6kXtG1jmX500zs3EYzAUzxSS_u1OrTIDZ1pPtJEdQN5k6qGs/s1600/IMG_4049.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbuR4V9000OEbnL-Vwe0oTqxvjuUFnhd88rofeT2UY1ECi_YNLQrsEp3IO-r2v0XkAZu-vDzruZDorRkCfXsntFm1knbc6kXtG1jmX500zs3EYzAUzxSS_u1OrTIDZ1pPtJEdQN5k6qGs/s1600/IMG_4049.JPG" height="240" width="320" /></a></div>
<br />
<br />
<br />
<h3>
The code</h3>
Here is a Gist with the example code. The most recent version will be my the github repo here:<br />
<a href="https://github.com/matt448/arduino/tree/master/MCP4251_tcon">https://github.com/matt448/arduino/tree/master/MCP4251_tcon</a><br />
<script src="https://gist.github.com/matt448/9612191.js"></script></div>
<br />
<br />
<h3>
Up next</h3>
Part 3 in my series of digital potentiometer posts will cover reading data from the MCP4251 to determine the wiper positions and the tcon status. Part 4 will cover using multiple SPI digital potentiometers. I will add a links here as I complete those posts.Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com11tag:blogger.com,1999:blog-9120755343492164185.post-73269138178495048642014-03-02T17:19:00.000-06:002014-07-31T17:27:42.799-05:00Adding MOLLE / PALS webbing to a backpack<div class="separator" style="clear: both; text-align: center;">
</div>
I really like my <a href="http://www.amazon.com/The-North-Face-Surge-Daypack/dp/B000NB2NWY" target="_blank">North Face Surge</a> backpack but I have never found the vertical daisy chain loops on the back panel to be very useful. I guess you can clip on small items with a carabiner but I never do that. I do have a few items that use the <a href="http://en.wikipedia.org/wiki/MOLLE" target="_blank">MOLLE</a> or <a href="http://en.wikipedia.org/wiki/Pouch_Attachment_Ladder_System" target="_blank">PALS</a> attachment system and I would like to attach those to the back panel of my pack. So I decided to try and modify my backpack.<br />
<br />
Here is a how the pack looked before I modified it.<br />
<br />
<table align="center">
<tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn6APehJ7HdW0FFePyG0K9y3MNemkJidD1l5ZTK5RPF7NAbcXnLZ3UaT3H6W8zUs82aFsITYRLsNBOqX8OJxunWi76xAPA2M838gkyw37SXbmYQUGZcA5H9T5O9PpwLAOkrH01NvBRrhM/s1600/IMG_3981.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn6APehJ7HdW0FFePyG0K9y3MNemkJidD1l5ZTK5RPF7NAbcXnLZ3UaT3H6W8zUs82aFsITYRLsNBOqX8OJxunWi76xAPA2M838gkyw37SXbmYQUGZcA5H9T5O9PpwLAOkrH01NvBRrhM/s1600/IMG_3981.jpg" height="200" width="150" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzWlpzzWa74xMPF0zk9I9yzAM-0mriqbnzSs0a1GtLwSG5gJMDBI3C2sd8hDWMshE4GNBEKd9Iyezq-uHCRhmNedIMnP5SeQqs27ZeTAwVFk1l13ZrHptJDBGnibNgIN1t0Su0WHpv8RE/s1600/IMG_3982.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzWlpzzWa74xMPF0zk9I9yzAM-0mriqbnzSs0a1GtLwSG5gJMDBI3C2sd8hDWMshE4GNBEKd9Iyezq-uHCRhmNedIMnP5SeQqs27ZeTAwVFk1l13ZrHptJDBGnibNgIN1t0Su0WHpv8RE/s1600/IMG_3982.jpg" height="200" width="150" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimV7-bE3eOW1SzZ7hW2fFmCG_odwflFQIzHtpHHwMb52sxUQIUCMwLHXMU72BH0AT40SbFe54lb3bnBXAk6J6GCLq9xUcfAkC5io1KYaU-bCg7TlaL9UeqhYPJMoo9WzffE6M0C41mUeo/s1600/IMG_3984.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimV7-bE3eOW1SzZ7hW2fFmCG_odwflFQIzHtpHHwMb52sxUQIUCMwLHXMU72BH0AT40SbFe54lb3bnBXAk6J6GCLq9xUcfAkC5io1KYaU-bCg7TlaL9UeqhYPJMoo9WzffE6M0C41mUeo/s1600/IMG_3984.jpg" height="200" width="150" /></a></div>
</td></tr>
</tbody></table>
<br />
The loops down the center of the flap are what I want to change. These vertical loops are usually referred to as a daisy chain. <a href="http://en.wikipedia.org/wiki/MOLLE" target="_blank">MOLLE</a>, or more specifically <a href="http://en.wikipedia.org/wiki/Pouch_Attachment_Ladder_System" target="_blank">PALS</a>, is method of attaching pouches and equipment to a bag. It is used by the military and law enforcement personnel to attach things like radios, ammo clips, knives, first aid kits, etc to bags and vests. There are quite a few <a href="http://www.lifeviewoutdoors.com/tactical-and-military-gear/molle-shoulder-bags-and-pouch-accessories/" target="_blank">handy generic pouches</a> as well. The PALS system uses one inch webbing spaced in horizontal rows one inch apart and sewn at one and half inch intervals. Most people seem to use the term MOLLE and PALS interchangeably but really MOLLE is a line of military gear that uses the PALS attachment system. Equipment that is attached using PALS webbing uses straps that are woven in and out of the rows and secured with a snap or velcro. Some equipment uses plastic clips that hook into the rows.<br />
<br />
Here is a diagram of how to sew PALS / MOLLE.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB12n6Jo26-iwAhabqFudYVwHVRf9yCAD9Q9xQARzhR9RldcUIM-a5PXVA9DW9mIm0pdhmfYlVs0aJHIi0VvyyNZBo3mkUrDYsyIqGZRKtrVi0Y360T8okPqsYD8qYh4I8bSH1g2aeBoY/s1600/PALS-MOLLE+stitching.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB12n6Jo26-iwAhabqFudYVwHVRf9yCAD9Q9xQARzhR9RldcUIM-a5PXVA9DW9mIm0pdhmfYlVs0aJHIi0VvyyNZBo3mkUrDYsyIqGZRKtrVi0Y360T8okPqsYD8qYh4I8bSH1g2aeBoY/s1600/PALS-MOLLE+stitching.png" height="223" width="400" /></a></div>
<br />
<br />
Before I modified my backpack I first tried sewing some PALS webbing onto scrap fabric.<br />
<br />
<table align="center">
<tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAnjwdICdkci1ER5NLTJSF4mhD_DTILz2G9NIVY6Canle1nOU83ry1y2Q1CbGiWRriuHWMdSlZ2lUrDkdxCp5LHaWB1gql-cPunMomTG8JRYAO6tI3wwvNdIb2A3HxV3MNFafdK3z8gH4/s1600/IMG_3978.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAnjwdICdkci1ER5NLTJSF4mhD_DTILz2G9NIVY6Canle1nOU83ry1y2Q1CbGiWRriuHWMdSlZ2lUrDkdxCp5LHaWB1gql-cPunMomTG8JRYAO6tI3wwvNdIb2A3HxV3MNFafdK3z8gH4/s1600/IMG_3978.JPG" height="150" width="200" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgizcLlVWvmiklOaLTNKH8iNBOvA1r982JTSBAadWAYMH8OI6c7CecSm7POIagn9W4aPn7_2F4PauTH6DUjouRN4T8IO2VDfiaWlFyruVGyqwfH3Vo5PP4guPU0Plsx8ZLmry1n6RcHVuY/s1600/IMG_3979.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgizcLlVWvmiklOaLTNKH8iNBOvA1r982JTSBAadWAYMH8OI6c7CecSm7POIagn9W4aPn7_2F4PauTH6DUjouRN4T8IO2VDfiaWlFyruVGyqwfH3Vo5PP4guPU0Plsx8ZLmry1n6RcHVuY/s1600/IMG_3979.JPG" height="150" width="200" /></a></div>
</td></tr>
</tbody></table>
<br />
It went pretty well on the scrap fabric. The ends of the webbing were a little difficult because had melted them a little too much. When cutting the webbing you need to use a flame to melt the ends to keep it from fraying but it only needs to be melted very lightly. If you melt it too much it will cause big lumps which are difficult to sew. I did a test fit of my Leatherman sheath and it fit perfectly so I moved on to modifying my backpack.<br />
<br />
The first step was to run a zigzag stitch across the rubbery material to hold it in place and to reinforce the strap before I shortened it. Then I used a <a href="http://en.wikipedia.org/wiki/Seam_ripper" target="_blank">seam ripper</a> to remove all the stitching below the zigzag stitch. After that I used some scissors to cut off the strap and rubbery material from the area I want to place rows of PALS webbing.<br />
<br />
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgChYeAjuMyg9S4sbj0y3NLm3_-ne38tZjK30zItSrwTfrjlxkN6uCt0CVGdGx9N96XKiWClLd97dDS9C4cwP3mV6nbvxELvtFZJPPKWZuBqrX5vyvEpUH8bu8JKp3ekWoM28avefmk5jQ/s1600/IMG_3985.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgChYeAjuMyg9S4sbj0y3NLm3_-ne38tZjK30zItSrwTfrjlxkN6uCt0CVGdGx9N96XKiWClLd97dDS9C4cwP3mV6nbvxELvtFZJPPKWZuBqrX5vyvEpUH8bu8JKp3ekWoM28avefmk5jQ/s1600/IMG_3985.jpg" height="320" width="240" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidGhsjAsja_zijJpd2o_u5VeXHop8o79OmD7-HdG1UFrzcb-9rut8VAYuXIp-xEOYQan4RKP6uvObn5YX_VZhNq8mkfYo3MZL7esRThIIgmkW103MNkX_S61cciHImG_SOY4UjptdkL88/s1600/IMG_3986.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidGhsjAsja_zijJpd2o_u5VeXHop8o79OmD7-HdG1UFrzcb-9rut8VAYuXIp-xEOYQan4RKP6uvObn5YX_VZhNq8mkfYo3MZL7esRThIIgmkW103MNkX_S61cciHImG_SOY4UjptdkL88/s1600/IMG_3986.jpg" height="320" width="240" /></a></div>
</td></tr>
</tbody></table>
<br />
<br />
Next I laid out the rows of webbing. I started out with laying pieces of webbing on the bag and measuring but it was difficult to visualize where the loops would end up. I made a paper diagram which made it easier to see how many full loops I could get. Because the flap tapers up I was only able to get three loops but that would be perfect for attaching my Leatherman and a flash light. Next I used a <a href="http://www.amazon.com/Dritz-Marking-Pencil-White-Soluble/dp/B000XZY3FK/ref=sr_1_5?ie=UTF8&qid=1393799037&sr=8-5" target="_blank">water soluble marking pencil</a> to lay out the webbing and sewing line locations.<br />
<br />
<table align="center">
<tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMX03_VFejzbChy7DVZNC0VdKG2vb56lHXhyoy97NKKwPVonAOIitWkq-CRvigw0o_D2SEwvAulWaWTU-QwP4WqXJmRktyPZAGl2-O2KAAxV1NGQ5xsmpXfylbccwRt3s2YV-og60eiJo/s1600/IMG_3987.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMX03_VFejzbChy7DVZNC0VdKG2vb56lHXhyoy97NKKwPVonAOIitWkq-CRvigw0o_D2SEwvAulWaWTU-QwP4WqXJmRktyPZAGl2-O2KAAxV1NGQ5xsmpXfylbccwRt3s2YV-og60eiJo/s1600/IMG_3987.jpg" height="200" width="150" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNkb-bNs8jGDRSXKPRfKhMy8z92mjsAH2ylsg8-_d4s5RlyWipHu4r0-bFtbvuGiqNS5zA_dQWlC2yLCFcPt4c59gJZiplcM5g0hazV-pDCV-LutWDs9XGcXYGQJVv1BoY9WO-1Hy8Jos/s1600/IMG_3988.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNkb-bNs8jGDRSXKPRfKhMy8z92mjsAH2ylsg8-_d4s5RlyWipHu4r0-bFtbvuGiqNS5zA_dQWlC2yLCFcPt4c59gJZiplcM5g0hazV-pDCV-LutWDs9XGcXYGQJVv1BoY9WO-1Hy8Jos/s1600/IMG_3988.jpg" height="200" width="150" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXKZntzUFREPsET3XyZGen1EHm0AJavU6XpPvdF6XUJpsEsAB_0ilUHgx8MB_fGMkMoJ6w9HczvV4FkGHg-HRlxMduxKIQhD0oE6IurNh7AN_B85rwPSJ8g4sZsKneFPLxKSN3838k4mk/s1600/IMG_3989.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXKZntzUFREPsET3XyZGen1EHm0AJavU6XpPvdF6XUJpsEsAB_0ilUHgx8MB_fGMkMoJ6w9HczvV4FkGHg-HRlxMduxKIQhD0oE6IurNh7AN_B85rwPSJ8g4sZsKneFPLxKSN3838k4mk/s1600/IMG_3989.jpg" height="200" width="150" /></a></div>
</td></tr>
</tbody></table>
<br />
<br />
I trimmed the ends of the webbing to the same taper as the flap and lightly melted the ends. Then I pinned the webbing in place.<br />
<br />
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhB-u84YLEV7QyHeJgiHxUgjPwtG8dKzxErrYhevfCOOL5TTPPoGapItaOfIa8aIqSMCB9tTeii-LZKIJTxpHq3x0zmHoLBPFR5__yFRdbr3-FErF-kt2k4tkW8lr_grPTj8D_24VvPuZw/s1600/IMG_3991.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhB-u84YLEV7QyHeJgiHxUgjPwtG8dKzxErrYhevfCOOL5TTPPoGapItaOfIa8aIqSMCB9tTeii-LZKIJTxpHq3x0zmHoLBPFR5__yFRdbr3-FErF-kt2k4tkW8lr_grPTj8D_24VvPuZw/s1600/IMG_3991.jpg" height="200" width="150" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGOLjs7YCaSwZCQ80-qC6P3FSBZBTqDwnn7H8Y77csMU9_Jnp6zRdBZYXITYHrV3mvD6lSd7gkKDPo94FvLuBvV0W_-3FUx02ck9tBw5joUyaKPfiXKgB_kVNznsnno0tMyrLkpBqGoi4/s1600/IMG_4006.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGOLjs7YCaSwZCQ80-qC6P3FSBZBTqDwnn7H8Y77csMU9_Jnp6zRdBZYXITYHrV3mvD6lSd7gkKDPo94FvLuBvV0W_-3FUx02ck9tBw5joUyaKPfiXKgB_kVNznsnno0tMyrLkpBqGoi4/s1600/IMG_4006.jpg" height="200" width="150" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiola4C2BBZWO7v3zOw3OKoSR0xH_y2uPx3XXREvKJDDAyVEpW1wsC_xQaGlwEouVaA9D_sIavwm5FjrBMqCBOhrCU89xuL7BYJBc6vWZomxqBU0uXDBEC-USX9QgpJN5ns7IUwmEuZG64/s1600/IMG_3992.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiola4C2BBZWO7v3zOw3OKoSR0xH_y2uPx3XXREvKJDDAyVEpW1wsC_xQaGlwEouVaA9D_sIavwm5FjrBMqCBOhrCU89xuL7BYJBc6vWZomxqBU0uXDBEC-USX9QgpJN5ns7IUwmEuZG64/s1600/IMG_3992.jpg" height="200" width="150" /></a></div>
</td></tr>
</tbody></table>
<br />
<br />
Next up was the sewing. The top piece of webbing wasn't too bad but the lower piece took some acrobatics to get all the lines sewn. I ran a straight stitch first and then a zigzag stitch over top of it for strength.<br />
<br />
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjns9X9HzXU3kgbHJi2EILXXylemJDagu7lCD9vGaaFPux2BEeUUDO-S6_eTI3dcsWmvTmGS-u0Gpmr8dPePQJr8-DCxHVrTPph1QnwhRtR2SBL6QzF_1brh2DxPG8Hsp81_-2qtSDCGp4/s1600/IMG_3993.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjns9X9HzXU3kgbHJi2EILXXylemJDagu7lCD9vGaaFPux2BEeUUDO-S6_eTI3dcsWmvTmGS-u0Gpmr8dPePQJr8-DCxHVrTPph1QnwhRtR2SBL6QzF_1brh2DxPG8Hsp81_-2qtSDCGp4/s1600/IMG_3993.jpg" height="200" width="150" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzO4tQfdHbHd04kawWNW6nrzIPhaWHZ8z-uxf9H4O7rqHCktGn8WpQr0zvBIa-bVk3hB8c33HV8CgL-uL7IQQ71vBgS55RPdYvIXXUT7cGr1RS0ltLt8zQ-dz4bEMSpTG9Gn50vMJX5d8/s1600/IMG_3994.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzO4tQfdHbHd04kawWNW6nrzIPhaWHZ8z-uxf9H4O7rqHCktGn8WpQr0zvBIa-bVk3hB8c33HV8CgL-uL7IQQ71vBgS55RPdYvIXXUT7cGr1RS0ltLt8zQ-dz4bEMSpTG9Gn50vMJX5d8/s1600/IMG_3994.jpg" height="200" width="150" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhetbJhXvYsvDk7Mcml8nAFB3TEfkas0bHnYygNwK_kBuNLk0zBtSQ-uyqSy8zhdxoej7FZh2QKah1-zavP1EuAKkVnbYgtDHZdbzYKKammW6XYa-YhObv_N6bus6qnnh3sIuYDwEkm2_Y/s1600/IMG_3995.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhetbJhXvYsvDk7Mcml8nAFB3TEfkas0bHnYygNwK_kBuNLk0zBtSQ-uyqSy8zhdxoej7FZh2QKah1-zavP1EuAKkVnbYgtDHZdbzYKKammW6XYa-YhObv_N6bus6qnnh3sIuYDwEkm2_Y/s1600/IMG_3995.jpg" height="200" width="150" /></a></div>
</td></tr>
</tbody></table>
<br />
<br />
Sewing is complete. The stitching is visible on the inside of the flap but it doesn't look too terrible and the flap is usually closed. Quick test fit of my Leatherman and then all that's left is to clean up the white pencil lines with a washcloth and some water.<br />
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJCiYLA7WD1ycMGIoP_PGat6o-IkUBn9oapj_sfXf2fgTFWDtOY7tmYXwUJpG1LHT-fUxJq_-QHvSP3Kp2A3XYa_3AJEB9czi6PWvq5Hemh_-SYmOt5DfgL1eW5m_nkct8sF5FcJMBJso/s1600/IMG_3996.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJCiYLA7WD1ycMGIoP_PGat6o-IkUBn9oapj_sfXf2fgTFWDtOY7tmYXwUJpG1LHT-fUxJq_-QHvSP3Kp2A3XYa_3AJEB9czi6PWvq5Hemh_-SYmOt5DfgL1eW5m_nkct8sF5FcJMBJso/s1600/IMG_3996.jpg" height="200" width="150" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQfCqAaJ14nIOhlDNlkR-FTkVdhFcuUHDzl_BKcs1NHf1mf7vRpiJAfvk5qTPmpewL34up1LU4iPZ5bl_Pe_cIRkpfN2pNOFBwH0YbBYkow57gJAQ0gQxcllraDzGFiVuYm_21sh6sgTQ/s1600/IMG_3997.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQfCqAaJ14nIOhlDNlkR-FTkVdhFcuUHDzl_BKcs1NHf1mf7vRpiJAfvk5qTPmpewL34up1LU4iPZ5bl_Pe_cIRkpfN2pNOFBwH0YbBYkow57gJAQ0gQxcllraDzGFiVuYm_21sh6sgTQ/s1600/IMG_3997.jpg" height="200" width="150" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEislp74eR_VvRsSMh2s1mW_RyboZKvcHU816-To_9tHQplBdSvf4HpKLYWImzOtFw9X1GamcQ7PS_iUdYB__SLQwZPQimYL7rInEEOIXWlB9vmby-L6nkLOcEltF54j944oDlDgJdpXWlw/s1600/IMG_3998.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEislp74eR_VvRsSMh2s1mW_RyboZKvcHU816-To_9tHQplBdSvf4HpKLYWImzOtFw9X1GamcQ7PS_iUdYB__SLQwZPQimYL7rInEEOIXWlB9vmby-L6nkLOcEltF54j944oDlDgJdpXWlw/s1600/IMG_3998.jpg" height="200" width="150" /></a></div>
</td></tr>
</tbody></table>
<br />
<br />
And here is the finished product. It turned out exactly like wanted. :-)<br />
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv34TzPcj3cGh4Ov60Cvf9ZLOl2aolfyLv5DNixjGFgXFbalbu_8VSwaAEr1hwBLAQRVsBIqNmKdDpUKzkqHxAOYN2rf_-TaujK-iaBZr0tVTgwUWJ8Ny2AdaZj4YR6Xm6FtelPHY2yEQ/s1600/IMG_4001.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv34TzPcj3cGh4Ov60Cvf9ZLOl2aolfyLv5DNixjGFgXFbalbu_8VSwaAEr1hwBLAQRVsBIqNmKdDpUKzkqHxAOYN2rf_-TaujK-iaBZr0tVTgwUWJ8Ny2AdaZj4YR6Xm6FtelPHY2yEQ/s1600/IMG_4001.jpg" height="200" width="150" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWsge7gXSqMncRAe96eM2urEiTQwJ__KX4A6CWUOx1AKXAxtdOekvq0voAkM6_5tvpijdMHXBCi4nd9mCx5a4uOmVqQJOsuTl-FPiuBpbK-NnwIE2KVqt5mnrTxmtbeZkEPpbgVFvVd24/s1600/IMG_4003.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWsge7gXSqMncRAe96eM2urEiTQwJ__KX4A6CWUOx1AKXAxtdOekvq0voAkM6_5tvpijdMHXBCi4nd9mCx5a4uOmVqQJOsuTl-FPiuBpbK-NnwIE2KVqt5mnrTxmtbeZkEPpbgVFvVd24/s1600/IMG_4003.jpg" height="200" width="150" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDH1XqgxwplZwjfvecUQLr7igOp-X6pfL0P8vdnVu260n8oXb91T9T_ww613JduuZEA8U0ntbcpIAzfJAHAoILDLmO4Rrwt8jTzeK-HefQtDcL2NKyJ7Efw-49RpqenqPmIySVYJkv9T8/s1600/IMG_4004.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDH1XqgxwplZwjfvecUQLr7igOp-X6pfL0P8vdnVu260n8oXb91T9T_ww613JduuZEA8U0ntbcpIAzfJAHAoILDLmO4Rrwt8jTzeK-HefQtDcL2NKyJ7Efw-49RpqenqPmIySVYJkv9T8/s1600/IMG_4004.jpg" height="200" width="150" /></a></div>
</td></tr>
</tbody></table>
<br />
<br />
[UPDATE 2014-07-31]<br />
<br />
Just a small update. I sewed my own MOLLE flashlight holder out of some 2" webbing and added that to my pack. My buddy bought me a 'tactical' pen which fits nicely on the center loops.
<br />
<br />
<table align="center"><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlgZUs875y8JVk4pdHf4jRYB4oaeW9k0VHK1OaXTXWapMnMn8VLbhp0P5Y80-Sr3YJ9ZjexVYva3nJjHUIqcYMd5XuCYgyLIGm43sppE-VlTT7ojK9YrMml4i22sRk5uL2YKuyGUOVyuU/s1600/IMG_4640.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlgZUs875y8JVk4pdHf4jRYB4oaeW9k0VHK1OaXTXWapMnMn8VLbhp0P5Y80-Sr3YJ9ZjexVYva3nJjHUIqcYMd5XuCYgyLIGm43sppE-VlTT7ojK9YrMml4i22sRk5uL2YKuyGUOVyuU/s1600/IMG_4640.jpg" height="320" width="240" /></a></div>
</td><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg6I_0m-OJFQpUCdqNJuPhfvF9j3_hGyyykDV9_hWx18JxQ6UoiE_k6kVOx8WjoGeVqmkYLWGJ8aSbr5cYU5FT_qPP8JIpB7JVAccSHZbi-NcO0yz-eixe9q5mYBLbk7lLBDKoNq8xzBs/s1600/IMG_4641.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg6I_0m-OJFQpUCdqNJuPhfvF9j3_hGyyykDV9_hWx18JxQ6UoiE_k6kVOx8WjoGeVqmkYLWGJ8aSbr5cYU5FT_qPP8JIpB7JVAccSHZbi-NcO0yz-eixe9q5mYBLbk7lLBDKoNq8xzBs/s1600/IMG_4641.jpg" height="320" width="240" /></a></div>
</td></tr>
</tbody></table>
<br />Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com6tag:blogger.com,1999:blog-9120755343492164185.post-47748581883299877512014-02-03T23:29:00.001-06:002014-12-01T09:00:41.750-06:00Arduino - Digital speedometer<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" /></a></div>
I have all aftermarket gauges in my car and a while ago my aftermarket speedometer died. The needle just dropped to zero while I was driving down the highway. Since then I have been using my Garmin GPS as my speedometer but it's maps are really out of date and I actually prefer to use <a href="https://www.waze.com/" target="_blank">Waze</a> on my iPhone for navigation. I wanted to ditch the Garmin but then I wouldn't have a speedometer. I thought it might be fun project to try and build a cheap speedometer using an Arduino Uno and some type of digital display.<br />
<br />
I bought a <a href="http://www.adafruit.com/products/880" target="_blank">green 7-Segment Display w/I2C backpack</a> and a <a href="http://www.adafruit.com/products/1480" target="_blank">2.2" color TFT LCD display</a> from <a href="http://www.adafruit.com/" target="_blank">Adafruit</a> to experiment with.<br />
<br />
<table align="center" border="0" style="width: 80%;">
<tbody>
<tr>
<td align="center"><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/AVvXsEh0Qc0E64zJk7jE0FveCq24g3V_x5eLyxrTOsjO3AtyY303T2SDrfIcsy7X5x-4xMmHEOhZ0SOvpPDE5PkAN1XlLs_CfKkNwDKVZE4NSbX6n0dHqzs-gxjxiTsExOSA_9oOK_VxL-LmKbg/s1600/Screen+Shot+2013-12-31+at+6.03.47+PM.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0Qc0E64zJk7jE0FveCq24g3V_x5eLyxrTOsjO3AtyY303T2SDrfIcsy7X5x-4xMmHEOhZ0SOvpPDE5PkAN1XlLs_CfKkNwDKVZE4NSbX6n0dHqzs-gxjxiTsExOSA_9oOK_VxL-LmKbg/s1600/Screen+Shot+2013-12-31+at+6.03.47+PM.png" height="109" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">7-Segment</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
</td><td align="center"><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/AVvXsEifqMlytopf2vAmoFOHr-wzcsFALIQzn84qwE3RSEIuqDitKmH-fxs7nSdeKVEA0ZBtUb7qPztqPZDYm7TiadmwJgIbhdv8BW2Csxy1cj8awPxUELfu60YFmpLDvAuVJRygzpA21nTPsWA/s1600/Screen+Shot+2013-12-31+at+6.12.20+PM.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifqMlytopf2vAmoFOHr-wzcsFALIQzn84qwE3RSEIuqDitKmH-fxs7nSdeKVEA0ZBtUb7qPztqPZDYm7TiadmwJgIbhdv8BW2Csxy1cj8awPxUELfu60YFmpLDvAuVJRygzpA21nTPsWA/s1600/Screen+Shot+2013-12-31+at+6.12.20+PM.png" height="200" width="134" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">2.2" TFT Display</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
</td></tr>
</tbody></table>
After playing with both displays I found the TFT display couldn't refresh fast enough. (<a href="http://matthewcmcmillan.blogspot.com/2014/01/arduino-improving-refresh-rate-of-tft.html" target="_blank">actually I just don't know how to make it refresh fast enough</a>). The redraw on the TFT made the numbers flash which was very annoying. I may use the TFT screen to show other info that doesn't have to be refreshed frequently like average speed and trip distance. The 7-Segment worked well so I focused on using it. The <a href="https://github.com/adafruit/Adafruit-LED-Backpack-Library" target="_blank">Adafruit LED Backpack library</a> for the 7-Segment display is pretty easy to use. Writing numbers to the 7 Segment display is nearly as simple as a Serial.print. The only issue I ran into was controlling the brightness. The brightness function in their library didn't work for me. I end up looking at the code in their library wrote my own function.<br />
<br />
The backpack on the 7 segment display allows it to be controlled by the Arduino using the <a href="http://en.wikipedia.org/wiki/I%C2%B2C" target="_blank">I2C protocol (also called Two Wire Interface)</a>. Without the I2C backpack you would have to directly control all eight segments of each number which would use up all the pins on the Arduino or you would have to figure out some other method which would probably end up being very similar to what Adafruit did. Each Arduino model has certain pins that are used for I2C. On the Uno pins analog 4 and analog 5 are used for this purpose. See the <a href="http://arduino.cc/en/reference/wire" target="_blank">Wire library page</a> for more I2C info.<br />
<br />
<br />
<h3>
What is a VSS?</h3>
<br />
Most modern computer controlled cars since the late 1990's have a sensor called a VSS or Vehicle Speed Sensor. The location of the sensor varies but they all do the same thing which is count the number of times some part of the drive train rotates. On my car the VSS is in the transmission. The output of the VSS is some number of pulses per mile in a 5 vdc square wave signal. The first step in this project was to find out how many pulses per mile my VSS puts out. This number varies from car manufacturer to car manufacturer and sometimes model to model. I found <a href="http://www.rostra.com/" target="_blank">a company</a> that makes aftermarket cruise control systems and <a href="http://www.rostra.com/manuals/Form4428L.pdf" target="_blank">their installation manual contained a list of cars and VSS pulses per mile</a>. The pulses per mile value can range from 2000 all the way up to 38600. The VSS on my car puts out 4000 ppm which seems to be a common value but you must find out the correct value for your particular vehicle otherwise the readings will be incorrect. You can also consult <a href="http://www.rostra.com/manuals/Form4428L.pdf" target="_blank">their installation manual</a> for the location of the VSS signal wire. It is important that you only tap into the VSS wire and not completely interrupt it. The engine and transmission computers use this signal as well.<br />
<br />
<br />
<h3>
Time for some math</h3>
<br />
So now I know my VSS puts out 4000 pulses per mile. Next I need to figure out how to convert that into miles per hour. After looking at some example code on how to measure pulses I decided I would count the VSS pulses for one second. With that info I could then convert the pulse count into mph. First I converted one hour (the hour from miles per hour) into seconds which is 3600. Then divide the number of pulses per mile by the number of seconds (4000/3600). Then you divide the number of pulses counted on the sensor by that value. Here is my final formula:<br />
<br />
<pre>miles per hour = pulse count/(VSS pulses per mile/time period)</pre>
<br />
<br />
<h3>
Building the prototype</h3>
<br />
I started with an Arduino Uno and an <a href="http://www.adafruit.com/products/51" target="_blank">Adafruit Protosheild</a>. I hacked up an old USB cable to connect the 7-segment display. A USB cable is perfect for this. Two wires for the I2C and two larger gauge wires for power and ground. I cut off the ends of the USB cable and stripped each of the wires. I tinned the wires with solder so I could plug them directly into the bread board and added some heat shrink tubing for strain relief. Here is a Fritzing diagram of the wiring:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoDS26mNj5IlI2d5suNDfZ5mqiHOF0Mnpxnd4UtFWxnTna7m_dGCJgE1iGbGeP7FPT9rWXphK2FLEqtnd6hIMWTrVMt0aDOYyz8GsWahkuMM2x1uYOD51F0kvp-c9QioNTFTK9kMBQGR8/s1600/Speedometer_7seg.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoDS26mNj5IlI2d5suNDfZ5mqiHOF0Mnpxnd4UtFWxnTna7m_dGCJgE1iGbGeP7FPT9rWXphK2FLEqtnd6hIMWTrVMt0aDOYyz8GsWahkuMM2x1uYOD51F0kvp-c9QioNTFTK9kMBQGR8/s1600/Speedometer_7seg.png" height="270" width="400" /></a></div>
<br />
- Connect 'C' (CLK) on the display to Analog #5. (Leonardo Digital #3, Mega digital #21)<br />
- Connect 'D' (DAT) on the display to Analog #4. (Leonardo Digital #2, Mega digital #20)<br />
- Connect GND on the display to common ground<br />
- Connect VCC+ on the display to power +5V<br />
<div>
- VSS sensor on the vehicle connects to Digital #5</div>
<div>
- Analog #0 is used to measure a Photocell (Light Dependent Resistor)</div>
<div>
<br /></div>
<div>
Here is how the wiring looks<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh83lFPTMH8Rky8qzP8MRO7OPwo9viVFEp9vbWcaNU0DX9RyXzIaGVXYre0LCBdxrrE8fusdtryyKUYuYbcUUrzH7r1_WNJc740mpFiIgbiSUBhnhrnQ1e6Q-8e8KamfkuKWqiEVfRVjRw/s1600/IMG_3842.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh83lFPTMH8Rky8qzP8MRO7OPwo9viVFEp9vbWcaNU0DX9RyXzIaGVXYre0LCBdxrrE8fusdtryyKUYuYbcUUrzH7r1_WNJc740mpFiIgbiSUBhnhrnQ1e6Q-8e8KamfkuKWqiEVfRVjRw/s1600/IMG_3842.JPG" height="240" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
I made a quick little cardboard housing for the 7-segment display to shield it from the sun.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPHB_bwxOoIFpuO_w8j2SQarwDkStRtHVX14CBuBEgGxRxYIyCgrJCoLyWpS2-NSMCaIrvLoA_vrCSvcs9ZWrmhqcQLxVvr5fTT8jiD-cOkh94p9wMXNnNJYOCxC7tOJ_TFosylJjX64w/s1600/IMG_3841.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPHB_bwxOoIFpuO_w8j2SQarwDkStRtHVX14CBuBEgGxRxYIyCgrJCoLyWpS2-NSMCaIrvLoA_vrCSvcs9ZWrmhqcQLxVvr5fTT8jiD-cOkh94p9wMXNnNJYOCxC7tOJ_TFosylJjX64w/s1600/IMG_3841.JPG" height="240" width="320" /></a></div>
<br />
After I tested it at night I decided to add a photocell (Light Dependent Resistor) to control the brightness of the display. It took some tweaking to get the brightness changes just right. Initially the brightness of the display fluctuated with every street light I passed. I changed the code to use an average of 30 light level readings. That way the brightness changes slowly.<br />
<br />
Here is how it looks in my car during the day.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_foUS6GXVJErtPMJxT6AsuqiwEVjKcb5QkhJH8wToV0bWgLL3uQL0dJg_rAoI_lHzpU-ujMom1QDSifAL-wCCpKr-RFmKWSzOcObY9obBbdwsCrzn_G8c-jv4yt39WFNlle8o2sImSC4/s1600/IMG_3840.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_foUS6GXVJErtPMJxT6AsuqiwEVjKcb5QkhJH8wToV0bWgLL3uQL0dJg_rAoI_lHzpU-ujMom1QDSifAL-wCCpKr-RFmKWSzOcObY9obBbdwsCrzn_G8c-jv4yt39WFNlle8o2sImSC4/s1600/IMG_3840.JPG" height="240" width="320" /></a></div>
<br />
and at night<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm0NZPJsvl2GLvqCjOekXw9IpoolTarzo3Nl0WGrrPYEw0mhPlsqSGxQG6QvnxnxAqcBhL3FKZY_zO5CNCwHlqAEHCZY4LGgy1Px3iQDts2PKrmVCYDDZpoA_LI3Xc9m7k0m5mhhFLfZs/s1600/IMG_3838.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm0NZPJsvl2GLvqCjOekXw9IpoolTarzo3Nl0WGrrPYEw0mhPlsqSGxQG6QvnxnxAqcBhL3FKZY_zO5CNCwHlqAEHCZY4LGgy1Px3iQDts2PKrmVCYDDZpoA_LI3Xc9m7k0m5mhhFLfZs/s1600/IMG_3838.JPG" height="240" width="320" /></a></div>
<br />
<h3>
The code</h3>
<br />
The github repo is here <a href="https://github.com/matt448/arduino/tree/master/Speedometer_7seg">https://github.com/matt448/arduino/tree/master/Speedometer_7seg</a><br />
The code for the hardware pulse counting section came straight from example 18.7 in the <a href="http://www.amazon.com/Arduino-Cookbook-Michael-Margolis/dp/1449313876" target="_blank">Arduino Cookbook</a>. My understanding of how this works is: the ATmega chip has a few hardware timers. This code uses a timer on Digital #5 on the UNO. The TCCR1B part of the code sets bits on that timer to configure it to count pulses. The code then waits for one second and reads how many pulses were stored in the hardware counter. Then the hardware counter is reset to zero for the next loop. Keep in mind this code is written specifically for an Arduino Uno. It would need to be modified to work with other boards.<br />
<br />
Here is the current version of the code in a gist.<br />
<br />
<br /></div>
<script src="https://gist.github.com/matt448/8797921.js"></script>
<br />
<h3>
Results
</h3>
I tested my new speedometer against the GPS and it was right on the money. It also reacts quite a bit faster than the GPS and it works inside a parking garage unlike the GPS. I have been using it for about a month now and it works great. The only negative I have found is the display isn't readable when the sun is shining directly into it which isn't very often because of the housing. I'm looking into other display options now that I have something that works. VFD displays seem like a good option. I'm also still tinkering with the 2.2" TFT display. Here is a video of the speedometer in action<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/_lE0XNUKAtE" width="560"></iframe>
<br />
<br />
<h3>
Next steps</h3>
I am planning to solder all the connections on a piece of perfboard that I have turned into a shield of sorts. I'll need to put it in a box and tuck it some where in the dash. Currently I am powering the unit with a 12volt to USB power supply which is plugged into a cigarette lighter jack. I might take that apart and package the guts of the power supply with the Uno.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipO7lGpmYzejjc78cID3QYTGarjskGyTsbDq190Qtcw-qcxDL_aLIMca5YHuSmLMaWEiFl5jFl8t0r480tPtYEHUgEJPaKE5d7Iby0QgqdN81529U1OH50j2IpLiUz-whmvFExIFUy0Jk/s1600/IMG_3843.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipO7lGpmYzejjc78cID3QYTGarjskGyTsbDq190Qtcw-qcxDL_aLIMca5YHuSmLMaWEiFl5jFl8t0r480tPtYEHUgEJPaKE5d7Iby0QgqdN81529U1OH50j2IpLiUz-whmvFExIFUy0Jk/s1600/IMG_3843.JPG" height="240" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhslZW3a2S48PLb45e57py1bbxgmK46qSRc23morFIgBweR6PxSBdAcfMUViTjJxsoX-YAezZAW4VCUnEjeM6BQLXwr4XDhNnqBnKG5LDVJKxZP_a6HhB4VFlN-Rv3vLhT6S-SrwdAb-Qg/s1600/IMG_3845.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhslZW3a2S48PLb45e57py1bbxgmK46qSRc23morFIgBweR6PxSBdAcfMUViTjJxsoX-YAezZAW4VCUnEjeM6BQLXwr4XDhNnqBnKG5LDVJKxZP_a6HhB4VFlN-Rv3vLhT6S-SrwdAb-Qg/s1600/IMG_3845.jpg" height="320" width="240" /></a></div>
<br />
<br />
<br />Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com47tag:blogger.com,1999:blog-9120755343492164185.post-82042215240145575662014-01-15T22:27:00.001-06:002014-10-22T08:54:28.298-05:00Arduino - Improving refresh rate of a TFT LCD display<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" /></a></div>
I'm working on a digital speedometer project for my car and I ordered a couple different displays from <a href="http://www.adafruit.com/" target="_blank">Adafruit</a> to experiment with. One of the displays I ordered is a <a href="http://www.adafruit.com/products/1480" target="_blank">2.2" color TFT LCD display</a>. I was really hoping to use this display to show the current speed of my car. One concern I had about using it for that purpose was the speed that an Arduino board could refresh the information on the screen. To test the display I wrote a simple sketch that just displays the number of seconds since start. Here is a video of that first attempt:<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/4ZVIlTC5bMs" width="560"></iframe>
<br />
<br />
The redraw time causes the numbers to look like they are flashing which is very annoying. The mistake I made was blanking out the entire screen with tft.fillScreen(ILI9340_BLACK). It takes quite a while to redraw the entire screen with black.
<br />
<br />
Next I tried drawing a black rectangle just on the area of the screen where I was drawing numbers. Here is the result:
<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/V083TOyUtSE" width="560"></iframe>
<br />
<br />
Huge improvement. Only blanking out that small area greatly sped up the redraw time.<br />
In this next video I have highlighted the redraw area in red to make it easier to see what I am talking about:<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/_7uB30xQ0po" width="560"></iframe>
<br />
<br />
What I am realizing at this point is you should only redraw information that has changed. If you watch the last video again, once the number goes past single digits the left digit looks like it is flashing. This is because it is being blanked out and redrawn every time the number changes. When you redraw something that hasn't changed it looks like flashing. Well that's it for now. I am going to continue to work on this more and figure out how to selectively redraw only digits that change. Once I figure that out I'll write up <a href="http://matthewcmcmillan.blogspot.com/2014/08/arduino-tft-lcd-display-refresh-rate-part2.html" target="_blank">another blog post</a>.<br />
[UPDATE] - Here is part two:<br />
<a href="http://matthewcmcmillan.blogspot.com/2014/08/arduino-tft-lcd-display-refresh-rate-part2.html" target="_blank"> http://matthewcmcmillan.blogspot.com/2014/08/arduino-tft-lcd-display-refresh-rate-part2.html</a><br />
<br />
<br />
Here is the code I was using to do my testing.
<br />
<script src="https://gist.github.com/matt448/8449600.js"></script>
<br />
<br />
<br />
[Updated 2014-08-08 - Added <a href="http://matthewcmcmillan.blogspot.com/2014/08/arduino-tft-lcd-display-refresh-rate-part2.html" target="_blank">link to part 2 of this topic</a>]
<br />
<br />
<br />Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com16tag:blogger.com,1999:blog-9120755343492164185.post-2531689155655427382014-01-11T22:16:00.000-06:002014-08-30T09:47:21.701-05:00Daemonized rvm ruby tasks using start-stop-daemon<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYuYcihGeWWECV4M8-1-zWIxxhl2NRbMsVM_8Sk3M5-Vx_DeNHfJWXKVYoYduVAZzMW4RqX0Q4lx1nHIZhyphenhyphenSgO-OMALwZ4HzimViZbK1RQD9HtJt6EOkhXWoQfCKH-ovEvlQmyStJDtjc/s1600/ruby_logo.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYuYcihGeWWECV4M8-1-zWIxxhl2NRbMsVM_8Sk3M5-Vx_DeNHfJWXKVYoYduVAZzMW4RqX0Q4lx1nHIZhyphenhyphenSgO-OMALwZ4HzimViZbK1RQD9HtJt6EOkhXWoQfCKH-ovEvlQmyStJDtjc/s1600/ruby_logo.png" /></a></div>
I am very new to Ruby so the solution described in this post might be very obvious to some but I could not find all the parts of this solution in one place. I cobbled together bits and pieces of other peoples startup and capistrano scripts to get this working. My research has also shown there are <a href="http://daemons.rubyforge.org/" target="_blank">ruby gems</a> that might handle some of this better but I wasn't trying to reinvent the wheel. Anyhow, on with the show. At work, during our <a href="http://capistranorb.com/documentation/overview/what-is-capistrano/" target="_blank">capistrano deployment</a> we have a ruby process that has to be launched in the background. We are using <a href="http://man.he.net/man8/start-stop-daemon" target="_blank">start-stop-daemon</a> to daemonize the process but our use of <a href="http://rvm.io/" target="_blank">rvm</a> complicates running rake because the rake binary is stored in the .rvm/gems directory. Normally the path to the rake binary is set from .bashrc and .bash_profile when you log in through a shell but when you execute things from cron, start-up scripts or other non-shell environments the paths don't exist. After some googling and tinkering I finally got something that worked:<br />
<br />
<span style="color: #999999;">task</span><span style="color: blue;"> </span><span style="color: #741b47;">:start_mytask</span><span style="color: #999999;">,</span><span style="color: blue;"> </span><span style="color: #741b47;">:roles</span><span style="color: blue;"> </span><span style="color: #999999;">=></span><span style="color: blue;"> </span><span style="color: #741b47;">:mytask</span><span style="color: #999999;">,</span><span style="color: blue;"> </span><span style="color: #741b47;">:except</span><span style="color: blue;"> </span><span style="color: #999999;">=> {</span><span style="color: blue;"> </span><span style="color: #741b47;">:no_release</span><span style="color: blue;"> </span><span style="color: #999999;">=></span><span style="color: blue;"> </span><span style="color: #741b47;">true</span><span style="color: blue;"> </span><span style="color: #999999;">}</span><span style="color: blue;"> </span><span style="color: #f1c232;">do</span><br />
<span style="color: blue;"> </span><span style="color: #999999;">run</span><span style="color: blue;"> </span><span style="color: #999999;">"</span><span style="color: #741b47;">RAILS_ENV=</span><span style="color: #999999;">#{rails_env} </span><span style="color: #741b47;">start-stop-daemon --start -b -m -o -d ~/current -p ~/pids/mytask.pid -a /home/ubuntu/.rvm/gems/ruby-1.9.3-p194@global/bin/rake mytask</span><span style="color: #999999;">"</span><br />
<span style="color: #f1c232;">end</span><br />
<br />
The downside with this script is I was calling rake for a specific version of ruby. At the time this was good enough to get us by. Fast forward several months and now we are preparing to upgrade to ruby 2.0. Our existing start script needed to be updated to use ruby 2.0 but I wanted to find a better way that wouldn't need to be tweaked each time we upgrade ruby. My first shot at updating the script I switched to executing rvm and calling '<a href="http://stackoverflow.com/questions/8275885/use-bundle-exec-rake-or-just-rake" target="_blank">bundle exec rake</a>':<br />
<br />
<span style="color: #999999;">task</span><span style="color: blue;"> </span><span style="color: #741b47;">:start_mytask</span><span style="color: #999999;">,</span><span style="color: blue;"> </span><span style="color: #741b47;">:roles</span><span style="color: blue;"> </span><span style="color: #999999;">=></span><span style="color: blue;"> </span><span style="color: #741b47;">:mytask</span><span style="color: #999999;">,</span><span style="color: blue;"> </span><span style="color: #741b47;">:except</span><span style="color: blue;"> </span><span style="color: #999999;">=> {</span><span style="color: blue;"> </span><span style="color: #741b47;">:no_release</span><span style="color: blue;"> </span><span style="color: #999999;">=></span><span style="color: blue;"> </span><span style="color: #741b47;">true</span><span style="color: blue;"> </span><span style="color: #999999;">}</span><span style="color: blue;"> </span><span style="color: #f1c232;">do</span><br />
<span style="color: blue;"> </span><span style="color: #999999;">run</span><span style="color: blue;"> </span><span style="color: #999999;">"</span><span style="color: #741b47;">RAILS_ENV=</span><span style="color: #999999;">#{rails_env} </span><span style="color: #741b47;">start-stop-daemon --start -b -m -o --chdir ~/current --pidfile ~/pids/mytask.pid --exec ~/.rvm/bin/rvm -- current do bundle exec rake mytask</span><span style="color: #999999;">"</span><br />
<span style="color: #f1c232;">end</span><br />
<br />
This eliminates directly calling rake for a specific version of ruby but introduces a different issue. Executing it this way causes rvm to launch in a bash shell which then executes the rake task. start-stop-daemon creates a pid file based off of the first process started which is the bash process not the rake task. So when you try to stop it start-stop-daemon tries to kill the bash process which won't end because it has a child process running the rake task. I was getting closer but it wasn't perfect. More googling ensued and I discovered I could use rvm-exec instead of rvm. The rvm-exec command fixes the bash shell problem. It was created specifically for calling rvm in scripts. Here is what I finally came up with:<br />
<br />
<span style="color: #999999;">task</span><span style="color: blue;"> </span><span style="color: #741b47;">:start_mytask</span><span style="color: #999999;">,</span><span style="color: blue;"> </span><span style="color: #741b47;">:roles</span><span style="color: blue;"> </span><span style="color: #999999;">=></span><span style="color: blue;"> </span><span style="color: #741b47;">:mytask</span><span style="color: #999999;">,</span><span style="color: blue;"> </span><span style="color: #741b47;">:except</span><span style="color: blue;"> </span><span style="color: #999999;">=> {</span><span style="color: blue;"> </span><span style="color: #741b47;">:no_release</span><span style="color: blue;"> </span><span style="color: #999999;">=></span><span style="color: blue;"> </span><span style="color: #741b47;">true</span><span style="color: blue;"> </span><span style="color: #999999;">}</span><span style="color: blue;"> </span><span style="color: #f1c232;">do</span><br />
<span style="color: #f1c232;"> </span><span style="color: #999999;">run</span><span style="color: blue;"> </span><span style="color: #999999;">"</span><span style="color: #741b47;">RAILS_ENV=</span><span style="color: #999999;">#{rails_env} </span><span style="color: #741b47;">start-stop-daemon --start -b -m -o --chdir ~/current --pidfile ~/pids/mytask.pid --exec ~/.rvm/bin/rvm-exec -- current bundle exec rake mytask</span><span style="color: #999999;">"</span><br />
<span style="color: #f1c232;">end</span><br />
<br />
It will now run independent of a ruby version number and since only one process is launched the pid file is created correctly. One other benefit I realized is now it is much easier to monitor this process. Previously the process was listed as just "rake". If you have more than one running that would get tricky to monitor. Launching it with this new script the process is listed as "rake mytask".<br />
<br />
Finally to stop the daemonized rake task run this command:<br />
<br />
<span style="color: #999999;">task</span><span style="color: blue;"> </span><span style="color: #741b47;">:stop_mytask</span><span style="color: #999999;">,</span><span style="color: blue;"> </span><span style="color: #741b47;">:roles</span><span style="color: blue;"> </span><span style="color: #999999;">=></span><span style="color: blue;"> </span><span style="color: #741b47;">:mytask</span><span style="color: #999999;">,</span><span style="color: blue;"> </span><span style="color: #741b47;">:except</span><span style="color: blue;"> </span><span style="color: #999999;">=> {</span><span style="color: blue;"> </span><span style="color: #741b47;">:no_release</span><span style="color: blue;"> </span><span style="color: #999999;">=></span><span style="color: blue;"> </span><span style="color: #741b47;">true</span><span style="color: blue;"> </span><span style="color: #999999;">}</span><span style="color: blue;"> </span><span style="color: #f1c232;">do</span><br />
<span style="color: #999999;">run "</span><span style="color: #741b47;">start-stop-daemon -o -p ~/pids/mytask.pid --stop</span><span style="color: #999999;">"</span><br />
<span style="color: #f1c232;">end</span><br />
<br />
<br />
[UPDATE 01/13/2014] I realized today after doing more testing that I should be calling 'current bundle exec rake' instead of 'default bundle exec rake'. When you are upgrading ruby versions it doesn't necessarily mean you want to change the default ruby version in rvm. Using 'current' will cause the script to use whatever ruby is specified in the .rvmrc. I have edited the above scripts to reflect my new findings.Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com4tag:blogger.com,1999:blog-9120755343492164185.post-18629082390522855592013-12-31T13:14:00.001-06:002013-12-31T13:35:15.225-06:00Simple way to integrate Nagios with Slack messaging<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGqQKbOvV-u19DkhjGOUQN-BEp6RRHoSnsP89Sq6C5LCipUvLui07dETUVbNAuh91jzkvlgRrlv7ZTxDnJ9gNfbYedIocqzWzVjWHe6hyphenhyphen8ybCGHaP7cgPoXu_FZnkzOMbq48GvGN70Fi4/s1600/slack_logo.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGqQKbOvV-u19DkhjGOUQN-BEp6RRHoSnsP89Sq6C5LCipUvLui07dETUVbNAuh91jzkvlgRrlv7ZTxDnJ9gNfbYedIocqzWzVjWHe6hyphenhyphen8ybCGHaP7cgPoXu_FZnkzOMbq48GvGN70Fi4/s1600/slack_logo.png" /></a></div>
At work we recently switched messaging applications from Skype to a new platform called <a href="https://slack.com/" target="_blank">Slack</a>. <a href="https://slack.com/" target="_blank">Slack</a> just launched in August 2013. I have read it is similar to <a href="https://campfirenow.com/" target="_blank">Campfire</a> but I've never used that platform so I can't really comment on that but it is much more useful than a basic chat client like Skype. With <a href="https://slack.com/" target="_blank">Slack</a> you can share files, easily search message history for text or files and integrate with 3rd party applications. Plus it is private for just your team or company. <a href="https://slack.com/" target="_blank">Slack</a> has quite a few preconfigured integrations plus the ability to create your own custom integrations. First we setup the <a href="https://github.com/" target="_blank">Github</a> integration which allows all of our commit messages to dump into a channel. Next we setup the <a href="https://trello.com/" target="_blank">Trello</a> integration to dump card changes from our main board into another channel. Then I went to setup the <a href="http://www.nagios.org/" target="_blank">Nagios</a> integration and ran into problems. They have a prebuilt integration for Nagios but I could not get it to work. It would post alert messages into the channel but the messages contained no information:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpJlhdnpNh_p9i0644A8qh5Nexz7qAPpaWe1ksTpC-wvidXYjh6muIFBjgZqVNC99e7tD16ykBZwRd-_Bwp1F4lREsc0024j5SoH6sBejEegeOx5cIFTi4O8UOoGzwPlXEg2-EIMe-y_U/s1600/slack_nagios_not_working.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpJlhdnpNh_p9i0644A8qh5Nexz7qAPpaWe1ksTpC-wvidXYjh6muIFBjgZqVNC99e7tD16ykBZwRd-_Bwp1F4lREsc0024j5SoH6sBejEegeOx5cIFTi4O8UOoGzwPlXEg2-EIMe-y_U/s1600/slack_nagios_not_working.png" height="234" width="320" /></a></div>
<br />
I mucked with their provided perl script quite a bit but I simply could not get it to work. It just kept posting empty messages. Being impatient and a do-it-yourselfer I set about trying to find another way to accomplish this. I looked through the list of integrations and noticed that they had a custom one called Incoming WebHooks which is an easy way to get messages from external sources posted into Slack. The simplest way to utilize Incoming WebHooks is to use curl to post the message to Slack's API. I wrote a little bash script that provides a detailed Nagios alert, a link back to the Nagios web page and conditional emoji's! Each warning level (OK, WARNING, CRITICAL and UNKNOWN) has it's own emoji icon. Here are some example messages in my Slack client:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFSmAP79UWiDPm7edGAzL-8u0t5BYTXJyAGQgxTV1THASFLQFgOqowTHG2QfAldKnedzZbRuz9KWDOMzsrXHidtZX_lDdpUuoOozAyno0AE2HUum0ymWyp2Fyx-rhbXZVRNANLyi_4Dxs/s1600/slack_using_webhooks.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFSmAP79UWiDPm7edGAzL-8u0t5BYTXJyAGQgxTV1THASFLQFgOqowTHG2QfAldKnedzZbRuz9KWDOMzsrXHidtZX_lDdpUuoOozAyno0AE2HUum0ymWyp2Fyx-rhbXZVRNANLyi_4Dxs/s1600/slack_using_webhooks.png" height="240" width="400" /></a></div>
<br />
Here is my bash script that posts to Slack. I placed it in /usr/local/bin<br />
<br />
<script src="https://gist.github.com/matt448/8200821.js"></script>
Here are the Nagios config lines that are added to commands.cfg<br />
<br />
<script src="https://gist.github.com/matt448/8200896.js"></script>
And finally lines I added to contacts.cfg<br />
<br />
<script src="https://gist.github.com/matt448/8200958.js"></script>
I'm not sure why Slack's prebuilt Nagios integration didn't work for me but I really like what I came up with. No Perl modules to install and the only outside dependency is curl. It's also pretty easy to modify the info in the alert message by adding or removing NAGIOS_ env variables in the curl statement.Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com16tag:blogger.com,1999:blog-9120755343492164185.post-27927284761075358132013-11-04T12:58:00.001-06:002013-11-04T12:58:16.693-06:00Upgrading existing Solr installation to new version of Jetty<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgV32eMd_NXDPMjh_xIQWhLgLClOTRmA1u-r1cZRBbEhUe_r6LYF60hll7P7_SizzJt7B5SZoOW-SgPyAEiQjNc-XxzC-JiJ8ytgc1sU2pfffziA5HZEFaVpdEuuSdcNSE75IH1bvp9AMc/s1600/solr_logo.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgV32eMd_NXDPMjh_xIQWhLgLClOTRmA1u-r1cZRBbEhUe_r6LYF60hll7P7_SizzJt7B5SZoOW-SgPyAEiQjNc-XxzC-JiJ8ytgc1sU2pfffziA5HZEFaVpdEuuSdcNSE75IH1bvp9AMc/s1600/solr_logo.png" /></a></div>
At work we have been running into a problem with <a href="http://lucene.apache.org/solr/" target="_blank">Apache Solr</a> crashing. Depending on how much it was used we would get several weeks of usage out of it before it crashed. Now it is only running for five days at a time. So this fire has started burning hot enough to be at the top of my to-do list.<br />
When it crashes it throws errors saying "Too many open files". Running lsof showed it wasn't actually open files but thousands of orphaned sockets left open. The sockets looked like this in the lsof output:<br />
<br />
<span style="color: lime;">java 2428 root 2173u sock 0,7 0t0 123291433 can't identify protocol</span><br />
<br />
There won't be anything listed in netstat. These sockets don't have open connections to anything. The Solr log file will start showing errors similar to this:<br />
<br />
<span style="color: lime;">SEVERE: java.io.FileNotFoundException: /usr/local/apache-solr-3.5.0/example/solr/data/index/_dgf.frq (Too many open files)</span><br />
<span style="color: lime;"><br /></span>
<span style="color: lime;">SEVERE: SolrIndexWriter was not closed prior to finalize(), indicates a bug -- POSSIBLE RESOURCE LEAK!!!</span><br />
<span style="color: lime;"><br /></span>
<span style="color: lime;">SEVERE: org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: NativeFSLock@./solr/data/index/write.lock</span><br />
<br />
Initially we dealt with this problem by monitoring the number of open files for the java process and running a reindex when it got close to the limit. Not a great solution but at the time there weren't enough hours in the day to put a bunch of effort into figuring this out. In my case the limit when Solr blew up was 4000 open sockets. Once Solr had that many sockets open it would just throw 500 errors.<br />
<br />
Usually the answer to a situation like this is upgrade Solr to a newer version. Unfortunately I couldn't do that in this case because we have a ruby gem that is dependent on Solr version 3.5. My research pointed to Jetty as the source problem and not Solr. Once I found <a href="https://jira.codehaus.org/browse/JETTY-1458" target="_blank">this post</a> I knew for sure Jetty was causing the orphaned sockets. Solr 3.5.0 is packaged with Jetty 6.1.26 which <a href="https://jira.codehaus.org/browse/JETTY-1458" target="_blank">has a bug</a> that causes the orphaned sockets under certain conditions. Because Jetty 6 is fairly old the developers are not going to fix it. At this point I set about upgrading Jetty to version 7.<br />
<br />
The first thing I had to figure out was what stuff was Solr and what stuff was Jetty. Turns out most of the package is Jetty. Solr is contained in apache-solr-3.5.0/example/solr and apache-solr-3.5.0/example/webapps/solr.war. So I decided to try and stuff Solr 3.5.0 into Jetty 7.6.13. Later I may try moving to the latest version of Jetty 9 but I'm just trying to solve this orphaned socket problem right now and was worried the older version of Solr might have problems with a newer Jetty.<br />
<br />
<h4>
Upgrading Jetty</h4>
Here are the steps I took to upgrade Solr 3.5.0 to Jetty 7<br />
<br />
<div class="p1">
Download latest Jetty 7 (jetty-distribution-7.6.13.v20130916.tar.gz at the time this was written) from here <a href="http://download.eclipse.org/jetty/7.6.13.v20130916/dist/">http://download.eclipse.org/jetty/7.6.13.v20130916/dist/</a></div>
<div class="p2">
<br /></div>
<div class="p1">
Untar jetty-distribution-7.6.13.v20130916.tar.gz</div>
<div class="p1">
<span style="color: lime; font-family: Courier New, Courier, monospace;">tar xfvz jetty-distribution-7.6.13.v20130916.tar.gz</span></div>
<div class="p2">
<br /></div>
<div class="p2">
Create destination directory for all the new files</div>
<div class="p1">
<span style="color: lime; font-family: Courier New, Courier, monospace;">mkdir /usr/local/apache-solr-3.5.0-jetty-7.6.13</span></div>
<div class="p1">
<span style="color: lime; font-family: Courier New, Courier, monospace;">mkdir /usr/local/apache-solr-3.5.0-jetty-7.6.13/example</span></div>
<div class="p2">
<br /></div>
<div class="p1">
copy the contents of jetty-distribution-7.6.13.v20130916 to new directory</div>
<div class="p1">
<span style="color: lime; font-family: Courier New, Courier, monospace;">cp -a jetty-distribution-7.6.13.v20130916/* /usr/local/apache-solr-3.5.0-jetty-7.6.13/example</span></div>
<div class="p2">
<br /></div>
<div class="p1">
Copy solr files from old solr installation to new Jetty directory</div>
<div class="p1">
<span style="color: lime; font-family: Courier New, Courier, monospace;">cp -a /usr/local/apache-solr-3.5.0/example/solr /usr/local/apache-solr-3.5.0-jetty-7.6.13/example</span></div>
<div class="p1">
<span style="color: lime; font-family: Courier New, Courier, monospace;">cp -a /usr/local/apache-solr-3.5.0/example/webapps/solr.war /usr/local/apache-solr-3.5.0-jetty-7.6.13/example/webapps/</span></div>
<div class="p2">
<br /></div>
<div class="p2">
Edit the jetty.xml config file to change the listening port</div>
<div class="p2">
<span style="color: lime; font-family: Courier New, Courier, monospace;">vi usr/local/apache-solr-3.5.0-jetty-7.6.13/example/etc/jetty.xml</span></div>
<div class="p2">
Change this line</div>
<div class="p2">
<span style="color: lime; font-family: Courier New, Courier, monospace;"><Set name="port"><Property name="jetty.port" default="8080"/></Set></span></div>
<div class="p2">
To this</div>
<div class="p2">
<span style="color: lime; font-family: 'Courier New', Courier, monospace;"><Set name="port"><Property name="jetty.port" default="8983"/></Set></span></div>
<div class="p2">
<br /></div>
<br />
<div class="p2">
At this point solr will run but there are some example war files and config files that aren't needed for Solr and should be cleaned up. </div>
<div class="p2">
<br /></div>
<div class="p2">
- Edit /usr/local/apache-solr-3.5.0-jetty-7.6.13/example/start.ini</div>
<div class="p2">
<span style="color: lime; font-family: Courier New, Courier, monospace;">vi /usr/local/apache-solr-3.5.0-jetty-7.6.13/example/start.ini</span></div>
<div class="p2">
Comment out the line</div>
<div class="p2">
<span style="color: lime; font-family: Courier New, Courier, monospace;">etc/jetty-testrealm.xml</span></div>
<div class="p2">
so it reads </div>
<div class="p2">
<span style="color: lime; font-family: Courier New, Courier, monospace;">#etc/jetty-testrealm.xml</span></div>
<div class="p2">
<br /></div>
<div class="p2">
- Clean up example war files</div>
<div class="p2">
<span style="color: lime; font-family: Courier New, Courier, monospace;"> cd /usr/local/apache-solr-3.5.0-jetty-7.6.13/example/webapps</span></div>
<div class="p2">
<span style="color: lime; font-family: Courier New, Courier, monospace;"> mkdir BAK</span></div>
<div class="p2">
<span style="color: lime; font-family: Courier New, Courier, monospace;"> mv test.war spdy.war BAK</span></div>
<div class="p2">
<br /></div>
- Clean up example config files<br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> cd /usr/local/apache-solr-3.5.0-jetty-7.6.13/example/etc</span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> mkdir BAK</span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> mv jetty-spdy.xml jetty-spdy-proxy.xml jetty-testrealm.xml BAK</span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> cd /usr/local/apache-solr-3.5.0-jetty-7.6.13/example/contexts</span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> mkdir BAK</span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> mv test.xml BAK</span><br />
<br />
I use a symbolic link for the installation directory so the start script doesn't have to be modified. Before restarting I have to switch that sym link.<br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> service solr stop</span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> cd /usr/local</span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> rm solr</span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> ln -s apache-solr-3.5.0-jetty-7.6.13 solr</span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> service solr start</span><br />
<br />
Then you can test hitting the service locally.<br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> curl localhost:8983/solr/</span><br />
<br />
it should return html that says something like this:<br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> <title>Welcome to Solr</title></span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> </head></span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"><br /></span>
<span style="color: lime; font-family: Courier New, Courier, monospace;"> <body></span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;"> <h1>Welcome to Solr!</h1></span><br />
<br />
You will probably need to run a reindex if transactions have been taking place while solr was down for the upgrade.<br />
<br />
<span style="font-size: x-small;">Resources used to compile this post</span><br />
<a href="http://comments.gmane.org/gmane.comp.ide.eclipse.jetty.user/919"><span style="font-size: x-small;">http://comments.gmane.org/gmane.comp.ide.eclipse.jetty.user/919</span></a><br />
<a href="https://github.com/umars/jetty-solr"><span style="font-size: x-small;">https://github.com/umars/jetty-solr</span></a><br />
<a href="http://stackoverflow.com/questions/6425759/how-to-upgrade-update-the-solr-jetty-ubuntu-package"><span style="font-size: x-small;">http://stackoverflow.com/questions/6425759/how-to-upgrade-update-the-solr-jetty-ubuntu-package</span></a><br />
<a href="https://jira.codehaus.org/browse/JETTY-1458"><span style="font-size: x-small;">https://jira.codehaus.org/browse/JETTY-1458</span></a><br />
<a href="http://grokbase.com/t/lucene/solr-user/123e6et8e0/too-many-open-files-lots-of-sockets"><span style="font-size: x-small;">http://grokbase.com/t/lucene/solr-user/123e6et8e0/too-many-open-files-lots-of-sockets</span></a>Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com0tag:blogger.com,1999:blog-9120755343492164185.post-5680916300825902122013-10-24T19:21:00.002-05:002014-03-27T17:55:19.538-05:00Arduino - Using digital potentiometers (AD8403)<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEKsnCdSgAWxcQH8VbZSygI8F-b0pq9BOgn7qA3EIrsBYAHqVP7QSzMK-4ABdsSwJVTvApnmdyHnAbMq5OEZxK_sUyoTJMpJPTa9ORgOg5JwYsUVNDMaO8qDXI3ji7v5SVis0LHBGIzao/s1600/arduino_logo.jpg" /></a></div>
I have seen several blog posts covering the use of digital potentiometers with an Arduino but I haven't seen any that demonstrate digital pots that contain a shutdown circuit. I'm working on a project that needs this particular feature.<br />
<br />
The shutdown circuit is of interest to me because I plan on interfacing with something that controls movement. In that application any value on the digital pot will cause a motor to move. Lower resistive values move forward and higher resistive values move back. I need a way to completely disable the potentiometer. My first prototype used two relays, two transistors and two resistors with different values. The Arduino would turn off and on the relays to cause movement. It worked because I could simply turn off both relays but it was quite bulky and the mechanical relays were noisy. A friend recommend a digital potentiometer as a replacement. A single digital pot chip would replace six components. I began researching them and found that not all of them include a shutdown circuit. I settled on the <a href="http://www.analog.com/en/digital-to-analog-converters/digital-potentiometers/ad8403/products/product.html" target="_blank">Analog Devices AD8403 chip</a>. It i<span style="font-family: inherit;">s a quad channel,</span> 256 position digitally controlled variable resistor. Communication is done through an SPI interface.<br />
<br />
So lets start with a demonstration of what happens when there is no shutdown circuit on a digital potentiometer and the Arduino is reset. The circuit and code cycles through each digital pot varying the brightness of an LED by running up and down all 255 positions of the pot. While this is running I press the reset button on the Arduino.<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="360" src="//www.youtube.com/embed/twRDaa5tIiQ" width="480"></iframe>
<br />
<br />
In this situation the digital pot chip still has power and the value of one the pots is stuck while the Arduino resets (demonstrated by the LED staying lit). In my real application this would cause movement to continue until the board finished restarting which is highly undesirable. This effect could be minimized somewhat by including code to reset values of the four pots on startup but there would still be a second or two of uncontrolled movement while the board restarts.<br />
<br />
Next is a demonstration of the same circuit but with the shutdown circuit enabled. The shutdown pin is connected to a pull down resistor. This causes the chip to go into shutdown mode if the Arduino resets or loses power. Again I press the reset button on the Arduino as it is running the code.<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="360" src="//www.youtube.com/embed/w_sljuID9u0" width="480"></iframe>
<br />
<br />
This is getting close to what I want but there is still the problem of the pot being set to some unknown value when the AD8B403 is taken out of shutdown mode. To handle this I added code to the setup function that sets the pots to a known value (zero in this case) before taking the chip out of shutdown mode.<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="360" src="//www.youtube.com/embed/XgPOLOmC7YU" width="480"></iframe>
<br />
<br />
<h4>
Circuit</h4>
Here is a photo and Fritzing diagram of the circuit.
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgezTDQ9Ib-QWdpohm16x-3kA9r9wGWAo7KmgAJLqgVrkEurKlGeyUKVVH6bg4Nz0Aa-BZnm3Cqvzl1BsVK8WD0-m419NWalgn0Rcta7q-IWO4-33ZnVGSUOVTNVMbgeTRiu9hpO8Gy8IQ/s1600/IMG_3408.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgezTDQ9Ib-QWdpohm16x-3kA9r9wGWAo7KmgAJLqgVrkEurKlGeyUKVVH6bg4Nz0Aa-BZnm3Cqvzl1BsVK8WD0-m419NWalgn0Rcta7q-IWO4-33ZnVGSUOVTNVMbgeTRiu9hpO8Gy8IQ/s1600/IMG_3408.JPG" height="300" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both;">
The connections are:</div>
<div class="separator" style="clear: both;">
* All A pins of AD8403 connected to +5V</div>
<div class="separator" style="clear: both;">
* All B pins of AD8403 connected to ground</div>
<div class="separator" style="clear: both;">
* An LED and a 220-ohm resisor in series connected from each W pin to ground</div>
<div class="separator" style="clear: both;">
* RS - to +5v</div>
<div class="separator" style="clear: both;">
* SHDN - to digital pin 7 and a 10k ohm pull down resistor</div>
<div class="separator" style="clear: both;">
* CS - to digital pin 10 (SS pin)</div>
<div class="separator" style="clear: both;">
* SDI - to digital pin 11 (MOSI pin)</div>
<div class="separator" style="clear: both;">
* CLK - to digital pin 13 (SCK pin)</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
The AD8403 is the 10k ohm version.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNtZ96_G3cvQFQ2Zo6P2bmXsaecZZjlYLB1vZT1YJGj1wX_kJhRKgG8SY3o9pgkAuVG5jwQ7043cFSdsSDGF_KbTKlm7wormcZElbZB0X0mBIL-FGdJBf1ww9AYQ2Yi2QScMOJpLbquN4/s1600/SPI_Digital_Pot_bb.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNtZ96_G3cvQFQ2Zo6P2bmXsaecZZjlYLB1vZT1YJGj1wX_kJhRKgG8SY3o9pgkAuVG5jwQ7043cFSdsSDGF_KbTKlm7wormcZElbZB0X0mBIL-FGdJBf1ww9AYQ2Yi2QScMOJpLbquN4/s1600/SPI_Digital_Pot_bb.png" height="400" width="316" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The Fritzing diagram is available here: <a href="https://github.com/matt448/arduino/raw/master/SPI_Digital_Pot_AD8403/SPI_Digital_Pot_AD8403.fzz">https://github.com/matt448/arduino/raw/master/SPI_Digital_Pot_AD8403/SPI_Digital_Pot_AD8403.fzz</a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h4>
Code</h4>
<div>
The most update to date version of the code is available here: <a href="https://github.com/matt448/arduino/blob/master/SPI_Digital_Pot_AD8403/SPI_Digital_Pot_AD8403.ino">https://github.com/matt448/arduino/blob/master/SPI_Digital_Pot_AD8403/SPI_Digital_Pot_AD8403.ino</a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The code to control this isn't very complex. This is my first time using an SPI device and I found it to be very straight forward. The Arduino IDE has an example sketch for controlling SPI digital pots under File > Examples > SPI > DigitalPotControl. I started with the example and modified it to include shutdown control. That example code also ran a bit slow because of the serial console messages so I removed all the serial communication code.</div>
<script src="https://gist.github.com/matt448/7139886.js"></script>
<br />
<h4>
Comment on shutdown pin</h4>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
So after getting through all this testing I noticed a limitation of the shutdown pin, it shuts down all four pots at the same time. In my real application I plan on controlling movement on four separate motors and moving them to a certain positions. Once the motor reaches it's position I want it to stop. But the only way to stop the motor is activate the shutdown which deactivates all four pots. This is a problem because the other three motors may not have reached their position when I need to shutdown. I did some more looking and found that <a href="http://www.microchip.com/" target="_blank">Microchip</a> makes a digital pot that has individually controllable software shutdown for each pot. I'm going to order a couple <a href="http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en531889" target="_blank">MCP4251</a> chips and I'll write up <a href="http://matthewcmcmillan.blogspot.com/2014/03/arduino-using-digital-potentiometers.html" target="_blank">another post</a> when I test them out.<br />
<br />
UPDATE 3/17/2014: <a href="http://matthewcmcmillan.blogspot.com/2014/03/arduino-using-digital-potentiometers.html" target="_blank">Post about the MCP4251 is available here</a><br />
UPDATE 3/27/2014: Added list of connections and resistor values. Also added links to github repo.Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com5tag:blogger.com,1999:blog-9120755343492164185.post-32815318476811646672013-10-10T17:04:00.000-05:002018-06-15T16:02:50.225-05:00Arduino - Sending data over a CAN bus<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZD3fuYBv164VE0vOa0DnvAB7JMC7DVXry-05tLnh1duhOrmrUzr6BTHud1WsvDOPB7HKpfu9_krSGQO46Ln00H24dILKLhOB-LC_m1B5IFH4nuVK-MP2kxlm-XL5yMSaY1QaJMuuutUU/s1600/arduino_logo.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZD3fuYBv164VE0vOa0DnvAB7JMC7DVXry-05tLnh1duhOrmrUzr6BTHud1WsvDOPB7HKpfu9_krSGQO46Ln00H24dILKLhOB-LC_m1B5IFH4nuVK-MP2kxlm-XL5yMSaY1QaJMuuutUU/s1600/arduino_logo.jpg" /></a></div>
I have been tinkering with CAN buses due to my interest in cars. It's fascinating to me that packets are flying around a modern vehicle controlling nearly everything. Gauges, lights, locks, engine sensors, etc. To have a better understanding of the basics of a CAN bus I wanted to build the simplest possible setup to send and receive CAN messages. I chose two Arduino Uno's with a <a href="http://www.seeedstudio.com/depot/canbus-shield-p-1240.html" target="_blank">Seeed Studio CAN-BUS shield</a> attached to each Uno. The Seeed shield is very straight forward and inexpensive. The <a href="https://www.sparkfun.com/products/10039" target="_blank">Sparkfun CAN-BUS shield</a> has an SD card slot, LCD connector and GPS connector. All of which are cool but drive up the price and complexity. The Seeed shield only does CAN bus and includes screw terminals which are handy for testing.<br />
<br />
<table align="center" border="0">
<tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiOTSlADxfwh25HIVP2jJqrN_ZeTfDOvIQhzTxNpGLG551yeO8JwzHP-6Y5VmU4bMa2zEmu13RpvlbZTKLd25X7BWkCuGog9ZwIWHamVEbj3ZwOyp3r3cz18Ql2ooRVP_ud22kygTRKzc/s1600/arduino_uno_r3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="158" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiOTSlADxfwh25HIVP2jJqrN_ZeTfDOvIQhzTxNpGLG551yeO8JwzHP-6Y5VmU4bMa2zEmu13RpvlbZTKLd25X7BWkCuGog9ZwIWHamVEbj3ZwOyp3r3cz18Ql2ooRVP_ud22kygTRKzc/s1600/arduino_uno_r3.jpg" width="200" /></a></div>
</td>
<td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS3idPDfnJAu-zp9_VW0ENjy4-4LPqE4QEYDKTogA7Na6KlWhsJYQFejFUGYXzHboq4czalKKMtXKG6zN8dcWooxd1ulFU9SanB1PMaUonuGW98oXdwskxX-JY7CF9zwsxXCYNHMOkHNI/s1600/canbus+shield.jpg" imageanchor="1"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS3idPDfnJAu-zp9_VW0ENjy4-4LPqE4QEYDKTogA7Na6KlWhsJYQFejFUGYXzHboq4czalKKMtXKG6zN8dcWooxd1ulFU9SanB1PMaUonuGW98oXdwskxX-JY7CF9zwsxXCYNHMOkHNI/s1600/canbus+shield.jpg" width="200" /></a>
</td>
</tr>
<tr><td align="center">Arduino Uno R3</td><td align="center">Seeed CAN-BUS Shield</td>
</tr>
</tbody></table>
<br />
What I wanted to do with this experiment was transmit the value of an analog pin hooked up to a linear potentiometer. The data would be sent from one Arduino to another over a CAN bus and then display that value on an LCD connected to the second Arduino. Here is a picture of my setup. (Ignore the Mega2560 above the LCD. It's not used here.)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTrTj6_rbpZA2-TEfYG6gS0pIo5cCmzRsYeQVEcYlr1MdobdDfWtgKdUQInoa8ziuwWFKlHz64R1ubLKzh60LaS90z6SXlK6JHOqp8VEp6EoXDus7EzjY4s0wI6FpvW1PwLz5Axg6eDR8/s1600/IMG_3365.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTrTj6_rbpZA2-TEfYG6gS0pIo5cCmzRsYeQVEcYlr1MdobdDfWtgKdUQInoa8ziuwWFKlHz64R1ubLKzh60LaS90z6SXlK6JHOqp8VEp6EoXDus7EzjY4s0wI6FpvW1PwLz5Axg6eDR8/s1600/IMG_3365.JPG" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
And here is a Fritzing diagram minus the CAN-BUS shields.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPZYPgH1jTp7U-ChH29hO1UoCV7KjekbVzNDNXko4e9lOolEJlEuZTjDUxv8lF-T8K7SPFALMLFSesvkGjex0mmu43G4Vg4A5n8uv8G0VFZcoHmvO-0XX9xk6p7Ul8ieopIK5bJfhHCGQ/s1600/can_test_bb.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="175" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPZYPgH1jTp7U-ChH29hO1UoCV7KjekbVzNDNXko4e9lOolEJlEuZTjDUxv8lF-T8K7SPFALMLFSesvkGjex0mmu43G4Vg4A5n8uv8G0VFZcoHmvO-0XX9xk6p7Ul8ieopIK5bJfhHCGQ/s1600/can_test_bb.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h4 style="clear: both; text-align: left;">
CAN bus termination</h4>
<div class="separator" style="clear: both; text-align: left;">
A CAN bus requires 120 Ohm termination resistors at each end of the bus. The Seeed Studio shields have built in termination resistors. When you connect two Seeed CAN bus shields togther like I did in this example you will have a properly terminated CAN bus. If you plan on connecting into an existing CAN bus that already has termination you can disable the built in termination resistors. To disable termination you can cut trace P1 or you can desolder resistor R1.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<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/AVvXsEgGINurgxjXChXMQkwdiHbm3tY8u3TorkNd992FqRGhCZn3tR6rHpCmG7coVn7jbqLVUOymEDyT2uwTMvzWB6Psqky9T7jKsXf8iEtW4rHHEgaNeGYQ04ABOvFUtk46XgpBDG1OaML4Ej4/s1600/seeed_term_resistor.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="266" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGINurgxjXChXMQkwdiHbm3tY8u3TorkNd992FqRGhCZn3tR6rHpCmG7coVn7jbqLVUOymEDyT2uwTMvzWB6Psqky9T7jKsXf8iEtW4rHHEgaNeGYQ04ABOvFUtk46XgpBDG1OaML4Ej4/s1600/seeed_term_resistor.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Close up view of the Seeed CAN bus shield<br />
termination resistors.</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: left;">
**Note: I have recently discovered the Seeed Studio CAN-BUS shield v1.0 uses a 60 ohm termination resistor for R3. While that worked for this small demo I later ran into issues when trying to use this shield with other nodes on a CAN bus. This 60 ohm resistor caused me many hours of frustration. If you are going to use this shield with on a bus with multiple nodes I would recommend desoldering R3 and using the correct 120 ohm resistance at the ends of your bus. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h4 style="clear: both; text-align: left;">
Connecting into an existing CAN bus</h4>
If you are planning on connecting into an existing CAN bus (like in a car) you need to remove/disable the termination resistor on the shield as explained above. The CAN bus in a vehicle already has termination resistors. Adding a new node with a termination resistor will cause errors and disrupt communication on the bus.<br />
<br />
Another important step is to connect a common ground between your Arduino board and the vehicle. If you are connecting at the OBD2 port pin 5 provides a signal ground. If you can't find a signal ground wire a chassis ground will suffice.<br />
<br />
<h4>
CAN bus messages
</h4>
<div>
So I should probably explain a bit about CAN bus messages. Each message is made up of an id and some data. The id's in hex start at 0x000 and go to 0x7FF or 0 to 2047 in decimal. In most systems lower id values are considered more important. The bus handles collisions by letting the lower id win the collision. The data can be between 1 and 8 bytes for each message. Each byte can have a value from 0 to 255 or in hex 0x00 to 0xFF. When you send a CAN bus message you transmit the id, how many bytes you are sending (this is called DLC) and the actual data. The receiver will only read the number of bytes you said should be in the message. So if you send a DLC of 4 but the message contains 8 bytes the receiver will only read the first 4 bytes. Eight bytes per message is a bit limiting but the tradeoff is the high reliability of the bus. So sometimes you have to be creative with stuffing data into those bytes. If the value you are sending is less than 255 you can just use a single byte. Larger numbers will require using multiple bytes. Ascii codes can be sent but only eight characters per message. Whatever method you use to stuff the data in will also have to be used to un-stuff the data on the receiver. In my simple example here I did some math to limit the range of values to 0-255. An analog pin produces values between 0-1024. I simply divided the result by four to give me data I could send in a single byte.</div>
<div>
CAN buses can operate at several different speeds up to 1 Mbit/s. Typical rates are 100 kbit/s, 125 kbit/s and 500 kbit/s. Slower rates allow for longer length buses. All devices on a bus must transmit at the same speed. The <a href="http://en.wikipedia.org/wiki/CAN_bus" target="_blank">CAN bus wikipedia page</a> is a good place to start if you want to learn more about the CAN protocol.</div>
<h4>
<br />
Code</h4>
I started with the example code provided by Seeed and modified it to add in the LCD output on the 'receiver' device and added reading of the potentiometer on A0 for the value that is transmitted. They have basic examples for send and receive. You can find some good info on <a href="http://wiki.seeedstudio.com/CAN-BUS_Shield_V1.2/" target="_blank">their wiki page</a>. Their <a href="https://github.com/Seeed-Studio/CAN_BUS_Shield" target="_blank">libraries are available here</a>. On my Mac I created the directory ~/Documents/Arduino/libraries/CAN_BUS_Shield for the library files. I unzipped the file and copied over the .h and .cpp files into that new directory. The zip file also contains the send and receive examples.<br />
<br />
Note that normally devices on a CAN bus are both receivers and transmitters of data. This is a simplified example where each device is only doing one task.<br />
<br />
<br />
<br />
<h3>
Sender code
</h3>
<script src="https://gist.github.com/matt448/6925235.js"></script>
<br />
<h3>
Receiver code
</h3>
<script src="https://gist.github.com/matt448/6925334.js"></script>
<br />
<h4>
Video
</h4>
<iframe allowfullscreen="" frameborder="0" height="360" src="//www.youtube.com/embed/us9ZEvdm09A" width="480"></iframe><br />
<br />
<br />
[Updated 2014-05-25: Noted value of A0 potentiometer in the Fritzing diagram]<br />
[Updated 2014-07-21: Added section about termination resistors]<br />
[Updated 2014-09-25: Added note about incorrect value of resistor R3 on Seeed's shield]<br />
[Updated 2015-03-10: Added additional notes about termination resistors]<br />
[Updated 2017-03-27: Added new section 'Connecting into an existing CAN bus']<br />
[Updated 2018-06-15: Fixed broken links for Seeed-Studio wiki and libraries] <br />
<br />
<br />
<br />Matthew McMillanhttp://www.blogger.com/profile/02359945130001450035noreply@blogger.com125