This is an overview of the GP2Y0A41SK0F and the OSS-ECAL offering for the GP2Y0A41SK0F. The GP2Y0A41SK0F is a distance measuring sensor IC (40mm to 300mm) made by Sharp.
MCU interface : ADC
CAUTION:Please be sure to refer to the latest version of the Datasheet prior to actual design.
GP2Y0A41SK0F
General description
GP2Y0A41SK0F is a distance measuring sensor unit, composed of an integrated combination of PSD(position sensitive detector), IR-LED (infrared emitting diode) and signal processing circuit. The variety of the reflectivity of the object, the environmental temperature and the operating duration are not influenced easily to the distance detection because of adopting the triangulation method. This device outputs the voltage corresponding to the detection distance. So this sensor can also be used as a proximity sensor.
Feature
- Distance measuring sensor is united with PSD, infrared LED and signal processing circuit
- Short measuring cycle (16.5ms)
- Distance measuring range : 4 to 30 cm
- Compact size (29.5 × 13.0 × 13.5mm)
- Analog output type
Application
- Touch-less switch
- Robot cleaner
- Sensor for energy saving
- Amusement equipment
OSS-ECAL specification
API Function
etSTS oGP2Y0A41SK0F( etCMD cmd, float32* rlt )
The oGP2Y0A41SK0F function is an API function that executes GP2Y0A41SK0F processing according to the command in the argument.
Return value | etSTS | OSS-ECAL status code | |
eSTS_FIN | Completed successfully | ||
eSTS_ERR_MIN | Minimum Distance error (rlt is minimum Distance) | ||
eSTS_ERR_MAX | Maximum Distance error (rlt is maximum Distance) | ||
eSTS_ERR_HAL_ADC | HAL ADC Error | ||
eSTS_ERR_COMMAND_CODE | Command selection error | ||
eSTS_ERR_OTHERS_RUN | Other components are executing the process | ||
eSTS_ERR_HAL_OTHERS_RUN | Other application is running HAL | ||
eSTS_ERR_ADC_OBJECT | AD conversion object selection error | ||
Parameter IN | etCMD cmd | OSS-ECAL command code | |
eCMD_START | Command to start AD conversion. | ||
eCMD_READ | Command that reads the AD conversion value, converts the AD conversion value to a characteristic Distance, and stores the Distance in rlt. AD conversion value to Distance conversion equation Voltage value = (AD conversion value × VDD) / ( 2AD bit ) Distance = table search value below (Min, Max Limit) | ||
eCMD_START_READ | Command that starts AD conversion, waits for AD conversion to finish, reads out the AD conversion value, converts the AD conversion value to a characteristic Distance, and stores the Distance in rlt. AD conversion value to Distance conversion equation Voltage value = (AD conversion value × VDD) / ( 2AD bit ) Distance = table search value below (Min, Max Limit) | ||
Parameter OUT | float32* rlt | Distance 40.0 to 300.0 [mm] |
Command Correspondence Table by HAL
Arduino | eCMD_START_READ |
ARM Mbed | eCMD_START_READ |
Infineon ModusToolbox | eCMD_START_READ |
NXP MCUXpresso iMXRT1051B_1052B | eCMD_START eCMD_READ eCMD_START_READ |
Renesas SSP | eCMD_START eCMD_READ eCMD_START_READ |
STM STM32Cube FW_F4 | eCMD_START eCMD_READ eCMD_START_READ |
etSTS oGP2Y0A41SK0F_START(void)
The oGP2Y0A41SK0F_START function is an API function to start AD conversion of the GP2Y0A41SK0F.
Return value | etSTS | OSS-ECAL status code | |
eSTS_FIN | Completed successfully | ||
eSTS_ERR_HAL_ADC | HAL ADC Error | ||
eSTS_ERR_OTHERS_RUN | Other components are executing the process | ||
eSTS_ERR_HAL_OTHERS_RUN | Other application is running HAL | ||
eSTS_ERR_ADC_OBJECT | AD conversion object selection error |
Function Correspondence Table by HAL
Arduino | – |
ARM Mbed | – |
Infineon ModusToolbox | – |
NXP MCUXpresso iMXRT1051B_1052B | X |
Renesas SSP | X |
STM STM32Cube FW_F4 | X |
etSTS oGP2Y0A41SK0F_READ( float32* rlt )
The oGP2Y0A41SK0F_READ function is an API function that checks for the end of AD conversion of the GP2Y0A41SK0F, reads the AD conversion value, converts the AD conversion value to a characteristic Distance , and stores the Distance in rlt.
AD conversion value to Distance conversion equation
Voltage value = (AD conversion value × VDD) / ( 2AD bit )
Distance = table search value below (Min, Max Limit)
Return value | etSTS | OSS-ECAL status code | |
eSTS_FIN | Completed successfully | ||
eSTS_ERR_MIN | Minimum Distance error (rlt is minimum Distance) | ||
eSTS_ERR_MAX | Maximum Distance error (rlt is maximum Distance) | ||
eSTS_ERR_HAL_ADC | HAL ADC Error | ||
eSTS_ERR_TIMEOUT | ADC Timeout error (AUTOSAR only) | ||
eSTS_ERR_OTHERS_RUN | Other components are executing the process | ||
eSTS_ERR_ADC_OBJECT | AD conversion object selection error | ||
Parameter OUT | float32* rlt | Distance 40.0 to 300.0 [mm] |
Function Correspondence Table by HAL
Arduino | – | |
ARM Mbed | – | |
Infineon ModusToolbox | – | |
NXP MCUXpresso iMXRT1051B_1052B | X | |
Renesas SSP | X | |
STM STM32Cube FW_F4 | X | Time-out time HAL_MAX_DELAY |
etSTS oGP2Y0A41SK0F_START_READ( float32* rlt )
The oGP2Y0A41SK0F_START_READ function is an API function that starts an AD conversion of the GP2Y0A41SK0F, waits for the AD conversion to finish, reads the AD conversion value, converts the AD conversion value to a Distance characteristic, and stores the Distance in rlt.
AD conversion value to Distance conversion equation
Voltage value = (AD conversion value × VDD) / ( 2AD bit )
Distance = table search value below (Min, Max Limit)
Return value | etSTS | OSS-ECAL status code | |
eSTS_FIN | Completed successfully | ||
eSTS_ERR_MIN | Minimum Distance error (rlt is minimum Distance) | ||
eSTS_ERR_MAX | Maximum Distance error (rlt is maximum Distance) | ||
eSTS_ERR_HAL_ADC | HAL ADC Error | ||
eSTS_ERR_OTHERS_RUN | Other components are executing the process | ||
eSTS_ERR_HAL_OTHERS_RUN | Other application is running HAL | ||
eSTS_ERR_ADC_OBJECT | AD conversion object selection error | ||
Parameter OUT | float32* rlt | Distance 40.0 to 300.0 [mm] |
Function Correspondence Table by HAL
Arduino | X | |
ARM Mbed | X | |
Infineon ModusToolbox | X | |
NXP MCUXpresso iMXRT1051B_1052B | X | |
Renesas SSP | X | |
STM STM32Cube FW_F4 | X | Time-out time HAL_MAX_DELAY |
Voltage/Distance conversion table

