View Single Post
  #1   Spotlight this post!  
Unread 10-01-2017, 20:22
Joe_Chase Joe_Chase is offline
Registered User
FTC #3397
 
Join Date: Dec 2013
Location: Essex, VT
Posts: 2
Joe_Chase is an unknown quantity at this point
I2C Help reading sparkfun line follower array

We're trying to read the line follower array with no success. It returns no data when read. The hardware (LED's, wires) is definitely working

The Device: https://www.sparkfun.com/products/13582

Has anybody got this device working? Help is appreciated.

Code:
package org.firstinspires.ftc.robotcontroller.internal;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DigitalChannel;
import com.qualcomm.robotcore.hardware.I2cAddr;
import com.qualcomm.robotcore.hardware.I2cController;
import com.qualcomm.robotcore.hardware.I2cDevice;
import java.util.concurrent.locks.Lock;
import com.qualcomm.robotcore.hardware.DeviceInterfaceModule;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.I2cDeviceSynchImpl;

/**
 * Created by greenteam on 1/7/17.
 */

@TeleOp(name = "LineSensor", group = "Sensor")

public class LineFollower extends OpMode {

    I2cDevice device;
    boolean ready;
    I2cAddr address;
    I2cDeviceSynchImpl sync;
    byte sensorData;

    @Override
    public void init(){
        device = hardwareMap.i2cDevice.get("LineFollower");
        address = I2cAddr.create7bit(0x3E);
        sync = new I2cDeviceSynchImpl(device, address, false);
        sync.engage();
    }

    @Override
    public void loop(){
        ready = device.isI2cPortReady();
        if(ready){
            byte sensorData = sync.read8(0x00);
        }
        DisplayData();
    }

    public void DisplayData() {
        telemetry.addData("Ready: ", ready ? "True" : "False");
        String s = String.format("%02X", sensorData);
        telemetry.addData("Data: ", s);
    }

}
Reply With Quote