Go to Post Given the time Banebots has already cost us, what's a little snow? - pfreivald [more]
Home
Go Back   Chief Delphi > Technical > Control System > Sensors
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 23-10-2015, 08:06
acastagna acastagna is offline
Registered User
FRC #1493
 
Join Date: Jan 2012
Location: Albany High School
Posts: 34
acastagna is an unknown quantity at this point
I2C issues

We are having trouble getting an andymark am-2314 accel/gyro unit to send data on the i2C network. This is our first time using I2C are not sure if we are having a code or hardware issue. We have been working with the ADXL-345 to start with, but the real goal is to get the gyro working.

The unit is wired 3.3V to 3.3 V, ground to ground, SCL to SCL, and SDA to SDA. We also have a 4.7k pullup resistor between SCL and 3.3V. We checked that all connections are good and there are no shorts. We are measuring 3.27 volts into the 2314, so we know the I2C port on the roborio has power.

Any advice would be appreciated. Thanks!

The JAVA code looks like this:
Code:
package org.usfirst.frc.team1493.robot;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.I2C;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class Robot extends IterativeRobot {

// 0x1D is the default accel address, 0x53 is the secondary accel address

// 0b1101000 is the default gyro address, 0b1101001 is the secondary gyro address


private static final byte kAddress = 0x1d;  // also tried 0x53
private static final byte kPowerCtlRegister = 0x2D;
private static final byte kDataFormatRegister = 0x31; // also trued 0b100
private static final byte kDataRegister = 0x32;
private static final double kGsPerLSB = 0.00390625;
private static final byte kPowerCtl_Link = 0x20, kPowerCtl_AutoSleep = 0x10, kPowerCtl_Measure = 0b1100; 
private static final byte kPowerCtl_Sleep = 0x04, kRange = 0x00;
private static final byte kDataFormat_SelfTest = (byte) 0x80, kDataFormat_SPI = 0x40, kDataFormat_IntInvert = 0x20;
private static final byte kDataFormat_FullRes = 0x08, kDataFormat_Justify = 0x04;


I2C I2CBus = new I2C(I2C.Port.kOnboard,kAddress);
double accel[] = new double[3];

    public void robotInit() {

// Turn on the measurements
//also tried this
// I2CBus.write(kPowerCtlRegister, 0);   //kPowerCtl_Measure);
// I2CBus.write(kPowerCtlRegister, 16);   //kPowerCtl_Measure);
// I2CBus.write(kPowerCtlRegister, 8);   //kPowerCtl_Measure);

I2CBus.write(kPowerCtlRegister, kPowerCtl_Measure);
I2CBus.write(kDataFormatRegister, kDataFormat_FullRes | kRange);
    }

    public void autonomousPeriodic() {
    }

    public void teleopPeriodic() {
       accel = getADXL345Data();
    }

    public void testPeriodic() {
    }

    public double [] getADXL345Data(){
    short x_axis,y_axis,z_axis;
    double acceleration[] = new double[3];
    byte buff[] = new byte[6];                                                                                                                                                                        
    I2CBus.read(kDataRegister,6,buff);

// also tried this to convert from bytes to integer
//    ByteBuffer convbuffer = ByteBuffer.wrap(buff);
//     convbuffer.order(ByteOrder.BIG_ENDIAN);
//     x_axis = convbuffer.getShort();
//     y_axis = convbuffer.getShort();
//     z_axis = convbuffer.getShort();

    x_axis = (short)((((int)buff[1])<<8) | buff[0]);
    y_axis = (short)((((int)buff[3])<<8) | buff[2]);
    z_axis = (short)((((int)buff[5])<<8) | buff[4]);
    acceleration[0] = x_axis * kGsPerLSB;
    acceleration[1] =  y_axis* kGsPerLSB;
    acceleration[2] = z_axis * kGsPerLSB;
    Timer.delay(0.050);

SmartDashboard.putString("DB/String 0", "buff0 " + (int)buff[0]);
SmartDashboard.putString("DB/String 1", "buff1 " + (int)buff[1]);
SmartDashboard.putString("DB/String 2", "buff2 " + (int)buff[2]);
SmartDashboard.putString("DB/String 3", "buff3 " + (int)buff[3]);
SmartDashboard.putString("DB/String 4", "buff4 " + (int)buff[4]);
SmartDashboard.putString("DB/String 5", "buff5 " + (int)buff[5]);
SmartDashboard.putNumber("DB/String 6",   x_axis);
SmartDashboard.putNumber("DB/String 7",   y_axis);
SmartDashboard.putNumber("DB/String 8",   z_axis);
// check if we are getting to this method
// SmartDashboard.putString("DB/String 8", "scale "+(int)(kGsPerLSB*1000));

    return acceleration;

    }

    

}
Reply With Quote
  #2   Spotlight this post!  
Unread 01-11-2015, 09:11
sraque's Avatar
sraque sraque is offline
Registered User
AKA: Steve Raque
FRC #2614 (MARS)
Team Role: Mentor
 
Join Date: Jun 2012
Rookie Year: 2009
Location: Morgantown, WV
Posts: 79
sraque is on a distinguished road
Re: I2C issues

We are a Labview Team, so I am going to be of limited help. For Labview, there are a large number of examples, and one of them is for the ADXL. If there are also examples provided in JAVA, then you may be able to narrow down the possible issues. I suppose you could also install the Labview environment and use this one example to narrow down your problem to code or hardware.
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 02:31.

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