HAL Support List
OSS-ECAL’s HAL support is as follows. (The list is being expanded sequentially.) Please note that even if the same HAL is used, different versions, MCUs, and development environments may not work together.
Manufacturer | SDK/IDE Tool | HAL Name | Ver | HALNAME | Support |
---|---|---|---|---|---|
Arduino | Arduino IDE | Arduino | 1.8.6 | ARDUINO | X |
Arm | Keil MDK v6 | Mbed OS | 6.17.0 | MBED | X |
Debian | – | GNU/Linux | 10.3 | Linux | – |
Infineon | ModusToolbox | mtb-hal-cat1 | 2.4.3 | ModusToolbox | X |
NXP | MCUXpresso SDK | SDK_2.x_EVKB-IMXRT1050 | 2.16 | iMXRT1051B1052B | X |
NXP | PlatformSDK_S32K1_2022_02 | AUTOSAR MCAL | 4.4 | MCAL | – |
Renesas | Synergy Software Package | HAL | 2.6.0 | SSP | X |
STMicroelectronics | STM32Cube | STM32CubeF4 | V1.28.1 | STM32F4 | X |
Development environment
The MCU and development environment during OSS-ECAL development are as follows.
HALNAME | Manufacturer | Board | MCU | IDE |
---|---|---|---|---|
ARDUINO | Arduino | 1.Mega 2560 Rev3 2.Arduino Pro Mini 3.3V | ATmega2560 ATmega328P | Arduino IDE 2.3.3 |
MBED | STMicroelectronics | STM32 Nucleo-64 boards | STM32F401RETx | Arm Keil Studio Cloud |
Linux | BeagleBoard | BeagleBone Black | TI AM335x | – |
ModusToolbox | Infineon | CY8CPROTO-063-BLE PSoC 6 BLE Prototyping Kit | CYBLE-416045-02 | ModusToolbox |
iMXRT1051B1052B | NXP | IMXRT1050-EVKB | i.MX RT1050 | MCUXpresso IDE |
MCAL | STMicroelectronics | S32K144EVB-Q100 | S32K144 | S32 Design Studio for S32 Platform |
SSP | Renesas | S7G2 SK | R7FS7G27H3A01CFC | e² studio for Renesas Synergy |
STM32F4 | STMicroelectronics | STM32 Nucleo-64 boards | STM32F401RETx | STM32CubeIDE |
File Structure
Folder* | File | Summary |
---|---|---|
GP2Y0A41SK0F_HALNAME_VERSION/sample | sample.c (.cpp) | Sample Application Program |
sample.h | Sample Application Header | |
GP2Y0A41SK0F_HALNAME_VERSION | oGP2Y0A41SK0F.c (.cpp) | OSS-ECAL Program for GP2Y0A41SK0F |
oGP2Y0A41SK0F.h | OSS-ECAL Header for GP2Y0A41SK0F | |
GP2Y0A41SK0F_ARDUINO.ino | Sample application programs for Arduino | |
oss_ecal.h | OSS-ECAL Common Header (Ver 01.00.00 or later) | |
user_setting.c (.cpp) | Const and Table of User setting | |
user_setting.h | Header of User setting | |
readme.md | Readme | |
OSS-ECAL Terms of Use.txt | OSS-ECAL Terms of Use |
* For HALNAME, please refer to HAL Support.
OSS-ECAL Download Contact
Please login before contacting us for downloads.
To register as a new user, click here.
Built-in How to
How to incorporate OSS-ECAL into user programs
How to incorporate multiple OSS-ECALs in a user program (same MCU function)
How to incorporate multiple OSS-ECALs in a user program (different MCU function)
How to incorporate multiple identical electronic components into a user program
How to reduce the impact on user programs by replacing electronic components
CAUTION
The sample version of OSS-ECAL is not intended to be used with Threads (Tasks) or interrupts of different priority. Please do not use it as in the example below.
Example: If each sensor is assigned to the same ADC group and the OSS-ECAL API is executed in processes with different priorities, correct values may not be obtained.
ADC Gr0 Ch0 Temperature sensor AD22100A 100ms cycle Thread (low priority) to take in temperature
ADC Gr0 Ch1 Pressure sensor MPX5999D Event interrupts (high priority) to take pressure