Shop OBEX P1 Docs P2 Docs Learn Events
Introducing the 3AD: 3-axis digital (I2C) accelerometer in DIP-8 package for $8 - Page 2 — Parallax Forums

Introducing the 3AD: 3-axis digital (I2C) accelerometer in DIP-8 package for $8

2»

Comments

  • vascojdbvascojdb Posts: 1
    edited 2010-12-07 19:10
    Hello.

    I was visiting the website buy they ran out of stock again. I wanted to ask if u have 3AD accelerometers and if u can send them in international order (to portugal or poland)

    Cause i am really trying to find cheap and good accelerometers and your seems to bee the best.

    Good work btw! :)

    Thanks
    Best regards.
    Vasco Baptista
    http://www.vascotech88.pt.vu
  • Nick McClickNick McClick Posts: 1,003
    edited 2010-12-07 20:56
    Hey Vasco! I just ran out because of a big order, but I might have a few left - I'll re-inventory them & let you know.
  • MacTuxLinMacTuxLin Posts: 821
    edited 2011-01-20 01:50
    Hi,
    We purchased 5 pcs of the above & have a number of questions:

    1. Noticed the address is set at x1D. If need to chain them up on I2C, how could I change the address of each unit?
       MMA7455_Address = $1D
    

    2. Instead of using default pin (28 & 29), if I use another 2 pins:
    a. I need to add the "Initialize" function in the main code, correct?
    PUB Initialize'(SCL) | SDA              ' An I2C device may be left in an
    

    b. SCL & SDA will change to, eg., SCL = 16, SDA = 17


    Thanks!
  • MacTuxLinMacTuxLin Posts: 821
    edited 2011-01-20 07:15
    OK, after reading the datasheet, it seems I can't change the address (Pin 4) :( or is there?
  • RaymanRayman Posts: 14,887
    edited 2011-01-20 08:11
    When plugged into spare eeprom socket of the Propeller Platform, the address line is grounded, so you can only have one that way...

    But, the 3AD module itself has 1 address pin (pin #7), so you can have two devices on the same I2C bus in principle.
    Just have one with pin#7 grounded and another with pin#7 at Vdd.
  • MacTuxLinMacTuxLin Posts: 821
    edited 2011-01-20 18:33
    :blank:Darn ... should have read the datasheet before getting them. Yes, pin# 7 of 3AD connects to pin# 4 on the MMA7445L. I'll probably need to connect 3AD via SPI but it seems pin#7's trace to pin#6 before AVdd is beneath the chip, or am I wrong? The rework is almost impossible then ... :(

    Is there any other way to connect these 5 3AD to a prop? Any advice is very welcome. Thanks.
  • TubularTubular Posts: 4,717
    edited 2011-01-20 19:10
    I have heard of people swapping over SDA and SCL to talk to a second device at the same address on the same bus. From a wiring point of view Prop === 3AD1 =x= 3AD2

    Your routines become something like
    PUB Initialize'(SCL) | SDA
    (take reading from 3AD-1)

    PUB Initialize'(SDA) | SCL
    (take reading from 3AD-2)

    Its probably not good to do this with the EEPROM on same SDA and SCL lines, but since you're talking about separate pins its probably worth a try.
  • MacTuxLinMacTuxLin Posts: 821
    edited 2011-01-20 20:03
    Thanks for the suggestion but ... it sounds scary:innocent:

    I'll look for other options. I do need to read 5 3AD & having 5 props sending data to another master prop would burn my budget thru & thru :tongue:
  • TubularTubular Posts: 4,717
    edited 2011-01-20 20:38
    5 Props? Hold that budget...

    How about 1 prop, 10 pins (5 separate I2C interfaces), either 1 cog in a fast round-robin detection, or if you need, use 5 cogs each talking to their own 3AD at maximum rate.
    Or you could share the clock (SCL) line amongst all, use 6 pins instead of 10 (1xSCL and 5xSDA). Much less scary :)

    The prop is wonderfully flexible at this kind of thing (compared to other micros where you have a single fixed I2C interface)
  • MacTuxLinMacTuxLin Posts: 821
    edited 2011-01-20 23:35
    Thanks. Yes, you're right! Sometimes the PIC/Atmel thinking keeps haunting my mind :P

    OK, the 1 prop with 10 pins looks delicious. So, looking at the code, while making the changes, I seems to have a problem:

    1. The address for MMA7445L is $1D for all 5, right? So if I perform a read:
    '*** In Main
    x[0] := i2c.GetAccelX8   '<-- which on of the 5 it is getting??
    
    
    '*** In GG_PSB_i2cDriver
    PUB GetAccelX8
    return Get1ByteAccelReg($06)
    
    PRI Get1ByteAccelReg(nReg)|m,v    
      m:=GetAccelReg(nReg)
      'need to swap bytes
      v:=m>>8
      return (v<<24)~>24  'result is signed 8 bit...
    
    PUB GetAccelReg(reg) |ackbit ,x
      'Retrieve contents of acclerometer register
       START
       ackbit:=Write(MMA7455_Address<<1)
       ackbit:=Write(reg) 
       STOP
       x:=in(MMA7455_Address)
       'Going to swap high and low bytes...
       return x  
    


    I'm writing:
    OBJ
      I2C : "GG_PSB_i2cDriver"
    
    CON
      SCL_1 = 8
      SCL_2 = 10
      SCL_3 = 12
      SCL_4 = 14
      SCL_5 = 16
    
    VAR
      long x[5], y[5], z[5]
    
    PUB Main
    
      I2C.Initialise(SCL_1)
      I2C.Initialise(SCL_2)
      I2C.Initialise(SCL_3)
      I2C.Initialise(SCL_4)
      I2C.Initialise(SCL_5)
    
      repeat
        repeat i from 0 to 4
          x[i] := i2c.GetAccelX8
          y[i] := i2c.GetAccelX8
          z[i] := i2c.GetAccelX8
          waitcnt(cnt + clkfreq/100)
    
    
    
    '*** In GG_PSB_i2cDriver, change to
    PUB Initialize(in_SCL) | in_SDA
      in_SDA := SCL + 1
      outa[in_SCL] := 1                       '   reinitialized.  Drive SCL high.
      dira[in_SCL] := 1
      dira[in_SDA] := 0                       ' Set SDA as input
      repeat 9
         outa[in_SCL] := 0                    ' Put out up to 9 clock pulses
         outa[in_SCL] := 1
         if ina[in_SDA]                      ' Repeat if SDA not driven high
            quit  
    
    
  • MacTuxLinMacTuxLin Posts: 821
    edited 2011-01-20 23:43
    I've figured it out now. I'll have to use Mike Green's Basic_i2CDriver as a boilerplate & mod from there. I'll post it after the changes & please help me to see if I made any bo-bo. Thanks.
  • MacTuxLinMacTuxLin Posts: 821
    edited 2011-01-21 02:16
    I got it to work!!! :smile::smile:

    This is an updated driver that supports as many 3AD as your available pins on 1 prop. I've tested using 2 3AD & it worked. Attached is the revised version for anyone interested.

    Thanks Tubular for the idea.
  • TubularTubular Posts: 4,717
    edited 2011-01-21 04:34
    Great news! Congratulations.
  • MacTuxLinMacTuxLin Posts: 821
    edited 2011-01-21 06:26
    Tubular wrote: »
    Great news! Congratulations.

    Thank you Tubular! I'm going to connect all 5 tomorrow & test them :D
  • MacTuxLinMacTuxLin Posts: 821
    edited 2011-01-22 10:45
    Hello Rayman,

    Do you think you could do some without the headers mounted? I'll get another 10 either from you or GG.

    Thanks
  • RaymanRayman Posts: 14,887
    edited 2011-01-22 12:03
    Ok, next time I make some, I'll leave the headers off a few for you before I send them to GG.
  • TubularTubular Posts: 4,717
    edited 2011-01-22 14:41
    Here's a pic of the 3AD with self stacking headers.
    (Mill max, available in various stack heights)

    Of course you can only have one 3AD in each stack, unless you modify that address pin
    1024 x 765 - 43K
  • MacTuxLinMacTuxLin Posts: 821
    edited 2011-01-23 11:22
    @Rayman
    Thanks. Pls let me know once you have them.

    @Tubular,
    Thanks. Actually, I need them to be as flat as possible.
  • MacTuxLinMacTuxLin Posts: 821
    edited 2011-01-27 09:23
    I have a question but sorry, might be a silly one:

    In the PSB_i2cDriver, why is the address always has a bitwise shift left?
    PUB GetAccelReg(reg) |ackbit ,x
      'Retrieve contents of acclerometer register
       START
       ackbit:=Write(MMA7455_Address<<1)    '<--Why need to shift when sending to Write
       ackbit:=Write(reg) 
       STOP
       x:=in(MMA7455_Address)
       'Going to swap high and low bytes...
       return x       
    
    Thanks.
  • RaymanRayman Posts: 14,887
    edited 2011-01-27 12:42
    You need the shift because in really, there are 2 addresses for the device... A read address and a write address. The last bit decides if it's read or write...
  • MacTuxLinMacTuxLin Posts: 821
    edited 2011-01-27 16:24
    :p Thanks. Been reading the datasheet but .... found that on page 24. :lol:
  • MacTuxLinMacTuxLin Posts: 821
    edited 2011-02-10 22:15
    Hello Rayman,

    I'm trying to implement a 1-to-8 I2C Switch & was trying to write a simple object. I was able to detect the 3AD on its SD0/SC0 but the readings I got were mostly -1. While reading the code, it looks like (sorry if I'm reading it wrongly) that the PUB Read function in PSB_i2cDriver reads 2 byte instead of 1 like in the Basic_i2c_Driver. May I know why? :innocent:

    Thank you.

    In PSB_i2cDriver:
    PUB Read(ackbit):data'(SCL, ackbit): data | SDA
    '' Read in i2c data, Data byte is output MSB first, SDA data line is
    '' valid only while the SCL line is HIGH.  SCL and SDA left in LOW state.
       data := 0
       dira[SDA]~                          ' Make SDA an input
       repeat 8                            ' Receive data from SDA
          outa[SCL]~~                      ' Sample SDA when SCL is HIGH
          data := (data << 1) | ina[SDA]
          outa[SCL]~
       outa[SDA] := ackbit                 ' Output ACK/NAK to SDA
       dira[SDA]~~
       outa[SCL]~~                         ' Toggle SCL from LOW to HIGH to LOW
       outa[SCL]~
       dira[SDA]~
       repeat 8                            ' Receive data from SDA
          outa[SCL]~~                      ' Sample SDA when SCL is HIGH
          data := (data << 1) | ina[SDA]
          outa[SCL]~
       outa[SDA] := NAK'ackbit                 ' Output ACK/NAK to SDA
       
       dira[SDA]~~
       outa[SCL]~~                         ' Toggle SCL from LOW to HIGH to LOW
       outa[SCL]~
       outa[SDA]~                          ' Leave SDA driven LOW
    

    In Basic_i2c_Driver:
    PUB Read(SCL, ackbit): data | SDA
    '' Read in i2c data, Data byte is output MSB first, SDA data line is
    '' valid only while the SCL line is HIGH.  SCL and SDA left in LOW state.
       SDA := SCL + 1
       data := 0
       dira[SDA]~                          ' Make SDA an input
       repeat 8                            ' Receive data from SDA
          outa[SCL]~~                      ' Sample SDA when SCL is HIGH
          data := (data << 1) | ina[SDA]
          outa[SCL]~
       outa[SDA] := ackbit                 ' Output ACK/NAK to SDA
       dira[SDA]~~
       outa[SCL]~~                         ' Toggle SCL from LOW to HIGH to LOW
       outa[SCL]~
       outa[SDA]~                          ' Leave SDA driven LOW
    

    Added: Rayman, its ok. I've found a solution to this problem so you don't need to bother to reply me. Thanks! :lol:
  • RaymanRayman Posts: 14,887
    edited 2011-02-11 05:32
    Glad you got it!
Sign In or Register to comment.