Initial Release of Program for PAT9125 OTS on L476RG Platform

Dependencies:   mbed

Fork of PAT9125_OTS_L476RG by PixArt

This section highlights the setup and operating guide to integrating PAT9125EL with the Nucleo L476RG.

Setup

Hardware:

  • 1. PC with Windows Operating System
  • 2. Nucleo L476RG Dev Kit Board from ST
  • 3. PAT9125EL Arduino Enabled Board
  • 4. USB Cable (one end with miniUSB)

Connection:

Please connect the board as show below.

/media/uploads/pixus_mbed/connection_with_labeling.jpg

Supplying Power

Connect the one end of the USB to the PC USB and the other to the Nucleo L476RG miniUSB as shown in the figure below.

/media/uploads/pixus_mbed/connection_with_power_led_red.jpg

I am assuming that you already know and are able to download the code at this point. Once programmed with the latest compiled .bin file, the LED should turn Green, as illustrated below.

/media/uploads/pixus_mbed/connection_with_power_led_green.jpg

Next, we will test to see if the sensor (PAT9125EL) is indeed functional, and able to display the rotational displacement, on the on-board LCD Display.

While you rotate the Rotational Shaft clockwise, you should see an increment in the digital count for "SHAFT" on the LCD Display, also showing "Up" as you rotate the shaft in the clockwise direction.

While you rotate the Rotational Shaft counter-clockwise, you should see decrease in the digital counts under "SHAFT"on the LCD Display, also showing "Down" as you rotate the shaft in the counter-clockwise direction.

While you push the shaft inward, you should see an increment in digital counts under SPRING. While pushed inward, it will show as "Pre" for Press on the LCD Display.

Conversely, once you release the shaft, the LCD Display should show "Rel" for "Release".

To RESET the digital count, press on the button on the bottom left side of the board. This should reset the digital count on "SHAFT" and "SPRING" to "+0000".

Have fun with this and should you have any questions, please do not hesitate to contact us.

