element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • 'Choose another store...'
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Freedom development platform
  • Products
  • Dev Tools
  • Freedom development platform
  • More
  • Cancel
Freedom development platform
Blog Interfacing HC-SR501 pyroelectric infrared PIR motion sensor detector module and FRDM-STBC-AGM01 sensor board to FRDM-KL43Z using Kinetis Design Studio 3.0 Kinetis SDK 1.2 Processor-Expert
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Freedom development platform requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: bheemarao
  • Date Created: 16 Oct 2015 7:24 AM Date Created
  • Views 372 views
  • Likes 0 likes
  • Comments 2 comments
  • pir_sensors
  • frdm-stbc-agm01
Related
Recommended

Interfacing HC-SR501 pyroelectric infrared PIR motion sensor detector module and FRDM-STBC-AGM01 sensor board to FRDM-KL43Z using Kinetis Design Studio 3.0 Kinetis SDK 1.2 Processor-Expert

bheemarao
bheemarao
16 Oct 2015

This is a project for interfacing PIR sensor module to FRDM-KL43Z using Kinetis Design Studio 3.0 Kinetis SDK 1.2 Processor-Expert

 

The module contains 3 pins for connection with system. The two of them are vcc 5v and Gnd. The third one is output from this module. The signal goes high when motion is detected. The output signal is 3.3v compliant. From your system after providing power you check the 3 rd pin for motion detection


image

Delay time is the time during which the output remains changed after the change caused by a detected motion. Or the delay between two subsequent motion detections.

 

Below are the features of the sensor module:

  • wide operating voltage range: default voltage DC 3.6V ~ 20V
  • Temperature compensation ( optional, not factory setting ) : In the summer, when the ambient temperature rises to 30 ~ 32 , detection distance is slightly shorter, temperature compensation can be used for certain performance compensation.
  • high output signal: the circuit can be easily implemented with various docking.
  • Micropower : quiescent current <50 microamps, especially for battery-powered automatic control products.
  • with induction blocking time ( default setting : 2.5S block time ) : sensor module output every time after induction (high variableTo the low level), you can set up a blockade followed by time period, during this time period does not accept any inductive sensor signals.This function can be achieved " sensor output time " and " blocking time "interval between the work can be applied to interval detection products; while this feature can effectively inhibit the load switching process for a variety of interference. ( This time can be set to zero seconds- tens of seconds )


Hardware details of STBC-AGM01 9-axis Sensor

It has FXAS21002C 3-axis gyroscope and FXOS8700C 6-axis integrated e-compass as part of the Freescale Freedom development platform

Schematic can be referred HERE

http://www.freescale.com/files/sensors/development_tools/printed_ciruit_boards_and_schematics/FRDM-STBC-AGM01-SCH.pdf


image

Hardware interface to KL43Z Freedom board:


image

We are connecting

I2CSDA0 (9) of STBC to I2C1SDA of KL43Z freedom board i.e > PTE0 (SDA) J2-18

I2CSCL0 (10) of STBC to I2C1SCL of KL43Z freedom board i.e > PTE1 (SCL) J2-20

 

The interrupt pins of the sensor are connected as follows:

INT1- 8700 (3) STBC >  J1-6   > PTD3

INT1-21002 (6) >  J1-12 >  PTA5

 

STBC-AGM01

FRDM-KL43Z

I2CSDA0 (9)

I2C1SDA : PTE0 (SDA) J2-18

I2CSCL0 (10)

I2C1SCL : PTE1 (SCL) J2-20

INT1- 8700 (3)

J1-6 : PTD3

INT1-21002 (6)

J1-12 :  PTA5

 

The corresponding 7-bit I2C slave address of STBC sensor board are

FXAS21002C is 0x20

FXOS8700CQ is 0x1E

 

We are connecting the signal pins of the sensor module as shown below:

VCC > J3-10 > P5V-USB

GND > J3-14

OUT > J4-12 > PTC-1 port pin

 

PIR- sensor

FRDM-KL43Z

VCC

J3-10 > P5V-USB

GND

J3-14

OUT

J4-12 > PTC-1

 

 

image

 

Components required in our project:

We are using 4 components for this project requirement:

  1. fsl_i2c
  2. fsl_gpio
  3. fsl_debug_console
  4. wait

 

image

 

Component fsl_i2c:

This component is configured with sensor interface with two devices FXOS8700CQ and FXAS21002C as shown below:


image

Pin PTE0 and PTE1 is connected to I2C SDA/SCL pins.


Component fsl_gpio:

Connections made to fsl_gpio component are

 

image


We have connected PTC-1 port pin as an input signal which is connected to ‘OUT’ pin signal of the sensor

Pin PTD3 is connected to INT1-8700 of STBC-AGM01 sensor board

Pin PTA5 is connected to INT1-21002 of STBC-AGM01 sensor board

 

Component fsl_debug_console:

We have connected debug UART to display the motion sensor output on the terminal

  The connection is as shown below:


 

image


Component wait

We have added this component to add delay in our software

Finally our main c program to perform this action is as shown below:

 

/*lint -restore Enable MISRA rule (6.3) checking. */
{
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
         PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/

FXOS8700CQ_DataReady = 1;
FXAS21002C_DataReady = 1;

FXOS8700CQ_Init();
FXAS21002C_Init();

debug_printf("Intruder based ACCEL/MAG/GYRO/TEMP sensing\t");
debug_printf("If Intruder is detected then sensor data are displayed\r\n");
unsigned int count = 0;
for(;;)       
{
while(GPIO_DRV_ReadPinInput(J4_12))      {
WAIT1_Waitms(500);          
if (FXOS8700CQ_DataReady){ 
FXOS8700CQ_ReadRegisters(OUT_X_MSB_REG, 12, AccelMagData);
              
// Read FXOS8700CQ data output registers 0x01-0x06 and 0x33 - 0x38
// 14-bit accelerometer data
Xout_Accel_14_bit = ((int16_t) (AccelMagData[0]<<8 | AccelMagData[1])) >> 2;      
// Compute 14-bit X-axis acceleration output value

Yout_Accel_14_bit = ((int16_t) (AccelMagData[2]<<8 | AccelMagData[3])) >> 2;      
// Compute 14-bit Y-axis acceleration output value 

Zout_Accel_14_bit = ((int16_t) (AccelMagData[4]<<8 | AccelMagData[5])) >> 2;      
// Compute 14-bit Z-axis acceleration output value
                      
debug_printf("Accel data   X:%d  Y:%d    Z:%d   ",Xout_Accel_14_bit, Yout_Accel_14_bit, Zout_Accel_14_bit);                 
FXOS8700CQ_ReadRegisters(OUT_X_MSB_REG, 12, AccelMagData);                   
Xout_Mag_16_bit = (int16_t) (AccelMagData[6]<<8 | AccelMagData[7]);        
// Compute 16-bit X-axis magnetic output value
                       
Yout_Mag_16_bit = (int16_t) (AccelMagData[8]<<8 | AccelMagData[9]);        
// Compute 16-bit Y-axis magnetic output value
                       
Zout_Mag_16_bit = (int16_t) (AccelMagData[10]<<8 | AccelMagData[11]);             
// Compute 16-bit Z-axis magnetic output value

                       
FXOS8700CQ_DataReady = 0; 
debug_printf("Mag data  X:%d      Y:%d   Z:%d   ",Xout_Mag_16_bit, Yout_Mag_16_bit, Zout_Mag_16_bit);                  
WAIT1_Waitms(10);                   
FXAS21002C_DataReady = 1;
}
               
if (FXAS21002C_DataReady ) {                            
FXAS21002C_ReadRegisters(GYRO_OUT_X_MSB_REG, 6, GyroData);           
// Read FXAS21002C data output registers 0x01-0x06                           
FXAS21002C_DataReady = 0;                         
// 16-bit gyro data
                             
Xout_Gyro_16_bit = (int16_t) (GyroData[0]<<8 | GyroData[1]);         
// Compute 16-bit X-axis output value
                             
Yout_Gyro_16_bit = (int16_t) (GyroData[2]<<8 | GyroData[3]);         
// Compute 16-bit Y-axis output value
                             
Zout_Gyro_16_bit = (int16_t) (GyroData[4]<<8 | GyroData[5]);         
// Compute 16-bit Z-axis output value                           
// Gyro data converted to dps
                             
Roll = (float) (Xout_Gyro_16_bit) / SENSITIVITY_250;                 
// Compute X-axis output value in dps
                             
Pitch = (float) (Yout_Gyro_16_bit) / SENSITIVITY_250;                
// Compute Y-axis output value in dps
                             
Yaw = (float) (Zout_Gyro_16_bit) / SENSITIVITY_250;                  
// Compute Z-axis output value in dps                          
// FXAS21002C_DataReady = 0;
                             
debug_printf("Gyro data  X axis:%d Y axis:%d     Z axis:%d",Xout_Gyro_16_bit, Yout_Gyro_16_bit, Zout_Gyro_16_bit);
                             
FXAS21002C_ReadRegisters(GYRO_TEMP_REG, 1, GyroData);
Temp = (int8_t) (GyroData[0]);                   
// FXAS21002C_DataReady = 0;
debug_printf("Temp is: %d degC\r\n",Temp);
//debug_printf("if Intruder detected then ACCEL/MAG/GYRO/Temp data are displayed\r\n");
 WAIT1_Waitms(10);
 FXOS8700CQ_DataReady = 1;
}
count++;
}// end of while


              
if (count==5){                    
debug_printf("if Intruder detected then ACCEL/MAG/GYRO/Temp data are displayed\r\n");
count = 0;
}
  }//End of main


The below functions used are defined inside main.c file (these functions have been referenced from the Freescale community link)


void FXOS8700CQ_Init (void)

void FXAS21002C_Init (void)

FXAS_status_t FXAS21002C_WriteRegister(uint8_t reg, uint8_t val)

FXAS_status_t FXAS21002C_ReadRegisters(uint8_t reg, uint8_t n, uint8_t *val)

FXOS_status_t FXOS8700CQ_WriteRegister(uint8_t reg, uint8_t val)

FXOS_status_t FXOS8700CQ_ReadRegisters(uint8_t reg, uint8_t n, uint8_t *val)



/******************************************************************************
* FXOS8700CQ initialization function
******************************************************************************/

void FXOS8700CQ_Init (void)
{
       FXOS8700CQ_WriteRegister(CTRL_REG2, 0x40);          // Reset all registers to POR values
       WAIT1_Waitms(1);

       //WAIT1_Waitms(5);

       FXOS8700CQ_WriteRegister(XYZ_DATA_CFG_REG, 0x00);             // +/-2g range with 0.244mg/LSB

       FXOS8700CQ_WriteRegister(M_CTRL_REG1, 0x1F);           // Hybrid mode (accelerometer + magnetometer), max OSR
       FXOS8700CQ_WriteRegister(M_CTRL_REG2, 0x20);           // M_OUT_X_MSB register 0x33 follows the OUT_Z_LSB register 0x06 (used for burst read)

       FXOS8700CQ_WriteRegister(CTRL_REG2, 0x02);      // High Resolution mode
       FXOS8700CQ_WriteRegister(CTRL_REG3, 0x00);             // Push-pull, active low interrupt
       FXOS8700CQ_WriteRegister(CTRL_REG4, 0x01);             // Enable DRDY interrupt
       FXOS8700CQ_WriteRegister(CTRL_REG5, 0x01);             // DRDY interrupt routed to INT1 - PTD4
       FXOS8700CQ_WriteRegister(CTRL_REG1, 0x25);             // ODR = 25Hz, Reduced noise, Active mode
}



/******************************************************************************
* FXAS21002C initialization function
******************************************************************************/

void FXAS21002C_Init (void)
{
       FXAS21002C_WriteRegister(GYRO_CTRL_REG1, 0x40);               // Reset all registers to POR values
       WAIT1_Waitms(1);

       FXAS21002C_WriteRegister(GYRO_CTRL_REG0, 0x03);               // High-pass filter disabled, +/-250 dps range -> 7.8125 mdps/LSB = 128 LSB/dps
       FXAS21002C_WriteRegister(GYRO_CTRL_REG2, 0x0C);               // Enable DRDY interrupt, mapped to INT1 - PTA5, push-pull, active low interrupt
       FXAS21002C_WriteRegister(GYRO_CTRL_REG1, 0x16);               // ODR = 25Hz, Active mode
}



/******************************************************************************
* Write the specified register of FXAS21002C.
* The reading process is through I2C.
******************************************************************************/

FXAS_status_t FXAS21002C_WriteRegister(uint8_t reg, uint8_t val)
{
       uint8_t cmd[1], buff[1];
       uint8_t retval = 0;

       cmd[0] = reg;
       buff[0] = val;

       retval = I2C_DRV_MasterSendDataBlocking (FSL_I2CCOM1, &i2cCom1_MasterConfig0, cmd, 1, buff, 1, 500);

       if(retval != kStatus_I2C_Success)
       {
              return kStatus_FXOS_I2CFail;
       }
       return kStatus_FXOS_Success;
}

 

 

 

/******************************************************************************
* Read the specified register value of FXAS21002C.
* The reading process is through I2C.
******************************************************************************/

FXAS_status_t FXAS21002C_ReadRegisters(uint8_t reg, uint8_t n, uint8_t *val)
{
       uint8_t cmd[1];
       uint8_t retval = 0;

       cmd[0] = reg;

 retval = I2C_DRV_MasterReceiveDataBlocking(FSL_I2CCOM1, &i2cCom1_MasterConfig0, cmd, 1, val, n, 700); //500

if(retval != kStatus_I2C_Success)
 {
return kStatus_FXOS_I2CFail;
 }
return kStatus_FXOS_Success;
}

 

 

/******************************************************************************
* Write the specified register of FXOS8700CQ.
* The reading process is through I2C.
******************************************************************************/

FXOS_status_t FXOS8700CQ_WriteRegister(uint8_t reg, uint8_t val)
{
       uint8_t cmd[1], buff[1];
       uint8_t retval = 0;

       cmd[0] = reg;
       buff[0] = val;

       retval = I2C_DRV_MasterSendDataBlocking (FSL_I2CCOM1, &i2cCom1_MasterConfig1, cmd, 1, buff, 1, 500);

       if(retval != kStatus_I2C_Success)
       {
              return kStatus_FXOS_I2CFail;
       }
       return kStatus_FXOS_Success;
}

 

 

 

/******************************************************************************
* Read the specified register value of FXOS8700CQ.
* The reading process is through I2C.
******************************************************************************/

FXOS_status_t FXOS8700CQ_ReadRegisters(uint8_t reg, uint8_t n, uint8_t *val)
{
       uint8_t cmd[1];
       uint8_t retval = 0;

       cmd[0] = reg;

 retval = I2C_DRV_MasterReceiveDataBlocking(FSL_I2CCOM1, &i2cCom1_MasterConfig1, cmd, 1, val, n, 700); //500

if(retval != kStatus_I2C_Success)
 {
return kStatus_FXOS_I2CFail;
 }
return kStatus_FXOS_Success;
}



Project working description


we are continuously reading the input port pin whether the motion sensor signal is sensed or not?

PIR is in continuous sensing mode, by default it displays the message “Intruder based ACCEL/MAG/GYRO/TEMP sensing      If Intruder is detected then sensor data are displayed“


If sensed positive for the first time the sensor device FXOS8700C (accelerometer and magnetometer) and FXAS21002C (gyrometer and temperature) present on STBC-AGM01 is enabled and 5 sets of sensor data is displayed on the hyper terminal and again the message “if Intruder detected then ACCEL/MAG/GYRO/Temp data are displayed” is displayed

After PIR is sensed again sensor data is displayed and the cycle repeats

 

The output is as shown below after configuring the serial terminal for the baud rate of 19200 and your com port


image



image


The video output for the same is shown below

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

I have enclosed the project folder and executables for your quick reference and evaluation

 

 

Happy interfacing PIR and FRDM-STBC sensor modules....image image image



Attachments:
  • Sign in to reply
  • bheemarao
    bheemarao over 7 years ago in reply to DAB

    Hi DAB,

     

    I have already put a blog on the sensor module, but need to spend time for getting performance, accuracy and stability. i will try to interface through ISF / Sensor tool box so that i will can see the result graphically.

     

    Best Regards

    Bheema Rao

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 7 years ago

    Are you doing a post on the sensor module?

     

    I am interesting in it performance, accuracy and stability.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube