Attiny85 as slave with specific address

Hi to everyone,
I’m trying to use an attiny85 as i2c slave and arduino mega as master, when I use the rambo modified library (TinyWireS) the example works perfectly. The problem is when I rerun the code giving to the slave the 0x76 address (of course I change the address in the master’s program) the program doesn’t work anymore. Can anyone help me? Thanks

attiny_i2c_slave.ino (584 Bytes)

master_reader_i2c_attiny85.ino (776 Bytes)

Hello,

76 (decimal) is not equal to 0x76 (hexadecimal) :slight_smile:

Hi guix,
Oh yeah you are right. However I changed the code right now in:
Wire.requestFrom(118, 6);
and in
Wire.requestFrom(0x76, 6);
but nothing to do... Do you have any other idea? Thanks so much

I've tried different address, in order to be sure about the format of the address I've used this syntax:
TinyWireS.begin((uint8_t)X);
(for the slave)
Wire.requestFrom((uint8_t)X, 6);
(for the master)
The strange thing is that when X is equal to 8,10,20,30 it works but if I change them in 50 76 118 it doesn't. Is it possible that the tiny85 supports at to a specific address in i2c? I know that is a bullshit because it uses a 7bit address, but at this point I really don't know what thing about it. Can anyone help me?
Thanks

Hi,
OPs code.
Slave;

#define I2C_SLAVE_ADDRESS 0x76 // Address of the slave
  
#include <TinyWireS.h>
 
#define ADC3 A3
 
void setup() {
    TinyWireS.begin(I2C_SLAVE_ADDRESS); // join i2c network
    TinyWireS.onRequest(requestEvent);
  
    pinMode(ADC3, INPUT_PULLUP);
}
 
void loop() {
    // This needs to be here
    TinyWireS_stop_check();
}
  
// Gets called when the ATtiny receives an i2c request
void requestEvent() {
    int val=analogRead(ADC3);
    byte valLow = val & 0xff;
    byte valHigh = (val >> 8);
    TinyWireS.send(valHigh);
    TinyWireS.send(valLow);
}

Master;

// Wire Master Reader
// by Nicholas Zambetti <http://www.zambetti.com>


// Demonstrates use of the Wire library
// Reads data from an I2C/TWI slave device
// Refer to the "Wire Slave Sender" example for use with this


// Created 29 March 2006


// This example code is in the public domain.




#include <Wire.h>


void setup() {
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
}


void loop() {
  Wire.requestFrom(76, 6);    // request 6 bytes from slave device #8   //8 e non 0x8


  while (Wire.available()) { // slave may send less than requested
    char c = Wire.read(); // receive a byte as character
    Serial.print(c);         // print the character
  }


  delay(500);
}

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks… Tom… :slight_smile:

Hi Tom, I'm really sorry I'll read it immediately, thanks :slight_smile: