Skip to content

Control up to 10 servo motors via I2C with this firmware for ATtiny2313 and ATtiny26 originally by Stefan Frings

Notifications You must be signed in to change notification settings

ftjuh/ServoController

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

I2C Servo Controller for ATtiny2313 and ATtiny26

This is a firmware for ATtiny2313 and ATtiny26 target (slave) devices that enables you to control up to 10 servo motors by a controller (master) device via I2C.

Original code by Stefan Frings. Find his original documentation (in German) here and an archived version of his original page (now offline) at archive.org.

This repository includes the original code in release 1, with bug fixes and additional documentation in subsequent releases maintained by me (ftjuh).

Why use this instead of PCA9685 and the like?

If you need servo control over I2C, you can use a number of dedicated chips and modules, e.g. the PCA9685, which in most cases will do just as well or even better. So you'll probably want to use this firmware only in special cases, e.g.

  • if the usual modules are too big for your needs,
  • if you want to customize the firmware,
  • if you need a special I2C address for some reason, or
  • if you want an example of a "raw" I2C target (slave) implementation which doesn't use a library.

In fact, Stefan's solution of using three timer interrupts for 10 servos is quite clever and instructive, and with only 1.6 Kb it's an impressive example of what you can get out of an ATtiny's very limited resources. On the other hands, it is also an example of the dangers of ignoring (or having to ignore) the merits of software reusability.

If you need a more generic solution for servo control over I2C, maybe in combination with other functionality, have a look at my I2Cwrapper project and its ServoI2C module.

Schematics

schematics

Example and demonstration

I used Stefan's code for my WeFish fischertechnik controller system, which is built around the Wemos D1 mini and compatibles. For the servo module , the ubiquitous PCA9685 modules would have been too big, while a bare ATtiny2313 with two capacitors was a natural fit (the servo module with an ATtiny2313 is the one in the middle):

https://forum.ftcommunity.de/download/file.php?id=2087

Watch it in action in this video:

Watch the video

This is the relevant Arduino code snippets from the above example, which used only one servo:

const byte servoUpPos = 108;
const byte servoDownPos = 125;

void setServo(byte pos) { // Stefan Fring's ATtiny2313 I2C servo driver
  Wire.beginTransmission(0x0F);
  Wire.write(pos); // only write servo 0 and be done
  Wire.endTransmission();
}

void plotAt(int mmTarget) { // make a dot at mmTarget mm
  runToMM(mmTarget);
  setServo(servoDownPos);
  delay(100);
  setServo(servoUpPos);
}

Author

Original code by Stefan Frings.

Bug fixes and additional documentation by ftjuh.

License

GNU GENERAL PUBLIC LICENSE (GPL)

About

Control up to 10 servo motors via I2C with this firmware for ATtiny2313 and ATtiny26 originally by Stefan Frings

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published