attiny84 tinywireS

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);
}

Try doing it using my ATTinyCore, and the builtin Wire library (instead of TinyWireS) - my core has a builtin Wire library that automatically selects the best I2C implementation available for that hardware, and it should use the appropriate code to do I2C slave with the USI, and it should work. If it doesn't, that's something I need to fix (and a perfect test case, since you've been kind enough to give me code!)

If that doesn't work, post schematic as well as adapted code.

thank you.

it works with that test code, so i suspect their library.

ive spent the last two days plugging various I2C library's into my code and trying to find various workarounds ,so you've probably just saved me a lot of aggravation. :slight_smile:

now just to implement it in the rest of my code.

Glad to hear that it seems to be working for you; the I2C slave stuff hasn't been well exercised AFAIK, so I'm particularly cheered when I hear people confirming that it works :wink: