ATtiny85 to control Haptic Motor Driver - Adafruit DRV2605L

Hi,

I want to shrink my Arduino to ATtiny as I am working on a wearable project.

I am working on the two bits below.

  • Adafruit DRV2605L motor driver: works fine on Arduino

  • ATtiny85: succeeded in blinking LED

so I wanted to put the code below to ATtiny85, but it is returning an error.

#include <Wire.h>
#include "Adafruit_DRV2605.h"

Adafruit_DRV2605 drv;

void setup() {
  // Serial.begin(9600);
  // Serial.println("DRV2605 Audio responsive test");
  drv.begin();
  drv.setMode(DRV2605_MODE_AUDIOVIBE);

  // ac coupled input, puts in 0.9V bias
  drv.writeRegister8(DRV2605_REG_CONTROL1, 0x20);  
 
  // analog input
  drv.writeRegister8(DRV2605_REG_CONTROL3, 0xA3);  
}

void useLRA();

void loop() {
}

This is exactly the same as the Adafruite library's example, except comment off the serial part as looks like the code doesn't like that part.

The error message says,


〜/libraries/Wire/src/utility/twi.c:76:16: error: 'SDA' undeclared (first use in this function)
digitalWrite(SDA, 1);

〜/libraries/Wire/src/utility/twi.c:77:16: error: 'SCL' undeclared (first use in this function)
digitalWrite(SCL, 1);


omission

〜/libraries/Wire/src/utility/twi.c:426:40: error: 'TWEN' undeclared (first use in this function)
TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
^
exit status 1
Error compiling for board ATtiny25/45/85.


So seems like Wire.h is not working so I downloaded TinyWire libraries and changed the Wire.h to TinyWire.h but it didn't work either.

Also, I thought ATtiny85 comes with SCL and SDA pin as default, is this understanding correct?

"ATtiny85 can simulate I2C on PB2 (pin 7) (SCL) and PB0 (pin 5) (SDA)"

reference;

If someone can help me to shrink my project, it is really really helpful!
Thank you so much in advance!

Which ATtiny core are you using?

Willem.

With attiny cores other than mine, the Wire library doesn't work - you need to use a different library made specifically for hardware on the attiny (which is a USI, not master/slave TWI like the normal ATmega chips have), and then modify the adafruit library to use that library.

Or, you can just use my ATTinyCore, which provides a version of Wire.h which transparently selects the correct implementation of I2C to use for the selected chip, so you CAN do what you're doing and expect it to work without changing anything in the sketch or modifying the library.

Willem43:
Which ATtiny core are you using?

Willem.

ATtiny 85 and 45, I tried both

DrAzzy:
With attiny cores other than mine, the Wire library doesn't work - you need to use a different library made specifically for hardware on the attiny (which is a USI, not master/slave TWI like the normal ATmega chips have), and then modify the adafruit library to use that library.

Or, you can just use my ATTinyCore, which provides a version of Wire.h which transparently selects the correct implementation of I2C to use for the selected chip, so you CAN do what you're doing and expect it to work without changing anything in the sketch or modifying the library.

GitHub - SpenceKonde/ATTinyCore: Arduino core for ATtiny 1634, 828, x313, x4, x41, x5, x61, x7 and x8

Dear DrAzzy,
Thank you so much for this.
I'm now getting "0.1uf ceramic capacitor" for trying your library!

Regarding the wiring,
You mentioned 8 steps here, but for my case, do I only need the first 3 steps for my ATtiny85?
(reference photo attached)

  • Vcc pin(s) connected to supply voltage (1.8~5v depending on part, clock speed, and fuse settings)
  • Gnd pin(s) connected to Ground
  • 0.1uf ceramic capacitor connected between Vcc and Gnd pins, as close to the part as practical.
  • If part has multiple Vcc pins, there should be 0.1uf cap from each one to ground, right next to the chip.
  • If part has an AVcc pin, that should be connected to Vcc.
  • If part has an AGnd pin, that should be connected to Gnd.
  • If part has an AVcc pin and an AGnd pin, 0.1uf ceramic capacitor between AVcc and AGnd, right next to the chip.
  • if part has an AVcc pin but no AGnd pin, 0.1uf cerapic capacitor between AVcc and Gnd, right next to the chip.

Or, should I follow the normal way to wire and upload the sketch as below and chose the ATTinyCore - ATtiny45/85 (Optiboot) from the board menu?
<the tutorial I was following as 'normal way'>

Thank you so much for your help!

If you are planning to program with an ISP programmer, choose the no bootloader option. If you are planning to upload with a serial adapter, choose the Optiboot version (this will reduce available space for the sketch). Either way, on a fresh chip, you must do "burn bootloader" - even if not using a bootloader, this step is needed in order to set the fuses, which determine clock source and BOD setting.

Correct, only the first three apply to the Tiny85.