{"id":721,"date":"2015-10-11T10:58:03","date_gmt":"2015-10-11T02:58:03","guid":{"rendered":"http:\/\/ukonline2000.com\/?p=721"},"modified":"2016-04-07T12:37:54","modified_gmt":"2016-04-07T04:37:54","slug":"16%e8%b7%af%e8%88%b5%e6%9c%ba%e6%8e%a7%e5%88%b6%e6%89%a9%e5%b1%95%e6%9d%bf%e4%bd%bf%e7%94%a8%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"http:\/\/ukonline2000.com\/?p=721","title":{"rendered":"16\u8def\u8235\u673a\u63a7\u5236\u6269\u5c55\u677f\u4f7f\u7528\u6559\u7a0b"},"content":{"rendered":"<p>&nbsp;<\/p>\n<h1 class=\"tb-main-title\" data-title=\"\u6811\u8393\u6d3epi arduino 16\u8def\u8235\u673a\u63a7\u5236\u6269\u5c55\u677f \u53ef\u7ea7\u8054\u6700\u5927\u652f\u6301256\u8def\u8235\u673a\">16\u8def\u8235\u673a\u63a7\u5236\u6269\u5c55\u677f<\/h1>\n<h2><span style=\"font-family: Tahoma;\">\u529f\u80fd\u63cf\u8ff0\uff1a<br \/>\n1.\u00a0 \u4f7f\u7528I2C\u63a5\u53e3\uff0c\u4e0d\u5360\u7528GPIO\u63a5\u53e3\uff08\u9ed8\u8ba4\u5730\u57400x6F\uff09<br \/>\n2.\u00a0 \u540c\u65f6\u652f\u6301\u6811\u8393\u6d3e\uff083.3v\u7535\u5e73\uff09\u548carduino\uff085v\u7535\u5e73\uff09\uff0c\u4f46\u4e24\u79cd\u4e3b\u63a7\u4e0d\u80fd\u540c\u65f6\u63a7\u5236<br \/>\n3. \u652f\u630116\u8defPWM\u901a\u9053\u8f93\u51fa\uff0c\u53ef\u4ee5\u63a7\u523616\u8def\u8235\u673a\u6216\u8005LED\u706f<br \/>\n4.\u00a012\u4f4d\u5206\u8fa8\u7387\uff0c\u53ef\u8c03PWM\u9891\u7387\u9ad8\u8fbe1.6KHz\uff0c\u53ef\u914d\u7f6e\u7684\u63a8\u633d\u6216\u5f00\u6f0f\u8f93\u51fa<br \/>\n5. 3P\u6807\u51c6\u63a5\u53e3\uff0c\u65b9\u4fbf\u8fde\u63a5\u8235\u673a\u548cLED\u706f<br \/>\n6. 4\u4f4d\u53ef\u8c03\u5730\u5740\uff08A0-A3\uff09\uff0c\u65b9\u4fbf\u7ea7\u8054\u6269\u5c55\u677f\uff0c\u6700\u5927\u53ef\u7ea7\u805416\u4e2a\u6269\u5c55\u677f\uff08\u53ef\u4ee5\u63a7\u5236256\u8def\u8235\u673a\u6216LED\u706f\uff09<\/span><\/h2>\n<h2><span style=\"font-family: Tahoma;\"><strong><span style=\"font-size: large;\">\u4ea7\u54c1\u53c2\u6570\uff1a<br \/>\n1.\u8235\u673a\u90e8\u5206\u4f9b\u7535\u8303\u56f4\uff1a4.5V~5.5V\u7684DC\u76f4\u6d41\uff08\u7535\u538b\u4e0e\u8235\u673a\u7684\u53c2\u6570\u6709\u5173\uff0c\u4e00\u822c\u4f7f\u75285V DC\uff09\u3002<br \/>\n2.\u63a7\u5236\u901a\u9053\uff1a\u540c\u65f6\u63a7\u523616\u8def\u3002\uff08\u8235\u673a\u901f\u5ea6\u7cbe\u786e\u53ef\u8c03\uff0c\u673a\u5668\u4eba\u52a8\u4f5c\u6d41\u7545\u81ea\u5982\uff09<br \/>\n3.\u901a\u8baf\u8f93\u5165\uff1aI2C<br \/>\n4.\u4fe1\u53f7\u8f93\u51fa\uff1aPWM\uff08\u9891\u7387\u9ad8\u8fbe1.6KHz\uff09<\/span><\/strong><\/span><\/h2>\n<h2><span style=\"font-family: Tahoma;\"><strong><span style=\"font-size: large;\">\u63a5\u53e3\u5b9a\u4e49\u56fe<\/span><\/strong><\/span><\/h2>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: Tahoma;\"><strong><span style=\"font-size: large;\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/img.alicdn.com\/imgextra\/i1\/13118880\/T2wObLXsBaXXXXXXXX_!!13118880.jpg\" alt=\"\" width=\"343\" height=\"217\" align=\"absmiddle\" \/><\/span><\/strong><\/span><\/p>\n<h2>\u4f7f\u7528\u6b65\u9aa4\uff1a<\/h2>\n<p>1.\u4f7f\u80fd\u6811\u8393\u6d3e\u7684I2C\u63a5\u53e3\uff0c\u53c2\u8003\u6559\u7a0bhttp:\/\/ukonline2000.com\/?p=728<\/p>\n<p>2.\u4e0b\u8f7d\u8f6f\u4ef6\u548c\u53c2\u8003\u7a0b\u5e8f<\/p>\n<p>sudo apt-get install git<\/p>\n<p>git clone https:\/\/github.com\/geekroo\/Geekroo-PiCobber-PWMServo.git<\/p>\n<p>3.\u5c06\u8235\u673a\u6216\u8005led\u706f\u8fde\u63a5\u5230\u8235\u673a\u6269\u5c55\u677f\u4e0a\uff0c\u5982\u4e0b\u56fe\uff08\u8bf7\u4e00\u5b9a\u6ce8\u610f\u8235\u673a\u7684\u7ebf\u5e8f\uff09<\/p>\n<p>\u8fde\u63a5\u8235\u673a<\/p>\n<h2><a href=\"http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_Servos.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-722\" src=\"http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_Servos-300x225.jpg\" alt=\"ServoPiCobber_Servos\" width=\"300\" height=\"225\" srcset=\"http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_Servos-300x225.jpg 300w, http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_Servos-400x300.jpg 400w, http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_Servos.jpg 979w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h2>\n<p>\u8fde\u63a5led\u706f<\/p>\n<h2><a href=\"http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_LEDs.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-723\" src=\"http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_LEDs-300x225.jpg\" alt=\"ServoPiCobber_LEDs\" width=\"300\" height=\"225\" srcset=\"http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_LEDs-300x225.jpg 300w, http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_LEDs-400x300.jpg 400w, http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_LEDs.jpg 979w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h2>\n<p>\u8fde\u63a55V\u7535\u6e90\u8f93\u5165<\/p>\n<h2><a href=\"http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_5V.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-724\" src=\"http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_5V-300x225.jpg\" alt=\"ServoPiCobber_5V\" width=\"300\" height=\"225\" srcset=\"http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_5V-300x225.jpg 300w, http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_5V-400x300.jpg 400w, http:\/\/ukonline2000.com\/wp-content\/uploads\/2015\/10\/ServoPiCobber_5V.jpg 979w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h2>\n<p>4.\u8fd0\u884c\u6d4b\u8bd5\u7a0b\u5e8f\uff0c\u8235\u673a\/led\u706f\u73b0\u5728\u5e94\u8be5\u6b63\u5e38\u5de5\u4f5c\u4e86<\/p>\n<p>cd \/Geekroo-PiCobber-PWMServo<\/p>\n<p>sudo\u00a0python Servo_Example.py<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e\uff5e<\/p>\n<h1>Library Reference<\/h1>\n<p>The driver consists of the following functions, which you can use to drive the underlying hardware when writing your own application in Python:<\/p>\n<h1>Initialize Object<\/h1>\n<p>You can create a new object for each HAT with<\/p>\n<p><strong>pwm = PWM(0x40)<\/strong><\/p>\n<p>In this case, pwm (lowercase) is the object created, and\u00a0PWM(0x40)\u00a0is the creation call. By default, all HATs are address 0x40, but by changing the address jumpers, you can create objects that use other addresses such as 0x60, 0x42, etc.<\/p>\n<h1>setPWMFreq(freq)<\/h1>\n<h2>Description<\/h2>\n<p>This function can be used to adjust the PWM frequency, which determines how many full &#8216;pulses&#8217; per second are generated by the IC. Stated differently, the frequency determines how &#8216;long&#8217; each pulse is in duration from start to finish, taking into account both the high and low segments of the pulse.<br \/>\nFrequency is important in PWM, since setting the frequency too high with a very small duty cycle can cause problems, since the &#8216;rise time&#8217; of the signal (the time it takes to go from 0V to VCC) may be longer than the time the signal is active, and the PWM output will appear smoothed out and may not even reach VCC, potentially causing a number of problems.<\/p>\n<h2>Arguments<\/h2>\n<ul>\n<li><strong>freq<\/strong>: A number representing the frequency in Hz, between 40 and 1000<\/li>\n<\/ul>\n<h2>Example<\/h2>\n<p>The following code will set the PWM frequency to the maximum value of 1000Hz:<\/p>\n<p>1.\u00a0 pwm.setPWMFreq(1000)<\/p>\n<p>&nbsp;<\/p>\n<h1>setPWM(channel, on, off)<\/h1>\n<h2>Description<\/h2>\n<p>This function sets the start (on) and end (off) of the high segment of the PWM pulse on a specific channel. \u00a0You specify the &#8216;tick&#8217; value between 0..4095 when the signal will turn on, and when it will turn of. \u00a0Channel indicates which of the 16 PWM outputs should be updated with the new values.<\/p>\n<h2>Arguments<\/h2>\n<ul>\n<li><strong>channel<\/strong>: The channel that should be updated with the new values (0..15)<\/li>\n<li><strong>on<\/strong>: The tick (between 0..4095) when the signal should transition from low to high<\/li>\n<li><strong>off<\/strong>:the tick (between 0..4095) when the signal should transition from high to low<\/li>\n<\/ul>\n<h2>Example<\/h2>\n<p>The following example will cause channel 15 to start low, go high around 25% into the pulse (tick 1024 out of 4096), transition back to low 75% into the pulse (tick 3072), and remain low for the last 25% of the pulse:<\/p>\n<p>1.\u00a0 pwm.setPWM(15, 1024, 3072)<\/p>\n<p>If you need to calculate pulse-width in microseconds, you can do that by first figuring out how long each cycle is. That would be 1\/<strong>freq<\/strong>\u00a0where\u00a0<strong>freq<\/strong>\u00a0is the PWM frequency you set above. For 1000 Hz, that would be 1 millisecond. Then divide by 4096 to get the time per tick, eg 1 millisecond \/ 4096 = ~0.25 microseconds. If you want a pulse that is 10 microseconds long, divide the time by time-per-tick (10us \/ 0.25 us = 40) then turn on at tick 0 and turn off at tick 40.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 16\u8def\u8235\u673a\u63a7\u5236\u6269\u5c55\u677f \u529f\u80fd\u63cf\u8ff0\uff1a 1.\u00a0 \u4f7f\u7528I2C\u63a5\u53e3\uff0c\u4e0d\u5360\u7528G &hellip; <a href=\"http:\/\/ukonline2000.com\/?p=721\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-721","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi"],"_links":{"self":[{"href":"http:\/\/ukonline2000.com\/index.php?rest_route=\/wp\/v2\/posts\/721","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ukonline2000.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ukonline2000.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ukonline2000.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ukonline2000.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=721"}],"version-history":[{"count":5,"href":"http:\/\/ukonline2000.com\/index.php?rest_route=\/wp\/v2\/posts\/721\/revisions"}],"predecessor-version":[{"id":930,"href":"http:\/\/ukonline2000.com\/index.php?rest_route=\/wp\/v2\/posts\/721\/revisions\/930"}],"wp:attachment":[{"href":"http:\/\/ukonline2000.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ukonline2000.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=721"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ukonline2000.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}