![](/media/cache/group/PixArt_Logo_150x75.png.50x50_q85.png)
Initial Release of Program for PAT9125 OTS on L476RG Platform
Dependencies: mbed
Fork of PAT9125_OTS_L476RG by
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.
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.
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.
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.
main.cpp
- Committer:
- pixus_mbed
- Date:
- 2018-02-21
- Revision:
- 22:5496743b160b
- Parent:
- 18:27c8c623f5d4
File content as of revision 22:5496743b160b:
/* mbed Microcontroller Library * Copyright (c) 2006-2013 ARM Limited * * 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 * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "mbed.h" #include "pixart_lcm.h" #include "pat9125_i2c.h" #include "pat9125_mbed.h" pat9125_mbed_state_s g_pat9125_mbed_state ; pat9125_mbed *gp_pat9125_mbed ; pixart_lcm *gp_pixart_lcm = NULL; SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); Serial pc(USBTX, USBRX); #define I2C_SDA_PIN I2C_SDA #define I2C_SCL_PIN I2C_SCL //DigitalIn sdaDummy(I2C_SDA_PIN, PullUp); //DigitalIn sclDummy(I2C_SCL_PIN, PullUp); pat9125_i2c *gp_pat9125_i2c;//(I2C_SDA0, I2C_SCL0); DigitalOut PIN_LCM_CSB(PB_6); DigitalOut PIN_LCM_RSTB(PA_9); DigitalOut PIN_LCM_RS(PC_7); InterruptIn PIN_SEN_MOTION(PB_3); DigitalIn motionDummy(PB_3, PullUp); DigitalIn PIN_BTN_L(PA_0); DigitalIn BTN_L_Dummy(PA_0, PullUp); DigitalIn PIN_BTN_R(PA_1); DigitalIn BTN_R_Dummy(PA_1, PullUp); DigitalOut PIN_GLED(PA_10); DigitalOut PIN_RLED(PB_4); #define I2C_ADDRESS 0x73 //----------------------------------------------------------------------- int main(void) { char addr = 0; char data ; // pc.set_flow_control(SerialBase::Disabled) ; pc.baud(115200); pc.printf("---------- Pixart PAT9125 Demo\n"); // +++++++ LCM Initialization +++++++ // // Chip must be deselected PIN_LCM_CSB = 1 ; // Setup the spi for 8 bit data, high steady state clock, // second edge capture, with a 1MHz clock rate spi.format(8,3); spi.frequency(1000000); gp_pixart_lcm = new pixart_lcm(&spi, &PIN_LCM_CSB, &PIN_LCM_RSTB, &PIN_LCM_RS) ; // ------- LCM Initialization ------- // // +++++++ PAT9125 Initialization +++++++ // gp_pat9125_i2c = new pat9125_i2c(I2C_SDA_PIN, I2C_SCL_PIN); gp_pat9125_i2c->frequency(400000); g_pat9125_mbed_state.p_i2c = gp_pat9125_i2c; g_pat9125_mbed_state.p_pc = &pc; g_pat9125_mbed_state.pBTN_L = &PIN_BTN_L ; g_pat9125_mbed_state.pBTN_R = &PIN_BTN_R ; g_pat9125_mbed_state.pINT = &PIN_SEN_MOTION; g_pat9125_mbed_state.pRLED = &PIN_RLED; g_pat9125_mbed_state.pGLED = &PIN_GLED; g_pat9125_mbed_state.pLCM = gp_pixart_lcm; g_pat9125_mbed_state.slave_id = (I2C_ADDRESS << 1); g_pat9125_mbed_state.sen_status = 0; gp_pat9125_mbed = new pat9125_mbed(&g_pat9125_mbed_state) ; gp_pixart_lcm->LCM_DisplayString_Boot(g_pat9125_mbed_state.sen_status); if(g_pat9125_mbed_state.sen_status == true) { pc.printf("Initial Sensor ... Done\n"); } else { pc.printf("Initial Sensor ... Fail\n"); } while(true) { gp_pat9125_mbed->task(); } }