{"id":156,"date":"2018-04-04T11:34:57","date_gmt":"2018-04-04T17:34:57","guid":{"rendered":"http:\/\/www.infinitewave.ca\/IWBlog\/?p=156"},"modified":"2018-04-04T11:51:58","modified_gmt":"2018-04-04T17:51:58","slug":"switches-part2-hookup-software-and-testing","status":"publish","type":"post","link":"https:\/\/www.infinitewave.ca\/IWBlog\/2018\/04\/04\/switches-part2-hookup-software-and-testing\/","title":{"rendered":"Switches &#8211; Part2 (Hookup, Software and Testing)"},"content":{"rendered":"<figure id=\"attachment_201\" class=\"thumbnail wp-caption alignnone\" style=\"width: 296px\"><a href=\"http:\/\/www.infinitewave.ca\/IWBlog\/wp-content\/uploads\/2018\/04\/Switches-Hookup.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-201 size-medium\" src=\"http:\/\/www.infinitewave.ca\/IWBlog\/wp-content\/uploads\/2018\/04\/Switches-Hookup-286x300.jpg\" alt=\"\" width=\"286\" height=\"300\" srcset=\"https:\/\/www.infinitewave.ca\/IWBlog\/wp-content\/uploads\/2018\/04\/Switches-Hookup-286x300.jpg 286w, https:\/\/www.infinitewave.ca\/IWBlog\/wp-content\/uploads\/2018\/04\/Switches-Hookup-768x806.jpg 768w, https:\/\/www.infinitewave.ca\/IWBlog\/wp-content\/uploads\/2018\/04\/Switches-Hookup-976x1024.jpg 976w, https:\/\/www.infinitewave.ca\/IWBlog\/wp-content\/uploads\/2018\/04\/Switches-Hookup.jpg 1464w\" sizes=\"auto, (max-width: 286px) 100vw, 286px\" \/><\/a><figcaption class=\"caption wp-caption-text\">Arduino and Relay Module Hookup<\/figcaption><\/figure>\n<p>This morning I hooked the whole thing up to the MTR-12, wrote the software, and did some testing.<\/p>\n<p><strong>Software:<\/strong><\/p>\n<p>For the test software, I added a couple of routines to the lamps program. First, I added the <em>processCommands()<\/em> routine to accept commands through the serial(USB) port. I wanted to be able to send it a switch number, and have the unit turn that relay on for a brief period of time. As brief as possible. It also has to tell me that the switch has been turned on, so I know what is going on. This routine is only for testing the functionality. I also added the <em>setSwitches()<\/em> routine to turn the switches on (and off.)\u00a0 This routine also let&#8217;s me know when a switch has been turned off.<\/p>\n<p>I have made an array of integers called switches[] and set them all to be zero. If the processCommands() routine receives a number, it changes the appropriate switches[] element to be 500. Every time the Arduino goes through a loop, it calls the setSwitches() routine and, if any of the switches are not zero, it pulls the appropriate relay module pin LOW, thereby activating the relay, and the switches[] element is decremented. Once the switches() element reaches zero, the appropriate pin is pulled HIGH again. This will allow me to see how long the switch needs to stay on in order to trigger the action. 500 loops should be a good starting point.<\/p>\n<p>Here are the new <em>setup()<\/em> and <em>loop()<\/em> functions:<\/p>\n<p><em>void setup() {<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(stopLampPin, INPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(recordLampPin, INPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(playLampPin, INPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(ffwdLampPin, INPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(rewLampPin, INPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(searchZLampPin, INPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(searchLampPin, INPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(cueLampPin, INPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(shuttleLampPin, INPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(autoRewLampPin, INPUT);<\/em><\/p>\n<p><em>\u00a0 \u00a0 pinMode(recSwPin, OUTPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(playSwPin, OUTPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(stopSwPin, OUTPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(rewSwPin, OUTPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(ffwdSwPin, OUTPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(cueSwPin, OUTPUT);<\/em><br \/>\n<em>\u00a0 \u00a0 pinMode(searchZSwPin, OUTPUT);<\/em><\/p>\n<p><em>\u00a0 \u00a0 Serial.begin(115200); <\/em><br \/>\n<em>\u00a0 \u00a0 sendLamps();<\/em><br \/>\n<em>}<\/em><\/p>\n<p><em>void loop() {<\/em><br \/>\n<em>\u00a0 \u00a0 setSwitches();<\/em><br \/>\n<em>\u00a0 \u00a0 getLamps();<\/em><br \/>\n<em>\u00a0 \u00a0 if (Serial.available()&gt;0){processCommands();}<\/em><br \/>\n<em>}<\/em><\/p>\n<p><strong>Testing:<\/strong><\/p>\n<p><iframe loading=\"lazy\" title=\"MTR-12 Auto-locator Project - Switches Testing\" width=\"648\" height=\"365\" src=\"https:\/\/www.youtube.com\/embed\/HpO9NQZSHqw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>Works great. The video tests all of the switches, except the CUE switch, as that one needs to be held down for the function to be apparent, and I haven&#8217;t written a routine for that. This is just proof of concept, remember. I did test that switch, and it does fire, so all is well.<\/p>\n<p><strong>Conclusions:<\/strong><\/p>\n<p>Well, the first thing you may notice is, when I hit switch 7 (search zero,) the damn lamp still doesn&#8217;t come on. Not sure if maybe our machine has a problem in this regard, or if it will fire when I trigger it properly from the fake keypad routine that will be written later on. This was a bit of a shock for me, as I fully expected it to send a searchZ lamp on message.<\/p>\n<p>After I shot this, I fooled around reducing the time that the switches stayed on. When I went down to 75 loops, the MTR-12 stopped responding to the commands, so I increased it to 100 and everything works well. 100 loops on the Arduino is a really short period of time. As I add more functionality to the loop() routine, it will extend the time it takes for each loop to execute, so I should be able to pull that number down in the future versions.<\/p>\n<p>With the lamps and switches working, I will now move on to the more tricky stuff, starting with the time displays. It may take a few days to make progress on this. Stay tuned&#8230;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This morning I hooked the whole thing up to the MTR-12, wrote the software, and did some testing. Software: For the test software, I added a couple of routines to the lamps program. First, I added the processCommands() routine to accept commands through the serial(USB) port. I wanted to be able to send it a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-156","post","type-post","status-publish","format-standard","hentry","category-mtr"],"_links":{"self":[{"href":"https:\/\/www.infinitewave.ca\/IWBlog\/wp-json\/wp\/v2\/posts\/156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infinitewave.ca\/IWBlog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infinitewave.ca\/IWBlog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infinitewave.ca\/IWBlog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infinitewave.ca\/IWBlog\/wp-json\/wp\/v2\/comments?post=156"}],"version-history":[{"count":13,"href":"https:\/\/www.infinitewave.ca\/IWBlog\/wp-json\/wp\/v2\/posts\/156\/revisions"}],"predecessor-version":[{"id":212,"href":"https:\/\/www.infinitewave.ca\/IWBlog\/wp-json\/wp\/v2\/posts\/156\/revisions\/212"}],"wp:attachment":[{"href":"https:\/\/www.infinitewave.ca\/IWBlog\/wp-json\/wp\/v2\/media?parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infinitewave.ca\/IWBlog\/wp-json\/wp\/v2\/categories?post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infinitewave.ca\/IWBlog\/wp-json\/wp\/v2\/tags?post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}