Go Down

Topic: Serial command lesson, sketch code errors (Read 1 time) previous topic - next topic

Ashton

I'm trying to run a serial command test sketch, that switches an LED 13 off & on, when an 'On' and 'off' is received via serial, using Hyperterminal I assume.

Project wiki:
http://mchobby.be/wiki/index.php?title=SerialCommand

When uploaded does not function, (old LED blink sketch continues to run)

Errors produced:
sketch_feb22a:17: error: stray '@' in program
sketch_feb22a:18: error: stray '@' in program
sketch_feb22a:6: error: 'to' does not name a type
sketch_feb22a:8: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:9: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:3: error: expected unqualified-id before '/' token
sketch_feb22a:25: error: expected unqualified-id before '/' token
sketch_feb22a.ino: In function 'void setup()':
sketch_feb22a:29: error: expected primary-expression before '/' token
sketch_feb22a:29: error: expected primary-expression before '/' token
sketch_feb22a:29: error: 'Initialize' was not declared in this scope
sketch_feb22a:29: error: expected `;' before 'the'
sketch_feb22a:32: error: 'ledPin' was not declared in this scope
sketch_feb22a:33: error: expected primary-expression before '/' token
sketch_feb22a:33: error: expected primary-expression before '/' token
sketch_feb22a:33: error: 'Displays' was not declared in this scope
sketch_feb22a:33: error: expected `;' before 'a'
sketch_feb22a.ino: In function 'void loop()':
sketch_feb22a:40: error: expected primary-expression before '/' token
sketch_feb22a:40: error: expected primary-expression before '/' token
sketch_feb22a:40: error: 'Check' was not declared in this scope
sketch_feb22a:40: error: expected `;' before 'if'
sketch_feb22a:97: error: expected `}' at end of input

Code: [Select]
/ * Command String In String using Serial Port
 
   The program waits for a command arrives on the serial monitor.
   Make sure the serial monitor of Arduino is well set to "Carriage Return"
     Enter 'on' turns on the LED connected to pin 13.
     Enter 'off' turns off the LED connected to pin 13.
   This provides an alternative to Bitlash.
   
   The circuit:
   The Pin 13 is connected to a 220-ohm resistor, which is then
   connected to a LED and then to ground (GND). As an alternative,
   you can watch the LED "L" visible on the Arduino board and
   already connected to pin 13.
   
   Created on July 21, 2010 by Mark Aosawa. mark.aosawa @ yahoo.com
   Deeply modified April 7, 2012 by C. Hobby, info@mchobby.be    
   
 * /
 
 / / String buffer / buffer
 String cmd = String ("");
 
 / / Initialize the LED pin 13 as output (OUTPUT)
 int ledPin = 13;
 
 void setup () {
 / / Initialize the serial communication (baud rate and 9600):
 Serial.begin (9600);

 pinMode (ledPin, OUTPUT);
 / / Displays a message when the serial port is open.
 / / Ensures that the program is running short
 Serial.println ("Serial communication is ready.");
 }

 void loop () {

   / / Check if characters are received on the serial port
   if (Serial.available ()> 0) {
     
      / / Temporary variable to copy the character read
      SerialInByte char;
      / / Read a character (byte)
      SerialInByte Serial.read = ();
     
      / / If this is <CR> -> process the order
      if (SerialInByte == 13) {
         ProcessCmd ();
      Else {}
         / / Otherwise, add the character to the buffer (cmd)
         cmd + = String (SerialInByte);
         
         / / Display a message and debug
         Serial.print ("SerialInByte:");
         Serial.print (SerialInByte, DEC);
         Serial.print ("Buffer");
         Serial.println (cmd);
      }
   }
 }
 
 / / Return the control (buffer contents) to the serial port
 printCmd void () {
   Serial.println (cmd);
 }
 
 / / Reset the buffer (and empty the serial port)
 clearCmd void () {
   cmd = "";
   Serial.flush ();
 }
 
 / / Interpret the command received
 / /
 ProcessCmd void () {
   / / A small debug message. The command is surrounded with [] to clear
   / / Identify each of the characters that compose (even spaces).
   Serial.print ("ProcessCmd for [");
   Serial.print (cmd);
   Serial.println ("]");
   
   if (cmd.equals ("on")) {
        printCmd ();
        digitalWrite (ledPin, HIGH);
        clearCmd ();
   } Else if (cmd.equals ("off")) {
       printCmd ();
       digitalWrite (ledPin, LOW);
       clearCmd ();
   Else {}
        / / All other commands are ignored.
        Serial.println ("unknown command");
        clearCmd ();
   }
}


Any advice appreciated.

AWOL

#1
Feb 22, 2013, 11:54 pm Last Edit: Feb 22, 2013, 11:59 pm by AWOL Reason: 1
A comment starts "//", not "/ /"

The other kind starts "/*", not "/ *"

Code: [Select]
SerialInByte Serial.read = (); that needs looking at, carefully.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Ashton

#2
Feb 23, 2013, 12:10 am Last Edit: Feb 23, 2013, 12:19 am by Ashton Reason: 1
I did change all of the comment marks to eliminate the spaces, error count drops to the below.

