I am trying to connect the MMA8452Q with AtTiny85 using the TinyWireM library. I made the proper hardware setup with pull-ups on SCL and SDA pins - tested it on Arduino Uno and it works, however when i connect the Tiny I cannot even get the handshake. The following code produces output 13 instead of 42 (0x2A)


MMA8452 Breakout ------------AtTiny85

3.3V -------voltage regulator------ 5V

SDA -----------^^(330)^^----------- PB0 (on attiny programmer marked as 5)

SCL -----------^^(330)^^----------- PB3 (on attiny programmer marked as 2)

GND --------------------------------- GND

(I also tried different pins with no luck)


//---bluetooth console communication stuff---//
#include <SoftwareSerial.h>
#define rxPin 1 //not important - needed for initialization
#define txPin A2
SoftwareSerial blueTooth(rxPin, txPin);
//      ---     //

#include "TinyWireM.h" // Used for I2C

// The SparkFun breakout board defaults to 1, set to 0 if SA0 jumper on the bottom of the board is set
#define MMA8452_ADDRESS 0x1D  // 0x1D if SA0 is high, 0x1C if low

#define WHO_AM_I   0x0D

void setup() {

  TinyWireM.begin(); //Join the bus as a master

void loop() {
   byte c =0;
   c = readRegister(WHO_AM_I); 

 // Read a single byte from addressToRead and return it as a byte
byte readRegister(byte addressToRead) {
  TinyWireM.endTransmission(); //endTransmission but keep the connection active

  TinyWireM.requestFrom(MMA8452_ADDRESS, 1); //Ask for 1 byte, once done, bus is released by default

  while(!TinyWireM.available()) ; //Wait for the data to come back
  return TinyWireM.receive(); //Return this one byte

Would anyone know how to get it right?

  • I2C pullup resistors are 4.7 kohm to Vcc (at 5V). SCL is PB2 (chip pin 7) and SDA is PB0 (chip pin 5). Commented Aug 7, 2017 at 14:11
  • 1
    changed the resistors. still getting the same output
    – Chris
    Commented Aug 9, 2017 at 17:52

2 Answers 2


On an ATtiny85 pin 5 (PB0) is SDA and pin 7 (PB2) is SCL for the I2C interface. You're using the wrong pin for SCL.

Additionally, your pull-up resistors are too strong. Somewhere between 4.7K Ohm and 10K Ohm are recommended for pull-up's on the SDA and SCL lines.


using the TinyWireM library.

Make sure the i2c actually works. Arduino libraries are generally of poor quality and just because someone wrote it doesn't mean it actually works. Get a logic analyzer or scope on the bus and see what's going on.

Once you can confirm that, get a datasheet for the 8452 and see how it works and code to it.

  • i tried doing what you suggested and also tried pluging i2c attiny as slave to uno as master. did not work either. Generally what i get on oscillator is some mess different than what i get when plugging uno. On uno i get nice square waves on clock and digital signals on sda. i ran some tests and used the pb0 and pb2 and pb3 pins on attiny for serial communication so the pins work (i guess?). Could it still be the chip problem? It seems that many folks succeed with using TinyWireM as i2c library... i dont know where to go from here
    – Chris
    Commented Aug 9, 2017 at 18:00
  • i scanned for i2c devices and it detects an i2c device at each address it scans... so weird
    – Chris
    Commented Aug 10, 2017 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.