Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 15:29 02 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Micromite Plus Logging to SD card

Author Message
Glen0
Regular Member

Joined: 12/10/2014
Location: New Zealand
Posts: 95
Posted: 11:15pm 18 Apr 2016
Copy link to clipboard 
Print this post

I am trying to log A/D conversions to the SD card on a SnadPIC. Does anyone have an example of code that writes time-stamped values to an SD card I could try. If I could achieve something similar to OpenLog that would be great.
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1114
Posted: 06:35pm 19 Apr 2016
Copy link to clipboard 
Print this post

Glen,

My Caravan Battery Monitor program does logging to an SD card.

Main issue is limiting the number of SD card writes. I use arrays to hold intermediate values then write to the card once an hour closing the file of at end of day and starting a new file for the new day using the date as the file name. I managed to get nearly two years worth of files (600 plus files) onto an SD card - eventually ran out of buffer space inside MMBasic for file names during file create.

Data is stored in the log file in comma separated variable form with the first record being the actual field names. This is directly importable into Excel

I set up a 2 second interrupt then set flags for 2 seconds, 1 minute, 1 hour and end of day.
I also create arrays to hold 1 minutes worth of 2 second readings and 1 hours worth of average 1 minute readings

The main program just loops checking these flags and processes accordingly.

I log 4 values BV (battery voltage), SV (solar volts), IC (input or charging current) and LC (load current).

The program is in the MMBasic library called CVanBM

It was written for MMBasic 4.5 but should be easily translateable to 5.1

Cheers,
Doug.

Hope it is of some use to you.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1114
Posted: 06:40pm 19 Apr 2016
Copy link to clipboard 
Print this post

Just had a look at my code - seems like it might have been neater to use multi dimension arrays for the 2 seconds and minute average logging for each of the fields (battery volts, solar volts input current and load current).

It should also be simple to add a time stamp to each record by adding an extra field to the minute average array.

If you wanted to log in finer detail than 1 minute entries, you could create another array as needed.

Doug.

... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
Glen0
Regular Member

Joined: 12/10/2014
Location: New Zealand
Posts: 95
Posted: 01:00pm 24 Apr 2016
Copy link to clipboard 
Print this post

Thanks for that. Had a little difficulty in finding your program. I have now found another corner of the back shed (library).
I am now successfully writing to an 8Gb Micro SD I scrounged from an old camera.

When first configuring the SD card I can only use "OPTION SDCARD 14" and not "OPTION SDCARD 14, 18" as shown in the micromite plus manual.
The snadpic manual shows both CD and CS on pin 2 of the SD card socket, which then

connects to pin 14 of the Pic Micro
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025