Shop OBEX P1 Docs P2 Docs Learn Events
PICAXE 18M+ and MMA7455 3-Axis Accelerometer Module — Parallax Forums

PICAXE 18M+ and MMA7455 3-Axis Accelerometer Module

PicAxePicAxe Posts: 4
edited 2014-12-04 14:55 in Accessories
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

  • kwinnkwinn Posts: 8,697
    edited 2014-12-02 08:42
    The answer to your poll question "Is I2C better than SPI" is " it depends on the application". I2C (Inter Integrated Circuit) is a simple hardware connection intended for 2 chips to be able to communicate. SPI (Serial Peripheral Interface ) is a serial bus system used mainly to connect multiple peripheral chips to a microcontroller.
  • PublisonPublison Posts: 12,366
    edited 2014-12-02 08:48
    Welcome to the forums.

    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.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-12-02 09:39
    Just as an FYI, the 18M supports I2C with a native command set. That said, on the PICAXE, I2C isn't necessarily simple. They have documentation in their general manual, plus a separate datasheet on I2C.

    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.
  • PicAxePicAxe Posts: 4
    edited 2014-12-02 17:18
    Just as an FYI, the 18M supports I2C with a native command set. That said, on the PICAXE, I2C isn't necessarily simple. They have documentation in their general manual, plus a separate datasheet on I2C.

    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.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-12-02 20:52
    There are a few PICAXE users here, me included, but not many. I've used it in some projects, but I've never used I2C on that chip. While the command set is not particularly hefty, getting into the chip to read the values isn't always clear. What may be happening in your case is:

    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.

    B) You're not setting up and then reading the correct registers inside the chip. The MMA7455 is a very full featured chip. You picked one of the more complicated ones to start out with!

    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.
  • PicAxePicAxe Posts: 4
    edited 2014-12-03 01:55
    There are a few PICAXE users here, me included, but not many. I've used it in some projects, but I've never used I2C on that chip. While the command set is not particularly hefty, getting into the chip to read the values isn't always clear. What may be happening in your case is:

    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.

    B) You're not setting up and then reading the correct registers inside the chip. The MMA7455 is a very full featured chip. You picked one of the more complicated ones to start out with!

    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
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-12-03 08:08
    As I noted before, this is code for the LIS302DL, a different chip than the one you're using. Though sometimes these devices share I2C addresses and registers, the LIS302DL and MMA7455 are from different manufacturers, so I'd question that assumption. Look at the BS2 demo for the values. At a minimum, you need to research the values to use every time you see a hi2c* command, to make sure you're using the right address and registers. Like I said, this is a tough nut for a beginner to crack.
  • Bill HenningBill Henning Posts: 6,445
    edited 2014-12-04 14:55
    I'd ask in the picaxe forums at

    http://www.picaxeforum.co.uk/forum.php

    you are much more likely to find someone there who has used the MMA7455 with a PicAxe
Sign In or Register to comment.