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

Committer:
PixArtVY
Date:
Wed Jul 18 18:36:47 2018 +0000
Revision:
5:e6cc13f2fc8b
Parent:
4:234a8616c0a6
Added Apache License notice.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
PixArtVY 0:2c144b6813d1 1 // PAA5101 Optical Tracking Minuature Chip reference code.
PixArtVY 5:e6cc13f2fc8b 2 // Version: 1.11
PixArtVY 5:e6cc13f2fc8b 3 // Latest Revision Date: 18 July 2018
PixArtVY 0:2c144b6813d1 4 // By PixArt Imaging Inc.
PixArtVY 0:2c144b6813d1 5 // Primary Engineer: Vincent Yeh (PixArt USA)
PixArtVY 0:2c144b6813d1 6
PixArtVY 5:e6cc13f2fc8b 7 // Copyright [2018] [Vincent Yeh]
PixArtVY 5:e6cc13f2fc8b 8 // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:
PixArtVY 5:e6cc13f2fc8b 9 // http://www.apache.org/licenses/LICENSE-2.0
PixArtVY 5:e6cc13f2fc8b 10
PixArtVY 5:e6cc13f2fc8b 11
PixArtVY 0:2c144b6813d1 12 /*
PixArtVY 0:2c144b6813d1 13 //=======================
PixArtVY 0:2c144b6813d1 14 //Revision History
PixArtVY 0:2c144b6813d1 15 //=======================
PixArtVY 5:e6cc13f2fc8b 16 Version 1.11 -- 18 July 2018
PixArtVY 5:e6cc13f2fc8b 17 Added apache license notice.
PixArtVY 5:e6cc13f2fc8b 18
PixArtVY 5:e6cc13f2fc8b 19 Version 1.1
PixArtVY 5:e6cc13f2fc8b 20 Fixed SPI frequency from 10MHz to 2MHz.
PixArtVY 5:e6cc13f2fc8b 21
PixArtVY 5:e6cc13f2fc8b 22 Version 1.0
PixArtVY 5:e6cc13f2fc8b 23 First release.
PixArtVY 0:2c144b6813d1 24 */
PixArtVY 0:2c144b6813d1 25
PixArtVY 0:2c144b6813d1 26 #include "mbed.h"
PixArtVY 0:2c144b6813d1 27 #include "registerArrays.h"
PixArtVY 0:2c144b6813d1 28 #include "SPIcommFunctions.h"
PixArtVY 0:2c144b6813d1 29
PixArtVY 0:2c144b6813d1 30 int main()
PixArtVY 0:2c144b6813d1 31 {
PixArtVY 0:2c144b6813d1 32 pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value.
PixArtVY 0:2c144b6813d1 33
PixArtVY 0:2c144b6813d1 34 spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge.
PixArtVY 3:1d5c2956f415 35 spi.frequency(2000000); // Set frequency for SPI communication.
PixArtVY 0:2c144b6813d1 36 cs = 1; // Initialize chip-select pin to be HIGH (inactive).
PixArtVY 0:2c144b6813d1 37
PixArtVY 0:2c144b6813d1 38 pc.printf("Program START\n\r");
PixArtVY 0:2c144b6813d1 39
PixArtVY 0:2c144b6813d1 40 writeRegister(0x7F, 0x00); //Reset to bank 0 before initializing again
PixArtVY 0:2c144b6813d1 41
PixArtVY 0:2c144b6813d1 42 pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly.
PixArtVY 0:2c144b6813d1 43 if(readRegister(0x00) != 0x31)
PixArtVY 0:2c144b6813d1 44 {
PixArtVY 0:2c144b6813d1 45 pc.printf("Communication protocol error! Terminating program.\n\r");
PixArtVY 0:2c144b6813d1 46 return 0;
PixArtVY 0:2c144b6813d1 47 }
PixArtVY 0:2c144b6813d1 48
PixArtVY 0:2c144b6813d1 49 writeRegister(0x06, 0x80); //Resets the chip now that we have verified that the communication works.
PixArtVY 0:2c144b6813d1 50 wait_ms(1); //Wait at least 1 millisecond after resetting for timing.
PixArtVY 0:2c144b6813d1 51
PixArtVY 0:2c144b6813d1 52 pc.printf("ID Check #2: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly after the reset.
PixArtVY 0:2c144b6813d1 53 if(readRegister(0x00) != 0x31)
PixArtVY 0:2c144b6813d1 54 {
PixArtVY 0:2c144b6813d1 55 pc.printf("Communication protocol error! Terminating program.\n\r");
PixArtVY 0:2c144b6813d1 56 return 0;
PixArtVY 0:2c144b6813d1 57 }
PixArtVY 0:2c144b6813d1 58
PixArtVY 0:2c144b6813d1 59 writeRegister(0x09, 0x5A); //Disables write-protect
PixArtVY 0:2c144b6813d1 60 writeRegister(0x51, 0x06); //Sets laser diode power. Value should be <= 6
PixArtVY 0:2c144b6813d1 61
PixArtVY 0:2c144b6813d1 62 load(initialize, initialize_size); //Loads initial register settings
PixArtVY 0:2c144b6813d1 63
PixArtVY 0:2c144b6813d1 64 writeRegister(0x5D, 0x3E); //Unlisted register. Internal recommendation...
PixArtVY 0:2c144b6813d1 65 wait_ms(10);
PixArtVY 0:2c144b6813d1 66 writeRegister(0x5D, 0x3F); //Unlisted register. Internal recommendation...
PixArtVY 0:2c144b6813d1 67
PixArtVY 0:2c144b6813d1 68 load(modeLaser, modeLaser_size); //Goes into laser mode which is the default mode (not LED)
PixArtVY 0:2c144b6813d1 69 mode = 0; //This variable tracks if we are in laser mode or LED mode. 0 = laser, 1 = LED
PixArtVY 0:2c144b6813d1 70 LDP = 0; //Change GPIO pin to the laser diode to be LOW to activate the laser.
PixArtVY 0:2c144b6813d1 71
PixArtVY 0:2c144b6813d1 72 writeRegister(0x09, 0x00); //Enables write-protect
PixArtVY 0:2c144b6813d1 73
PixArtVY 0:2c144b6813d1 74
PixArtVY 0:2c144b6813d1 75
PixArtVY 0:2c144b6813d1 76 while(1) //After all setup/initialization is done, we can loop for interrupts and mode detection.
PixArtVY 0:2c144b6813d1 77 {
PixArtVY 0:2c144b6813d1 78 checkMode(); //Checks image quality and switches to laser or LED mode accordingly.
PixArtVY 0:2c144b6813d1 79
PixArtVY 2:045cc9f995ae 80 if(readRegister(0x02) & 0x80) //If motion bit (bit 7 of register 0x02) is 1, movement has been detected.
PixArtVY 0:2c144b6813d1 81 {
PixArtVY 0:2c144b6813d1 82 grabData(); //Grabs data into variables deltaX and deltaY.
PixArtVY 0:2c144b6813d1 83 printData(); //Prints deltaX and deltaY, but only if they have changed from their previous values.
PixArtVY 0:2c144b6813d1 84 }
PixArtVY 0:2c144b6813d1 85 }
PixArtVY 0:2c144b6813d1 86 }