Thanks for reaching out!
I'd like you to check the ADC example found in https://github.com/intel-iot-devkit/mraa/blob/master/examples/analogin_a0.c, I also post it here:
uint16_t adc_value = 0;
float adc_value_float = 0.0;
adc_a0 = mraa_aio_init(0);
if (adc_a0 == NULL)
adc_value = mraa_aio_read(adc_a0);
adc_value_float = mraa_aio_read_float(adc_a0);
fprintf(stdout, "ADC A0 read %X - %d\n", adc_value, adc_value);
fprintf(stdout, "ADC A0 read float - %.5f\n", adc_value_float);
I noticed several differences between this example and your code. For instance, on the line where you establish the AIO context, it should look like the following:
Also, I found the way you read and print the data strange. I suggest you to check the example above and follow the configuration that is used there.
Let me know how it goes.
Im pretty sure that adc_a0 is only a name for variable. Main initialization happens in mraa_aio_init(0); in my code i want to initialize AIO 4, so it is also good.
Im sorry it is really my mistake. I created function like below:
int read_from_aio(mraa_aio_context sensor)
So it is the same.
And fprintf(stdout,...); == printf(...).
I'm glad to hear that you found the cause of this issue. If you ever have any other doubts, please don't hesitate to come back to the community, we'll try to help you in any way we can.
But i didnt. All I said is that the example code is the same as mine. By my mistake I mean that i didnt copy my read_from_aio function.
Im still looking forward for help.
I apologize, I misunderstood you completely.
I don’t have access to one of this modules, have you checked its ranges? I mean, these sensors often use a method where you have to use a mathematical function to have the real value. You might want to verify that this is not the case.
Also, if you connect the sensor to an oscilloscope are the reading congruent with what mraa receives? Maybe mraa is actually sensing the data correctly and the issue is somewhere else, it would be good to check this possibility.
I’ll be waiting for your response.