Errors with corrected comment marks:
sketch_feb22a:24: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:25: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:26: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a.ino: In function 'void loop()':
sketch_feb22a:42: error: 'SerialInByte' was not declared in this scope
sketch_feb22a:42: error: expected `;' before 'char'
sketch_feb22a:44: error: expected `;' before 'Serial'
sketch_feb22a:48: error: 'ProcessCmd' was not declared in this scope
sketch_feb22a:49: error: 'Else' was not declared in this scope
sketch_feb22a:49: error: expected `;' before '{' token
sketch_feb22a:51: error: expected primary-expression before '=' token
sketch_feb22a.ino: At global scope:
sketch_feb22a:63: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:68: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:75: error: expected constructor, destructor, or type conversion before 'void'


Updated code:
Code: [Select]
/* Command String In String using Serial Port
 
    The program waits for a command arrives on the serial monitor.
    Make sure the serial monitor of Arduino is well set to "Carriage Return"
      Enter 'on' turns on the LED connected to pin 13.
      Enter 'off' turns off the LED connected to pin 13.
    This provides an alternative to Bitlash.
   
    The circuit:
    The Pin 13 is connected to a 220-ohm resistor, which is then
    connected to a LED and then to ground (GND). As an alternative,
    you can watch the LED "L" visible on the Arduino board and
    already connected to pin 13.
   
    Created on July 21, 2010 by Mark Aosawa. mark.aosawa @ yahoo.com
    Deeply modified April 7, 2012 by C. Hobby, info@mchobby.be   
   
  */
 
  // String buffer / buffer
  String cmd = String ("");
 
  // Initialize the LED pin 13 as output (OUTPUT)
  int ledPin = 13;
 
  void setup () {
  // Initialize the serial communication (baud rate and 9600):
  Serial.begin (9600);

  pinMode (ledPin, OUTPUT);
  // Displays a message when the serial port is open.
  // Ensures that the program is running short
  Serial.println ("Serial communication is ready.");
  }

  void loop () {

    // Check if characters are received on the serial port
    if (Serial.available ()> 0) {
     
       // Temporary variable to copy the character read
       SerialInByte char;
       // Read a character (byte)
       SerialInByte Serial.read = ();
     
       // If this is <CR> -> process the order
       if (SerialInByte == 13) {
          ProcessCmd ();
       Else {}
          // Otherwise, add the character to the buffer (cmd)
          cmd + = String (SerialInByte);
         
          // Display a message and debug
          Serial.print ("SerialInByte:");
          Serial.print (SerialInByte, DEC);
          Serial.print ("Buffer");
          Serial.println (cmd);
       }
    }
  }
 
  // Return the control (buffer contents) to the serial port
  printCmd void () {
    Serial.println (cmd);
  }
 
  // Reset the buffer (and empty the serial port)
  clearCmd void () {
    cmd = "";
    Serial.flush ();
  }
 
  // Interpret the command received
  //
  ProcessCmd void () {
    // A small debug message. The command is surrounded with [] to clear
    // Identify each of the characters that compose (even spaces).
    Serial.print ("ProcessCmd for [");
    Serial.print (cmd);
    Serial.println ("]");
   
    if (cmd.equals ("on")) {
         printCmd ();
         digitalWrite (ledPin, HIGH);
         clearCmd ();
    } Else if (cmd.equals ("off")) {
        printCmd ();
        digitalWrite (ledPin, LOW);
        clearCmd ();
    Else {}
         // All other commands are ignored.
         Serial.println ("unknown command");
         clearCmd ();
    }
}


Arrch


I did change all of the comment marks to eliminate the spaces, but my error count goes to 26.

Errors with corrected comment marks:
sketch_feb22a:26: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:27: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:28: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a.ino: In function 'void loop()':
sketch_feb22a:44: error: 'SerialInByte' was not declared in this scope
sketch_feb22a:44: error: expected `;' before 'char'
sketch_feb22a:46: error: expected `;' before 'Serial'
sketch_feb22a:50: error: 'ProcessCmd' was not declared in this scope
sketch_feb22a:51: error: 'Else' was not declared in this scope
sketch_feb22a:51: error: expected `;' before '{' token
sketch_feb22a:53: error: expected primary-expression before '=' token
sketch_feb22a.ino: At global scope:
sketch_feb22a:65: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:70: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:77: error: expected constructor, destructor, or type conversion before 'void'




Yet, you're not going to give us the updated code?

AWOL

#4
Feb 23, 2013, 12:16 am Last Edit: Feb 23, 2013, 12:17 am by AWOL Reason: 1
Else != else

Did you try contacting C. Hobby, info@mchobby.be ?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

billroy

A straight copy-paste of the code at the wiki url compiles fine here.

It might be simpler to start with that code, rather than fight the typos.

-br

AWOL

Quote
A straight copy-paste of the code at the wiki url compiles fine here.

Here too.
Difficult to see how how cut and paste could get go so wrong for the OP.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Ashton

#7
Feb 23, 2013, 12:32 am Last Edit: Feb 23, 2013, 12:35 am by Ashton Reason: 1
Oh No!

I set my Chrome browser Translate feature to Off, then copy & pasted the code.
Now compiles & uploads without error.

Works perfect.


Go Up