Go to Post Great teams derive from great mentors. - Barry Bonzack [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-02-2016, 09:57
Ian R. Ian R. is offline
Registered User
FRC #2283 (Panteras)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Mexico
Posts: 13
Ian R. will become famous soon enough
MPU-9150 (I2C) with Labview

Hello everyone,

This year, our team decided to go ahead and use an extra motion tracking devide. We opted for the MPU-9150, but we are having problems getting it to work with Labview.
It is connected to the roboRIO's onboard I2C, and we based our Labview code on this Arduino example: http://playground.arduino.cc/Main/MPU-9150

After hours of trying to get a response from it, we haven't had any success. I'll upload the code later today

Last edited by Ian R. : 02-02-2016 at 10:04.
Reply With Quote
  #2   Spotlight this post!  
Unread 02-02-2016, 12:27
RyanN's Avatar
RyanN RyanN is offline
RyanN
AKA: Ryan Nazaretian
FRC #4901 (Garnet Squadron)
Team Role: Mentor
 
Join Date: Jun 2006
Rookie Year: 2005
Location: Columbia, SC
Posts: 1,126
RyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond repute
Re: MPU-9150 (I2C) with Labview

Quote:
Originally Posted by Ian R. View Post
Hello everyone,

This year, our team decided to go ahead and use an extra motion tracking devide. We opted for the MPU-9150, but we are having problems getting it to work with Labview.
It is connected to the roboRIO's onboard I2C, and we based our Labview code on this Arduino example: http://playground.arduino.cc/Main/MPU-9150

After hours of trying to get a response from it, we haven't had any success. I'll upload the code later today
I used the MPU-9150 a few years ago on my senior design project for college. It was a pain in the butt to get the magnetometer working. The accelerometer and gyro were relatively easy though.

Please post your code and I'll take a look at it.
__________________
Garnet Squadron
FRC 4901
Controls Mentor
@rnazaretian

Previous mentor and student from Team Fusion, FRC 364
Reply With Quote
  #3   Spotlight this post!  
Unread 02-02-2016, 17:19
Ian R. Ian R. is offline
Registered User
FRC #2283 (Panteras)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Mexico
Posts: 13
Ian R. will become famous soon enough
Re: MPU-9150 (I2C) with Labview

Quote:
Originally Posted by RyanN View Post
I used the MPU-9150 a few years ago on my senior design project for college. It was a pain in the butt to get the magnetometer working. The accelerometer and gyro were relatively easy though.

Please post your code and I'll take a look at it.
Here are the relevant snippets of code:
Periodic Tasks:


MPU Config VI:


Read HL VI:


We've tried with MPU address 0x68 and 0x69, but no luck so far

Last edited by Ian R. : 02-02-2016 at 17:29.
Reply With Quote
  #4   Spotlight this post!  
Unread 03-02-2016, 08:08
RyanN's Avatar
RyanN RyanN is offline
RyanN
AKA: Ryan Nazaretian
FRC #4901 (Garnet Squadron)
Team Role: Mentor
 
Join Date: Jun 2006
Rookie Year: 2005
Location: Columbia, SC
Posts: 1,126
RyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond repute
Re: MPU-9150 (I2C) with Labview

Can you include your I2C Open code as well (probably stuck in the Begin.vi)?

Your config code looks messed up. Why are you re-opening so many times?

You only need to do one 'open'. The device address is stored after that.

Your config should happen before you start your while loop. Currently, you're trying to do two things at once. Use the Error block to control the order of execution.

Comment what your config code is doing at each point.

Monitor the error outputs. If it can't communicate, it will tell you.
__________________
Garnet Squadron
FRC 4901
Controls Mentor
@rnazaretian

Previous mentor and student from Team Fusion, FRC 364

Last edited by RyanN : 03-02-2016 at 08:11.
Reply With Quote
  #5   Spotlight this post!  
Unread 03-02-2016, 08:54
Ian R. Ian R. is offline
Registered User
FRC #2283 (Panteras)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Mexico
Posts: 13
Ian R. will become famous soon enough
Re: MPU-9150 (I2C) with Labview

Quote:
Originally Posted by RyanN View Post
Can you include your I2C Open code as well (probably stuck in the Begin.vi)?

Your config code looks messed up. Why are you re-opening so many times?

You only need to do one 'open'. The device address is stored after that.

Your config should happen before you start your while loop. Currently, you're trying to do two things at once. Use the Error block to control the order of execution.

Comment what your config code is doing at each point.

Monitor the error outputs. If it can't communicate, it will tell you.
Yes, the config code is really messy right now. We used the Arduino example and then made it inside LabVIEW.
All we do inside the begin.vi is open the I2C with the I2C On-board bus and 0x69 address. I'll post the code later on today.
About the error outputs, there's no error at all.

We also tried to clear just the sleep byte at 0x6B inside the begin.vi and then read raw values from the temperature sensor at 0x41 and 0x42 while in timed tasks, but we got no response
Reply With Quote
  #6   Spotlight this post!  
Unread 03-02-2016, 08:55
RyanN's Avatar
RyanN RyanN is offline
RyanN
AKA: Ryan Nazaretian
FRC #4901 (Garnet Squadron)
Team Role: Mentor
 
Join Date: Jun 2006
Rookie Year: 2005
Location: Columbia, SC
Posts: 1,126
RyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond repute
Re: MPU-9150 (I2C) with Labview

Quote:
Originally Posted by Ian R. View Post
Yes, the config code is really messy right now. We used the Arduino example and then made it inside LabVIEW.
All we do inside the begin.vi is open the I2C with the I2C On-board bus and 0x69 address. I'll post the code later on today.
About the error outputs, there's no error at all.

We also tried to clear just the sleep byte at 0x6B inside the begin.vi and then read raw values from the temperature sensor at 0x41 and 0x42 while in timed tasks, but we got no response
What breakout board are you using?

My recommendation is to keep it as simple as possible. I think reading the temperature is a good start. Don't try anything else until you get that working.

So, create a minimum programming sequence to get the temperature. Once you get that working, start implementing other stuff such as setting the gains.
__________________
Garnet Squadron
FRC 4901
Controls Mentor
@rnazaretian

Previous mentor and student from Team Fusion, FRC 364

Last edited by RyanN : 03-02-2016 at 08:59.
Reply With Quote
  #7   Spotlight this post!  
Unread 03-02-2016, 08:58
Ian R. Ian R. is offline
Registered User
FRC #2283 (Panteras)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Mexico
Posts: 13
Ian R. will become famous soon enough
Re: MPU-9150 (I2C) with Labview

Quote:
Originally Posted by RyanN View Post
What breakout board are you using?
We're using Sparkfun's SEN-11486 (https://www.sparkfun.com/products/11486)
We also tried the temperature reading using address 0x68 instead of 0x69, but we got the same result

Last edited by Ian R. : 03-02-2016 at 09:07.
Reply With Quote
  #8   Spotlight this post!  
Unread 03-02-2016, 11:02
RyanN's Avatar
RyanN RyanN is offline
RyanN
AKA: Ryan Nazaretian
FRC #4901 (Garnet Squadron)
Team Role: Mentor
 
Join Date: Jun 2006
Rookie Year: 2005
Location: Columbia, SC
Posts: 1,126
RyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond repute
Re: MPU-9150 (I2C) with Labview

Quote:
Originally Posted by Ian R. View Post
We're using Sparkfun's SEN-11486 (https://www.sparkfun.com/products/11486)
We also tried the temperature reading using address 0x68 instead of 0x69, but we got the same result
The breakout board has the A0 pin connected to ground, so you are correct in using 0x68.

I have no idea if my code works since I no longer have an MPU-9150, but maybe it'll point out your problem.
Attached Thumbnails
Click image for larger version

Name:	MPU-9150 Temperature Read.png
Views:	31
Size:	41.0 KB
ID:	19955  
Attached Files
File Type: vi MPU-9150 Read Temperature.vi (17.5 KB, 8 views)
__________________
Garnet Squadron
FRC 4901
Controls Mentor
@rnazaretian

Previous mentor and student from Team Fusion, FRC 364
Reply With Quote
  #9   Spotlight this post!  
Unread 03-02-2016, 14:33
Ian R. Ian R. is offline
Registered User
FRC #2283 (Panteras)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Mexico
Posts: 13
Ian R. will become famous soon enough
Re: MPU-9150 (I2C) with Labview

Quote:
Originally Posted by RyanN View Post
The breakout board has the A0 pin connected to ground, so you are correct in using 0x68.

I have no idea if my code works since I no longer have an MPU-9150, but maybe it'll point out your problem.
Thanks, I'll give it a try later today and post the results
Reply With Quote
  #10   Spotlight this post!  
Unread 03-02-2016, 19:35
Ian R. Ian R. is offline
Registered User
FRC #2283 (Panteras)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Mexico
Posts: 13
Ian R. will become famous soon enough
Re: MPU-9150 (I2C) with Labview

Quote:
Originally Posted by RyanN View Post
The breakout board has the A0 pin connected to ground, so you are correct in using 0x68.

I have no idea if my code works since I no longer have an MPU-9150, but maybe it'll point out your problem.
Ok, did some tweaking and it worked. I added the gyro and accelerometer too, BUT the magnetometer is still an issue. According to the Arduino code I was refering to, as well as the GitHub example linked in the Sparkfun page, you have to open a new channel with device 0x0C, which is the magnetometer, and then set the register 0x0A to 0x01, but the issue is there is NO 0x0C device.
Reply With Quote
  #11   Spotlight this post!  
Unread 03-02-2016, 20:16
RyanN's Avatar
RyanN RyanN is offline
RyanN
AKA: Ryan Nazaretian
FRC #4901 (Garnet Squadron)
Team Role: Mentor
 
Join Date: Jun 2006
Rookie Year: 2005
Location: Columbia, SC
Posts: 1,126
RyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond repute
Re: MPU-9150 (I2C) with Labview

Quote:
Originally Posted by RyanN View Post
I used the MPU-9150 a few years ago on my senior design project for college. It was a pain in the butt to get the magnetometer working. The accelerometer and gyro were relatively easy though.

Please post your code and I'll take a look at it.
Told ya so!

It's been three years since I messed with it.

So the magnetometer is a 3rd party sensor. InvenSense doesn't make it... they just buy the silicon and wire it up inside the little chip you have, then slap black plastic and their logo on top. (I think it's really an MPU 6050 core with a magnetometer wired up).

The magnetometer is hidden behind the auxiliary I2C bus on the IMU. You have to talk through the auxiliary bus in order to talk to the magnetometer. You can setup the IMU to go into pass-through mode.

I wish I had access to my old code (Thanks IT for deleting it).

This might get you started: https://github.com/sparkfun/MPU-9150...50/MPU6050.cpp

Code:
void MPU6050::getMotion9(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz, int16_t* mx, int16_t* my, int16_t* mz) {
    
	//get accel and gyro
	getMotion6(ax, ay, az, gx, gy, gz);
	
	//read mag
	I2Cdev::writeByte(devAddr, MPU6050_RA_INT_PIN_CFG, 0x02); //set i2c bypass enable pin to true to access magnetometer
	delay(10);
	I2Cdev::writeByte(MPU9150_RA_MAG_ADDRESS, 0x0A, 0x01); //enable the magnetometer
	delay(10);
	I2Cdev::readBytes(MPU9150_RA_MAG_ADDRESS, MPU9150_RA_MAG_XOUT_L, 6, buffer);
	*mx = (((int16_t)buffer[1]) << 8) | buffer[0];
        *my = (((int16_t)buffer[3]) << 8) | buffer[2];
        *mz = (((int16_t)buffer[5]) << 8) | buffer[4];		
}
You can find those register constants in https://github.com/sparkfun/MPU-9150...6050/MPU6050.h
__________________
Garnet Squadron
FRC 4901
Controls Mentor
@rnazaretian

Previous mentor and student from Team Fusion, FRC 364
Reply With Quote
  #12   Spotlight this post!  
Unread 03-02-2016, 20:51
Ian R. Ian R. is offline
Registered User
FRC #2283 (Panteras)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Mexico
Posts: 13
Ian R. will become famous soon enough
Re: MPU-9150 (I2C) with Labview

Quote:
Originally Posted by RyanN View Post
Told ya so!

It's been three years since I messed with it.

So the magnetometer is a 3rd party sensor. InvenSense doesn't make it... they just buy the silicon and wire it up inside the little chip you have, then slap black plastic and their logo on top. (I think it's really an MPU 6050 core with a magnetometer wired up).

The magnetometer is hidden behind the auxiliary I2C bus on the IMU. You have to talk through the auxiliary bus in order to talk to the magnetometer. You can setup the IMU to go into pass-through mode.

I wish I had access to my old code (Thanks IT for deleting it).

This might get you started: https://github.com/sparkfun/MPU-9150...50/MPU6050.cpp

Code:
void MPU6050::getMotion9(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz, int16_t* mx, int16_t* my, int16_t* mz) {
    
	//get accel and gyro
	getMotion6(ax, ay, az, gx, gy, gz);
	
	//read mag
	I2Cdev::writeByte(devAddr, MPU6050_RA_INT_PIN_CFG, 0x02); //set i2c bypass enable pin to true to access magnetometer
	delay(10);
	I2Cdev::writeByte(MPU9150_RA_MAG_ADDRESS, 0x0A, 0x01); //enable the magnetometer
	delay(10);
	I2Cdev::readBytes(MPU9150_RA_MAG_ADDRESS, MPU9150_RA_MAG_XOUT_L, 6, buffer);
	*mx = (((int16_t)buffer[1]) << 8) | buffer[0];
        *my = (((int16_t)buffer[3]) << 8) | buffer[2];
        *mz = (((int16_t)buffer[5]) << 8) | buffer[4];		
}
You can find those register constants in https://github.com/sparkfun/MPU-9150...6050/MPU6050.h
I've already got the register constants from the register sheet, but this line of code should perform all the magic:
Code:
I2Cdev::writeByte(devAddr, MPU6050_RA_INT_PIN_CFG, 0x02); //set i2c bypass enable pin to true to access magnetometer
I thought the mag was wired as an additional I2C device, and not behind the IMU.
Thanks for pointing it out!
Reply With Quote
  #13   Spotlight this post!  
Unread 04-02-2016, 19:19
Ian R. Ian R. is offline
Registered User
FRC #2283 (Panteras)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Mexico
Posts: 13
Ian R. will become famous soon enough
Re: MPU-9150 (I2C) with Labview

Quote:
Originally Posted by RyanN View Post
Told ya so!

It's been three years since I messed with it.

So the magnetometer is a 3rd party sensor. InvenSense doesn't make it... they just buy the silicon and wire it up inside the little chip you have, then slap black plastic and their logo on top. (I think it's really an MPU 6050 core with a magnetometer wired up).

