Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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@1:10365086d44e, 2018-07-18 (annotated)
- Committer:
- PixArtVY
- Date:
- Wed Jul 18 18:37:21 2018 +0000
- Revision:
- 1:10365086d44e
- Parent:
- 0:c00f2464eee3
Added Apache License notice.
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 | 1:10365086d44e | 2 | // Version: 1.1 |
| PixArtVY | 1:10365086d44e | 3 | // Latest Revision Date: 18 July 2018 |
| PixArtVY | 0:c00f2464eee3 | 4 | // By PixArt Imaging Inc. |
| PixArtVY | 0:c00f2464eee3 | 5 | // Primary Engineer: Vincent Yeh (PixArt USA) |
| PixArtVY | 0:c00f2464eee3 | 6 | |
| PixArtVY | 1:10365086d44e | 7 | // Copyright [2018] [Vincent Yeh] |
| PixArtVY | 1:10365086d44e | 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 | 1:10365086d44e | 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| PixArtVY | 1:10365086d44e | 10 | |
| PixArtVY | 1:10365086d44e | 11 | |
| PixArtVY | 0:c00f2464eee3 | 12 | /* |
| PixArtVY | 0:c00f2464eee3 | 13 | //======================= |
| PixArtVY | 0:c00f2464eee3 | 14 | //Revision History |
| PixArtVY | 0:c00f2464eee3 | 15 | //======================= |
| PixArtVY | 1:10365086d44e | 16 | Version 1.1 -- 18 July 2018 |
| PixArtVY | 1:10365086d44e | 17 | Added apache license notice. |
| PixArtVY | 1:10365086d44e | 18 | |
| PixArtVY | 0:c00f2464eee3 | 19 | Version 1.0 -- 13 Mar. 2018 |
| PixArtVY | 0:c00f2464eee3 | 20 | First release. |
| PixArtVY | 0:c00f2464eee3 | 21 | */ |
| PixArtVY | 0:c00f2464eee3 | 22 | |
| PixArtVY | 0:c00f2464eee3 | 23 | #include "mbed.h" |
| PixArtVY | 0:c00f2464eee3 | 24 | #include "SPIcommFunctions.h" |
| PixArtVY | 0:c00f2464eee3 | 25 | |
| PixArtVY | 0:c00f2464eee3 | 26 | int main() |
| PixArtVY | 0:c00f2464eee3 | 27 | { |
| PixArtVY | 0:c00f2464eee3 | 28 | pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. |
| PixArtVY | 0:c00f2464eee3 | 29 | |
| PixArtVY | 0:c00f2464eee3 | 30 | spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge. |
| PixArtVY | 0:c00f2464eee3 | 31 | spi.frequency(1000000); // Set frequency for SPI communication. |
| PixArtVY | 0:c00f2464eee3 | 32 | cs = 1; // Initialize chip select as inactive. |
| PixArtVY | 0:c00f2464eee3 | 33 | |
| PixArtVY | 0:c00f2464eee3 | 34 | pc.printf("Program START\n\r"); |
| PixArtVY | 0:c00f2464eee3 | 35 | |
| PixArtVY | 0:c00f2464eee3 | 36 | pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. |
| PixArtVY | 0:c00f2464eee3 | 37 | if(readRegister(0x00) != 0x49) |
| PixArtVY | 0:c00f2464eee3 | 38 | { |
| PixArtVY | 0:c00f2464eee3 | 39 | pc.printf("Communication protocol error! Terminating program.\n\r"); |
| PixArtVY | 0:c00f2464eee3 | 40 | return 0; |
| PixArtVY | 0:c00f2464eee3 | 41 | } |
| PixArtVY | 0:c00f2464eee3 | 42 | |
| PixArtVY | 0:c00f2464eee3 | 43 | initializeSensor(); |
| PixArtVY | 0:c00f2464eee3 | 44 | |
| PixArtVY | 0:c00f2464eee3 | 45 | while(1) |
| PixArtVY | 0:c00f2464eee3 | 46 | { |
| PixArtVY | 0:c00f2464eee3 | 47 | //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 | 48 | |
| PixArtVY | 0:c00f2464eee3 | 49 | if(readRegister(0x02) & 0x80) |
| PixArtVY | 0:c00f2464eee3 | 50 | { |
| PixArtVY | 0:c00f2464eee3 | 51 | grabData(); |
| PixArtVY | 0:c00f2464eee3 | 52 | printData(); |
| PixArtVY | 0:c00f2464eee3 | 53 | } |
| PixArtVY | 0:c00f2464eee3 | 54 | } |
| PixArtVY | 0:c00f2464eee3 | 55 | } |
PMW3901MB | Far-Field Optical Motion Tracking Sensor