Hot answers tagged

12

int, long, etc have different sizes depended on the compiler and target. Use explicit sizes to make sure you're variables have the size you want. Eg. uint8_t, int16_t or int32_t, ... (as @Mat commented) Also, I wouldn't use bool (if writing in C) as it's not really standard in C and the size is also implementation dependent: https://stackoverflow.com/...


12

There are three main issues you may need to deal with when passing structures between systems that use different processors. The first is that data types vary in size between architectures. You can avoid this for integers by avoiding the basic C types and instead using the fixed size types from stdint.h/cstdint. For floating point types this is less of a ...


11

Say you have a string of 1000 characters in Flash, and you want to print it to Serial. Yes, you need to load it into RAM in order to pass that data around the place for printing. But, do you need to put all of it in RAM at once? No. You only need one character at a time. So instead of taking 1000 characters and allocating 1000 bytes of RAM and copying ...


9

There is a lot you are missing. Such as: SoftwareSerial is using RAM. The system stack is using RAM. The Arduino core software is using RAM. There's plenty more going on than just your sketch. For instance, where do you think it stores the current millis() and micros() counts? Where do you think incoming serial data gets buffered? Where do you think your ...


9

The Arduino EEPROM library is compatible with the ATTiny range of AVR microcontrollers as the library itself is built on the standard Atmel AVR avr/eeprom.h 'library' so it is compatible with all the AVR microcontrollers. The EEPROM also doesn't take to being written or read to often as EEPROM can wear very quickly. Reading though does not cause much damage ...


9

There are several "Arduinos" with memory capacities ranging from slightly less than 32k/2k/16MHz (Flash/RAM/CPUClock) ("Uno") to 512k/96k/84MHz ("Due".) In addition, there are "mostly compatible" boards that expand that range down to less than 8k/512/8MHz ("Gemma", "Digistump") and up to about 1M/256k/120MHz (TI "EK-TM4C1294XL Launchpad"), and "somewhat ...


9

You can decipher most of them yourself. A u prefix means unsigned. The number is the number of bits used. There's 8 bits to the byte. The _t means it's a typedef. So a uint8_t is an unsigned 8 bit value, so it takes 1 byte. A uint16_t is an unsigned 16 bit value, so it takes 2 bytes (16/8 = 2) The only fuzzy one is int. That is "a signed integer value at ...


9

