Lỗi interrupt does not name of a file năm 2024

It’s 11 PM on a Wednesday. You’ve just spent three hours toiling on your next Arduino project, and FINALLY, you’re ready to give your sketch a whirl. You hit upload, palms sweaty with anticipation to see all your hard work come to fruition. It’s then you see the error:

No such file or directory.

Surely this is a chance aberration. “Nothing to worry about,” you mutter, sleep-starved and semi-delirious as you hit upload again. And once more, those maddening words, “no such file or directory,” stare back at you in hostile gaslighting mockery.

Have you been here?

If you’re trying to run an Arduino sketch but keep coming across the “no such file or directory” error, don’t worry. This is actually a pretty common problem, and there are two easy fixes that almost always work.

Keep on reading. We’ll show you what they are.

No such file error!

Error messages can be such a pain. They do, however, serve a useful purpose by telling us something about what went wrong. At first glance, the no such file or directory error is particularly maddening because it seems to break that useful purpose rule. Of course there’s a file or directory! You just made the thing, and it’s right there, tucked inside a directory.

But hold up, let’s take a closer look. If you look at the bottom portion of the Arduino IDE where the error message shows up, there’s this handy little button that says “copy error messages.”

Lỗi interrupt does not name of a file năm 2024

Click on that now. You probably won’t fall off your chair to learn that by clicking that button, you just copied the error message from the little window at the bottom of The Serial Monitor’s UI to the clipboard of your computer.

This copy feature is ridiculously useful. You could, for example, paste the error message into Google and learn more about the error. Or you could take advantage of the active Arduino community by asking for help in a forum. For this situation, however, we can be a bit more basic. All we’re going to do is take a closer look at what the message is actually saying. To do that, just fire up your PC’s text editor and paste it into the blank screen.

Decoding the no such file error

Here it is, that pesky error in all its freshly pasted glory.

Lỗi interrupt does not name of a file năm 2024

I’ll break it down for you line by line.

  • The first line is easy. It’s just describing the Arduino version in use, what operating system is running, and which board you have selected.
  • Line 2 begins to zero in on the problem.
    • The first bit, “knob,” is referring to the name of the program. This is your sketch, basically.
    • The second bit is what usually begins to confuse people, but it’s easy once you know. The “10” in this example is telling you the error occurred on line 10 of your sketch. The “19” is telling you the length of the line of code in spaces and characters. The first number is usually the more helpful of the two because you can use it to locate the error in your sketch.
  • Then we get to the smoking gun of the error. It says, “servo.h: No such file or directory”.

So this thing, “Servo.h.” That’s the thing we need to fix, and thanks to line 2, we know where to find it. Line 10. It’s always line 10.

Now that we know what’s going on a bit better, let’s get down to the business of implementing a fix.

The error of our ways

Let’s lay down some scrutiny on this accursed line 10.

It says “

include

When we verify this code, this line is telling the Arduino IDE compiler, “Hey, for this program to work, you need to go get this file called servo.h”.

Let’s say you had a label-making machine, and you wanted to use it to print some cool motivational labels, like “Success!” and “Keep Trying!” and “Look, Nachos!” To make that happen, you’ll first have to load in a roll of labels. No roll of labels? Well, then the label maker isn’t gonna work.

The sketch you’re trying to upload is like the label maker. The file (in our example, the file named “servo.h”) is the roll of labels.

Lỗi interrupt does not name of a file năm 2024

So the error message actually is saying something useful. It’s saying, “Hey programmer, you said I needed this other file. Well, I looked for it and it’s not there. What gives?”

Now we know the error message isn’t complete gibberish, let’s look at the two most common scenarios that cause it.

Scenario 1 – Fat fingers

This sketch is one that you’ve written. You’re actually the one who wrote the “

include” line. The first thing you should check is your spelling and capitalization. Maybe you spelled the name of the library incorrectly? Or (as with the example below) perhaps you capitalized the wrong letters.

