I am using the normal adafruit Trinket(5V) with the MMA8542 breakout board from Sparkfun. Because the trinket has an ATtiny chip inside it requires the TinyWire Library. Unfortunately I am unable to read data from the sensor.
The connections are the following:
- #0-->330ohm-->SDA
- #2-->330ohm-->SCL
The accelerometer is also powered by a regulated 3.3V source.
Here is the code that I adapted from one of the examples provided with the TinyWire.h library. I am not getting anything from the sensor. If anyone can help it would be greatly appreciated.
#define I2C_ADDR 0x1D // Edit if backpack A0/A1 jumpers set
#include <TinyWireM.h>
//#include <SFE_MMA8452Q.h>
#include <USI_TWI_Master.h>
int acc= 0;
int led = 1; // blink 'digital' pin 1 - AKA the built in red LED
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
TinyWireM.begin();
}
void loop() {
// put your main code here, to run repeatedly:
Get_acc();
if (acc!= 0) {
digitalWrite(led,HIGH); //using the LED as a visual output
}
}
void Get_acc(){ // Get the temperature from a DS1621
int acc;
TinyWireM.beginTransmission(I2C_ADDR);
TinyWireM.send(0xEE); // if one-shot, start conversions now
TinyWireM.endTransmission(); // Send 1 byte to the slave
delay(750); // if one-shot, must wait ~750 ms for conversion
TinyWireM.beginTransmission(I2C_ADDR);
TinyWireM.send(0xAA); // read temperature (for either mode)
TinyWireM.endTransmission(); // Send 1 byte to the slave
TinyWireM.requestFrom(I2C_ADDR,1); // Request 1 byte from slave
acc = TinyWireM.receive(); // get the temperature
}