I'm pretty new to the Arduino. So the project I've been working on is a motorcycle or automotive data/GPS logger. I'm using an Uno, the GPS logger shield from Adafruit, a BNO055 for lean angle detection, and an OBD2 (UART) adapter from Freematics. I got the GPS, lean angle detection, and OBD2 adapter working together then tried to add the data logger. The data logger took a lot more memory than I expected (well, I wasn't thinking about how much memory I was using at the time).
Without Logging:
Sketch uses 23,880 bytes (74%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,513 bytes (73%) of dynamic memory, leaving 535 bytes for local variables. Maximum is 2,048 bytes.
With Logging and without OBD2:
Sketch uses 29,714 bytes (92%) of program storage space. Maximum is 32,256 bytes.
Global variables use 2,077 bytes (101%) of dynamic memory, leaving -29 bytes for local variables. Maximum is 2,048 bytes.
I used the Adafruit code and edited it minimally to do what I need it to do. I don't have any arrays, I have a few strings for manipulating the incoming GPS data, and 9 includes. I have a fair number of print statements I've used for testing but those will go away anyway when I'm finished with the project. Is there anything I can do to reduce the size of this program? I'm thinking I'll have to leave out some of the features I was wanting.
Really? If he is already up to 29714 without including the OBD2, and he needs 23880 with OBD2 but no data logging at all, I await the result with faint interest.
However, it is only a suggestion, and I will modify my post appropriately with one word!
PROGMEM is not actually used a lot. The F() macro is much more useful. I don't know why it's a 'playground' item, but this is the most-official-looking tutorial page that I can find with 60 seconds of googling: Arduino Playground - Memory
So the code is a bit of a mess. I got the GPS, angle, and OBD2 working together first, then tried throwing in the SD card logging, but was out of memory. So I took out the OBD2 code to see if that gave me enough room but I'm still over. I tried using the F() macro but was getting an error, so I'm looking into that. Taking out most of the print statements alone brought down memory usage but I still get the low memory warning.
Sketch uses 28,170 bytes (87%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,867 bytes (91%) of dynamic memory, leaving 181 bytes for local variables. Maximum is 2,048 bytes.
I'm looking into progmem and the F macro, I didn't know they existed. Thanks for that
Yeah. I was using a gyro and accelerometer using a complementary filter to get lean/roll angle but it wasn't quite where I wanted it after quite a bit of messing around. So I picked up one of these:
Basically plug and play. Really cool sensor. I haven't tested it much but it works great at my desk, sitting in my car, and walking around the yard.
The recording to SD seems incomplete. Further, if you record at all, I would imagine you would want to record the data against time, and I'm not sure you are adressing that at all. maybe it is in the GPS data.
The recording stuff seems to be ruff 'n' ready and verbose as well, but I don't suppose that is he cause of your real problem.
It would help if you posted the code in the proper manner with the </> tags.
If the only problem ends up being memory, you can throw more hardware at it - the 1284p has 16k sram 128k flash, while the '2560 (as used in mega) has 8 and 256.
Nick_Pyner:
The recording to SD seems incomplete. Further, if you record at all, I would imagine you would want to record the data against time, and I'm not sure you are adressing that at all. maybe it is in the GPS data.
The recording stuff seems to be ruff 'n' ready and verbose as well, but I don't suppose that is he cause of your real problem.
It would help if you posted the code in the proper manner with the </> tags.
I tried using the code tags but the forum said the post was too many characters. No, the program I posted is not recording anything to the SD card. I was aware of that. My plan of attack for this project was to make sure everything worked individually and then add a piece, try/fix the program with the new piece, add another piece, etc.
My original GPS logging code by itself would write to the SD card. When I started Frankensteining my code together I realized I was running low on memory and never finished adding everything because it wasn't going to fit on the board anyway.
I was mostly wondering if there was any way to significantly reduce the amount of memory my program was using with a coding technique. My first thought was to get a different board, but wanted to learn about any coding strategy before I took the easy way out. But if that's the only solution, c'est la vie
J-moges:
My plan of attack for this project was to make sure everything worked individually and then add a piece, try/fix the program with the new piece, add another piece, etc.
My first thought was to get a different board, but wanted to learn about any coding strategy before I took the easy way out. But if that's the only solution, c'est la vie
Your plan of attack is most reasonable but, ultimately, you get to the position where you are sending a boy on a man's job and getting a Mega isn't the easy way out, it's the only way out. C'est la vie and I submit this was rather self-evident in your first post.
You are not alone with this. One data logging programme is much the same as another and it seems pretty common to find that a Uno isn't up to the job. Indeed, I suspect yours is bigger than most.