The rude awakening that my code exceeded the 2k bytes of RAM in the Atmel ATmega328 uC's quickly put the brake on the progress. I have spent some time in the weekend investigating what are the big RAM consumers and to find way to work around them. Else I have to readjust the list of features that I set.
The original features that I established in part 2 of this series:
- Engine oil pressure
- Engine oil temperature
- Starting battery voltage
- Humidity in the cockpit
- Ambient temperature in the cockpit
- Outside ambient temperature
- Data logger
I identified the major RAM consumers. The worst offender is the library for the 128x64 OLED driver. It requires over 1k (128 x 64 = 1024) of RAM because it uses a frame buffer for the entire display. The example code that runs a demo loop alone consumes 1291 bytes. That is 63% of all available RAM.
The second large RAM consumer is the library for the SD card. Anything that handling file storage requires data buffers. These are legacy designs that model after the magnetic disc. Approximately 512 bytes are set aside for FAT file handling. A simple demo code writing console entry to the SD card consumes 706 bytes.
The third large RAM consumer is the real time clock (RTC). Just adding the RTClib library alone consumes 207 bytes. You can see short of a miracle my choice of hardware pieces are doomed. Clearly I must do something about the OLED display. May be dropping it and go with the much bigger 20x4 dot matrix LCD display instead.
Of all the Arduino devices, I managed to pick three of the biggest RAM hoggers for a project.
It turned out there is another more memory efficient OLED library. After I played with it awhile, it is obvious designed for the purpose of addressing this RAM constrain problem with this category of uCs. While the documentation does not point this out, the way you must use the library give the clue that it uses a much smaller frame buffer for the display. For my OLED, it breaks it up into 4 vertical segments and updates them sequentially. Everything has a price. The economy in RAM use makes the library much less user friendly. I would have to substantially restructure my algorithm just to try it. From other people's report, it consumes about 512 bytes. Given how dire the situation looked I have little choice but to invest some time assessing it, hoping to shave off substantial amount of RAM use in each of these areas.
I also looked into the SD card library. There is not much anyone can do to reduce the RAM usage due to the FAT file handling. Not much can be done either with the RTC library. There are lots of variables needed to handle the construction and deconstrution of the year, month, day, hour, minute, and second.
Switching the OLED library turned out making all the difference. It cut down the RAM used by nearly 1k bytes. By now there was a sliver of hope that may be I can have the cake and eat it too - that is to keep all the features that I set out to accomplish.
I started to put in the codes for the SD card. I test compile and the RAM use was still within acceptable level. I then add in the RTC codes and test compile again. I could not believe the result. The RAM use was still looking good. The code was pretty rough at this point, but I can begin to see some blue sky.
soup noodles with smoked brisket and beef meat balls; unfortunately this is the last of the brisket that I made recently
my improvised SD card reader so I can download the data logger files into the PC for verifying the code is working
having played with the data logger shield which requires a full size SD card, I wish it uses a SD micro card slot instead as it would save so much space for used by something else
here is the closeup of the data logger shield peggy back onto the Arduino Uno
I have the joystick control roughly coded
There were more small packages arrived today - a project box, a touch screen LCD display, and a 4 channel ADC breakout board.
more cheap thrill goodies arrive via post
most of these were shipped from China, but some were shipped from Vientiane which is the capital of Loas
While there are a lot of enclosures out there for the Arduino Uno, the problem is most are made to accommodate only the Uno. Any additional functions like in my case the data logger shield and the miscellaneous bits have to go onto the outside. Leave you wonder why these needs are not addressed. With a lot of searching I found this project box that may work.
it is meant to be water resistant but the gasket is just an insert instead of a purpose made o-ring; I am not complaining as the price is right
it is not perfect but it is as close as I can expect - I think I can make it work quite well; I am quite confident that I can fit all the uC main module pieces all into this box
there is only one A/D converter inside but with an analog multiplexer at the front end
I couldn't wait to test out the 16-bit 4-channel ADC. It is extremely easy to use as it is all self-contained. Less than 1/2 hour I have it connected to my prototype system and up and running, reporting voltage measurements. With this there are now 7 channels of analog inputs.
No comments:
Post a Comment