PICAXE 18M+ and MMA7455 3-Axis Accelerometer Module
Hi all, I am new to PICAXE and PARALLAX and trying to learn how to use the I2C bus to talk to a MMA7455 Accelerometer with a PICAXE 18M+. Probably not the easiest thing for a newbie to try, but, like the idea of using communications. As I have never used Arduino or any other platform, trying with Picaxe Basic programming as that is what I have been using. Please, does anyone have a routine written in Basic that I can use to start with to read the X, Y and Z axis and use. Finally have the DEBUG function and cable working with the picaxe so now looking forward to trying this then other parallax modules. Just need help to get my first I2C away and understand the process. Yes, I am about a one week novice, but want to get my teeth into this thing and the few routines I wrote seem to do nothing, so prefer a baseline to modify, all help appreciated.Next will be the Sensor Sampler Pack if I can just get this worked out.
Comments
You can try and adapt the BasicStamp Basic program to the PICAXE.
http://www.parallax.com/downloads/mma7455-3-axis-accelerometer-basic-stamp-demo-code
Although someone here might be versed with PICAXE, these forums cater to Parallax microcontrollers.
As a beginner, I think this is way too much to take on as an early project. But if you're persistent, you may be able to get it to work by seeing what others have done. Doing a quick Google search turned up the following page near the top:
http://husstechlabs.com/support/tutorials/triple-axis-acceleroemter-with-picaxe/
It's for a different accelerometer chipset than yours, but the example code demonstrates the general process.
While you may be using Parallax's MMA7455 module, it's a common component, so examples you may find don't have to be the exact same one as yours.
***
THANKS, I had found that and did modify the code but the numbers never change and no errors show up. I will try a bit more persistance with that code and see if it will work or not.
I had hoped a parallax forum member had used this chip who was also a picaxe user - let me try some more code changes. Thanks all for any positive response.
A) You're not using the right I2C address for the device. The example I provided is for a different accelerometer, which probably has a different I2C address. Be sure you're using the one for the MMA7455.
Not knowing your application, you may find a different kind of accelerometer easier to use. Parallax doesn't sell one, but you could look around for the type that returns an analog voltage relative to the g-force. The "ADXL" chips have this feature. Sparkfun sells several variations. Rather than deal with serial communications, you instead connect each axis to a separate ADC pin, then read the value.
I'd actually LOVE to see Parallax add one of these to their lineup, such as the ADXL377. The code to read the device is much simpler, and great for beginning programmers.
That said, overall a chip like the MMA7455 is more accurate, especially as it has temperature compensation, and allows for in-device calibration of 0g. Whether or not you need that accuracy is a matter between you and your project.
Another option is the Memsic 2125; however, it's 2-axis and not 3. You read the values with the Pulsin statement. The g-force is provided as a varying pulse width.
***
Thanks, looked at that and like that as an option 2, the voltage unit (non parallax) as option 1, much easier and the MMA7455 as option 3 now seems to be the best way to progress and learn.
Managed to get my modified routine working, but the data does not change - missing something ? The code is a modified version with the MMA7455 $var from the online datasheet. Feel free to comment.
It is still work in progress, but I think if no-one else has done this will have to change from parallax for my first setup at least
Moved the debug, PicAxe seems to not display data if DEBUG is not in the right place ? Thanks if anyone can help.
;Parallax 28526 Accelerometer i2C with PicAxe18M2
symbol who = b8 'who am I
symbol dat = b9 'data ready
symbol X= w5
symbol Y= w6
symbol Z= w7
symbol TEMP = w8 'for use in calculations
symbol sign = b10 'sign byte
symbol ii = b11 'counter
low 6 'comms
let ii = 0
let X = 0
let Y = 0
let Z = 0
let sign = %00000000 'This is the sign byte, this is how it works: Bit0 is for the X axis
'Bit1 is for the Y axis
'Bit2 is for the Z axis
'When the respective Bit is = 1 then the reading is negative
init:
high 6
hi2csetup i2cmaster, $39, i2cslow, i2cbyte 'set up the I2C protocol for ?????
'hi2cout $20, (%01000111) 'Disable power down and enable X,Y,Z axis
pause 10
data_check:
hi2cin $0A,(dat) 'Check if new data is ready
dat = dat | %11110111 'isolate the ZYXDA bit with bit operation
pause 10
if dat = 255 then goto read_data
goto data_check
read_data:
'hi2cin $0F,(who) 'Read who_am_i register sanity check should equal %00111011 or $3B
debug
'*************************
hi2cin $06,(TEMP) 'Read X
if TEMP > 127 then 'if it's negative remove the sign and raise a marker
TEMP = 256 - TEMP
TEMP = TEMP*18
X = X + TEMP
sign = sign | %00000001 'Bit operation to signal it's negative
else
TEMP = TEMP*18
X = X + TEMP
sign = sign &/ %00000001 'Bit operation to clear negative signal
endif
'**************************
hi2cin $07,(TEMP) 'Read Y
if TEMP > 127 then 'if it's negative remove the sign and raise a marker
TEMP = 256 - TEMP
TEMP = TEMP*18
Y = Y + TEMP
sign = sign | %00000010 'Bit operation to signal it's negative
else
TEMP = TEMP*18
Y = Y + TEMP
sign = sign &/ %00000010 'Bit operation to clear negative signal
endif
'*************************
hi2cin $08,(TEMP) 'Read Z
if TEMP > 127 then 'if it's negative remove the sign and raise a marker
TEMP = 256 - TEMP
TEMP = TEMP*18
Z = Z + TEMP
sign = sign | %00000100 'Bit operation to signal it's negative
else
TEMP = TEMP*18
Z = Z + TEMP
sign = sign &/ %00000100 'Bit operation to clear negative signal
endif
ii = ii+1
'***************************
if ii = 10 then 'Take an average over 10 cycles
ii = 0
X = X/10
Y = Y/10
Z = Z/10
else
X = 0
Y = 0
Z = 0
endif
goto data_check
http://www.picaxeforum.co.uk/forum.php
you are much more likely to find someone there who has used the MMA7455 with a PicAxe