Today's blog post once again comes from our technical support team. The reason is the notification of several customers who receive the error "error: stray '/ 302'" or "error: stray '\ 240' in program" when compiling in the ArduinoIDE, I would also like to introduce a feature in Notepad ++ that is interesting for beginners .
This error occurs among others when the copied sketch is loaded into the Arduino IDE with the wrong coding. For computer scientists, these problems are "part of the daily routine" and are clarified at the very beginning of the training. As a pure user, you have very few contact points with the coding of files.
Since the encoding of characters is a rather extensive topic, I just want to show you today how to get the errors from the ArduinoIDE so that the (copied) sketch runs through.
So let's start with the ArduinoIDE by copying, compiling and getting the error message shown above.
In the ArduinoIDE there is the option in the Tools menu to carry out an automatic correction, which you can find here:
After executing this menu item we already see part of the problem:
Trying to simply search for the characters with Ctrl + F and not replacing with anything will delete the "special characters", but will not lead to success.
We use today Nodepad ++ to clear out the source code and change the coding. Notepad ++ is a fairly simple and efficient program that is available for free download. In my opinion, a very good and extensive text editor that is easy to use and comfortable to use.
After the download and installation, we can directly paste the code copied with CTRL + V:
In the menu we have the option to convert the encoding, but after a few tries we find problems with it and quickly get to the troubleshooting. First we make sure that UTF-8 is selected, like here in the picture:
Then we change the selection to "ANSI":
With the "Find and Replace" function we can remove these characters quite quickly, please note that Space before and after the "special character" to copy:
However, if we copied the code now, the error would reappear in the IDE. To prevent this, we set the coding around menu back to UTF-8 and see:
To remove these characters, we use a great feature of Nodepad ++: the block selection. To do this, hold down the ALT key and drag a frame around the characters to be removed:
The blocks marked in this way can be deleted quite easily:
An indispensable tool for beginners, for example to process log files efficiently or to be able to handle text files without Excel or script knowledge.
If you have removed all blocks, you can copy the prepared code back into the ArduinoIDE.
Now a little beauty correction, the automatic formatting:
Here is the result:
So we have arrived at the end of today's article and look forward to the next post :) See you later