Git Product home page Git Product logo

attiny-pid's Introduction

ATTiny85 PID Controller

This library provides an I2C controllable ATTiny85 PID controller.

Two pin control

Function Name ATTiny85 Olimexino85
SCL PB2 7 2
SDA PB0 5 0
MOTOR_UP PB11 6 1
MOTOR_DOWN PB42 3 4
SIGNAL_READ A3 2 3

1PWM on timer 0; ~500 Hz

2PWM on timer 1; ~1000Hz

Three pin control

Function Name ATTiny85 Olimexino85
SCL PB2 7 2
SDA PB0 5 0
MOTOR_UP PB5/#RESET 1 #RST
MOTOR_DOWN PB4 3 4
MOTOR_SPEED PB11 6 1
SIGNAL_READ A3 2 3

1PWM on timer 0; ~500 Hz

The following I2C commands are supported:

	MOTOR_I2C_COMMAND_STOP
	MOTOR_I2C_COMMAND_HALT
	PID_I2C_COMMAND_ENABLE
	PID_I2C_COMMAND_DISABLE
	PID_I2C_COMMAND_RESET
	PID_I2C_COMMAND_SET_VALUE
	PID_I2C_COMMAND_SET_K_P
	PID_I2C_COMMAND_SET_K_I
	PID_I2C_COMMAND_SET_K_D
	PID_I2C_COMMAND_SET_DEAD_BAND

Reading the measurement value:

	// Read from Slave
	Wire.requestFrom(target, (size_t)(sizeof i2cData.parameterValue));

	if (Wire.getError())
	{
		Serial.print("FAIL\n");
	}
	else
	{
		// If no error then read Rx data into buffer and print
		uint8_t len = io::i2cRead(i2cData.parameterValue, true);
		// Serial.printf("read bytes: %d, value: %d\n", len, i2cData.parameterValue);
	}

Example for sending a byte command:

	Wire.beginTransmission(0x4);		  // Slave address
	io::i2cWrite(PID_I2C_COMMAND_ENABLE); // Write string to I2C Tx buffer (incl. string null at end)
	Wire.endTransmission();

	if (Wire.getError())
		...

Example for sending a command with a parameter:

	i2cData.parameterValue = 10;
	Wire.beginTransmission(0x4);		   // Slave address
	io::i2cWrite(PID_I2C_COMMAND_SET_K_P);
	io::i2cWrite(i2cData.parameterValue);
	Wire.endTransmission();

	if (Wire.getError())
		...

attiny-pid's People

Contributors

slugh23 avatar michaelkrone avatar

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.