Arduino Forum

Using Arduino => Programming Questions => Topic started by: SkyCrafter on Mar 22, 2018, 10:14 pm

Title: Arduino Coding Serial Error
Post by: SkyCrafter on Mar 22, 2018, 10:14 pm
So, i'm just sitting here and trying to make a code to access the controls for my project, and the serial isn't being declared. I am beginning the serial in the setup and using serial printing in a function.
Code: (all my code so far, just started) Error Line Bolded
Code: [Select]
void setup() {
 Serial.begin(115200);
 passcodeCheck();
 
}
const int passcode = 1324;
int access = 0;
int incomingByte = Serial.read();
void passcodeCheck() {
  [b]Serial.print("Enter Passcode: ");[/b]
  Serial.print(incomingByte);
 }

Error Message
Code: [Select]
DestroyerShip:17: error: 'Serial' was not declared in this scope

   Serial.print("Enter Passcode: ");

   ^

exit status 1
'Serial' was not declared in this scope

Thanks  :smiley-lol:
Title: Re: Arduino Coding Serial Error
Post by: GrooveFlotilla on Mar 22, 2018, 10:23 pm
Code: [Select]
int incomingByte = Serial.read();Not in a function.
Oops
Title: Re: Arduino Coding Serial Error
Post by: SkyCrafter on Mar 22, 2018, 10:33 pm
I know, I need it to be global. not just the one function.
Title: Re: Arduino Coding Serial Error
Post by: GrooveFlotilla on Mar 22, 2018, 10:34 pm
When do you think the Serial.read is going to be executed?
Is that a good idea?

(In return for you not posting all your code, I'm not posting complete answers. Hope that's OK with you)
Title: Re: Arduino Coding Serial Error
Post by: SkyCrafter on Mar 22, 2018, 10:49 pm
I don't know, I thought it would be executed each time I call the variable? Or is there another way to receive multiple characters from the serial monitor?
Also, did you read my first post? that IS all my code...
Title: Re: Arduino Coding Serial Error
Post by: GrooveFlotilla on Mar 22, 2018, 10:51 pm
You call functions.
You do not call variables (unless the variable is a function pointer)

The only way to receive multiple characters is to call, directly or indirectly, Serial.read.

Quote
Also, did you read my first post? that IS all my code..
I assumed you were being economical with the truth to avoid embarrassment.
Title: Re: Arduino Coding Serial Error
Post by: SkyCrafter on Mar 22, 2018, 10:59 pm
Read this. the forum guidelines on how to post a programming question. then read the whole thing as you have CLEARLY not read it...
If you get an error, post the error (copy and paste). Not just "I got an error".
With coding problems, if possible post a "minimal" sketch that demonstrates the problem - not hundreds of lines of code. <----- read this back to me!
If you have debugging information in your sketch, post your debugging displays.
Title: Re: Arduino Coding Serial Error
Post by: GrooveFlotilla on Mar 22, 2018, 11:01 pm
A minimal sketch will have a setup function, and a loop function.

