Merging i2c-sensor code with SPI SD-card code

Hi, I'm working on a project where I'm using an i2c-sensor and an SPI based SD-card "extension" to store the info from the sensor to an SD card. My problem is that I haven't got enough programming knowledge to combine the 2 working codes I've found for each of the devices. Can someone help me?

The code couldn't be posted on the forum, the thread would be too long, so this is a link to the code:

So you have linked to two demo programs - one copies the accelorometer readings to Serial, the other copies 3 analog pin readings to an SD file. What do you want to do ? Copy the accelorometer reading to the SD card?

The "Overview" of what you have to do: Put the the two programs in one file. Take alle the setup() bits and put them in one setup() call. Likewise the loop bits. When this compiles you will need to change the Serial.print() of the accelorometer bit to datafile.print() and remove the analogRead bits.

Hope this gives you enough of a help to finish the details yourself.

(ByTheWay - when you write a post you can can click on AdvancedOptions below the text entry field, and upload large program sketch source code - this way you do not need to make links)

Thank you for the tips :slight_smile: I did as you said and I didn’t get any errors when compiling, but I only get

" Initializing SD card…card initialized
Freescale MMA7455 accelerometer
May 2012 "

I found that anything past " error = MMA7455_init(); " doesn’t print.

any suggestions?

The code is attached

Sensor_og_datalogg_kode.ino (13.7 KB)

No suggestions on where the error lies.

On the other hand, I suggest putting a print in the various MMA7455 routines on entry to see if you "hang" somehow (or goes into never-never land due to some memory overflow/overwrite)