I have been trying a lot to deal with the flow-motion sensor but I couldn't arrive to a clear result. It might be I can't understand the procedure..

I'm using cs1 on raspberry Defining the spi by this code

import spidev
import time

spi = spidev.SpiDev()
spi.max_speed_hz = 2000000

following this to read the product ID or delta_x I have to send the address and then read so either i use xfer2 or write and then read by the two cases I always get zero or 23 on product ID

resp = spi.xfer2([0x00])


resp = spi.readbytes(10)


ADNS3080 datasheet

py-spidev documentation

1 Answer 1


It would be helpful if you link to the spec of the device rather than relying on people to search for you.

The device requires two bytes.

Try resp = spi.xfer([0, 0]) to read the product id. The result (23 or 0x17) should be in resp[1].

If that is not reliable you are going to have to drop the speed to accommodate the 50 µs delay between bytes.

  • I did update my post, Can you please explain me why the device require two bytes. first address and second the data ?. I did try to read the delta_x using the address 0x03 using xfer but the result is always 0 and by using write and read the result is 23. regarding the time I did the sleep as yo usee down. code resp = spi.xfer([0x03,0x00]) or code spi.writebytes([0x03]) time.sleep(0.000050) resp = spi.readbytes(1)
    – Feras
    Apr 26, 2016 at 7:51
  • Doesn't the spec say 2 bytes are required for a read or write on page 16? Page 17 shows the various delays needed. Have you cut the speed down to less than 20 kbps? That would ensure the timing for most commands. Because of the timing requirements I would use my own GPIO for chip select and toggle it on and off as required. You might be able to achieve the same effect with xfer2. You have not explained (in a form I can understand) which, if any, commands are working and which are not.
    – joan
    Apr 26, 2016 at 8:48
  • I changed the wiring to toggle the cs. if I type this code only it gives me zero for Product ID code GPIO.output(cs, GPIO.LOW) spi.writebytes([0x00]) resp = spi.readbytes(1) GPIO.output(cs, GPIO.HIGH) time.sleep(0.00015) but if I add this code before code GPIO.output(cs, GPIO.LOW) #resp = spi.xfer2([0x00,0]) #print resp[1] GPIO.output(cs, GPIO.HIGH) time.sleep(0.00015) the second request and the first request gives 23. I can't find the logic behind this behavior and I don't know why it gives zero for delta_x
    – Feras
    Apr 26, 2016 at 10:18
  • small update: the problem was the lens it required more light to respond.
    – Feras
    Apr 26, 2016 at 10:35
  • @Feras That's good. If you can get it to work reliably you could answer your own question with the details. That would be useful for people who come across the question.
    – joan
    Apr 26, 2016 at 10:51

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.