{"id":6415,"date":"2022-11-20T16:43:02","date_gmt":"2022-11-20T15:43:02","guid":{"rendered":"https:\/\/dronesonen.usn.no\/?p=6415"},"modified":"2022-11-29T08:37:07","modified_gmt":"2022-11-29T07:37:07","slug":"connect-4-week-13-14-11-20-11","status":"publish","type":"post","link":"https:\/\/dronesonen.usn.no\/?p=6415","title":{"rendered":"Connect 4 &#8211; Week 13 (14.11 &#8211; 20.11)"},"content":{"rendered":"\n<p>Because the deadline is getting closer and closer, this week&#8217;s report is written in a more bullet-point style:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>We got a MCP3008 adc converter from Zoran. We used following tutorial to get it working https:\/\/medium.com\/nerd-for-tech\/how-to-add-light-and-temperature-sensors-to-raspberry-pi-a1e0c7d6d37f<br>It was tricky getting the right python packages, as the raspi wasn&#8217;t connected with internet and we needed to install the packages offline with the package file. That lead to some dependencies conflict but after a &#8220;short time&#8221; (1 or 2 hours tbh) we got all packages installed. Wiring 3 photoresistors for testing, we got good results. The MCP3008 is a 8 bit adc, that means we get values from 0 to 128. The values in the python program are from 0 to 128000 (the last 3 digits of those values have just no meaning it&#8217;s related in how the adc communicates the signals over the spi bus to the raspi). With no coin inside and with red light we got a value about 63000. With a coin inside it dropped down to 55000. That was a huge success because this is a change we can always reliable and safe detect. We directly wrote the software function for the coin detection, it returns the colum where a coin is detected and gives it to our game function.. The threshold for detection is set to 57000.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>def get_triggered_resistor(monitored_channels, triggered_value_threshold = 57000):\n    if len(monitored_channels) == 0:\n        if DEBUG:\n            print(\"no monitored channels, returning error value -1\")\n        return -1\n    \n    while True:\n        # getting new values from adc\n        value0 = config.chan0.value\n        value1 = config.chan1.value\n        value2 = config.chan2.value\n        value3 = config.chan3.value\n        value4 = config.chan4.value\n        value5 = config.chan5.value\n        value6 = config.chan6.value\n    \n        if 0 in monitored_channels and value0 &lt; triggered_value_threshold:\n            if DEBUG:\n                print(\"chan0 change detected with value \" + str(value0))\n            return 0\n        elif 1 in monitored_channels and value1 &lt; triggered_value_threshold:\n            if DEBUG:\n                print(\"chan1 change detected with value \" + str(value1))\n            return 1\n        elif 2 in monitored_channels and value2 &lt; triggered_value_threshold:\n            if DEBUG:\n                print(\"chan2 change detected with value \" + str(value2))\n            return 2\n        elif 3 in monitored_channels and value3 &lt; triggered_value_threshold:\n            if DEBUG:\n                print(\"chan3 change detected with value \" + str(value3))\n            return 3        \n        elif 4 in monitored_channels and value4 &lt; triggered_value_threshold:\n            if DEBUG:\n                print(\"chan4 change detected with value \" + str(value4))\n            return 4\n        elif 5 in monitored_channels and value5 &lt; triggered_value_threshold:\n            if DEBUG:\n                print(\"chan5 change detected with value \" + str(value5))\n            return 5\n        elif 6 in monitored_channels and value6 &lt; triggered_value_threshold:\n            if DEBUG:\n                print(\"chan6 change detected with value \" + str(value6))\n            return 6            \n\n    print(\"if this message is shown, something went catastrophic wrong\")\n    return -1<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>We screwed the electrical components on the base plate which is hidden in the housing. Therefore we made right sized and aligned holes in the wood to use screws and nuts for fixing the raspi, the motordriver and the dc converter.<\/li><li>With mounted rasperry pi on the base plate, there is no more space for connecting a lan cable. Solution: Using the oboard wifi chip and setting up a wifi hotspot. With that we can connect our laptop to it and still use ssh and control the rasperry pi and our programs. We used following tutorial for setting up the hotspot: https:\/\/learn.sparkfun.com\/tutorials\/setting-up-a-raspberry-pi-3-as-an-access-point\/all<\/li><li>We finally also powered the raspi over the dc converter with the now new soldered 90\u00b0 microusb cable and found a new big problem. The dc converter only provides 4.7v and therefore the Rasperry pi doesn&#8217;t boot and goes into a bootloop. We asked Zoran if we can get a stronger one, we hope we will get it next week where all should be put together and be working..<\/li><li>Richard provided us a new big wooden plate, where we will mount the whole game on it next week.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/IMG-20221116-WA0003-1-1024x576.jpg\" alt=\"\" class=\"wp-image-6552\" width=\"512\" height=\"288\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/IMG-20221116-WA0003-1-1024x576.jpg 1024w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/IMG-20221116-WA0003-1-300x169.jpg 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/IMG-20221116-WA0003-1-768x432.jpg 768w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/IMG-20221116-WA0003-1-1536x864.jpg 1536w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/IMG-20221116-WA0003-1.jpg 1920w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><figcaption>you see the new wood plate hidden under all our stuff&#8230;<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>We made a design for the plate where the control elements get mounted on.  That means in detail: the lcd display, the start\/stop button and the difficulty button. Also we soldered cables to the buttons that we can connect them next week easily to our breadboard again. Also there is now a backplate behind the buttons glued that you cannot push the buttons into the housing.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"565\" height=\"560\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/WhatsApp-Image-2022-11-20-at-19.13.19.jpeg\" alt=\"\" class=\"wp-image-6555\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/WhatsApp-Image-2022-11-20-at-19.13.19.jpeg 565w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/WhatsApp-Image-2022-11-20-at-19.13.19-300x297.jpeg 300w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/WhatsApp-Image-2022-11-20-at-19.13.19-150x150.jpeg 150w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/><figcaption>the control elements<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\" id=\"block-f1d3b7d4-65aa-4b3f-a530-de51a0dcbddb\"><li>We made a mechanism so that the coins stay in the board and fall out only when you slide it sideways at the game end.<\/li><li>We made some more feets so that the whole machine gets 18 mm higher, that the coin dispenser is higher than the gameboard.<\/li><li>We made the mechanism that pushes the coin into the board. A video says more than 1000 words:<\/li><\/ul>\n\n\n\n<div style=\"width: 414px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-6415-1\" width=\"414\" height=\"360\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"\/wp-content\/uploads\/2022\/11\/WhatsApp-Video-2022-11-20-at-19.22.59.mp4?_=1\" \/><a href=\"\/wp-content\/uploads\/2022\/11\/WhatsApp-Video-2022-11-20-at-19.22.59.mp4\">\/wp-content\/uploads\/2022\/11\/WhatsApp-Video-2022-11-20-at-19.22.59.mp4<\/a><\/video><\/div>\n\n\n\n<p>One problem here is that sometimes the coins don&#8217;t fall down by there own in the dispenser. So we added a 9v block battery on top of the coins for weight. Now 95% of the coins are falling down and gets dropped out correctly.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/WhatsApp-Image-2022-11-20-at-19.19.23-768x1024.jpeg\" alt=\"\" class=\"wp-image-6558\" width=\"384\" height=\"512\" srcset=\"https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/WhatsApp-Image-2022-11-20-at-19.19.23-768x1024.jpeg 768w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/WhatsApp-Image-2022-11-20-at-19.19.23-225x300.jpeg 225w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/WhatsApp-Image-2022-11-20-at-19.19.23-1152x1536.jpeg 1152w, https:\/\/dronesonen.usn.no\/wp-content\/uploads\/2022\/11\/WhatsApp-Image-2022-11-20-at-19.19.23.jpeg 1200w\" sizes=\"auto, (max-width: 384px) 100vw, 384px\" \/><figcaption>Also our cornflakes box helpes us again. It catched the dropped coins \ud83d\ude09<\/figcaption><\/figure>\n\n\n\n<p>We also directly implemented the servo motor routine of the coin dropper in our game code as a seperate function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def push_coin():\n    # config.servo.value = -1 # move servo to init position\n    # sleep(1)\n\n    for pos in range(-10, 20):\n        config.servo.value = 0.1 * pos\n        if DEBUG:\n            print(\"Move servo to position \" + str(pos))\n        sleep(0.1)      \n    sleep(0.5)\n    config.servo.value = -1 # move servo to init position\n    config.servo.deteach() # or value to None<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Because the deadline is getting closer and closer, this week&#8217;s report is written in a more bullet-point style: We got a MCP3008 adc converter from Zoran. We used following tutorial to get it working https:\/\/medium.com\/nerd-for-tech\/how-to-add-light-and-temperature-sensors-to-raspberry-pi-a1e0c7d6d37fIt was tricky getting the right python packages, as the raspi wasn&#8217;t connected with internet and we needed to install the [&hellip;]<\/p>\n","protected":false},"author":90,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[98,93,1],"tags":[85],"class_list":["post-6415","post","type-post","status-publish","format-standard","hentry","category-connect-4","category-smart-systems-2022","category-uncategorized","tag-connect-4"],"_links":{"self":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/6415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/users\/90"}],"replies":[{"embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6415"}],"version-history":[{"count":19,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/6415\/revisions"}],"predecessor-version":[{"id":6566,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=\/wp\/v2\/posts\/6415\/revisions\/6566"}],"wp:attachment":[{"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dronesonen.usn.no\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}