Many Attiny85s and 828s as I2C slaves

Hi all, I'm working on a project where I'm making an array of panels with different knobs and buttons on each of them, which will be hot-swappable on I2C communication and all controlled by a master uno or mega.
I've chosen the attiny828 as it's large amount of analog pins and small price is perfect for most of the panels.

I bought some attiny85 chips just to test if my idea is feasible, however after many videos and tutorials i am unable to get the attiny85 chip to send information over I2C to an arduino uno, let alone reading a potentiometer's state and then sending it.

My question is: is it doable to use attiny chips (especially 828s) as I2C slaves in this way? Realistically, i only need to send 1-2 states of analog pins back at a time per panel. The master can handle all logic and processing of those states as far as I'm concerned. I just haven't seen attiny chips used in this larger and unique way often, so I'm having my doubts.

here's an example of one of the codes used for the attiny. I followed tutorials using arduino uno as an ISP for the chip and it went well as far as i could tell:

#include <TinyWireM.h>

#define pot_pin1 A2
#define I2C_SLAVE_ADDRESS 0x10

void setup() {
  TinyWireM.begin(I2C_SLAVE_ADDRESS);
}

void loop() {
  int potValue = analogRead(pot_pin1);
  
  TinyWireM.beginTransmission(0x08);
  TinyWireM.write(potValue);
  TinyWireM.endTransmission();

  delay(100);
}

Any help is appreciated. Thanks!

Then use slave code on the ATTiny, using onRequest().

You realize the I2C protocol maximum wire length is measured in centimeters. Not in meters.
The protocol is designed for communication between devices on the same PCB.

It is also not considered hot swappable.

Is that sketch of post #1 for ATtiny85 or ATtiny828?

I had much better luck with I2C code on a Tiny85 talking to an Uno when using the ATTinyCore core by Spence Konde. >> GitHub - SpenceKonde/ATTinyCore: Arduino core for ATtiny 1634, 828, x313, x4, x41, x5, x61, x7 and x8.
For the core, here is a version of Wire and some exampes that may help.

1 Like

Is there another form of communication I can use with these chips that does? Assuming I am just sending analog pin states?

The most distanced panel from the master will be shorter than a meter. I only chose I2C to continue with the idea because of its ability to use only 2 pins across several devices.

It’s for the 85. I’m assuming there won’t be too much difference in the code when and if I start using 828s, other than pins.

Many bus systems do the same (RS-485...).

1 Like

What about USB? Do attiny chips, along with minimal extra hardware, have the ability to communicate this way? It would solve the hot-swap issue and I could find some way to process the oncoming information on a computer, which an uno or a mega was going to do anyways.

Checking the Functionality of I2C Bus between UNO and ATtiny85
1. Build the following setup (Fig-1) between Arduino UNO and Digispark Attiny85 Dev Board using I2C Bus. Do not connect the wiper of Pot with (PB5)ADC0-pin of ATtiny85.


Figure-1:

2. Upload the following sketch in UNO.

#include<Wire.h>
#define slaveAddress 0x23

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  pinMode(13, OUTPUT);
  //--------------------
  Wire.beginTransmission(slaveAddress);
  byte busStatus = Wire.endTransmission();
  if (busStatus != 0)
  {
    Serial.println("Slave is not found.");
    while (true); //wait for ever
  }
  Serial.println("Slave is found.");
}

void loop()
{
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
  //----------------
  Wire.requestFrom(slaveAddress, 2);
  unsigned int y = Wire.read() << 8 | Wire.read();
  float testVolt = (5.0 / 1023.0) * y;
  Serial.print("Voltage received fromm Slave: ");
  Serial.println(testVolt, 1);
  delay(1000);
}

3. Upload the following sketch into ATtiny85 of the Digispark ATtiny85 Dev Board.

#include<Wire.h>
#define slaveAddress 0x23

void setup() 
{
  Wire.begin(slaveAddress); 
  Wire.onRequest(sendEvent);  
}

void loop() 
{
  delay(5);
}

void sendEvent()
{
  unsigned int y = analogRead(A0);
  Wire.write(highByte(y));
  Wire.write(lowByte(y));
}

4. Press RESET Button of Arduino UNO. Check that the following message has appeared on SM1.

Slave is found.

5. Connect wiper of Pot with (PB5)ADC0-pin of ATtiny85.
6. Rotate the Pot and check that the following readings do appear on SM1.

Voltage received fromm Slave: 3.0
Voltage received fromm Slave: 3.0
Voltage received fromm Slave: 2.7
Voltage received fromm Slave: 3.9
Voltage received fromm Slave: 4.6
Voltage received fromm Slave: 4.9
Voltage received fromm Slave: 5.0

Thanks, I’ll try this out. It’s just a raw attiny chip, but I assume it’ll work the same.

It is very convenient to work if you have a Digispark ATtiny85 Dev Board.

Yes, however I am only using 85s for testing, I will be switching to probably 828s for more analog pins. Trying to keep it affordable as I may have up to 20 of these panels.

The wire library doesn’t work on a raw attiny85. Will wireS or wireM work interchangeably?

I am simply using Wire.h Libray that works for Attiny85. Please, see my post #12.

How many analog channels do you need for each MCU?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.