5 Replies Latest reply on Nov 2, 2016 1:24 PM by Intel Corporation

    Intel Edison + KPS-5130 - getting RGB signals

    Pawek

      I need help. I have this module: https://botland.com.pl/czujniki-swiatla-i-koloru/5394-analogowy-detektor-koloru-rgb-z-led-mod-52.html [PL, but I believe it isnt that important]

      which is just circiut for: 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 <unistd.h>
      #include <stdlib.h>
      #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;
         default:
        printf("Unsupported color: %s \n", __FUNCTION__);
        val_color = -1;
         break;
         }
         //val_color = 0; // <-- For avoid stop motor in dev process.
         return val_color;
      }
      
      mraa_aio_context red;
      
      
      int main(void)
      {
         /*Initialize mraa libraries*/
        mraa_init();
        red = mraa_aio_init(AIO_RED);
         /*Main loop*/
         while(1)
         {
        printf("%d\n",get_color(COLOR_RED));
      
         }
      
         return 0;
      }
      

      mraa_read_aio function returns strange values and seems to doesnt react whenever sensor is connected or not. Im pretty sure that i have connected everything properly.

      The most probably reason is that i read RAW data, but i dont know how to calculate values.

      I would be grateful if anybody helps me.

      Thanks,

      Pawel

        • 1. Re: Intel Edison + KPS-5130 - getting RGB signals
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          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 <unistd.h>
          #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.

          • 2. Re: Intel Edison + KPS-5130 - getting RGB signals
            Pawek

            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ł

            • 3. Re: Intel Edison + KPS-5130 - getting RGB signals
              Intel Corporation
              This message was posted on behalf of Intel Corporation

              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.

              • 4. Re: Intel Edison + KPS-5130 - getting RGB signals
                Pawek

                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ł

                • 5. Re: Intel Edison + KPS-5130 - getting RGB signals
                  Intel Corporation
                  This message was posted on behalf of Intel Corporation

                  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.