Unknown errors.

Hi,

Im a total novice when it comes to programming and I was wondering if anyone could help me.

I understand this is not a basic project (especially for a novice) but i like a challenge. The project uses a raspberry pi as a bridge for home kit. This sends requests over IP:port to the first Arduino (UNO) with an ethernet shield to process the commands. After the first Arduino process the command it is sent through Serial.print over the RX, Tx pins to this Arduino.

For this Uno I am trying to receive commands in through Serial then run them as a function. This arduino has 2 buttons (overrideButton, overrideOpen), one motor (on a shield) and an LED strip. I am able to control all 3 independantly.
After much research I have written this program:

#include <Stepper.h>

void setup() {
  //arduino set up
  Serial.begin(9600); //start serial
      //ints  
  String serialInput = "";
  int overrideButton = false; // turn override on
  int overrideOpen = false; // open curtains while in override
  bool openState = false; //check if open
  int ambient = ""; //collection for sensor
 const int stepsPerRevolution = 212; // motor revolution
  int motorMove = 3800; //how far the motor has to move to flly close the curtain
  int red = 0; //brightness out of 255
  int green = 0; //brightness out of 255
  int blue = 0; //brightness out of 255

Stepper myStepper(stepsPerRevolution, 8, 11, 12, 13);
 myStepper.setSpeed(180);
  

  //pins decleration
  int sensor = A4;
  int RX = 0;
  int TX = 1;
  int redbutton = 2;
  int redPin = 3;
  int blackButton = 4;
  int greenPin = 5;
  int bluePin = 6;
  int motorPower = 7;
  int motor1 = 8;  
  int motor2 = 9;  
  int motor3 = 10;  
  int motor4 = 11;  
  int motor5 = 12;  
  int motor6 = 13;  

//pinmodes
pinMode(2, INPUT); //button
pinMode(3, OUTPUT); //redled
pinMode(4, INPUT); //button
pinMode(5, OUTPUT); //greenled
pinMode(6, OUTPUT); //blueled
pinMode(7, OUTPUT); //motorpower
pinMode(8, OUTPUT); //motorcontrol
pinMode(9, OUTPUT); //motorsheildpower
pinMode(10, OUTPUT); //motorsheildpower
pinMode(11, OUTPUT); //motorcontrol
pinMode(12, OUTPUT); //motorcontrol
pinMode(13, OUTPUT); //motorcontrol

}

void loop() {
 
 while(bool !overrideButton) {
  if (Serial.available() >0) {
    while(Serial.available() > 0) {
String serialInput += (char)Serial.read();
      delay(150);
    }
  }
  Serial.print( int serialInput);
 serialInput;
serialInput = "";
  if (blackButton == HIGH) {

      overrideButton = !overrideButton
    }
  }
}
 while (bool overrideButton == true) {
      if(blackButton == HIGH) {

      overrideButton = !overrideButton
    }
  }
    if (redButton == HIGH) {
    
      overrideOpne = !overrideOpen
    }
    if (overrideOpen == true) {
      curtainOpen();
    } else if (curtainOpen == false) {
      curtainClose();
    } else {
      for(int x = 0; x < 8; x++) {
      Serial.print("ERROR ");
      Serial.println("override function curtainopen not a bool!");
      }
    }
  }
}

