Arduino IDE 2.0 read-only editor issue

Hi, I like the Arduino environment but the latest version 2.0.0 gives me a headache. I can not edit my own source code any more. (platform is a Windows 10 PC)

Steps to reproduce:

  • Start Arduino IDE 2.0.0
  • Select BBC micro:bit V2
  • File->New Sketch opens as expected. I can edit, no problem.
  • File->Save (leaving the suggested filename, no change)
  • Unexpected behaviour: sketch editor is now in Read Only mode ? I can not edit my own, newly created sketch. Is this a bug or a new special trick I need to do ?

Kind regards, Rob

Welcome to the forum

Can we assume that all is OK with version 1 of the IDE ?

What is the full path to your sketchbook folder ?

Yes, version 1.8 works good. Maybe it has to do with the fact that I have my Documents folder on a non standard location ?

D:\documents\Arduino

(the reason for that is that my d: drive is much bigger than my c drive)

That location was no problem with version 1.8.

Locating your sketchbook folder on drive D: should not cause a problem. The reason that I asked was that I have seen reports of problems where people used OneDrive

Hi @rouderaa42

When you say "Read Only mode", do you mean that a " Cannot edit in read-only editor " tooltip appears any time you attempt to type in the editor?

image

Or are you seeing something different from that?

Does the problem also occur if you save the sketch to your C: drive?

I did an additional test with doing a 'save as..' to the standard windows directory : C:\Users<username>\Arduino This gives no 'read-only' tooltip problems. So could it be that the IDE 2.0 decides on being read-only if the filename path does not contain the windows user path c:\users<username> ? If that is the case, maybe it would be another idea to being read-only if the 'libraries' entry is present in the full path ?

Why speculate when it would only take a few seconds for you to find out?

Save the sketch to a path that does not contain the Windows user path and then comment here to let us know your findings.

:slight_smile:

That is indeed puzzling. The only similar report I am aware of is this:

The IDE is designed to treat any file from outside the sketch folder as "read-only". This is done to prevent the user from accidentally modifying library, core, or toolchain files opened via the " Go to Definition " or " Peek Definition " features, which would result in very confusing bugs.

In the bug report above, I believe the symlink makes the IDE think the files are outside the sketch folder (likely one of the two paths is being resolved to its true location on the file system).

So there might be something special about your 'd:\Documents\Arduino that causes some similar confusion in the IDE.

Note that the "read-only" I refer to is completely unrelated to a read only file attribute set in the file system.

Thank you for your help and feedback. I had a look at compiling the Arduino IDE to debug this problem but that is not an easy task for me. So I am going to use the workaround of using the 'd:\Arduino' directory that I created and that resolves this issue for me.

If you are interested in building the Arduino IDE from source, I would be happy to help you out with that. There are some instructions here:

https://github.com/arduino/arduino-ide/blob/main/docs/development.md

I'll be the first to say those instructions need improvement. This is something I plan to work on, but have been having trouble finding the time to do so.

If you want to play around with debugging the IDE, you might be interested to know that it has a built-in debugger. This is available even in the normal IDE distribution you already have installed. So you can use that even if you don't manage to build the IDE from source.

I'll share the instructions for the basic use of this debugger:

  • Press the Ctrl + Shift + P keyboard shortcut ( Command + Shift + P for macOS users) to open the " Command Palette ".
  • Run the " Toggle Developer Tools " command. The " Developer Tools " panel will open on the left side of the Arduino IDE window.
  • Select the " Sources " tab from the Developer Tools panel.
  • If it is not already open, click the " Show navigator " icon on the left side of the " Sources " tab toolbar to open the " Navigator " panel.
  • Select the " Page " tab from the the " Navigator " panel on the left of the " Developer Tools " panel.
  • Select top > file:// > <IDE installation URI> > bundle.js from the " Navigator " panel.
  • The Arduino IDE UI will now hang for a while. Wait for it to become responsive again.
  • Click the ⋮ icon on the " Developer Tools " panel toolbar.
  • Select " Open file " from the menu.
  • From the menu that opens, select the source file where you want to set a breakpoint.
  • Click on the left gutter at the line that contains the code of interest to add a breakpoint.
  • Deselect the " Deactivate breakpoints " icon if it is selected.
  • Trigger the action in the Arduino IDE that will execute that line of code. The execution will pause when it hits the breakpoint. You can hover the mouse over the variables to see their values. You can use the " Resume script execution ", " Step over ... ", " Step into ... ", " Step out of ... ", " Step " buttons in the widget on the right of the " Developer Tools " panel.
  • When finished debugging, select the " Deactivate breakpoints " icon.

