Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Bob DS1825 LDC1614 LDC1101 SDFileSystem mbed
Fork of Inductive_Sensor by
main.cpp
- Committer:
- bobgiesberts
- Date:
- 2015-12-18
- Revision:
- 2:1a203732fc95
- Parent:
- 1:22c272515015
- Child:
- 4:ae441c5727b9
File content as of revision 2:1a203732fc95:
#include "mbed.h"
#include "LDC1101.h"
#include "SDFileSystem.h"
#include "Bob.h"
#include <iostream>
using namespace std;
/**
* @file main.cpp
* @brief This file programs the processor for the inductive force sensor
* using the library LDC1101.h and LDC1101.cpp.
* - Red Led: processing communication with LDC1101
* - Green Led: processing SD card
*
* @author Bob Giesberts
*
* @date 2015-12-17
*/
Bob bob(PTB0, PTB1, PTC3, PTE0); // red led, green led, sd_enable, sd_present
Serial pc(USBTX, USBRX);
int main(void){
/** --- Connection to LDC1101 --- */
pc.printf("Connect to LDC1101...");
LDC1101 ldc(PTC6, PTC7, PTC5, PTC4, 120E-12, 16E6); // mosi, miso, sck, cs, capacitor (F), f_CLKIN (Hz)
pc.printf("success!\r\n");
bob.flash(2);
wait(0.2);
/** --- Connection to sensor --- */
pc.printf("Connect to sensor...");
if(ldc.get_LHR_Data() != 16777215)
{
pc.printf("success!\r\n");
bob.flash_red(2);
}else{
pc.printf("failed!\r\n");
bob.red();
}
/** --- Start measuring! --- */
while(1)
{
clock_t t = clock();
int L = ldc.get_LHR_Data();
pc.printf("%.2f;%d\n", t/100.0, L);
wait(0.05); // 20 Hz
}
/* let's leave this part out while calibrating the sensor
// --- Connection to SD card ---
pc.printf("Connect to SD card...");
if(bob.checkSD() == 1){
pc.printf("success!\r\n");
}else{
pc.printf("failed!\r\n");
}
// Load SD File system
SDFileSystem SD(PTD6, PTD7, PTD5, PTD4, "sd"); // mosi, miso, sclk, cs, sd_name
// Open or create data file
pc.printf("Opening data file...");
mkdir("/sd/mydir", 0777);
FILE *fp = fopen("/sd/data.txt", "w");
if(fp != NULL) {
pc.printf("success!\r\n");
}else{
pc.printf("failed!\r\n");
}
// Write current settings to data file
fprintf(fp, "DIVIDER : %d\r\n", ldc.get_divider());
fprintf(fp, "RESPONSETIME : %d\r\n", ldc.get_responsetime());
fprintf(fp, "RP_MIN : %f\r\n", ldc.get_RPmin());
fprintf(fp, "LHR_RCOUNT : %d\r\n", ldc.get_Rcount());
fprintf(fp, "\r\n\r\n");
fclose(fp);
while(1)
{
clock_t t = clock();
// get value from sensor
int L = ldc.get_LHR_Data();
// if the sensor is connected
if(L != 16777215) {
// settings
pc.printf("ResponseTime: %d", ldc.get_responsetime());
pc.printf(", Divider: %d", ldc.get_divider());
pc.printf(", RP_MIN: %.0f", ldc.get_RPmin());
pc.printf(", R_COUNT: %d", ldc.get_Rcount());
pc.printf(", Q: %.2f", ldc.get_Q());
pc.printf("\r\n");
// results
pc.printf("Time = %.2f", t/100.0);
pc.printf(", L_DATA = %d", L);
pc.printf(", f_sensor = %.2f MHz", ldc.get_fsensor()/1000000);
pc.printf(", L = %.2f uH", 1000000*ldc.get_Inductance());
pc.printf("\r\n");
pc.printf("\r\n");
// feedback: it's working
bob.flash_red(1);
// Store data on SD card
if( bob.checkSD() == 1 ) {
fp = fopen("/sd/data.txt", "a");
//for(int i = 0; i < 100; i++){ Store one continuous stream of data, 30 seconds
fprintf(fp, "%.2f, ", t/100.0);
fprintf(fp, "%d\r\n", L);
//}
fclose(fp);
}else{
pc.printf("Error: SD card disconnected, please reinsert.\r\n");
bob.green();
}
}else{
pc.printf("Error: Sensor disconnected, please reconnect.\r\n");
bob.red();
}
// Telkens een periode van 10 - 30 seconden continue meten, dan een half uur pauze.
// In die pauze alles op laagste vermogen (LDC1101 in shutdown modus, SD uit, leds uit)
// ldc.sleep(); sd_pin = 0;
// wait(1800); // FOR LATER: wait half an hour, 60 * 30 = 1800
// ldc.wakeup(); sd_pin = 1;
}
*/
}
