Go Down

Topic: ATtiny85 to control Haptic Motor Driver - Adafruit DRV2605L (Read 256 times) previous topic - next topic

sakurara

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!

Willem43


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.

https://github.com/SpenceKonde/ATTinyCore
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

sakurara


sakurara

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


Thank you so much for your help!


DrAzzy

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.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Go Up