Problems in running my sketch in Arduino Nano RP2040

Hi!!! I'm just a chemist and I'm really really new to work with Arduino, so that my knowledge is very basic! I need to control with Arduino My TCS34725 Color Sensor and DFRobot 1602 Display, but I have a problem. When I use Arduino Nano, my sketch is running correctly, but when I upload the sketch on Arduino Nano RP2040 I receive that error message:

"Compilation error: 'char read' redeclared as different kind of symbol"

Why happens that? What can I do to solve the problem?

Please let me know if the format of the message is not corresponding to the rule of the community!

Really really thanks for your kind attention, sincerely!!

Please post you sketch and full error message, using code tags when you do

really really thanks for your attention, sincerely!!

Here the sketch:

/* CODE TO CONTROL THE COLOR PICKER */

/* Connect SCL to analog 5
Connect SDA to analog 4
Connect VDD to 3.3V DC
Connect GROUND to common ground */

/* INCLUDING THE LIBRARIES */

#include <Wire.h>;

#include <Adafruit_TCS34725.h>; /* TCS34725 Color Sensor Library */

#include <DFRobot_RGBLCD1602.h>; /* DFrobot Display Library */

#include <BasicLinearAlgebra.h>; /* library to calculate the calibration matrix */

/* VARIABLES DECLARATION */

char comando;
char read = 1;
int data;
unsigned long r; /* Declaring the red, green and blue values unsigned long variables */
unsigned long g;
unsigned long b;
unsigned long c;
unsigned long red01;
unsigned long green01;
unsigned long blue01;
double red_normalized;
double green_normalized;
double blue_normalized;
double red_calibrated;
double green_calibrated;
double blue_calibrated;
unsigned long multiplier;
unsigned long factor;
int red_rounded;
int green_rounded;
int blue_rounded;

/* SPECIFYING THAT WE ARE USING THE NAMESPACE BLA */

using namespace BLA;

/* PERIPHERALS INITIALIZATION */

/* TCS34725 definition with default values (integration time= 2.4 ms and gain = 1x) */

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_614MS, TCS34725_GAIN_1X);

/* DFRobot definition (16 characters and two rows) */

DFRobot_RGBLCD1602 lcd(/*RGBAddr*/ 0x60, /*lcdCols*/ 16, /*lcdRows*/ 2);

/*   */




void setup(void) {
  Serial.begin(9600); /* opening of the serial port and setting the data rata to 9600 */

  /* Initializating the display DFRobot */

  lcd.init();




  /* Checking and warning if the connections of the sensor are right or not. 
If that condition gives value 1, the connections are correct,
otherwise the wiring needs to be controlled */

  if (tcs.begin()) {
    Serial.println("Found TCS34725");
  } else {
    Serial.println("No TCS34725 found ... check your connections");
    while (1)
      ;
  }
}


/* Starting to get the red, green, blue and clear values */


void loop(void) {
  uint16_t r, g, b, c; /* Defining red, green and blue as variables */

  /* NORMALIZING TO THE CLEAR THE r, g, b VALUES */

  multiplier = 255;
  factor = multiplier * 1000000 / c;
  red01 = factor * r;
  green01 = factor * g;
  blue01 = factor * b;
  red_normalized = red01 / 1000000;
  green_normalized = green01 / 1000000;
  blue_normalized = blue01 / 1000000;

  /* CALIBRATING THE NORMALIZED VALUES */

  BLA::Matrix<3, 3> M = { 1.5740, -0.1524, -0.1751, -0.4020, 1.5593, -0.4360, -0.1184, 0.0212, 1.0005 }; /* declaring the matrix A 3 rows and 3 columns */

  BLA::Matrix<3, 1> v = { red_normalized, green_normalized, blue_normalized }; /* declaring the column vector */

  BLA::Matrix<3, 1> D = M * v; /* moltiplication of the calibration matrix with the data from the sensor */

  red_calibrated = D(0);

  green_calibrated = D(1);

  blue_calibrated = D(2);

  /* Rounding the calibrated values */

  red_rounded = round(red_calibrated);
  green_rounded = round(green_calibrated);
  blue_rounded = round(blue_calibrated);






  if (read) {
    tcs.getRawData(&r, &g, &b, &c); /* getting the data from the TCS34725 */
    Serial.print("Red: ");
    Serial.print(red_rounded, DEC);
    Serial.print(" ");
    Serial.print("Green: ");
    Serial.print(green_rounded, DEC);
    Serial.print(" ");
    Serial.print("Blue: ");
    Serial.print(blue_rounded, DEC);
    Serial.print(" ");
    Serial.print("Clear: ");
    Serial.print(c, DEC);
    Serial.print(" ");
    Serial.println(" ");

    /* setting the Red, Green and Blue values to the Backlight of DFRobot */
    lcd.setRGB(red_rounded, green_rounded, blue_rounded);
    showDataLCD();
  }



  if (Serial.available() > 0) {
    comando = Serial.read();
    switch (comando) {
      case 'R':
        tcs.getRawData(&r, &g, &b, &c); /* getting the data from the TCS34725 */
        Serial.print("Red: ");
        Serial.print(red_rounded, DEC);
        Serial.print(" ");
        Serial.print("Green: ");
        Serial.print(green_rounded, DEC);
        Serial.print(" ");
        Serial.print("Blue: ");
        Serial.print(blue_rounded, DEC);
        Serial.print(" ");
        Serial.print("Clear: ");
        Serial.print(c, DEC);
        Serial.print(" ");
        Serial.println(" ");

        /* setting the Red, Green and Blue values to the Backlight of DFRobot */

        lcd.setRGB(red_rounded, green_rounded, blue_rounded);
        











        break;


      case 'W':
        data = Serial.parseInt();
        break;

      case 'G':
        comando = Serial.read();
        tcs.setGain(comando);
        break;
      case 'C':
        read = 1;

        break;
      case 'S':
        read = 0;
        break;
    }
  }
}



