{"id":2549,"date":"2013-01-01T09:56:11","date_gmt":"2013-01-01T14:56:11","guid":{"rendered":"http:\/\/www.plastibots.com\/?p=2549"},"modified":"2015-03-14T06:15:24","modified_gmt":"2015-03-14T11:15:24","slug":"remote-cnc-shutdown-using-tablet-foscam-fi8918w-ipcam-arduino","status":"publish","type":"post","link":"https:\/\/www.plastibots.com\/index.php\/2013\/01\/01\/remote-cnc-shutdown-using-tablet-foscam-fi8918w-ipcam-arduino\/","title":{"rendered":"Remote Shutdown using a Foscam FI8918W"},"content":{"rendered":"<p style=\"text-align: left;\">As a parent of 2 children and an obsession with cramming my hobbies in whenever I can, I decided to devise a means to remotely monitor my CNC (a ShapeOko) and also <a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-2557 alignright\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl1-300x210.jpg\" alt=\"CNCControl1\" width=\"300\" height=\"210\" srcset=\"https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl1-300x210.jpg 300w, https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl1.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>provide the ability for me to remotely shut it down if things go arwy during a milling session. \u00a0 I picked up a <a href=\"http:\/\/foscam.us\/\" target=\"_blank\">Foscam<\/a> FI8918W IPCam at a &#8216;car boot&#8217; sale (I love that name) when I was visting in England this past summer. \u00a0For 5 quid nonetheless! \u00a0I don&#8217;t think the folks selling it had any idea what it was worth. \u00a0When asking the woman the standard &#8220;does it work&#8221; question, I knew I was going to get it regardless of my knowing that there was a good chance it would not work. \u00a0Well, my luck prevailed, as the unit worked flawlessly with the exception that the smell of smoke was embedded in the plastic (would hate to see the previous owners lungs!). Yuk. \u00a0 Oh, and I also had to pickup a North American plug adapter &#8211; for all about$2 from DX.<\/p>\n<p style=\"text-align: left;\">My original plan was to pickup up an Arduino Network shield and use the camera to watch the CNC via custom webpage using streaming video and then, with some buttons, call the Arduino to trigger a servo to hit the Esc key on the CNC keyboard (which in turn would trigger Mach3 to shut down the CNC). \u00a0There were a few problems with this. 1) I have to wait for the Network shield to come from China (about a month or so), and I did not want to run a lengthy network cable from my router in the basement into the garage. \u00a0An Arduino WiFi shield was also out of the question as they are costly.<\/p>\n<p style=\"text-align: left;\">Then it hit me.. \u00a0The Foscam has the ability to remotely trigger the IR LEDs to go on or off. \u00a0 \u00a0I managed to trace the signal wire to a wire on the mainboard that goes HI (1.5V) when the IR LEDs are on, and LOW (0v) when off. \u00a0Voila! \u00a0Tapping this signal then bringing it out to an ATTiny85 with a bit of simple code, I could control a servo connected to the keyboard.. \u00a0So, onto the Arduino IDE, and out came the soldering iron. \u00a0A few hours later, here we are.<\/p>\n<p><!--more--><\/p>\n<p>Foscam publishes an <a title=\"Foscam IPCam API\" href=\"http:\/\/www.foscam.es\/descarga\/ipcam_cgi_sdk.pdf\" target=\"_blank\">API <\/a>to it&#8217;s camera interface which allows <a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl0.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-medium wp-image-2556\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl0-300x185.jpg\" alt=\"CNCControl0\" width=\"300\" height=\"185\" srcset=\"https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl0-300x185.jpg 300w, https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl0.jpg 876w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>you to create your own pages and embed the camera stream and other functions in it. I just needed something simple &#8211; a video stream and a big STOP button. There area number of other buttons there to allow me to view various status outputs as well as change some settings. However, the only thing I need to do is stop the CNC (button triggers the call to turn the IR LEDs off) and turn the IR LED&#8217;s back on (small button below the Stop button). As part of the whole process, the IR LEDs need to be triggered back on in order to reset the control unit as this puts the voltage HIGH again. I had Javascript behind the Stop button doing this at first (triggering IR OFF, then IR ON), however, it caused reliability issues on my Andriod tablet (using Opera) and sometimes did not work (something that I could not have for this to work properly since the trigger HAS to work).<\/p>\n<p style=\"text-align: center;\">[ad name=&#8221;GoogleAS728x90ImgOnly&#8221;]<\/p>\n<p>Showing the ATTiny85 circuit and the servo. The circuit is simple, the Tiny watches the output trigger from the camera, when it goes HIGH, it triggers the servo to &#8216;tap&#8217; the Esc key. I also added an LED in there to provide visual feedback. Since the Tiny does not allow you to monitor via Serial, I was also using the LED as a debug tool. During testing, I wanted to make sure there were no phantom taps triggered (as I had this happen earlier). I used the LED to count the number of taps and blink that count.<br \/>\n<a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-2558 aligncenter\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl2-300x169.jpg\" alt=\"CNCControl2\" width=\"300\" height=\"169\" srcset=\"https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl2-300x169.jpg 300w, https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl2.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Showing the modifications to the Foscam IPCam. This is an earlier picture before I was taking power from the camera. Since then, I have power coming directly off the power adapter inputs (bottom right shown with the black wire and red (drawn-in) wire). The IR LED trigger signal is the gray wire connected to pin #3 from the right.<br \/>\n<a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl4.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-2553 aligncenter\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl4-300x169.jpg\" alt=\"CNCControl4\" width=\"300\" height=\"169\" srcset=\"https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl4-300x169.jpg 300w, https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl4.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>This is the servo mounted to the keyboard. &#8230; and of course, the ideal way to build custom mounting solutions &#8211; LEGO Technic. Check the rest of this site out if you are wondering why I use LEGO.<br \/>\n<a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl5.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-2554 aligncenter\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl5-300x169.jpg\" alt=\"CNCControl5\" width=\"300\" height=\"169\" srcset=\"https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl5-300x169.jpg 300w, https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl5.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p style=\"text-align: center;\">[ad name=&#8221;GoogleAS728x90ImgOnly&#8221;]<\/p>\n<p>I wanted the ability to easily remove and install the servo to the keyboard. I used a set of Technic friction pins and glued them in. The servo is mounted to a Technic 15 hole beam so it slides on and off easily, but is also secure enough to stay in place when the servo is triggered.<br \/>\n<a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl6.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-2555 aligncenter\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl6-300x275.jpg\" alt=\"CNCControl6\" width=\"300\" height=\"275\" srcset=\"https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl6-300x275.jpg 300w, https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl6.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Here&#8217;s the ShapeOko &amp; IPCam.<\/p>\n<p><a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl8.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-2582\" src=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl8-300x175.jpg\" alt=\"CNCControl8\" width=\"300\" height=\"175\" srcset=\"https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl8-300x175.jpg 300w, https:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl8.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Here&#8217;s a video below of the system in action during testing. Now, I can roam around the house, be cooking dinner, etc.. while checking on the CNC and trigger a shutdown if needed. The Foscam also has a microphone, so I can also listen for those crazy noises you hear when your CNC skips a step and things go wrong &#8211; you know them, I&#8217;m sure you&#8217;ve heard it too!<br \/>\n(<a href=\"http:\/\/www.youtube.com\/embed\/PZgWuric3Ok\" target=\"_blank\">Link<\/a>)<br \/>\n<a href=\"http:\/\/youtu.be\/PZgWuric3Ok\"><iframe loading=\"lazy\" src=\"http:\/\/www.youtube.com\/embed\/PZgWuric3Ok\" width=\"425\" height=\"350\" frameborder=\"0\"><\/iframe><br \/>\n<\/a><\/p>\n<p>Improvements that could be done:<\/p>\n<ul>\n<li>The IR LEDs have to be triggered back on. Streamline the web interface component to ensure it automatically turns the IR LEDs back on after each Stop call. This could just be a Javascript timing issue. The code works by calling a new window, waiting a short period of time, then closing it. It does this for both the Stop call, and the call to turn the IR LEDs back on. During testing, I had both together in one call and it worked fine on my PC (networked), but did not work on my wireless tablet (it would miss either or both calls). By taking out the call to turn the IR LEDs back on, it reliably turns them off when called.<\/li>\n<li>The camera itself uses a photo resistor to turn the IR LEDs during daytime. This is not good considering that my CNC work area is well lit. Covering it with black tape does the trick. To solve the problem, I could modify the Foscam to not dim the IR LEDs (apparently this setting already exists for other Foscam cameras).<\/li>\n<\/ul>\n<p>Other Thoughts:<\/p>\n<ul>\n<li><span style=\"line-height: 13px;\">This could be used for other projects if you have a similar Foscam camera and want to remotely trigger actions using an Arduino or other microcontroller.<\/span><\/li>\n<\/ul>\n<p>Files \/ Code:<\/p>\n<p><a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControl_WebInterfaceHTML.txt\">CNCControl_WebInterfaceHTML<\/a><\/p>\n<p>Arduino 1.0.3 Code: \u00a0<a href=\"http:\/\/www.plastibots.com\/wordpress\/wp-content\/uploads\/2013\/01\/CNCControlFoscamFI8918W_1_2.zip\">CNCControlFoscamFI8918W_1_2<\/a>\u00a0 (must have Servo8Bit library).<\/p>\n<pre>\r\n\/\/This is written to go onto an ATTiny85. If using an Arduino, change pin references. Also must change back to using the Servo library\r\n\/\/as Servo8Bit wont work.\r\n\r\n\/\/ATTiny85 Pinouts:\r\n\/\/ ________\r\n\/\/ Reset |1 8| VCC\r\n\/\/ Pin 3(analog in 3) |2 7| Pin 2 (analog in 1)\r\n\/\/ Pin 4(analog in 2) |3 6| Pin 1 (PWM)\r\n\/\/ GND |4 5| Pin 0 (PWM)\r\n\/\/ --------\r\n\/\/\r\n\/\/\r\n\r\n#include \"Servo8Bit.h\"\r\nServo8Bit myservo; \/\/create a servo object.\r\n\/\/a maximum of five servo objects can be created\r\nint statusLED = 0; \/\/shows as Pin 0 on ATTiny (pin 5 on board)\r\nint pos = 0; \/\/ variable to store the servo position\r\n\/\/int foscamIRpin = A0; \/\/when IR is on, pin is high 1.5v. Else LOW 0v\r\nint foscamIRpin = 3; \/\/ shows as Pin 3(analog in 3) - labelled pin #3 on ATTiny85 board layout - when IR is on, pin is high 1.5v. Else LOW 0v\r\nint state = 1;\r\nint doneOnce = 0;\r\nint CNCoff = 0;\r\nint blinkCount = 0;\r\nvoid setup()\r\n{\r\n\r\nmyservo.attach(1,544,2200); \/\/shows as Pin 1 on ATTiny (pin 6 on board)\r\n\r\n\/\/Serial.begin (9600);\r\n\/\/Serial.print(\"Started... running...\"); Serial.println();\r\npinMode(foscamIRpin, INPUT);\r\npinMode(statusLED, OUTPUT);\r\n\/\/get the starting state of the IR LEDs\r\n\/\/if (analogRead(foscamIRpin) < 1) { startState = 0;} else {startState = 1;};\r\n\/\/Serial.print(\"StartState: \"); Serial.print(startState);\r\n\/\/Serial.println();\r\n\r\n\/\/send servo to start position\r\nmyservo.write(0);\r\n\r\n}\r\n\r\nvoid loop()\r\n{\r\n\r\n\/\/Stop button clicked - IR goes off - trigger CNC Stop - but only if it hasn't alread been triggered\r\n\/\/startState of 0 means IRs where already off - dont want to trigger keyboard stop\r\n\/\/startState of 1 means IRs are on at start - good this is what we want.\r\nif (analogRead(foscamIRpin) < 1 &#038;&#038; CNCoff == 0)\r\n{\r\n\/\/IR LEDs are off\r\n\r\nhitKey(2);\r\ndigitalWrite(statusLED, HIGH); \/\/ turn the LED on (HIGH is the voltage level)\r\nblinkCount ++;\r\nCNCoff = 1;\r\ndoneOnce = 0;\r\n\/\/Serial.print(\"Stop clicked - IR LEDs off \"); Serial.println();\r\ndelay(500);\r\ndigitalWrite(statusLED, LOW); \/\/ turn the LED of\r\n\r\n}\r\n\/\/this is to catch when the IR LED have been reset (switched back on). It will reset the system for the next round of cutting.\r\n\/\/will look for a way in the web form to have it automatically reset the IR LEDs after a triggered shutdown.\r\nelse if (analogRead(foscamIRpin) > 50 && doneOnce == 0)\r\n{\r\n\/\/IR LEDs are on\r\n\/\/Serial.print(\"Start clicked - IR LEDs on \"); Serial.println();\r\nCNCoff = 0;\r\ndoneOnce = 1;\r\n}\r\n\/\/Serial.print(\"IRVoltage: \"); Serial.print(analogRead(foscamIRpin));\r\n\/\/Serial.print(\" CNCoff: \"); Serial.print(CNCoff);\r\n\/\/Serial.print(\" DoneOnce: \"); Serial.print(doneOnce);\r\n\/\/Serial.println();\r\ndelay(100);\r\n\/\/blink(blinkCount);\r\n}\r\nvoid hitKey(int spd)\r\n{\r\n\/\/CNCoff = 1;\r\n\/\/Serial.print(\"CNC Triggered to shut off. \");\r\n\/\/Serial.println();\r\n\r\nfor(pos = 0; pos < 60; pos += 1) \/\/ goes from 0 degrees to 180 degrees\r\n{ \/\/ in steps of 1 degree\r\nmyservo.write(pos); \/\/ tell servo to go to position in variable 'pos'\r\n\r\n\/\/Serial.println (myservo.read());\r\ndelay(spd); \/\/ waits 15ms for the servo to reach the position\r\n}\r\nfor(pos = 60; pos>=1; pos-=1) \/\/ goes from 180 degrees to 0 degrees\r\n{\r\nmyservo.write(pos); \/\/ tell servo to go to position in variable 'pos'\r\n\/\/Serial.println (myservo.read());\r\ndelay(spd); \/\/ waits 15ms for the servo to reach the position\r\n\r\n}\r\n\r\ndelay(100);\r\n\r\n}\r\n\r\n\/*\r\nvoid blink(int cnt)\r\n{\r\nint i;\r\nif (cnt > 0)\r\n{\r\nfor (i = 0; i<=cnt; i++)\r\n{\r\ndigitalWrite(statusLED, HIGH);\r\ndelay(10);\r\ndigitalWrite(statusLED, LOW);\r\ndelay(100);\r\n}\r\n}\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>As a parent of 2 children and an obsession with cramming my hobbies in whenever I can, I decided to devise a means to remotely monitor my CNC (a ShapeOko) and also provide the ability for me to remotely shut it down if things go arwy during a milling session. \u00a0 I picked up a Foscam FI8918W IPCam at a &#8216;car boot&#8217; sale (I love that name) when I was visting in England this past &hellip; <a href=\"https:\/\/www.plastibots.com\/index.php\/2013\/01\/01\/remote-cnc-shutdown-using-tablet-foscam-fi8918w-ipcam-arduino\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"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":[65,6,57],"tags":[64,68,74],"class_list":["post-2549","post","type-post","status-publish","format-standard","hentry","category-arduino-electronics","category-dyihacks","category-electronics","tag-arduino","tag-attiny85","tag-fi8918w","has_no_thumb"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pK41j-F7","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/posts\/2549","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/comments?post=2549"}],"version-history":[{"count":0,"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/posts\/2549\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/media?parent=2549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/categories?post=2549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.plastibots.com\/index.php\/wp-json\/wp\/v2\/tags?post=2549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}