本文整理汇总了Java中com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException类的典型用法代码示例。如果您正苦于以下问题:Java UnsupportedBusNumberException类的具体用法?Java UnsupportedBusNumberException怎么用?Java UnsupportedBusNumberException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnsupportedBusNumberException类属于com.pi4j.io.i2c.I2CFactory包,在下文中一共展示了UnsupportedBusNumberException类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: WiringPiI2CDevice
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的package包/类
public WiringPiI2CDevice(String key, DeviceFactoryInterface deviceFactory, int controller, int address,
int addressSize, int clockFrequency) throws RuntimeIOException {
super(key, deviceFactory);
this.controller = controller;
this.address = address;
/*
handle = I2C.wiringPiI2CSetup(address);
if (handle == -1) {
handle = CLOSED;
throw new IOException("Error in I2C.wiringPiI2CSetup(" + address + ")");
}
*/
Logger.debug("Opening I2C device ({}, 0x{})...",
Integer.valueOf(controller), Integer.toHexString(address));
try {
device = I2CFactory.getInstance(controller).getDevice(address);
} catch (UnsupportedBusNumberException | IOException e) {
throw new RuntimeIOException(e);
}
Logger.debug("I2C device ({}, 0x{}) opened",
Integer.valueOf(controller), Integer.toHexString(address));
}
开发者ID:mattjlewis,项目名称:diozero,代码行数:24,代码来源:WiringPiI2CDevice.java
示例2: Pi4jI2CDevice
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的package包/类
public Pi4jI2CDevice(String key, DeviceFactoryInterface deviceFactory, int controller, int address,
int addressSize, int clockFrequency) throws RuntimeIOException {
super(key, deviceFactory);
this.controller = controller;
this.address = address;
Logger.debug(String.format("Opening I2C device ({}, 0x{})...",
Integer.valueOf(controller), Integer.toHexString(address)));
try {
device = I2CFactory.getInstance(controller).getDevice(address);
} catch (UnsupportedBusNumberException | IOException e) {
throw new RuntimeIOException(e);
}
Logger.debug(String.format("I2C device ({}, 0x{}) opened",
Integer.valueOf(controller), Integer.toHexString(address)));
}
开发者ID:mattjlewis,项目名称:diozero,代码行数:17,代码来源:Pi4jI2CDevice.java
示例3: createProvider
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的package包/类
private PCA9685GpioProvider createProvider() throws UnsupportedBusNumberException, IOException {
BigDecimal frequency = PCA9685GpioProvider.ANALOG_SERVO_FREQUENCY;
BigDecimal frequencyCorrectionFactor = new BigDecimal("1.0578");
I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
return new PCA9685GpioProvider(bus, 0x40, frequency, frequencyCorrectionFactor);
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:8,代码来源:PCA9685GpioServoExample.java
示例4: main
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, UnsupportedBusNumberException, IOException {
System.out.println("<--Pi4J--> MCP3424 GPIO Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// create custom MCP3424 GPIO provider
final MCP3424GpioProvider provider = new MCP3424GpioProvider(I2CBus.BUS_1, 0x6C, 18, 1);
// provision gpio input pins from MCP3424
GpioPinAnalogInput inputs[] = { gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH0, "Channel-0"),
gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH1, "Channel-1"),
gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH2, "Channel-2"),
gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH3, "Channel-3") };
// Keep this sample program running for 10 minutes
for (int count = 0; count < 600; count++) {
StringBuilder sb = new StringBuilder();
// Print current analog input conversion values from each input channel
for(GpioPinAnalogInput input : inputs){
double analog = provider.getAnalogValue(input.getPin());
sb.append(" \t[" + input.getValue() + " -> " + analog + " V] ");
}
// Print out all analog input conversion values
System.out.println("<MCP3424 VALUES> " + sb.toString());
Thread.sleep(1000);
}
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
gpio.shutdown();
System.out.println("<--Pi4J--> Exiting MCP3424 GPIO Example.");
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:39,代码来源:MCP3424GpioExampleNonMonitored.java
示例5: main
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的package包/类
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws InterruptedException, UnsupportedBusNumberException, IOException{
System.out.println("Turbidostat Application Run");
System.out.println("Setting up Raspberry Pi and Syringe Pumps");
final GpioController gpio = GpioFactory.getInstance();
MCP23017_Control MCPControl0x20 = new MCP23017_Control(0x20);
MCP23017_Control MCPControl0x21 = new MCP23017_Control(0x21);
Fluids fluids = new Fluids();
for(int i = 0; i < 3; i++) {
SyringePump addPump = new SyringePump(
MCPControl0x20.provisionOutput(DIR_PINS[i], PinState.LOW),
MCPControl0x20.provisionOutput(STEP_PINS[i], PinState.LOW),
MCPControl0x20.provisionOutput(ENABLE_PINS[i], PinState.LOW),
MCPControl0x21.provisionInput(MAX_STOP_PINS[i]),
MCPControl0x21.provisionInput(MIN_STOP_PINS[i]),
DEFAULT_RATE
);
fluids.addPump(addPump);
}
/////// INSERT FLUIDS COMMANDS HERE
System.out.println("Calibrating pumps");
for(int i = 0; i < 3; i++) {
System.out.println("Calibrating pump #" + i);
fluids.calibrateFrom(i);
}
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:40,代码来源:Tstat.java
示例6: main
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, UnsupportedBusNumberException, IOException {
System.out.println("<--Pi4J--> MCP3424 GPIO Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// create custom MCP3424 GPIO provider
final MCP3424GpioProvider provider = new MCP3424GpioProvider(I2CBus.BUS_1, 0x6C, 18, 1);
// provision gpio input pins from MCP3424
GpioPinAnalogInput inputs[] = { gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH0, "Channel-0"),
gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH1, "Channel-1"),
gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH2, "Channel-2"),
gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH3, "Channel-3") };
// Define the amount that the ADC input conversion value must change before
// a 'GpioPinAnalogValueChangeEvent' is raised. This is used to prevent unnecessary
// event dispatching for an analog input that may have an acceptable or expected
// range of value drift.
provider.setEventThreshold(0, inputs); // all inputs; alternatively you can set thresholds on each input discretely
// Print current analog input conversion values from each input channel
for(GpioPinAnalogInput input : inputs){
System.out.print("<INITIAL VALUE> [" + input.getName() + "] : RAW VALUE = " + input.getValue());
System.out.println(" -> " + provider.getAnalogValue(input.getPin()) + " V");
}
// create and register gpio pin listener
gpio.addListener(new GpioPinListenerAnalog() {
@Override
public void handleGpioPinAnalogValueChangeEvent(GpioPinAnalogValueChangeEvent event) {
// get pin
GpioPin pin = event.getPin();
// get RAW value
double value = event.getValue();
// get Volt value
double analog = provider.getAnalogValue(pin.getPin());
// display output
System.out.print("<CHANGED VALUE> [" + pin + "] : RAW VALUE = " + value);
System.out.println(" -> " + analog + " V");
}
}, inputs);
provider.setMonitorInterval(50);
provider.setMonitorEnabled(true);
// Keep this sample program running for 10 minutes
for (int count = 0; count < 600; count++) {
Thread.sleep(1000);
}
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
gpio.shutdown();
System.out.println("<--Pi4J--> Exiting MCP3424 GPIO Example.");
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:62,代码来源:MCP3424GpioExample.java
示例7: main
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的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
示例8: main
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的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
示例9: main
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的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
示例10: main
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, UnsupportedBusNumberException, IOException {
System.out.println("<--Pi4J--> ADS1115 GPIO Example ... started.");
// number formatters
final DecimalFormat df = new DecimalFormat("#.##");
final DecimalFormat pdf = new DecimalFormat("###.#");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// create custom ADS1115 GPIO provider
final ADS1115GpioProvider gpioProvider = new ADS1115GpioProvider(I2CBus.BUS_1, ADS1115GpioProvider.ADS1115_ADDRESS_0x48);
// provision gpio analog input pins from ADS1115
GpioPinAnalogInput myInputs[] = {
gpio.provisionAnalogInputPin(gpioProvider, ADS1115Pin.INPUT_A0, "MyAnalogInput-A0"),
gpio.provisionAnalogInputPin(gpioProvider, ADS1115Pin.INPUT_A1, "MyAnalogInput-A1"),
gpio.provisionAnalogInputPin(gpioProvider, ADS1115Pin.INPUT_A2, "MyAnalogInput-A2"),
gpio.provisionAnalogInputPin(gpioProvider, ADS1115Pin.INPUT_A3, "MyAnalogInput-A3"),
};
// ATTENTION !!
// It is important to set the PGA (Programmable Gain Amplifier) for all analog input pins.
// (You can optionally set each input to a different value)
// You measured input voltage should never exceed this value!
//
// In my testing, I am using a Sharp IR Distance Sensor (GP2Y0A21YK0F) whose voltage never exceeds 3.3 VDC
// (http://www.adafruit.com/products/164)
//
// PGA value PGA_4_096V is a 1:1 scaled input,
// so the output values are in direct proportion to the detected voltage on the input pins
gpioProvider.setProgrammableGainAmplifier(ProgrammableGainAmplifierValue.PGA_4_096V, ADS1115Pin.ALL);
// Define a threshold value for each pin for analog value change events to be raised.
// It is important to set this threshold high enough so that you don't overwhelm your program with change events for insignificant changes
gpioProvider.setEventThreshold(500, ADS1115Pin.ALL);
// Define the monitoring thread refresh interval (in milliseconds).
// This governs the rate at which the monitoring thread will read input values from the ADC chip
// (a value less than 50 ms is not permitted)
gpioProvider.setMonitorInterval(100);
// create analog pin value change listener
GpioPinListenerAnalog listener = new GpioPinListenerAnalog()
{
@Override
public void handleGpioPinAnalogValueChangeEvent(GpioPinAnalogValueChangeEvent event)
{
// RAW value
double value = event.getValue();
// percentage
double percent = ((value * 100) / ADS1115GpioProvider.ADS1115_RANGE_MAX_VALUE);
// approximate voltage ( *scaled based on PGA setting )
double voltage = gpioProvider.getProgrammableGainAmplifier(event.getPin()).getVoltage() * (percent/100);
// display output
System.out.println(" (" + event.getPin().getName() +") : VOLTS=" + df.format(voltage) + " | PERCENT=" + pdf.format(percent) + "% | RAW=" + value + " ");
}
};
myInputs[0].addListener(listener);
myInputs[1].addListener(listener);
myInputs[2].addListener(listener);
myInputs[3].addListener(listener);
// keep program running for 10 minutes
Thread.sleep(600000);
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
gpio.shutdown();
System.out.println("Exiting ADS1115GpioExample");
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:81,代码来源:ADS1115GpioExample.java
示例11: main
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, UnsupportedBusNumberException, IOException {
System.out.println("<--Pi4J--> MCP23017 GPIO Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// create custom MCP23017 GPIO provider
final MCP23017GpioProvider provider = new MCP23017GpioProvider(I2CBus.BUS_1, 0x21);
// provision gpio input pins from MCP23017
GpioPinDigitalInput myInputs[] = {
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A0, "MyInput-A0", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A1, "MyInput-A1", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A2, "MyInput-A2", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A3, "MyInput-A3", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A4, "MyInput-A4", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A5, "MyInput-A5", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A6, "MyInput-A6", PinPullResistance.PULL_UP),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A7, "MyInput-A7", PinPullResistance.PULL_UP),
};
// create and register gpio pin listener
gpio.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
// display pin state on console
System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = "
+ event.getState());
}
}, myInputs);
// provision gpio output pins and make sure they are all LOW at startup
GpioPinDigitalOutput myOutputs[] = {
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B0, "MyOutput-B0", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B1, "MyOutput-B1", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B2, "MyOutput-B2", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B3, "MyOutput-B3", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B4, "MyOutput-B4", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B5, "MyOutput-B5", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B6, "MyOutput-B6", PinState.LOW),
gpio.provisionDigitalOutputPin(provider, MCP23017Pin.GPIO_B7, "MyOutput-B7", PinState.LOW)
};
// keep program running for 20 seconds
for (int count = 0; count < 10; count++) {
gpio.setState(true, myOutputs);
Thread.sleep(1000);
gpio.setState(false, myOutputs);
Thread.sleep(1000);
}
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
gpio.shutdown();
System.out.println("Exiting MCP23017GpioExample");
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:59,代码来源:MCP23017GpioExample.java
示例12: main
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, UnsupportedBusNumberException, IOException {
System.out.println("<--Pi4J--> ADS1015 GPIO Example ... started.");
// number formatters
final DecimalFormat df = new DecimalFormat("#.##");
final DecimalFormat pdf = new DecimalFormat("###.#");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// create custom ADS1015 GPIO provider
final ADS1015GpioProvider gpioProvider = new ADS1015GpioProvider(I2CBus.BUS_1, ADS1015GpioProvider.ADS1015_ADDRESS_0x48);
// provision gpio analog input pins from ADS1015
GpioPinAnalogInput myInputs[] = {
gpio.provisionAnalogInputPin(gpioProvider, ADS1015Pin.INPUT_A0, "MyAnalogInput-A0"),
gpio.provisionAnalogInputPin(gpioProvider, ADS1015Pin.INPUT_A1, "MyAnalogInput-A1"),
gpio.provisionAnalogInputPin(gpioProvider, ADS1015Pin.INPUT_A2, "MyAnalogInput-A2"),
gpio.provisionAnalogInputPin(gpioProvider, ADS1015Pin.INPUT_A3, "MyAnalogInput-A3"),
};
// ATTENTION !!
// It is important to set the PGA (Programmable Gain Amplifier) for all analog input pins.
// (You can optionally set each input to a different value)
// You measured input voltage should never exceed this value!
//
// In my testing, I am using a Sharp IR Distance Sensor (GP2Y0A21YK0F) whose voltage never exceeds 3.3 VDC
// (http://www.adafruit.com/products/164)
//
// PGA value PGA_4_096V is a 1:1 scaled input,
// so the output values are in direct proportion to the detected voltage on the input pins
gpioProvider.setProgrammableGainAmplifier(ProgrammableGainAmplifierValue.PGA_4_096V, ADS1015Pin.ALL);
// Define a threshold value for each pin for analog value change events to be raised.
// It is important to set this threshold high enough so that you don't overwhelm your program with change events for insignificant changes
gpioProvider.setEventThreshold(500, ADS1015Pin.ALL);
// Define the monitoring thread refresh interval (in milliseconds).
// This governs the rate at which the monitoring thread will read input values from the ADC chip
// (a value less than 50 ms is not permitted)
gpioProvider.setMonitorInterval(100);
// create analog pin value change listener
GpioPinListenerAnalog listener = new GpioPinListenerAnalog()
{
@Override
public void handleGpioPinAnalogValueChangeEvent(GpioPinAnalogValueChangeEvent event)
{
// RAW value
double value = event.getValue();
// percentage
double percent = ((value * 100) / ADS1015GpioProvider.ADS1015_RANGE_MAX_VALUE);
// approximate voltage ( *scaled based on PGA setting )
double voltage = gpioProvider.getProgrammableGainAmplifier(event.getPin()).getVoltage() * (percent/100);
// display output
System.out.println(" (" + event.getPin().getName() +") : VOLTS=" + df.format(voltage) + " | PERCENT=" + pdf.format(percent) + "% | RAW=" + value + " ");
}
};
myInputs[0].addListener(listener);
myInputs[1].addListener(listener);
myInputs[2].addListener(listener);
myInputs[3].addListener(listener);
// keep program running for 10 minutes
Thread.sleep(600000);
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
gpio.shutdown();
System.out.println("Exiting ADS1015GpioExample");
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:81,代码来源:ADS1015GpioExample.java
示例13: main
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的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
示例14: main
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, UnsupportedBusNumberException, IOException {
System.out.println("<--Pi4J--> PCF8574 GPIO Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// create custom MCP23017 GPIO provider
final PCF8574GpioProvider provider = new PCF8574GpioProvider(I2CBus.BUS_1, PCF8574GpioProvider.PCF8574A_0x3F);
// provision gpio input pins from MCP23017
GpioPinDigitalInput myInputs[] = {
gpio.provisionDigitalInputPin(provider, PCF8574Pin.GPIO_00),
gpio.provisionDigitalInputPin(provider, PCF8574Pin.GPIO_01),
gpio.provisionDigitalInputPin(provider, PCF8574Pin.GPIO_02)
};
// create and register gpio pin listener
gpio.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
// display pin state on console
System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = "
+ event.getState());
}
}, myInputs);
// provision gpio output pins and make sure they are all LOW at startup
GpioPinDigitalOutput myOutputs[] = {
gpio.provisionDigitalOutputPin(provider, PCF8574Pin.GPIO_04, PinState.LOW),
gpio.provisionDigitalOutputPin(provider, PCF8574Pin.GPIO_05, PinState.LOW),
gpio.provisionDigitalOutputPin(provider, PCF8574Pin.GPIO_06, PinState.LOW)
};
// on program shutdown, set the pins back to their default state: HIGH
gpio.setShutdownOptions(true, PinState.HIGH, myOutputs);
// keep program running for 20 seconds
for (int count = 0; count < 10; count++) {
gpio.setState(true, myOutputs);
Thread.sleep(1000);
gpio.setState(false, myOutputs);
Thread.sleep(1000);
}
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
gpio.shutdown();
System.out.println("Exiting PCF8574GpioExample");
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:52,代码来源:PCF8574GpioExample.java
示例15: main
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的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
示例16: MCP23017_Control
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的package包/类
public MCP23017_Control(int address) throws UnsupportedBusNumberException, IOException {
this.gpio = GpioFactory.getInstance();
this.provider = new MCP23017GpioProvider(I2CBus.BUS_1, address);
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:6,代码来源:MCP23017_Control.java
示例17: main
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, UnsupportedBusNumberException, IOException {
System.out.println("<--Pi4J--> MCP23017 GPIO Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// create custom MCP23017 GPIO provider
final MCP23017GpioProvider provider = new MCP23017GpioProvider(I2CBus.BUS_1, 0x20);
// provision gpio input pins from MCP23017
GpioPinDigitalInput myInputs[] = {
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A0, "MyInput-A0", PinPullResistance.OFF),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A1, "MyInput-A1", PinPullResistance.OFF),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A2, "MyInput-A2", PinPullResistance.OFF),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A3, "MyInput-A3", PinPullResistance.OFF),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A4, "MyInput-A4", PinPullResistance.OFF),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A5, "MyInput-A5", PinPullResistance.OFF),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A6, "MyInput-A6", PinPullResistance.OFF),
gpio.provisionDigitalInputPin(provider, MCP23017Pin.GPIO_A7, "MyInput-A7", PinPullResistance.OFF),
};
// create and register gpio pin listener
gpio.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
// display pin state on console
System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = "
+ event.getState());
}
}, myInputs);
// provision gpio output pins and make sure they are all LOW at st
|
请发表评论