本文整理汇总了Java中com.pi4j.io.spi.SpiChannel类的典型用法代码示例。如果您正苦于以下问题:Java SpiChannel类的具体用法?Java SpiChannel怎么用?Java SpiChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SpiChannel类属于com.pi4j.io.spi包,在下文中一共展示了SpiChannel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: BMP280
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
public BMP280(Protocol protocol, int deviceID, int i2cBusID) throws Exception {
this.protocol = protocol;
if(protocol == Protocol.I2C) {
I2Cbus = I2CFactory.getInstance(i2cBusID);
I2Cdevice = I2Cbus.getDevice(deviceID);
}
else if(protocol == Protocol.SPI) {
/* Set SPI to run default speed (1Mhz) in default mode (Mode 0) */
SPIdevice = SpiFactory.getInstance(SpiChannel.CS0, SpiDevice.DEFAULT_SPI_SPEED, SpiDevice.DEFAULT_SPI_MODE);
}
else {
throw new Exception("Invalid protocol set: " + protocol);
}
loadCurrentConfigSettingsFromDevice();
loadCompensationValues();
}
开发者ID:whitestripes,项目名称:BMP280,代码行数:19,代码来源:BMP280.java
示例2: initSpi
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
/**
* Init the SPI controller using default bindings (7.8 MHz)
*
* If you observe flickering on longer runs, initializing with a slower speed like 4Mhz.
*
* @throws IOException If can't open SPI (not a raspi or not running sudo)
*/
public static void initSpi() throws IOException {
initSpi(
SpiChannel.CS0,
7800000, // see list of speeds at https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md
SpiDevice.DEFAULT_SPI_MODE
);
}
开发者ID:dlopuch,项目名称:apa102-java-rpi,代码行数:15,代码来源:Apa102Output.java
示例3: main
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
/**
* Sample SPI Program
*
* @param args (none)
* @throws InterruptedException
* @throws IOException
*/
public static void main(String args[]) throws InterruptedException, IOException {
// print program title/header
console.title("<-- The Pi4J Project -->", "SPI test program using MCP3004/MCP3008 AtoD Chip");
// allow for user to exit program using CTRL-C
console.promptForExit();
// This SPI example is using the Pi4J SPI interface to communicate with
// the SPI hardware interface connected to a MCP3004/MCP3008 AtoD Chip.
//
// Please make sure the SPI is enabled on your Raspberry Pi via the
// raspi-config utility under the advanced menu option.
//
// see this blog post for additional details on SPI and WiringPi
// http://wiringpi.com/reference/spi-library/
//
// see the link below for the data sheet on the MCP3004/MCP3008 chip:
// http://ww1.microchip.com/downloads/en/DeviceDoc/21294E.pdf
// create SPI object instance for SPI for communication
spi = SpiFactory.getInstance(SpiChannel.CS0,
SpiDevice.DEFAULT_SPI_SPEED, // default spi speed 1 MHz
SpiDevice.DEFAULT_SPI_MODE); // default spi mode 0
// continue running program until user exits using CTRL-C
while(console.isRunning()) {
read();
Thread.sleep(1000);
}
console.emptyLine();
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:40,代码来源:SpiExample.java
示例4: setRFID
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
public void setRFID(String pinRST, String cs) {
this.pinRFID = GPIOUtils.parsePin(pinRST);
if (cs!=null && cs.length()>0) {
int cs_i = Integer.parseInt(cs);
this.csRFID = SpiChannel.getByNumber(cs_i);
if (this.csRFID==null)
throw new UnsupportedOperationException("Invalid rfid.cs option:"+cs);
}
else {
this.csRFID = SpiChannel.CS0;
}
}
开发者ID:gustavohbf,项目名称:robotoy,代码行数:13,代码来源:RoboToyServerController.java
示例5: MFRC522
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
public MFRC522(GpioController gpio,Pin pinNRSTPD,SpiChannel channel) throws IOException {
this.pinNRSTPD = pinNRSTPD;
this.spiChannel = channel;
spi = SpiFactory.getInstance(spiChannel,
SpiDevice.DEFAULT_SPI_SPEED, // default spi speed 1 MHz
SpiDevice.DEFAULT_SPI_MODE); // default spi mode 0
rstOut = gpio.provisionDigitalOutputPin(pinNRSTPD, "RC522RST");
rstOut.setShutdownOptions(true, PinState.HIGH, PinPullResistance.OFF);
rstOut.high();
init();
}
开发者ID:gustavohbf,项目名称:robotoy,代码行数:13,代码来源:MFRC522.java
示例6: main
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try {
Adxl362 adxl362 = new Adxl362(SpiChannel.CS0, 5000000, SpiMode.MODE_0);
adxl362.doSoftReset();
adxl362.beginMeasurement();
while(true) {
System.out.println("X is: " + adxl362.readXData() + ", Y is: " + adxl362.readYData() + ", Z is: " + adxl362.readZData() + ", TEMP is: " + adxl362.readTempData());
Thread.sleep(1000);
}
} catch(IOException | InterruptedException e) {
e.printStackTrace();
}
}
开发者ID:vishal-android-freak,项目名称:ADXL362-Interfacing-Library,代码行数:18,代码来源:Adxl.java
示例7: main
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, IOException {
//
// This SPI example is using the Pi4J SPI interface to communicate with
// the SPI hardware interface connected to a MCP23S17 I/O Expander.
//
// Please note the following command are required to enable the SPI driver on
// your Raspberry Pi:
// > sudo modprobe spi_bcm2708
// > sudo chown `id -u`.`id -g` /dev/spidev0.*
//
// this source code was adapted from:
// https://github.com/thomasmacpherson/piface/blob/master/python/piface/pfio.py
//
// see this blog post for additional details on SPI and WiringPi
// http://wiringpi.com/reference/spi-library/
//
// see the link below for the data sheet on the MCP23S17 chip:
// http://ww1.microchip.com/downloads/en/devicedoc/21952b.pdf
System.out.println("<--Pi4J--> SPI test program using MCP3002 AtoD Chip");
// create SPI object instance for SPI for communication
spi = SpiFactory.getInstance(SpiChannel.CS0,
SpiDevice.DEFAULT_SPI_SPEED, // default spi speed 1 MHz
SpiDevice.DEFAULT_SPI_MODE); // default spi mode 0
// infinite loop
while(true) {
read();
Thread.sleep(1000);
}
}
开发者ID:iot-labs,项目名称:communication,代码行数:34,代码来源:SpiExample.java
示例8: MCP2515
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
public MCP2515(NetworkManager manager, SPIChannel channel, SPIMode mode, int speed) throws IOException {
SpiChannel c = null;
SpiMode m = null;
this.manager = manager;
switch(channel) {
case CE0:
c = SpiChannel.CS0;
break;
case CE1:
c = SpiChannel.CS1;
break;
}
switch(mode) {
case MODE0:
m = SpiMode.MODE_0;
break;
case MODE1:
m = SpiMode.MODE_1;
break;
case MODE2:
m = SpiMode.MODE_2;
break;
case MODE3:
m = SpiMode.MODE_3;
break;
}
driver = SpiFactory.getInstance(c, speed, m);
}
开发者ID:pglotfel,项目名称:ithinkican,代码行数:34,代码来源:MCP2515.java
示例9: MCP3008Adc
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
@Inject
public MCP3008Adc(Gpio gpio, SpiChannel spiChannel, Pin inputPin, Reading.Type readingType, String units) {
LOG.info("Initializing analog sensor through MCP3008 at spiChannel '" + spiChannel + "', input pin '" + inputPin + "', readingType '"
+ readingType + "', units '" + units + "'");
this.readingType = readingType;
this.units = units;
try {
this.input = gpio.provisionAnalogInputPin(new MCP3008GpioProvider(spiChannel), inputPin);
this.initiated = true;
LOG.info("Initializing of analog sensor through MCP3008 finished OK.");
} catch (Exception e) {
LOG.error("Unable to initialize analog sensor reader through MCP3008.", e);
this.initiated = false;
}
}
开发者ID:PoJD,项目名称:hawa,代码行数:16,代码来源:MCP3008Adc.java
示例10: setup
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
@Override
public void setup(MotionSensorLightDetails details) {
LightCapable lightCapable = details.getLightCapable();
LOG.info("Hooking up lights for " + lightCapable.getName() + " ...");
lightCapable.setLightControl(new GpioControl(gpio, details.getControlProvider(), lightCapable.getName() + " light control", details
.getLightControlPin()));
lightCapable.setLightSwitch(new GpioSwitch(gpio, details.getSwitchProvider(), lightCapable.getName() + " light switch", details
.getLightSwitchPin()));
lightCapable.getLightSwitch().addObserver(new ControlObserver(lightCapable.getLightControl()));
// #15 this makes sure that after the primary observer does it work (e.g. light switch fired and control changed), the respective details are
// updated too
// the same logic then below in motion sensor
Observer<Controllable, Boolean> lightCapableUpdatingObserver = new LightCapableUpdatingObserver(lightCapable);
lightCapable.getLightSwitch().addObserver(lightCapableUpdatingObserver);
if (details.getMotionSensorPin() != null && details.getLightLevelSensorPin() != null) {
// skip the units since we do not know them :)
lightCapable.setLightLevelSensor(new MCP3008Adc(gpio, SpiChannel.CS0, details.getLightLevelSensorPin(), Reading.Type.light, ""));
// motion sensor depends on light switch - so that the motion sensor does nothing if light switch is enabled and switched on
// it also depends on light level sensor - if the sensor reads too high (too bright), then the motion sensor does nothing too
lightCapable.setMotionSensor(new GpioObservableSensor(
gpio, details.getSwitchProvider(), lightCapable.getName() + " motion sensor", details.getMotionSensorPin()));
lightCapable.getMotionSensor().addObserver(
new SpecificationsDependentObserver(
lightCapable.getLightControl(),
new SensorDisabledOrOffSpecification(lightCapable.getLightSwitch()),
new LightLevelBelowTresholdOrControlOnSpecification(lightCapable, details.getLightLevelTreshold(), lightCapable
.getLightControl())));
lightCapable.getMotionSensor().addObserver(lightCapableUpdatingObserver);
}
LOG.info("Done");
}
开发者ID:PoJD,项目名称:hawa,代码行数:38,代码来源:DefaultMotionSensorLightTrigger.java
示例11: main
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
System.out.println("<--Pi4J--> MCP3008 ADC Example (NON-MONITORED) ... started.");
// Create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// Create custom MCP3008 analog gpio provider
// we must specify which chip select (CS) that that ADC chip is physically connected to.
final AdcGpioProvider provider = new MCP3008GpioProvider(SpiChannel.CS0,
SpiDevice.DEFAULT_SPI_SPEED,
SpiDevice.DEFAULT_SPI_MODE,
false); // <<-- the 'false' value here disable the base background monitoring thread
// So why would I want to disable the background monitoring thread?
// Well, that depends on how you plan on integrating this into your project.
// If you need/want pin event notification, then you must keep the background
// monitoring thread enabled. If you only need to periodically obtain analog
// input conversion values or only need to acquire the value as the result of
// some other event or condition in your application, then you can disable the
// background monitoring thread to reduce the runtime overhead.
// If its disabled, then anytime you request the pin.getValue() to get an analog
// conversion value it will get the value directly from the ADC chip synchronously
// in your process call. If background monitoring is enabled, then calls to
// pin.getValue() return you the last acquired (cached) value and does not
// perform an immediate data acquisition.
// Provision gpio analog input pins for all channels of the MCP3008.
// (you don't have to define them all if you only use a subset in your project)
final GpioPinAnalogInput inputs[] = {
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH0, "MyAnalogInput-CH0"),
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH1, "MyAnalogInput-CH1"),
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH2, "MyAnalogInput-CH2"),
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH3, "MyAnalogInput-CH3"),
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH4, "MyAnalogInput-CH4"),
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH5, "MyAnalogInput-CH5"),
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH6, "MyAnalogInput-CH6"),
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH7, "MyAnalogInput-CH7")
};
// 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){
sb.append(" \t[" + input.getValue() + "] ");
}
// Print out all analog input conversion values
System.out.println("<MCP3008 VALUES> " + sb.toString());
Thread.sleep(1000);
}
// When your program is finished, make sure to stop all GPIO activity/threads by shutting
// down the GPIO controller (this method will forcefully shutdown all GPIO monitoring threads
// and background scheduled tasks)
gpio.shutdown();
System.out.println("Exiting MCP3008GpioExampleNonMonitored");
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:63,代码来源:MCP3008GpioExampleNonMonitored.java
示例12: main
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
System.out.println("<--Pi4J--> MCP3008 ADC Example ... started.");
// Create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// Create custom MCP3008 analog gpio provider
// we must specify which chip select (CS) that that ADC chip is physically connected to.
final AdcGpioProvider provider = new MCP3008GpioProvider(SpiChannel.CS0);
// Provision gpio analog input pins for all channels of the MCP3008.
// (you don't have to define them all if you only use a subset in your project)
final GpioPinAnalogInput inputs[] = {
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH0, "MyAnalogInput-CH0"),
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH1, "MyAnalogInput-CH1"),
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH2, "MyAnalogInput-CH2"),
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH3, "MyAnalogInput-CH3"),
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH4, "MyAnalogInput-CH4"),
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH5, "MyAnalogInput-CH5"),
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH6, "MyAnalogInput-CH6"),
gpio.provisionAnalogInputPin(provider, MCP3008Pin.CH7, "MyAnalogInput-CH7")
};
// 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(100, inputs); // all inputs; alternatively you can set thresholds on each input discretely
// Set the background monitoring interval timer for the underlying framework to
// interrogate the ADC chip for input conversion values. The acceptable monitoring
// interval will be highly dependant on your specific project. The lower this value
// is set, the more CPU time will be spend collecting analog input conversion values
// on a regular basis. The higher this value the slower your application will get
// analog input value change events/notifications. Try to find a reasonable balance
// for your project needs.
provider.setMonitorInterval(250); // milliseconds
// Print current analog input conversion values from each input channel
for(GpioPinAnalogInput input : inputs){
System.out.println("<INITIAL VALUE> [" + input.getName() + "] : RAW VALUE = " + input.getValue());
}
// Create an analog pin value change listener
GpioPinListenerAnalog listener = new GpioPinListenerAnalog()
{
@Override
public void handleGpioPinAnalogValueChangeEvent(GpioPinAnalogValueChangeEvent event)
{
// get RAW value
double value = event.getValue();
// display output
System.out.println("<CHANGED VALUE> [" + event.getPin().getName() + "] : RAW VALUE = " + value);
}
};
// Register the gpio analog input listener for all input pins
gpio.addListener(listener, inputs);
// Keep this sample program running for 10 minutes
for (int count = 0; count < 600; count++) {
Thread.sleep(1000);
}
// When your program is finished, make sure to stop all GPIO activity/threads by shutting
// down the GPIO controller (this method will forcefully shutdown all GPIO monitoring threads
// and background scheduled tasks)
gpio.shutdown();
System.out.println("Exiting MCP3008GpioExample");
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:75,代码来源:MCP3008GpioExample.java
示例13: main
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
System.out.println("<--Pi4J--> MCP3204 ADC Example ... started.");
// Create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// Create custom MCP3204 analog gpio provider
// we must specify which chip select (CS) that that ADC chip is physically connected to.
final AdcGpioProvider provider = new MCP3204GpioProvider(SpiChannel.CS0);
// Provision gpio analog input pins for all channels of the MCP3204.
// (you don't have to define them all if you only use a subset in your project)
final GpioPinAnalogInput inputs[] = {
gpio.provisionAnalogInputPin(provider, MCP3204Pin.CH0, "MyAnalogInput-CH0"),
gpio.provisionAnalogInputPin(provider, MCP3204Pin.CH1, "MyAnalogInput-CH1"),
gpio.provisionAnalogInputPin(provider, MCP3204Pin.CH2, "MyAnalogInput-CH2"),
gpio.provisionAnalogInputPin(provider, MCP3204Pin.CH3, "MyAnalogInput-CH3")
};
// 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(100, inputs); // all inputs; alternatively you can set thresholds on each input discretely
// Set the background monitoring interval timer for the underlying framework to
// interrogate the ADC chip for input conversion values. The acceptable monitoring
// interval will be highly dependant on your specific project. The lower this value
// is set, the more CPU time will be spend collecting analog input conversion values
// on a regular basis. The higher this value the slower your application will get
// analog input value change events/notifications. Try to find a reasonable balance
// for your project needs.
provider.setMonitorInterval(250); // milliseconds
// Print current analog input conversion values from each input channel
for(GpioPinAnalogInput input : inputs){
System.out.println("<INITIAL VALUE> [" + input.getName() + "] : RAW VALUE = " + input.getValue());
}
// Create an analog pin value change listener
GpioPinListenerAnalog listener = new GpioPinListenerAnalog()
{
@Override
public void handleGpioPinAnalogValueChangeEvent(GpioPinAnalogValueChangeEvent event)
{
// get RAW value
double value = event.getValue();
// display output
System.out.println("<CHANGED VALUE> [" + event.getPin().getName() + "] : RAW VALUE = " + value);
}
};
// Register the gpio analog input listener for all input pins
gpio.addListener(listener, inputs);
// Keep this sample program running for 10 minutes
for (int count = 0; count < 600; count++) {
Thread.sleep(1000);
}
// When your program is finished, make sure to stop all GPIO activity/threads by shutting
// down the GPIO controller (this method will forcefully shutdown all GPIO monitoring threads
// and background scheduled tasks)
gpio.shutdown();
System.out.println("Exiting MCP3204GpioExample");
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:71,代码来源:MCP3204GpioExample.java
示例14: main
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
System.out.println("<--Pi4J--> MCP3204 ADC Example (NON-MONITORED) ... started.");
// Create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// Create custom MCP3204 analog gpio provider
// we must specify which chip select (CS) that that ADC chip is physically connected to.
final AdcGpioProvider provider = new MCP3204GpioProvider(SpiChannel.CS0,
SpiDevice.DEFAULT_SPI_SPEED,
SpiDevice.DEFAULT_SPI_MODE,
false); // <<-- the 'false' value here disable the base background monitoring thread
// So why would I want to disable the background monitoring thread?
// Well, that depends on how you plan on integrating this into your project.
// If you need/want pin event notification, then you must keep the background
// monitoring thread enabled. If you only need to periodically obtain analog
// input conversion values or only need to acquire the value as the result of
// some other event or condition in your application, then you can disable the
// background monitoring thread to reduce the runtime overhead.
// If its disabled, then anytime you request the pin.getValue() to get an analog
// conversion value it will get the value directly from the ADC chip synchronously
// in your process call. If background monitoring is enabled, then calls to
// pin.getValue() return you the last acquired (cached) value and does not
// perform an immediate data acquisition.
// Provision gpio analog input pins for all channels of the MCP3204.
// (you don't have to define them all if you only use a subset in your project)
final GpioPinAnalogInput inputs[] = {
gpio.provisionAnalogInputPin(provider, MCP3204Pin.CH0, "MyAnalogInput-CH0"),
gpio.provisionAnalogInputPin(provider, MCP3204Pin.CH1, "MyAnalogInput-CH1"),
gpio.provisionAnalogInputPin(provider, MCP3204Pin.CH2, "MyAnalogInput-CH2"),
gpio.provisionAnalogInputPin(provider, MCP3204Pin.CH3, "MyAnalogInput-CH3")
};
// 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){
sb.append(" \t[" + input.getValue() + "] ");
}
// Print out all analog input conversion values
System.out.println("<MCP3204 VALUES> " + sb.toString());
Thread.sleep(1000);
}
// When your program is finished, make sure to stop all GPIO activity/threads by shutting
// down the GPIO controller (this method will forcefully shutdown all GPIO monitoring threads
// and background scheduled tasks)
gpio.shutdown();
System.out.println("Exiting MCP3204GpioExampleNonMonitored");
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:59,代码来源:MCP3204GpioExampleNonMonitored.java
示例15: main
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
System.out.println("<--Pi4J--> MCP3004 ADC Example ... started.");
// Create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// Create custom MCP3004 analog gpio provider
// we must specify which chip select (CS) that that ADC chip is physically connected to.
final AdcGpioProvider provider = new MCP3004GpioProvider(SpiChannel.CS0);
// Provision gpio analog input pins for all channels of the MCP3004.
// (you don't have to define them all if you only use a subset in your project)
final GpioPinAnalogInput inputs[] = {
gpio.provisionAnalogInputPin(provider, MCP3004Pin.CH0, "MyAnalogInput-CH0"),
gpio.provisionAnalogInputPin(provider, MCP3004Pin.CH1, "MyAnalogInput-CH1"),
gpio.provisionAnalogInputPin(provider, MCP3004Pin.CH2, "MyAnalogInput-CH2"),
gpio.provisionAnalogInputPin(provider, MCP3004Pin.CH3, "MyAnalogInput-CH3")
};
// 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(100, inputs); // all inputs; alternatively you can set thresholds on each input discretely
// Set the background monitoring interval timer for the underlying framework to
// interrogate the ADC chip for input conversion values. The acceptable monitoring
// interval will be highly dependant on your specific project. The lower this value
// is set, the more CPU time will be spend collecting analog input conversion values
// on a regular basis. The higher this value the slower your application will get
// analog input value change events/notifications. Try to find a reasonable balance
// for your project needs.
provider.setMonitorInterval(250); // milliseconds
// Print current analog input conversion values from each input channel
for(GpioPinAnalogInput input : inputs){
System.out.println("<INITIAL VALUE> [" + input.getName() + "] : RAW VALUE = " + input.getValue());
}
// Create an analog pin value change listener
GpioPinListenerAnalog listener = new GpioPinListenerAnalog()
{
@Override
public void handleGpioPinAnalogValueChangeEvent(GpioPinAnalogValueChangeEvent event)
{
// get RAW value
double value = event.getValue();
// display output
System.out.println("<CHANGED VALUE> [" + event.getPin().getName() + "] : RAW VALUE = " + value);
}
};
// Register the gpio analog input listener for all input pins
gpio.addListener(listener, inputs);
// Keep this sample program running for 10 minutes
for (int count = 0; count < 600; count++) {
Thread.sleep(1000);
}
// When your program is finished, make sure to stop all GPIO activity/threads by shutting
// down the GPIO controller (this method will forcefully shutdown all GPIO monitoring threads
// and background scheduled tasks)
gpio.shutdown();
System.out.println("Exiting MCP3004GpioExample");
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:71,代码来源:MCP3004GpioExample.java
示例16: main
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, IOException, PlatformAlreadyAssignedException {
// ####################################################################
//
// since we are not using the default Raspberry Pi platform, we should
// explicitly assign the platform as the OrangePi platform.
//
// ####################################################################
PlatformManager.setPlatform(Platform.ORANGEPI);
// print program title/header
console.title("<-- The Pi4J Project -->", "SPI test program using MCP3004/MCP3008 AtoD Chip");
// allow for user to exit program using CTRL-C
console.promptForExit();
// This SPI example is using the Pi4J SPI interface to communicate with
// the SPI hardware interface connected to a MCP3004/MCP3008 AtoD Chip.
//
// Please note the following command are required to enable the SPI driver on
// your BananaPro:
// > sudo modprobe spi-sun7i
//
// see this blog post for additional details on SPI and WiringPi
// http://wiringpi.com/reference/spi-library/
//
// see the link below for the data sheet on the MCP3004/MCP3008 chip:
// http://ww1.microchip.com/downloads/en/DeviceDoc/21294E.pdf
// create SPI object instance for SPI for communication
spi = SpiFactory.getInstance(SpiChannel.CS0,
SpiDevice.DEFAULT_SPI_SPEED, // default spi speed 1 MHz
SpiDevice.DEFAULT_SPI_MODE); // default spi mode 0
// continue running program until user exits using CTRL-C
while(console.isRunning()) {
read();
Thread.sleep(1000);
}
console.emptyLine();
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:43,代码来源:SpiExample.java
示例17: main
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, IOException, PlatformAlreadyAssignedException {
// ####################################################################
//
// !!!!! ATTENTION !!!!! ALL GPIO PINS ON ODROID-XU4 ARE 1.8VDC.
// INCLUDING THE SPI PINS
//
// THIS MEANS THAT YOU MUST USE A LEVEL SHIFTER IF USING WITH A 3.3VDC/5VDC CIRCUIT.
// YOU CAN USE THE OPTIONAL ODROID XU4-SHIFTER SHIELD TO PERFORM THE LEVEL SHIFTING:
// http://www.hardkernel.com/main/products/prdt_info.php?g_code=G143556253995
//
// ####################################################################
// ####################################################################
//
// since we are not using the default Raspberry Pi platform, we should
// explicitly assign the platform as the Odroid platform.
//
// ####################################################################
PlatformManager.setPlatform(Platform.ODROID);
// print program title/header
console.title("<-- The Pi4J Project -->", "SPI test program using MCP3004/MCP3008 AtoD Chip");
// allow for user to exit program using CTRL-C
console.promptForExit();
// This SPI example is using the Pi4J SPI interface to communicate with
// the SPI hardware interface connected to a MCP3004/MCP3008 AtoD Chip.
//
// Please note the following command are required to enable the SPI driver on
// your Odroid C1/C1+:
// > sudo modprobe spicc
// > sudo modprobe spidev
//
// see this blog post for additional details on SPI and WiringPi
// http://wiringpi.com/reference/spi-library/
//
// see the link below for the data sheet on the MCP3004/MCP3008 chip:
// http://ww1.microchip.com/downloads/en/DeviceDoc/21294E.pdf
// create SPI object instance for SPI for communication
spi = SpiFactory.getInstance(SpiChannel.CS0,
SpiDevice.DEFAULT_SPI_SPEED, // default spi speed 1 MHz
SpiDevice.DEFAULT_SPI_MODE); // default spi mode 0
// !! ATTENTION !! The Odroid implementation of WiringPi does not currently support
// SPI modes other than 0 (zero).
// continue running program until user exits using CTRL-C
while(console.isRunning()) {
read();
Thread.sleep(1000);
}
console.emptyLine();
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:56,代码来源:SpiExample.java
示例18: main
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, IOException, PlatformAlreadyAssignedException {
// ####################################################################
//
// since we are not using the default Raspberry Pi platform, we should
// explicitly assign the platform as the Odroid platform.
//
// ####################################################################
PlatformManager.setPlatform(Platform.ODROID);
// print program title/header
console.title("<-- The Pi4J Project -->", "SPI test program using MCP3004/MCP3008 AtoD Chip");
// allow for user to exit program using CTRL-C
console.promptForExit();
// This SPI example is using the Pi4J SPI interface to communicate with
// the SPI hardware interface connected to a MCP3004/MCP3008 AtoD Chip.
//
// Please note the following command are required to enable the SPI driver on
// your Odroid C1/C1+:
// > sudo modprobe spicc
// > sudo modprobe spidev
//
// see this blog post for additional details on SPI and WiringPi
// http://wiringpi.com/reference/spi-library/
//
// see the link below for the data sheet on the MCP3004/MCP3008 chip:
// http://ww1.microchip.com/downloads/en/DeviceDoc/21294E.pdf
// create SPI object instance for SPI for communication
spi = SpiFactory.getInstance(SpiChannel.CS0,
SpiDevice.DEFAULT_SPI_SPEED, // default spi speed 1 MHz
SpiDevice.DEFAULT_SPI_MODE); // default spi mode 0
// !! ATTENTION !! The Odroid implementation of WiringPi does not currently support
// SPI modes other than 0 (zero).
// continue running program until user exits using CTRL-C
while(console.isRunning()) {
read();
Thread.sleep(1000);
}
console.emptyLine();
}
开发者ID:uwigem,项目名称:uwigem2017,代码行数:45,代码来源:SpiExample.java
示例19: main
import com.pi4j.io.spi.SpiChannel; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
System.out.println("<--Pi4J--> MCP3004 ADC Example (NON-MONITORED) ... started.");
// Create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// Create custom MCP3004 analog gpio provider
// we must specify which chip select (CS) that that ADC chip is physically connected to.
final AdcGpioProvider provider = new MCP3004GpioProvider(SpiChannel.CS0,
SpiDevice.DEFAULT_SPI_SPEED,
SpiDevice.DEFAULT_SPI_MODE,
false); // <<-- the 'false' value here disable the base background monitoring thread
// So why would I want to disable the background monitoring thread?
// Well, that depends on how you plan on integrating this into your project.
// If you need/want pin event notification, then you must keep the background
// monitoring thread enabled. If you only need to periodically obtain analog
// input conversion values or only need to acquire the value as the result of
// some other event or condition in your application, then you can disable the
// background monitoring thread to reduce the runtime overhead.
// If its disabled, then anytime you request the pin.getValue() to get an analog
// conversion value it will get the value directly from the ADC chip synchronously
// in your process call. If background monitoring is enabled, then calls to
// pin.getValue() return you the last acquired (cached) value and does not
// perform an immediate data acquisition.
// Provision gpio analog input pins for all channels of the MCP3004.
// (you don't have to define them all if you only use a subset in your project)
final GpioPinAnalogInput inputs[] = {
gpio.provisionAnalogInputPin(provider, MCP3004Pin.CH0, "MyAnalogInput-CH0"),
gpio.provisionAnalogInputPin(provider, MCP3004Pin.CH1, "MyAnalogInput-CH1"),
gpio.provisionAnalogInputPin(provider, MCP3004Pin.CH2, "MyAnalogInput-CH2"),
gpio.provisionAnalogInputPin(provider, MCP3004Pin.CH3, "MyAnalogInput-CH3")
};
// 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){
sb.append(" \t[" + input.getValue() + "] ");
}
// Print out all analog input conversion values
System.out.println("<MCP3004 VALUES> " + sb.toString());
Thread.sleep(1000);
}
// When your program is finished, make sure to stop all GPIO activity/threads by shutting
// down the GPIO controller (this method will forcefully shutdown all GPIO monitoring threads
// and background scheduled tasks)
gpio.shutdown();
System
|
请发表评论