Go Down

Topic: Code compiles and loads to Nano but wont run when a function is included.  (Read 155 times) previous topic - next topic

dannysprogis

Greetings,

I am creating a small device based on a Nano that has a 4x4 matrix keypad as an input and a few i2C devices as peripherals.
1) OLED display  64x128 SSD1306  @address 0x3C
2) EEPROM memory @address 0x50
3) RTC @address 0x68

The code looks for keypress inputs and when a valid 6-digit number is entered, it is written to the EEPROM @ 0x50 with a date and time from the RTC.
All of my code works individually in test functions (examples, etc.) and complies, loads and runs on my circuit until I add one specific function that is based on the i2C scanner example. As soon as I include this function, my code will compile and load without error but freezes my device and nothing runs.
The function that causes error is called I2C_Test() and is called by Key_A_Pressed() (or KEY_B, C ) line 5. Currently the function is commented out and the code compiles and runs perfectly showing all of the relevant info on the display with relevant keypad inputs but as soon as I uncomment the code nothing works.

Initially, I thought that I might be using too much program storage space but I am only at 62% according to the compiler. The i2C function I am adding is not using any new or special libraries that are not already in use so I am lost as to why I cannot get it to run...

I have attached a zip folder containing the full code and all the functions in additional tabs.

Any help would be greatly appreciated. 

Thanks in advance!




pylon

Quote
Initially, I thought that I might be using too much program storage space but I am only at 62% according to the compiler. The i2C function I am adding is not using any new or special libraries that are not already in use so I am lost as to why I cannot get it to run...
You probably run out of RAM. The SSD1306 library is a memory hog, you have to program extremely efficient to use that library with other functions on a ATmega328p based Arduino.

You could save a lot of memory if you use the F() macro consequently. If the IDE returns that your sketch uses more than about 900 bytes for global variables you're out because the library will allocate almost 1100 bytes at startup to hold the display buffer.
Using older version of the library help me save a few bytes...
Also modifying the library to eliminate code parts you don't use also may save some RAM.

dannysprogis

Thanks Pylon!

Ill see what i can do to tidy it up over the weekend!

dannysprogis

Thanks Pylon! F() has solved my issue. I have not needed to tweak the SSD1306 library but will keep that in mind for the future.

Go Up