10 years, 10 months ago.

How to use light sensor on FRDM-K22F?

FRDM-K22F has a visible light sensor - ALS-PT19-315C/L177/TR8 - as one of onboard sensors. How can I read value of it? What is its pin name?

Some pin names are shown in those documents: - ADC0_DP3 in http://developer.mbed.org/platforms/FRDM-K22F/ - ADC0_DP3/ADC0_SE3 in http://developer.mbed.org/media/uploads/sam_grove/frdm-k22f_sch.pdf - A0P3 in https://developer.mbed.org/media/uploads/mareikeFSL/frdm-k1_rev_1.3.pdf - Nothing in User's Guide http://developer.mbed.org/media/uploads/sam_grove/frdmk22fug.pdf

But I cannot find out any definitions of such pin names in the source code (PinNames.h for K22F): https://developer.mbed.org/users/mbed_official/code/mbed-src/file/01cb89f68337/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K22F/PinNames.h

Question relating to:

The FRDM-K22F is an ultra-low-cost development platform for Kinetis K Series K2x (K22F) MCUs built on ARM® Cortex™-M4 processor. Features include easy access to MCU I/O, battery-ready, low-power operation, a …

I'm also hoping to see some code ;)

posted by Mickey Leroy 28 Mar 2015

For example, I wrote a simple code like this:

#include "mbed.h"

AnalogIn light(ADC0_DP3);

int main()
{
    while (true) {
        printf("Current value of the Visible light sensor: %f\r\n", light.read());
        wait(0.5);
    }
}

But I got an error:

Quote:

Error: Identifier "ADC0_DP3" is undefined in "main.cpp", Line: 3, Col: 16

The pinname "ADC0_DP3" came from pin layout. I think "ADC0_DP3" should be defined in PinNames.h...

posted by Shun SKNN 28 Mar 2015

When I jumper ADC0_DP3 and A0, I can read values via A0. /media/uploads/sknn/original_rps20150329_022139.jpg

#include "mbed.h"

AnalogIn light(A0);

int main()
{
    while (true) {
        printf("Current value of the Visible light sensor: %f\r\n", light.read());
        wait(0.5);
    }
}

Value decreases while I put my hand over the sensor.

/media/uploads/sknn/k22f_lightsensor.jpg

This result shows that the light sensor is working but I cannot get its value via ADC0_DP3.

posted by Shun SKNN 28 Mar 2015

2 Answers

10 years, 2 months ago.

Hi there,

AnalogIn light(ADC1_DP0);

I can confirm that does not work.

Would it be possible to know where is the source file where pin names are defined?

thanks fabrizio

10 years, 10 months ago.

Hey Shun, checkout the schematic file -> on page 5 you'll see the Visible light sensor... it's ADC1_DP0 / ADC0_DP3 Let me know how it works out!

Thank you for your comment. I've tried "ADC1_DP0" and "ADC0_DP3" in the source code shown above but I always get a same error. Aren't they pinnames?

posted by Shun SKNN 28 Mar 2015