Open kixell opened 6 years ago
Yes, in fact, each one I mail out is tested with a Teensy LC. That is what I built my test jig with as well.
On Sun, Jul 8, 2018, 7:26 PM kixell notifications@github.com wrote:
I'm not sure this is correct but this is how I have this wired currently. Wire PMW3360 TeensyLC Notes O RS Not Used NotUsed Ow GD G GD = GND Bu MT Pin 0 MT = Pin 0 BuW SS Pin 10 SS = CS0 -or- CS G SC Pin 13 SC = SCK0 -or- SCK GW MO Pin 11 MO = MOSI0 -or- DOUT Br MI Pin 12 MI = MISO0 -or- DIN BrW VI 3v VI = 3.3V
[image: image] https://user-images.githubusercontent.com/20509578/42425576-6e3d106e-82dc-11e8-91fc-49b1f50af090.png
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mrjohnk/PMW3360DM-T2QU/issues/18, or mute the thread https://github.com/notifications/unsubscribe-auth/ABG0-e1knHlfRbuXuyr0f3PjdTBUCDqjks5uEqM6gaJpZM4VG72d .
I'm a complete novice at this and any help is greatly appreciated.
I changed the code to
#define Motion_Interrupt_Pin 6
const int ncs = 21; //This is the SPI "slave select" pin that the sensor is hooked up to
and then changed the MT pin to 21 and the SS pin to 6.
Is this correct?
I'm not getting and cursor motion and it seems like there is no light coming from the senor.
You probably need to also modify the attachInterrupt statement to the same pin you connected the MT from the sensor to. ncs needs to be the same as what you connected the SS to.
Also, spend some time trying the polling example. It does not use the hardware interrupt or MT pin and is more simple than the other one.
On Sun, Jul 8, 2018, 10:13 PM kixell notifications@github.com wrote:
I'm a complete novice at this and any help is greatly appreciated.
I changed the code to `
define Motion_Interrupt_Pin 6
const int ncs = 21; //This is the SPI "slave select" pin that the sensor is hooked up to `
and then changed the MT pin to 21 and the SS pin to 6.
Is this correct?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mrjohnk/PMW3360DM-T2QU/issues/18#issuecomment-403348018, or mute the thread https://github.com/notifications/unsubscribe-auth/ABG0-fclFTX1V9Kltadb_9BedYvQ0w9cks5uEspegaJpZM4VG72d .
I'm using the polling code. and uploading to the Teensy LS with the following settings.
I am now able to get the data from the Serial Monitor to show data but the cursor isn't moving.
Should it be?
USB type: Serial + Keyboad + Mouse + Joystick
CPU Speed: "48 MHz"
Port "COM1"
is this correct?
MT to Pin 9 SS to Pin 10 MO to Pin 11 MI to Pin 12
/*
* This example bypasses the hardware motion interrupt pin
* and polls the motion data registers at a fixed interval
*/
#include <SPI.h>
#include <avr/pgmspace.h>
// Registers
#define Product_ID 0x00
#define Revision_ID 0x01
#define Motion 0x02
#define Delta_X_L 0x03
#define Delta_X_H 0x04
#define Delta_Y_L 0x05
#define Delta_Y_H 0x06
#define SQUAL 0x07
#define Raw_Data_Sum 0x08
#define Maximum_Raw_data 0x09
#define Minimum_Raw_data 0x0A
#define Shutter_Lower 0x0B
#define Shutter_Upper 0x0C
#define Control 0x0D
#define Config1 0x0F
#define Config2 0x10
#define Angle_Tune 0x11
#define Frame_Capture 0x12
#define SROM_Enable 0x13
#define Run_Downshift 0x14
#define Rest1_Rate_Lower 0x15
#define Rest1_Rate_Upper 0x16
#define Rest1_Downshift 0x17
#define Rest2_Rate_Lower 0x18
#define Rest2_Rate_Upper 0x19
#define Rest2_Downshift 0x1A
#define Rest3_Rate_Lower 0x1B
#define Rest3_Rate_Upper 0x1C
#define Observation 0x24
#define Data_Out_Lower 0x25
#define Data_Out_Upper 0x26
#define Raw_Data_Dump 0x29
#define SROM_ID 0x2A
#define Min_SQ_Run 0x2B
#define Raw_Data_Threshold 0x2C
#define Config5 0x2F
#define Power_Up_Reset 0x3A
#define Shutdown 0x3B
#define Inverse_Product_ID 0x3F
#define LiftCutoff_Tune3 0x41
#define Angle_Snap 0x42
#define LiftCutoff_Tune1 0x4A
#define Motion_Burst 0x50
#define LiftCutoff_Tune_Timeout 0x58
#define LiftCutoff_Tune_Min_Length 0x5A
#define SROM_Load_Burst 0x62
#define Lift_Config 0x63
#define Raw_Data_Burst 0x64
#define LiftCutoff_Tune2 0x65
//Set this to what pin your "INT0" hardware interrupt feature is on
#define Motion_Interrupt_Pin 9
const int ncs = 10; //This is the SPI "slave select" pin that the sensor is hooked up to
byte initComplete=0;
volatile int xydat[2];
volatile byte movementflag=0;
byte testctr=0;
unsigned long currTime;
unsigned long timer;
unsigned long pollTimer;
//Be sure to add the SROM file into this sketch via "Sketch->Add File"
extern const unsigned short firmware_length;
extern const unsigned char firmware_data[];
void setup() {
Serial.begin(9600);
pinMode (ncs, OUTPUT);
pinMode(Motion_Interrupt_Pin, INPUT);
digitalWrite(Motion_Interrupt_Pin, HIGH);
attachInterrupt(9, UpdatePointer, FALLING);
SPI.begin();
SPI.setDataMode(SPI_MODE3);
SPI.setBitOrder(MSBFIRST);
//SPI.setClockDivider(4);
performStartup();
delay(5000);
dispRegisters();
initComplete=9;
}
void adns_com_begin(){
digitalWrite(ncs, LOW);
}
void adns_com_end(){
digitalWrite(ncs, HIGH);
}
byte adns_read_reg(byte reg_addr){
adns_com_begin();
// send adress of the register, with MSBit = 0 to indicate it's a read
SPI.transfer(reg_addr & 0x7f );
delayMicroseconds(100); // tSRAD
// read data
byte data = SPI.transfer(0);
delayMicroseconds(1); // tSCLK-NCS for read operation is 120ns
adns_com_end();
delayMicroseconds(19); // tSRW/tSRR (=20us) minus tSCLK-NCS
return data;
}
void adns_write_reg(byte reg_addr, byte data){
adns_com_begin();
//send adress of the register, with MSBit = 1 to indicate it's a write
SPI.transfer(reg_addr | 0x80 );
//sent data
SPI.transfer(data);
delayMicroseconds(20); // tSCLK-NCS for write operation
adns_com_end();
delayMicroseconds(100); // tSWW/tSWR (=120us) minus tSCLK-NCS. Could be shortened, but is looks like a safe lower bound
}
void adns_upload_firmware(){
// send the firmware to the chip, cf p.18 of the datasheet
Serial.println("Uploading firmware...");
//Write 0 to Rest_En bit of Config2 register to disable Rest mode.
adns_write_reg(Config2, 0x20);
// write 0x1d in SROM_enable reg for initializing
adns_write_reg(SROM_Enable, 0x1d);
// wait for more than one frame period
delay(10); // assume that the frame rate is as low as 100fps... even if it should never be that low
// write 0x18 to SROM_enable to start SROM download
adns_write_reg(SROM_Enable, 0x18);
// write the SROM file (=firmware data)
adns_com_begin();
SPI.transfer(SROM_Load_Burst | 0x80); // write burst destination adress
delayMicroseconds(15);
// send all bytes of the firmware
unsigned char c;
for(int i = 0; i < firmware_length; i++){
c = (unsigned char)pgm_read_byte(firmware_data + i);
SPI.transfer(c);
delayMicroseconds(15);
}
//Read the SROM_ID register to verify the ID before any other register reads or writes.
adns_read_reg(SROM_ID);
//Write 0x00 to Config2 register for wired mouse or 0x20 for wireless mouse design.
adns_write_reg(Config2, 0x00);
// set initial CPI resolution
adns_write_reg(Config1, 0x15);
adns_com_end();
}
void performStartup(void){
adns_com_end(); // ensure that the serial port is reset
adns_com_begin(); // ensure that the serial port is reset
adns_com_end(); // ensure that the serial port is reset
adns_write_reg(Power_Up_Reset, 0x5a); // force reset
delay(50); // wait for it to reboot
// read registers 0x02 to 0x06 (and discard the data)
adns_read_reg(Motion);
adns_read_reg(Delta_X_L);
adns_read_reg(Delta_X_H);
adns_read_reg(Delta_Y_L);
adns_read_reg(Delta_Y_H);
// upload the firmware
adns_upload_firmware();
delay(10);
Serial.println("Optical Chip Initialized");
}
void UpdatePointer(void){
if(initComplete==9){
//write 0x01 to Motion register and read from it to freeze the motion values and make them available
adns_write_reg(Motion, 0x01);
adns_read_reg(Motion);
xydat[0] = (int)adns_read_reg(Delta_X_L);
xydat[1] = (int)adns_read_reg(Delta_Y_L);
movementflag=1;
}
}
void dispRegisters(void){
int oreg[7] = {
0x00,0x3F,0x2A,0x02 };
char* oregname[] = {
"Product_ID","Inverse_Product_ID","SROM_Version","Motion" };
byte regres;
digitalWrite(ncs,LOW);
int rctr=0;
for(rctr=0; rctr<4; rctr++){
SPI.transfer(oreg[rctr]);
delay(1);
Serial.println("---");
Serial.println(oregname[rctr]);
Serial.println(oreg[rctr],HEX);
regres = SPI.transfer(0);
Serial.println(regres,BIN);
Serial.println(regres,HEX);
delay(1);
}
digitalWrite(ncs,HIGH);
}
int convTwosComp(int b){
//Convert from 2's complement
if(b & 0x80){
b = -1 * ((b ^ 0xff) + 1);
}
return b;
}
void loop() {
currTime = millis();
if(currTime > timer){
Serial.println(testctr++);
timer = currTime + 2000;
}
if(currTime > pollTimer){
UpdatePointer();
xydat[0] = convTwosComp(xydat[0]);
xydat[1] = convTwosComp(xydat[1]);
if(xydat[0] != 0 || xydat[1] != 0){
Serial.print("x = ");
Serial.print(xydat[0]);
Serial.print(" | ");
Serial.print("y = ");
Serial.println(xydat[1]);
}
pollTimer = currTime + 20;
}
}
That sketch does not have a mouse movement component, but you could certainly add one of you would like. It would be a statement like the one below that would be inserted near the bottom of the code in the section that prints out the motion data.
Mouse.move(convTwosComp(xydat[0]),convTwosComp(xydat[1]))
On Mon, Jul 9, 2018, 11:23 PM kixell notifications@github.com wrote:
I'm using the polling code. and uploading to the Teensy LS with the following settings. I am now able to get the data from the Serial Monitor to show data but the cursor isn't moving. Should it be?
USB type: Serial + Keyboad + Mouse + Joystick CPU Speed: "48 MHz" Port "COM1"
is this correct?
MT to Pin 9 SS to Pin 10 MO to Pin 11 MI to Pin 12
/*
- This example bypasses the hardware motion interrupt pin
- and polls the motion data registers at a fixed interval */
include
include <avr/pgmspace.h>
// Registers
define Product_ID 0x00
define Revision_ID 0x01
define Motion 0x02
define Delta_X_L 0x03
define Delta_X_H 0x04
define Delta_Y_L 0x05
define Delta_Y_H 0x06
define SQUAL 0x07
define Raw_Data_Sum 0x08
define Maximum_Raw_data 0x09
define Minimum_Raw_data 0x0A
define Shutter_Lower 0x0B
define Shutter_Upper 0x0C
define Control 0x0D
define Config1 0x0F
define Config2 0x10
define Angle_Tune 0x11
define Frame_Capture 0x12
define SROM_Enable 0x13
define Run_Downshift 0x14
define Rest1_Rate_Lower 0x15
define Rest1_Rate_Upper 0x16
define Rest1_Downshift 0x17
define Rest2_Rate_Lower 0x18
define Rest2_Rate_Upper 0x19
define Rest2_Downshift 0x1A
define Rest3_Rate_Lower 0x1B
define Rest3_Rate_Upper 0x1C
define Observation 0x24
define Data_Out_Lower 0x25
define Data_Out_Upper 0x26
define Raw_Data_Dump 0x29
define SROM_ID 0x2A
define Min_SQ_Run 0x2B
define Raw_Data_Threshold 0x2C
define Config5 0x2F
define Power_Up_Reset 0x3A
define Shutdown 0x3B
define Inverse_Product_ID 0x3F
define LiftCutoff_Tune3 0x41
define Angle_Snap 0x42
define LiftCutoff_Tune1 0x4A
define Motion_Burst 0x50
define LiftCutoff_Tune_Timeout 0x58
define LiftCutoff_Tune_Min_Length 0x5A
define SROM_Load_Burst 0x62
define Lift_Config 0x63
define Raw_Data_Burst 0x64
define LiftCutoff_Tune2 0x65
//Set this to what pin your "INT0" hardware interrupt feature is on
define Motion_Interrupt_Pin 9
const int ncs = 10; //This is the SPI "slave select" pin that the sensor is hooked up to
byte initComplete=0; volatile int xydat[2]; volatile byte movementflag=0; byte testctr=0; unsigned long currTime; unsigned long timer; unsigned long pollTimer;
//Be sure to add the SROM file into this sketch via "Sketch->Add File" extern const unsigned short firmware_length; extern const unsigned char firmware_data[];
void setup() { Serial.begin(9600);
pinMode (ncs, OUTPUT);
pinMode(Motion_Interrupt_Pin, INPUT); digitalWrite(Motion_Interrupt_Pin, HIGH); attachInterrupt(9, UpdatePointer, FALLING);
SPI.begin(); SPI.setDataMode(SPI_MODE3); SPI.setBitOrder(MSBFIRST); //SPI.setClockDivider(4);
performStartup();
delay(5000);
dispRegisters(); initComplete=9;
}
void adns_com_begin(){ digitalWrite(ncs, LOW); }
void adns_com_end(){ digitalWrite(ncs, HIGH); }
byte adns_read_reg(byte reg_addr){ adns_com_begin();
// send adress of the register, with MSBit = 0 to indicate it's a read SPI.transfer(reg_addr & 0x7f ); delayMicroseconds(100); // tSRAD // read data byte data = SPI.transfer(0);
delayMicroseconds(1); // tSCLK-NCS for read operation is 120ns adns_com_end(); delayMicroseconds(19); // tSRW/tSRR (=20us) minus tSCLK-NCS
return data; }
void adns_write_reg(byte reg_addr, byte data){ adns_com_begin();
//send adress of the register, with MSBit = 1 to indicate it's a write SPI.transfer(reg_addr | 0x80 ); //sent data SPI.transfer(data);
delayMicroseconds(20); // tSCLK-NCS for write operation adns_com_end(); delayMicroseconds(100); // tSWW/tSWR (=120us) minus tSCLK-NCS. Could be shortened, but is looks like a safe lower bound }
void adns_upload_firmware(){ // send the firmware to the chip, cf p.18 of the datasheet Serial.println("Uploading firmware...");
//Write 0 to Rest_En bit of Config2 register to disable Rest mode. adns_write_reg(Config2, 0x20);
// write 0x1d in SROM_enable reg for initializing adns_write_reg(SROM_Enable, 0x1d);
// wait for more than one frame period delay(10); // assume that the frame rate is as low as 100fps... even if it should never be that low
// write 0x18 to SROM_enable to start SROM download adns_write_reg(SROM_Enable, 0x18);
// write the SROM file (=firmware data) adns_com_begin(); SPI.transfer(SROM_Load_Burst | 0x80); // write burst destination adress delayMicroseconds(15);
// send all bytes of the firmware unsigned char c; for(int i = 0; i < firmware_length; i++){ c = (unsigned char)pgm_read_byte(firmware_data + i); SPI.transfer(c); delayMicroseconds(15); }
//Read the SROM_ID register to verify the ID before any other register reads or writes. adns_read_reg(SROM_ID);
//Write 0x00 to Config2 register for wired mouse or 0x20 for wireless mouse design. adns_write_reg(Config2, 0x00);
// set initial CPI resolution adns_write_reg(Config1, 0x15);
adns_com_end(); }
void performStartup(void){ adns_com_end(); // ensure that the serial port is reset adns_com_begin(); // ensure that the serial port is reset adns_com_end(); // ensure that the serial port is reset adns_write_reg(Power_Up_Reset, 0x5a); // force reset delay(50); // wait for it to reboot // read registers 0x02 to 0x06 (and discard the data) adns_read_reg(Motion); adns_read_reg(Delta_X_L); adns_read_reg(Delta_X_H); adns_read_reg(Delta_Y_L); adns_read_reg(Delta_Y_H); // upload the firmware adns_upload_firmware(); delay(10); Serial.println("Optical Chip Initialized"); }
void UpdatePointer(void){ if(initComplete==9){
//write 0x01 to Motion register and read from it to freeze the motion values and make them available adns_write_reg(Motion, 0x01); adns_read_reg(Motion); xydat[0] = (int)adns_read_reg(Delta_X_L); xydat[1] = (int)adns_read_reg(Delta_Y_L); movementflag=1; }
}
void dispRegisters(void){ int oreg[7] = { 0x00,0x3F,0x2A,0x02 }; char* oregname[] = { "Product_ID","Inverse_Product_ID","SROM_Version","Motion" }; byte regres;
digitalWrite(ncs,LOW);
int rctr=0; for(rctr=0; rctr<4; rctr++){ SPI.transfer(oreg[rctr]); delay(1); Serial.println("---"); Serial.println(oregname[rctr]); Serial.println(oreg[rctr],HEX); regres = SPI.transfer(0); Serial.println(regres,BIN); Serial.println(regres,HEX); delay(1); } digitalWrite(ncs,HIGH); }
int convTwosComp(int b){ //Convert from 2's complement if(b & 0x80){ b = -1 * ((b ^ 0xff) + 1); } return b; }
void loop() {
currTime = millis();
if(currTime > timer){ Serial.println(testctr++); timer = currTime + 2000; }
if(currTime > pollTimer){ UpdatePointer(); xydat[0] = convTwosComp(xydat[0]); xydat[1] = convTwosComp(xydat[1]); if(xydat[0] != 0 || xydat[1] != 0){ Serial.print("x = "); Serial.print(xydat[0]); Serial.print(" | "); Serial.print("y = "); Serial.println(xydat[1]); } pollTimer = currTime + 20; }
}
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mrjohnk/PMW3360DM-T2QU/issues/18#issuecomment-403695951, or mute the thread https://github.com/notifications/unsubscribe-auth/ABG0-f9dSWpkM1UVa4hCnC9Fg0y2C9iQks5uFCxEgaJpZM4VG72d .
Thanks for all your help. I've got motion now from the mouse on my computer, but it stops after only a few seconds. I commented out the print lines in the loop so those wouldn't be writing to memory. I'm also removing any values with an absolute value > 100 they seem to be bad and I'm getting a lot of them. They are causing the mouse to skip quite quite a lot. Any thoughts on the program stopping after a few seconds?
void loop() {
currTime = millis();
/*
//
if(currTime > timer){
//Serial.println(testctr++);
timer = currTime + 2000;
}
if(currTime > pollTimer){
UpdatePointer();
xydat[0] = convTwosComp(xydat[0]);
xydat[1] = convTwosComp(xydat[1]);
if(xydat[0] != 0 || xydat[1] != 0){
Serial.print("x = ");
Serial.print(xydat[0]);
Serial.print(" | ");
Serial.print("y = ");
Serial.println(xydat[1]);
}
pollTimer = currTime + 20;
Mouse.move(convTwosComp(xydat[0]),convTwosComp(xydat[1]));
}
*/
if(currTime > pollTimer){
UpdatePointer();
pollTimer = currTime + 20;
xydat[0] = convTwosComp(xydat[0]);
xydat[1] = convTwosComp(xydat[1]);
if (abs(xydat[0]) > 100){
xydat[0] = 0;
}
if (abs(xydat[1]) > 100){
xydat[1] = 0;
}
//Mouse.move(convTwosComp(xydat[0]),convTwosComp(xydat[1]));
Mouse.move(xydat[0],xydat[1]);
}
I imagine that the mouse move statement is being called to quickly. Maybe try moving that up inside the brace above it; right below the last print statement. Your can also adjust the pollTimer. It is set to check for movement every 20 milliseconds. Maybe try that every 100 milliseconds (10 times per second)
On Tue, Jul 10, 2018, 9:47 PM kixell notifications@github.com wrote:
Thanks for all your help. I've got motion now from the mouse on my computer, but it stops after only a few seconds. I commented out the print lines in the loop so those wouldn't be writing to memory. I'm also removing any values with an absolute value > 100 they seem to be bad and I'm getting a lot of them. They are causing the mouse to skip quite quite a lot. Any thoughts on the program stopping after a few seconds?
void loop() {
currTime = millis(); /* // if(currTime > timer){ //Serial.println(testctr++); timer = currTime + 2000; }
if(currTime > pollTimer){ UpdatePointer(); xydat[0] = convTwosComp(xydat[0]); xydat[1] = convTwosComp(xydat[1]); if(xydat[0] != 0 || xydat[1] != 0){ Serial.print("x = "); Serial.print(xydat[0]); Serial.print(" | "); Serial.print("y = "); Serial.println(xydat[1]); } pollTimer = currTime + 20; Mouse.move(convTwosComp(xydat[0]),convTwosComp(xydat[1])); } */ if(currTime > pollTimer){ UpdatePointer(); pollTimer = currTime + 20;
xydat[0] = convTwosComp(xydat[0]); xydat[1] = convTwosComp(xydat[1]);
if (abs(xydat[0]) > 100){ xydat[0] = 0; }
if (abs(xydat[1]) > 100){ xydat[1] = 0; }
//Mouse.move(convTwosComp(xydat[0]),convTwosComp(xydat[1])); Mouse.move(xydat[0],xydat[1]); }
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mrjohnk/PMW3360DM-T2QU/issues/18#issuecomment-404027661, or mute the thread https://github.com/notifications/unsubscribe-auth/ABG0-ZBFgAbArnq6hS4aQOn1CkAcaGejks5uFWdbgaJpZM4VG72d .
Thanks again for all your help. For some reason this is working with the #define Motion_Interrupt_Pin 9 but the wire is connected to 6.
I'm ok with that working as is but I have an additional question. Is it possible to change/set the DPI? Should I open a new issue for this question?
Yes, the CPI can be changed. I believe this is covered in the datasheet regarding the "configuration II" register. You simply write a new a hex value to this register.
On Tue, Jul 17, 2018, 9:33 AM kixell notifications@github.com wrote:
Thanks again for all your help. For some reason this is working with the
define Motion_Interrupt_Pin 9 but the wire is connected to 6.
I'm ok with that working as is but I have an additional question. Is it possible to change/set the DPI? Should I open a new issue for this question?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mrjohnk/PMW3360DM-T2QU/issues/18#issuecomment-405603824, or mute the thread https://github.com/notifications/unsubscribe-auth/ABG0-RjIMlZoY1tAyl4_JU8cWM1IQesKks5uHfW_gaJpZM4VG72d .
I'm not sure this is correct but this is how I have this wired currently.