im trying to control a servo from an attiny84, which in turn is controlled by a nano via i2c.
i'm using this library:https://github.com/nadavmatalon/TinyWireS
i'm getting an bug where, when sending a position, the output is only updated when a request is sent.
without the request the attiny84, will not update the servo.and the request only returns 1.
any ideas?
slave Code (attiny84)
#include <Servo.h>
#include <TinyWireS.h>
Servo servo;
volatile byte targetPos;
void setup()
{
//servo
servo.attach(0);//pinServo);
//twi
TinyWireS.begin(8);
TinyWireS.onReceive(receiveEvent);
TinyWireS.onRequest(requestEvent);
}
void loop()
{
servo.write(targetPos);
}
void requestEvent()
{
static byte i=0;
TinyWireS.write(i);
i++;
}
void receiveEvent(uint8_t howMany)
{
targetPos=TinyWireS.read();
}
master code(nano)
#include <Wire.h>
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
}
void loop() {
byte i;
i=rand()%180;
Wire.beginTransmission(8);
Wire.write(i);
Wire.endTransmission();
Wire.requestFrom(8,1); //this line is need to write to the attiny...
delay(500);
}