Pages: [1]   Go Down
Author Topic: Serial command lesson, sketch code errors  (Read 740 times)
0 Members and 1 Guest are viewing this topic.
Illinois, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/ * 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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24424
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A comment starts "//", not "/ /"

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

Code:
SerialInByte Serial.read = ();
that needs looking at, carefully.
« Last Edit: February 22, 2013, 05:59:49 pm by AWOL » Logged

"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.

Illinois, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/* 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 ();
    }
}
« Last Edit: February 22, 2013, 06:19:56 pm by Ashton » Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24424
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Else != else

Did you try contacting C. Hobby, info@mchobby.be ?
« Last Edit: February 22, 2013, 06:17:41 pm by AWOL » Logged

"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.

0
Offline Offline
God Member
*****
Karma: 39
Posts: 986
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24424
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Illinois, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh No!

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

Works perfect.

« Last Edit: February 22, 2013, 06:35:24 pm by Ashton » Logged

Pages: [1]   Go Up
Jump to: