0

I have stored light sensor values in comb1, as an array in an unsigned int. I am trying to send these values to a microprocessor. The values are taken from a sensor stored in an array. Then I am trying to send the commands through this:

for(int i = 0; i < 6; i++) {
  Serial1.print("AT+SEND=488,3,%u\r\n", comb1[i]);
}

The entire code compiles fine until I add this line of code. I receive this error message:

Energia: 1.8.11E23 (Windows 10), Board: "MSP-EXP430FR2355LP"

C:\Users\turne\OneDrive\Documents\Energia\M_Station\M_Station.ino: In function 'void loop()':

M_Station:137:55: error: call of overloaded 'print(const char [19], unsigned int&)' is ambiguous

C:\Users\turne\OneDrive\Documents\Energia\M_Station\M_Station.ino:137:55: note: candidates are:

C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:63:12: note: size_t Print::print(unsigned char, int) <near match>

C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:63:12: note:   no known conversion for argument 1 from 'const char [19]' to 'unsigned char'

C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:64:12: note: size_t Print::print(int, int) <near match>

C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:64:12: note:   no known conversion for argument 1 from 'const char [19]' to 'int'

C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:65:12: note: size_t Print::print(unsigned int, int) <near match>

C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:65:12: note:   no known conversion for argument 1 from 'const char [19]' to 'unsigned int'

C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:66:12: note: size_t Print::print(long int, int) <near match>

C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:66:12: note:   no known conversion for argument 1 from 'const char [19]' to 'long int'

C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:67:12: note: size_t Print::print(long unsigned int, int) <near match>

C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:67:12: note:   no known conversion for argument 1 from 'const char [19]' to 'long unsigned int'

Multiple libraries were found for "Wire.h"
 Used: C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\libraries\Wire
exit status 1
call of overloaded 'print(const char [19], unsigned int&)' is ambiguous

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

This is my whole code:

#include <Wire.h>
#include <msp430.h>
#define VEML7700 0x10

// digital pin 40 has a pushbutton attached to it:
const int Switch = 24;
String DataIn; // Variable to store in the String value
int Sendback = 0;
int Sendreq = 0;
int maintain = 0;
unsigned int comb [6];
unsigned int comb1 [6];

void setup() {
  Serial1.begin(115200); // Set up Serial to 115200 baud
  pinMode(Switch, OUTPUT);
  digitalWrite(Switch, LOW); // turn off switch
  // I2C protocol set up
  Wire.begin();
  Wire.beginTransmission(VEML7700);
  Wire.write(0x00);
  Wire.write(0x00);
  Wire.write(0x08);
  Wire.endTransmission();
  Wire.beginTransmission(VEML7700);
  Wire.write(0x01);
  Wire.write(0x00);
  Wire.write(0x00);
  Wire.endTransmission();
  Wire.beginTransmission(VEML7700);
  Wire.write(0x02);
  Wire.write(0xFF);
  Wire.write(0xFF);
  Wire.endTransmission();
  Wire.beginTransmission(VEML7700);
  Wire.write(0x03);
  Wire.write(0x04);
  Wire.write(0x00);
  Wire.endTransmission();
}