/* Showing the calibrated data in the DFRobot RGB 1602 display */


void showDataLCD(void) {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("R");
  lcd.print(red_rounded);
  lcd.setCursor(6, 0);
  lcd.print("G");
  lcd.print(green_rounded);
  lcd.setCursor(12, 0);
  lcd.print("B");
  lcd.print(blue_rounded);
  lcd.setCursor(0, 1);
  lcd.print("Color Picker");
  delay(2000);
}

and here the error message

F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino:21:6: error: 'char read' redeclared as different kind of symbol
 char read = 1;
      ^~~~
In file included from C:\Users\MSI\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.2.1\cores\arduino/mbed/platform/include/platform/platform.h:26:0,
                 from C:\Users\MSI\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.2.1\cores\arduino/mbed/platform/include/platform/FileHandle.h:25,
                 from C:\Users\MSI\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.2.1\cores\arduino/macros.h:41,
                 from C:\Users\MSI\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.2.1\variants\NANO_RP2040_CONNECT/pins_arduino.h:2,
                 from C:\Users\MSI\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.2.1\cores\arduino/Arduino.h:76,
                 from C:\Users\MSI\AppData\Local\arduino\sketches\9A95C6BF0A26362DC92A72CB82C31D46\sketch\Aveiro02.ino.cpp:1:
C:\Users\MSI\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.2.1\cores\arduino/mbed/platform/include/platform/mbed_retarget.h:740:13: note: previous declaration 'ssize_t read(int, void*, size_t)'
     ssize_t read(int fildes, void *buf, size_t nbyte);
             ^~~~
F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino: In function 'void loop()':
F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino:193:28: error: invalid conversion from 'char' to 'tcs34725Gain_t' [-fpermissive]
         tcs.setGain(comando);
                            ^
In file included from F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino:12:0:
C:\Users\MSI\Documents\Arduino\libraries\Adafruit_TCS34725/Adafruit_TCS34725.h:205:8: note:   initializing argument 1 of 'void Adafruit_TCS34725::setGain(tcs34725Gain_t)'
   void setGain(tcs34725Gain_t gain);
        ^~~~~~~
F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino:196:16: error: assignment of function 'ssize_t read(int, void*, size_t)'
         read = 1;
                ^
F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino:196:16: error: cannot convert 'int' to 'ssize_t(int, void*, size_t) {aka int(int, void*, unsigned int)}' in assignment
F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino:200:16: error: assignment of function 'ssize_t read(int, void*, size_t)'
         read = 0;
                ^
F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino:200:16: error: cannot convert 'int' to 'ssize_t(int, void*, size_t) {aka int(int, void*, unsigned int)}' in assignment

exit status 1

Compilation error: 'char read' redeclared as different kind of symbol

It looks like one of the libraries used has a function named read and you have a variable named read, hence the error message saying

Try changing the name of your variable to something else less likely to conflict with the name of the function

Note that I am not sure that this is the problem or that changing the name will solve it, but it is worth trying

As an aside, I would also declare the variable as a boolean and give it values of true or false, but that is up to you

really really thanks for your help!! I've tried to change the name to the variable, but I receive this error message:

F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\ColorPickerforRP2040\ColorPickerforRP2040.ino: In function 'void loop()':
F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\ColorPickerforRP2040\ColorPickerforRP2040.ino:193:28: error: invalid conversion from 'char' to 'tcs34725Gain_t' [-fpermissive]
         tcs.setGain(comando);
                            ^
In file included from F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\ColorPickerforRP2040\ColorPickerforRP2040.ino:12:0:
C:\Users\MSI\Documents\Arduino\libraries\Adafruit_TCS34725/Adafruit_TCS34725.h:205:8: note:   initializing argument 1 of 'void Adafruit_TCS34725::setGain(tcs34725Gain_t)'
   void setGain(tcs34725Gain_t gain);
        ^~~~~~~

exit status 1

Compilation error: invalid conversion from 'char' to 'tcs34725Gain_t' [-fpermissive]gita o incolla il codice qui

also, I've tried to declare the variable as boolean, but I receive the same message as the first one: in this case I have bool in place of char....

