Here are pics of my setup:
|Compass is lower left. It needed a 3.3V power supply, which is the voltage regulator on the lower breadboard.|
The compass was from jaycon and is based on the HMC5883L chip. It communicated over I2C. There's an arduino library for it, but it's buggy. No attempt was made to calibrate or scale it correctly. The SD card board is a basic one from sparkfun that has on-board regulators so you can give it 5V (SD cards need 3.3V). The arduino 10bit ADC was used for both the signal reading and the voltmeter. Data loging timing was done with the arduino's timer 1 operating in CTC interrupt mode. The interrupt would trigger an interrupt service routine that would trigger a flag that would run the data reading and writing loop. Doing any kind of serial communication (writing to terminal, reading I2C compass, writing to SD card over SPI, etc.) inside the ISR would crash the program because serial communication is interrupt driven. It worked because we weren't sampling very fast (40Hz). High sample rates probably would have required some other way of doing it. I wrote a simple MATLAB script for plotting the data from the SD card. I had to add an outlier removal scheme because the compass would randomly have huge outliers.
Again, like with all of these projects, I can't post the code until the professor changes the projects.
compass, arduino datasheets
arduino SD card library documentation