SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By tomh
#177555
Hello Everyone,

Im doing a new kind of project where i use a adafruit 3v trinket to read out a MMA8452 accelerometer. I've made the code and it works on a normal Arduino but not on the trinket because of the Wire library.

Do you guys have any idea how i could fix it?

I've tried this code but I've got many errors
Code: Select all
#include <TinyWireM.h> 
#include <SFE_MMA8452Q.h> // Includes the SFE_MMA8452Q library
#include <VirtualWire.h>
char *controller;
MMA8452Q accel;

void setup()
{
  TinyWireM.begin(); 
  accel.init(SCALE_8G, ODR_1);
  vw_set_ptt_inverted(true);
  vw_set_tx_pin(3);
  vw_setup(5000);
}

// The loop function will simply check for new data from the
//  accelerometer and print it out if it's available.
void loop()
{
  // Use the accel.available() function to wait for new data
  //  from the accelerometer.
  if (accel.available())
  {
    // First, use accel.read() to read the new variables:
    accel.read();
    sprintf(controller, "%d %d %d", accel.cx, accel.cy, accel.cz);
    vw_send((uint8_t *)controller, strlen(controller));
    vw_wait_tx();
  }
}
Thanks
Tom
User avatar
By Ross Robotics
#177602
How are we supposed to help if you don't post the errors?
By Mee_n_Mac
#177610
My guess is that the MMA8452Q library is not fully compatible w/the TinyWireM library. As codlink said, post the errors.