{"id":237,"date":"2015-07-04T01:43:09","date_gmt":"2015-07-04T06:43:09","guid":{"rendered":"http:\/\/www.edplese.com\/blog\/?p=237"},"modified":"2015-07-04T01:45:38","modified_gmt":"2015-07-04T06:45:38","slug":"electronic-gates-for-wooden-trains","status":"publish","type":"post","link":"https:\/\/www.edplese.com\/blog\/2015\/07\/04\/electronic-gates-for-wooden-trains\/","title":{"rendered":"Electronic Gates for Wooden Trains"},"content":{"rendered":"<p><a href=\"http:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/screenshot.png\"><br \/>\n<\/a>This morning I built the controller and software for the electronic gate system I&#8217;ve been working on for my sons&#8217; wooden trains. \u00a0This\u00a0brought interactive control to raising and lowering the gates through a web app. \u00a0The result: \u00a0it was a hit with my kids and they enjoyed it the rest of the day!<\/p>\n<p><a href=\"http:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/screenshot.png\"><img loading=\"lazy\" class=\"aligncenter wp-image-248 size-medium\" src=\"http:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/screenshot-300x186.png\" alt=\"screenshot\" width=\"300\" height=\"186\" srcset=\"https:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/screenshot-300x186.png 300w, https:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/screenshot.png 999w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h2>Gates<\/h2>\n<p>The gates themselves are 3D printed gate housings with an <a href=\"http:\/\/amzn.to\/1RXmZUv\" target=\"_blank\">SG90 9g RC servo<\/a> that supports and opens the gate. \u00a0I designed these in <a href=\"http:\/\/www.openscad.org\/\" target=\"_blank\">OpenSCAD<\/a> and printed them out on a <a href=\"http:\/\/amzn.to\/1GWkmMH\" target=\"_blank\">Da Vinci 1.0<\/a> 3D printer. \u00a0After printing the only assembly required was two screws to hold in the servo and the rest pushed together. \u00a0For the gate it is beneficial to leave it as a push-fit so that under abuse from the trains it will simply fall off rather than cause some component to break.<\/p>\n<p><a href=\"http:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_214603.jpg\"><img loading=\"lazy\" class=\" size-medium wp-image-240 aligncenter\" src=\"http:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_214603-300x225.jpg\" alt=\"20150703_214603\" width=\"300\" height=\"225\" srcset=\"https:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_214603-300x225.jpg 300w, https:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_214603-1024x768.jpg 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_215154.jpg\"><img loading=\"lazy\" class=\"aligncenter wp-image-242 size-medium\" src=\"http:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_215154-300x225.jpg\" alt=\"20150703_215154\" width=\"300\" height=\"225\" srcset=\"https:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_215154-300x225.jpg 300w, https:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_215154-1024x768.jpg 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h2>Controller Hardware<\/h2>\n<p>The parts for the controller are:<\/p>\n<ul>\n<li><a href=\"http:\/\/amzn.to\/1LJAjwa\" target=\"_blank\">Raspberry Pi Model B<\/a> &#8211; This is an older model and I&#8217;d recommend either the <a href=\"http:\/\/amzn.to\/1KCMDNS\" target=\"_blank\">Model B+<\/a> or the <a href=\"http:\/\/amzn.to\/1eqQfGi\" target=\"_blank\">Raspberry Pi 2<\/a>\u00a0though the instructions will vary a bit from this page.<\/li>\n<li><a href=\"http:\/\/amzn.to\/1KCMKsG\" target=\"_blank\">Adafruit Servo Hat<\/a> &#8211; This plugs into the Raspberry Pi and allows for control of up to 16 RC servos.<\/li>\n<li><a href=\"http:\/\/amzn.to\/1KCMQ3I\" target=\"_blank\">Edimax EW-7811UN USB WiFi adapter<\/a> &#8211; This is a common USB WiFi adapter for the Raspberry Pi.<\/li>\n<li><a href=\"http:\/\/amzn.to\/1RXo4fa\" target=\"_blank\">3 ft. Servo Extension Cables<\/a> &#8211; The servo cables are quite short and these\u00a0let them reach across the table.<\/li>\n<li><a href=\"http:\/\/amzn.to\/1FZRbr2\" target=\"_blank\">8 GB SD Card<\/a>\u00a0&#8211; An SD Card a few GB in size. \u00a0For a few dollars more you can get one double the size.<\/li>\n<li>2 5V power supplies around 1A. \u00a0I used an old phone charger with a Micro-USB connector for the Raspberry Pi and\u00a0a separate power supply to connect to the Servo Hat.<\/li>\n<\/ul>\n<p>The website for the Servo Hat includes a note: \u00a0&#8220;can be used with the Model A or B if you use a tall 2&#215;13 header instead of the included 2&#215;20&#8221;. \u00a0Another approach to getting this to fit on the Model B is to remove the component video output connector from the Raspberry Pi. \u00a0I clipped it off and connector (the yellow one) and the Servo Hat fit perfectly onto the board. \u00a0I also placed\u00a0some electrical tape over the solder joints on the bottom side of the Servo Hat to prevent it from shorting out on the HDMI connector and capacitor on the Raspberry Pi board.<\/p>\n<p><a href=\"http:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_222854.jpg\"><img loading=\"lazy\" class=\"aligncenter size-medium wp-image-243\" src=\"http:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_222854-300x225.jpg\" alt=\"20150703_222854\" width=\"300\" height=\"225\" srcset=\"https:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_222854-300x225.jpg 300w, https:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_222854-1024x768.jpg 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>When fully assembled it is about the size of a deck of playing cards:<\/p>\n<h2><a href=\"http:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_214702.jpg\"><img loading=\"lazy\" class=\"aligncenter wp-image-241 size-medium\" src=\"http:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_214702-300x225.jpg\" alt=\"20150703_214702\" width=\"300\" height=\"225\" srcset=\"https:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_214702-300x225.jpg 300w, https:\/\/www.edplese.com\/blog\/wp-content\/uploads\/2015\/07\/20150703_214702-1024x768.jpg 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/h2>\n<h2>Base Install<\/h2>\n<p>The high level process for installing and prepping the base system is shown below which assumes some general familiarity with these systems and steps.<\/p>\n<ol>\n<li><a href=\"http:\/\/archlinuxarm.org\/platforms\/armv6\/raspberry-pi\" target=\"_blank\">Install Arch Linux<\/a>.<\/li>\n<li>Connect the Raspberry Pi to a wired Ethernet connection.<\/li>\n<li>Run dhcpcd to acquire an IP address.<\/li>\n<li>Install packages for WiFi setup, I2C which is used to interface with\u00a0the Servo Hat, and Python.\n<pre>pacman -Sy dialog wpa_supplicant i2c-tools python2-pip base-devel python2-flask<\/pre>\n<\/li>\n<li>Run wifi-menu to configure the WiFi.<\/li>\n<li>Edit\u00a0\/etc\/wpa_supplicant\/wpa_supplicant.conf to configure persistent WiFi security settings.<\/li>\n<li>Set the WiFi to be enabled at bootup. \u00a0Use the name provided when running wifi-menu, e.g.\n<pre>netctl enable wlan0-mynet<\/pre>\n<\/li>\n<li>Install the Python I2C libraries:\n<pre>pip2 install smbus-cffi<\/pre>\n<\/li>\n<li>Edit\u00a0\/etc\/modules-load.d\/raspberrypi.conf and add the two lines to enable I2C support:\n<pre>i2c-bcm2708<\/pre>\n<pre>i2c-dev<\/pre>\n<\/li>\n<li>Edit \/boot\/config.txt and uncomment\u00a0device_tree_param=i2c_arm=on<\/li>\n<\/ol>\n<p>At this point SSH should be working over WiFi into the Raspberry Pi.<\/p>\n<h2>Software<\/h2>\n<p>The control software provides the web front end and also the server-side code to control the servos.<\/p>\n<p>The code is up on GitHub at:<\/p>\n<p>https:\/\/github.com\/edplese\/gatecontroller<\/p>\n<p>Once checked out\u00a0and copied\u00a0over to the Raspberry Pi it can be\u00a0run with the following command which will start the server and listen on port 5000:<\/p>\n<pre>python2 main.py<\/pre>\n<p>The intent is that this is utilized through a tablet form factor but it works well also on other formats as well.<\/p>\n<h2>Closing Thoughts<\/h2>\n<p>I had\u00a0also considered the ESP8266 WiFi module for this project in combination with the more generic <a href=\"http:\/\/amzn.to\/1JKlk2P\" target=\"_blank\">Adafruit Servo Driver<\/a>. \u00a0I\u00a0opted for the Raspberry Pi due to the self-contained nature as the ESP8266 approach would have needed a separate system to run the web application.<\/p>\n<p>Given that the Servo Hat can control 16 servos I am curious what other types of servo-controlled features would work well in\u00a0this format.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This morning I built the controller and software for the electronic gate system I&#8217;ve been working on for my sons&#8217; wooden trains. \u00a0This\u00a0brought interactive control to raising and lowering the gates through a web app. \u00a0The result: \u00a0it was a hit with my kids and they enjoyed it the rest of the day! Gates The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/posts\/237"}],"collection":[{"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/comments?post=237"}],"version-history":[{"count":9,"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/posts\/237\/revisions"}],"predecessor-version":[{"id":251,"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/posts\/237\/revisions\/251"}],"wp:attachment":[{"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/media?parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/categories?post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edplese.com\/blog\/wp-json\/wp\/v2\/tags?post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}