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: mbed SDFileSystem_
Diff: main.cpp
- Revision:
- 7:b69fa9bb320d
- Parent:
- 6:bf4321ef0330
- Child:
- 8:7f80139df48d
--- a/main.cpp Wed Aug 04 06:41:02 2021 +0000 +++ b/main.cpp Thu Aug 19 08:38:59 2021 +0000 @@ -1,5 +1,6 @@ #include "mbed.h" #include "SDFileSystem.h" +#include "time.h" /* This basic example just shows how to read the ADC internal channels raw values. Please look in the corresponding device reference manual for a complete @@ -42,84 +43,103 @@ DigitalOut led(PB_5); int initLIS3DH(); int read3axes(short *tx,short *ty,short *tz); -int readTemp(short *tmp); +//int readTemp(short *tmp); FILE *fp; int main() { - short x,y,z,tmp; - - int i,l; - int lwaight; - float wt; - uint32_t dt; -#if 0 - pc.printf("\nSTM32 Loadcell example\r\n"); - while(1) { - led = !led; - hx_clk=1; - wait(1.0); - hx_clk=0; - wait(1.0); - dt=0; - for(i=0;i<24;i++) { - hx_clk=1; - wait_us(1); - dt <<= 1; - if (hx_dt==0) dt |= 1; - hx_clk=0; - wait_us(1); - } - hx_clk=1; - wait_us(1); - hx_clk=0; - pc.printf("data = %08x %d ",dt,dt); - wt = (float)(dt) * 0.000038f - 1.2f; - pc.printf("waight = %3.3f\r\n",wt); - } -#endif + short x,y,z,count=0; + float ox,oy,oz,oldacc = 0; + double xyz[3],newacc=0; + //int ret = 0; + char buf[512]; + //char *retchar = NULL; + //time_t t;//24H = 86400s initLIS3DH(); - h3dacc.init(H3LIS331DL_ODR_100Hz, H3LIS331DL_NORMAL,H3LIS331DL_FULLSCALE_2);//これで初期化している + h3dacc.init(H3LIS331DL_ODR_100Hz, H3LIS331DL_NORMAL,H3LIS331DL_FULLSCALE_8);//これで初期化している FULLSCALE_8=400G + h3dacc.setHPFMode(H3LIS331DL_HPM_NORMAL_MODE_RES);//High Pass Filter ON - pc.printf("\nSTM32 ADC internal channels reading example\r\n"); - pc.printf("\nSTM32 3D acc sensor example\r\n"); + //pc.printf("\nSTM32 ADC internal channels reading example\r\n"); + //pc.printf("\nSTM32 3D acc sensor example\r\n"); fp = fopen("/sd/testlog.txt", "a"); if (fp == NULL) { - pc.printf("open error!!\r\n"); + //pc.printf("open error!!\r\n"); } else { - pc.printf("SD opened\r\n"); - fclose(fp); + //pc.printf("SD opened\r\n"); + //fclose(fp); wait_ms(10); } while(1) { -// pc.printf("ADC Temp = %f\r\n", (adc_temp.read()*100)); -// pc.printf("ADC VRef = %f\r\n", adc_vref.read()); -// pc.printf("\033[2A"); //On board ACC sensor x=y=z=0; read3axes(&x,&y,&z); - readTemp(&tmp); - pc.printf("x=%d y=%d z=%d tmperature=%d\r\n", x,y,z,tmp); - pc.printf("x=%f y=%f z=%f\r\n", (float)x/1024.0f,(float)y/1024.0f,(float)z/1024.0f); + //readTemp(&tmp); + //pc.printf("x=%d y=%d z=%d tmperature=%d\r\n", x,y,z,tmp); + //t = time(NULL); + if(count == 5){ + ox = (float)x/1024.0f; + oy = (float)y/1024.0f; + oz = (float)z/1024.0f; + ox = ox * ox; + oy = oy * oy; + oz = oz * oz; + oldacc = sqrt(ox + oy + oz); + + //pc.printf("oldacc %ld %f",time(NULL),sqrt(powf((float)x/1024.0f,2) + powf((float)y/1024.0f,2) + powf((float)z/1024.0f,2))); + pc.printf("oldacc %ld, %f\r\n", time(NULL), oldacc); + //pc.printf("oldacc %ld x=%f y=%f z=%f\r\n", time(NULL), (float)x/1024.0f,(float)y/1024.0f,(float)z/1024.0f); + count = 0; + } // Extra ACC sensor - x=y=z=0; - h3dacc.readXYZ(&x, &y, &z); - pc.printf("High x=%d y=%d z=%d \r\n", x,y,z); + //x=y=z=0; + //h3dacc.readXYZ(&x, &y, &z); + h3dacc.getAcceleration(xyz); + //t = time(NULL); + xyz[0] = xyz[0] * xyz[0]; + xyz[1] = xyz[1] * xyz[1]; + xyz[2] = xyz[2] * xyz[2]; + newacc = xyz[0] + xyz[1] + xyz[2]; + newacc = sqrt(newacc); + //pc.printf("newacc %ld x=%lf, y=%lf, z=%lf \r\n", time(NULL), xyz[0], xyz[1], xyz[2]); + pc.printf("newacc %ld, %lf\r\n", time(NULL), newacc); + //ret = fprintf(fp, "x=%lf, y=%lf, z=%lf \r\n", xyz[0], xyz[1], xyz[2]); + //pc.printf("fprintf ret:%d\r\n", ret); + /* + retchar = fgets(buf,64,fp); + if(!retchar){ + if(fp){ + fclose(fp); + fp = NULL; + } + } + else{ + pc.printf("%s\r\n",buf); + } + */ + + //pc.printf("High x=%d y=%d z=%d \r\n", x,y,z); led = !led; - wait(1.0); + count++; + if(time(NULL) > 86400){ + //Create New File + fclose(fp); + //fp = fopen(); + } + wait(0.2); } } /*********** porting **************/ + void spiFormat(int b,int m) { STSPI.format(b,m); /* 8bit */ } @@ -132,3 +152,6 @@ int spiWrite(int wd) { return ( STSPI.write(wd)); } + +void error(const char* format, ...) { +} \ No newline at end of file