Shop OBEX P1 Docs P2 Docs Learn Events
ADXL345 accel - only 2 sigfigs — Parallax Forums

ADXL345 accel - only 2 sigfigs

jbirdmanjbirdman Posts: 9
edited 2011-01-24 06:57 in Propeller 1
I'm new to the propeller and trying to get an adxl345 accelerometer working, using this object: http://obex.parallax.com/objects/562/

I can get it working and read data from it (using the demo included), but it'll only read in 2 sigfigs (ie instead of 32_something ft/s/s, i only read 32). I've dug though the code in the object and the demo and done some searching but I'm officially stumped so I'd appreciate some help.

Thanks,

~Bird

Comments

  • jbirdmanjbirdman Posts: 9
    edited 2011-01-21 06:38
    I think the issue is here in the ADXL345 Object. The data is read using a function Read2byte
    PUB Read2byte(_axis): data
    '' 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.
    '' The routine reflects the ADXL345 datasheet recommendations for
    '' multiple byte read for each axis.
    
       StartI2C
       Write(deviceAddressWrite | 0)
       Write(_axis)
       StartI2C
       Write(deviceAddressRead | 0)
    
       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] := ACK                    ' Output ACK
       repeat 8                            ' Receive data from SDA
          outa[SCL]~~                      ' Sample SDA when SCL is HIGH
          data := (data << 1) | ina[SDA]
          outa[SCL]~
    
       data := data << 16                  ' Shift data bits 16 bits left these are LSB 
       outa[SDA] := NAK                    ' Output NAK to SDA
       
       dira[SDA]~~
       outa[SCL]~~                         ' Toggle SCL from LOW to HIGH to LOW
       outa[SCL]~
       outa[SDA]~                          ' Leave SDA driven LOW
       StopI2C
    
       data := data <- 8                   ' puts the 8MSB to the 8LSB
       data := ~data                       ' extend sign
    

    My suspicion is that in order to get more digits I need to read more than two bytes, but I don't know enough about i2c to figure out how to do that, I've tried playing around with the Read2byte function but haven't gotten it working.
  • TtailspinTtailspin Posts: 1,326
    edited 2011-01-22 08:48
    Welcome jbirdman,

    Could You post more of Your code? just use the handy Archive feature in the Prop tool.

    I am not sure what a "sigfigs" is...
  • jbirdmanjbirdman Posts: 9
    edited 2011-01-23 23:33
    I'll have to make a sheepish admission to posting for help after only a day of struggling, turns out I just needed to learn more about i2c and digital accelerometers (I have quite a bit of experience with analog sensors, but little with digital). I set up the read from the accelerometer wrong and only got the MSB, hence why I only got two significant figures (I only got 32 instead of 32.something). As it happens if you get both bytes from the accelerometer all of the data is there :).

    Thanks for the offer of help, I can still post the code if you're interested.
  • TtailspinTtailspin Posts: 1,326
    edited 2011-01-24 06:57
    Cool, now I know what is "sigfigs".

    I'm telling you, this stuff is so easy, it's hard...
    Feel free to post up Your code, it serves as an example for others trying to hard..:smile:

    Personally, I get a kick out of seeing code I have written previously, I have come very far in a year, (for me anyway).
    and I am amazed that I could actually make the thing work in spite of my copy and paste code "writing" skills.
Sign In or Register to comment.