Committer:
pixus_mbed
Date:
Fri Oct 20 01:52:15 2017 +0000
Branch:
Branch_nRF51
Revision:
11:29053223499c
Parent:
2:4fb710ae08dd
For FRDM-K64F

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pixus_mbed 0:411244c71423 1 /* mbed Microcontroller Library
pixus_mbed 0:411244c71423 2 * Copyright (c) 2006-2013 ARM Limited
pixus_mbed 0:411244c71423 3 *
pixus_mbed 0:411244c71423 4 * Licensed under the Apache License, Version 2.0 (the "License");
pixus_mbed 0:411244c71423 5 * you may not use this file except in compliance with the License.
pixus_mbed 0:411244c71423 6 * You may obtain a copy of the License at
pixus_mbed 0:411244c71423 7 *
pixus_mbed 0:411244c71423 8 * http://www.apache.org/licenses/LICENSE-2.0
pixus_mbed 0:411244c71423 9 *
pixus_mbed 0:411244c71423 10 * Unless required by applicable law or agreed to in writing, software
pixus_mbed 0:411244c71423 11 * distributed under the License is distributed on an "AS IS" BASIS,
pixus_mbed 0:411244c71423 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
pixus_mbed 0:411244c71423 13 * See the License for the specific language governing permissions and
pixus_mbed 0:411244c71423 14 * limitations under the License.
pixus_mbed 0:411244c71423 15 */
pixus_mbed 0:411244c71423 16
pixus_mbed 0:411244c71423 17 #include "mbed.h"
pixus_mbed 0:411244c71423 18 #include "pixart_lcm.h"
pixus_mbed 0:411244c71423 19 #include "pat9125_i2c.h"
pixus_mbed 0:411244c71423 20 #include "pat9125_mbed.h"
pixus_mbed 0:411244c71423 21
pixus_mbed 0:411244c71423 22 pat9125_mbed_state_s g_pat9125_mbed_state ;
pixus_mbed 0:411244c71423 23 pat9125_mbed *gp_pat9125_mbed ;
pixus_mbed 0:411244c71423 24 pixart_lcm *gp_pixart_lcm ;
pixus_mbed 0:411244c71423 25
pixus_mbed 0:411244c71423 26
pixus_mbed 0:411244c71423 27 Serial pc(USBTX, USBRX);
pixus_mbed 2:4fb710ae08dd 28 #define I2C_SDA_PIN I2C_SDA
pixus_mbed 2:4fb710ae08dd 29 #define I2C_SCL_PIN I2C_SCL
pixus_mbed 0:411244c71423 30 pat9125_i2c *gp_pat9125_i2c;//(I2C_SDA0, I2C_SCL0);
pixus_mbed 2:4fb710ae08dd 31 SPI spi(D11, NC, D13);
pixus_mbed 0:411244c71423 32
pixus_mbed 2:4fb710ae08dd 33 DigitalOut PIN_LCM_CSB(D10);
pixus_mbed 2:4fb710ae08dd 34 DigitalOut PIN_LCM_RSTB(D8);
pixus_mbed 2:4fb710ae08dd 35 DigitalOut PIN_LCM_RS(D9);
pixus_mbed 0:411244c71423 36
pixus_mbed 2:4fb710ae08dd 37 InterruptIn PIN_SEN_MOTION(D3);
pixus_mbed 2:4fb710ae08dd 38 DigitalIn motionDummy(D3, PullUp);
pixus_mbed 2:4fb710ae08dd 39 DigitalIn PIN_BTN_L(A0);
pixus_mbed 2:4fb710ae08dd 40 DigitalIn PIN_BTN_R(A1);
pixus_mbed 0:411244c71423 41
pixus_mbed 2:4fb710ae08dd 42 DigitalOut PIN_GLED(D2);
pixus_mbed 2:4fb710ae08dd 43 DigitalOut PIN_RLED(D5);
pixus_mbed 0:411244c71423 44 #define I2C_ADDRESS 0x73
pixus_mbed 0:411244c71423 45
pixus_mbed 0:411244c71423 46 //-----------------------------------------------------------------------
pixus_mbed 0:411244c71423 47 int main(void)
pixus_mbed 0:411244c71423 48 {
pixus_mbed 0:411244c71423 49 char addr = 0;
pixus_mbed 0:411244c71423 50 char data ;
pixus_mbed 11:29053223499c 51 pc.set_flow_control(SerialBase::Disabled) ;
pixus_mbed 0:411244c71423 52 pc.baud(115200);
pixus_mbed 0:411244c71423 53 pc.printf("---------- Pixart PAT9125 Demo\n");
pixus_mbed 0:411244c71423 54
pixus_mbed 0:411244c71423 55 // +++++++ LCM Initialization +++++++ //
pixus_mbed 0:411244c71423 56 // Chip must be deselected
pixus_mbed 0:411244c71423 57 PIN_LCM_CSB = 1 ;
pixus_mbed 0:411244c71423 58
pixus_mbed 0:411244c71423 59 // Setup the spi for 8 bit data, high steady state clock,
pixus_mbed 0:411244c71423 60 // second edge capture, with a 1MHz clock rate
pixus_mbed 0:411244c71423 61 spi.format(8,3);
pixus_mbed 0:411244c71423 62 spi.frequency(1000000);
pixus_mbed 0:411244c71423 63 gp_pixart_lcm = new pixart_lcm(&spi, &PIN_LCM_CSB, &PIN_LCM_RSTB, &PIN_LCM_RS) ;
pixus_mbed 0:411244c71423 64 // ------- LCM Initialization ------- //
pixus_mbed 0:411244c71423 65
pixus_mbed 0:411244c71423 66 // +++++++ PAT9125 Initialization +++++++ //
pixus_mbed 1:73967d37f487 67 gp_pat9125_i2c = new pat9125_i2c(I2C_SDA_PIN, I2C_SCL_PIN);
pixus_mbed 0:411244c71423 68 gp_pat9125_i2c->frequency(400000);
pixus_mbed 0:411244c71423 69 g_pat9125_mbed_state.p_i2c = gp_pat9125_i2c;
pixus_mbed 0:411244c71423 70 g_pat9125_mbed_state.p_pc = &pc;
pixus_mbed 0:411244c71423 71 g_pat9125_mbed_state.pBTN_L = &PIN_BTN_L ;
pixus_mbed 0:411244c71423 72 g_pat9125_mbed_state.pBTN_R = &PIN_BTN_R ;
pixus_mbed 0:411244c71423 73 g_pat9125_mbed_state.pINT = &PIN_SEN_MOTION;
pixus_mbed 0:411244c71423 74 g_pat9125_mbed_state.pRLED = &PIN_RLED;
pixus_mbed 0:411244c71423 75 g_pat9125_mbed_state.pGLED = &PIN_GLED;
pixus_mbed 0:411244c71423 76 g_pat9125_mbed_state.pLCM = gp_pixart_lcm;
pixus_mbed 0:411244c71423 77 g_pat9125_mbed_state.slave_id = (I2C_ADDRESS << 1);
pixus_mbed 0:411244c71423 78 g_pat9125_mbed_state.sen_status = 0;
pixus_mbed 0:411244c71423 79
pixus_mbed 0:411244c71423 80 gp_pat9125_mbed = new pat9125_mbed(&g_pat9125_mbed_state) ;
pixus_mbed 0:411244c71423 81 gp_pixart_lcm->LCM_DisplayString_Boot(g_pat9125_mbed_state.sen_status);
pixus_mbed 0:411244c71423 82
pixus_mbed 0:411244c71423 83 if(g_pat9125_mbed_state.sen_status == true)
pixus_mbed 0:411244c71423 84 {
pixus_mbed 0:411244c71423 85 pc.printf("Initial Sensor ... Done\n");
pixus_mbed 0:411244c71423 86 }
pixus_mbed 0:411244c71423 87 else
pixus_mbed 0:411244c71423 88 {
pixus_mbed 0:411244c71423 89 pc.printf("Initial Sensor ... Fail\n");
pixus_mbed 0:411244c71423 90 }
pixus_mbed 0:411244c71423 91 while(true)
pixus_mbed 0:411244c71423 92 {
pixus_mbed 0:411244c71423 93 gp_pat9125_mbed->task();
pixus_mbed 0:411244c71423 94 }
pixus_mbed 0:411244c71423 95 }