Try opening Arduino IDE to run as administrator. I experienced the same issue and this got me by until I can sort it out.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

Related Topics

Makeblock Forum

Problems uploading

I cannot upload my mblock programs to the arduino board. It happens with all the programs that I’ve tried. Mblock is connected and mLink2 open. I cannot undestand what the problem is. The message that appears says Failed to compile file code.cpp

Arduino compile fail

Arduino server disconnected.

The whole message: It appears: Command failed: avr-toolchain/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I"/app/src/external/arduino/avr-library/variants/standard" -I"/root/mblock-avr/temp/build" -I"avr-library/cores/arduino" -I"arduino-libraries/makeblock/src/" -I"arduino-libraries/makeblock/src/utility/avr/" -I"avr-library/libraries/Wire/src/utility/" -I"avr-library/libraries/Wire/src/" -I"avr-library/libraries/EEPROM/src/" -I"avr-library/libraries/SPI/src/" -I"avr-library/libraries/SoftwareSerial/src/" -I"arduino-libraries/arduino/WiFi/src/" -I"arduino-libraries/arduino/SD/src/" -I"arduino-libraries/arduino/Bridge/src/" -I"arduino-libraries/arduino/Temboo/src/" -I"arduino-libraries/arduino/Servo/src/" -I"arduino-libraries/arduino/Ethernet/src/" -I"arduino-libraries/arduino/TFT/src/" -I"arduino-libraries/arduino/SpacebrewYun/src/" -I"arduino-libraries/arduino/LiquidCrystal/src/" -I"arduino-libraries/arduino/GSM/src/" “/root/mblock-avr/temp/build/code.cpp” -o “/root/mblock-avr/temp/build/code.o” /root/mblock-avr/temp/build/code.cpp:15:7: error: conflicting declaration ‘float A0’ float A0 = 0; ^~ In file included from avr-library/cores/arduino/Arduino.h:257:0, from /root/mblock-avr/temp/build/code.cpp:1: /app/src/external/arduino/avr-library/variants/standard/pins_arduino.h:65:22: note: previous declaration as ‘const uint8_t A0’ static const uint8_t A0 = PIN_A0; ^~ /root/mblock-avr/temp/build/code.cpp: In function ‘void setup()’: /root/mblock-avr/temp/build/code.cpp:27:39: error: assignment of read-only variable ‘A0’ A0 = (1 + analogRead(A0+0) / 100); ^

Failed to compile file code.cpp

What codes are you uploading and what arduino are you using?

Captura%20de%20pantalla%202023-08-25%20145929

The error message says that there is a conflicting declaration of the variable A0 in your code. The variable A0 is already defined as a constant in the Arduino library, but you are trying to assign a new value to it.

To resolve this issue, you need to choose a different variable name for your A0 variable. Here’s an example of how you can modify your code:

Basically, you just need to rename your variable.

After making this change, please try uploading your mBlock program to the Arduino board again to see if the issue is resolved.

Itsourcecode.com

Valueerror assignment destination is read-only

One of the errors that developers often come across is the ValueError: assignment destination is read-only .

This error typically occurs when you try to modify a read-only object or variable.

What does the ValueError: assignment destination is read-only error mean?

Please enable JavaScript

Humix

This error occurs when you try to modify a read-only object or variable in your code. The error message indicates that the assignment destination is restricted to being read-only.

How the Error Occurs?

These are the following examples of how the error occurs.

Example 1: Modifying an Immutable Tuple

  • The code creates a tuple called “my_tuple” with the values 1, 2, and 3.
  • Tuples are immutable, meaning their elements cannot be changed once they are created.
  • The line “my_tuple[0] = 10” attempts to modify the value at index 0 of the tuple to 10, which is not allowed and will result in a valueerror.

Example 2: Attempting to Modify a String

The code attempts to change the first character of a string but produces a valueerror because strings cannot be directly modified.

Example 3: Assigning to a Constant

The code example attempts to assign a new value (3.14) to the constant math.pi in Python.

However, in Python, constants are typically immutable and cannot be modified once defined.

