Reference firmware for PixArt's PMW3901MB 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 PMW3901MB sensor and evaluation board.
For general information about this product, please visit this product's components page here:
https://os.mbed.com/components/PMW3901MB-Far-Field-Optical-Motion-Track/
For guides and tips on how to setup and evaluate the PMW3901MB sensor with the Nordic nRF52-DK microcontroller using this reference code, please visit this guide:
https://os.mbed.com/teams/PixArt/code/3901_referenceFirmware/wiki/Guide-for-nRF52-DK-Platform
For guides and tips on how to setup and evaluate the PMW3901MB sensor with any microcontroller using this reference code, please visit this guide:
https://os.mbed.com/teams/PixArt/code/3901_referenceFirmware/wiki/Guide-for-Any-Platform
main.cpp@0:c00f2464eee3, 2018-03-14 (annotated)
- Committer:
- PixArtVY
- Date:
- Wed Mar 14 21:22:43 2018 +0000
- Revision:
- 0:c00f2464eee3
- Child:
- 1:10365086d44e
First release.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PixArtVY | 0:c00f2464eee3 | 1 | // PMW3901MB: Optical Motion Tracking Chip reference code. |
PixArtVY | 0:c00f2464eee3 | 2 | // Version: 1.0 |
PixArtVY | 0:c00f2464eee3 | 3 | // Latest Revision Date: 13 Mar. 2018 |
PixArtVY | 0:c00f2464eee3 | 4 | // By PixArt Imaging Inc. |
PixArtVY | 0:c00f2464eee3 | 5 | // Primary Engineer: Vincent Yeh (PixArt USA) |
PixArtVY | 0:c00f2464eee3 | 6 | |
PixArtVY | 0:c00f2464eee3 | 7 | /* |
PixArtVY | 0:c00f2464eee3 | 8 | //======================= |
PixArtVY | 0:c00f2464eee3 | 9 | //Revision History |
PixArtVY | 0:c00f2464eee3 | 10 | //======================= |
PixArtVY | 0:c00f2464eee3 | 11 | Version 1.0 -- 13 Mar. 2018 |
PixArtVY | 0:c00f2464eee3 | 12 | First release. |
PixArtVY | 0:c00f2464eee3 | 13 | */ |
PixArtVY | 0:c00f2464eee3 | 14 | |
PixArtVY | 0:c00f2464eee3 | 15 | #include "mbed.h" |
PixArtVY | 0:c00f2464eee3 | 16 | #include "SPIcommFunctions.h" |
PixArtVY | 0:c00f2464eee3 | 17 | |
PixArtVY | 0:c00f2464eee3 | 18 | int main() |
PixArtVY | 0:c00f2464eee3 | 19 | { |
PixArtVY | 0:c00f2464eee3 | 20 | pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. |
PixArtVY | 0:c00f2464eee3 | 21 | |
PixArtVY | 0:c00f2464eee3 | 22 | spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge. |
PixArtVY | 0:c00f2464eee3 | 23 | spi.frequency(1000000); // Set frequency for SPI communication. |
PixArtVY | 0:c00f2464eee3 | 24 | cs = 1; // Initialize chip select as inactive. |
PixArtVY | 0:c00f2464eee3 | 25 | |
PixArtVY | 0:c00f2464eee3 | 26 | pc.printf("Program START\n\r"); |
PixArtVY | 0:c00f2464eee3 | 27 | |
PixArtVY | 0:c00f2464eee3 | 28 | pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. |
PixArtVY | 0:c00f2464eee3 | 29 | if(readRegister(0x00) != 0x49) |
PixArtVY | 0:c00f2464eee3 | 30 | { |
PixArtVY | 0:c00f2464eee3 | 31 | pc.printf("Communication protocol error! Terminating program.\n\r"); |
PixArtVY | 0:c00f2464eee3 | 32 | return 0; |
PixArtVY | 0:c00f2464eee3 | 33 | } |
PixArtVY | 0:c00f2464eee3 | 34 | |
PixArtVY | 0:c00f2464eee3 | 35 | initializeSensor(); |
PixArtVY | 0:c00f2464eee3 | 36 | |
PixArtVY | 0:c00f2464eee3 | 37 | while(1) |
PixArtVY | 0:c00f2464eee3 | 38 | { |
PixArtVY | 0:c00f2464eee3 | 39 | //pc.printf("MOTION bit: %2X\n\r", (readRegister(0x02) & 0x80) >> 7); //Prints motion bit for debugging. 1 = motion detected. 0 = no motion detected. |
PixArtVY | 0:c00f2464eee3 | 40 | |
PixArtVY | 0:c00f2464eee3 | 41 | if(readRegister(0x02) & 0x80) |
PixArtVY | 0:c00f2464eee3 | 42 | { |
PixArtVY | 0:c00f2464eee3 | 43 | grabData(); |
PixArtVY | 0:c00f2464eee3 | 44 | printData(); |
PixArtVY | 0:c00f2464eee3 | 45 | } |
PixArtVY | 0:c00f2464eee3 | 46 | } |
PixArtVY | 0:c00f2464eee3 | 47 | } |