What does this error message mean?

Hello, I’m a 64 year old working through the [excellent] tutorials,and trying to get my head around all this new “language”! I’m up to Chapter 2 -“Using Digital Pins” and when I click Upload, I get an error message that says :- expected ‘}’ at end of input. I have no idea what this means? I’ve copied the code exactly the same as the presenter [Sam] and tried it a few times with no success.Does anyone know what this means or what I’ve done wrong? Thanks-Ian

The upload will first compile your code if necessary, before uploading it. The message is a compiler message saying the code is not valid and does not compile.

The C++ code uses “{” and “}” to delimit blocks of code, and requires the delimiters to be matched. The compiler has found a '{", but has reached the end of the input file before finding a matching “}”. Make sure you have copied ALL of the code into your file.

Thanks for your reply , Robin. I’ve copied the code as per the tutorial,but will go through it again,and look for anything missing.

I’ve re-written the code,changing only the type of bracket symbol,from [ to {. I now get an error code that says :- expected ’ ; ’ before ‘{’ token. I have the code exactly as per the tutorial.What is token?

Is this the code you are trying to upload ?? It complies ok.
The { } brackets define the two functions setup() and void(), there should be no [ ] brackets.
If this is the code and you are using an Arduino then it should work.

expected ’ ; ’ before ‘{’ token
In C code every line must have ; at the end, you have a line without one.

If this is not the code can you post the code you have ??

Regards
Jim
(Core Electronics Customer)

int buttonPin = 2;
int ledPin = 3;

void setup() {
  // setup pin modes
  pinMode(ledPin, OUTPUT);                  
  pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
  // read state of buttonPin and store it as the buttonState variable
  int buttonState = digitalRead(buttonPin);
  // write the value of buttonState to ledPin
  digitalWrite(ledPin, buttonState);
}

Hello Jim, Yes,this is the code I am using-exactly the same.I have a ; at the end of each line.

Regards-Ian

OK. Unsure why it is not working. But …
I have seen a situation where hidden characters are in the code that are not displayed on the screen. (alt characters maybe) It depends how the code was cut and pasted and if alt and a key were inadvertently pressed.

I know its a pain. But you could open a new, window type the code into that window. If it looks exactly the same and works then maybe it is a hidden character in the original code. Even commenting out lines in the code until it works may help. You can select the Verify button rather than the Upload button, it does the same thing but does not load the code to the Arduino.

Not really sure how to help further without the code in front of me. A text editor like Sublime Text or even Windows Notepad might be able to help. Unsure if you are using Windows or Apple PC.

Regards
Jim
(Core Electronics Customer)

Hi Jim,

I’m using windows 10. I’ll try what you suggested and hopefully find something in there that’s causing the problem.Thanks again.

Regards-Ian

@Ian80523

I would recommend you get a C++ syntax reference so that you can understand the structure, syntax, etc of the code you are working with.

Perhaps something like http://www.cplusplus.com/doc/tutorial/

Also available as a downloadable PDF http://www.cplusplus.com/files/tutorial.pdf

And specifically for the Arduino https://www.arduino.cc/en/Tutorial/Foundations

1 Like

OK, I’ll have a look at that. Thanks again Robin. This stuff is a bit of a steep learning curve for an old “analogue” tech.!

Cheers-Ian

Good recommendation from Robin.
I have not been able to break the code by inadvertently typing alt characters or anything else.

I only experienced code that seemed to have hidden characters in it once; when I cut and pasted from a particular web site. Every other time a cut and paste has worked ok, anything from the Core Electronics Tutorials has worked ok.

Cheers
Jim
(Core Electronics Customer)

Hi Jim,

I’m wondering whether there is something else going on apart from the code,as I’ve successfully used the code from Core Electronics first Chapter [flashing Led] before,and it’s worked OK. Now,I can’t get the flashing Led code to work either. That leads me to another question :- if the flashing Led code was on the Arduino board before,and then I loaded the next [modified flashing Led] code from Chapter 2, does it just “write over” the code that was pre-existing in the Arduino?

Cheers-Ian

Yes. Upload overwrites what was there before. The old code is gone.

If previously working code no longer works (and the code you are using is very basic), look for what you may have changed. The code as provided by the web site definitely works.

From what you have said the problem is not in uploading the code to the Arduino, it is in compiling it. When you click the Upload button, the C code is first compiled into machine code the Arduino processor can run. Then that compiled code is transferred to the Arduino via the USB serial link.
You can click the Verify button which performs just a compile, you don’t need the Arduino attached.

I assume you are using the Arduino IDE and a UNO or similar with a USB cable to your PC.

Cheers
Jim

Also remember that the sketch being compiled isn’t the only source file that is compiled to form the binary blob for upload.

Selecting the correct board definition causes .CPP and .h files for the board in question to used and compiled as well. If your sketch appears to be o.k., there is always a possibility some of the underlying files have been corrupted.

As you probably don’t have many sketches, you could always remove the Arduino IDE, and re-install it. That should fix up any corruptions in the underlying files

Yes Jim, Arduino Uno and USB cable. I’ve re-installed the IDE and gone back to Chapter 1.6,which is just blinking a LED.It now accepts and uploads the code [white message],but the onboard Led doesn’t blink.Now I’m really stumped!

Cheers-Ian

Hi Robin, Yes I reinstalled the IDE and went back to Chapter 1.6-blinking the onboard Led. It now accepts and uploads the code [white message],but the Led doesn’t blink. As I said to Jim who has also been replying,I’m really stumped now!

Cheers-Ian

Hey Ian,

Can you please copy your script that you’re using and paste it into this forum. It may be being caused by a syntax error. All the best with your projects!

Bryce
Core Electronics | Support

@Bryce
We are making progress. The sketch does compile now. So that’s a step in the right direction.

@Ian80523
Check that you have

  1. The correct board type selected, and
  2. The correct serial port selected.

The receive LED should flicker when code is being uploaded to the board.

The receive Led does flicker when I upload,but then nothing happens.The [orange/yellow ] Led does not flash on and off. Faulty UNO board?


void setup() {

// put your setup code here, to run once:

pinMode[13,OUTPUT];

}

void loop() {

// put your main code here, to run repeatedly:

digitalWrite[13,HIGH];

delay[1000];

digitalWrite[13,LOW];

delay[1000];

}