Another Mouse sensor guy needing help

I have read a bunch of them and I am still in need of help processing data from a optical mouse sensor I have either a paw3402 or a mcs12085 (with a seperate resonator) to work with.

Right now I am trying to just get x, y values but eventually I want to interpret those vales and make the arduino spin a haptic motor every time the sensor registers movement over "x" values and then reset to do it again... Can anyone help me???

Right now all I get back is repeating 14640 line after line.

I am jumping off something done by John Graham-Cumming (see below for ino sketch .cpp and .h data)

Thanks a BUNCH,

Rory

mcs-12085.cpp (3.08 KB)

mcs-12085.h (305 Bytes)

mcs-12085.ino (1.59 KB)

I suspect you should call mcs12085_init() in setup().

Too bad the library doesn't come with any examples.

You have to use Pin 4 for clock and Pin 7 data unless you edit mcs-12085.cpp.

John,

Thanks for getting back with me I am using 4 and 7 for now. I inserted the mcs12085_int() and now get data in the serial monitor but it is gibberish.. see screen capture attached

I am guessing wrong baud rate for the chip.

tested baud rate change and no luck. Is there something in the .cpp file that is not converting it to a legible integer? Each line of gibberish is only created when the sensor moving; with no movement it is only a comma.

Got it to give me tangible data in x or y but not together. this is fine because I am only concerned with one axis... So
Can anyone help me with the script to record and sum the outputs from my chip and when the total movement is greater than +/- 10 it runs a vib motor sketch (below) and resets for next delta movement?

I THANK YOU VERY MUCH in advance.

const int motorPin = 3;

void setup()
{
pinMode(motorPin, OUTPUT);
}

void loop()
{
digitalWrite(motorPin, HIGH);
delay(40);

I think your problem is this:

Serial.println(mcs12085_dx(),mcs12085_dy());

If you look up the definition of .println() it will not display two integers if you pass two integers. You should make one call per integer:

Serial.print(mcs12085_dx()); 
Serial.println(mcs12085_dy());

yep your right. I overlooked that fact. I am very new to c++ and am learning the commands as I go. So please be patient.

Now I am trying to sum the outputs and generate my response it works at the correct movement rate. But I want it to fire 3x when I move one large jump that is 3 times my threshold..? should I be using if else statments or sum function? is an if statement the best way to deal with the negative values?

int i = mcs12085_dy();



 for (i;  i >= 4; i = i + i + i + i + i + i + i + i + i + i + i + i + i)
 {
  vib();
  } 

 for (i;  i >= 8; i=i)
 {
  vib2();
 } 

 for (i; i >= 19; i = i)
 {
 vib3();
  } 

// for (int i = mcs12085_dy(); 19 < i < 24; i = i + i + i + i + i)
// {
//  vib4();
//  } 


 void vib()
{
  digitalWrite(motorPin, HIGH);
  delay(5);
  digitalWrite(motorPin, LOW);
  
}

 void vib2()
{
  digitalWrite(motorPin, HIGH);
  delay(5);
  digitalWrite(motorPin, LOW);
  delay(150);
  digitalWrite(motorPin, HIGH);
  delay(5);
  digitalWrite(motorPin, LOW);

}

 void vib3()
{
  digitalWrite(motorPin, HIGH);
  delay(5);
  digitalWrite(motorPin, LOW);
  delay(150);
  digitalWrite(motorPin, HIGH);
  delay(5);
  digitalWrite(motorPin, LOW);
  delay(150);
  digitalWrite(motorPin, HIGH);
  delay(5);
  digitalWrite(motorPin, LOW);

What I would do is just measure absolute motion and vibrate each time the motion exceeds your vibrate threshold:

unsigned long TotalMotion;
const unsigned long Threshold = 20;  // Vibrate each time motion exceeds 20 pixels
void loop() {
    int motion = mcs12085_dy();
   if (motion >= 0)
      TotalMotion += motion;  /// shorthand for 'TotalMotion = TotalMotion + motion;'
   else
      TotalMotion -= motion;  // Subtract any negative values

  // Vibrate if threshold is reached
   if (TotalMotion >= Threshold) {
     TotalMotion -= Threshold;
      digitalWrite(motorPin, HIGH);
      delay(5);
      digitalWrite(motorPin, LOW);
      delay(150);
   }
}

John-

Thanks. I realize that there are multiple ways to tackle this and I have strugled finding the best way. I was trying to write the script for total motion + motion and didn't know how to write it. Thanks a lot; especially for including the description text next to your code! THANKS again from another novice c++/duino guy.

Hey, Rory.

Still out there, messing with your hacked mouse?

I'm just getting started. I ran across John G-C's article

The mouse I'm using has a MX8733 optical sensor 8-pin chip. It seems very similar to the MCS-12086.

I'm also using an Arduino UNO. I'm connected fine. And I'm running the Arduino code just like yours.
However, I'm only getting -1 for both X and Y. Nothing else.

Could you post a pic of how you wired your mouse chip? I don't get what I'm doing wrong.

Thanks!
Rick