public class Spi extends Object
WiringPi includes a software-driven PWM handler capable of outputting a PWM signal on any of the Raspberry Pi's GPIO pins.
There are some limitations. To maintain a low CPU usage, the minimum pulse width is 100uS. That combined with the default suggested range of 100 gives a PWM frequency of 100Hz. You can lower the range to get a higher frequency, at the expense of resolution, or increase to get more resolution, but that will lower the frequency. If you change the pulse-width in the drive code, then be aware that at delays of less than 100uS wiringPi does it in a software loop, which means that CPU usage will rise dramatically, and controlling more than one pin will be almost impossible.
Also note that while the routines run themselves at a higher and real-time priority, Linux can still affect the accuracy of the generated signal.
However, within these limitations, control of a light/LED or a motor is very achievable.
You must initialize wiringPi with one of wiringPiSetup() or wiringPiSetupGpio() functions beforehand. wiringPiSetupSys() is not fast enough, so you must run your programs with sudo.
Before using the Pi4J library, you need to ensure that the Java VM in configured with access to the following system libraries:
This library depends on the wiringPi native system library. (developed by Gordon Henderson @ https://projects.drogon.net/)
Modifier and Type | Field and Description |
---|---|
static int |
CHANNEL_0 |
static int |
CHANNEL_1 |
Modifier and Type | Method and Description |
---|---|
static int |
wiringPiSPIDataRW(int channel,
byte[] data,
int len)
wiringPiSPIDataRW:
|
static int |
wiringPiSPIDataRW(int channel,
String data,
int len)
wiringPiSPIDataRW:
|
static int |
wiringPiSPIGetFd(int channel)
wiringPiSPIGetFd:
|
static int |
wiringPiSPISetup(int channel,
int speed)
wiringPiSPISetup:
|
public static int wiringPiSPIGetFd(int channel)
wiringPiSPIGetFd:
Return the file-descriptor for the given channel
channel
- SPI channelpublic static int wiringPiSPIDataRW(int channel, String data, int len)
wiringPiSPIDataRW:
Write and Read a block of data over the SPI bus. Note the data is being read into the transmit buffer, so will overwrite it! This is also a full-duplex operation.
(ATTENTION: the 'data' argument can only be a maximum of 1024 characters.)
channel
- SPI channeldata
- len
- public static int wiringPiSPIDataRW(int channel, byte[] data, int len)
wiringPiSPIDataRW:
Write and Read a block of data over the SPI bus. Note the data is being read into the transmit buffer, so will overwrite it! This is also a full-duplex operation.
(ATTENTION: the 'data' argument can only be a maximum of 1024 characters.)
channel
- SPI channeldata
- len
- public static int wiringPiSPISetup(int channel, int speed)
wiringPiSPISetup:
Open the SPI device, and set it up, etc.
channel
- SPI channelspeed
- SPI speedCopyright © 2012-2019 Pi4J. All Rights Reserved.