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.

Files at this revision

API Documentation at this revision

Comitter:
pixus_mbed
Date:
Fri Oct 20 10:58:39 2017 +0000
Parent:
10:ccb7b47e31c3
Child:
16:7bea34dc0356
Commit message:
1. Separate LCD and UART mode.; 2. Configure BTN with default pull-up.; 3. NULL handle.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
pat9125_mbed/pat9125_mbed.cpp Show annotated file Show diff for this revision Revisions of this file
pat9125_mbed/pat9125_mbed.h Show annotated file Show diff for this revision Revisions of this file
pixart_lcm/pixart_lcm.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Oct 20 01:48:20 2017 +0000
+++ b/main.cpp	Fri Oct 20 10:58:39 2017 +0000
@@ -19,18 +19,25 @@
 #include "pat9125_i2c.h"
 #include "pat9125_mbed.h"
 
+#define LCM_MODE
+
 pat9125_mbed_state_s g_pat9125_mbed_state ;
 pat9125_mbed *gp_pat9125_mbed ;
-pixart_lcm *gp_pixart_lcm ;
+pixart_lcm *gp_pixart_lcm = NULL;
+Serial  *serial = NULL ;
 
+#ifdef LCM_MODE
+SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK);
+#else
+Serial  pc(USBTX, USBRX);
+#endif
 
-Serial  pc(USBTX, USBRX);
 #define I2C_SDA_PIN I2C_SDA
 #define I2C_SCL_PIN I2C_SCL
-//DigitalIn sdaDummy(I2C_SDA0, PullUp);
-//DigitalIn sclDummy(I2C_SCL0, PullUp);
+//DigitalIn sdaDummy(I2C_SDA_PIN, PullUp);
+//DigitalIn sclDummy(I2C_SCL_PIN, PullUp);
 pat9125_i2c *gp_pat9125_i2c;//(I2C_SDA0, I2C_SCL0);
-SPI spi(PA_7, NC, PA_5);
+
 
 DigitalOut PIN_LCM_CSB(PB_6);
 DigitalOut PIN_LCM_RSTB(PA_9);
@@ -38,8 +45,11 @@
 
 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);
