ADXL335 analog ACC

Post Reply
cob
Posts: 37
Joined: Thu Jul 07, 2011 12:00 am

ADXL335 analog ACC

Post by cob »

Hi all,
Being not acquainted with Wii I ordered by mistake a WII RemotePlus. It is serial BGW22-4 dated 2010-07-22. I also ordered a first Nck, not finding anything looking like and ACC on it. I discovered the thing I needed was a Motion Plus and not a Remote Plus. So I got one of the clone Motion Plus with 2 Invenses classic Gyros on it. The second Nck was not working. So I ordered another one. Bad luck! Not working either. But, on the Wii Remote there is a nice ADXL335! By the way the two Nck were equipped with a MMA6631 and MMA7660. Useless as one is only 2 axis and the other is analog ACC outperformed by the ADXL335.
I used the ADXL335 on analog input A1-A2-A3 and it works. But I suspected a problem. Here it is:
Due to 3.3V for ADXL335, the reading of the values is not correct. I adapted some code from Sparkfun and modified the MWII soft that way:

After multiple test, I came back to original vlaues for ADC ACC as I had too much sensitivity. Vibration were more important than usable signal. So the original code for ADCACC in Sensors.pde is the one valid. Main change is is config.h where orientation is corrected, the chip being oriented as per datasheet, so here in config.h :

Code: Select all

/* ADC accelerometer */
 //for 5DOF from sparkfun, uses analog PIN A1/A2/A3 - by uncommenting this you loose CAMSTAB
//#define ADCACC
#define ADXL335 //Added to adjust and scale up analog output of ADXL335 as it is on 3.3V
//if you want to change to orientation of individual sensor
#define ACC_ORIENTATION(X, Y, Z)  {accADC[ROLL]  =  Y; accADC[PITCH]  = -X; accADC[YAW]  = Z;}
//#define GYRO_ORIENTATION(X, Y, Z) {gyroADC[ROLL] = -Y; gyroADC[PITCH] =  X; gyroADC[YAW] = Z;}
//#define MAG_ORIENTATION(X, Y, Z)  {magADC[ROLL]  = X; magADC[PITCH]  = Y; magADC[YAW]  = Z;}

in def.h :

Code: Select all

#if defined(ADXL335) || defined(ADXL345) || defined(BMA020) || defined(BMA180) || defined(NUNCHACK) || defined(ADCACC)
  #define ACC 1
#else
  #define ACC 0
#endif


a line to change if needed the CMPF FACTOR only for ADX335 without touching other ADCACCs in IMU.pde :

Code: Select all

/* Set the Gyro Weight for Gyro/Acc complementary filter */
/* Increasing this value would reduce and delay Acc influence on the output of the filter*/
/* Default WMC value: 300/ previous value 310.0f*/
#if defined (ADXL335)
#define GYR_CMPF_FACTOR 310.0f
#else
#define GYR_CMPF_FACTOR 310.0f
#endif


in Sensors.pde before ADCACC:

Code: Select all

// ************************************************************************************************************
// ADXL335 ACC  was a try to get more sensitivity, useless too much noise and vibrations & already cared for in the original code.
// ************************************************************************************************************

// ************************************************************************************************************
// ADC ACC
// ************************************************************************************************************

#if defined (ADCACC) || defined (ADXL335)
void ACC_init(){
  pinMode(A1,INPUT);
  pinMode(A2,INPUT);
  pinMode(A3,INPUT);
  acc_1G = 426; //acc_1G is the value of ACCZ when the multi is perfectly flat.
}

void ACC_getADC() {
  ACC_ORIENTATION( -analogRead(A1) ,
                   -analogRead(A2) ,
                    analogRead(A3) );
  ACC_Common();
}
#endif

It gives normal ACC reading on the GUI and efficient in LEVEL Mode.

Regards
Last edited by cob on Tue Aug 02, 2011 11:44 am, edited 8 times in total.

demands
Posts: 35
Joined: Fri Jul 22, 2011 8:59 am
Location: Linköping, Sweden

Re: ADXL335 analog ACC

Post by demands »

