当前位置: 首页>>代码示例>>Java>>正文


Java I2CDevice.read方法代码示例

本文整理汇总了Java中com.pi4j.io.i2c.I2CDevice.read方法的典型用法代码示例。如果您正苦于以下问题:Java I2CDevice.read方法的具体用法?Java I2CDevice.read怎么用?Java I2CDevice.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.pi4j.io.i2c.I2CDevice的用法示例。


在下文中一共展示了I2CDevice.read方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
/**
 * Alter these values to change device operation
 *
 * @param args
 * @throws java.io.IOException
 * @throws com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException
 * @throws java.lang.InterruptedException
 */
// Device addresses 0x29, 0x39, 0x49 are possible by setting addr pin to
// GND, Floating, and +3.3V respectively
public static void main(String[] args)
        throws IOException, I2CFactory.UnsupportedBusNumberException, InterruptedException {
    // Set up the I2C libraries
    I2CBus I2C_BUS;
    I2CDevice TSL2561;

    // Get i2c I2C_BUS
    // Number depends on RasPI version
    I2C_BUS = I2CFactory.getInstance(I2CBus.BUS_1);

    System.out.println("Connected to bus. OK.");

    // Get device itself
    TSL2561 = I2C_BUS.getDevice(TSL2561_ADDR);
    System.out.println("Connected to device.");

    System.out.println("Device ID: " + TSL2561.read(TSL2561_REG_ID));

    // Initialize device by issuing command with data value 0x03        
    TSL2561.write(TSL2561_REG_CONTROL, TSL2561_POWER_UP);

    while (true) {
        System.out.println("Waiting...");
        Thread.sleep(500);

        byte d0L = (byte) TSL2561.read((byte) (TCS34725_COMMAND_BIT | DATA_0_LOW));
        byte d0H = (byte) TSL2561.read((byte) (TCS34725_COMMAND_BIT | DATA_0_HIGH));
        byte d1L = (byte) TSL2561.read((byte) (TCS34725_COMMAND_BIT | DATA_1_LOW));
        byte d1H = (byte) TSL2561.read((byte) (TCS34725_COMMAND_BIT | DATA_1_HIGH));

        if (VERBOSE) {
            System.out.println("Data 0: " + bytesToInt(d0H, d0L));
            System.out.println("Data 1: " + bytesToInt(d1H, d1L));
        }
    }
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:47,代码来源:TSL2561_First_Test.java

示例2: main

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
/**
 * Program Main Entry Point
 *
 * @param args
 * @throws InterruptedException
 * @throws PlatformAlreadyAssignedException
 * @throws IOException
 * @throws UnsupportedBusNumberException
 */
public static void main(String[] args) throws InterruptedException, PlatformAlreadyAssignedException, IOException, UnsupportedBusNumberException {

    // ####################################################################
    //
    // since we are not using the default Raspberry Pi platform, we should
    // explicitly assign the platform as the OrangePi platform.
    //
    // ####################################################################
    PlatformManager.setPlatform(Platform.ORANGEPI);

    // create Pi4J console wrapper/helper
    // (This is a utility class to abstract some of the boilerplate code)
    final Console console = new Console();

    // print program title/header
    console.title("<-- The Pi4J Project -->", "I2C Example");

    // allow for user to exit program using CTRL-C
    console.promptForExit();

    // get the I2C bus to communicate on
    I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_0);

    // create an I2C device for an individual device on the bus that you want to communicate with
    // in this example we will use the default address for the TSL2561 chip which is 0x39.
    I2CDevice device = i2c.getDevice(TSL2561_ADDR);

    // next, lets perform am I2C READ operation to the TSL2561 chip
    // we will read the 'ID' register from the chip to get its part number and silicon revision number
    console.println("... reading ID register from TSL2561");
    int response = device.read(TSL2561_REG_ID);
    console.println("TSL2561 ID = " + String.format("0x%02x", response) + " (should be 0x50)");

    // next we want to start taking light measurements, so we need to power up the sensor
    console.println("... powering up TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_UP);

    // wait while the chip collects data
    Thread.sleep(500);

    // now we will perform our first I2C READ operation to retrieve raw integration
    // results from DATA_0 and DATA_1 registers
    console.println("... reading DATA registers from TSL2561");
    int data0 = device.read(TSL2561_REG_DATA_0);
    int data1 = device.read(TSL2561_REG_DATA_1);

    // print raw integration results from DATA_0 and DATA_1 registers
    console.println("TSL2561 DATA 0 = " + String.format("0x%02x", data0));
    console.println("TSL2561 DATA 1 = " + String.format("0x%02x", data1));

    // before we exit, lets not forget to power down light sensor
    console.println("... powering down TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_DOWN);
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:64,代码来源:I2CExample.java

示例3: main

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
/**
 * Program Main Entry Point
 *
 * @param args
 * @throws InterruptedException
 * @throws PlatformAlreadyAssignedException
 * @throws IOException
 * @throws UnsupportedBusNumberException
 */
public static void main(String[] args) throws InterruptedException, PlatformAlreadyAssignedException, IOException, UnsupportedBusNumberException {

    // ####################################################################
    //
    // since we are not using the default Raspberry Pi platform, we should
    // explicitly assign the platform as the Odroid platform.
    //
    // ####################################################################
    PlatformManager.setPlatform(Platform.ODROID);

    // create Pi4J console wrapper/helper
    // (This is a utility class to abstract some of the boilerplate code)
    final Console console = new Console();

    // print program title/header
    console.title("<-- The Pi4J Project -->", "I2C Example");

    // allow for user to exit program using CTRL-C
    console.promptForExit();

    // get the I2C bus to communicate on
    // - I2CBus.BUS_1 uses 40 pin header, pin #3 as I2CA_SDA (SDA1) and pin #5 as I2CA_SCL (SCL1)
    // - I2CBus.BUS_2 uses 40 pin header, pin #27 as I2CB_SDA (SDA2) and pin #28 as I2CB_SCL (SCL2)
    // see GPIO PIN MAP here: http://www.hardkernel.com/main/products/prdt_info.php?g_code=G143703355573&tab_idx=2
    I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_2);

    // create an I2C device for an individual device on the bus that you want to communicate with
    // in this example we will use the default address for the TSL2561 chip which is 0x39.
    I2CDevice device = i2c.getDevice(TSL2561_ADDR);

    // next, lets perform am I2C READ operation to the TSL2561 chip
    // we will read the 'ID' register from the chip to get its part number and silicon revision number
    console.println("... reading ID register from TSL2561");
    int response = device.read(TSL2561_REG_ID);
    console.println("TSL2561 ID = " + String.format("0x%02x", response) + " (should be 0x50)");

    // next we want to start taking light measurements, so we need to power up the sensor
    console.println("... powering up TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_UP);

    // wait while the chip collects data
    Thread.sleep(500);

    // now we will perform our first I2C READ operation to retrieve raw integration
    // results from DATA_0 and DATA_1 registers
    console.println("... reading DATA registers from TSL2561");
    int data0 = device.read(TSL2561_REG_DATA_0);
    int data1 = device.read(TSL2561_REG_DATA_1);

    // print raw integration results from DATA_0 and DATA_1 registers
    console.println("TSL2561 DATA 0 = " + String.format("0x%02x", data0));
    console.println("TSL2561 DATA 1 = " + String.format("0x%02x", data1));

    // before we exit, lets not forget to power down light sensor
    console.println("... powering down TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_DOWN);
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:67,代码来源:I2CExample.java

示例4: main

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
/**
 * Program Main Entry Point
 *
 * @param args
 * @throws InterruptedException
 * @throws PlatformAlreadyAssignedException
 * @throws IOException
 * @throws UnsupportedBusNumberException
 */
public static void main(String[] args) throws InterruptedException, PlatformAlreadyAssignedException, IOException, UnsupportedBusNumberException {

    // ####################################################################
    //
    // since we are not using the default Raspberry Pi platform, we should
    // explicitly assign the platform as the BananaPro platform.
    //
    // ####################################################################
    PlatformManager.setPlatform(Platform.BANANAPRO);

    // create Pi4J console wrapper/helper
    // (This is a utility class to abstract some of the boilerplate code)
    final Console console = new Console();

    // print program title/header
    console.title("<-- The Pi4J Project -->", "I2C Example");

    // allow for user to exit program using CTRL-C
    console.promptForExit();

    // get the I2C bus to communicate on
    // - I2CBus.BUS_2 uses header pin CON6:3 as SDA and header pin CON6:5 as SCL
    // - I2CBus.BUS_3 uses header pin CON6:27 as SDA and header pin CON6:28 as SCL
    I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_2);

    // create an I2C device for an individual device on the bus that you want to communicate with
    // in this example we will use the default address for the TSL2561 chip which is 0x39.
    I2CDevice device = i2c.getDevice(TSL2561_ADDR);

    // next, lets perform am I2C READ operation to the TSL2561 chip
    // we will read the 'ID' register from the chip to get its part number and silicon revision number
    console.println("... reading ID register from TSL2561");
    int response = device.read(TSL2561_REG_ID);
    console.println("TSL2561 ID = " + String.format("0x%02x", response) + " (should be 0x50)");

    // next we want to start taking light measurements, so we need to power up the sensor
    console.println("... powering up TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_UP);

    // wait while the chip collects data
    Thread.sleep(500);

    // now we will perform our first I2C READ operation to retrieve raw integration
    // results from DATA_0 and DATA_1 registers
    console.println("... reading DATA registers from TSL2561");
    int data0 = device.read(TSL2561_REG_DATA_0);
    int data1 = device.read(TSL2561_REG_DATA_1);

    // print raw integration results from DATA_0 and DATA_1 registers
    console.println("TSL2561 DATA 0 = " + String.format("0x%02x", data0));
    console.println("TSL2561 DATA 1 = " + String.format("0x%02x", data1));

    // before we exit, lets not forget to power down light sensor
    console.println("... powering down TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_DOWN);
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:66,代码来源:I2CExample.java

示例5: main

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
/**
 * Program Main Entry Point
 *
 * @param args
 * @throws InterruptedException
 * @throws PlatformAlreadyAssignedException
 * @throws IOException
 * @throws UnsupportedBusNumberException
 */
public static void main(String[] args) throws InterruptedException, PlatformAlreadyAssignedException, IOException, UnsupportedBusNumberException {

    // ####################################################################
    //
    // since we are not using the default Raspberry Pi platform, we should
    // explicitly assign the platform as the BananaPi platform.
    //
    // ####################################################################
    PlatformManager.setPlatform(Platform.BANANAPI);

    // create Pi4J console wrapper/helper
    // (This is a utility class to abstract some of the boilerplate code)
    final Console console = new Console();

    // print program title/header
    console.title("<-- The Pi4J Project -->", "I2C Example");

    // allow for user to exit program using CTRL-C
    console.promptForExit();

    // get the I2C bus to communicate on
    // - I2CBus.BUS_2 uses header pin CON3:3 as SDA and header pin CON3:5 as SCL
    I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_2);

    // create an I2C device for an individual device on the bus that you want to communicate with
    // in this example we will use the default address for the TSL2561 chip which is 0x39.
    I2CDevice device = i2c.getDevice(TSL2561_ADDR);

    // next, lets perform am I2C READ operation to the TSL2561 chip
    // we will read the 'ID' register from the chip to get its part number and silicon revision number
    console.println("... reading ID register from TSL2561");
    int response = device.read(TSL2561_REG_ID);
    console.println("TSL2561 ID = " + String.format("0x%02x", response) + " (should be 0x50)");

    // next we want to start taking light measurements, so we need to power up the sensor
    console.println("... powering up TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_UP);

    // wait while the chip collects data
    Thread.sleep(500);

    // now we will perform our first I2C READ operation to retrieve raw integration
    // results from DATA_0 and DATA_1 registers
    console.println("... reading DATA registers from TSL2561");
    int data0 = device.read(TSL2561_REG_DATA_0);
    int data1 = device.read(TSL2561_REG_DATA_1);

    // print raw integration results from DATA_0 and DATA_1 registers
    console.println("TSL2561 DATA 0 = " + String.format("0x%02x", data0));
    console.println("TSL2561 DATA 1 = " + String.format("0x%02x", data1));

    // before we exit, lets not forget to power down light sensor
    console.println("... powering down TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_DOWN);
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:65,代码来源:I2CExample.java

示例6: main

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
/**
 * Program Main Entry Point
 *
 * @param args
 * @throws InterruptedException
 * @throws PlatformAlreadyAssignedException
 * @throws IOException
 * @throws UnsupportedBusNumberException
 */
public static void main(String[] args) throws InterruptedException, PlatformAlreadyAssignedException, IOException, UnsupportedBusNumberException {

    // create Pi4J console wrapper/helper
    // (This is a utility class to abstract some of the boilerplate code)
    final Console console = new Console();

    // print program title/header
    console.title("<-- The Pi4J Project -->", "I2C Example");

    // allow for user to exit program using CTRL-C
    console.promptForExit();

    // get the I2C bus to communicate on
    I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_1);

    // create an I2C device for an individual device on the bus that you want to communicate with
    // in this example we will use the default address for the TSL2561 chip which is 0x39.
    I2CDevice device = i2c.getDevice(TSL2561_ADDR);

    // next, lets perform am I2C READ operation to the TSL2561 chip
    // we will read the 'ID' register from the chip to get its part number and silicon revision number
    console.println("... reading ID register from TSL2561");
    int response = device.read(TSL2561_REG_ID);
    console.println("TSL2561 ID = " + String.format("0x%02x", response) + " (should be 0x50)");

    // next we want to start taking light measurements, so we need to power up the sensor
    console.println("... powering up TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_UP);

    // wait while the chip collects data
    Thread.sleep(500);

    // now we will perform our first I2C READ operation to retrieve raw integration
    // results from DATA_0 and DATA_1 registers
    console.println("... reading DATA registers from TSL2561");
    int data0 = device.read(TSL2561_REG_DATA_0);
    int data1 = device.read(TSL2561_REG_DATA_1);

    // print raw integration results from DATA_0 and DATA_1 registers
    console.println("TSL2561 DATA 0 = " + String.format("0x%02x", data0));
    console.println("TSL2561 DATA 1 = " + String.format("0x%02x", data1));

    // before we exit, lets not forget to power down light sensor
    console.println("... powering down TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_DOWN);
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:56,代码来源:I2CExample.java


注:本文中的com.pi4j.io.i2c.I2CDevice.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。