Shop OBEX P1 Docs P2 Docs Learn Events
help: I2C in SPIN — Parallax Forums

help: I2C in SPIN

coderbadcoderbad Posts: 29
edited 2015-01-31 11:14 in Propeller 1
Hi, I want to use accelerometer mpu-6050 for a project, I'm new in spin and I don't know how the I2C works with this micro using spin, somenody know? I'v seem examples with the itg3200 but this one is different, is there a guide how to use I2C in spin?
Thanks

Comments

  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-01-27 23:30
    I2C is a very simple protocol, and your part documentation should spell out the details of each transaction. I've attached my low-level I2C object; I've used this with a very wide variety of devices. Note that it expects pull-ups on both the SDA and SCL lines.
  • coderbadcoderbad Posts: 29
    edited 2015-01-28 23:09
    Thanks my friend, I'm gonna check it how it works, if you could recommend me a good book to learn spin, please
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-01-28 23:30
    coderbad wrote: »
    Thanks my friend, I'm gonna check it how it works, if you could recommend me a good book to learn spin, please

    I have a bunch of links to Spin tutorials in post #3 of my index (see my signature).

    Post #3 includes links to JonnyMac's SpinZone articles.

    I really like the Spin tutorials in the version 1.0 edition to the Propeller Manual. I have a pdf file of this version in my Dropbox, with a link to the file in post #3.

    I encourage you to read Jon's SpinZone articles. They're a lot fun and I learned a lot from them.
  • wmosscropwmosscrop Posts: 409
    edited 2015-01-29 06:31
    coderbad wrote: »
    Hi, I want to use accelerometer mpu-6050 for a project, I'm new in spin and I don't know how the I2C works with this micro using spin, somenody know? I'v seem examples with the itg3200 but this one is different, is there a guide how to use I2C in spin?
    Thanks

    I'm currently working on a robotic project that uses the mpu-6050 for angular rotation (yaw) measurement. I've based my code on the very useful MPU-6050 object available in the Propeller Object Exchange (obex).

    What are you going to use the chip to measure?

    Walter
  • coderbadcoderbad Posts: 29
    edited 2015-01-29 08:23
    wmosscrop wrote: »
    I'm currently working on a robotic project that uses the mpu-6050 for angular rotation (yaw) measurement. I've based my code on the very useful MPU-6050 object available in the Propeller Object Exchange (obex).

    What are you going to use the chip to measure?

    Walter
    I want to use the chip for angular rotation, my university project is a quadcopter, so I need yaw and row

    Danny
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-01-29 08:28
    wmosscrop wrote: »
    I'm currently working on a robotic project that uses the mpu-6050 for angular rotation (yaw) measurement. I've based my code on the very useful MPU-6050 object available in the Propeller Object Exchange (obex).

    Walter,

    Have you compared the Propeller MPU-6050 code performance with the Arduino code's performance?

    I was under the impression the Propeller code returned the raw data while the Arduino code took advantage of the on-chip filters. I was very impressed by the Arduino's code performance and I've just about decided I'll use an Arduino as a slave to interface with the MPU-6050 chip.

    I should really investigate this myself but I was hoping you might have already made this comparison.
  • wmosscropwmosscrop Posts: 409
    edited 2015-01-29 09:31
    Duane Degn wrote: »
    Have you compared the Propeller MPU-6050 code performance with the Arduino code's performance?

    Duane,

    No, I haven't. You are correct that the Propeller code just returns the raw values. I didn't even try to use the on-chip filters; instead, I calculate the yaw angles the hard way (sampling over time).

    My project doesn't need exact measurements (all I need to know is approximately how far I've actually turned, left or right). This is for self-edification so I tend to do things the hard way :)

    If I were to need more exact/faster measurements I'd also go with using an Arduino as a slave device.

    Walter
  • wmosscropwmosscrop Posts: 409
    edited 2015-01-29 09:34
    coderbad wrote: »
    I want to use the chip for angular rotation, my university project is a quadcopter, so I need yaw and row

    Danny,

    I'd recommend thinking about Duane's idea to use an slave Arduino which in turn takes advantage of the MPU-6050's on-chip filters.

    My code is too slow and not accurate enough to use for quadcopter control.

    Walter
  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-01-29 09:53
    takes advantage of the MPU-6050's on-chip filters.

    If the Arduino can do that, why not the Propeller? It's just I2C, right? If I2C in Spin is too slow, one can use PASM. I've attached my generic PASM I2C code. Since it uses a cog, only one instance is allowed (I'm working on the assumption there is only one I2C buss). I recently used this code to load a pre-compiled (binary) image from an SD card into the Propeller (I'm doing what the Propeller booter does). It's actually faster than downloading a pre-compiled binary from the Propeller Tool (my code uses blocks, the P/T does things byte-by-byte).
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-01-29 10:05
    JonnyMac wrote: »
    If the Arduino can do that, why not the Propeller? It's just I2C, right?

    Yes, but translating C to Spin/PASM is not always straight forward and even when it is, it takes time.
    I believe there's a Propeller C version of the fancy MPU-6050 code but I'm not aware of a Spin/PASM version.

    I'd love a Spin/PASM version of the MPU-6050 code but I don't want it enough to spend the time (I assume) it would take to translate the code.
  • coderbadcoderbad Posts: 29
    edited 2015-01-29 11:02
    Duane Degn wrote: »
    Yes, but translating C to Spin/PASM is not always straight forward and even when it is, it takes time.
    I believe there's a Propeller C version of the fancy MPU-6050 code but I'm not aware of a Spin/PASM version.

    I'd love a Spin/PASM version of the MPU-6050 code but I don't want it enough to spend the time (I assume) it would take to translate the code.

    Yes, I think like JonnyMac, If the Arduino can do that, why not the Propeller? moreover, I have to do the control using propeller chip, if I had to use arduino as a slave, I do all the control using arduino, but that´s not the idea
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2015-01-31 11:14
    Name your poison.

    A. Port MCP-6050 C code to Propeller SPIN and PASM

    or

    B. Take existing Propeller SPIN and PASM for another IMU and adapt it to the MCP-6050.

    Both use I2C. Personally, I would select B anyday. Jason Dorie has already created code that flies and just needs to be refitted to your preferred IMU.
Sign In or Register to comment.