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


Java I2CBus.getDevice方法代码示例

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


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

示例1: main

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的package包/类
public static void main(String[] args) 
        throws IOException, I2CFactory.UnsupportedBusNumberException, 
        InterruptedException {
    
    // Connect to I2C bus 1
    I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_1);
    
    // Create device object
    I2CDevice device = i2c.getDevice(PCF8574P_ADDRESS);
    
    while(true) {
        device.write((byte)0x40,(byte)0);
        Thread.sleep(1000);
        device.write((byte)0x40,(byte)1);
    }
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:17,代码来源:PFC8574P.java

示例2: initialize

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的package包/类
@Override
public void initialize(ConfigurationProvider configurationProvider) throws IOException {
    // this is a "robot leg problem"
    // see https://github.com/google/guice/wiki/FrequentlyAskedQuestions#How_do_I_build_two_similar_but_slightly_different_trees_of_objec
    // we have a leftMotor and a rightMotor - same class, different configuration
    // I did not use the private module solution as it is a bit scary to look at. But maybe:
    // TODO: clean this mess up - MotorControllers should be injected
    I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
    I2CDevice device = bus.getDevice(0x40);
    PCA9685PWMGenerator driver = new PCA9685PWMGenerator(device);
    driver.open();
    driver.setFrequency(50);

    leftMotor = new MotorControllerImpl(driver.getOutput(14),
            configurationProvider.bind("motorLeft", MotorControllerConfiguration.class));
    rightMotor = new MotorControllerImpl(driver.getOutput(15),
            configurationProvider.bind("motorRight", MotorControllerConfiguration.class));

    LOGGER.debug("Completed setting up DriveController");
}
 
开发者ID:weiss19ja,项目名称:amos-ss16-proj2,代码行数:21,代码来源:DriveControllerImpl.java

示例3: initialize

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的package包/类
@Override
public void initialize(ConfigurationProvider configurationProvider) throws IOException {
    super.initialize(configurationProvider);

    I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
    I2CDevice device = bus.getDevice(0x40);
    PCA9685PWMGenerator driver = new PCA9685PWMGenerator(device);
    driver.open();
    driver.setFrequency(50);

    horizontalHeadMotor = new ServoControllerImpl(driver.getOutput(1),
            configurationProvider.bind("servo1", ServoConfiguration.class));
    verticalHeadMotor = new ServoControllerImpl(driver.getOutput(0),
            configurationProvider.bind("servo0", ServoConfiguration.class));

    horizontalHeadMotor.setPosition(headPositionHorizontal);
    verticalHeadMotor.setPosition(headPositionVertical);
    LOGGER.debug("Completed setting up HeadController");
}
 
开发者ID:weiss19ja,项目名称:amos-ss16-proj2,代码行数:20,代码来源:HeadControllerImpl.java

示例4: getDevice

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的package包/类
public I2CDevice getDevice(int busAddress, int deviceAddress) {
	try {
		String key = String.format("%d.%d", busAddress, deviceAddress);
		if (!devices.containsKey(key)) {
			// FIXME -- remove put in createDevice
			I2CBus bus = I2CFactory.getInstance(busAddress);
			log.info(String.format("getDevice %d", deviceAddress));
			I2CDevice device = bus.getDevice(deviceAddress);

			Device d = new Device();
			d.bus = bus;
			d.device = device;
			d.type = "display";

			devices.put(key, d);
			return d.device;

		} else {
			return devices.get(key).device;
		}
	} catch (Exception e) {
		Logging.logError(e);
	}

	return null;
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:27,代码来源:RasPi.java

示例5: writeToDisplay

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的package包/类
public void writeToDisplay(int address, byte b0, byte b1, byte b2, byte b3) {
  try {

    I2CBus i2cbus = I2CFactory.getInstance(rasPiBus);
    I2CDevice device = i2cbus.getDevice(address);
    device.write(address, (byte) 0x80);

    I2CDevice display = i2cbus.getDevice(0x38);
    display.write(new byte[] { 0, 0x17, b0, b1, b2, b3 }, 0, 6);

    device.write(address, (byte) 0x83);

  } catch (Exception e) {
    Logging.logError(e);
  }
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:17,代码来源:PickToLight.java

示例6: BME280

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的package包/类
public BME280() {
    try {
        // Create I2C bus
        I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
        // Get I2C device, BME280 I2C address is 0x76(108)
        device = bus.getDevice(0x76);
    } catch (Exception e) {
        Logger.error("Failed to get BME280.");
        e.printStackTrace();
    }
}
 
开发者ID:Siketyan,项目名称:TempMonitor,代码行数:12,代码来源:BME280.java

示例7: main

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的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

示例8: writeToDisplay

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的package包/类
public void writeToDisplay(int address, byte b0, byte b1, byte b2, byte b3) {
	try {

		I2CBus i2cbus = I2CFactory.getInstance(rasPiBus);
		I2CDevice device = i2cbus.getDevice(address);
		device.write(address, (byte) 0x80);

		I2CDevice display = i2cbus.getDevice(0x38);
		display.write(new byte[] { 0, 0x17, b0, b1, b2, b3 }, 0, 6);

		device.write(address, (byte) 0x83);

	} catch (Exception e) {
		Logging.logError(e);
	}
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:17,代码来源:PickToLight.java

示例9: create

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的package包/类
public static Optional<NodeController> create(int busNum, int address) {
  try {
    I2CBus bus = I2CFactory.getInstance(busNum);
    LOG.info("Connected to I2C bus.");

    I2CDevice device = bus.getDevice(address);
    LOG.info("Connected to device");
    return Optional.of(new HTU21DControllerImpl(bus, device));
  } catch (IOException e) {
    LOG.error("Cannot create I2C temp sensor controller.", e);
  }
  return Optional.empty();
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:14,代码来源:HTU21DControllerImpl.java

示例10: IrListener

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的package包/类
private IrListener() throws IOException, I2CFactory.UnsupportedBusNumberException {
    super("IR Listener", Command.CLOSE);
    Reporting.registerControl("IR Listener", 'i');
    gpio = GpioFactory.getInstance();
    i2cInt = gpio.provisionDigitalInputPin(RaspiPin.GPIO_07, "I2C interrupt");
    i2cInt.setShutdownOptions(true);
    I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
    device = bus.getDevice(0x60);
}
 
开发者ID:The-Retired-Programmer,项目名称:gpssurvey,代码行数:10,代码来源:IrListener.java

示例11: WiiMotionPlus

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的package包/类
public WiiMotionPlus(I2CBus bus) throws IOException {
    initDevice = bus.getDevice(0x53);
    device = bus.getDevice(0x52);
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:5,代码来源:I2CWiiMotionPlusExample.java

示例12: main

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的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

示例13: main

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的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

示例14: main

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的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

示例15: main

import com.pi4j.io.i2c.I2CBus; //导入方法依赖的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


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