Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Hot answers tagged

35

It should be possible as long as the security bit isn't set. This question was asked on EE a while back. Is it possible to extract code from an arduino board? But you won't get the Arduino code you wrote back. The code is compiled into assembly and you'll have to convert that back to C yourself.


28

Know this is old but I ran onto it during my search for Nano(V3)'s not uploading so thought might help someone else. Problem is the bootloader - Arduino IDE BUT I Found an easy solution (right under my nose). I realized that my nano's had been uploading just fine then I had finally updated the Arduino AVR Boards from 1.6.20 to 1.6.21. I didn't think ...


20

This answer doesn't directly answer the question, but still will result in the same end result. The Arduino IDE uses temporary directories to store build files, including the original sketch as well as the HEX and intermediate files. On a Mac, these are in /var/folders by default, and on a Windows machine they are in …\Local Settings\Temp\ (which depending ...


20

First, let's see a few examples of what can go wrong. Uninitialized local variables void setup() { int status; pinMode(13, OUTPUT); digitalWrite(13, status); } As pointed out by Edgar Bonet in the comments, local variables like status in the code above are not implicitly initialized by the C++ compiler. So, the outcome of the code above is ...


12

You second code may be smaller in size but due to the function call overhead the max execution speed is reduced. Does this matter in your case? No, because you have huge delays anyway, but if the code was an actual series of repeated calculations that should be executed as fast as possible then it would make a difference. As a general rule, smaller code is ...


11

Yes and no. You're kinda vague on what you want to do. I've made this into a few different sections (mainly focused on reading sensor data... it applies to everything but that's the context I'm using): Threads AFAIK all Arduinos only have one core (they can do one thing at once). For most Arduino boards, hardware multithreading isn't supported. However, ...


10

First off, a sketch that uses Serial cannot really be considered an empty sketch as Serial drags along a lot of function definitions, at least one Serial class instance (more on Arduino Mega, for instance), plus probably some more global variables... sizeof Serial may be interesting to display as Serial is not limited to the TX and RX buffers, as you seem ...


9

There are no runtime exceptions. There is only undefined behaviour. Really, there are no exceptions at all. If you try to perform an invalid operation, it's results will be unknown. There is no runtime checking at all, except what you implement. Your program is running on bare-metal hardware. It's the Desktop equivalent of running in ring-0 all the time, ...


8

This schematic shows a complete connection of a blinking led. Red cable = +5V (pin 8) White cable = Ground (pin 4) Resistor = 1 end at pin 5 (IO 0) and the other in the LED anode (+) Led anode (+) in the resistor, cathode (-) (small leg) in the ground Resistor = 330 Ohms The arduino in the picture is not necessary, just used to give power. But in the video ...


8

Can we read and get C codes from compiled codes from Arduino hardwares? While it is possible, even trivial, to disassemble machine code, it is very difficult to convert the assembly code into a higher-level language, and essentially impossible to turn it back into an exact copy of the source code it came from. There simply isn't enough information in the ...


7

Generally speaking, smaller is better. However, there is a point where too small actually makes the program run slower. My suggestion is if you are working on a sketch and it is blatantly obvious that you are repeating code over and over again, I would rip that out and put it into a function, not only does it make the program smaller, it makes it easier to ...


7

This variable: String utcDateString = ""; Is a C++ String, not a character array like sprintf() is expecting. To convert this string to a character array such that sprintf is expecting, you must use .c_str() in your sprintf, i.e.: sprintf(foo,"This is a format for %s", utcDateString.c_str()); Doing this should prevent the sprintf line from causing a ...


7

Short answer: No; From the atmega328's data sheet (though it applies to all AVR's): AVR uses a Harvard architecture – with separate memories and buses for program and data. Instructions in the program memory are executed with a single level pipelining. While one instruction is being executed, the next instruction is pre-fetched from the program ...


7

I investigated this at some length a while back. On this page about putting constant data into program memory I obsessively tracked down every last byte of memory used in a small sketch. This was the sketch: #include "memdebug.h" void setup () { Serial.begin (115200); Serial.println (); Serial.print (F("Free memory = ")); Serial.println (...


7