Therefore, this code will likely raise a valueerror .

Example 4: Altering an Immutable Data Structure

This code example demonstrates how to modify a value in an immutable data structure in Python.

It starts with a dictionary called “ my_dict ” that has a key-value pair of ‘ key ‘ and ‘ value ‘.

The code then changes the value associated with the ‘key’ to ‘ new_value ‘ by assigning it directly using indexing.

Solutions for ValueError: assignment destination is read-only

Here are some solutions to solve the ValueError: assignment destination is read-only:

Solution 1: Use Mutable Data Structures

Instead of using immutable data structures like tuples or strings, switch to mutable ones such as lists or dictionaries.

Mutable objects allow modifications, eliminating the read-only error.

For example:

Solution 2: Reassign Variables

If you encounter the valueerror while attempting to modify a variable, try reassigning it with a new value.

This method can help you resolve the read-only restriction.

Solution 3: Check Documentation and Restrictions

In some cases, certain objects or variables are intentionally designed to be read-only.

It’s important to consult the documentation or source code to understand any restrictions required.

Make sure that the object you’re attempting to modify is meant to be changed.

Solution 4: Use a Copy or Clone

If the object you’re working with is meant to be read-only, consider creating a copy or clone of it.

By doing this, you can modify the duplicate without affecting the original read-only object.

Solution 5: Identify Context-Specific Solutions

The ValueError: assignment destination is read-only error that can be context-specific.

Analyze the specific context where the error occurs and seek solutions to that scenario.

Understanding the possible cause will aid in finding a proper resolution.

Solution 6: Seek Help from the Community

If all the solutions are not working, don’t hesitate to reach out to the programming community for assistance.

Online forums, developer communities, and platforms like Stack Overflow can provide valuable insights and guidance from experienced programmers.

Frequently Asked Questions

To resolve this valueerror, you can apply different solutions such as using mutable data structures, reassigning variables, checking documentation and restrictions, using copies or clones, identifying context-specific solutions, or seeking help from the programming community.

The error arises because the variable you are attempting to modify is marked as read-only. It could be intentionally designed this way or due to a restriction imposed by the programming language or framework you are using.

In some cases, you can convert a read-only object into a writable one by using techniques like creating a copy or clone of the object. However, this depends on the specific context and the restrictions imposed on the program.

Yes, there are similar errors that you may encounter in different programming languages. For example, in JavaScript, you might encounter the error TypeError: Assignment to a constant variable when trying to modify a constant.

The ValueError: assignment destination is read-only error can be encountered when attempting to modify read-only objects or variables in your code.

By following the solutions provided in this article, such as using mutable data structures, reassigning variables, checking restrictions, making copies or clones, considering context-specific solutions, and seeking community help, you can effectively resolve this error.

Additional Resources

  • Valueerror: could not convert tuple of form to variable
  • Valueerror unconverted data remains
  • Valueerror index contains duplicate entries cannot reshape

Leave a Comment Cancel reply

You must be logged in to post a comment.

IMAGES

  1. Variables in Arduino programming (Simplified Tutorial)

    error assignment of read only variable arduino

  2. How to Use Arrays in Arduino Programming

    error assignment of read only variable arduino

  3. Arduino Programming: Variables

    error assignment of read only variable arduino

  4. Arduino Programming: Variables

    error assignment of read only variable arduino

  5. Compile error at upload or verify in arduino ide

    error assignment of read only variable arduino

  6. Explain how to fix 'variable must be const'

    error assignment of read only variable arduino

