Unable to retreive the analog values from connected IR sensor
lonedeveloper
New Member Posts: 1 ✭
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
-
Could you please provide the serial number to me??
There will be a sticker "Cxxxxx" on the board.
Or also can take a picture to me.Not all SKUs of UP2 have ADC function, please refer to the link as below. (Quick reference)
https://github.com/up-board/up-community/wiki/Hardware_Specification_UP2Best Regards,
Harry Chiu