{"id":842,"date":"2020-02-01T13:36:04","date_gmt":"2020-02-01T18:36:04","guid":{"rendered":"https:\/\/blog.lufamily.ca\/kang\/?p=842"},"modified":"2020-02-21T16:30:49","modified_gmt":"2020-02-21T21:30:49","slug":"custom-counter","status":"publish","type":"post","link":"https:\/\/blog.lufamily.ca\/kang\/2020\/02\/01\/custom-counter\/","title":{"rendered":"Custom Counter"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"alignleft size-medium\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"300\" src=\"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/51dOBEopNJL._SL1001_-300x300.jpg\" alt=\"\" class=\"wp-image-846\" srcset=\"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/51dOBEopNJL._SL1001_-300x300.jpg 300w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/51dOBEopNJL._SL1001_-150x150.jpg 150w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/51dOBEopNJL._SL1001_-768x768.jpg 768w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/51dOBEopNJL._SL1001_.jpg 1001w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><figcaption>Circular Knitting Machine<\/figcaption><\/figure><\/div>\n\n\n\n<p>This all started when my wife started to use a circular knitting machine that she purchased recently. These machines can be used to quickly knit hats, scarfs, slippers, etc. I have seen her creating yarn goodness within a matter of minutes. The machine certainly decreases the time to produce goods when compared to traditional hand knitting by several folds. As a toy, literally, it has proven its worth several times over.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignright size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/Screen-Shot-2020-02-01-at-1.01.24-PM-1024x822.png\" alt=\"\" class=\"wp-image-849\" width=\"336\" height=\"270\" srcset=\"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/Screen-Shot-2020-02-01-at-1.01.24-PM-1024x822.png 1024w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/Screen-Shot-2020-02-01-at-1.01.24-PM-300x241.png 300w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/Screen-Shot-2020-02-01-at-1.01.24-PM-768x616.png 768w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/Screen-Shot-2020-02-01-at-1.01.24-PM-1536x1232.png 1536w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/Screen-Shot-2020-02-01-at-1.01.24-PM.png 1568w\" sizes=\"auto, (max-width: 336px) 85vw, 336px\" \/><figcaption>Microswitch placement<\/figcaption><\/figure><\/div>\n\n\n\n<p>While using the machine, she has found that keeping count on the number of times the machine has revolved can be somewhat challenging. Of course this situation created a need for an electronic counter.<\/p>\n\n\n\n<p>The idea is to use a microswitch to detect the notches on the machine, and use an ATMEGA328P microcontroller (MCU), running at 16MHz, to keep track of the count. The MCU is the same used by the famous Arduino hobby board.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-medium\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"280\" src=\"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_1691-scaled-e1580580577952-300x280.jpeg\" alt=\"\" class=\"wp-image-844\" srcset=\"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_1691-scaled-e1580580577952-300x280.jpeg 300w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_1691-scaled-e1580580577952-1024x957.jpeg 1024w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_1691-scaled-e1580580577952-768x718.jpeg 768w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_1691-scaled-e1580580577952-1536x1435.jpeg 1536w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_1691-scaled-e1580580577952.jpeg 1849w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><figcaption>Installing the Boot Loader to an ATMEGA328P<\/figcaption><\/figure><\/div>\n\n\n\n<p>I setup a Raspberry Pi workstation and installed the Arduino IDE on Raspbian. Using a simple circuit described <a rel=\"noreferrer noopener\" aria-label=\"here (opens in a new tab)\" href=\"https:\/\/www.arduino.cc\/en\/Tutorial\/ArduinoToBreadboard\" target=\"_blank\">here<\/a>. I was able to install the boot loader and program a generic ATMEGA328P chip using an Arduino Uno board.<\/p>\n\n\n\n<p>The next step is to create a simple Arduino sketch that keeps count on the number of times the microswitch has been pressed. I also enhanced the sketch to track each press as a &#8220;tick&#8221; and have the ability to remember how many ticks make a single revolution of the knitting machine. In this fashion, the counter can be used on different sizes of circular knitting machines. The goal is to count both the number of ticks and the number of revolutions knitted so far.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_1694-1024x768.jpeg\" alt=\"\" class=\"wp-image-845\" srcset=\"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_1694-1024x768.jpeg 1024w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_1694-300x225.jpeg 300w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_1694-768x576.jpeg 768w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_1694-1536x1152.jpeg 1536w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_1694.jpeg 1667w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption>Prototype the circuit<\/figcaption><\/figure>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/AD253-2T.jpg\" alt=\"\" class=\"wp-image-852\" width=\"150\" height=\"150\" srcset=\"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/AD253-2T.jpg 400w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/AD253-2T-300x300.jpg 300w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/AD253-2T-150x150.jpg 150w\" sizes=\"auto, (max-width: 150px) 85vw, 150px\" \/><figcaption>Perfboard example<\/figcaption><\/figure><\/div>\n\n\n\n<p>The circuit is then prototyped on a breadboard with an LCD display (<a rel=\"noreferrer noopener\" aria-label=\"LCD 1602 (opens in a new tab)\" href=\"https:\/\/www.amazon.ca\/SODIAL-Character-Display-Controller-Backlight\/dp\/B00K6Y06TU\/ref=sr_1_3?gclid=Cj0KCQiA4NTxBRDxARIsAHyp6gBtTk2tNToy3Hv1feQWTkwIVEZ6sK0gSo81W7z-TCz0fB6E0yq5hPgaAkaZEALw_wcB&amp;hvadid=229933597134&amp;hvdev=c&amp;hvlocphy=9000804&amp;hvnetw=g&amp;hvqmt=e&amp;hvrand=13186001761673443416&amp;hvtargid=kwd-300685417351&amp;hydadcr=4518_9988540&amp;keywords=lcd+1602&amp;qid=1580581046&amp;sr=8-3\" target=\"_blank\">LCD 1602<\/a>). This was the easy part. The hardest part is to solder everything on a perfboard and then design a suitable 3D printed case.<\/p>\n\n\n\n<p>It took many tries on the 3D printer to get certain tolerance right. Finally, putting everything together we get this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"740\" src=\"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_0052-1024x740.jpeg\" alt=\"\" class=\"wp-image-847\" srcset=\"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_0052-1024x740.jpeg 1024w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_0052-300x217.jpeg 300w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_0052-768x555.jpeg 768w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_0052-1536x1110.jpeg 1536w, https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_0052.jpeg 1992w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption>Working counter integrated with the knitting machine!<\/figcaption><\/figure>\n\n\n\n<p>I have to say that this work was super satisfying. As a bonus, the counter can work with any type of sensors or switches that act as Normally Open (NO) and closes when it detects or closed respectively.<\/p>\n\n\n\n<p>As a learning process and an experiment, I would like to create a simple PCB with <a href=\"https:\/\/jlcpcb.com\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"JCLPCB (opens in a new tab)\">JCLPCB<\/a>. However, I have yet to start on that yet.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This all started when my wife started to use a circular knitting machine that she purchased recently. These machines can be used to quickly knit hats, scarfs, slippers, etc. I have seen her creating yarn goodness within a matter of minutes. The machine certainly decreases the time to produce goods when compared to traditional hand &hellip; <a href=\"https:\/\/blog.lufamily.ca\/kang\/2020\/02\/01\/custom-counter\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Custom Counter&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":843,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[108],"tags":[],"class_list":["post-842","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-electronics-hobby"],"jetpack_featured_media_url":"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2020\/02\/IMG_0054.jpeg","jetpack_shortlink":"https:\/\/wp.me\/p7V6i8-dA","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/posts\/842","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/comments?post=842"}],"version-history":[{"count":5,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/posts\/842\/revisions"}],"predecessor-version":[{"id":854,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/posts\/842\/revisions\/854"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/media\/843"}],"wp:attachment":[{"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/media?parent=842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/categories?post=842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/tags?post=842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}