{"id":7946,"date":"2020-11-05T00:00:57","date_gmt":"2020-11-04T15:00:57","guid":{"rendered":"https:\/\/techclass.wfjydl.com\/?p=7946"},"modified":"2022-03-08T15:22:04","modified_gmt":"2022-03-08T07:22:04","slug":"cmucam5-pixy%e8%a7%86%e8%a7%89%e7%9b%b8%e6%9c%ba%e4%bc%a0%e6%84%9f%e5%99%a8%e7%ae%80%e4%bb%8b","status":"publish","type":"post","link":"https:\/\/techclass.wfjydl.com\/knowledge\/tech-info\/how-tos\/arduino\/an-intro-to-cmucam5-pixy-vision-camera-sensor","title":{"rendered":"CMUcam5 Pixy\u89c6\u89c9\u76f8\u673a\u4f20\u611f\u5668\u7b80\u4ecb"},"content":{"rendered":"<p><script type=\"text\/javascript\" src=\"https:\/\/ssl-cache.stream.ne.jp\/www50\/eqa194obdo\/jmc_pub\/jmc_swf\/player\/t3\/if.js\" charset=\"UTF-8\"><span data-mce-type=\"bookmark\" style=\"display: inline-block; width: 0px; overflow: hidden; line-height: 0;\" class=\"mce_SELRES_start\">\ufeff<\/span><\/script><\/p>\n<div class=\"\u201cthe_content_wrapper\u201d\">\n<p>\u8fd9\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e<a href=\"https:\/\/www.deviceplus.com\/\">DevicePlus.com<\/a>\u82f1\u8bed\u7f51\u7ad9\u7684\u7ffb\u8bd1\u7a3f\u3002<\/p>\n<div id=\"attachment_3563\" class=\"wp-caption alignnone\" style=\"width: 710px;\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3563 size-full\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor.png\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor.png 700w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-300x225.png 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-195x146.png 195w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-50x38.png 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-100x75.png 100w\" alt=\"camera sensor\" width=\"700\" height=\"525\" aria-describedby=\"caption-attachment-3563\" \/><\/p>\n<p id=\"caption-attachment-3563\" class=\"wp-caption-text\">PixyMon \u548c Arduino<\/p>\n<\/div>\n<p>\u8be5\u9879\u76ee\u7684\u76ee\u6807\u662f\u5411\u60a8\u4ecb\u7ecdCMUcam5 Pixy\uff0c\u5e76\u5c55\u793a\u5982\u4f55\u5728\u60a8\u81ea\u5df1DIY\u7684\u9879\u76ee\u4e2d\u5b9e\u73b0\u76f8\u673a\u529f\u80fd\uff0c\u60a8\u4f1a\u53d1\u73b0\u5373\u4f7f\u5bf9\u4e8e\u4e00\u4e2a\u590d\u6742\u7684\u673a\u7535\u7cfb\u7edf\uff08\u6bd4\u5982\u8f6e\u5f0f\u81ea\u4e3b\u673a\u5668\u4eba\uff09\u6765\u8bf4\uff0c\u8fd9\u4e5f\u662f\u975e\u5e38\u7b80\u5355\u6613\u6267\u884c\u7684\u64cd\u4f5c\u3002Pixy\u662f\u4e00\u79cd\u7075\u6d3b\u3001\u7d27\u51d1\u3001\u53ef\u8c03\u8282\u4e14\u6613\u4e8e\u8bbe\u7f6e\u7684\u76f8\u673a\u4f20\u611f\u5668\uff0c\u80fd\u591f\u68c0\u6d4b\u5e76\u4f20\u9012\u67d0\u4e9b\u7c7b\u578b\u5bf9\u8c61\u7684\u4fe1\u606f\u3002\u6211\u4eec\u5c06\u4ecb\u7ecd\u6709\u5173\u76f8\u673a\u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u5e76\u4e86\u89e3\u5728Pixy\u548cArduino\u4e4b\u95f4\u8fdb\u884c\u901a\u4fe1\u7684\u4e00\u822c\u65b9\u6cd5\u3002<\/p>\n<h2>\u786c\u4ef6<\/h2>\n<ul>\n<li>Arduino Uno (\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55 Arduino)<\/li>\n<li>CMUcam5 Pixy \u76f8\u673a<\/li>\n<li>\u4f3a\u670d\u7535\u673a (S06NF)<\/li>\n<li>\u4e00\u5c0f\u5757\u6728\u5934\uff08\u7528\u6765\u5c06\u76f8\u673a\u5b89\u88c5\u5230\u4f3a\u670d\u4e0a, \u6211\u5c06\u53ea\u4f7f\u7528\u87ba\u4e1d\u5b89\u88c5\uff09<\/li>\n<li>\u7ebf\u7f06 \uff08\u7528\u4e8e\u76f8\u673aUSB MINI \u4ee5\u53caUno USB B\uff09<\/li>\n<li>\u7528\u4e8e\u4f3a\u670d\u7684\u5916\u63a55V\u7535\u6e90\uff08\u8b66\u544a\uff01\u5982\u679c\u60a8\u5c06\u4f3a\u670d\u8fde\u63a5\u5230\u60a8\u7684Arduino\u4e0a\uff0c\u5e76\u901a\u8fc7USB\u4f9b\u7535\uff0c\u60a8\u7684 Arduino\u5c06\u4f1a\u88ab\u70e7\u574f\uff09\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>\u8f6f\u4ef6<\/h2>\n<ul>\n<li>Arduino IDE 1.6.9<\/li>\n<li>PixyMon \u8f6f\u4ef6<\/li>\n<li>\u7528\u4e8eArduino\u7684PixyMon\u5e93<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<div id=\"attachment_3564\" class=\"wp-caption alignnone\" style=\"width: 710px;\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3564\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-2.png\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-2.png 700w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-2-300x225.png 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-2-195x146.png 195w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-2-50x37.png 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-2-100x75.png 100w\" alt=\"camera sensor\" width=\"700\" height=\"524\" aria-describedby=\"caption-attachment-3564\" \/><\/p>\n<p id=\"caption-attachment-3564\" class=\"wp-caption-text\">\u56fe1\uff1aCMUcam5 Pixy\u76f8\u673a<\/p>\n<\/div>\n<p class=\"normal\">CMUcam5 Pixy\u662f\u4e00\u6b3e\u5c0f\u578b\u3001\u6613\u4e8e\u64cd\u4f5c\u3001\u6210\u672c\u4f4e\u4e14\u5f00\u6e90\u7684\u76f8\u673a\u3002\u5b83\u62e5\u6709\u72ec\u7acb\u7684\u5904\u7406\u5668\uff0c\u6bcf\u79d2\u53ef\u5bf9\u63a2\u6d4b\u5230\u7684\u4fe1\u606f\u8fdb\u884c50\u6b21\u8f93\u51fa\u3002\u5b83\u8fd8\u53ef\u4ee5\u4e0eArduino\u3001Raspberry Pi\u7b49\u8fde\u63a5\u3002CMUcam5 Pixy\u4f7f\u7528\u975e\u5e38\u5e38\u89c1\u7684\u63a5\u53e3\uff0c\u4f8b\u5982SPI\u300112C\u3001UART\u4ee5\u53caUSB\uff0c\u5e76\u4e14\u5177\u6709\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7a0b\u5e8f\uff0c\u53ef\u8ba9\u60a8\u8fde\u63a5\u5230\u60a8\u7684\u8bbe\u5907\u4e0a\uff0c\u70b9\u51fb<span style=\"color: #1155cc;\">\u6b64\u5904<\/span>\u53ef\u4ee5\u514d\u8d39\u4e0b\u8f7d\u3002<\/p>\n<p>&nbsp;<\/p>\n<p class=\"normal\"><span style=\"font-size: 20.0pt; line-height: 115%;\">\u8bbe\u7f6ePixy<\/span><\/p>\n<p class=\"normal\">\u70b9\u51fb<span style=\"color: #1155cc;\">\u6b64\u5904<\/span>\u4e0b\u8f7d\u8f6f\u4ef6PixyMon\u5e76\u5b89\u88c5\u3002\u5b89\u88c5\u65f6\uff0c\u8bf7\u901a\u8fc7USB\u8fde\u63a5Pixy\uff0c\u7136\u540e\u68c0\u67e5RGB Led\u706f\u662f\u5426\u4eae\u8d77\u3002<\/p>\n<p class=\"normal\">\u6253\u5f00PixyMon\uff0c\u5e76\u786e\u4fddPixy\u662f\u901a\u8fc7USB\u8fdb\u884c\u8fde\u63a5\u7684\u3002\u5982\u679c\u6240\u6709\u8fde\u63a5\u6b63\u786e\uff0c\u5b83\u5c06\u8f93\u51fa\u76f8\u673a\u6240\u201c\u770b\u5230\u201d\u7684\u5185\u5bb9\u3002\u4f8b\u5982\uff0c\u6211\u653e\u7f6e\u4e86\u4e00\u4e2a\u7d2b\u8272\u7684\u76d6\u5b50\u4f5c\u4e3a\u6d4b\u8bd5\u5bf9\u8c61\uff0c\u6765\u68c0\u67e5Pixy\u76f8\u673a\u7684\u8f93\u51fa\u3002<\/p>\n<div id=\"attachment_3565\" class=\"wp-caption alignnone\" style=\"width: 555px;\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3565\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-3.png\" sizes=\"auto, (max-width: 545px) 100vw, 545px\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-3.png 545w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-3-300x289.png 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-3-152x146.png 152w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-3-50x48.png 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-3-78x75.png 78w\" alt=\"camera sensor\" width=\"545\" height=\"525\" aria-describedby=\"caption-attachment-3565\" \/><\/p>\n<p id=\"caption-attachment-3565\" class=\"wp-caption-text\">\u56fe2\uff1aPixy Raw\u8f93\u51fa\u56fe\u50cf<\/p>\n<\/div>\n<p>\u8fdb\u5165\u201cAction\u201d\u5b50\u83dc\u5355\uff0c\u5e76\u70b9\u51fb\u201cSet Signature 1\u201d\uff0c\u89c6\u9891\u5c06\u4f1a\u505c\u6ede\uff0c\u60a8\u53ef\u4ee5\u9009\u62e9\u60f3\u8981\u7528\u76f8\u673a\u68c0\u6d4b\u7684\u989c\u8272\/\u5bf9\u8c61\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3566\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-4.png\" sizes=\"auto, (max-width: 270px) 100vw, 270px\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-4.png 270w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-4-154x300.png 154w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-4-75x146.png 75w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-4-26x50.png 26w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-4-39x75.png 39w\" alt=\"camera sensor\" width=\"270\" height=\"525\" \/><\/p>\n<p class=\"normal\">\u6807\u8bb0\u597d\u989c\u8272\/\u5bf9\u8c61\u540e\uff0c\u89c6\u9891\u5c06\u4f1a\u5f00\u59cb\u64ad\u653e\uff0c\u5e76\u4e14\u76f8\u673a\u4f20\u611f\u5668\u5c06\u4f1a\u5bf9\u989c\u8272\/\u5bf9\u8c61\u8fdb\u884c\u68c0\u6d4b\uff0c\u5982\u56fe3\u6240\u793a\u3002\u5728\u540c\u4e00\u65f6\u95f4\uff0c\u60a8\u6700\u591a\u53ef\u4ee5\u8bbe\u7f6e7\u4e2a\u60f3\u8981\u68c0\u6d4b\u7684\u5bf9\u8c61\/\u989c\u8272\u3002\u5982\u679c\u60a8\u8fdb\u884c\u4e86\u6b63\u786e\u6807\u8bb0\uff0c\u5e76\u4e14\u8bbe\u7f6e\u4e86\u89c6\u91ce\u8303\u56f4\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u5bf9\u591a\u4e2a\u5bf9\u8c61\/\u989c\u8272\u7684\u68c0\u6d4b\u3002<\/p>\n<div id=\"attachment_3567\" class=\"wp-caption alignnone\" style=\"width: 548px;\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3567\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-5.png\" sizes=\"auto, (max-width: 538px) 100vw, 538px\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-5.png 538w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-5-300x293.png 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-5-150x146.png 150w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-5-50x50.png 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-5-77x75.png 77w\" alt=\"camera sensor\" width=\"538\" height=\"525\" aria-describedby=\"caption-attachment-3567\" \/><\/p>\n<p id=\"caption-attachment-3567\" class=\"wp-caption-text\">\u56fe3\uff1aPixy\u68c0\u6d4b\u4e0b\u7684\u89c6\u56fe<\/p>\n<\/div>\n<p>\u5982\u679c\u60f3\u8981\u6e05\u9664\u9884\u8bbe\u6807\u8bb0\uff0c\u60a8\u53ef\u4ee5\u70b9\u51fb<strong>Action -&gt; Clear All Signatures<\/strong>\uff0c\u76f4\u63a5\u6e05\u9664\u6240\u6709\u6807\u8bb0 \uff0c\u6216\u8005\u9009\u62e9<strong>Clear Signature <\/strong>\u6765\u5bf9\u6807\u8bb0\u4e00\u4e00\u6e05\u9664\uff08\u5728\u63a7\u5236\u9875\u9762\u8f93\u5165\u6807\u8bb0\u7f16\u53f7\uff09\u3002<\/p>\n<p>\u70b9\u51fb<strong>Settings -&gt; Signature 1<\/strong>\u8fdb\u884c\u8c03\u6574\uff0c\u60a8\u53ef\u4ee5\u4fee\u6539Pixy\u89c6\u91ce\u5c3a\u5bf8\u7684\u5927\u5c0f\u3002<\/p>\n<h2>\u5176\u4ed6\u8bbe\u7f6e\uff08<strong>File -&gt; Configure<\/strong>\uff09<\/h2>\n<ul>\n<li>\u901a\u8fc7\u66f4\u6539\u76f8\u673a\u4eae\u5ea6\uff0c\u60a8\u53ef\u4ee5\u5728\u9ed1\u6697\u73af\u5883\u4e2d\u8fdb\u884c\u4fe1\u606f\u63a2\u6d4b\u3002<\/li>\n<li>\u5728 <strong>Camera<\/strong> \u9009\u9879\u4e2d\uff0c\u60a8\u53ef\u4ee5\u8c03\u6574\u767d\u5e73\u8861\uff0c\u8fd9\u975e\u5e38\u6709\u7528\u3002<\/li>\n<li>\u4f7f\u7528 <strong>Action -&gt; Default<\/strong> \u7a0b\u5e8f\uff0c\u60a8\u5c06\u53ea\u770b\u5230\u6240\u68c0\u6d4b\u5230\u7684\u989c\u8272\uff0c\u6ca1\u6709\u89c6\u9891\u8f93\u51fa\u3002<\/li>\n<\/ul>\n<p>\u6709\u4e00\u4e2a\u4e13\u7528\u4e8e\u5728\u60a8\u7684Arduino\u4e0a\u4f7f\u7528Pixy\u7684\u81ea\u5b9a\u4e49\u5e93\u3002\u6211\u4f7f\u7528\u7684\u662fArduino Uno\uff0c\u4f46\u662f\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u7248\u672c\u3002\u8fd9\u4e2a\u5e93\u975e\u5e38\u6709\u7528\uff0c\u4e0d\u4ec5\u4e3a\u521d\u5b66\u8005\u63d0\u4f9b\u4e86\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u4e5f\u4e3a\u4e13\u5bb6\u63d0\u4f9b\u4e86\u7edd\u4f73\u7684\u5f00\u53d1\u5e73\u53f0\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u8981\u8bbe\u7f6e\u4e00\u4e2a\u68c0\u6d4b\u5bf9\u8c61\uff0c\u7c7b\u4f3c\u4e8e\u6211\u4eec\u4e4b\u524d\u5728\u8bbe\u7f6e\u76f8\u673a\u65f6\u6240\u8fdb\u884c\u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u70b9\u51fb\u6b64\u5904\u4e0b\u8f7dArduino\u5e93\uff08\u5728\u201c<strong>Arduino libraries and examples<\/strong> \u201d\u6587\u4ef6\u5939\u4e0b\uff09\u3002[https:\/\/www.cmucam.org\/attachments\/download\/1157\/arduino_pixy-0.1.7.zip]\u3002\u8fd9\u5c06\u5b9e\u73b0\u60a8\u7684Arduino\u548cPixy\u76f8\u673a\u4e4b\u95f4\u7684\u901a\u4fe1\u3002\u7136\u540e\uff0c\u5c06\u5176\u6dfb\u52a0\u5230Arduino IDE\uff08<strong>Sketch -&gt; Include Library -&gt; Add .zip Library<\/strong>\uff09\u3002<\/p>\n<p>\u70b9\u51fb<strong>Example-&gt;Pixy-&gt;hello_world<\/strong>\uff0c\u6253\u5f00\u4e00\u4e2a\u540d\u79f0\u4e3ahello_world\u7684\u7b80\u5355\u793a\u4f8b\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3568\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-6.png\" sizes=\"auto, (max-width: 681px) 100vw, 681px\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-6.png 681w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-6-300x231.png 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-6-189x146.png 189w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-6-50x39.png 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-6-97x75.png 97w\" alt=\"camera sensor\" width=\"681\" height=\"525\" \/><\/p>\n<p>\u5c06\u5176\u4e0a\u4f20\u5230\u60a8\u7684\u5f00\u53d1\u677f\u4e0a\uff0c\u5e76\u6253\u5f00\u7ec8\u7aef\uff08<strong>Tools -&gt; Serial Monitor<\/strong>\uff09\u3002<\/p>\n<p>\u6b64\u65f6\uff0c\u60a8\u5c06\u770b\u5230\u4e00\u6761\u4fe1\u606f\uff0c\u663e\u793a\u201cStarting\u2026 \u201d\uff0c\u7136\u540e\u5c06\u663e\u793a\u6709\u5173\u68c0\u6d4b\u5230\u7684\u5bf9\u8c61\u7684\u4fe1\u606f\u3002<\/p>\n<p>hello_world\u4ee3\u7801\u91ca\u4e49<\/p>\n<p>\u5728 <strong>setup()<\/strong> \u51fd\u6570\u4e2d\uff0c\u5bf9\u7f16\u53f7\u548cpixy\u8fdb\u884c\u521d\u59cb\u5316\u548c\u76f8\u5173\u8bbe\u7f6e\u3002<\/p>\n<p><strong>loop()<\/strong> \u51fd\u6570\u5305\u542b\u51e0\u4e2a\u53d8\u91cf\uff0c\u8fd9\u4e9b\u53d8\u91cf\u7528\u4e8e\u6253\u5370\u4ee5\u53ca\u4ecepixy\u83b7\u53d6\u6a21\u5757\u3002\u4f7f\u7528<strong> pixy.getBlocks()<\/strong> \u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u83b7\u53d6\u68c0\u6d4b\u5230\u7684\u5bf9\u8c61\u3002<strong>if (i%50==0)<\/strong> \u4ee3\u7801\u53ef\u4ee5\u7528\u6765\u8bbe\u7f6e\u6211\u4eec\u60f3\u8981\u83b7\u53d6\u4fe1\u606f\u7684FPS\u3002\u5982\u679c\u6211\u4eec\u60f3\u8981\u6bcf\u79d2\u949f\u83b7\u53d6\u4e00\u6761\u4fe1\u606f\uff0c\u5c31\u8981\u5199 <strong>%1 <\/strong> \u800c\u4e0d\u662f <strong>%50<\/strong>\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>\/*\r\n *  explaining the (((pixy.blocks[j].x)\/2)+10)-60\r\n *  with pixy.blocks[j].x we get the x position of the object detected\r\n *  we divide it because the max value it can read is 320\r\n *  I did the + 10 for small adjustments \r\n *  the -60 is used for rotating away from the object\r\n *\/\r\n \r\n#include &lt;Servo.h&gt;\r\n#include &lt;Pixy.h&gt;\r\n \r\nServo myservo;  \/\/ create servo object to control a servo\r\nPixy pixy;  \t\/\/ create pixy object for controlling the pixy camera\r\n \r\n\/\/ function for testing the servo\r\nvoid test_camera(){ \r\n  myservo.write(0);\r\n  delay(1000);\r\n  myservo.write(90);\r\n  delay(1000);\r\n  myservo.write(180);\r\n  delay(1000);\r\n  myservo.write(90); \/\/ get the camera centered\r\n}\r\n \r\nvoid setup() {\r\n  \/\/Serial.begin(9600); \/\/ initialize serial\r\n  myservo.attach(9);\t\/\/ attaches the servo on pin 9 to the servo object\r\n  test_camera();    \t\/\/ executing testing for the servo\r\n  pixy.init();      \t\/\/ initing the pixy camera\r\n}\r\n \r\nvoid loop() {\r\n  \/\/variables\r\n  static int i = 0;\r\n  int j;\r\n  uint16_t blocks;\r\n  char buf[32]; \r\n  int32_t xpos;\r\n  \r\n  \/\/ grabing the blocks\r\n  blocks = pixy.getBlocks();\r\n  \r\n  \/\/ If there are detect blocks\r\n  if (blocks)\r\n  {\r\n\ti++;\r\n \r\n\t\/\/ we are using 50FPS \r\n\tif (i%50==0)\r\n\t{\r\n  \tsprintf(buf, \"Detected %d:\\n\", blocks);\r\n  \tfor (j=0; j&lt;blocks; j++)\r\n  \t{\r\n    \tsprintf(buf, \"  block %d: \", j);\r\n        \r\n    \t\/\/Serial.println((((pixy.blocks[j].x)\/2)+10)-60); \/\/print out to what position will the servo go\r\n \r\n    \t\/\/ this is used so the servo can't get stuck at minimum and maximum values\r\n    \tif(((((pixy.blocks[j].x)\/2)+10)-60) &gt; 180 || ((((pixy.blocks[j].x)\/2)+10)-60) &lt; 0 ) \r\n    \t{\r\n      \tmyservo.write(90);  \/\/ if at min or max go to the middle\r\n    \t}\r\n    \telse{\r\n \r\n    \t\/\/ if there is no problem with min and max\r\n    \tmyservo.write((((pixy.blocks[j].x)\/2)+10)-60);\r\n    \t}\r\n  \t}\r\n\t}\r\n  }\r\n}\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>sprintf(buf, \u201cDetected %d:\\n\u201d, blocks); <\/strong>\u8f93\u51fa\u7531ID\u68c0\u6d4b\u5230\u7684\u5f53\u524d\u5bf9\u8c61\uff0c\u5e76\u5c06\u5fc5\u8981\u7684\u6570\u636e\u653e\u5165\u7f13\u51b2\u533a\u3002\u5728for\u5faa\u73af\u4e2d\uff0c\u6211\u4eec\u5c06\u4f1a\u83b7\u5f97\u6240\u6709\u7c7b\u578b\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u68c0\u6d4b\u5bf9\u8c61\u3001\u5bbd\u5ea6\u3001\u9ad8\u5ea6\u3001x\u3001y\u4ee5\u53ca\u6807\u8bb0\u4fe1\u606f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3570\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-7.png\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-7.png 700w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-7-300x148.png 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-7-260x129.png 260w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-7-50x25.png 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-7-150x75.png 150w\" alt=\"camera sensor\" width=\"700\" height=\"346\" \/><\/p>\n<h2>\u901a\u8fc7\u4f3a\u670d\u8fdb\u884c\u63a7\u5236<\/h2>\n<p>\u73b0\u5728\uff0cPixy\u5df2\u7ecf\u6210\u529f\u8fde\u63a5\u5230\u4e86Arduino\uff0c\u6211\u5c06\u505a\u4e00\u4e2a\u7b80\u5355\u7684\u5b9e\u9a8c\uff0c\u5c06Pixy\u8fde\u63a5\u5230\u4f3a\u670d\uff0c\u5e76\u4e14\u5728\u76f8\u673a\u201c\u770b\u5230\u201c\u67d0\u79cd\u7c7b\u578b\u7684\u989c\u8272\/\u5bf9\u8c61\u65f6\u8ba9\u4f3a\u670d\u63a7\u5236\u79bb\u5f00\u3002<\/p>\n<p>\u5728\u672c\u5b9e\u9a8c\u4e2d\uff0c\u6211\u5c06\u628aPixy\u7684\u68c0\u6d4b\u5bf9\u8c61\u8bbe\u7f6e\u4e3a\u5706\u5f62\u7d2b\u8272\u5bb9\u5668\uff0c\u7136\u540e\u8fdb\u884c\u7f16\u7a0b\uff0c\u8fd9\u6837\u4e00\u6765\uff0c\u6bcf\u5f53\u8fd9\u79cd\u5bb9\u5668\u8fdb\u5165\u76f8\u673a\u7684\u89c6\u91ce\uff0c\u4f3a\u670d\u5c31\u4f1a\u63a7\u5236\u79bb\u5f00\u8fd9\u4e2a\u7269\u4f53\u3002<\/p>\n<p>\u88c5\u7f6e\u7ed3\u6784\uff1a<\/p>\n<div id=\"attachment_3571\" class=\"wp-caption alignnone\" style=\"width: 709px;\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3571\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-8.png\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-8.png 699w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-8-300x225.png 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-8-194x146.png 194w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-8-50x38.png 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-8-100x75.png 100w\" alt=\"camera sensor\" width=\"699\" height=\"525\" aria-describedby=\"caption-attachment-3571\" \/><\/p>\n<p id=\"caption-attachment-3571\" class=\"wp-caption-text\">\u56fe4\uff1a\u5df2\u5b8c\u6210\u7684\u88c5\u7f6e\u7ed3\u6784<\/p>\n<\/div>\n<p class=\"normal\"><span style=\"font-size: 12.0pt; line-height: 115%;\">\u6211\u4f7f\u7528\u7684\u662fS06NF\u4f3a\u670d\uff0c\u5e76\u4e14\u7528\u5c0f\u87ba\u4e1d\u9489\u5c06\u4f3a\u670d\u8fde\u63a5\u5230\u76f8\u673a\u4e0a\uff0c\u5982\u56fe5\u6240\u793a\u3002<\/span><\/p>\n<div id=\"attachment_3572\" class=\"wp-caption alignnone\" style=\"width: 710px;\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3572\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-9.png\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-9.png 700w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-9-300x225.png 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-9-195x146.png 195w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-9-50x38.png 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-9-100x75.png 100w\" alt=\"camera sensor\" width=\"700\" height=\"525\" aria-describedby=\"caption-attachment-3572\" \/><\/p>\n<p id=\"caption-attachment-3572\" class=\"wp-caption-text\">\u56fe5\uff1a\u76f8\u673a\u4e0e\u4f3a\u670d\u7535\u673a\u8fde\u63a5<\/p>\n<\/div>\n<p class=\"normal\">\u5bf9\u4e8e\u786c\u4ef6\u90e8\u5206\uff0c\u4ec5\u8fdb\u884c\u7b80\u5355\u7684\u63a5\u7ebf\u3002\u5c06SPI\u7ebf\u7f06\u8fde\u63a5\u5230\u76f8\u673a\u4e0a\uff0c\u5c06\u4f3a\u670d\u4e0eArduino\u8fde\u63a5\u3002\u6211\u4f7f\u7528\u5f15\u811a9\u6765\u63a7\u5236\u4f3a\u670d\u3002<\/p>\n<div id=\"attachment_3573\" class=\"wp-caption alignnone\" style=\"width: 663px;\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3573\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-10.png\" sizes=\"auto, (max-width: 653px) 100vw, 653px\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-10.png 653w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-10-300x241.png 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-10-182x146.png 182w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-10-50x40.png 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/camera-sensor-10-93x75.png 93w\" alt=\"camera sensor\" width=\"653\" height=\"525\" aria-describedby=\"caption-attachment-3573\" \/><\/p>\n<p id=\"caption-attachment-3573\" class=\"wp-caption-text\">\u56fe6\uff1a\u63a5\u7ebf\u56fe<\/p>\n<\/div>\n<p>\u8b66\u544a\uff01<\/p>\n<p>\u4e0d\u8981\u5fd8\u8bb0\u8fde\u63a5GND\u3002\u5982\u679c\u60a8\u6ca1\u6709\u5c06\u7535\u6e90\u3001\u4f3a\u670d\u548cArduino GND\u8fde\u63a5\u5728\u4e00\u8d77\uff0c\u4f3a\u670d\u5668\u5c06\u4f1a\u5954\u6e83\uff01<\/p>\n<p>\u8fd9\u91cc\uff0c\u6211\u4f7f\u7528\u7684\u662f\u7528\u4e8e5V\u7535\u6e90\u7684\u65e7\u578b\u9002\u914d\u5668\u3002<\/p>\n<p><script type=\"text\/javascript\">\n\tjstream_t3.PlayerFactoryIF.create({\n\tb:\"eqa194obdo.eq.webcdn.stream.ne.jp\/www50\/eqa194obdo\/jmc_pub\/jmc_swf\/player\/\",\n\tc:\"NDc3\",\n\tm:\"NTU0\",\n\ts:{\n\t\thp:360,\n\t\til:\"off\",\n\t\trb:\"off\",\n\t\tsn:\"f,t,g\",\n\t\twp:640\n\t}});\n<\/script><\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86PixyMon\u76f8\u673a\u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u5e76\u4e14\u5f00\u53d1\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u4f3a\u670d\u9a71\u52a8\u5e94\u7528\u3002\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u4f1a\u79bb\u5f00\u68c0\u6d4b\u5bf9\u8c61\u800c\u4e0d\u662f\u5bf9\u8c61\u8ffd\u8e2a\u7684\u7cfb\u7edf\u3002\u5728\u7b2c\u4e8c\u90e8\u5206\u4e2d\uff0c\u6211\u4eec\u4f1a\u7ee7\u7eed\u6df1\u5165\u62d3\u5c55\u8fd9\u4e2a\u7406\u5ff5\uff0c\u5f00\u53d1\u51fa\u4e00\u79cd\u5177\u6709\u591a\u4e2a\u4f3a\u670d\u7684\u4ea4\u4e92\u7cfb\u7edf\uff0c\u901a\u8fc7\u5c06\u4e00\u4e2a\u7403\u4f5c\u4e3a\u5bf9\u8c61\uff0c\u5b9e\u73b0\u5bf9\u684c\u5b50\u65b9\u4f4d\u7684\u63a7\u5236\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6709\u4efb\u4f55\u610f\u89c1\u6216\u7591\u95ee\uff0c\u8bf7\u5728<a href=\"https:\/\/plus.google.com\/102235885073289153873\" target=\"_blank\" rel=\"noopener noreferrer\">Google +<\/a>\u4e0a\u7559\u8a00\uff0c\u5e76\u5173\u6ce8\u6211\u4eec\u7684\u52a8\u6001\u3002<\/p>\n<p><strong><a href=\"https:\/\/techclass.wfjydl.com\/knowledge\/tech-info\/how-tos\/arduino\/intro-to-cmucam5-pixy-vision-camera-sensor-part-2-creating-a-ball-balance-beam\">\u7ee7\u7eed\u9605\u8bfb\u672c\u6587\u7684\u7b2c\u4e8c\u90e8\u5206 &gt;<\/a><\/strong><\/p>\n<div class=\"author-box-wrapper\">\n<div class=\"avatar-wrapper\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2016\/07\/Silard-Gal_avatar_1469203917-64x64.png\" alt=\"Silard Gal\" width=\"64\" height=\"64\" \/><\/div>\n<div class=\"desc-wrapper\">\n<h5>Silard Gal<\/h5>\n<div class=\"desc\">\n<p>Silard\u6765\u81ea\u585e\u5c14\u7ef4\u4e9a\uff0c\u70ed\u7231\u4e0e\u7535\u5b50\u548c\u7f16\u7a0b\u6709\u5173\u7684\u6240\u6709\u4e8b\u7269\u3002\u559c\u6b22\u4f7f\u7528Arduino\u3001Raspberry Pi\u3001Atmel\u7b49\u6765\u521b\u5efa\u5404\u79cd\u9879\u76ee\uff0c\u5e76\u4e3a\u6210\u4e3a\u81ea\u4e3b\u673a\u5668\u4eba\u56e2\u961f\u7684\u4e00\u5458\u800c\u611f\u5230\u81ea\u8c6a\u3002<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"\u8fd9\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8eDevicePlus.com\u82f1\u8bed\u7f51\u7ad9\u7684\u7ffb\u8bd1\u7a3f\u3002 PixyMon \u548c Arduino \u8be5\u9879\u76ee\u7684\u76ee\u6807\u662f\u5411\u60a8\u4ecb\u7ecdCMUcam5 Pixy\uff0c\u5e76\u5c55\u793a\u5982\u4f55\u5728\u60a8\u81ea\u5df1DIY\u7684\u9879\u76ee\u4e2d\u5b9e\u73b0\u76f8\u673a\u529f\u80fd\uff0c\u60a8\u4f1a\u53d1\u73b0\u5373\u4f7f\u5bf9\u4e8e\u4e00\u4e2a\u590d\u6742\u7684\u673a [&hellip;]","protected":false},"author":3,"featured_media":16731,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1130],"tags":[],"class_list":["post-7946","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino"],"acf":[],"wps_subtitle":"","_links":{"self":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts\/7946","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/comments?post=7946"}],"version-history":[{"count":78,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts\/7946\/revisions"}],"predecessor-version":[{"id":16737,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts\/7946\/revisions\/16737"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/media\/16731"}],"wp:attachment":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/media?parent=7946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/categories?post=7946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/tags?post=7946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}