I am not familiar with the library and do not have it installed so cannot test your sketch

From the error message it would seem that the setGain() function takes a parameter of type tcs34725Gain_t whereas your comado variable is of type char

      case 'G':
        comando = Serial.read();
        tcs.setGain(comando);
        break;

Where did you get the list of values that can be passed to setGain() ?

1 Like

It's really just a matter of reading the error message and thinking about what you're asking the program to do.

This is the line the compiler complained about.

tcs.setGain(comando);

This is the error.

invalid conversion from 'char' to 'tcs34725Gain_t'

This is how you declared comando.

char comando;

This is the declaration of the function your code called in the line that produced the error.

void setGain(tcs34725Gain_t gain);

The function expects an argument with the type of tcs34725Gain_t. Your code passed an argument of type char. The compiler can't do a conversion from char to tcs34725Gain_t.

Since comando is a character that you're reading from the user, your program will have to select a value for gain from the set of values defined by tcs34725Gain_t and pass that value to setGain, not the character the user typed. And if we look in the library's header file, we find that the defined values are:

/** Gain settings for TCS34725  */
typedef enum {
  TCS34725_GAIN_1X = 0x00,  /**<  No gain  */
  TCS34725_GAIN_4X = 0x01,  /**<  4x gain  */
  TCS34725_GAIN_16X = 0x02, /**<  16x gain */
  TCS34725_GAIN_60X = 0x03  /**<  60x gain */
} tcs34725Gain_t;

So you have to pass one of those values to setGain. Though what good it will do to pass a single fixed value is of concern: having some mechanism in the program to select a particular gain value would appear at first glance to be more useful.

2 Likes

Really really thanks for your help!!! For what i've understood, I can set a value from the one indicated in the library and see what happens!! I let you know what happens!!

Hi!! From what i've understood, the values of gains are listed in the library: I will try to set a value for the gain and let's see what happen!!

@van_der_decken and I have both suggested the same reason for the error and I certainly don't see how 'G' would work

Looking forward to you trying an integer value between 0 and 3

1 Like

Hi all! I've just tried to insert a value from the library and something weird happens: the sketch passes the verify, but nothing is working: my TCS34725 sensor and the dispaly remain switched off!!! What it seems really weird to me, is that the original code that I've send is perfectly working with arduino nano, not need to specify a value from the library!!

PS: I've tested with different values from the libraries and for each of one the sketch is correct!!

Well, let's see. Off the top of my head:

  1. The classic Nano is a 5V board, the RP2040 is a 3.3V board.
  2. The Adafruit TCS34725 breakout is a 5V board with level conversion for the 3.3V IC. So you're pulling your I2C lines up to 5V, which I'm not sure that the 3.3V RP2040 will appreciate.
  3. I have no idea what "I've tested with different values from the libraries and for each of one the sketch is correct!!" you're trying to say here.
  4. "the sketch passes the verify, but nothing is working" makes me wonder if you're actually uploading the sketch; a verify just compiles it.
  5. The Adafruit TCS34725 is a discontinued product, so perhaps it doesn't even work with the RP2040 out of the box (though it wouldn't be at the top of my list of suspects).

Edit: on reading Adafruit's product page it would seem #1 and #2 are likely off the hook, as the breakout is spec'd to work with 3-5V. Unless you're powering the breakout board with 5V, that is.

No problem with the voltage: before to use with Arduino nano, I've used the system with Arduino Uno basic and it worked at 3.3 V, so the voltage is correct. Sorry, I've explained bad myself. What I would like to mean is that I've changed the sketch in this way:


      case 'G':
        comando = Serial.read();
        tcs.setGain(TCS34725_GAIN_4X);
        break;
      case 'C':
        leggi = 1;

Also, what I would like to say, is that when I do Sketch Verify/compile, evrything is ok: I have the white writing without any error message, but at the same time nothing is working!!

I'm still not clear on whether or not you're actually uploading the sketch, or simply compiling it. But no matter. I can't see what you see, and I'm not clear on what it is you're trying to say, and there's no sense getting worked up over it.

I'll just leave you with this suggestion: try one of the examples bundled with the TCS34725 library and see if that works on the RP2040. Start simple, and work your way up until you encounter whatever problem is it that you're having.

Good luck with your project.

2 Likes

Yes, I'm uploading the sketch and nothing works after uploading, also if the sketch is formally correct!! Also, I've tried the examples that I can find in the menu File of the IDE with TCS34725 sensor, but they don't work....

I've tried the examples that I can find in the menu File of the IDE with TCS34725 sensor, but they don't work....

Try using 2.2k or 4.7K external pull ups on the i2c pins.

Hi!!! Sorry for the late, just need to do several things!! I've tried the examples from the IDE, but they doesn't work. Also, I've quickly double clicked the reset bottom, so that the mass storage appear and I could drop inside the file:

blink.ino.elf.uf2

and after I should see the built-in LED to start to blink and shifts between red, green and blue, but I can see just the red light....

I really can't understand!!!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.