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 Si7020 LPS25H LSM303D
main.cpp@9:bc5dc16ad97d, 2019-01-06 (annotated)
- Committer:
- pingu_98
- Date:
- Sun Jan 06 19:19:56 2019 +0000
- Revision:
- 9:bc5dc16ad97d
- Parent:
- 8:1b347e764f16
updated forked repos
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| screamer | 0:005629fe3609 | 1 | #include "mbed.h" |
| pingu_98 | 7:7137218c4432 | 2 | #include "Si7020.h" |
| pingu_98 | 7:7137218c4432 | 3 | #include "LPS25H.h" |
| pingu_98 | 8:1b347e764f16 | 4 | #include "LSM303D.h" |
| screamer | 0:005629fe3609 | 5 | |
| screamer | 0:005629fe3609 | 6 | DigitalOut myled(LED1); |
| screamer | 0:005629fe3609 | 7 | |
| pingu_98 | 7:7137218c4432 | 8 | Serial pc(SERIAL_TX, SERIAL_RX); //serial debug output, 9600 bps 8 bit, no parity 1 stop bit no flow control. |
| pingu_98 | 7:7137218c4432 | 9 | |
| pingu_98 | 7:7137218c4432 | 10 | //I2C declarations |
| pingu_98 | 7:7137218c4432 | 11 | I2C i2c(PB_9,PB_8); // SDA, SCL |
| pingu_98 | 7:7137218c4432 | 12 | I2CSlave slave(PB_3,PB_10); // SDA, SCL |
| pingu_98 | 7:7137218c4432 | 13 | Si7020 si(&i2c); |
| pingu_98 | 7:7137218c4432 | 14 | LPS25H baro(&i2c, LPS25H_G_CHIP_ADDR); |
| pingu_98 | 7:7137218c4432 | 15 | |
| pingu_98 | 7:7137218c4432 | 16 | AnalogIn adc(ADC_TEMP); |
| pingu_98 | 7:7137218c4432 | 17 | |
| pingu_98 | 8:1b347e764f16 | 18 | LSM303D lsm303d_1(&i2c); |
| pingu_98 | 8:1b347e764f16 | 19 | static float magx,magy,magz,accx,accy,accz; |
| pingu_98 | 8:1b347e764f16 | 20 | //static LSM303D::raw_data accxx,accyy,acczz,magxx,magyy,magzz; |
| pingu_98 | 8:1b347e764f16 | 21 | //static LSM303D::vector<LSM303D::raw_data> a,m; |
| pingu_98 | 8:1b347e764f16 | 22 | |
| pingu_98 | 7:7137218c4432 | 23 | //int I2C_ADDR = 0x00200; |
| pingu_98 | 7:7137218c4432 | 24 | static const char I2C_ADDR = 0xE5 ; |
| screamer | 0:005629fe3609 | 25 | int main() { |
| pingu_98 | 7:7137218c4432 | 26 | |
| pingu_98 | 7:7137218c4432 | 27 | //i2c setups |
| pingu_98 | 7:7137218c4432 | 28 | i2c.frequency(100000); //Set the clock frequency |
| pingu_98 | 7:7137218c4432 | 29 | slave.frequency(100000); //Set the clock frequency |
| pingu_98 | 7:7137218c4432 | 30 | slave.address(I2C_ADDR); |
| pingu_98 | 8:1b347e764f16 | 31 | |
| pingu_98 | 7:7137218c4432 | 32 | |
| pingu_98 | 8:1b347e764f16 | 33 | pc.printf("Hello world! Cosmic Pi STM32F401RE Test program\n"); |
| screamer | 0:005629fe3609 | 34 | while(1) { |
| pingu_98 | 8:1b347e764f16 | 35 | pc.printf("This is a loop\n"); |
| pingu_98 | 8:1b347e764f16 | 36 | //flash the power LED |
| bcostm | 2:b60cb847489c | 37 | myled = 1; // LED is ON |
| bcostm | 2:b60cb847489c | 38 | wait(0.2); // 200 ms |
| bcostm | 2:b60cb847489c | 39 | myled = 0; // LED is OFF |
| bcostm | 2:b60cb847489c | 40 | wait(1.0); // 1 sec |
| pingu_98 | 8:1b347e764f16 | 41 | |
| pingu_98 | 8:1b347e764f16 | 42 | //STM32 internal temp sensor |
| pingu_98 | 7:7137218c4432 | 43 | float tempuc = adc.read()*100; |
| pingu_98 | 8:1b347e764f16 | 44 | pc.printf("Internal Temp Sensor (ADC) = %.1f\r\n", tempuc); |
| pingu_98 | 8:1b347e764f16 | 45 | |
| pingu_98 | 8:1b347e764f16 | 46 | //Si7006 readout, temperature and humidity |
| pingu_98 | 7:7137218c4432 | 47 | float humid; |
| pingu_98 | 7:7137218c4432 | 48 | if(si.getHumidity(&humid) != 0) { |
| pingu_98 | 7:7137218c4432 | 49 | printf("Error getting humidity\n"); |
| pingu_98 | 7:7137218c4432 | 50 | humid = -1; |
| pingu_98 | 7:7137218c4432 | 51 | } |
| pingu_98 | 7:7137218c4432 | 52 | |
| pingu_98 | 7:7137218c4432 | 53 | float temp; |
| pingu_98 | 7:7137218c4432 | 54 | if(si.getTemperature(&temp) != 0) { |
| pingu_98 | 7:7137218c4432 | 55 | printf("Error getting temperature"); |
| pingu_98 | 7:7137218c4432 | 56 | temp = -1; |
| pingu_98 | 7:7137218c4432 | 57 | } |
| pingu_98 | 8:1b347e764f16 | 58 | printf("Si7006 readout - Humidity = %f%% Temperature = %fC\n", humid, temp); |
| pingu_98 | 7:7137218c4432 | 59 | |
| pingu_98 | 8:1b347e764f16 | 60 | //LPS25H readout |
| pingu_98 | 7:7137218c4432 | 61 | baro.get(); |
| pingu_98 | 8:1b347e764f16 | 62 | printf("LPH25S readout: Pressure: %.1f, Temperature: %.1f\r\n", |
| pingu_98 | 7:7137218c4432 | 63 | baro.pressure(), baro.temperature()); |
| pingu_98 | 7:7137218c4432 | 64 | |
| pingu_98 | 8:1b347e764f16 | 65 | //LSM303D readout (accel + mag) |
| pingu_98 | 8:1b347e764f16 | 66 | if (lsm303d_1.read(&accx,&accy,&accz,&magx,&magy,&magz) !=0) { |
| pingu_98 | 8:1b347e764f16 | 67 | printf("Error getting LSM303D values\n"); |
| pingu_98 | 8:1b347e764f16 | 68 | } |
| pingu_98 | 8:1b347e764f16 | 69 | |
| pingu_98 | 8:1b347e764f16 | 70 | printf("LSM303D mag readout x: %f y: %f z: %f\n\r",magx,magy,magz); |
| pingu_98 | 8:1b347e764f16 | 71 | printf("LSM303D acc readout x: %f y: %f z: %f\n\r",accx,accy,accz); |
| pingu_98 | 8:1b347e764f16 | 72 | |
| pingu_98 | 7:7137218c4432 | 73 | |
| pingu_98 | 7:7137218c4432 | 74 | wait(1); |
| screamer | 0:005629fe3609 | 75 | } |
| screamer | 0:005629fe3609 | 76 | } |
| pingu_98 | 7:7137218c4432 | 77 | |
| pingu_98 | 7:7137218c4432 | 78 | |
| pingu_98 | 7:7137218c4432 | 79 | |
| pingu_98 | 7:7137218c4432 | 80 |