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:
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…
noclue said:I tried this script too: https://github.com/renesas-rz/rza_linux-4.9_bsp/blob/master/adc_example/adc_example.c.
Just FYI, the idea of that program was to access the ADC registers directly…
#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 MicBis, 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!