Package jpigpio
Class PigpioSocket
java.lang.Object
jpigpio.impl.CommonPigpio
jpigpio.PigpioSocket
- All Implemented Interfaces:
JPigpio
public class PigpioSocket extends CommonPigpio
An implementation of the Pigpio Java interface using sockets to connect to the target pigpio demon
socket interface (see http://abyz.co.uk/rpi/pigpio/sif.html)
See
See
JPigpio interface for full documentation-
Field Summary
Fields Modifier and Type Field Description intPIGPIOD_MESSAGE_SIZEFields inherited from interface jpigpio.JPigpio
PI_ALT0, PI_ALT1, PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5, PI_CLEAR, PI_DEFAULT_DUTYCYCLE_RANGE, PI_EITHER_EDGE, PI_FALLING_EDGE, PI_GPIO10, PI_GPIO11, PI_GPIO12, PI_GPIO13, PI_GPIO14, PI_GPIO15, PI_GPIO16, PI_GPIO17, PI_GPIO18, PI_GPIO19, PI_GPIO2, PI_GPIO20, PI_GPIO21, PI_GPIO22, PI_GPIO23, PI_GPIO24, PI_GPIO25, PI_GPIO26, PI_GPIO27, PI_GPIO3, PI_GPIO4, PI_GPIO5, PI_GPIO6, PI_GPIO7, PI_GPIO8, PI_GPIO9, PI_HIGH, PI_HW_CLK_MAX_FREQ, PI_HW_CLK_MIN_FREQ, PI_HW_PWM_MAX_FREQ, PI_HW_PWM_MIN_FREQ, PI_HW_PWM_RANGE, PI_I2C1_SCL, PI_I2C1_SDA, PI_INPUT, PI_LOW, PI_LSBFIRST, PI_MAX_DUTYCYCLE_RANGE, PI_MAX_SERVO_PULSEWIDTH, PI_MICROSECONDS, PI_MILLISECONDS, PI_MIN_DUTYCYCLE_RANGE, PI_MIN_SERVO_PULSEWIDTH, PI_MSBFIRST, PI_NO_TX_WAVE, PI_NTFY_FLAGS_ALIVE, PI_NTFY_FLAGS_GPIO, PI_NTFY_FLAGS_WDOG, PI_OFF, PI_ON, PI_OUTPUT, PI_PUD_DOWN, PI_PUD_OFF, PI_PUD_UP, PI_RISING_EDGE, PI_SCRIPT_FAILED, PI_SCRIPT_HALTED, PI_SCRIPT_INITING, PI_SCRIPT_RUNNING, PI_SCRIPT_WAITING, PI_SECONDS, PI_SERVO_OFF, PI_SET, PI_SPI_BAUD_125KHZ, PI_SPI_BAUD_1MHZ, PI_SPI_BAUD_250KHZ, PI_SPI_BAUD_2MHZ, PI_SPI_BAUD_4MHZ, PI_SPI_BAUD_500KHZ, PI_SPI_BAUD_8MHZ, PI_SPI_CE0, PI_SPI_CE1, PI_SPI_CHANNEL0, PI_SPI_CHANNEL1, PI_SPI_MISO, PI_SPI_MODE0, PI_SPI_MODE1, PI_SPI_MODE2, PI_SPI_MODE3, PI_SPI_MOSI, PI_SPI_SCLK, PI_TIMEOUT, PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_ONE_SHOT_SYNC, PI_WAVE_MODE_REPEAT, PI_WAVE_MODE_REPEAT_SYNC, PI_WAVE_NOT_FOUND -
Constructor Summary
Constructors Constructor Description PigpioSocket(java.lang.String host, int port)The constructor of the class. -
Method Summary
Modifier and Type Method Description voidaddCallback(GPIOListener gpioListener)Calls a user supplied function (a callback) whenever the specified GPIO edge is detected.
The user supplied callback receives three parameters, the GPIO, the level, and the tick.
If a user callback is not specified a default tally callback is provided which simply counts edges.longgetCurrentTick()intgetPWMDutycycle(int gpio)Returns the PWM dutycycle being used on the GPIO.
For normal PWM the dutycycle will be out of the defined range for the GPIO (see [*getPWMRange*]).
If a hardware clock is active on the GPIO the reported dutycycle will be 500000 (500k) out of 1000000 (1M).
If hardware PWM is active on the GPIO the reported dutycycle will be out of a 1000000 (1M).intgetPWMFrequency(int gpio)Returns the frequency of PWM being used on the GPIO.
Returns the frequency (in Hz) used for the GPIO.
For normal PWM the frequency will be that defined for the GPIO by [*setPWMFrequency*].
If a hardware clock is active on the GPIO the reported frequency will be that set by [*hardwareClock*].
If hardware PWM is active on the GPIO the reported frequency will be that set by [*hardwarePWM*].intgetPWMRange(int gpio)Returns the range of PWM values being used on the GPIO.
If a hardware clock or hardware PWM is active on the GPIO the reported range will be 1000000 (1M).intgetPWMRealRange(int gpio)Returns the real (underlying) range of PWM values being used on the GPIO.intgetServoPulseWidth(int gpio)Not implementedvoidgpioDelay(long delay)Delay for the specified number of microsecondsintgpioGetMode(int pin)Retrieve the mode of the given gpiovoidgpioInitialize()booleangpioRead(int pin)Retrieve the state of the gpiovoidgpioServo(int gpio, int pulseWidth)Starts (500-2500) or stops (0) servo pulses on the GPIO.
The selected pulsewidth will continue to be transmitted until changed by a subsequent call to set_servo_pulsewidth.
The pulsewidths supported by servos varies and should probably be determined by experiment.voidgpioSetAlertFunc(int pin, Alert gpioAlert)voidgpioSetMode(int pin, int mode)Set the mode of the gpiovoidgpioSetPullUpDown(int pin, int pud)voidgpioTerminate()Terminate the usage of the pigpio interfaces.longgpioTick()voidgpioTrigger(int gpio, long pulseLen, boolean level)Set the specified gpio to the level specified by level for the duration (in micro-sec) specified by pulseLen and then set the gpio back to not-level.voidgpioWrite(int pin, boolean value)Set the state of the gpiolonggpioxPulseAndWait(int outGpio, int inGpio, long waitDuration, long pulseHoldDuration, boolean pulseLow)Not implementedvoidi2cClose(int handle)Closes the I2C device associated with handle.inti2cOpen(int i2cBus, int i2cAddr)Returns a handle (>=0) for the device at the I2C bus address.
i2c_flags:= 0, no flags are currently defined.
Normally you would only use the [*i2c_**] functions if you are or will be connecting to the Pi over a network.inti2cReadDevice(int handle, byte[] data)Returns count bytes read from the raw device associated with handle.voidi2cWriteDevice(int handle, byte[] data)Writes the data bytes to the raw device associated with handle.voidnotifyBegin(int handle, int bits)Starts notifications on a handle.
The notification sends state changes for each GPIO whose corresponding bit in bits is set.voidnotifyClose(int handle)Stops notifications on a handle and releases the handle for reuse.intnotifyOpen()Returns a notification handle (>=0).
A notification is a method for being notified of GPIO state changes via a pipe.
Pipes are only accessible from the local machine so this function serves no purpose if you are using Python from a remote machine.voidnotifyPause(int handle)Pauses notifications on a handle.
Notifications for the handle are suspended until [*notify_begin*] is called again.
voidreconnect()Try reconnecting to pigpio.voidremoveCallback(GPIOListener gpioListener)Remove callback listener object from notification thread.voidserialClose(int handle)Closes the serial device associated with handle.intserialDataAvailable(int handle)Returns the number of bytes available to be read from the device associated with handle.intserialOpen(java.lang.String tty, int baudRate, int flags)Returns a handle for the serial tty device opened at baud bits per second.
Normally you would only use the [*serial_**] functions if you are or will be connecting to the Pi over a network.byte[]serialRead(int handle, int count)Reads up to count bytes from the device associated with handle.
The returned value is a tuple of the number of bytes read and a bytearray containing the bytes.byteserialReadByte(int handle)Returns a single byte from the device associated with handle.voidserialWrite(int handle, byte[] data)Writes the data bytes to the device associated with handle.voidserialWriteByte(int handle, byte data)Writes a single byte to the device associated with handle.voidsetDebug(boolean flag)Not implementedvoidsetPWMDutycycle(int gpio, int dutycycle)Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO.intsetPWMFrequency(int gpio, int frequency)Sets the frequency (in Hz) of the PWM to be used on the GPIO.
Returns the frequency actually set.voidsetPWMRange(int gpio, int range)Sets the range of PWM values to be used on the GPIO.voidsetServoPulseWidth(int gpio, int pulseWidth)voidsetWatchdog(int userGpio, int timeout)Sets a watchdog timeout for a GPIO.
The watchdog is nominally in milliseconds.
Only one watchdog may be registered per GPIO.
The watchdog may be cancelled by setting timeout to 0.
If no level change has been detected for the GPIO for timeout milliseconds any notification for the GPIO has a report written to the fifo with the flags set to indicate a watchdog timeout.
The callback class interprets the flags and will call registered notificationListeners for the GPIO with level TIMEOUT.
voidspiClose(int handle)Closes the SPI device associated with handle.intspiOpen(int spiChannel, int spiBaudRate, int flags)Returns a handle for the SPI device on channel.intspiRead(int handle, byte[] data)Reads count bytes from the SPI device associated with handle.
The returned value is a tuple of the number of bytes read and a bytearray containing the bytes.intspiWrite(int handle, byte[] data)Writes the data bytes to the SPI device associated with handle.intspiXfer(int handle, byte[] txData, byte[] rxData)Writes the data bytes to the SPI device associated with handle, returning the data bytes read from the device.
The returned value is a tuple of the number of bytes read and a bytearray containing the bytes.intwaveAddGeneric(java.util.ArrayList<Pulse> pulses)Adds a list of pulses to the current waveform.
Returns the new total number of pulses in the current waveform.
The pulses are interleaved in time order within the existing waveform (if any).
Merging allows the waveform to be built in parts, that is the settings for GPIO#1 can be added, and then GPIO#2 etc.
If the added waveform is intended to start after or within the existing waveform then the first pulse should consist solely of a delay.voidwaveAddNew()Starts a new empty waveform.
You would not normally need to call this function as it is automatically called after a waveform is created with the [*wave_create*] function.intwaveAddSerial(int userGpio, int baud, byte[] data, int offset, int bbBits, int bbStop)Adds a waveform representing serial data to the existing waveform (if any).voidwaveClear()This function clears all waveforms and any data added by calls to the wave_add_* functions.intwaveCreate()Creates a waveform from the data provided by the prior calls to the [*wave_add_**] functions.
Returns a wave id (>=0) if OK, otherwise PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID.
The data provided by the [*wave_add_**] functions is consumed by this function.
As many waveforms may be created as there is space available.voidwaveDelete(int waveId)This function deletes the waveform with id wave_id.
Wave ids are allocated in order, 0, 1, 2, etc.intwaveSendOnce(int waveId)Transmits the waveform with id wave_id.intwaveSendRepeat(int waveId)Transmits the waveform with id wave_id.booleanwaveTxBusy()Returns 1 if a waveform is currently being transmitted, otherwise 0.intwaveTxStop()Stops the transmission of the current waveform.
This function is intended to stop a waveform started with wave_send_repeat.Methods inherited from class jpigpio.impl.CommonPigpio
gpioDelay, gpioShiftOut, gpioShiftOut, gpioShiftOut, gpioShiftOut
-
Field Details
-
PIGPIOD_MESSAGE_SIZE
public final int PIGPIOD_MESSAGE_SIZE- See Also:
- Constant Field Values
-
-
Constructor Details
-
PigpioSocket
The constructor of the class.- Parameters:
host- The host name or ip address of the pigpio daemon.port- The port of the pigpio daemon.- Throws:
PigpioException- if not able to initialize/connect to pigpiod
-
-
Method Details
-
gpioInitialize
- Throws:
PigpioException
-
reconnect
Description copied from interface:JPigpioTry reconnecting to pigpio. This does make sense in case of socket pigpiod interface- Throws:
PigpioException
-
gpioTerminate
Description copied from interface:JPigpioTerminate the usage of the pigpio interfaces.- Throws:
PigpioException- on error
-
gpioSetMode
Description copied from interface:JPigpioSet the mode of the gpio- Parameters:
pin- The gpio pin to setmode- The mode of the pin. One of PI_INPUT or PI_OUTPUT- Throws:
PigpioException- on pigpiod error
-
gpioGetMode
Description copied from interface:JPigpioRetrieve the mode of the given gpio- Parameters:
pin- The gpio to retrieve the mode- Returns:
- The mode of the gpio
- Throws:
PigpioException- on pigpiod error
-
gpioSetPullUpDown
- Throws:
PigpioException
-
gpioRead
Description copied from interface:JPigpioRetrieve the state of the gpio- Parameters:
pin- The gpio pin to retrieve- Returns:
- The state of the gpio, one of PI_HIGH or PI_LOW (or equivalents)
- Throws:
PigpioException- on pigpiod error
-
gpioWrite
Description copied from interface:JPigpioSet the state of the gpio- Parameters:
pin- The gpio pin to setvalue- The desired value of the new pin state. One of PI_HIGH or PI_LOW (or equivalents)- Throws:
PigpioException- on pigpiod error
-
notifyOpen
Description copied from interface:JPigpioReturns a notification handle (>=0).
A notification is a method for being notified of GPIO state changes via a pipe.
Pipes are only accessible from the local machine so this function serves no purpose if you are using Python from a remote machine. The in-built (socket) notifications provided by [*callback*] should be used instead.
Notifications for handle x will be available at the pipe named /dev/pigpiox (where x is the handle number).
E.g. if the function returns 15 then the notifications must be read from /dev/pigpio15.
Notifications have the following structure.
seqno: starts at 0 each time the handle is opened and then increments by one for each report.. . I seqno I flags I tick I level . .
flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags indicate a GPIO which has had a watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity.
tick: the number of microseconds since system boot. It wraps around after 1h12m.
level: indicates the level of each GPIO. If bit 1<<x is set then GPIO x is high.
... h = pi.notify_open(); if h >= 0:; pi.notify_begin(h, 1234); ...- Returns:
- notification handle
- Throws:
PigpioException- on pigpiod error
-
notifyBegin
Description copied from interface:JPigpioStarts notifications on a handle.
The notification sends state changes for each GPIO whose corresponding bit in bits is set.
The following code starts notifications for GPIO 1, 4, 6, 7, and 10 (1234 = 0x04D2 = 0b0000010011010010).
... h = pi.notify_open() if h >= 0: pi.notify_begin(h, 1234) ...- Parameters:
handle- >=0 (as returned by a prior call to [*notify_open*])bits- a 32 bit mask indicating the GPIO to be notified.- Throws:
PigpioException- on pigpiod error
-
notifyPause
Description copied from interface:JPigpioPauses notifications on a handle.
Notifications for the handle are suspended until [*notify_begin*] is called again.
... h = pi.notify_open() if h >= 0: pi.notify_begin(h, 1234) ... pi.notify_pause(h) ... pi.notify_begin(h, 1234) ...- Parameters:
handle- >=0 (as returned by a prior call to [*notify_open*])- Throws:
PigpioException- on pigpiod error
-
notifyClose
Description copied from interface:JPigpioStops notifications on a handle and releases the handle for reuse.... h = pi.notify_open() if h >= 0: pi.notify_begin(h, 1234) ... pi.notify_close(h) ... ...- Parameters:
handle- >=0 (as returned by a prior call to [*notify_open*])- Throws:
PigpioException- on pigpiod error
-
setWatchdog
Description copied from interface:JPigpioSets a watchdog timeout for a GPIO.
The watchdog is nominally in milliseconds.
Only one watchdog may be registered per GPIO.
The watchdog may be cancelled by setting timeout to 0.
If no level change has been detected for the GPIO for timeout milliseconds any notification for the GPIO has a report written to the fifo with the flags set to indicate a watchdog timeout.
The callback class interprets the flags and will call registered notificationListeners for the GPIO with level TIMEOUT.
... pi.setWatchdog(23, 1000) # 1000 ms watchdog on GPIO 23 pi.setWatchdog(23, 0) # cancel watchdog on GPIO 23 ...- Parameters:
userGpio- 0-31timeout- 0-60000- Throws:
PigpioException- on pigpiod error
-
waveClear
Description copied from interface:JPigpioThis function clears all waveforms and any data added by calls to the wave_add_* functions.- Throws:
PigpioException- on pigpiod error
-
waveAddGeneric
Description copied from interface:JPigpioAdds a list of pulses to the current waveform.
Returns the new total number of pulses in the current waveform.
The pulses are interleaved in time order within the existing waveform (if any).
Merging allows the waveform to be built in parts, that is the settings for GPIO#1 can be added, and then GPIO#2 etc.
If the added waveform is intended to start after or within the existing waveform then the first pulse should consist solely of a delay.
... G1=4 G2=24 pi.set_mode(G1, pigpio.OUTPUT) pi.set_mode(G2, pigpio.OUTPUT) flash_500=[] # flash every 500 ms flash_100=[] # flash every 100 ms # ON OFF DELAY flash_500.addListener(pigpio.pulse(1<<G1, 1<<G2, 500000)) flash_500.addListener(pigpio.pulse(1<<G2, 1<<G1, 500000)) flash_100.addListener(pigpio.pulse(1<<G1, 1<<G2, 100000)) flash_100.addListener(pigpio.pulse(1<<2, 1<<G1, 100000)) pi.wave_clear() # clear any existing waveforms pi.wave_add_generic(flash_500) # 500 ms flashes f500 = pi.wave_create() # create and save id pi.wave_add_generic(flash_100) # 100 ms flashes f100 = pi.wave_create() # create and save id pi.wave_send_repeat(f500) time.sleep(4) pi.wave_send_repeat(f100) time.sleep(4) pi.wave_send_repeat(f500) time.sleep(4) pi.wave_tx_stop() # stop waveform pi.wave_clear() # clear all waveforms ...- Parameters:
pulses- list of pulses to add to the waveform.- Returns:
- Returns the new total number of pulses in the current waveform.
- Throws:
PigpioException- on pigpiod error
-
waveAddSerial
public int waveAddSerial(int userGpio, int baud, byte[] data, int offset, int bbBits, int bbStop) throws PigpioExceptionDescription copied from interface:JPigpioAdds a waveform representing serial data to the existing waveform (if any). The serial data starts [*offset*] microseconds from the start of the waveform.
Returns the new total number of pulses in the current waveform.
The serial data is formatted as one start bit, [*bb_bits*] data bits, and [*bb_stop*]/2 stop bits.
It is legal to add serial data streams with different baud rates to the same waveform.
The bytes required for each character depend upon [*bb_bits*].
For [*bb_bits*] 1-8 there will be one byte per character.
For [*bb_bits*] 9-16 there will be two bytes per character.
For [*bb_bits*] 17-32 there will be four bytes per character.
... pi.wave_add_serial(4, 300, 'Hello world') pi.wave_add_serial(4, 300, b"Hello world") pi.wave_add_serial(4, 300, b'\\x23\\x01\\x00\\x45') pi.wave_add_serial(17, 38400, [23, 128, 234], 5000) ...- Parameters:
userGpio- GPIO to transmit data. You must set the GPIO mode to output.baud- 50-1000000 bits per second.data- the bytes to write.offset- number of microseconds from the start of the waveform, default 0.bbBits- number of data bits, default 8.bbStop- number of stop half bits, default 2.- Returns:
- Returns the new total number of pulses in the current waveform.
- Throws:
PigpioException- on pigpiod error
-
waveAddNew
Description copied from interface:JPigpioStarts a new empty waveform.
You would not normally need to call this function as it is automatically called after a waveform is created with the [*wave_create*] function.
... pi.wave_add_new() ...- Throws:
PigpioException- on pigpiod error
-
waveTxBusy
Description copied from interface:JPigpioReturns 1 if a waveform is currently being transmitted, otherwise 0.
... pi.wave_send_once(0) # send first waveform while pi.wave_tx_busy(): # wait for waveform to be sent time.sleep(0.1) pi.wave_send_once(1) # send next waveform ...- Returns:
- The return code from wave_tx_busy.
- Throws:
PigpioException- on pigpiod error
-
waveTxStop
Description copied from interface:JPigpioStops the transmission of the current waveform.
This function is intended to stop a waveform started with wave_send_repeat.
... pi.wave_send_repeat(3) time.sleep(5) pi.wave_tx_stop() ...- Returns:
- The return code from wave_tx_stop.
- Throws:
PigpioException- on pigpiod error
-
waveCreate
Description copied from interface:JPigpioCreates a waveform from the data provided by the prior calls to the [*wave_add_**] functions.
Returns a wave id (>=0) if OK, otherwise PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID.
The data provided by the [*wave_add_**] functions is consumed by this function.
As many waveforms may be created as there is space available. The wave id is passed to [*wave_send_**] to specify the waveform to transmit.
Normal usage would be- Step 1. [*wave_clear*] to clear all waveforms and added data.
- Step 2. [*wave_add_**] calls to supply the waveform data.
- Step 3. [*wave_create*] to create the waveform and get a unique id
Repeat steps 2 and 3 as needed.
Step 4. [*wave_send_**] with the id of the waveform to transmit.
A waveform comprises one or more pulses.
A pulse specifies
- the GPIO to be switched on at the start of the pulse.
- the GPIO to be switched off at the start of the pulse.
- the delay in microseconds before the next pulse.
When a waveform is started each pulse is executed in order with the specified delay between the pulse and the next.
... wid = pi.wave_create() ...- Returns:
- wave id (>=0) if OK, otherwise PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID.
- Throws:
PigpioException- on pigpiod error
-
waveDelete
Description copied from interface:JPigpioThis function deletes the waveform with id wave_id.
Wave ids are allocated in order, 0, 1, 2, etc.
... pi.wave_delete(6) # delete waveform with id 6 pi.wave_delete(0) # delete waveform with id 0 ...- Parameters:
waveId- >=0 (as returned by a prior call to [*wave_create*]).- Throws:
PigpioException- on pigpiod error
-
waveSendOnce
Description copied from interface:JPigpioTransmits the waveform with id wave_id. The waveform is sent once.
NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled.
Returns the number of DMA control blocks used in the waveform.
... cbs = pi.wave_send_once(wid) ...- Parameters:
waveId- >=0 (as returned by a prior call to [*wave_create*]).- Returns:
- Returns the number of DMA control blocks used in the waveform.
- Throws:
PigpioException- on pigpiod error
-
waveSendRepeat
Description copied from interface:JPigpioTransmits the waveform with id wave_id. The waveform repeats until wave_tx_stop is called or another call to [*wave_send_**] is made.
NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled.
Returns the number of DMA control blocks used in the waveform.
... cbs = pi.wave_send_repeat(wid) ...- Parameters:
waveId- >=0 (as returned by a prior call to [*wave_create*]).- Returns:
- Returns the number of DMA control blocks used in the waveform.
- Throws:
PigpioException- on pigpiod error
-
i2cOpen
Description copied from interface:JPigpioReturns a handle (>=0) for the device at the I2C bus address.
i2c_flags:= 0, no flags are currently defined.
Normally you would only use the [*i2c_**] functions if you are or will be connecting to the Pi over a network. If you will always run on the local Pi use the standard SMBus module instead.
For the SMBus commands the low level transactions are shown at the end of the function description. The following abbreviations are used.
. . S (1 bit) : Start bit P (1 bit) : Stop bit Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. A, NA (1 bit) : Accept and not accept bit. Addr (7 bits): I2C 7 bit address. reg (8 bits): Command byte, which often selects a register. Data (8 bits): A data byte. Count (8 bits): A byte defining the length of a block operation. [..]: Data sent by the device. . . ... h = pi.i2c_open(1, 0x53) # open device at address 0x53 on bus 1 ...- Parameters:
i2cBus- 0-1.i2cAddr- 0x00-0x7F.- Returns:
- Returns a handle (>=0) for the device at the I2C bus address.
- Throws:
PigpioException- on pigpiod error
-
i2cClose
Description copied from interface:JPigpioCloses the I2C device associated with handle.... pi.i2c_close(h) ...- Parameters:
handle- >=0 (as returned by a prior call to [*i2c_open*]).- Throws:
PigpioException- on pigpiod error
-
i2cReadDevice
Description copied from interface:JPigpioReturns count bytes read from the raw device associated with handle.. . S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P . .
The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the number of bytes read will be less than zero (and will contain the error code).... (count, data) = pi.i2c_read_device(h, 12) ...- Parameters:
handle- >=0 (as returned by a prior call to [*i2c_open*]).data- >0, the number of bytes to read.- Returns:
- Returns count bytes read from the raw device associated with handle.
- Throws:
PigpioException- on pigpiod error
-
i2cWriteDevice
Description copied from interface:JPigpioWrites the data bytes to the raw device associated with handle.. . S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P . .
... pi.i2c_write_device(h, b"\\x12\\x34\\xA8") pi.i2c_write_device(h, b"help") pi.i2c_write_device(h, 'help') pi.i2c_write_device(h, [23, 56, 231]) ...- Parameters:
handle- >=0 (as returned by a prior call to [*i2c_open*]).data- the bytes to write.- Throws:
PigpioException- on pigpiod error
-
gpioDelay
Description copied from interface:JPigpioDelay for the specified number of microseconds- Parameters:
delay- The number of microseconds for which to block- Throws:
PigpioException- on pigpiod error
-
gpioTick
- Throws:
PigpioException
-
getCurrentTick
- Throws:
PigpioException
-
gpioServo
Description copied from interface:JPigpioStarts (500-2500) or stops (0) servo pulses on the GPIO.
The selected pulsewidth will continue to be transmitted until changed by a subsequent call to set_servo_pulsewidth.
The pulsewidths supported by servos varies and should probably be determined by experiment. A value of 1500 should always be safe and represents the mid-point of rotation.
You can DAMAGE a servo if you command it to move beyond its limits.
... pi.setServoPulsewidth(17, 0); // off pi.setServoPulsewidth(17, 1000); // safe anti-clockwise pi.setServoPulsewidth(17, 1500); // centre pi.setServoPulsewidth(17, 2000); // safe clockwise ...- Parameters:
gpio- GPIO to control the servo. 0-31pulseWidth- The pulse width of the pulse (500-2500).
0 = off
500 = most anti-clockwise
2500 = most clock-wise- Throws:
PigpioException- on pigpiod error
-
setServoPulseWidth
- Throws:
PigpioException
-
getServoPulseWidth
Not implemented- Parameters:
gpio- user gpio 0-31- Returns:
- Returns the servo pulsewidth.
- Throws:
PigpioException- on pigpiod error
-
gpioSetAlertFunc
- Throws:
PigpioException
-
gpioTrigger
Description copied from interface:JPigpioSet the specified gpio to the level specified by level for the duration (in micro-sec) specified by pulseLen and then set the gpio back to not-level.- Parameters:
gpio- The GPIO pin to pulse.pulseLen- The duration in microseconds to hold the pulse.level- The level to target the pulse.- Throws:
PigpioException- on pigpiod error
-
spiOpen
Description copied from interface:JPigpioReturns a handle for the SPI device on channel. Data will be transferred at baud bits per second. The flags may be used to modify the default behaviour of 4-wire operation, mode 0, active low chip select.
An auxiliary SPI device is available on all models but the A and B and may be selected by setting the A bit in the flags. The auxiliary device has 3 chip selects and a selectable word size in bits.
Normally you would only use the [*spi_**] functions if you are or will be connecting to the Pi over a network. If you will always run on the local Pi use the standard SPI module instead.
spi_flags consists of the least significant 22 bits.
. . 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m . . mm defines the SPI mode. WARNING: modes 1 and 3 do not appear to work on the auxiliary device. . . Mode POL PHA 0 0 0 1 0 1 2 1 0 3 1 1 . .
px is 0 if CEx is active low (default) and 1 for active high.
ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise.
A is 0 for the standard SPI device, 1 for the auxiliary SPI.
W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Standard SPI device only.
nnnn defines the number of bytes (0-15) to write before switching the MOSI line to MISO to read data. This field is ignored if W is not set. Standard SPI device only.
T is 1 if the least significant bit is transmitted on MOSI first, the default (0) shifts the most significant bit out first. Auxiliary SPI device only.
R is 1 if the least significant bit is received on MISO first, the default (0) receives the most significant bit first. Auxiliary SPI device only.
bbbbbb defines the word size in bits (0-32). The default (0) sets 8 bits per word. Auxiliary SPI device only.
The [*spi_read*], [*spi_write*], and [*spi_xfer*] functions transfer data packed into 1, 2, or 4 bytes according to the word size in bits.
For bits 1-8 there will be one byte per character.
For bits 9-16 there will be two bytes per character.
For bits 17-32 there will be four bytes per character.
E.g. 32 12-bit words will be transferred in 64 bytes.
The other bits in flags should be set to zero.
... # open SPI device on channel 1 in mode 3 at 50000 bits per second h = pi.spi_open(1, 50000, 3) ...- Parameters:
spiChannel- The channel to open.
0-1 (0-2 for the auxiliary SPI device).spiBaudRate- The baud rate for transmission and reception. Some constants are provided:- PI_SPI_BAUD_125KHZ
- PI_SPI_BAUD_250KHZ
- PI_SPI_BAUD_500KHZ
- PI_SPI_BAUD_1MHZ
- PI_SPI_BAUD_2MHZ
- PI_SPI_BAUD_4MHZ
- PI_SPI_BAUD_8MHZ
flags- Control flags. The flags can include:- Returns:
- A handle used in subsequent SPI API calls
- Throws:
PigpioException- on pigpiod error
-
spiClose
Description copied from interface:JPigpioCloses the SPI device associated with handle.... pi.spi_close(h) ...- Parameters:
handle- The handle to be closed.
>=0 (as returned by a prior call to [*spi_open*]).- Throws:
PigpioException- on pigpiod error
-
spiRead
Description copied from interface:JPigpioReads count bytes from the SPI device associated with handle.
The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the number of bytes read will be less than zero (and will contain the error code).
... (b, d) = pi.spi_read(h, 60) # read 60 bytes from device h if b == 60: # process read data else: # error path ...- Parameters:
handle- The handle from which to read. >=0 (as returned by a prior call to [*spi_open*]).data- An array into which to read data.- Returns:
- The number of bytes actually read.
- Throws:
PigpioException- on pigpiod error
-
spiWrite
Description copied from interface:JPigpioWrites the data bytes to the SPI device associated with handle.... pi.spi_write(0, b'\\x02\\xc0\\x80') # write 3 bytes to device 0 pi.spi_write(0, b'defgh') # write 5 bytes to device 0 pi.spi_write(0, "def") # write 3 bytes to device 0 pi.spi_write(1, [2, 192, 128]) # write 3 bytes to device 1 ...- Parameters:
handle- The handle into which to write. >=0 (as returned by a prior call to [*spi_open*]).data- An array of data to write to SPI.- Returns:
- The number of bytes actually written
- Throws:
PigpioException- on pigpiod error
-
spiXfer
Description copied from interface:JPigpioWrites the data bytes to the SPI device associated with handle, returning the data bytes read from the device.
The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the number of bytes read will be less than zero (and will contain the error code).
... (count, rx_data) = pi.spi_xfer(h, b'\\x01\\x80\\x00') (count, rx_data) = pi.spi_xfer(h, [1, 128, 0]) (count, rx_data) = pi.spi_xfer(h, b"hello") (count, rx_data) = pi.spi_xfer(h, "hello") ...- Parameters:
handle- The handle into which to write. >=0 (as returned by a prior call to [*spi_open*]).txData- An array of data to write.rxData- An array of data to read.- Returns:
- The number of bytes actually transferred.
- Throws:
PigpioException- on pigpiod error
-
setPWMDutycycle
Description copied from interface:JPigpioStarts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO.
The [*setPWMRange*] function can change the default range of 255.... pi.setPWMDutycycle(4, 0) # PWM off pi.setPWMDutycycle(4, 64) # PWM 1/4 on pi.setPWMDutycycle(4, 128) # PWM 1/2 on pi.setPWMDutycycle(4, 192) # PWM 3/4 on pi.setPWMDutycycle(4, 255) # PWM full on ...- Parameters:
gpio- user gpio 0-31dutycycle- 0-range (range defaults to 255).- Throws:
PigpioException- on pigpiod error
-
getPWMDutycycle
Description copied from interface:JPigpioReturns the PWM dutycycle being used on the GPIO.
For normal PWM the dutycycle will be out of the defined range for the GPIO (see [*getPWMRange*]).
If a hardware clock is active on the GPIO the reported dutycycle will be 500000 (500k) out of 1000000 (1M).
If hardware PWM is active on the GPIO the reported dutycycle will be out of a 1000000 (1M).... pi.setPWMDutycycle(4, 25) print(pi.getPWMDutycycle(4)) 25 pi.setPWMDutycycle(4, 203) print(pi.getPWMDutycycle(4)) 203 ...- Parameters:
gpio- user gpio 0-31- Returns:
- PWM dutycycle
- Throws:
PigpioException- on pigpiod error
-
setPWMRange
Description copied from interface:JPigpioSets the range of PWM values to be used on the GPIO.... pi.set_PWM_range(9, 100) # now 25 1/4, 50 1/2, 75 3/4 on pi.set_PWM_range(9, 500) # now 125 1/4, 250 1/2, 375 3/4 on pi.set_PWM_range(9, 3000) # now 750 1/4, 1500 1/2, 2250 3/4 on ...- Parameters:
gpio- user gpio 0-31range- range 25-40000- Throws:
PigpioException- on pigpiod error
-
getPWMRange
Description copied from interface:JPigpioReturns the range of PWM values being used on the GPIO.
If a hardware clock or hardware PWM is active on the GPIO the reported range will be 1000000 (1M).... pi.set_PWM_range(9, 500) print(pi.get_PWM_range(9)) 500 ...- Parameters:
gpio- user gpio 0-31- Returns:
- range of PWM values
- Throws:
PigpioException- on pigpiod error
-
getPWMRealRange
Description copied from interface:JPigpioReturns the real (underlying) range of PWM values being used on the GPIO.
If a hardware clock is active on the GPIO the reported real range will be 1000000 (1M).
If hardware PWM is active on the GPIO the reported real range will be approximately 250M divided by the set PWM frequency.... pi.setPWMFrequency(4, 800) System.out.println(pi.getPWMRealRange(4)) 250 ...- Parameters:
gpio- user gpio 0-31- Returns:
- the real (underlying) range of PWM values
- Throws:
PigpioException- on pigpiod error
-
setPWMFrequency
Description copied from interface:JPigpioSets the frequency (in Hz) of the PWM to be used on the GPIO.
Returns the frequency actually set.... pi.setPWMFrequency(4,0) print(pi.getPWMFrequency(4)) 10 pi.set_PWMFrequency(4,100000) print(pi.getPWMFrequency(4)) 8000 ...- Parameters:
gpio- user gpio 0-31frequency- >= 0 Hz- Returns:
- Returns the frequency actually set.
- Throws:
PigpioException- on pigpiod error
-
getPWMFrequency
Description copied from interface:JPigpioReturns the frequency of PWM being used on the GPIO.
Returns the frequency (in Hz) used for the GPIO.
For normal PWM the frequency will be that defined for the GPIO by [*setPWMFrequency*].
If a hardware clock is active on the GPIO the reported frequency will be that set by [*hardwareClock*].
If hardware PWM is active on the GPIO the reported frequency will be that set by [*hardwarePWM*].... pi.setPWMFrequency(4,0) print(pi.getPWMFrequency(4)) 10 pi.setPWMFrequency(4, 800) print(pi.getPWMFrequency(4)) 800 ...- Parameters:
gpio- user gpio 0-31- Returns:
- frequency (in Hz) used for the GPIO.
- Throws:
PigpioException- on pigpiod error
-
serialOpen
Description copied from interface:JPigpioReturns a handle for the serial tty device opened at baud bits per second.
Normally you would only use the [*serial_**] functions if you are or will be connecting to the Pi over a network. If you will always run on the local Pi use the standard serial module instead.
The baud rate must be one of 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, or 230400.
... h1 = pi.serial_open("/dev/ttyAMA0", 300) h2 = pi.serial_open("/dev/ttyUSB1", 19200, 0) ...- Parameters:
tty- serial device to openbaudRate- baud rate in bits per second, see below.flags- connection flags. No flags are currently defined.- Returns:
- handle for opened device
- Throws:
PigpioException- on pigpiod error
-
serialClose
Description copied from interface:JPigpioCloses the serial device associated with handle.... pi.serial_close(h1) ...- Parameters:
handle- >=0 (as returned by a prior call to [*serial_open*]).- Throws:
PigpioException- on pigpiod error
-
serialReadByte
Description copied from interface:JPigpioReturns a single byte from the device associated with handle.... b = pi.serial_read_byte(h1) ...- Parameters:
handle- >=0 (as returned by a prior call to [*serial_open*]).- Returns:
- single byte from opened device
- Throws:
PigpioException- on pigpiod error
-
serialWriteByte
Description copied from interface:JPigpioWrites a single byte to the device associated with handle.... pi.serial_write_byte(h1, 23) pi.serial_write_byte(h1, ord('Z')) ...- Parameters:
handle- >=0 (as returned by a prior call to [*serial_open*]).data- 0-255, the value to write.- Throws:
PigpioException- on pigpiod error
-
serialRead
Description copied from interface:JPigpioReads up to count bytes from the device associated with handle.
The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the number of bytes read will be less than zero (and will contain the error code).... (b, d) = pi.serial_read(h2, 100) if b > 0: # process read data ...- Parameters:
handle- >=0 (as returned by a prior call to [*serial_open*]).count- >0, the number of bytes to read.- Returns:
- read bytes
- Throws:
PigpioException- on pigpiod error
-
serialWrite
Description copied from interface:JPigpioWrites the data bytes to the device associated with handle.... pi.serial_write(h1, b'\\x02\\x03\\x04') pi.serial_write(h2, b'help') pi.serial_write(h2, "hello") pi.serial_write(h1, [2, 3, 4]) ...- Parameters:
handle- >=0 (as returned by a prior call to [*serial_open*]).data- the bytes to write.- Throws:
PigpioException- on pigpiod error
-
serialDataAvailable
Description copied from interface:JPigpioReturns the number of bytes available to be read from the device associated with handle.... rdy = pi.serial_data_available(h1) if rdy > 0: (b, d) = pi.serial_read(h1, rdy) ...- Parameters:
handle- >=0 (as returned by a prior call to [*serial_open*]).- Returns:
- number of bytes available to be read
- Throws:
PigpioException- on pigpiod error
-
setDebug
Not implemented- Throws:
PigpioException
-
gpioxPulseAndWait
public long gpioxPulseAndWait(int outGpio, int inGpio, long waitDuration, long pulseHoldDuration, boolean pulseLow) throws PigpioExceptionNot implemented- Parameters:
outGpio- The pin on which the output pulse will occur.inGpio- The pin on which the input pulse will be sought.waitDuration- The maximum time to wait in microseconds.pulseHoldDuration- The time to hold the output pulse in microseconds.pulseLow- True if the pulse should be a low pulse otherwise a high pulse will be sent.- Returns:
- The time in microseconds waiting for a pulse or -1 to signfify a timeout.
- Throws:
PigpioException- on pigpiod error
-
addCallback
Description copied from interface:JPigpioCalls a user supplied function (a callback) whenever the specified GPIO edge is detected.
The user supplied callback receives three parameters, the GPIO, the level, and the tick.
If a user callback is not specified a default tally callback is provided which simply counts edges. The count may be retrieved by calling the tally function. The count may be reset to zero by calling the reset_tally function.
The callback may be cancelled by calling the cancel function.
A GPIO may have multiple notificationListeners (although I can't think of a reason to do so).
... def cbf(gpio, level, tick): print(gpio, level, tick) cb1 = pi.callback(22, pigpio.EITHER_EDGE, cbf) cb2 = pi.callback(4, pigpio.EITHER_EDGE) cb3 = pi.callback(17) print(cb3.tally()) cb3.reset_tally() cb1.cancel() # To cancel callback cb1. ...- Parameters:
gpioListener- user supplied callback object.- Throws:
PigpioException
-
removeCallback
Description copied from interface:JPigpioRemove callback listener object from notification thread.- Parameters:
gpioListener- GPIOListener object- Throws:
PigpioException- on pigpiod error
-