VIDEO

  1. New arduino nano uploading error problem and Arduino nano drive problem solved (#circuiteffects)

  2. 10/113 Declare a Read-Only Variable with the const Keyword

  3. error: assignment of read-only variable

  4. Cannot edit in read-only editor problem in vs code solved

  5. readonly in c# in hindi

  6. TypeError: Assignment to constant variable SOLVED Javascript

COMMENTS

  1. Assignment of read-only variable error

    Hi, so recently I just made this project but it doesn't seems to work.. it kept on saying the same thing, and that is "Assignment of read-only variable 'VAL'. I don't know what to do, so please check the code below and see if you can help me. const int A = 13; const int B = 12; const int C = 11; const int ON = 500; const int OFF = 0;

  2. assignment of read-only variable

    I understand that local variable turns 0 after leaving function, but I cannot find what to do to keep its value. Globals did not help. The answer to part 1 is to make the variable static. The answer to part 2 is to write the code properly. If making a variable global didn't work, for some definition of work, you are doing something else wrong.

  3. Error compilación, assignment of read-only variable

    Arduino:1.8.4 (Windows 10), Tarjeta:"Arduino/Genuino Uno" C:\Users\Andrés Poveda\Documents\Arduino\proyecto_ciencias\proyecto_ciencias.ino: In function 'void loop()': proyecto_ciencias:23: error: assignment of read-only variable 'z' proyecto_ciencias:24: error: assignment of read-only variable 'w' proyecto_ciencias:25: error: assignment of ...

  4. arduino

    TalkingClock:71: error: variable 'ampm' must be const in order to be put into read-only section by means of 'attribute((progmem))' ampm[] = { am, pm }; exit status 1 variable 'hours' must be const in order to be put into read-only section by means of ' attribute ((progmem))'

  5. Error message

    Apparently not... But since you gave me a push in that direction.. I will expand my limited knowledge of its use and meaning.. Thanks

  6. Using Variables in Sketches

    A variable has other advantages over a value like a number. Most importantly, you can change the value of a variable using an assignment (indicated by an equals sign). For example: pin = 12; will change the value of the variable to 12. Notice that we don't specify the type of the variable: it's not changed by the assignment.

  7. Variables

    Variables. A variable is a place to store a piece of data. It has a name, a value, and a type. For example, this statement (called a declaration ): int pin = 13; creates a variable whose name is pin, whose value is 13, and whose type is int. Later on in the program, you can refer to this variable by its name, at which point its value will be ...

  8. C++ error: assignment of read-only variable

    In your code you set up the parking variable with a const, this is telling the compiler that it will not be modified later.You then modify parking later by setting it to true or false. Using std::string is far more idiomatic c++ though. So I would do this instead:

  9. arduino uno

    I am a beginner in using Arduino and programming in c/c++. I am trying to connect a 10-segment LED and a moisture sensor to my Arduino Uno, and when the moisture level is very low, the first 2 red ...

  10. c++

    2. Your first problem, the one the compiler is reporting, is that by default the value of local variables is what is captured by a block - which means the local variable cannot be modified by the block only its value used. If you add the __block modifier to a local variable then a block will capture the variable - which means the block sees the ...

  11. PDF 1 Introduction 2 Basic Variable Operations: De ne, Assign, and Recall

    and all text to the end of the line is ignored by the Arduino IDE. The text is only there for humans to read. Note that we did not write int LEDpinRed = 5; // red LED which has a comment statement that does not add any information about the purpose of the pin assignment. The name of the variable conveys the idea that this pin probably has ...

  12. Arduino IDE 2.0 read-only editor issue

    From the menu that opens, select the source file where you want to set a breakpoint. Click on the left gutter at the line that contains the code of interest to add a breakpoint. Deselect the " Deactivate breakpoints " icon if it is selected. Trigger the action in the Arduino IDE that will execute that line of code.

  13. Making Arduino UNO read-only

    you could disable the reset connection between the USB interface chip and the ATMEGA. This would make it a lot harder to get into the bootloader which is used to download new sketches. on an UNO specifically, you could reflash the USB interface micro to disable it entirely, or just remove the code for manipulating the reset line (if you still ...

  14. Assigning value to readonly variable during declaration

    Generally though, you'd want to use. readonly c="$(( a + b ))" i.e. quoting the expansion. If the variable IFS has a value that includes the digit 2, it could otherwise lead to an empty value in c. The value would be empty as the shell would have split the arguments to readonly on the 2, resulting in the command. readonly c=.

  15. Problems uploading

    Here's an example of how you can modify your code: myA0 = (1 + analogRead(A0 + 0) / 100); // Rest of your setup code. // Your loop code. Basically, you just need to rename your variable. After making this change, please try uploading your mBlock program to the Arduino board again to see if the issue is resolved.

  16. [SOLVED] Valueerror assignment destination is read-only

    Solution 4: Use a Copy or Clone. If the object you're working with is meant to be read-only, consider creating a copy or clone of it. By doing this, you can modify the duplicate without affecting the original read-only object. For example: my_tuple = (1, 2, 3) my_modified_tuple = list(my_tuple) my_modified_tuple[0] = 10.