8 years, 9 months ago.

How to send sensor(I2C) data to SD card??

Hi, Here i'm using Nucleo-L053R8 controller. I have a Temperatire and humidity sensor connected in I2C communication. Now,I'm trying to send data from sensor to SD card. How to do it?. thank you.

Question relating to:

  1. include "mbed.h"
  2. include "ms5611.h"
  3. include "SDFileSystem.h"

ms5611 ms(D14, D15, ms5611::CSBpin_1); SDFileSystem sd(D11,D12,D13,PB_6, "sd"); MOSI, MISO, SCLK, SSEL

Serial pc(USBTX, USBRX); local terminal interface

int main (void) { pc.baud(115200); set up USB serial speed

set up the ms5611 pc.printf("\n\nInitializing the MS5611..\n"); ms.cmd_reset(); pc.printf("Ready\n"); FILE *fp = fopen("/sd/mbed.txt", "w");

while(1) { double Temp = ms.calcTemp(); calculate press and temp, then returns current temperature in degC double Press = ms.calcPressure(); calculate press and temp, then returns current pressure in mb double GetPress = ms.getPressure(); returns current pressure in mb. Does no calculations. Ususally done after calcTemp()

pc.printf("Temp: %.2f degC\n", Temp); pc.printf("Barometer: %.1f mB %.3f in/Hg\n", Press, Press * 0.0295301);

fprintf(fp,"Temp: %.2f degC\n", Temp); fclose(fp); wait(2.0); } }

would this code send data to SD card??

posted by Mohan gandhi Vinnakota 14 Jul 2015

If you try it for a while, put the SD card in you PC and see what you have.

This should work though:

snip

 FILE *fp = fopen("/sd/Templog.txt", "a"); 
  
                  fprintf (fp,"Temp: %3.3f degC\r,",Temp);
                    
                  fclose(fp);              
posted by Paul Staron 14 Jul 2015

Thank you. its working.

posted by Mohan gandhi Vinnakota 15 Jul 2015
Be the first to answer this question.