Lỗi interrupt does not name of a file năm 2024

So “servo.h” should actually have a capital “S.” In full and with correct capitalization, it should read, “Servo.h.” You’ll notice above that the word servo changes color when it’s correctly capitalized. That color change signifies that the library name “Servo” is recognized as a “keyword” in the Arduino IDE.

Keep in mind that might not be the case for all the libraries you’re using. In other words, the color change won’t always indicate you’re using the right spelling or capitalization, but it’s often a helpful visual reminder.

Oh, and it’s probably good to mention that everyone in the history of Arduino programming has misspelled or incorrectly capitalized a word at some point. It’s amazing how long you can stare at a line of code and miss something like that.

So don’t sweat it.

Scenario 2 – Missing files

This brings us to the next common scenario for the “no such file or directory” error.

So often, working with Arduinos involves taking code that someone else has developed and shared online and then tailoring it to your project. That’s part of what makes it so easy to get stuff done with Arduino. One problem that frequently happens when we do that, however, is we accidentally introduce code without a matching file.

An easy way to check to see if you have the file a sketch is looking for is to navigate to Sketch > Include Library from within the Arduino IDE. Then look for the name of that library.

Lỗi interrupt does not name of a file năm 2024

Whatever library the

include statement was calling for, you want to look through this big long list for a library with the exact same name. If you don’t see the file name there, this means the library isn’t installed. You’ll have to add that library before the sketch will compile without errors.

So, how do you add that library?

The easiest way is to go to Sketch > Include Library > Manage Libraries. The Arduino IDE will open up a dialogue box from which you can search for the library you need.

Lỗi interrupt does not name of a file năm 2024

Make sure you type the exact word that matches the

include line. Once you find the missing library, go ahead and click Install. The Arduino IDE will let you know that it’s installing the library you requested and updating the software accordingly.

Next, just double-check that the library has been successfully installed by going to Sketch > Include Library. You should see your new library in the dropdown list.

Good news! If the library is there, you should now be able to compile your sketch error-free.

Other library locations

OK, there’s one little fly in the ointment. How do these dang ointment flies always manage to complicate things so?

Here’s the thing. Not all libraries live in this convenient pop-up window inside the Arduino IDE. The Arduino community is bubbling with clever ideas, but cleverness (unlike processed cheese) doesn’t always come in conveniently standardized, individually wrapped slices. There are tons of different ways to find Arduino libraries on the web.

If you’re downloading or copying a program from the internet, just go to the page where you got that program and take a close look at the library the author is referencing. They may, for example, have a link to GitHub, which is a place where people keep a lot of code libraries.

Lỗi interrupt does not name of a file năm 2024

Wherever you find it, usually the library will be included in a .zip file package. Once you’ve downloaded the .zip file, fire up the Arduino IDE and go to Sketch > Include Library > Add .ZIP library. Then navigate to the location you downloaded the file and select it. Assuming no additional ointment flies invade your workflow, the Arduino IDE will pop up the message “Library added to your libraries” just above the dark area where the original “no such file or directory” error appeared.

Now it’s business as usual! Just go to Sketch > Include Library, and the new library will appear in the drop-down list.

As the dyslexic Frenchman once said to the oversized violinist: “Viola!”

You now know not one but two ways to add a new library. What a time to be alive!

Review

A quick recap, then.

We’ve looked at the two main scenarios that cause the “no such file or directory” error to appear after you compile your sketch:

  • The fat fingers phenomenon: Check your spelling and capitalization! If you wrote the sketch, there’s a mighty good chance you introduced a tiny error. And don’t beat yourself up over it! Literally every coder has done this.
  • The missing files mixup: Failing that, if you copied code from someone else check that you have the correct libraries installed. Don’t see your library? Install it using the method described above, and you should be good to go.

There may be no such thing as a free lunch, a coincidence, or a luck dragon. But rest assured. Your files and directories? They’re alive and well.