@@ -48,12 +58,11 @@
 //-----------------------------------------------------------------------
 int main(void)
 {
+    int i = 0;
     char addr = 0;
     char data ;
-    pc.set_flow_control(SerialBase::Disabled) ;
-    pc.baud(115200);
-    pc.printf("---------- Pixart PAT9125 Demo\n");  
 
+#ifdef LCM_MODE
     // +++++++ LCM Initialization +++++++ //
     // Chip must be deselected
     PIN_LCM_CSB = 1 ;
@@ -64,12 +73,17 @@
     spi.frequency(1000000);
     gp_pixart_lcm = new pixart_lcm(&spi, &PIN_LCM_CSB, &PIN_LCM_RSTB, &PIN_LCM_RS) ;
     // ------- LCM Initialization ------- //
-    
+#else
+    serial = &pc ;
+    //pc.set_flow_control(SerialBase::Disabled) ;
+    pc.baud(115200);
+    pc.printf("---------- Pixart PAT9125 Demo\n");      
+#endif    
     // +++++++ 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.p_pc = serial;
     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;
@@ -79,9 +93,10 @@
     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_pat9125_mbed = new pat9125_mbed(&g_pat9125_mbed_state) ;  
+#ifdef LCM_MODE     
     gp_pixart_lcm->LCM_DisplayString_Boot(g_pat9125_mbed_state.sen_status);
-    
+#else    
     if(g_pat9125_mbed_state.sen_status == true) 
     {
         pc.printf("Initial Sensor ... Done\n");
@@ -90,8 +105,10 @@
     {
         pc.printf("Initial Sensor ... Fail\n");
     }
+#endif    
     while(true)
     {
       gp_pat9125_mbed->task();
     }
+    
 }
--- a/pat9125_mbed/pat9125_mbed.cpp	Fri Oct 20 01:48:20 2017 +0000
+++ b/pat9125_mbed/pat9125_mbed.cpp	Fri Oct 20 10:58:39 2017 +0000
@@ -36,13 +36,29 @@
 #define attachInterrupt(pin,b,c)  //pin->enable_irq()
 #define digitalPinToInterrupt(pin) pin
 #define detachInterrupt(pin)  //pin->disable_irq()
-#define LCM_DisplayString_Reset gp_state->pLCM->LCM_DisplayString_Reset
-#define LCM_DisplayDecimal(a,b,c,d) gp_state->pLCM->LCM_DisplayDecimal(a,b,c,d)
-#define LCM_DisplayString(a,b,c) gp_state->pLCM->LCM_DisplayString(a,b,c)
+//#define LCM_DisplayString_Reset gp_state->pLCM->LCM_DisplayString_Reset
+//#define LCM_DisplayDecimal(a,b,c,d) gp_state->pLCM->LCM_DisplayDecimal(a,b,c,d)
+//#define LCM_DisplayString(a,b,c) gp_state->pLCM->LCM_DisplayString(a,b,c)
 
 #define I2C_RESET gp_state->p_i2c = gp_state->p_i2c->reset(); //workaround for nRF51 mbed
 
 
+static void LCM_DisplayString(unsigned char line, unsigned char position, const char *ptr)
+{
+    if(gp_state->pLCM == NULL) return ;
+    gp_state->pLCM->LCM_DisplayString(line, position, ptr);
+}
+static void LCM_DisplayDecimal(unsigned char line, unsigned char position, unsigned int hex_word, unsigned char digits)
+{
+    if(gp_state->pLCM == NULL) return ;
+    gp_state->pLCM->LCM_DisplayDecimal(line, position, hex_word, digits) ;
+}
+static void LCM_DisplayString_Reset(void)
+{
+    if(gp_state->pLCM == NULL) return ;
+    gp_state->pLCM->LCM_DisplayString_Reset();
+}
+
 unsigned char  xy2uart_enh=0;
 
 //for OTS
@@ -284,22 +300,26 @@
   
 void println()
 {
+    if(gp_state->p_pc == NULL) return ;
     gp_state->p_pc->printf("\n");
 }
 
 void println(String str)
 {
+    if(gp_state->p_pc == NULL) return ;
     const char * c = str.c_str();
     gp_state->p_pc->printf(c);
     gp_state->p_pc->printf("\n");
 }
 void print(String str)
 {
+    if(gp_state->p_pc == NULL) return ;
     const char * c = str.c_str();
     gp_state->p_pc->printf(c);
 }
 void print(signed int value)
 {
+    if(gp_state->p_pc == NULL) return ;
     gp_state->p_pc->printf("%d",value);
 }
 
@@ -325,6 +345,7 @@
 
 void serialEvent() 
 {
+  if(gp_state->p_pc == NULL) return ;
   while (gp_state->p_pc->readable())
   {
     // get the new byte:
@@ -576,10 +597,9 @@
 }
 pat9125_mbed::pat9125_mbed(pat9125_mbed_state_s *state)
 {
-    gp_state = state ;
-    //gp_state->p_pc->printf("PAT9125 ADDR0 %x\n", OTS_Read_Reg(0));      
+    gp_state = state ;    
     gp_state->sen_status = OTS_Sensor_Init(); 
-    gp_state->p_pc->printf("OTS_Sensor_Init\n"); 
+    print("OTS_Sensor_Init\n"); 
     gp_state->pINT->fall(&OTS_MotionPin_ISR); //interrupt at low state
 }
 
--- a/pat9125_mbed/pat9125_mbed.h	Fri Oct 20 01:48:20 2017 +0000
+++ b/pat9125_mbed/pat9125_mbed.h	Fri Oct 20 10:58:39 2017 +0000
@@ -1,6 +1,7 @@
 #ifndef PAT9125_MBED_H
 #define PAT9125_MBED_H
-#include "stdint.h"
+#include <stdint.h>
+#include <stddef.h>
 #include "mbed.h"
 #include "pat9125_i2c.h"
 #include "pixart_lcm.h"
--- a/pixart_lcm/pixart_lcm.h	Fri Oct 20 01:48:20 2017 +0000
+++ b/pixart_lcm/pixart_lcm.h	Fri Oct 20 10:58:39 2017 +0000
@@ -11,10 +11,10 @@
     public:           
 
         pixart_lcm(SPI *pSPI, DigitalOut *pCSB, DigitalOut *pRSTB, DigitalOut *pRS) ;
-        void LCM_DisplayString(unsigned char line, unsigned char position, const char *ptr) ;
-        void LCM_DisplayDecimal(unsigned char line, unsigned char position, unsigned int hex_word, unsigned char digits) ;
-        void LCM_DisplayString_Reset(void);
-        void LCM_DisplayString_Boot(boolean sen_status);
+        void LCM_DisplayString(unsigned char line, unsigned char position, const char *ptr) ; 
+        void LCM_DisplayDecimal(unsigned char line, unsigned char position, unsigned int hex_word, unsigned char digits) ; 
+        void LCM_DisplayString_Reset(void); 
+        void LCM_DisplayString_Boot(boolean sen_status); 
 
 };
 #endif