Reference firmware for PixArt's PAT9130EW 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.

Guide for Any Platform

This Wiki page provides a detailed guide on how to setup and operate PixArt's PAT9130 sensor with any mBed-supported microcontroller.



  • 1.) PC with Windows Operating System
  • 2.) PAT9130EW Evaluation Board
  • 3.) Any mBed-Supported Microcontroller & Associated Cables
    • (Cables are often USB-A male to USB-B male or USB-A male to micro-USB male)
  • 4.) Standard Male Pin Headers
  • 5.) Jumper Cables
  • 6.) Soldering Station
    • NOTE: PC and soldering station not included in image.
      • You will need to solder the pin headers to the evaluation board similar to the following image:

Importing Code

First, we need to import code into the microcontroller to start talking to the sensor. For the firmware code, please visit this product's components page here:

  • 1.) Login/create an mBed account.

  • 2.) Import the reference firmware into mBed's online compiler using the "Import program" button. You can find this in the link above. /media/uploads/PixArtVY/import_program_Hg4D0ZL.jpg

  • 3.) When importing the program, make sure you import it as a program and not a library. /media/uploads/PixArtVY/importing.jpg

  • 4.) Make sure the selected platform is the platform that you are using. /media/uploads/PixArtVY/platform.jpg

  • 5.) Make sure your microcontroller is plugged into your PC. It should show up as a separate drive similar to the (C:) drive. Then, you can compile the program and save the HEX file into your microcontroller. 800

    • NOTE: If you suspect your code did not import properly, please try unplugging the device, plugging it back in, and then re-compiling and saving the code into the device.


Please refer to the images and notes below for details on how to connect your hardware.
The above images show how the sensor connects to the Nordic nRF52-DK as a template. To connect it to your own microcontroller of choice, please follow these steps:

  • 1.) First make sure you have chosen the platform that you have. See step 4 in the "Importing Code" section.
  • 2.) Assign any GPIO pins on your microcontroller to the SPI pins you want.
    • Change "static SPI spi(p23, p24, p25);" to "static SPI spi( [any_pin], [any_pin], [any_pin] );"
      • You will also need to change "static DigitalOut cs(p22);" to "static DigitalOut cs( [any_pin] );"
  • 3.) With pins properly assigned, simply use jumper cables to connect them to the corresponding pins on the PAT9130EW evaluation board.

    ===Other notes:===
  • VDD on the PAT9130EW evaluation board connects to any 3.3V pin (usually VDD) on your microcontroller.
  • GND on the PAT9130EW evaluation board connects to any GND pin on your microcontroller.
  • NC = No connection.
    • NOTE: You will need a 2-to-1 connection because this sensor uses 3-Wire SPI (data pin "SDIO" on the evaluation board is bi-directional). The SDIO pin on the evaluation board needs to connect to BOTH the MISO and MOSI pin that have you assigned to your microcontroller.

Functional Test

  • 2.) Open Tera Term and go to File > New Connection or use the hotkey "Alt + N". Select "Serial" and choose the COM port corresponding to your microcontroller. Then click on "OK". /media/uploads/PixArtVY/tera_term_serial.jpg

  • 3.) Go to Setup > Serial Port and set the baud rate to 115200. Then click on "OK".

  • 4.) Go to Setup > Terminal and change "Receive" from "CR" to "LF". Then click on "OK".

  • 5.) With the hardware wired up properly, the firmware loaded into the microcontroller, and the terminal emulator set up, we should now be able to see the sensor working. If you move your finger in front of the sensor (remember the working distance is 5mm to 60mm for glossy surfaces and 20mm to 40mm for surfaces like white paper), you should see outputs on the terminal: /media/uploads/PixArtVY/tera_term_output.jpg
    • "deltaX" and "deltaY" show the number of counts detected per report.
    • "X-axis Counts" and "Y-axis Counts" show the total number of counts recorded throughout runtime.

Thank you for choosing PixArt! If you have any questions, feel free to contact us at:

All wikipages