I need help. I have this module: https://botland.com.pl/czujniki-swiatla-i-koloru/5394-analogowy-detektor-koloru-rgb-z-led-mod-52.htm... https://botland.com.pl/czujniki-swiatla-i-koloru/5394-analogowy-detektor-koloru-rgb-z-led-mod-52.htm... [PL, but I believe it isnt that important]
It have 3 analog signal output for RGB respectively. I want to detect colors RGB intensity in 0-255 values.
Im using mraa libraries.
My simplified code:
# define AIO_RED 4
int get_color(int color)
val_color = read_from_aio(red);
//color = read_from_aio(blue);
val_color = 0;
// color = read_from_aio(green);
val_color = 0;
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:
# include "mraa/aio.h"
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 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.