Unable to retreive the analog values from connected IR sensor

lonedeveloper
lonedeveloper New Member Posts: 1
edited July 18 in UP Squared Windows

I am working with the Upsquared maker board and interfacing a GP2Y0A21 IR sensor using the EAPI library.

  • I need to read analog values from a GPIO pin.
  • I am unable to find the appropriate funciton to retreive the analog values.

Actual Program:

double GP2Y0A21::readADC() {
    uint32_t level = 0;
    //*/
    EApiStatus_t status = EApiGPIOGetLevel(EAPI_GPIO_GPIO_ID(gpioPin), 0xFFFFFFFF, &level);
    if (status != EAPI_STATUS_SUCCESS) {
        std::cerr << "Failed to read GPIO level! Status: " << status << std::endl;
        return 0;
    }
    std::cout << "GPIO Level read from pin " << gpioPin << ": " << level << std::endl;
    return convertToAnalog(level);
    /*/
    uint32_t value = 0;
    EApiStatus_t status = EApiBoardGetValue(EAPI_GPIO_GPIO_ID(gpioPin), &value); // Assuming adcChannelId maps to an appropriate EApiId_t value
    if (status != EAPI_STATUS_SUCCESS) {
        std::cerr << "Failed to read ADC value! Status: " << status << std::endl;
        return 0.0;
    }
    std::cout << "ADC Value read from channel " << gpioPin << ": " << value << std::endl;
    return convertToAnalog(value);


}

Challenges:

The first case get only the digital vlaues and
the second case throws read error.

Kindly throw some light on this. I am thankful for your little guidance and needul help,

Answers

Privacy Policy