The magnetometer is hidden behind the auxiliary I2C bus on the IMU. You have to talk through the auxiliary bus in order to talk to the magnetometer. You can setup the IMU to go into pass-through mode.

I wish I had access to my old code (Thanks IT for deleting it).

This might get you started: https://github.com/sparkfun/MPU-9150...50/MPU6050.cpp

Code:
void MPU6050::getMotion9(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz, int16_t* mx, int16_t* my, int16_t* mz) {
    
	//get accel and gyro
	getMotion6(ax, ay, az, gx, gy, gz);
	
	//read mag
	I2Cdev::writeByte(devAddr, MPU6050_RA_INT_PIN_CFG, 0x02); //set i2c bypass enable pin to true to access magnetometer
	delay(10);
	I2Cdev::writeByte(MPU9150_RA_MAG_ADDRESS, 0x0A, 0x01); //enable the magnetometer
	delay(10);
	I2Cdev::readBytes(MPU9150_RA_MAG_ADDRESS, MPU9150_RA_MAG_XOUT_L, 6, buffer);
	*mx = (((int16_t)buffer[1]) << 8) | buffer[0];
        *my = (((int16_t)buffer[3]) << 8) | buffer[2];
        *mz = (((int16_t)buffer[5]) << 8) | buffer[4];		
}
You can find those register constants in https://github.com/sparkfun/MPU-9150...6050/MPU6050.h
Ok, I tested it out today, and we finally got a response from the mag.
But anither issue arised. While we can read from all the low byte registers, the high ones always return 0.
We tried communicating with the mag directly, as well as through the MPU, but it's the same problem.
I'm not sure if we have to read each independent register and then shift the high one and add the low one to it, or if we should read the low register and ask for 2 bytes.
Reply With Quote
  #14   Spotlight this post!  