Okay, here is how it works, and I checked it to make sure. Sure you can use hard paths, but every programmer hates using hard paths. They are not portable at all, and they lock your program in place. You use soft or hard links to the files in the project (look up the man pages on "ln"). But,... talk about ugly! So the question is how to do it "correctly"? ...


7

## is the concatenation operator in macros. It joins two macros or pieces of text together when expanded. #define _SET_INPUT(IO) do {DIO ## IO ## _DDR &= ~MASK(DIO ## IO ## _PIN); } while (0) _SET_INPUT(3); woukd expand to: do {DIO3_DDR &= ~MASK(DIO3_PIN); } while (0); You can read more about how it works here: https://gcc.gnu.org/onlinedocs/...


7

The standard (but not very good) solution is to seed the random number generator from an analogRead() on an unconnected pin. For better options, see this answer to a related question.


6

Since you already know how to hook up a pot and read it's value, it's quite simple. You already have it hooked up in a voltage divider configuration and are getting a 10 bit (0-1023) value using analogRead(), you just need to decide what to do with it. Assume potVal has the value of the pot.; if (potVal < 256) { // Pot is one quarter turn or less } ...


6

There is one mechanism that can get MCU from erratic state and it's the watchdog timer. If you're implementing some code that will repeatedly run in a loop, that will not run anytime longer than some fixed time, you can set this time as watchdog period and enable the timer. Then, you have to repeatedly reset the timer in the loop. If your code freezes at ...


6

Ignacio Vazquez-Abrams has already outlined the schematics. There must be a C program compiled and uploaded to it, just like an Arduino board would have. There are however some differences between a fully equipped Arduino board with an ATMega328P and a bare ATtiny85 you would have to care for in your code: A bare ATtiny85 runs at 1 MHz (8 MHz internal ...


6

Adding hysteresis behavior to your code is not difficult. You just need to store the state you're in and make the thresholds for transitioning into another state dependent on that. You can use an enum to store the state: enum BatteryStates { Red, Orange, Green }; Then, instead of defining and checking against one threshold value, define two thresholds ...


6

It does four things, basically: It adds #include <Arduino.h> to the top of your file, which gives you access to all the classes, functions and defined variables/macros of the API. It joins together all the INO files together into a single monolithic file (in the same order as the tabs in the window), It matches #include entries with libraries and adds ...


6

Equality comparison in C and C++ is expressed by == operator. ==, not =. This if (wavecolor = 0) { actually assigns zero to your wavecolor variable, thus destroying the value you just read. The common sense says that you actually need and in your conditions, not or if (wavecolor > 0 and wavecolor < 333) { The or conditions that you curently use ...


5

This error message basically shows up for any communication problem, so by itself, it is not all that instructive. The Arduino Nano is supposed to have auto-reset, but maybe your clone does not? In that case, you'd have to press the reset key on the board just before starting an upload.


5

You'd need a hardware debugger for something like this. But usually you'll see the program not behaving as you expect it to and will have to look at that section of the code to identify the problem. A common/quick/easy way to do this is to add print statements to print out the values of variables or just anything so you know the program gets to that point ...


5

No. The foundation of a Harvard architecture such as AVR is to only allow code that exists within program space to be executed, and EEPROM is not within program space. It is possible, however, to write a virtual machine that will run from flash. This VM can then read program-become-data from anywhere and take action based on it.


5

You have two #define statements at the top of your code #define trigPin 3; #define echoPin 2; The way #define works is that it replaces every instance of the name with everything after it on the line so trigPin is being replaced with 3; as opposed to 3 as intended. Fixing this should solve some of your problems.


5

Here is the absolute minimal schematic required to blink a LED beyond power and decoupling: Refer to "Which resistor to use for this LED" to calculate the appropriate value for R1.


5

They are the conditional operator. If the expression before the ? is true then the result is the expression before the :, otherwise it is the expression after.


5

Lean the proper C syntax. This is completely wrong: void gf() int a = f;//test the conditions of f and store in new variable int a { And this is just as wrong for the same reasons: void ei() int k = 3 int a = Serial.read(); {digitalWrite(k, a);}


Only top voted, non community-wiki answers of a minimum length are eligible