Back to you.
Title: Re: Arduino Coding Serial Error
Post by: Robin2 on Mar 22, 2018, 11:08 pm
Have a look at the examples in Serial Input Basics (http://forum.arduino.cc/index.php?topic=396450.0) - simple reliable ways to receive data.

...R
Title: Re: Arduino Coding Serial Error
Post by: SkyCrafter on Mar 22, 2018, 11:13 pm
Robin2 Thank you for real info
Props to you, +1 Karma
Title: Re: Arduino Coding Serial Error
Post by: GrooveFlotilla on Mar 23, 2018, 12:27 am
Just for $hits and giggles, I took the code from the original post, removed the [b][/b] tags, and pasted it into the IDE.
Try as hard as I can, I can't get it to produce the error message @SkyCrafter claims for it.
All I get is the expected "undefined reference to `loop' "

I wonder why that is?
Title: Re: Arduino Coding Serial Error
Post by: SkyCrafter on Mar 23, 2018, 03:23 pm
were you actually uploading it? what programmer? what board?
Title: Re: Arduino Coding Serial Error
Post by: GrooveFlotilla on Mar 23, 2018, 03:43 pm
How can you expect to upload something that does not and cannot compile?
What difference would an un-invoked programmer make to the outcome of a failed compilation?
(Anyway, aren't you the one who is supposed to furnish all that detail?)
Please, start making some sense.
Title: Re: Arduino Coding Serial Error
Post by: GrooveFlotilla on Mar 23, 2018, 07:16 pm
Ha Ha Ha Ha

I just looked at some of your other posts, like "Error while burning bootloader to attiny85".
I assume this is related to the same project.

Ha Ha Ha Ha.
Title: Re: Arduino Coding Serial Error
Post by: SkyCrafter on Mar 26, 2018, 04:00 pm
no?
im going to use a mega for this project. stop posting on this.
Title: Re: Arduino Coding Serial Error
Post by: surbyte on Mar 26, 2018, 05:42 pm
@SkyCrafter, please post your full code.
It's impossible to help you if you don't help us!!
Title: Re: Arduino Coding Serial Error
Post by: TolpuddleSartre on Mar 26, 2018, 07:00 pm
If you take the code posted above, and compile it for a Mega, you should see this:
Code: [Select]
Arduino: 1.6.12 (Linux), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

/tmp/ccNfzOpl.ltrans0.ltrans.o: In function `main':
ccNfzOpl.ltrans0.o:(.text.startup+0x202): undefined reference to `loop'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

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


If you put in a dummy loop
Code: [Select]
void setup() {
 Serial.begin(115200);
 passcodeCheck();
 
}
const int passcode = 1324;
int access = 0;
int incomingByte = Serial.read();

void passcodeCheck() {
  Serial.print("Enter Passcode: ");
  Serial.print(incomingByte);
 }


void loop (){} // <<< I ADDED THIS
and compiled it, again, for a Mega, you should see this message
Code: [Select]
Sketch uses 2,090 bytes (0%) of program storage space. Maximum is 253,952 bytes.
Global variables use 204 bytes (2%) of dynamic memory, leaving 7,988 bytes for local variables. Maximum is 8,192 bytes.
.

The only way I can see that you could get a error for Serial not being defined, would be if you compiled the code for a processor that doesn't have a UART.
Title: Re: Arduino Coding Serial Error
Post by: SkyCrafter on Mar 29, 2018, 03:59 pm
OOF.
Title: Re: Arduino Coding Serial Error
Post by: sterretje on Mar 29, 2018, 04:14 pm
OOF.
Out of focus ?
Title: Re: Arduino Coding Serial Error
Post by: TolpuddleSartre on Mar 29, 2018, 04:14 pm
OOF.
Did you have something to add, or are you just channeling a Gaston Lagaffe comic?
Title: Re: Arduino Coding Serial Error
Post by: surbyte on Mar 29, 2018, 04:32 pm
This code compiles but you canĀ“t control access with that, because you are reading only one char in passcodeCheck().

I just reorder your lines.



Code: [Select]
const int passcode = 1324;
int access = 0;
   

void setup() {
 Serial.begin(115200);
 passcodeCheck();
}

void loop() {
}

void passcodeCheck() {

  int incomingByte = Serial.read();
  Serial.print("Enter Passcode: ");
  Serial.print(incomingByte);
}



Quote
AVR Memory Usage
----------------
Device: atmega328p

Program:    1766 bytes (5.4% Full)
(.text + .data + .bootloader)

Data:        202 bytes (9.9% Full)
(.data + .bss + .noinit)


 [SUCCESS] Took 49.31 seconds

[03/29/18 11:29:19]
Title: Re: Arduino Coding Serial Error
Post by: SkyCrafter on Mar 29, 2018, 05:08 pm
I need to collect at least 4 characters, as it will be a 4 digit passcode to unlock the system
Title: Re: Arduino Coding Serial Error
Post by: TolpuddleSartre on Mar 29, 2018, 06:22 pm
Robin2 has a serial basics topic that covers all sorts of common serial issues.
Title: Re: Arduino Coding Serial Error
Post by: Robin2 on Mar 29, 2018, 08:41 pm
Robin2 has a serial basics topic that covers all sorts of common serial issues.
But that was way-back-when in Reply #8 and I assume the OP studied it carefully and decided s/he did not like it. :)

...R