RZ/V2L ADC Interface

Hello all,

I had asked a question before about RZ/V2L Evaluation Kit ADC Pin Layout and after researching into embedded linux and understanding the build process and yocto, I managed to get a better understanding of how this board works. Thank you in advance to those replies.

In my previous forum post, one of the replies had mentioned to execute this command:

cat /sys/bus/iio/devices/iio\:device0/in_voltage{channel_number}_raw

I was able to retrieve values from this command but one thing I noticed is when I run this command I find that all of the channels are outputting around the same value (~1800 - 1900) even though for most of them there is nothing connected to their respective channels. Then to test if everything was working ok, I connected a basic potentiometer to channel 2 and I was able to see the values go up and down as I turned the sensor, however, the values being returned were showcasing very large jumps in value (e.g., it would go from 4 to 500 to 1800 to 4090 as I turned the potentiometer from low setting to high), there wasn't a steady increase.

My questions:

  1. When you are connecting your sensors to this particular evaluation board do you experience such large jumps? Or perhaps I am doing something wrong
  2. Lastly, the cat command above was useful for quickly testing if I am receiving values, I tried to implement a c program which is included during the build process to read from the adc but no luck. I tried this script too: https://github.com/renesas-rz/rza_linux-4.9_bsp/blob/master/adc_example/adc_example.c. Does anyone have any suggestions or tips for how they read sensor data into their programs?

Thank you in advance, I'm relatively new to embedded linux and programming with this board so all help is greatly appreciated!

  • 1) I would check the voltage with a multimeter, input range is 0-3.3V.
    2) Just open and read it as a file, plenty of guides on the web on this.

    #include <stdio.h>

    #define ADC_FILE "/sys/bus/iio/devices/iio:device0/in_voltage0_raw" // file path to ADC result

    int main() {
    FILE *fp;
    int result;

    fp = fopen(ADC_FILE, "r"); // open the file in read mode
    if (fp == NULL) {
    printf("Error opening file!\n");
    return 1;

    fscanf(fp, "%d", &result); // read the ADC result from the file
    printf("ADC Result: %d\n", result); // print the ADC result

    fclose(fp); // close the file

    return 0;

  • Just FYI, the idea of that program was to access the ADC registers directly from an application.

    The reason was that some users did not like the standard Linux API interface, so this this was an example of how a user program could just access the ADC registers directly. No device driver is needed. Basically......like what you could do in a bare-metal or RTOS environment..

    Since the ADC is very simple, and only a couple registers, making a full "proper Linux Device Driver" might be overkill. Since this is "Embedded Linux"......I suggest just breaking the rules and doing some things more simple.

  • HI , thank you for your reply and the advice. I'm going to check the voltage now here with the multimeter.

    Thank you also for sharing some example code, the code above is producing the same output from the cat command which is what I was hoping to get. I just need to check the voltage from the multimeter as the code is outputting the numbers with large jumps between them.

  • Hi Chris, thank you for your reply. That makes sense now, I'll try to keep it simple then and build on the code MicBis pasted above. Thank you again for your help!