Code Monkey home page Code Monkey logo

servocontroller's Introduction

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)

servocontroller's People

Contributors

ftjuh avatar

Stargazers

 avatar

Watchers

 avatar

servocontroller's Issues

ESP8266 controller will crash the target firmware if addresses >=0x40 are used on the bus

ESP8266 as controller uses a very tight timing after a start condition. Analysis with a logic analyzer shows that the ESP8266 will pull SDA up very soon after pulling SCL low. Addresses >= 0x40 will result in a '1' bit sent immediately after that.

Logic Analyzer output from Pulseview (remove ".zip" from file extension): 0x40 24Mhz 20k samples.sr.zip

The original code will erroneously interpret this as a stop condition because it does not buffer the state of SDA between detecting a pin change and interpreting this change as a stop condition. Also, it ignores SCL in doing so.

        // Wait until end of start condition or begin of stop condition 
        while ((PINB & 128) && !(PINB & 32));

        // Break when a stop condition has been received while waiting
        if (PINB & 32) {
          break;
        }

After the false detection of a stop detection the above break; command will cause an exit from the main loop, putting the device in an undefined, non reactive state.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.