help: I2C in SPIN
coderbad
Posts: 29
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
Thanks
Comments
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.
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
Danny
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.
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
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
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).
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
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.