Go Down

Topic: Arduino Coding Serial Error (Read 957 times) previous topic - next topic

surbyte

@SkyCrafter, please post your full code.
It's impossible to help you if you don't help us!!

TolpuddleSartre

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.

SkyCrafter

Some people are just dinguses. Some people are just geniuses. I'm a dingus. It's fun to push dinguses down the stairs. It's fun to push yourself down the stairs.

sterretje

If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

TolpuddleSartre

OOF.
Did you have something to add, or are you just channeling a Gaston Lagaffe comic?

surbyte

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]

SkyCrafter

I need to collect at least 4 characters, as it will be a 4 digit passcode to unlock the system
Some people are just dinguses. Some people are just geniuses. I'm a dingus. It's fun to push dinguses down the stairs. It's fun to push yourself down the stairs.

TolpuddleSartre

Robin2 has a serial basics topic that covers all sorts of common serial issues.

Robin2

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
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up