ACS712.h (Rob Tillaert) and ATtiny85 (Digispark) setup

I have this most useful library by Rob Tillaert adapted for a specific use in short-circuit detection, using an ATmega328P (Atmega168P would also work).

I would now like to use this program on an ATtiny85 (more specifically a Digispark pcb).

Only three pins are required: two digital out and one analog in.

I know that a Digispark has double use for PB4 and PB3 (USB interface), PB5 is used for RST, leaving PB2 (A1) for the analog input.

The ACS712.h library uses this syntax for its configuration:

ACS712  ACS(A0, 5.0, 1023, 185);

..where the first variable designates the analog pin on which to read the ACS712 signal.

What value must this variable be given so as for the library to read from an ATtiny85 PB2 (A1)?
Below is the code, where two digital outputs already are assigned to PB0 ('relay') and PB1 ('led').

#include "ACS712.h"
#define relay 0
#define led 1
bool relayState = false;

//  Arduino UNO has 5.0 volt with a max ADC value of 1023 steps
//  ACS712 5A  uses 185 mV per A
//  ACS712 20A uses 100 mV per A
//  ACS712 30A uses  66 mV per A

ACS712  ACS(A0, 5.0, 1023, 185);
//  ESP 32 example (might requires resistors to step down the logic voltage)
//  ACS712  ACS(25, 3.3, 4095, 185);

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  Serial.println(__FILE__);
  Serial.print("ACS712_LIB_VERSION: ");
  Serial.println(ACS712_LIB_VERSION);

  ACS.autoMidPoint();
  //  Serial.println(ACS.getMidPoint());
  pinMode(relay, OUTPUT);
  pinMode(led, OUTPUT);
}

void loop()
{
  int mA = abs(ACS.mA_AC());
  Serial.println(mA);    // comment out to increase loop speed

  if (mA > 1500 && relayState == false)
  {
    digitalWrite(relay, HIGH);
    digitalWrite(led, HIGH);
    relayState = true;
    delay(500);
  }
  else if (mA > 1500 && relayState == true)
  {
    digitalWrite(relay, LOW);
    digitalWrite(led, LOW);
    relayState = false;
    delay(500);
  }
}

A1.

1 Like

Thank you!
I somehow suspected that but I'd better get confirmation from a knowledgeable source.

I based that on the assumption that you are using the ATtinyCore and you have selected the ATtiny85

1 Like

Yes I do.

Edit: I use ISP (with AVRdudess v8.0 and usbtiny) and no bootloader

Then you are all set
Have a nice day!

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