Serial ReadBytesUntil Error

Hello,

I’m new here and am trying to compile a code that would take a part of the input (which ends with a question mark) and then use it for other things, but I keep getting various errors trying to set up the Serial.readBytesUntil function. I have tried it with and without arrays. Here is the full code. Help is greatly appreciated!

boolean slot1taken = false;
boolean slot2taken = false;
boolean slot3taken = false;
char endCondition[1] = {"?"};
char slot[5] = {0,0,0,0};
int bytes = 8;

void setup() {
  // initialize serial:
  Serial.begin(115200);
}

void loop() {
  if (Serial.available() > 0) {
    Serial.readBytesUntil(endCondition, slot[0], bytes);
    delay(500);
    Serial.print("I received: ");
    Serial.println(slot[0]);
  }
  if (slot[0] = slot[1])
  {
    //unlock slot1
    slot1taken = false;
  }
  else if (slot[0] = slot[2])
  {
    //unlock slot2
    slot2taken = false;
  }
  else if (slot[0] = slot[3])
  {
    //unlock slot3
    slot3taken = false;
  }
  else {
    if (slot1taken = false)
    {
      //lock slot1
      slot1taken = true;
      slot[1] = slot[0];
    }
    else if (slot2taken = false)
    {
      //lock slot2
      slot2taken = true;
      slot[2] = slot[0];
    }
    else if (slot3taken = false)
    {
      //lock slot3
      slot3taken = true;
      slot[3] = slot[0];
    }
  }
}

With this code the error I get is:

call of overloaded ‘readBytesUntil(char [1], char&, int&)’ is ambiguous

Before I did not have the int length value and it was still acting up :o

So I have managed to compile it by removing the [0] after slot in the readbytesuntil line, but now the output I received gives me either R or 0...

first parameter in readBytesUntil should be a char endCondition = '?'.

Serial.println(slot[0]) prints the first character of the array. Serial.println(slot) prints the zero terminated (!) char arry.

you can't read more bytes then your buffer size. you want to read 8 bytes into 5 bytes buffer. and add one position for the terminating zero.

byte length = Serial.readBytesUntil('?', slot, BUFFER_LENGTH);
slot[length] = 0;
Serial.println(slot);

There are multiple problems with your code

char endCondition[1] = {"?"};

Remove the array size from the declaration or change it to 2 to allow for the terminating zero on the string or it will not compile. Better still change it to

char endCondition = '?';
   Serial.readBytesUntil(endCondition, slot[0], bytes);

The function may read multiple bytes and needs somewhere to store them. One array level is not enough. Change this to

   Serial.readBytesUntil(endCondition, slot, bytes);

With those changes the program compiles but there are other problems

 if (slot[0] = slot[1])

This is not doing a comparison, it is doing an assignment. Change = to == There are other instances of the same problem in your code.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R