Hot answers tagged

10

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 ...


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

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 ...


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

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

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 ...


5

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 ...


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

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

Simplest thing would probably be to edit your copy of SoftwareSerial.h and replace #define _SS_MAX_RX_BUFF 64 on line 42 by something smaller. If your loop() runs fast enough (no delays, no blocking code) you could probably get away with buffering only a very few bytes. Or you could rewrite the library so that, instead of buffering the incoming bytes, it ...


4

The simplest approach to reducing RAM usage of the program shown is to get rid of the three 128-byte pixel arrays. They are not needed for the program to function. Instead of writing pixelsArray1[i]=analogRead(A1)/4; pixelsArray2[i]=analogRead(A2)/4; pixelsArray3[i]=analogRead(A3)/4; write if (analogRead(A1)/4 == 0 && analogRead(A2)/4 == 0 &&...


4

by putting the declaration for variable char double2StrBuff1[10]; inside the function, is the memory allocated from the stack and therefore recovered upon exiting the function This is correct. is the fact that double2StrBuff1 is a pointer means that the pointer is allocated in the stack but the values are located in the heap (therefore what I am ...


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

This question is not really about the Arduino. It is about GNU C/C++ compiler optimizations. By adding the keyword const the compiler can do a lot of optimization. One is that the value does not need to be stored in SRAM. The value can end up as part of an instruction, become part of an expression that is evaluated at compile-time, etc. In the Arduino-...


4

On my answer to the question you are referencing, I state that “If you use the heap like a stack (last in is first out), then it will behave like a stack and not fragment.” This seems to be exactly your usage pattern, thus you should not fear fragmentation. Of course, the caveat written in Michel Keijzers’ answer applies: you should make sure that no other ...


4

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 ...


4

If you have a constant c-string (char array) in your code without F macro or progmem, then the string is copied into RAM at start an stays there. If in a function you use the F macro or you create a char buffer of some size and copy the progmem string into the buffer, on function return the variables are deleted from stack and the memory is released. In ...


4

Yes, you can use malloc() on the Arduino - however it is not something I would recommend you use since memory is at a premium and excessive use of malloc() and free() causes heap fragmentation which can eat your memory up and cause random crashes (String is the biggest culprit of this). I am not sure what you mean by "clean" the memory. When power is ...


4

The library, as it stands, doesn't support direct sending from PROGMEM. However it's not too hard to get around that - if your C++ is up to it. The IRsendRaw class is a child class that extends the IRsendBase with a single function. You just need to do the same thing to create a new class that implements the functions in a way that can read from PROGMEM. ...


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