Go to Post Remember, there are many differents path to obtaining knowledge. There's no need to pigeonhole the process. - Karthik [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 06-02-2015, 21:20
Brindlefly's Avatar
Brindlefly Brindlefly is offline
Registered User
AKA: Jake Kinsella
FRC #4761 (Robockets)
Team Role: Leadership
 
Join Date: Nov 2014
Rookie Year: 2014
Location: Reading, MA
Posts: 8
Brindlefly will become famous soon enough
Help! Why Can't I Read Gyro Values Over the I2C Interface!

We bought a MPU 6050 gyro/accelerometer from Sparkfun Electronics. The spec sheet says the I2C address is 0x68 and that the WhoAmI register is at adress 075. When we read from that address we get the expected output of 104 decimal (0x68). When we tried to read the gyro register, at 0x43 - 0x47, we only get zeros. When we try to read the temperature register, we also get zeros. Is there something we have to do to enable reporting of the values?

Code:
private I2C gyro = new I2C(I2C.Port.kOnboard, 0x68);
	
	protected void initialize () {
		gyro.write(0x6B, 0x80);
	}
	
	protected void execute () {
		byte[] whoAmI = new byte[1];
		gyro.read(0x75, 1, whoAmI);
		System.out.println("WhoAmI: " + whoAmI[0]);
		
		for (int i = 0x43; i <= 0x47; i += 0x02) {
			byte[] angle = new byte[2];
			gyro.read(i, 2, angle);
		
			System.out.println(i + ": " + angle[0] + "" + angle[1]);
		}
	}
	
	protected boolean isFinished () {
		return false;
	}
	
	protected void end () {
		
	}
	
	protected void interrupted () {
		end();
	}
Reply With Quote
  #2   Spotlight this post!  
Unread 06-02-2015, 21:38
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: Help! Why Can't I Read Gyro Values Over the I2C Interface!

Looking at this Arduino driver, I think you need to select a range for the gyro and possibly wake it from sleep. According to the register map, that means writing 0 (250 degrees/sec), 1 (500 degrees/sec), 2 (1000 degrees/sec) or 3 (2000 degrees/sec) to bits 3-4 of the GYRO_CONFIG register (0x1B). To wake it from sleep, write a 0 to bit 6 of the PWR_MGMT_1 register (0x6B). You also might want to change the clock source to one of the gyros to increase accuracy.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #3   Spotlight this post!  
Unread 06-02-2015, 21:44
Brindlefly's Avatar
Brindlefly Brindlefly is offline
Registered User
AKA: Jake Kinsella
FRC #4761 (Robockets)
Team Role: Leadership
 
Join Date: Nov 2014
Rookie Year: 2014
Location: Reading, MA
Posts: 8
Brindlefly will become famous soon enough
Re: Help! Why Can't I Read Gyro Values Over the I2C Interface!

Thanks for your help. I will try tomorrow!
Reply With Quote
  #4   Spotlight this post!  
Unread 07-02-2015, 10:21
Brindlefly's Avatar
Brindlefly Brindlefly is offline
Registered User
AKA: Jake Kinsella
FRC #4761 (Robockets)
Team Role: Leadership
 
Join Date: Nov 2014
Rookie Year: 2014
Location: Reading, MA
Posts: 8
Brindlefly will become famous soon enough
Re: Help! Why Can't I Read Gyro Values Over the I2C Interface!

Ok, now I am getting an output from the gyro but it changes only when you turn it and then it goes back to zero when it stops turning.

Code:
private I2C gyro = new I2C(I2C.Port.kOnboard, 0x68);
	
	protected void initialize () {
		gyro.write(0x6B, 0x03); // Power
		gyro.write(0x1A, 0x1B); // Basic Config
		gyro.write(0x1B, 0x18); // Gyro Config
	}
	
	protected void execute () {
		
		byte[] angle = new byte[1];
		gyro.read(0x47, 2, angle);
		
		double rotation = (angle[1] << 8) | angle[0];
		
		System.out.println("Rotation: " + rotation);
	}
	
	protected boolean isFinished () {
		return false;
	}
	
	protected void end () {
		
	}
	
	protected void interrupted () {
		end();
	}
Reply With Quote
  #5   Spotlight this post!  
Unread 07-02-2015, 10:55
Brindlefly's Avatar
Brindlefly Brindlefly is offline
Registered User
AKA: Jake Kinsella
FRC #4761 (Robockets)
Team Role: Leadership
 
Join Date: Nov 2014
Rookie Year: 2014
Location: Reading, MA
Posts: 8
Brindlefly will become famous soon enough
Re: Help! Why Can't I Read Gyro Values Over the I2C Interface!

Ok now I am adding up the values from the gyro to get degrees, but when the robot turns in the positive direction the value shoots up to the thousands, and in the positive direction it goes to -3 max.
Reply With Quote
  #6   Spotlight this post!  
Unread 07-02-2015, 14:41
Brindlefly's Avatar
Brindlefly Brindlefly is offline
Registered User
AKA: Jake Kinsella
FRC #4761 (Robockets)
Team Role: Leadership
 
Join Date: Nov 2014
Rookie Year: 2014
Location: Reading, MA
Posts: 8
Brindlefly will become famous soon enough
Re: Help! Why Can't I Read Gyro Values Over the I2C Interface!

Ok I just figured it out. Here is the code for anyone who is interested.

Code:
private static double degrees = 0;
	
	private I2C gyro = RobotMap.gyro;
	
	public GyroSensor () {
		gyro.write(0x6B, 0x03); // Power
		gyro.write(0x1A, 0x18); // Basic Config
		gyro.write(0x1B, 0x00); // Gyro Config
	}
	
	public double getDegrees (double deltaTime) {
		byte[] angle = new byte[1];
		gyro.read(0x47, 1, angle);
		
		double rotation = (angle[0] * deltaTime) * 2;
		
		degrees += rotation;
		
		return -degrees;
	}
Reply With Quote
  #7   Spotlight this post!  
Unread 08-02-2015, 21:43
EricS-Team180's Avatar
EricS-Team180 EricS-Team180 is offline
SPAM, the lunchmeat of superheroes!
AKA: Eric Schreffler
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Apr 2002
Rookie Year: 2001
Location: Stuart, Florida
Posts: 561
EricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond repute
Re: Help! Why Can't I Read Gyro Values Over the I2C Interface!

Hey Thanks!
We were just looking for something like this <sweet>
__________________

Don't PANIC!
S. P. A. M.
Reply With Quote
  #8   Spotlight this post!  
Unread 20-03-2016, 01:01
David Lame David Lame is offline
Registered User
FRC #0247
 
Join Date: Feb 2015
Location: Berkley, MI
Posts: 86
David Lame is a jewel in the roughDavid Lame is a jewel in the roughDavid Lame is a jewel in the roughDavid Lame is a jewel in the rough
Re: Help! Why Can't I Read Gyro Values Over the I2C Interface!

Bumping this year old thread to thank the authors. This came up on a google search, and it was part of what got me able to get my new mpu6050 working.
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 11:52.

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