In addition to the rule of always using fixed and predictable sizes across different architectures, it's also a good idea to pack your structs. This prevents the compiler from padding smaller variables with blanks to align them with the architecture's word boundary when needed. For example: struct Package { uint8_t doorOpened; uint16_t light; ...


8

That is an incredibly hard question to give a definitive answer to. In general using OO consumes more memory, but that is the price you pay for greater flexibility and ease of use. The difference is usually minor though. Variables within an object take the same amount of space as variables outside an object. It's just the overhead of instantiating the ...


7

There is no DRAM, SRAM nor flash interface in ATmega, so you can't extend your chip memory. You can only connect serial (SPI, I2C) or parallel memory (usind GPIO). Neither SPI nor I2C require any specific libraries. SPI is much simpler to program than I2C and much faster, but require more wires. Instead of using rather slow EEPROM, you can try FRAM (non-...


7

The microcontroller is executing one command at a time from..where? Flash memory directly. The AVR core can only execute instructions from Flash memory. It uses a two-bus system known as Harvard Architecture, where the Instruction Bus is connected to Flash and is used to execute instructions, and the Data Bus is connected to SRAM, EEPROM, all the ...


7

In general only the functions actually used by your code are included in the final linkage of the binary. However it's not always possible for the compiler to know what is used and what isn't. In the case of simple functions and classes there's no problem - the linker is intelligent enough to work it out and only link in the functions that are actually used. ...


6

const means different things in different contexts as far as storage goes. For a simple numeric value the compiler will generally replace the constant with the literal value. Any mathematics using purely constants or literals will be replaced at compile time with the result. For instance, the code: const int a = 3; const int b = 4; void setup() { int ...


6

String is not a simple type like an int or a char. It is a class with many member functions and, more importantly, operators. When you create the object it allocates room for that object either on the stack (for a local variable) or in the global data area if it's a global variable. However that object doesn't contain the memory used to store the actual ...


6

Isn't the space taken up by the local variable supposed to be freed up from the SRAM once the functions runs because I have declared the variable locally? This is correct. The local arrays you have take up RAM only while the corresponding function is executing. They do not consume any static RAM (i.e. .data and .bss, what the Arduino IDE improperly ...


6

CPU temperature Some Arduino boards have a microcontroller with a temperature sensor inside. For example the Arduino Uno can measure the temperature inside the microcontroller. As far as I know, no one uses it. It is not accurate and a microcontroller should not get hot in the first place. The microcontroller or processor on the Arduino board can run at ...


6

I am afraid there is no good solution to this problem. One option I do like is to use the __flash qualifier instead of PROGMEM: const uint8_t ram_array[] = { 1, 2, 3, 4 }; __flash const uint8_t flash_array[] = { 5, 6, 7, 8 }; void function_reading_ram(const uint8_t *array) { uint8_t secondElement = array[1]; // ... } void function_reading_flash(...


5

Personally I like the Amtel 24C256 chip/module. It is I2C enabled and the standard Wire library is all you need to talk to it. It is 256 bits or 32K 8 bit bytes in size. Data is sent and read in byte chunks. Addressing is at the bit level. It can run on 3.3V and 5V. Ebay has a bunch of suppliers for it. There's a number of good How-To's on line.


5

Some things I noticed in your code: You are writing everything to the same address (is that intentional?) You are only writing the first 6 six bytes of your arrays (I am pretty sure that is intentional) You are declaring these arrays to be bigger than what you are putting in them (this is again probably intentional, but I am just guessing) So here is an ...


5

No. There is no external memory interface on the ATmega328P, so all external memory requires some sort of library to use.


5

Reserving space will help reduce memory fragmentation, but much of what else you are doing is swamping that small improvement you have made. The biggest area of concern is your cutString function, which you have omitted from your code above. Passing a String as a parameter, modifying it, and then returning it again, ends up in new String objects being ...


5

Interesting. If you want hex you have to tell it to print in hex. If I change your display line to: Serial.println(displayInt, HEX); Then I get: 940C 3594 35 C00 940C Compare this to what the decompiled file looks like: 0: 0c 94 35 00 jmp 0x6a ; 0x6a <__ctors_end> 4: 0c 94 5d 00 jmp 0xba ; 0xba <__bad_interrupt> 8:...


5

You must declare the array in global space or static, and make sure the function you pass the buffer pointer to knows it is in PROGMEM. void send22() { static unsigned int irSignal[] PROGMEM= {8988, 4548, 572, 1688, 572, 1688, 600, 532, 572, 568, 572, 572, 576, 572, 572, 580, 572, 1724, 544, 556, 576, 1684, 600, 1660, 608, 532, 604, 540, 608, 540, 600, ...


5

You can quite easily connect multiple 128kB SPI ram chips to an Arduino. 4 of them together would give you 512kB of extra SPI-connected SRAM. Access isn't super fast. Another option is to use a parallel 8-bit SRAM chip. These take a lot more wiring since you need 8 wires for the data, log2(n) wires for the address, plus a couple of control wires (OE, WE, ...


5

Knowing the stack size is pretty easy: the stack pointer is initially set to RAMEND and goes down as the stack grows. Thus: static inline size_t stack_size() { return RAMEND - SP; } should I add this in 'strategic' locations [...] Obviously, the result will depend on where this is evaluated. Ideally you should test this in the deepest parts of your ...


5

Initialize the entire SRAM space from the top of the heap to the bottom of the stack, either during setup, or in a modified version of the Arduino-provided main() function, with some unlikely pattern, such as {0x55, 0xAA, ...} or "UnusedUnused...". After your program has run a while, examine memory for dirty footprints, reading up from the top of heap to ...


5

On the ESP8266 there's very little to choose from between the two. It all really boils down to what you want to store and how you best want to access it. EEPROM emulation is ideal for small bits of data - configuration values and that sort of thing. Where you just want to store a few of values that would seldom change. SPIFFS though is better at dealing ...


5

More than 20 years, and probably more than 100 years. That's the guaranteed minimum: Data retention: 20 years at 85°C/100 years at 25°C(1) (1) Reliability Qualification results show that the projected data retention failure rate is much less than 1 PPM over 20 years at 85°C or 100 years at 25°C.


4

No accepted or up-voted answers, eh? I'll try my hand. :) How big of a project can be built using Arduino? Depends on the model. You can go from around 4 KB of programmable memory to 256 KB, and then get into the larger models like the Due (512 KB). Are there memory concerns? There are always memory concerns, however when you have gigabytes of RAM (...


4

(Duplicate of this.) In your example, neither definition of MAX_ARRAY_LEN will use program space nor RAM. If you were to use the definition somewhere, it will certainly use program space in the instruction that uses that constant: for (int i=0 i<MAX_ARRAY_LEN, i++) Serial.print( my_array[i] ); In this case, a CPU instruction will load the constant 3 ...


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