In my previous project I have used spidev in order to work with ADC, and in python script I could have:

spi = spidev.SpiDev()
adc = spi.xfer2([1,(8+channel)<<4,0])

Now I'm trying to work with pigpio library (to avoid the permission demands) but I'm not really sure how to use pigpio's spi_open and spi_xfer functions. Looks like they take more input arguments than spi.open and spi.xfer2. Can someone explain to me what these arguments are - in some analogy with my previous approach with spidev? Thanks a lot.

1 Answer 1



You only need to specify the channel and bit rate. The flags should normally be left as 0. The call returns a handle (a small number >=0) which is passed to the other SPI functions.

h = spi_open(0, 1000000) # get handle for SPI channel 0 at 1000000 bits per second.


Ypu specify the handle (returned by spi_open) and the data to send. The number of bytes received and the bytes themselves are returned.

adc_channel = 0

count, data = spi_xfer(h, [1,(8+adc_channel)<<4,0])

Send three bytes to the SPI device defined by handle h. The individual bytes are 1, (8+adc_channel)<<4, and 0.

count will be 3 (the number of bytes received is always the same as the number of bytes send except for errors) and data will be a list of three bytes (data[0], data[1], and data[2]).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.