{"id":176,"date":"2013-02-18T15:21:22","date_gmt":"2013-02-18T22:21:22","guid":{"rendered":"http:\/\/www.meanboyfriend.com\/overdue\/?p=176"},"modified":"2013-02-18T16:20:49","modified_gmt":"2013-02-18T23:20:49","slug":"sound-the-octo-alert","status":"publish","type":"post","link":"http:\/\/www.meanboyfriend.com\/overdue\/2013\/02\/sound-the-octo-alert\/","title":{"rendered":"Sound the Octo-alert!"},"content":{"rendered":"<p>Both our children are currently big <a href=\"http:\/\/www.bbc.co.uk\/cbeebies\/octonauts\/\">Octonauts<\/a>\u00a0fans &#8211; if you haven&#8217;t come across the Octonauts, they are a team of underwater explorers who featured in\u00a0<a href=\"http:\/\/www.octonauts.com\/book.html\">a series of books<\/a>\u00a0by a Canadian duo jointly known as <a href=\"http:\/\/www.octonauts.com\/book.html\">Meomi<\/a>. The books have been made into an incredibly popular TV cartoon shown in the UK on the <a href=\"http:\/\/www.bbc.co.uk\/cbeebies\/\">CBeebies channel<\/a> (the BBC channel aimed at younger children).<\/p>\n<p style=\"text-align: center;\">\u00a0<a href=\"http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/IMG_0001.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-177 aligncenter\" alt=\"Octoalert illustration\" src=\"http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/IMG_0001-1024x682.jpg\" width=\"567\" height=\"377\" srcset=\"http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/IMG_0001-1024x682.jpg 1024w, http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/IMG_0001-300x200.jpg 300w, http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/IMG_0001-450x300.jpg 450w\" sizes=\"auto, (max-width: 567px) 100vw, 567px\" \/><\/a><\/p>\n<p>Whenever there is an emergency, Captain Barnacle will order &#8220;Sound the Octo-alert!&#8221; &#8211; the big button with the distinctive Octopus logo will be pressed, and alarms sounds, and the Octonauts report for duty. As I said, both our children are big fans, and Freya does a mean Octo-alert imitation, so when I was looking for a new Arduino project to do with Bryn, I thought building a working Octo-alert would be great fun.<\/p>\n<p>While you can get an extension (called a shield) for an Arduino to record and play sound (e.g.\u00a0<a href=\"http:\/\/www.ladyada.net\/make\/waveshield\/\">http:\/\/www.ladyada.net\/make\/waveshield\/<\/a>) I hadn&#8217;t got one of these, and I thought a simpler (and in some ways more satisfying) approach would be to have the Arduino joined up to the computer and have a button on the Arduino trigger a sound\/video file on the computer. A quick search found the <a href=\"http:\/\/octoalert.com\">Octoalert website<\/a>\u00a0&#8211; with a clickable Octo-alert image which then plays an mp3 of the Octo-alert sound. Given this was already there and worked, my idea morphed into triggering the alert from this website by simulating a &#8216;click&#8217; on the image.<\/p>\n<p>However, before we got to this point we needed to build an appropriate Arduino circuit and craft a button and console. The Arduino circuit is a very simple one &#8211; just a single button wired up to an LED and of course a pin on the Arduino. Once I&#8217;d put the circuit diagram on, Bryn was able to get going on the wiring. Some of the components are still a bit fiddly for Bryn to put into the breadboard by himself, but for the wires he can follow the diagram and put the wires in himself. I helped with the bits he couldn&#8217;t manage, and generally supervised him &#8211; but he could do a lot of this himself.<\/p>\n<p>To create the button we cut in half a small plastic ball, Damyanti drew the logo, and Bryn set to work glueing on orange tissue paper<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/octoalert1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-198 aligncenter\" alt=\"octoalert1\" src=\"http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/octoalert1-1024x493.jpg\" width=\"567\" height=\"272\" srcset=\"http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/octoalert1-1024x493.jpg 1024w, http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/octoalert1-300x144.jpg 300w, http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/octoalert1-500x241.jpg 500w, http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/octoalert1.jpg 1634w\" sizes=\"auto, (max-width: 567px) 100vw, 567px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: left;\">A simple &#8216;button press&#8217; program for the Arduino is available from\u00a0http:\/\/www.oomlout.com\/oom.php\/products\/ardx\/circ-07 and I adapted this slightly so that the LED flashed several times on a single button press, and so the button also controlled the output to the serial port &#8211; which allows the Arduino to send data back to the computer it is joined to. The Arduino code looked like this:<\/p>\n<pre style=\"text-align: left;\">\/\/ set pin numbers:\r\nconst int buttonPin = 3;     \/\/ the number of the pushbutton pin\r\nconst int ledPin =  9;      \/\/ the number of the LED pin\r\n\r\n\/\/ variables will change:\r\nint buttonState = 0;         \/\/ variable for reading the pushbutton status\r\n\r\nvoid setup() {\r\n  \/\/ initialize the LED pin as an output:\r\n  pinMode(ledPin, OUTPUT);      \r\n  \/\/ initialize the pushbutton pin as an input:\r\n  pinMode(buttonPin, INPUT);\r\n  \/\/ initialize serial port\r\n  Serial.begin(9600);  \r\n}\r\n\r\nint interval_time = 500;\r\n\r\nvoid loop(){\r\n  \/\/ read the state of the pushbutton value:\r\n  buttonState = digitalRead(buttonPin);\r\n\r\n  \/\/ check if the pushbutton is pressed.\r\n  \/\/ if it is, the buttonState is HIGH:\r\n  if (buttonState == HIGH) {     \r\n    \/\/ LED off:    \r\n    digitalWrite(ledPin, LOW);\r\n    Serial.println(\"0\");\r\n    delay(interval_time);\r\n  } else {\r\n    \/\/ turn LED on:\r\n    Serial.println(\"1\");\r\n    for (int i=0;i &lt; 10;i++) { \r\n      digitalWrite(ledPin, HIGH); \r\n      delay(500);\r\n      digitalWrite(ledPin, LOW);\r\n      delay(500);\r\n    }\r\n    delay(interval_time);\r\n  }\r\n}<\/pre>\n<p style=\"text-align: left;\">On the computer side I needed a mechanism to read the output on the serial port &#8211; I found a hint on how to do this here\u00a0http:\/\/playground.arduino.cc\/Interfacing\/Ruby. I also needed a way of accessing the\u00a0<a href=\"http:\/\/octoalert.com\">Octoalert website<\/a>\u00a0&#8211; I knew there was a Ruby Gem to control a browser called Watir, so I got this installed, and after a few false starts (the task was complicated by the fact that clicking the button on the website actually runs some javascript) I got some code working that could read the input from the Arduino and trigger the necessary javascript on the website:<\/p>\n<pre style=\"text-align: left;\">#!\/usr\/bin\/ruby\r\nrequire 'rubygems'\t\r\nrequire 'watir-webdriver'\r\nrequire 'serialport'\r\n\r\n#params for serial port  \r\n port_str = \"\/dev\/tty.usbmodem1411\"\r\n baud_rate = 9600  \r\n data_bits = 8  \r\n stop_bits = 1  \r\n parity = SerialPort::NONE  \r\n\r\n sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity) \r\n browser = Watir::Browser.new\r\n\r\n #just read forever  \r\n while true do\r\n   while (i = sp.gets) do\r\n   \tputs i\r\n    if i.to_i &gt; 0\r\n    \tbrowser.goto \"http:\/\/octoalert.com\"\r\n\t\tbrowser.link(:id,\"playLink\").fire_event \"onclick\"\r\n\t\tsleep(7)\r\n\t\tbrowser.goto \"http:\/\/brynpatelstephens.com\"\r\n   \telse\r\n\t\tputs \"No Octoalert\"\r\n\tend\r\n   end \r\n end<\/pre>\n<p style=\"text-align: left;\">With this code running on the computer, and the Arduino program loaded to the board we had a working button &#8211; we now needed to put the whole thing together.<\/p>\n<p style=\"text-align: left;\">A bit of improvisation with some cardboard and we mounted the Octo-alert button in such a way it could sit over the Arduino and pushing down on it pushed the actual button on the Arduino. I cut a hole in a cardboard box for the button to be mounted in, and Bryn decorated it in the style of the Octonauts instrument panel.<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/octoalert2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-199 aligncenter\" alt=\"octoalert2\" src=\"http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/octoalert2-496x1024.jpg\" width=\"298\" height=\"614\" srcset=\"http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/octoalert2-496x1024.jpg 496w, http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/octoalert2-145x300.jpg 145w, http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/octoalert2.jpg 561w\" sizes=\"auto, (max-width: 298px) 100vw, 298px\" \/><\/a><\/p>\n<p style=\"text-align: left;\">This was a nice project, in that it mixed some nice crafting (glueing the tissue paper, making the control panel) with a very simple circuit &#8211; all of which Bryn could either do by himself, or with a small amount of help. The programming was slightly more tricky, and I just got on this with while Bryn did other stuff &#8211; but I explained a bit about how the Arduino was able to &#8216;talk&#8217; to the computer which I think he got. He also was quite concerned that by using the sound\/graphic from the website that we were &#8216;stealing&#8217; another&#8217;s work &#8211; which meant an opportunity to talk about the web and how it worked &#8211; although I&#8217;m not entirely sure he understood my explanation of using the website versus copying the files &#8211; and to be honest I&#8217;m not sure I quite understand it either &#8211; after all in both cases you end up with a copy of the file on your computer!<\/p>\n<p style=\"text-align: left;\">And it wasn&#8217;t just fun for me and Bryn &#8211; Freya got to join in too as you can see in this video &#8211; yes, it&#8217;s time to sound the Octo-alert \ud83d\ude42<\/p>\n\t<video id=\"wp_mep_1\" src=\"http:\/\/www.meanboyfriend.com\/overdue\/wp-content\/uploads\/2013\/02\/octoalert.m4v\"  width=\"480\" height=\"270\"  controls=\"controls\" preload=\"none\"  >\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t<\/video>\r\n<script type=\"text\/javascript\">\r\njQuery(document).ready(function($) {\r\n\t$('#wp_mep_1').mediaelementplayer({\r\n\t\tm:1\r\n\t\t\r\n\t\t,features: ['playpause','current','progress','duration','volume','tracks','fullscreen']\r\n\t\t\r\n\t});\r\n});\r\n<\/script>\r\n\n","protected":false},"excerpt":{"rendered":"<p>Both our children are currently big Octonauts\u00a0fans &#8211; if you haven&#8217;t come across the Octonauts, they are a team of underwater explorers who featured in\u00a0a series of books\u00a0by a Canadian duo jointly known as Meomi. The books have been made into an incredibly popular TV cartoon shown in the UK on the CBeebies channel (the&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[7,8,9,11,10],"class_list":["post-176","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-arduino","tag-coding","tag-codingforkids","tag-octoalert","tag-octonauts"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.meanboyfriend.com\/overdue\/wp-json\/wp\/v2\/posts\/176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.meanboyfriend.com\/overdue\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.meanboyfriend.com\/overdue\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.meanboyfriend.com\/overdue\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.meanboyfriend.com\/overdue\/wp-json\/wp\/v2\/comments?post=176"}],"version-history":[{"count":17,"href":"http:\/\/www.meanboyfriend.com\/overdue\/wp-json\/wp\/v2\/posts\/176\/revisions"}],"predecessor-version":[{"id":204,"href":"http:\/\/www.meanboyfriend.com\/overdue\/wp-json\/wp\/v2\/posts\/176\/revisions\/204"}],"wp:attachment":[{"href":"http:\/\/www.meanboyfriend.com\/overdue\/wp-json\/wp\/v2\/media?parent=176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.meanboyfriend.com\/overdue\/wp-json\/wp\/v2\/categories?post=176"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.meanboyfriend.com\/overdue\/wp-json\/wp\/v2\/tags?post=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}