Just tested your code...
Seems to be working good...
One question though, are you using this with or without 3.3v AREF??
I tested without AREF, which seems to be working (resolution is so-so)...
With AREF, nothing's working, the Tx on Duemi stops working if I have 3.3v AREF...

Since my ADXL335 is part of a 6dof Razor (http://www.sparkfun.com/products/10010), next step for me is to get the analog gyro working...

cob
Posts: 37
Joined: Thu Jul 07, 2011 12:00 am

Re: ADXL335 analog ACC

Post by cob »

I changed the acc orientation as I saw today it was wrong on the GUI. The code above in my first post has been corrected.
Attached is a shema of ADXL335 and its output pins as per data sheet.

I'm sorry I don't use the AREF pin. I have a 3.3V reg on which the ADXL335 is connected.
As far as I've seen on pin 12 it gives out 4.4 V used with Multiwii. Too much for ADXL335.
VCC pin gives 5.1 V
I'm using an Arduino ProMini (ATMEL 328) 16MHz 5V

May be you should find a regulator 3.3 V :roll:
ADXL335.jpg
(19.96 KiB) Not downloaded yet

demands
Posts: 35
Joined: Fri Jul 22, 2011 8:59 am
Location: Linköping, Sweden

Re: ADXL335 analog ACC

Post by demands »

New code looks good, I have acc X = A1, acc Y = A2 and acc Z = A3...
I'm currently using Arduino Duemilanove, which has a regulated 3.3v...
I think everything looks good (remember my noobie status :) ) in MWConf GUI, although the animations are very very slow compared to when I turn the the breadboard, and only show half of how I turn it (90deg only displays as ~45deg in MWConf animation)...
At least everything is turning in the right direction (I think :? )

But looking at the line graph, and the actual values, they're changing immediatly when I move the prototype, and the resolution looks good...
Could you please confirm some values measured:

Lying flat on the ground:
ROLL = 0
PITCH = 0
Z = ~420

90deg PITCH (pointing straight to heaven)
ROLL = 0
PITCH = -190
Z = ~240

90deg ROLL (turn breadboard 90deg right, up on its edge)
ROLL = 190
PITCH = 0
Z = ~220

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: ADXL335 analog ACC

Post by ziss_dm »

Hi cob,
I do not think you need to scale values or shift zero point, the current WMC code should handle it automatically during ACC calibration. You need only to specify correct acc_1G value.
This should be enough to make EstimateAttitude() procedure work correctly (I'm assuming we are talking about current dev. version)


regards,
ziss_dm

cob
Posts: 37
Joined: Thu Jul 07, 2011 12:00 am

Re: ADXL335 analog ACC

Post by cob »

Yes ziss_dm, you are totally right! Thanks for caring ;)
After multiple tests and try I reverted back to standard ADCACC and corrected the first post. The reason I went on that is very tiny readings on the Gui on the 1.0x scale, having to magnify at least 3x to see correctly. I'm using the very last dev where files are mostly dated 20110721. (in "trunk" folder Google code).

The acc value for Z axis is 426 on my ADXL335, 331 for x and y . So I use 426.

Hi demands, the only thing you need to do is set acc_1G value and check orientation of the chip. The former post n°1 I did has been updated and is reverted back to original code for Analog Acc.

regards

demands
Posts: 35
Joined: Fri Jul 22, 2011 8:59 am
Location: Linköping, Sweden

Re: ADXL335 analog ACC

Post by demands »

Just reverted back to original ADCACC code, though setting acc_1g to 68 as proposed in this thread: viewtopic.php?f=8&t=561
Worked perfectly, I'd suggest you read the thread... It turned into a "acc_1g for Z axis on ADXL335"-thread ;)
Well, the axis' seems inverted, but thats easily fixed...

Thanks!

cob
Posts: 37
Joined: Thu Jul 07, 2011 12:00 am

Re: ADXL335 analog ACC

Post by cob »

Still doesn't make much sense to me, but thank you demands for having digged into that.
Probably the acc_1g calculation (426-290/2) is peculiar to the math involved in the code.
True enough it works perfectly that way.

Post Reply