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 JPigpio interface for full documentation
  • Field Summary

    Fields 
    Modifier and Type Field Description
    int PIGPIOD_MESSAGE_SIZE  
  • Constructor Summary

    Constructors 
    Constructor Description
    PigpioSocket​(java.lang.String host, int port)
    The constructor of the class.
  • Method Summary

    Modifier and Type Method Description
    void addCallback​(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.
    long getCurrentTick()  
    int getPWMDutycycle​(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).
    int getPWMFrequency​(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*].
    int getPWMRange​(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).
    int getPWMRealRange​(int gpio)
    Returns the real (underlying) range of PWM values being used on the GPIO.
    int getServoPulseWidth​(int gpio)
    Not implemented
    void gpioDelay​(long delay)
    Delay for the specified number of microseconds
    int gpioGetMode​(int pin)
    Retrieve the mode of the given gpio
    void gpioInitialize()  
    boolean gpioRead​(int pin)
    Retrieve the state of the gpio
    void gpioServo​(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.
    void gpioSetAlertFunc​(int pin, Alert gpioAlert)  
    void gpioSetMode​(int pin, int mode)
    Set the mode of the gpio
    void gpioSetPullUpDown​(int pin, int pud)  
    void gpioTerminate()
    Terminate the usage of the pigpio interfaces.
    long gpioTick()  
    void gpioTrigger​(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.
    void gpioWrite​(int pin, boolean value)
    Set the state of the gpio
    long gpioxPulseAndWait​(int outGpio, int inGpio, long waitDuration, long pulseHoldDuration, boolean pulseLow)
    Not implemented
    void i2cClose​(int handle)
    Closes the I2C device associated with handle.
    int i2cOpen​(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.
    int i2cReadDevice​(int handle, byte[] data)
    Returns count bytes read from the raw device associated with handle.
    void i2cWriteDevice​(int handle, byte[] data)
    Writes the data bytes to the raw device associated with handle.
    void notifyBegin​(int handle, int bits)
    Starts notifications on a handle.

    The notification sends state changes for each GPIO whose corresponding bit in bits is set.
    void notifyClose​(int handle)
    Stops notifications on a handle and releases the handle for reuse.
    int notifyOpen()
    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.
    void notifyPause​(int handle)
    Pauses notifications on a handle.

    Notifications for the handle are suspended until [*notify_begin*] is called again.

    void reconnect()
    Try reconnecting to pigpio.
    void removeCallback​(GPIOListener gpioListener)
    Remove callback listener object from notification thread.
    void serialClose​(int handle)
    Closes the serial device associated with handle.
    int serialDataAvailable​(int handle)
    Returns the number of bytes available to be read from the device associated with handle.
    int serialOpen​(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.
    byte serialReadByte​(int handle)
    Returns a single byte from the device associated with handle.
    void serialWrite​(int handle, byte[] data)
    Writes the data bytes to the device associated with handle.
    void serialWriteByte​(int handle, byte data)
    Writes a single byte to the device associated with handle.
    void setDebug​(boolean flag)
    Not implemented
    void setPWMDutycycle​(int gpio, int dutycycle)
    Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO.
    int setPWMFrequency​(int gpio, int frequency)
    Sets the frequency (in Hz) of the PWM to be used on the GPIO.

    Returns the frequency actually set.
    void setPWMRange​(int gpio, int range)
    Sets the range of PWM values to be used on the GPIO.
    void setServoPulseWidth​(int gpio, int pulseWidth)  
    void setWatchdog​(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.

    void spiClose​(int handle)
    Closes the SPI device associated with handle.
    int spiOpen​(int spiChannel, int spiBaudRate, int flags)
    Returns a handle for the SPI device on channel.
    int spiRead​(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.
    int spiWrite​(int handle, byte[] data)
    Writes the data bytes to the SPI device associated with handle.
    int spiXfer​(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.
    int waveAddGeneric​(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.
    void waveAddNew()
    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.
    int waveAddSerial​(int userGpio, int baud, byte[] data, int offset, int bbBits, int bbStop)
    Adds a waveform representing serial data to the existing waveform (if any).
    void waveClear()
    This function clears all waveforms and any data added by calls to the wave_add_* functions.
    int waveCreate()
    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.
    void waveDelete​(int waveId)
    This function deletes the waveform with id wave_id.

    Wave ids are allocated in order, 0, 1, 2, etc.
    int waveSendOnce​(int waveId)
    Transmits the waveform with id wave_id.
    int waveSendRepeat​(int waveId)
    Transmits the waveform with id wave_id.
    boolean waveTxBusy()
    Returns 1 if a waveform is currently being transmitted, otherwise 0.
    int waveTxStop()
    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

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • PigpioSocket

      public PigpioSocket​(java.lang.String host, int port) throws PigpioException
      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

      public void gpioInitialize() throws PigpioException
      Throws:
      PigpioException
    • reconnect

      public void reconnect() throws PigpioException
      Description copied from interface: JPigpio
      Try reconnecting to pigpio. This does make sense in case of socket pigpiod interface
      Throws:
      PigpioException
    • gpioTerminate

      public void gpioTerminate() throws PigpioException
      Description copied from interface: JPigpio
      Terminate the usage of the pigpio interfaces.
      Throws:
      PigpioException - on error
    • gpioSetMode

      public void gpioSetMode​(int pin, int mode) throws PigpioException
      Description copied from interface: JPigpio
      Set the mode of the gpio
      Parameters:
      pin - The gpio pin to set
      mode - The mode of the pin. One of PI_INPUT or PI_OUTPUT
      Throws:
      PigpioException - on pigpiod error
    • gpioGetMode

      public int gpioGetMode​(int pin) throws PigpioException
      Description copied from interface: JPigpio
      Retrieve 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

      public void gpioSetPullUpDown​(int pin, int pud) throws PigpioException
      Throws:
      PigpioException
    • gpioRead

      public boolean gpioRead​(int pin) throws PigpioException
      Description copied from interface: JPigpio
      Retrieve 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

      public void gpioWrite​(int pin, boolean value) throws PigpioException
      Description copied from interface: JPigpio
      Set the state of the gpio
      Parameters:
      pin - The gpio pin to set
      value - The desired value of the new pin state. One of PI_HIGH or PI_LOW (or equivalents)
      Throws:
      PigpioException - on pigpiod error
    • notifyOpen

      public int notifyOpen() throws PigpioException
      Description copied from interface: JPigpio
      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. 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.
       
       . .
       I seqno
       I flags
       I tick
       I level
       . .
       
      seqno: starts at 0 each time the handle is opened and then increments by one for each report.

      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

      public void notifyBegin​(int handle, int bits) throws PigpioException
      Description copied from interface: JPigpio
      Starts 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

      public void notifyPause​(int handle) throws PigpioException
      Description copied from interface: JPigpio
      Pauses 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

      public void notifyClose​(int handle) throws PigpioException
      Description copied from interface: JPigpio
      Stops 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

      public void setWatchdog​(int userGpio, int timeout) throws PigpioException
      Description copied from interface: JPigpio
      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.

      
       ...
       pi.setWatchdog(23, 1000) # 1000 ms watchdog on GPIO 23
       pi.setWatchdog(23, 0)    # cancel watchdog on GPIO 23
       ...
      Parameters:
      userGpio - 0-31
      timeout - 0-60000
      Throws:
      PigpioException - on pigpiod error
    • waveClear

      public void waveClear() throws PigpioException
      Description copied from interface: JPigpio
      This function clears all waveforms and any data added by calls to the wave_add_* functions.
      Throws:
      PigpioException - on pigpiod error
    • waveAddGeneric

      public int waveAddGeneric​(java.util.ArrayList<Pulse> pulses) throws PigpioException
      Description copied from interface: JPigpio
      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.
      
       ...
       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&lt;&lt;G1, 1&lt;&lt;G2, 500000))
       flash_500.addListener(pigpio.pulse(1&lt;&lt;G2, 1&lt;&lt;G1, 500000))
      
       flash_100.addListener(pigpio.pulse(1&lt;&lt;G1, 1&lt;&lt;G2, 100000))
       flash_100.addListener(pigpio.pulse(1&lt;&lt;2, 1&lt;&lt;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 PigpioException
      Description copied from interface: JPigpio
      Adds 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

      public void waveAddNew() throws PigpioException
      Description copied from interface: JPigpio
      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.
      
       ...
       pi.wave_add_new()
       ...
       
      Throws:
      PigpioException - on pigpiod error
    • waveTxBusy

      public boolean waveTxBusy() throws PigpioException
      Description copied from interface: JPigpio
      Returns 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

      public int waveTxStop() throws PigpioException
      Description copied from interface: JPigpio
      Stops 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

      public int waveCreate() throws PigpioException
      Description copied from interface: JPigpio
      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. 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
      1. the GPIO to be switched on at the start of the pulse.
      2. the GPIO to be switched off at the start of the pulse.
      3. the delay in microseconds before the next pulse.
      Any or all the fields can be zero. It doesn't make any sense to set all the fields to zero (the pulse will be ignored).
      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

      public void waveDelete​(int waveId) throws PigpioException
      Description copied from interface: JPigpio
      This 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

      public int waveSendOnce​(int waveId) throws PigpioException
      Description copied from interface: JPigpio
      Transmits 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

      public int waveSendRepeat​(int waveId) throws PigpioException
      Description copied from interface: JPigpio
      Transmits 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

      public int i2cOpen​(int i2cBus, int i2cAddr) throws PigpioException
      Description copied from interface: JPigpio
      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. 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

      public void i2cClose​(int handle) throws PigpioException
      Description copied from interface: JPigpio
      Closes 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

      public int i2cReadDevice​(int handle, byte[] data) throws PigpioException
      Description copied from interface: JPigpio
      Returns 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

      public void i2cWriteDevice​(int handle, byte[] data) throws PigpioException
      Description copied from interface: JPigpio
      Writes 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

      public void gpioDelay​(long delay) throws PigpioException
      Description copied from interface: JPigpio
      Delay for the specified number of microseconds
      Parameters:
      delay - The number of microseconds for which to block
      Throws:
      PigpioException - on pigpiod error
    • gpioTick

      public long gpioTick() throws PigpioException
      Throws:
      PigpioException
    • getCurrentTick

      public long getCurrentTick() throws PigpioException
      Throws:
      PigpioException
    • gpioServo

      public void gpioServo​(int gpio, int pulseWidth) throws PigpioException
      Description copied from interface: JPigpio
      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. 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-31
      pulseWidth - The pulse width of the pulse (500-2500).
      0 = off
      500 = most anti-clockwise
      2500 = most clock-wise
      Throws:
      PigpioException - on pigpiod error
    • setServoPulseWidth

      public void setServoPulseWidth​(int gpio, int pulseWidth) throws PigpioException
      Throws:
      PigpioException
    • getServoPulseWidth

      public int getServoPulseWidth​(int gpio) throws PigpioException
      Not implemented
      Parameters:
      gpio - user gpio 0-31
      Returns:
      Returns the servo pulsewidth.
      Throws:
      PigpioException - on pigpiod error
    • gpioSetAlertFunc

      public void gpioSetAlertFunc​(int pin, Alert gpioAlert) throws PigpioException
      Throws:
      PigpioException
    • gpioTrigger

      public void gpioTrigger​(int gpio, long pulseLen, boolean level) throws PigpioException
      Description copied from interface: JPigpio
      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.
      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

      public int spiOpen​(int spiChannel, int spiBaudRate, int flags) throws PigpioException
      Description copied from interface: JPigpio
      Returns 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

      public void spiClose​(int handle) throws PigpioException
      Description copied from interface: JPigpio
      Closes 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

      public int spiRead​(int handle, byte[] data) throws PigpioException
      Description copied from interface: JPigpio
      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. 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

      public int spiWrite​(int handle, byte[] data) throws PigpioException
      Description copied from interface: JPigpio
      Writes 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

      public int spiXfer​(int handle, byte[] txData, byte[] rxData) throws PigpioException
      Description copied from interface: JPigpio
      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. 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

      public void setPWMDutycycle​(int gpio, int dutycycle) throws PigpioException
      Description copied from interface: JPigpio
      Starts (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-31
      dutycycle - 0-range (range defaults to 255).
      Throws:
      PigpioException - on pigpiod error
    • getPWMDutycycle

      public int getPWMDutycycle​(int gpio) throws PigpioException
      Description copied from interface: JPigpio
      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).
      
       ...
       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

      public void setPWMRange​(int gpio, int range) throws PigpioException
      Description copied from interface: JPigpio
      Sets 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-31
      range - range 25-40000
      Throws:
      PigpioException - on pigpiod error
    • getPWMRange

      public int getPWMRange​(int gpio) throws PigpioException
      Description copied from interface: JPigpio
      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).
      
       ...
       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

      public int getPWMRealRange​(int gpio) throws PigpioException
      Description copied from interface: JPigpio
      Returns 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

      public int setPWMFrequency​(int gpio, int frequency) throws PigpioException
      Description copied from interface: JPigpio
      Sets 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-31
      frequency - >= 0 Hz
      Returns:
      Returns the frequency actually set.
      Throws:
      PigpioException - on pigpiod error
    • getPWMFrequency

      public int getPWMFrequency​(int gpio) throws PigpioException
      Description copied from interface: JPigpio
      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*].
      
       ...
       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

      public int serialOpen​(java.lang.String tty, int baudRate, int flags) throws PigpioException
      Description copied from interface: JPigpio
      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. 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 open
      baudRate - 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

      public void serialClose​(int handle) throws PigpioException
      Description copied from interface: JPigpio
      Closes 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

      public byte serialReadByte​(int handle) throws PigpioException
      Description copied from interface: JPigpio
      Returns 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

      public void serialWriteByte​(int handle, byte data) throws PigpioException
      Description copied from interface: JPigpio
      Writes 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

      public byte[] serialRead​(int handle, int count) throws PigpioException
      Description copied from interface: JPigpio
      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. 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

      public void serialWrite​(int handle, byte[] data) throws PigpioException
      Description copied from interface: JPigpio
      Writes 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

      public int serialDataAvailable​(int handle) throws PigpioException
      Description copied from interface: JPigpio
      Returns the number of bytes available to be read from the device associated with handle.
      
       ...
       rdy = pi.serial_data_available(h1)
      
       if rdy &gt; 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

      public void setDebug​(boolean flag) throws PigpioException
      Not implemented
      Throws:
      PigpioException
    • gpioxPulseAndWait

      public long gpioxPulseAndWait​(int outGpio, int inGpio, long waitDuration, long pulseHoldDuration, boolean pulseLow) throws PigpioException
      Not 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

      public void addCallback​(GPIOListener gpioListener) throws PigpioException
      Description copied from interface: JPigpio
      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. 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

      public void removeCallback​(GPIOListener gpioListener) throws PigpioException
      Description copied from interface: JPigpio
      Remove callback listener object from notification thread.
      Parameters:
      gpioListener - GPIOListener object
      Throws:
      PigpioException - on pigpiod error