Unread 05-02-2016, 07:44
RyanN's Avatar
RyanN RyanN is offline
RyanN
AKA: Ryan Nazaretian
FRC #4901 (Garnet Squadron)
Team Role: Mentor
 
Join Date: Jun 2006
Rookie Year: 2005
Location: Columbia, SC
Posts: 1,126
RyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond repute
Re: MPU-9150 (I2C) with Labview

Quote:
Originally Posted by Ian R. View Post
Ok, I tested it out today, and we finally got a response from the mag.
But anither issue arised. While we can read from all the low byte registers, the high ones always return 0.
We tried communicating with the mag directly, as well as through the MPU, but it's the same problem.
I'm not sure if we have to read each independent register and then shift the high one and add the low one to it, or if we should read the low register and ask for 2 bytes.
Sparkfun's example code does a 6-byte burst read. I just checked the AK8975's datasheet and it says is compatible with burst read:
Quote:
Originally Posted by Section 8.1
Addresses from 00H to 0CH and from 10H to 12H are compliant with automatic increment function of serial interface respectively.
The AK8975 returns a signed 16-bit integer, so negative numbers should return something in the MSB. That's pretty easy to replicate by rotating the sensor 180 degrees.

I'm not sure what's going on from your description. Mind sharing your current LabVIEW code?
__________________
Garnet Squadron
FRC 4901
Controls Mentor
@rnazaretian

Previous mentor and student from Team Fusion, FRC 364
Reply With Quote
  #15   Spotlight this post!  
Unread 05-02-2016, 08:37
Ian R. Ian R. is offline
Registered User
FRC #2283 (Panteras)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Mexico
Posts: 13
Ian R. will become famous soon enough
Re: MPU-9150 (I2C) with Labview

Quote:
Originally Posted by RyanN View Post
Sparkfun's example code does a 6-byte burst read. I just checked the AK8975's datasheet and it says is compatible with burst read:


The AK8975 returns a signed 16-bit integer, so negative numbers should return something in the MSB. That's pretty easy to replicate by rotating the sensor 180 degrees.

I'm not sure what's going on from your description. Mind sharing your current LabVIEW code?
Sure, I'll upload it later today.
We tried to rotate the sensor all the way around, but the MSB wasn't returning anything, and the LSB is just ranging from 20 to 50
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 04:21.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi