[I2C] Attiny85 Slave device

Hello !

I want to use an Attiny85 as a slave to send some data over I2C to a master (in my case, Uno). I burned the bootloader on the Attiny85(Internal clock, 16 Mhz) and downloaded the TinyWireS library. This is the code on the Attiny:

#include <TinyWireS.h>

void setup() {
  TinyWireS.begin(8);                
  TinyWireS.onRequest(requestEvent); 
}

void loop() {
  //
}

void requestEvent() {
  TinyWireS.send("helloo"); 
}

Arduino Uno runs the following:

#include <Wire.h>

void setup() {
  Wire.begin();        
  Serial.begin(9600);  
}

void loop() {
  Wire.requestFrom(8, 6);   

  while (Wire.available()) { 
    char c = Wire.read(); 
    Serial.println(c);         
  }

  delay(500);
}

The circuit works, Attiny is sending data, but…not really what I want. That’s what I receive (serial monitor):

`
ÿ
ÿ
ÿ
ÿ
ÿ
`
ÿ
ÿ
ÿ
ÿ
ÿ
`
ÿ
ÿ
ÿ
ÿ
ÿ

What I’m doing wrong ? :sob:

Attiny85(Internal clock, 16 Mhz)

Interesting, I never heard of an ATtiny85 model that has a 16MHz internal oscillator. The internal oscillator of an ATtiny85 runs at 8MHz.

What bootloader did you burn? The IDE doesn't have a bootloader for the ATtiny platform so please provide a link to the bootloader you used.

Please provide a wiring diagram of how you connected the two processors (all wires and parts!). How long is the cable between the two?

It might be the digispark - I have several, and the default is 16.5MHz.

There are some quirky timing things with that platform...

Thanks,
DragonJ

It might be the digispark - I have several, and the default is 16.5MHz.

Where do you have that information from? The digispark I know run at 8MHz. Please provide a link the page where you found the specification of 16.5 MHz.

Which attiny core do you use to program? The ATtinyCore available in the boards manager of the IDE doesn't have support for the digispark. Every ATtiny85 has an internal 8MHz oscillator. You can have external resonators or crystals that put the clock to 16MHz or 20MHz. As the digispark doesn't show an external clock source it probably runs at 8MHz.

I guess that's your problem.

First of all, thank you for your answers.

I used this files for supporting Attiny boards on Arduino IDE: GitHub - damellis/attiny: ATtiny microcontroller support for the Arduino IDE
Also, check this: Add internal 16 MHz PLL clock support for ATtiny25/45/85. · damellis/attiny@6bba7d4 · GitHub

After that, I'ver burned the bootloader normally, following this tutorial: Programming ATtiny85 with Arduino Uno - Arduino Project Hub

The "Blink" test worked great.

Also, check this: Add internal 16 MHz PLL clock support for ATtiny25/45/85. · damellis/attiny@6bba7d4 · GitHub

This is very insteresting. I didn't know that the X5 Tinys have that high frequency PLL internally. Using the low fuse value in the patch I found the appropriate section (6.2.2) in the datasheet. Thank you, I love to learn new stuff!

TinyWireS.send("helloo");

Please provide a link to the library you're using. My version of TinyWireS defines the send method like this:

    void send(uint8_t data);

So you can send one byte after the other and there's no version that accepts a string. Unfortunately the compiler doesn't complain about that mistake. Fix that and try again. Post the results.

This is the library: TinyWire/TinyWireS at master · rambo/TinyWire · GitHub

Where should I change the code ?

Where should I change the code ?

Replace

TinyWireS.send("helloo");

by

TinyWireS.send('h');
TinyWireS.send('e');
TinyWireS.send('l');
TinyWireS.send('l');
TinyWireS.send('o');
TinyWireS.send('o');

Unfortunately, sending one byte at a time doesn't change anything.

A strange thing is if I change to print the character as a DEC, I get a "96" output.

Serial.println(c, DEC);   
[code]

Please change the line on the UNO

Wire.requestFrom(8, 6);

to

  int read = Wire.requestFrom(8, 6);
  if (read < 6) {
    Serial.print("Error reading from I2C, read bytes: ");
    Serial.print(read);
  }

I guess that the connection doesn’t work at all and the problem might be in the hardware. Please post a photo of your setup showing all connections.