[转载] [Arduino模块]SD20 伺服电机控制器

2013-12-181.3万
AI 快速预览详细 收起
SD20 伺服电机控制器是一款通过I2C接口控制多个伺服电机的模块。它支持精确的脉冲宽度控制,适用于需要精确控制的应用场景。本文提供了详细的电路图和代码示例,帮助用户快速上手。通过I2C接口,可以轻松实现对多个伺服电机的控制,节省了手动调试的时间。
[Arduino模块]
SD20 伺服电机控制器

电路示意:



代码示例:
  1. /*
  2. Example for SD20 servo driver chip. This will drive a servo from the
  3. first servo pin on the SD20 from 1ms to 2ms repeatedly. This also shows
  4. how to how to set use the expand mode to set custom ranges.
  5. By James Henderson, 2012.
  6. */
  7. #include <Wire.h>
  8. #define SD20ADDRESS 0x61                // Address of the SD20
  9. #define GETSOFT     (byte)0x00                    // Byte to get software version
  10. int softVer = 0;                        // Stores software version
  11. void setup(){
  12.   Wire.begin();                          
  13.   Serial.begin(9600);
  14.   Software();                           // Call function that reads software version
  15. // setExpand();                          // Calls function that sets expand mode values for servo movement
  16. }
  17. void loop(){
  18.   
  19.   for(int x = 1; x <= 20; x++){
  20.     Wire.beginTransmission(SD20ADDRESS);  // Send value of 254 to servo pins
  21.       Wire.write(x);
  22.       Wire.write(255);
  23.     Wire.endTransmission();
  24.     delayMicroseconds(100);
  25.   }
  26.     delay(500);
  27.   for(int x = 1; x <= 20; x++){
  28.     Wire.beginTransmission(SD20ADDRESS);  // Send value of 1 to servo pins
  29.       Wire.write(x);
  30.       Wire.write(1);
  31.     Wire.endTransmission();
  32.     delayMicroseconds(100);
  33.   }
  34.   delay(500);   
  35.       
  36. }
  37. /*void setExpand(){                     // Function to define custom settings for expanded mode
  38.   
  39.   Wire.beginTransmission(sd20Address);  // Send 43 to register 21
  40.   Wire.send(21);
  41.   Wire.send(43);
  42.   Wire.endTransmission();
  43.   
  44.   delayMicroseconds(70);                // Wait for SD20 to process the byte we just sent to it
  45.   
  46.   Wire.beginTransmission(sd20Address);  // Set offset
  47.   Wire.send(22);
  48.   Wire.send(0x03);
  49.   Wire.send(0x34);
  50.   Wire.endTransmission();
  51.   
  52.   delayMicroseconds(70);                // Wait for SD20 to process the byte we just sent to it
  53.   
  54. }
  55. */
  56. void Software(){                         // Function that reads software revision
  57.   Wire.beginTransmission(SD20ADDRESS);  
  58.   Wire.write(GETSOFT);                   // Send to the register that returns the software revision
  59.   Wire.endTransmission();               
  60.   
  61.   Wire.requestFrom(SD20ADDRESS, 1);      // Request 1 byte from SD20
  62.   while(Wire.available() > 0){           // While there are bytes to read
  63.   softVer = Wire.read();                 // Get software revision
  64.   }
  65.   Serial.println(softVer);               // Print software version to arduino serial monitor
  66. }
复制代码





创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(0)
- 没有更多了 -