Reference firmware for PixArt's PAA5101 sensor and evaluation board. "Hello World" and "Library" contain the exact same files. Please import just one of the two into your mBed compiler as a new program and not as a library.
Welcome to the code repository for PixArt's PAA5101 sensor and evaluation board.
For general information about this product, please visit this product's components page here:
https://os.mbed.com/components/PAA5101-Floor-Tracking-Sensor-with-Wide-/
For guides and tips on how to setup and evaluate the PAA5101 sensor with the Nordic nRF52-DK microcontroller using this reference code, please visit this guide:
https://os.mbed.com/teams/PixArt/code/5101_referenceCode/wiki/Guide-for-nRF52-DK-Platform
For guides and tips on how to setup and evaluate the PAA5101 sensor with any microcontroller using this reference code, please visit this guide:
https://os.mbed.com/teams/PixArt/code/5101_referenceCode/wiki/Guide-for-Any-Platform
main.cpp
- Committer:
- PixArtVY
- Date:
- 2018-03-19
- Revision:
- 0:2c144b6813d1
- Child:
- 2:045cc9f995ae
File content as of revision 0:2c144b6813d1:
// PAA5101 Optical Tracking Minuature Chip reference code. // Version: 1.0 // Latest Revision Date: 29 Jan. 2018 // By PixArt Imaging Inc. // Primary Engineer: Vincent Yeh (PixArt USA) /* //======================= //Revision History //======================= Version 1.0 -- ???????????????????????????????????? First release. */ #include "mbed.h" #include "registerArrays.h" #include "SPIcommFunctions.h" int main() { pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge. spi.frequency(10000000); // Set frequency for SPI communication. cs = 1; // Initialize chip-select pin to be HIGH (inactive). pc.printf("Program START\n\r"); writeRegister(0x7F, 0x00); //Reset to bank 0 before initializing again pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. if(readRegister(0x00) != 0x31) { pc.printf("Communication protocol error! Terminating program.\n\r"); return 0; } writeRegister(0x06, 0x80); //Resets the chip now that we have verified that the communication works. wait_ms(1); //Wait at least 1 millisecond after resetting for timing. pc.printf("ID Check #2: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly after the reset. if(readRegister(0x00) != 0x31) { pc.printf("Communication protocol error! Terminating program.\n\r"); return 0; } writeRegister(0x09, 0x5A); //Disables write-protect writeRegister(0x51, 0x06); //Sets laser diode power. Value should be <= 6 load(initialize, initialize_size); //Loads initial register settings writeRegister(0x5D, 0x3E); //Unlisted register. Internal recommendation... wait_ms(10); writeRegister(0x5D, 0x3F); //Unlisted register. Internal recommendation... load(modeLaser, modeLaser_size); //Goes into laser mode which is the default mode (not LED) mode = 0; //This variable tracks if we are in laser mode or LED mode. 0 = laser, 1 = LED LDP = 0; //Change GPIO pin to the laser diode to be LOW to activate the laser. writeRegister(0x09, 0x00); //Enables write-protect while(1) //After all setup/initialization is done, we can loop for interrupts and mode detection. { checkMode(); //Checks image quality and switches to laser or LED mode accordingly. if(imageQualityOK && readRegister(0x02) & 0x80) //If motion bit (bit 7 of register 0x02) is 1, movement has been detected. Also checks if imageQuality is good enough. { grabData(); //Grabs data into variables deltaX and deltaY. printData(); //Prints deltaX and deltaY, but only if they have changed from their previous values. } } }