void loop() {
  if (Serial1.available()) { // Serial is receiving?
    DataIn = Serial1.readString(); // Reading from Serial
    if (DataIn.indexOf("Wake!") > 0) { // Checking for "Wake!" String
    }
    //storing light sensor values to be sent to 'M' Station
    for (int i = 0; i < 3; i++) {
      int Cup = Wire.read(); // receive a byte as character
      int Cdown = Wire.read(); // receive a byte as character
      if (Cdown < 200) {
        maintain = 1;
        delay(10);
      }
      else {
        maintain = 0;
        delay(10);
      }
      comb[i] = Cdown * 256 + Cup; // array to get assigned values in each position
    }
    digitalWrite(Switch, HIGH); // turn on switch////////////////////////////////////////////////////////////////////////////
    delay(10);
    //storing light sensor values to be sent to second set 'M' Station
    {
      for (int i = 3; i < 6; i++) {
        int Cup = Wire.read(); // receive a byte as character
        int Cdown = Wire.read(); // receive a byte as character
        if (Cdown < 200) {
          maintain = 1;
          delay(10);
        }
        else {
          maintain = 0;
          delay(10);
        }
        comb[i] = Cdown * 256 + Cup; // array to get assigned values in each position
      }
    }
    for (int i = 0; i < 6; i++) {
      //Serial.println(comb[i]);
    }
  }
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  if (Serial1.available()) { // Serial is receiving?
    DataIn = Serial1.readString(); // Reading from Serial
    //storing light sensor values to be sent to 'M' Station
    for (int i = 0; i < 3; i++) {
      int Cup = Wire.read(); // receive a byte as character
      int Cdown = Wire.read(); // receive a byte as character
      if (Cdown < 200) {
        maintain = 1;
        delay(10);
      }
      else {
        maintain = 0;
        delay(10);
      }
      comb1[i] = Cdown * 256 + Cup; // array to get assigned values in each position
    }
    digitalWrite(Switch, LOW); // turn off switch/////////////////////////////////////////////////////////////////
    delay(10);
    //storing light sensor values to be sent to 'M' Station
    for (int i = 3; i < 6; i++) {
      int Cup = Wire.read(); // receive a byte as character
      int Cdown = Wire.read(); // receive a byte as character
      if (Cdown < 200) {
        maintain = 1;
        delay(10);
      }
      else {
        maintain = 0;
        delay(10);
      }
      comb1[i] = Cdown * 256 + Cup; // array to get assigned values in each position
    }
    Sendback = 2;
    Sendreq = 0;
    maintain = 0;
    for (int i = 0; i < 6; i++) {
      Serial1.print("AT+SEND=488,3,%u\r\n", comb1[i]);
    }
  }
  if (Sendback == 1) {
    Serial1.print("AT+SEND=488,3,Up!\r\n"); // Send AT command with String "Up!"
    delay(10);
    Sendback = 0;
    Sendreq = 1;
  }
  if (Sendreq == 1) {
    Wire.beginTransmission(VEML7700);
    Wire.write(0x04);
    Wire.write(0x04);
    Wire.endTransmission(false);
    Wire.requestFrom(VEML7700, 2, true);
    while (Wire.available()); // slave may send less than requested
  }
  if (maintain == 1) {
    Serial1.print("AT+SEND=488,4,req!\r\n"); // Send AT command with String "req!"
    delay(10);
    maintain = 0;
  }
  if (Sendback == 2) {
    Serial1.print("AT+SEND=488,5,Down!\r\n"); // Send AT command with String "Down!"
    delay(10);
    Sendback = 0;
    Sendreq = 0;
    maintain = 0;
  }
  delay(100);
}

Please let me know if you need any more information. I think overloading means that there are different kinds of information stored on comb1 and the compiler does not know which to choose from? But comb1 is declared as an unsigned int and nothing but integers are in the value. I do not know if I have the wrong understanding of what overloaded means, or if I am assigning multiple kinds of data in comb1. Please let me know what you think.

dda
  • 6,030
  • 2
  • 25
  • 34
Ivickt
  • 29
  • 5
  • 2
    the error message is saying that there is no variant of `print` matching your arguments. does the library have a `printf` method? – jdigital Nov 13 '22 at 00:07
  • Looks like there's no overload that takes a `char*`, but there is one that takes a single `char` (and an `int`), so maybe you could write a local function that takes a `char*` and loops over the characters. – 500 - Internal Server Error Nov 13 '22 at 01:02
  • There was already print methods that were working before i added the for loop. – Ivickt Nov 13 '22 at 02:48
  • those other `print` calls only have a single string argument. – jdigital Nov 13 '22 at 02:58
  • I do not Understand what i Need to do to fix this error. If I change the unisigned int to the char then the error is still the same, it looks like the it is trying to choose between one or the other for the Const char[18] and the unsinged int. I do not know how to clear up the confusion. – Ivickt Nov 14 '22 at 00:06
  • It looks to me that "overload" here refers to [function overloading](https://en.wikipedia.org/wiki/Function_overloading), but it is weird to see it in C – Rafs Dec 02 '22 at 08:45

1 Answers1

0

Serial1.print("AT+SEND=488,3,%u\r\n", comb1[i]);

print doesn't work with formatted strings. You need to use printf.

dda
  • 6,030
  • 2
  • 25
  • 34