Arduino Forum

Using Arduino => Microcontrollers => Topic started by: sakurara on Apr 20, 2019, 10:12 pm

Title: ATtiny85 to control Haptic Motor Driver - Adafruit DRV2605L
Post by: sakurara on Apr 20, 2019, 10:12 pm
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.

Code: [Select]

#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;
https://www.instructables.com/id/Using-an-I2C-LCD-on-Attiny85/


If someone can help me to shrink my project, it is really really helpful!
Thank you so much in advance!
Title: Re: ATtiny85 to control Haptic Motor Driver - Adafruit DRV2605L
Post by: Willem43 on Apr 21, 2019, 10:45 am
Which ATtiny core are you using?

Willem.
Title: Re: ATtiny85 to control Haptic Motor Driver - Adafruit DRV2605L
Post by: DrAzzy on Apr 21, 2019, 11:26 pm
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.

https://github.com/SpenceKonde/ATTinyCore (https://github.com/SpenceKonde/ATTinyCore)
Title: Re: ATtiny85 to control Haptic Motor Driver - Adafruit DRV2605L
Post by: sakurara on Apr 22, 2019, 05:32 pm
Which ATtiny core are you using?

Willem.
ATtiny 85 and 45, I tried both
Title: Re: ATtiny85 to control Haptic Motor Driver - Adafruit DRV2605L
Post by: sakurara on Apr 22, 2019, 05:57 pm
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.

https://github.com/SpenceKonde/ATTinyCore (https://github.com/SpenceKonde/ATTinyCore)
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)

https://github.com/SpenceKonde/ATTinyCore/blob/master/Wiring.md



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'>
https://www.instructables.com/id/Program-an-ATtiny-with-Arduino/


Thank you so much for your help!


Title: Re: ATtiny85 to control Haptic Motor Driver - Adafruit DRV2605L
Post by: DrAzzy on Apr 22, 2019, 11:48 pm
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.