Community
cancel
Showing results for 
Search instead for 
Did you mean: 
idata
Community Manager
1,056 Views

Intel Edison + KPS-5130 - getting RGB signals

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]

which is just circiut for: https://botland.com.pl/index.php?controller=attachment&id_attachment=1683 https://botland.com.pl/index.php?controller=attachment&id_attachment=1683 [ENG]

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:

# include

# include  

# define AIO_RED 4

 

 

int get_color(int color)

 

{

 

int val_color;

 

switch (color)

 

{

 

case COLOR_RED:

 

val_color = read_from_aio(red);

 

break;

 

case COLOR_BLUE:

 

//color = read_from_aio(blue);

 

val_color = 0;

 

break;

 

case COLOR_GREEN:

 

// color = read_from_aio(green);

 

val_color = 0;

 

break<span class=...
0 Kudos
5 Replies
idata
Community Manager
32 Views

Hello Pawek,

 

 

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

 

# include "mraa/aio.h"

 

 

int main()

 

{

 

mraa_aio_context adc_a0;

 

uint16_t adc_value = 0;

 

float adc_value_float = 0.0;

 

 

adc_a0 = mraa_aio_init(0);

 

if (adc_a0 == NULL)

 

{

 

return 1;

 

}

 

 

for (;;)

 

{

 

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);

 

}

 

 

mraa_aio_close(adc_a0);

 

 

return MRAA_SUCCESS;

 

}

 

 

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:

 

 

mraa_aio_context adc_a0;

 

 

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.

 

-Peter.
idata
Community Manager
32 Views

Hi,

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)

{

return mraa_aio_read(sensor);

}

So it is the same.

And fprintf(stdout,...); == printf(...).

Best,

Paweł

idata
Community Manager
32 Views

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.

 

 

-Peter.
idata
Community Manager
32 Views

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.

Best,

Paweł

idata
Community Manager
32 Views

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.

 

-Peter.
Reply