Show Posts
Pages: [1]
1  Using Arduino / Sensors / Re: how to use a mma7361 accelerometer what is wrong? on: January 28, 2014, 09:52:17 am
Maybe this can help future readers
https://code.google.com/p/mma7361-library/
2  Forum 2005-2010 (read only) / Troubleshooting / I2C problem wire.available returns 0 on: December 14, 2010, 12:01:54 pm
Hello,
I'm using an ITG3200 sparkfun breakout board gyroscope. I have the problem that after a variable number of wire commando's my wire.available returns 0. Mostly the number of commando's is not more than 1000. what can cause this?

part of the library i'm using, it get's stuck in the while statement
Code:
byte ITG3200::read(byte reg) {
  Wire.beginTransmission(_gyro_address);
  Wire.send(reg);
  Wire.endTransmission();
  Wire.beginTransmission(_gyro_address);
  Wire.requestFrom(_gyro_address, 1);
  while (Wire.available() == 0) {
  }; // block unil data is available
  byte buf = Wire.receive();
  Wire.endTransmission();
  return buf;
}

The weird thing is that it first returns data and then stops and then sometimes it works for a really long time(like 2 hrs or more)
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: C++ problem with classes on: December 03, 2010, 11:16:17 am
ok I think I got it, thank you very much PaulS
c++ basics are far away after not writing any code for some time :-)
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: C++ problem with classes on: December 03, 2010, 11:07:20 am
so i should make it a global variable?
or a private member?
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: C++ problem with classes on: December 03, 2010, 11:00:35 am
I meant the arguments that accelero.begin(...) takes
Will they remain so accelero in getSide still knows the parameters (pin numbers in this case)
Code:
AcceleroDice::AcceleroDice(int sleepPin, int selfTestPin, int zeroGPin, int xPin, int yPin, int zPin, int xOffset, int yOffset, int zOffset)
{
  AcceleroMMA7361 accelero;
  accelero.begin(13, 12, 11, A0, A1, A2, 5, -40, 20);
6  Forum 2005-2010 (read only) / Syntax & Programs / Re: C++ problem with classes on: December 03, 2010, 10:38:22 am
So, if I'm correct I should call the "AcceleroMMA7361 accelero;" constructor in "int AcceleroDice::getSide()" and in AcceleroDice::AcceleroDice
But do the arguments as sleepPin remain??
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: C++ problem with classes on: December 03, 2010, 09:55:35 am
Hi, I'm having a similar problem, therefor reusing this thread

I want to use a library i previously created in a new library i'm creating.

in the new library's constructor I call the old library's constructor.

But then I can't use the old library's function in the new library's functions

New library constructor
Code:
AcceleroDice::AcceleroDice(int sleepPin, int selfTestPin, int zeroGPin, int xPin, int yPin, int zPin, int xOffset, int yOffset, int zOffset)
{
  AcceleroMMA7361 accelero (13, 12, 11, A0, A1, A2, 5, -40, 20);
  ArrayDataAnalyse arrayDataAnalyse;
  int _diceTreshold = 35;
  int _side = 0;
  int _lastSide = 0;
  ...
}

Code:
int AcceleroDice::getSide()
{
  try
  {
    int i =0;
    while (_j<_average*2)
    {
      _x = accelero.getXAccel();
      _y = accelero.getYAccel();
      _z = accelero.getZAccel();
...
do i have to construct the old libary every time i use the function getSide or is there a way how i can do it only once (and of course if there is such a way is it better to use?)

compiler returned this btw
AcceleroDice.cpp: In member function 'int AcceleroDice::getSide()':
AcceleroDice.cpp:65: error: 'accelero' was not declared in this scope
8  Forum 2005-2010 (read only) / Development / Re: Library for Accelerometer MMA7361 on: December 22, 2010, 12:26:24 pm
@lebenj
I connected the sparkfun GSEL pin directly to the 3.3V which gave no problem. When your application is only for testing I dont think you need your resistor. But when your finishing your prototype I bet it's better to be on the safe side and use the resistor.
So i don't recommend doing it (it's comparable to short circuiting a fuse in your household, as long as everthing is fine it works but when something screws up, it screws up bad)

@BroHogan: at the moment I'm adding a simple callibrate function and a setpolarity function, also reworking the offsets so they have effect on the raw data instead of the G's
9  Forum 2005-2010 (read only) / Development / Re: Library for Accelerometer MMA7361 on: December 22, 2010, 11:06:34 am
Currently working on the AREF version. The 1.5G mode will come later. I expect it to be fully mature half of januari.
10  Forum 2005-2010 (read only) / Development / Re: Library for Accelerometer MMA7361 on: December 09, 2010, 12:19:46 pm
I can only modify my last post. Anyhow here is a small update already. I'm planning to add the 1,5G sensitivity via a setSensitivity() function, later this year.


Revision History

Version 0.1: get raw values
Version 0.2: get voltages and G forces
Version 0.3: removed begin parameters offset, added public function setOffSets(int,int,int) added a private variable _offSets[3] containing the offset on each axis changed the long and double return values of private and public functions to int

new header file

Code:
/**************************************************************************************************
 * acceleroMMA7361.h - Library for retrieving data from the MMA7361 accelerometer. Only tested         *
 * with Duemilanove                                                                               *
 * Following functions need improving. I asumed the output to be linear (it is nearly linear but  *
 * not really). I also asumed the Arduino input to be scaled 0-5V                                 *
 * I also 'hard pinned' the G-Selector pin to 6G mode (HIGH) so nothing can be found here about   *
 * 1.5G sensitivity this will be fixed in later versions                                          *
 * begin variables                                                                                *
 *  -int sleepPin: number indicating to which pin the sleep port is attached. DIGITAL OUT         *
 *  -int selfTestPin: number indicating to which pin the selftest port is attached.DIGITAL OUT    *
 *  -int zeroGPin: number indicating to which pin the ZeroGpin is connected to. DIGITAL IN        *
 *  -int xPin: number indicating to which pin the x-axis pin is connected to. ANALOG IN           *
 *  -int yPin: number indicating to which pin the y-axis  pin is connected to. ANALOG IN          *
 *  -int zPin: number indicating to which pin the z-axis  pin is connected to. ANALOG IN          *
 *                                                                                                *
 * Functions currently present:                                                                   *
 *  -getXRaw(): Instantly returns the raw data from the X-axis analog I/O port of the Arduino as  *
 *    a int. WARNING! OFFSET HAS NO INFLUENCE                                                     *
 *  -getYRaw(): Instantly returns the raw data from the Y-axis analog I/O port of the Arduino as  *
 *    a int. WARNING! OFFSET HAS NO INFLUENCE                                                     *
 *  -getZRaw(): Instantly returns the raw data from the Z-axis analog I/O port of the Arduino as  *
 *    a int. WARNING! OFFSET HAS NO INFLUENCE                                                     *
 *  -getXVolt(): Instantly returns the voltage in miliVolts from the X-axis analog I/O port of    *
 *    the Arduino as a int. WARNING! OFFSET HAS NO INFLUENCE                                      *
 *  -getYVolt(): Instantly returns the voltage in miliVolts from the Y-axis analog I/O port of    *
 *    the Arduino as a int. WARNING! OFFSET HAS NO INFLUENCE                                      *
 *  -getZVolt(): Instantly returns the voltage in miliVolts from the Z-axis analog I/O port of    *
 *    the Arduino as a int. WARNING! OFFSET HAS NO INFLUENCE                                      *
 *  -getXAccel(): Instantly returns the acceleration of the X-axis as a int (1G = 100.00)         *
 *  -getYAccel(): Instantly returns the acceleration of the Y-axis as a int (1G = 100.00)         *
 *  -getXAccel(): Instantly returns the acceleration of the Z-axis as a int (1G = 100.00)         *
 *  -setOffSets( int offSetX, int offSetY, int offSetZ):                                          *
 **************************************************************************************************
 * Revision History:                                                                              *
 *  Version 0.1: get raw values                                                                   *
 *  Version 0.2: get voltages and G forces                                                        *
 *  Version 0.3: removed begin parameters offset, added public function setOffSets(int,int,int)   *
 *               added a private variable _offSets[3] containing the offset on each axis          *
 *               changed the long and double return values of private and public functions to int *
 **************************************************************************************************
 * Created by Jef Neefs: Suggestions, questions or comments please contact me                     *
 *  -mail: neefsj at gmail dot com                                                                *
 *  -skype: studioj                                                                               *
 **************************************************************************************************/
#ifndef AcceleroMMA7361_h
#define AcceleroMMA7361_h
#include <WProgram.h>

class AcceleroMMA7361
{
  public:
    AcceleroMMA7361();
    void begin(int sleepPin, int selfTestPin, int zeroGPin, int xPin, int yPin, int zPin);
    int getXRaw();
    int getYRaw();
    int getZRaw();
    int getXVolt();
    int getYVolt();
    int getZVolt();
    int getXAccel();
    int getYAccel();
    int getZAccel();
    int getTotalVector();
      void setOffSets(int xOffSet, int yOffSet, int zOffSet);
      
  private:
      int _mapMMA7361V(int value);
      int _mapMMA7361G(int value);
    int _sleepPin;
      int _selfTestPin;
      int _zeroGPin;
      int _xPin;
      int _yPin;
      int _zPin;
      int _offSets[3];
};
#endif


cpp
Code:
#include <WProgram.h>
#include <AcceleroMMA7361.h>

AcceleroMMA7361::AcceleroMMA7361()
{
}

void AcceleroMMA7361::begin(int sleepPin, int selfTestPin, int zeroGPin, int xPin, int yPin, int zPin)
{
  pinMode(sleepPin, OUTPUT);
  pinMode(selfTestPin, OUTPUT);
  pinMode(zeroGPin, INPUT);
  pinMode(xPin, INPUT);
  pinMode(yPin, INPUT);
  pinMode(zPin, INPUT);
  digitalWrite(sleepPin,HIGH);
  digitalWrite(selfTestPin,LOW);
  _sleepPin = sleepPin;
  _selfTestPin = selfTestPin;
  _zeroGPin = zeroGPin;
  _xPin = xPin;
  _yPin = yPin;
  _zPin = zPin;
  setOffSets(0,0,0);
}

void AcceleroMMA7361::setOffSets(int xOffSet, int yOffSet, int zOffSet)
{
  _offSets[0]= xOffSet;
  _offSets[1]= yOffSet;
  _offSets[2]= zOffSet;
}

int AcceleroMMA7361::getXRaw()
{
  return analogRead(_xPin);
}

int AcceleroMMA7361::getYRaw()
{
  return analogRead(_yPin);
}

int AcceleroMMA7361::getZRaw()
{
  return analogRead(_zPin);
}

int AcceleroMMA7361::getXVolt()
{
  return _mapMMA7361V(analogRead(_xPin));
}

int AcceleroMMA7361::getYVolt()
{
  return _mapMMA7361V(analogRead(_yPin));
}

int AcceleroMMA7361::getZVolt()
{
  return _mapMMA7361V(analogRead(_zPin));
}

int AcceleroMMA7361::getXAccel()
{
  return _mapMMA7361G(analogRead(_xPin))+ _offSets[0];
}

int AcceleroMMA7361::getYAccel()
{
  return _mapMMA7361G(analogRead(_yPin)) + _offSets[1];
}

int AcceleroMMA7361::getZAccel()
{
  return _mapMMA7361G(analogRead(_zPin)) + _offSets[2];
}

int AcceleroMMA7361::_mapMMA7361V(int value)
{
  return map(value,0,1024,0,5000);
}

int AcceleroMMA7361::_mapMMA7361G(int value)
{
  return map(value,0,1024,-800,1600);
}

download library http://rapidshare.com/files/435911796/AcceleroMMA7361v0_3.zip

BroHogan you had some code to share?
11  Forum 2005-2010 (read only) / Development / Re: Library for Accelerometer MMA7361 on: December 08, 2010, 03:03:35 pm
@ Senso and BroHogan

I was expecting comments and improvements. I'm definitly not the best programmer in the world :-) but i felt people could be helped by a library. Therefore, any help, hints or tips for improvement are happily received.

I used the sparkfun breakout board btw
12  Forum 2005-2010 (read only) / Development / Re: Library for Accelerometer MMA7361 on: December 08, 2010, 02:55:20 am
Quote
- Looks like you assume it will be run at 5V.  3.3V gives more accuracy.

I assume 3.3V working voltage BUT the axis all attached to a 0-5 analog input gate. can i change the input gate itself? otherwise 0-1023 equals 0-5V

Quote
- Maybe you should have a param for the Aref voltage.

maybe yes (do you mean parameterwise change the input gates from 0-5V to 0-3.3V)
i do feel i have alot parameters already

Quote
- That accel has 2 sensitives - 1.5/6g. Looks like you expect 1g max.


I set it to 6G sensitivity, thats not mentioned in the header comment indeed.
Code:
long AcceleroMMA7361::_mapMMA7361G(int value)
{
  return map(value,0,1024,-800,1600);
}

that function maps 0-5V volt to from -8G to +16G (as the output voltage of the MMA7361 will off course never reach those values) therefor 6G = 3.3V


Quote
- Not sure how you calc g - (1 g = 9.80665 m/s2)
I think i answered this in the above question

Quote
(Not to crazy about the site that hosting your zip. You should check out "Dropbox".)
I feel ok using this host

Quote
I've been messing with an example for the MMA7361. If there is any interest, I can post it.
Of course there is no point sharing a lib if it is not open for input

Thank you for your comments I'll post version 0.3 maybe later today
13  Forum 2005-2010 (read only) / Development / Re: Library for Accelerometer MMA7361 on: December 07, 2010, 06:09:45 am
in the zip are examples as wel as a keyword.txt present.

I dont know where I should put this in the playground, there are several places where I could put it.

b.e. "Interfacing with Hardware or "Code Library and Tutorials"...
14  Forum 2005-2010 (read only) / Development / Library for Accelerometer MMA7361 on: December 07, 2010, 05:31:43 am
Hello people,

I'm posting my first library. It's a library for the MMA7361 accelerometer. I hope this is the correct way to share libraries

Since no library was available I believed posting mine would help some people.

I'm always open for suggestions since this is my first library I expect it not to be perfect.

available for download http://rapidshare.com/files/435429883/AcceleroMMA7361.zip

header file
Code:
/**************************************************************************************************
 * acceleroMMA7361.h - Library for retrieving data from the MMA7361 accelerometer. Only tested         *
 * with Duemilanove                                                                               *
 * Following functions need improving. I asumed the output to be linear (it is nearly linear but  *
 * not really). I also asumed the Arduino input to be scaled 0-5V                                 *
 * begin variables                                                                                *
 *       -int sleepPin: number indicating to which pin the sleep port is attached. DIGITAL OUT         *
 *      -int selfTestPin: number indicating to which pin the selftest port is attached.DIGITAL OUT    *
 *      -int zeroGPin: number indicating to which pin the ZeroGpin is connected to. DIGITAL IN        *
 *      -int xPin: number indicating to which pin the x-axis pin is connected to. ANALOG IN           *
 *      -int yPin: number indicating to which pin the y-axis  pin is connected to. ANALOG IN          *
 *      -int zPin: number indicating to which pin the z-axis  pin is connected to. ANALOG IN          *
 *      -int offset: array indicating the G offset on the x,y and z-axis                              *
 * Functions currently present:                                                                   *
 *  -getXRaw(): Instantly returns the raw data from the X-axis analog I/O port of the Arduino as  *
 *    a double. WARNING! OFFSET HAS NO INFLUENCE                                                  *
 *  -getYRaw(): Instantly returns the raw data from the Y-axis analog I/O port of the Arduino as  *
 *    a double. WARNING! OFFSET HAS NO INFLUENCE                                                  *
 *  -getZRaw(): Instantly returns the raw data from the Z-axis analog I/O port of the Arduino as  *
 *    a double. WARNING! OFFSET HAS NO INFLUENCE                                                  *
 *  -getXVolt(): Instantly returns the voltage in miliVolts from the X-axis analog I/O port of    *
 *    the Arduino as a double. WARNING! OFFSET HAS NO INFLUENCE                                   *
 *  -getYVolt(): Instantly returns the voltage in miliVolts from the Y-axis analog I/O port of    *
 *    the Arduino as a double. WARNING! OFFSET HAS NO INFLUENCE                                   *
 *  -getZVolt(): Instantly returns the voltage in miliVolts from the Z-axis analog I/O port of    *
 *    the Arduino as a double. WARNING! OFFSET HAS NO INFLUENCE                                   *
 *  -getXAccel(): Instantly returns the acceleration of the X-axis as a double (1G = 100.00)      *
 *  -getYAccel(): Instantly returns the acceleration of the Y-axis as a double (1G = 100.00)      *
 *  -getXAccel(): Instantly returns the acceleration of the Z-axis as a double (1G = 100.00)      *
 **************************************************************************************************
 * Revision History:                                                                              *
 *  Version 0.1: get raw values                                                                   *
 *  Version 0.2: get voltages and G forces                                                        *
 **************************************************************************************************
 * Created by Jef Neefs: Suggestions, questions or comments please contact me                     *
 * - mail: neefsj at gmail dot com                                                                *
 * - skype: studioj                                                                               *
 **************************************************************************************************/
#ifndef AcceleroMMA7361_h
#define AcceleroMMA7361_h
#include <WProgram.h>

class AcceleroMMA7361
{
  public:
    AcceleroMMA7361();
    void begin(int sleepPin, int selfTestPin, int zeroGPin, int xPin, int yPin, int zPin, int xOffset, int yOffset, int zOffset);
    double getXRaw();
    double getYRaw();
    double getZRaw();
    double getXVolt();
    double getYVolt();
    double getZVolt();
    double getXAccel();
    double getYAccel();
    double getZAccel();
    double getTotalVector();
      
  private:
      long _mapMMA7361V(int value);
      long _mapMMA7361G(int value);
    int _sleepPin;
      int _selfTestPin;
      int _zeroGPin;
      int _xPin;
      int _yPin;
      int _zPin;
      int _xOffset;
      int _yOffset;
      int _zOffset;
};
#endif

cpp file
Code:
comment header as in h file is left away
#include <WProgram.h>
#include <AcceleroMMA7361.h>

AcceleroMMA7361::AcceleroMMA7361()
{
}

void AcceleroMMA7361::begin(int sleepPin, int selfTestPin, int zeroGPin, int xPin, int yPin, int zPin, int xOffset, int yOffset, int zOffset)
{
  pinMode(sleepPin, OUTPUT);
  pinMode(selfTestPin, OUTPUT);
  pinMode(zeroGPin, INPUT);
  pinMode(xPin, INPUT);
  pinMode(yPin, INPUT);
  pinMode(zPin, INPUT);
  digitalWrite(sleepPin,HIGH);
  digitalWrite(selfTestPin,LOW);
  _sleepPin = sleepPin;
  _selfTestPin = selfTestPin;
  _zeroGPin = zeroGPin;
  _xPin = xPin;
  _yPin = yPin;
  _zPin = zPin;
  _xOffset = xOffset;
  _yOffset = yOffset;
  _zOffset = zOffset;
}

double AcceleroMMA7361::getXRaw()
{
  return analogRead(_xPin);
}

double AcceleroMMA7361::getYRaw()
{
  return analogRead(_yPin);
}

double AcceleroMMA7361::getZRaw()
{
  return analogRead(_zPin);
}

double AcceleroMMA7361::getXVolt()
{
  return _mapMMA7361V(analogRead(_xPin));
}

double AcceleroMMA7361::getYVolt()
{
  return _mapMMA7361V(analogRead(_yPin));
}

double AcceleroMMA7361::getZVolt()
{
  return _mapMMA7361V(analogRead(_zPin));
}

double AcceleroMMA7361::getXAccel()
{
  return _mapMMA7361G(analogRead(_xPin))+ _xOffset;
}

double AcceleroMMA7361::getYAccel()
{
  return _mapMMA7361G(analogRead(_yPin)) + _yOffset;
}

double AcceleroMMA7361::getZAccel()
{
  return _mapMMA7361G(analogRead(_zPin)) + _zOffset;
}

long AcceleroMMA7361::_mapMMA7361V(int value)
{
  return map(value,0,1024,0,5000);
}

long AcceleroMMA7361::_mapMMA7361G(int value)
{
  return map(value,0,1024,-800,1600);
}
Pages: [1]