0

I am using ADNS3080 optical flow in raspberry pi 3. I set SPI connection between raspberry and ADNS3080 optical flow. I used spidev library for reading values in python. I want to read delta_x and delta_y position which registers corresponding to 0x03 and 0x04 numbers in datasheet. So I am using this code for reading registers:

import spidev
import time
spi = spidev.SpiDev()
spi.open(0,0)
while True:
   resp = spi.xfer2([0x03, 0x04])
   print resp
   time.sleep(1)

I am taking "0,0" results in every loop. I have checked the connections hardware and there are no problems. What is the reason why I can't read these values?

tlfong01
  • 4,665
  • 3
  • 10
  • 24
  • Hello @erenpostaci, Welcome and nice to meet you. Ah, let me see. (1) Are you sure your mouse is not in NPD (Power Down Mode)? (2) Are you sure you can spi.xfer2 both ∆x and ∆y registers in a row? To troubleshoot, perhaps you can just do ∆x first. (3) I understand you have double checked hardware wiring (open short tests with a multimeter, I suppose), but I strongly recommend to do SPI loopback to make sure the software side is also OK. Reference: https://imgur.com/gallery/uxYDTgz. PS - You can search "SPI, loopback" in this forum for my fully debugged, newbie friendly SPI loopback programs. – tlfong01 Feb 20 '20 at 01:36
  • I read the datasheet page 16 saying the following: "Read Operation - A read operation, defined as data going from the ADNS3080 to the micro-controller, is always initiated by the micro-controller and consists of two bytes. The first byte contains the address, is sent by the micro-controller over MOSI, and has a “0” as its MSB to indicate data direction. The second byte contains the data and is driven by the ADNS-3080 over MISO. The sensor outputs MISO bits on falling edges of SCLK and samples MOSI bits on every rising edge of SCLK. / to continue, ... – tlfong01 Feb 20 '20 at 01:45
  • So I guess that to read ∆x register, you should try this: spi.xfer2(∆x-register-addr, dummy-byte). Let me know if my guess is correct. Cheers. – tlfong01 Feb 20 '20 at 01:48
  • @tlfong01 thank you for your answer. I have used optical flow board not ADNS-3080 microcontroller. Also you can look in this link . I checked connection. Also I have checked in ardunio uno board. And I can get values from this board. What can you suggest code for get position in python? – erenpostaci Feb 20 '20 at 12:02
  • Ha, I am confused. The first sentence in your question is: "I am using ADNS3080 optical flow in raspberry pi 3", Just now you are saying: "I have used optical flow board not ADNS-3080 microcontroller". I need to followed the link you just gave me, to clear my mind. See you later. – tlfong01 Feb 20 '20 at 12:32
  • Just now I checked out your new link and found it is just a image. Anyway, I used the marking in the image and found the following: (1) "Mouse-based Optical Flow Sensor (ADNS3080)": https://ardupilot.org/copter/docs/common-mouse-based-optical-flow-sensor-adns3080.html. Please let me know if I am going in the correct direction? – tlfong01 Feb 20 '20 at 12:37
  • @tlfong01 yes. I am using Mouse-based Optical Flow Sensor (ADNS3080). And I want to get position values from this board. – erenpostaci Feb 20 '20 at 12:43
  • Anyway, I googled further from there and found tutorials talking about FPV and Mission Planner. This reminds me I once answer another question involving FPV and Missioner. Coming back to your statement "I have used optical flow board not ADNS-3080 microcontroller" Now can you tell me if the following statements are true" (1) ADNS-3080 is a microcontroller, (2) Optical Flow is a sensor, not a controller. (3) Rpi talks to the Optical Flow sensor using SPI. – tlfong01 Feb 20 '20 at 12:47
  • The Q&A I referred above is this one: (1) https://raspberrypi.stackexchange.com/questions/105223/how-can-rpi4b-use-uart-to-read-and-analyze-received-data-at-a-3dr-fpv-air-radio/105489#105489. (2) PLEASE READ THE CHAT RECORD: https://chat.stackexchange.com/rooms/100706/discussion-on-question-by-thelazy-how-can-rpi4b-use-uart-to-read-and-analyze-rec. Does your project has anything related to it? – tlfong01 Feb 20 '20 at 12:48
  • Now let me know if my following guess is correct: In the tutorial the "Mouse-based Optical Flow Sensor (ADNS3080)" is connected to APM1/2 microcontroller. But now you don't want to use APM1/2. You want to use RPI. – tlfong01 Feb 20 '20 at 12:56
  • @tlfong01 I am using optical flow sensor and this sensor is contaning ADNS-3080 microcontroller. So I want to get position values from this sensor with help of python in raspberry pi-3. Every sample about this board has written Ardunio environments. So I adapted Ardiuno Uno which connecting SPI communication and I can get position values in this sensor. At the end of the day I want to run this sensor in raspberry - 3 so I am using python spidev library for getting the position values. – erenpostaci Feb 20 '20 at 12:57
  • Another question: Is your project FPV, and are you using MPU6000/MPU6050/MPU9250 or something similar? – tlfong01 Feb 20 '20 at 12:59
  • No I don't use FPV for this project. No I never use MPU6000/MPU6050/MPU9250. – erenpostaci Feb 20 '20 at 13:00

0 Answers0