int curtainOpen() {
 if (openstate == false) {
  
  digitalWrite(7, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);

myStepper.step(motorMove);

  digitalWrite(7, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
 }
 openState = true;
 Serial.println("Curtains are open"); 
}


int curtainClose() {
 if (openstate == true) {
  
  digitalWrite(7, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);

myStepper.step(-motorMove);

  digitalWrite(7, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
 }
 openState = false;
 Serial.println("Curtains are closed"); 
}

int led() {
  digitalWrite(redPin, red);
  digitalWrite(greenPin, green);
  digitalWrite(bluePin, blue);
  
  Serial.print(" Red = ");
  Serial.print(red);
  Serial.print(";");
  Serial.print(" Green = ");
  Serial.print(green);
  Serial.print(";");
  Serial.print(" Blue = ");
  Serial.print(blue);
  Serial.println(";");
}

int brightness() {
  ambient = analogRead(sensor); 
  Serial.print("Sensor = ");
  Serial.print(ambient);
  Serial.println(";");
}

i have been having issues with all 3 sets of software, but this one is causing me the most grief. the compiler kicks out these errors:

HardwareArduino:59: error: expected primary-expression before ‘bool’
while(bool !overrideButton) {
^
HardwareArduino:59: error: expected ‘)’ before ‘bool’
HardwareArduino:59: error: expected unqualified-id before ‘!’ token
while(bool !overrideButton) {
^
HardwareArduino:154: error: expected ‘}’ at end of input
}
^
exit status 1
expected primary-expression before ‘bool’

Despite my best efforts i have not been able to clear these errors.

Thank you all in advance.

Remove the bool type from the while for starters.

All those variables you defined inside setup aren't visible in any other function. Move them out to global scope,

Thank you both, thats removed a load of errors. Please could anyone help with this error "expected initializer before '+=' token"? All of the reading I have done suggests i have done these statements correctly...

Please could anyone help with this error "expected initializer before '+=' token"?

Sure. When you post your code.

All of the reading I have done suggests i have done these statements correctly...

The compiler appears to disagree with you.

Stew: ... this error "expected initializer before '+=' token"

is pretty clear... look here:

String serialInput += (char)Serial.read();

your compiler expected an initializer...

String serialInput = "";  // initialize a String called serialInput
serialInput += (char)Serial.read();  // append the string

but you still have a lot of issues:

Serial.print( int serialInput); // what the heck is this, for example?

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

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

...R

thank you, i have changed that.

the compiler is still kicking out an error with

HardwareArduino:35: error: ‘myStepper’ does not name a type
myStepper.setSpeed(180);
^
exit status 1
‘myStepper’ does not name a type

just to show you the code:

#include <Stepper.h>
      //ints  
  String serialInput = "";
  int overrideButton = false; // turn override on
  int overrideOpen = false; // open curtains while in override
  bool openState = false; //check if open
  int ambient = ""; //collection for sensor
 const int stepsPerRevolution = 212; // motor revolution
  int motorMove = 3800; //how far the motor has to move to flly close the curtain
  int red = 0; //brightness out of 255
  int green = 0; //brightness out of 255
  int blue = 0; //brightness out of 255
  const byte numChars = 32;
  char receivedChars[numChars];
  boolean newData = false;
      //pins decleration
  int sensor = A4;
  int RX = 0;
  int TX = 1;
  int redButton = digitalRead(2);
  int redPin = 3;
  int blackButton = digitalRead(4);
  int greenPin = 5;
  int bluePin = 6;
  int motorPower = 7;
  int motor1 = 8;  
  int motor2 = 9;  
  int motor3 = 10;  
  int motor4 = 11;  
  int motor5 = 12;  
  int motor6 = 13;  

//unknow
Stepper myStepper(stepsPerRevolution, 8, 11, 12, 13);
myStepper.setSpeed(180);

void setup() {
  //arduino set up
  Serial.begin(9600); //start serial

//pinmodes
pinMode(2, INPUT); //button
pinMode(3, OUTPUT); //redled
pinMode(4, INPUT); //button
pinMode(5, OUTPUT); //greenled
pinMode(6, OUTPUT); //blueled
pinMode(7, OUTPUT); //motorpower
pinMode(8, OUTPUT); //motorcontrol
pinMode(9, OUTPUT); //motorsheildpower
pinMode(10, OUTPUT); //motorsheildpower
pinMode(11, OUTPUT); //motorcontrol
pinMode(12, OUTPUT); //motorcontrol
pinMode(13, OUTPUT); //motorcontrol

}

void loop() {
 
 while(!overrideButton) {
  
recvWithStartEndMarkers();
    showNewData();

  Serial.print(serialInput);
 serialInput;
serialInput = "";
  if (blackButton == HIGH) {
      overrideButton = !overrideButton;
    }
  }
 while (overrideButton == true) {
      if(blackButton == HIGH) {

      overrideButton = !overrideButton;
    }
  }
    if (redButton == HIGH) {
      overrideOpen = !overrideOpen;
    }
    if (overrideOpen == true) {
      curtainOpen();
    } else if (curtainOpen == false) {
      curtainClose();
    } else {
      for(int x = 0; x < 8; x++) {
      Serial.print("ERROR ");
      Serial.println("override function curtainopen not a bool!");
      }
    }
  }

int curtainOpen() {
 if (openState == false) {
  
  digitalWrite(7, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);

myStepper.step(motorMove);

  digitalWrite(7, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
 }
 openState = true;
 Serial.println("Curtains are open"); 
}


int curtainClose() {
 if (openState == true) {
  
  digitalWrite(7, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);

myStepper.step(-motorMove);

  digitalWrite(7, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
 }
 openState = false;
 Serial.println("Curtains are closed"); 
}

int led() {
  digitalWrite(redPin, red);
  digitalWrite(greenPin, green);
  digitalWrite(bluePin, blue);
  
  Serial.print(" Red = ");
  Serial.print(red);
  Serial.print(";");
  Serial.print(" Green = ");
  Serial.print(green);
  Serial.print(";");
  Serial.print(" Blue = ");
  Serial.print(blue);
  Serial.println(";");
}

int brightness() {
  ambient = analogRead(sensor); 
  Serial.print("sensor = ");
  Serial.print(ambient);
  Serial.println(";");
}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;
 
    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        serialInput = receivedChars;
        newData = false;
    }
}

myStepper.setSpeed(180);Move it into a function.

I think this line should be inside the setup() function

myStepper.setSpeed(180);

...R

Thank you all for you help. Its working as expected now :)

Stew: Thank you both, thats removed a load of errors. Please could anyone help with this error "expected initializer before '+=' token"? All of the reading I have done suggests i have done these statements correctly...

Ok, dude. If your sketches won't compile, then you are having basic problems with the syntax of the language.

To fix this, google "C++ tutorial" and do a C++ tutorial. Trying to code by example or by guessing is going to take longer than doing a structured walk-through of how the language works, which is what a tutorial is.

Just do the first few chapters - declarations, data types, scope and lifetime, expressions, statements, functions. Once it starts talking about classes in a lot of detail, you can stop.

Arduino has a couple of differences to most C programming, but you need to do a tutorial to fill in all those gaps.