Code Monkey home page Code Monkey logo

pmw3360's People

Contributors

per1234 avatar sunjunkim avatar tinxx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pmw3360's Issues

Sensor Initialization Failed - Compatible with ESP32 ?

Hello, I am trying to use this library on a ESP32.
I changed in the library the file "PWM3360.cpp" and remplaced SPI.begin() by SPI.begin(18, 19, 23, ss_pin) ; because MISO, MOSI and SCK pins aren't the same.

I tried to use the "basic_interrupt" example but I keep getting the issue "Sensor Initialization Failed". I am sure of the hardware part. I am wondering if the library is compatible with ESP32 ?

Thank you

Two's complement for burst motion values

Hello, I am just having trouble converting the dx and dy values from readBurst to usable signed integers and wondering if I could get some assistance on that. I was using the code from mrjohnk to do two's convolution on the DX_L and DY_L registers readings, but it doesn't seem to work on the raw dx and dy values from your code. It seems your code is returning a 16 bit number instead of an 8 bit..? Not sure on how to translate that. I just want to be able to use decimal integer values for motion tracking in a robotics project. Thanks!
Here is the code that I have been using:

int convTwosComp(int b){
  //Convert from 2's complement
  if(b & 0x80){                     // 0x80 (hex) = 10000000 (bin) = 128 (dec)
    b = -1 * ((b ^ 0xff) + 1);      // 0xff (hex) = 11111111 (bin) = 255 (dec)
  }
  return b;
}

PMW3360 & Banana-Pi Leaf S3

I am working with an open-source DIY mouse project that currently uses the ADND505 sensor(https://www.lynxware.org/), but I am wanting to modify it to use the PMW3360 Sensor. The project uses the Banana-Pi Leaf S3 chip (https://wiki.banana-pi.org/BPI-Leaf-S3). He said he looked into this sensor but was unable to find the code to use for his current project. This chip uses ESP32-S3 and supports Arduino programming. As a sidenote, his last version of this mouse used the ATMEGA32u4 controller, which I know you have a GitHub using that with the PMW3360. So if the PMW3360 won't work with the Banana-Pi, then I can go that route.

Since I am pretty new to all of this I started googling how to connect 2, but didn't find much documentation. I then decided to ask Chat GPT about it and it says that it is possible. I was wondering if you could confirm what it told me?

When asked about connecting the PMW3360 to the Banana Pi Leaf S3:
**Yes, you can connect a PMW3360 optical sensor to a Banana Pi Leaf S3 board using an Arduino. However, there are a few things to consider.

The PMW3360 sensor communicates using SPI (Serial Peripheral Interface), so you will need to use the SPI pins on the Banana Pi Leaf S3 and Arduino to establish communication between the two devices. You'll need to connect the following pins:

Banana Pi Leaf S3 SPI Pins:

  • MOSI (Master Out Slave In): Connect to Arduino's MOSI pin.
  • MISO (Master In Slave Out): Connect to Arduino's MISO pin.
  • SCK (Serial Clock): Connect to Arduino's SCK pin.
  • CS (Chip Select): Connect to a digital pin on the Arduino. You can choose any available digital pin.

Additionally, you need to connect the power and ground pins of the PMW3360 sensor to the appropriate pins on the Arduino.

Here's a general wiring setup:

PMW3360 Arduino Banana Pi Leaf S3

VCC -> 5V 5V
GND -> GND GND
SCK -> SCK SPI SCLK
MISO -> MISO SPI MISO
MOSI -> MOSI SPI MOSI
CS -> Digital Pin SPI CS

Once the connections are made, you can write Arduino code to communicate with the PMW3360 sensor over SPI. You'll need to initialize the SPI interface and configure the necessary settings for the PMW3360, such as resolution and sample rate. Then, you can read data from the sensor and process it as needed.

Keep in mind that this is a high-level overview, and the exact implementation details will depend on your specific hardware setup and the libraries you choose to use. Make sure to consult the datasheet and documentation of the PMW3360 sensor and refer to the Arduino and Banana Pi Leaf S3 documentation for further guidance on SPI communication and pin configurations.**

When asked to provide the full Arduino code using the library from SparkFun:

**Certainly! Here's the complete code that combines the PMW3360 sensor, Arduino, and Banana Pi Leaf S3 for SPI communication:

Arduino Code:(cpp)

#include <SPI.h>
#include <PMW3360.h>

// Define the Chip Select (CS) pin
const int CS_PIN = 10;  // Choose any available digital pin

// Create an instance of the PMW3360 class
PMW3360 mouse(CS_PIN);

void setup() {
  // Initialize SPI communication
  SPI.begin();
  
  // Initialize the PMW3360 sensor
  mouse.init();
  
  // Configure the sensor settings (e.g., resolution, sample rate)
  mouse.setCPI(800);   // Set CPI (Counts Per Inch)
  mouse.setSampleRate(2000);  // Set sample rate in Hz
}

void loop() {
  // Read motion data from the sensor
  int16_t motionX, motionY;
  bool motionDetected = mouse.getMotion(&motionX, &motionY);
  
  // Print the motion data if motion is detected
  if (motionDetected) {
    Serial.print("Motion X: ");
    Serial.print(motionX);
    Serial.print("  Motion Y: ");
    Serial.println(motionY);
  }
  
  // Add a delay between readings
  delay(10);
}

Banana Pi Code: (python)

import spidev

# Open SPI bus
spi = spidev.SpiDev()
spi.open(0, 0)  # Use the appropriate bus and chip select (CS) pins

# Read motion data from the Arduino
def read_motion():
    # Request motion data from Arduino
    spi.xfer([0x00])
    # Read the motion data
    motion_data = spi.xfer([0x00, 0x00, 0x00, 0x00])
    # Extract X and Y motion values
    motion_x = (motion_data[0] << 8) | motion_data[1]
    motion_y = (motion_data[2] << 8) | motion_data[3]
    return motion_x, motion_y

# Continuous motion data reading
while True:
    # Read motion data from the sensor
    motion_x, motion_y = read_motion()

    # Print the motion data
    print(f"Motion X: {motion_x}  Motion Y: {motion_y}")

Make sure to upload the Arduino code to your Arduino board using the Arduino IDE. Connect the PMW3360 sensor to the Arduino as described earlier in our conversation. On the Banana Pi, make sure you have the spidev module installed (you can install it using pip install spidev). Connect the SPI pins on the Banana Pi (MISO, MOSI, SCK, and CS) to the corresponding pins on the Arduino.

The Arduino code reads motion data from the PMW3360 sensor using SPI communication and sends it over the serial port. The Banana Pi code then reads the motion data from the Arduino through SPI using the spidev module and prints it to the console.

Note that in the Banana Pi code, you may need to adjust the spi.open(0, 0) line to match the appropriate SPI bus and chip select (CS) pins on your specific Banana Pi model. Refer to the Banana Pi documentation for the correct SPI pins.

Remember to establish a common ground connection between the Arduino and the Banana Pi to ensure proper communication.**

Thank you so much, and I look forward to hearing back.
-Ian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.