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

Color sensor + Edison using C

Hello,

I have this color sensor: https://botland.com.pl/czujniki-swiatla-i-koloru/5394-analogowy-detektor-koloru-rgb-z-led-mod-52.htm... KPS-5130.

I want to know how to read it properly using C mrra lib.

My code:

// [...]

# define AIO_RED 5

mraa_aio_context red;

red = mraa_aio_init(AIO_RED);

// [...]

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;

default:

printf("Unsupported color: %s \n",__FUNCTION__);

val_color = -1;

break;

}

return val_color;

}

// [...]

int main()

{

while(true)

{

printf("val %d \n", get_color(COLOR_RED));

}

}

Unfortunately, it doesnt give me right values. Trully it doesnt react at all when i plug or unplug my sensor. I get just garbage. I plugged it to 5V, GND and plugged only red color analog output to A5 on board. I feel that is problem with number in # define. What get readings from A5.

How to read values of red, green and blue?

Thanks,

Paweł

Edit: i clicked on "solved" by accident

0 Kudos
6 Replies
idata
Community Manager
65 Views

Hi Pawel,

Thank you for your interest in the Intel Edison Platform.

Before we start debugging your code. Have you installed the latest updates of the mraa libraries? Please try the "opkg update" command. Can you please tell me how you are connecting this sensor.

I will be waiting for your reply, have a nice day.

Best Regards,

-Jose

idata
Community Manager
65 Views

Yes. I have the newest mraa libraries. I have the same problem with gp2y0a distance sensor.

Color: Vcc -> 5V , Gnd -> GND, Red analog out -> A4 in on Edison (no on grove base board)

Color: Vcc -> 5V , Gnd -> GND, Distance out -> A5 in on Edison (no on grove base board)

Now im using A0,A1,A2 ports on Grove base board.

Both seems to send garbage.

distance:

int get_distance(void){

float volts = read_from_aio(distance);

if(volts >= 80 && volts <= 530)

{

float distance = (2076)/(volts - 11);

return (int)distance;

}

else

{

return 0;

}

}

This is how i connect color sensor, distance is connected similar. Only difference is that signal AIO is in A5:

Is mraa_aio_init(5) initialize A5? mraa_aio_init(4) init A4? It works when i use that Grove board connectors, but is it work on that side GPIO/AIOs?

Thanks,

Paweł

Direct readings from AIO using mraa_aio_read(,,) for distance shows sometimes 600V which i think isnt proper

When I plug out signal it reports about 120

idata
Community Manager
65 Views

Hi Pawel,

 

 

If it is working using the Grove board connectors it should work without it. So maybe you are not initializing well the analog pins, can you try using var a0 = new m.Aio(pin) [ where pin is 0 to 5 ]. If this doesn't work could you please give me your whole code including the libraries you are using. I hope you find this information useful.

 

 

I will be waiting for your reply, have a nice day.

 

 

Best Regards,

 

-Jose
idata
Community Manager
65 Views

Hi Pawel,

 

 

Were you able to connect your color sensor to your Edison? Please let me know in order to help you.

 

 

I will be waiting for your reply, have a nice day.

 

 

Regards,

 

-Jose
idata
Community Manager
65 Views

Probably the sensor was crashed. Thanks for support.

idata
Community Manager
65 Views

Hi Pawel,

 

 

Always happy to help, if you have any more technical questions regarding the Intel Edison please don't hesitate to contact us.

 

 

Have a nice day.

 

 

Regards,

 

-Jose
Reply