
STM32F103C8T6-Cayenne-WIZnet_SD1306_BMP280
Dependencies: Cayenne-MQTT-mbed mbed Cayenne-WIZnet_Library WIZnet_Library BME280
Revision 10:63b5e5d19bee, committed 2019-11-08
- Comitter:
- dadangjia
- Date:
- Fri Nov 08 00:16:02 2019 +0000
- Parent:
- 9:3ba93660c82e
- Commit message:
- STM32F103C8T6,CAYENNE ,SD1306,BMP280
Changed in this revision
MPU6050.lib | Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 3ba93660c82e -r 63b5e5d19bee MPU6050.lib --- a/MPU6050.lib Mon Apr 23 13:43:45 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/users/BaserK/code/MPU6050/#b2f689b5fb63
diff -r 3ba93660c82e -r 63b5e5d19bee main.cpp --- a/main.cpp Mon Apr 23 13:43:45 2018 +0000 +++ b/main.cpp Fri Nov 08 00:16:02 2019 +0000 @@ -21,13 +21,14 @@ WIZnetInterface ethernet(&spi, PB_0, PB_1); // SPI, SEL, Reset MQTTNetwork<WIZnetInterface> network(ethernet); CayenneMQTT::MQTTClient<MQTTNetwork<WIZnetInterface>, MQTTTimer> mqttClient(network, username, password, clientID); -char buffer[7][20]; +char buffer[8][20]; float Temperature,Pressure; long ADC_VALUE[3]; AnalogIn ADC_MQ2(A0); //ADC1,MQ2空气质量检测 AnalogIn ADC_MQ3(A1); //ADC2,MQ3空气质量检测 AnalogIn analog_value(A2); // ADC3,可调电位器 - +Ticker ticker; +float tickerTime = 0.5; #include "CriusOLED.h" void OLED_INIT() { @@ -37,31 +38,60 @@ reset_display(); } -#include "MPU6050.h" -//MPU6050采集数据 -Ticker ticker; -MPU6050 mpu6050; -float pitchAngle = 0;float rollAngle = 0; -float tickerTime = 0.5; -void compFilter() {mpu6050.complementaryFilter(&pitchAngle, &rollAngle);} - #include "BME280.h" BME280 sensor(PB_9, PB_8); void bme280_dat() { Temperature=sensor.getTemperature(); Pressure=sensor.getPressure()*100; - ADC_VALUE[0] = (long)(ADC_MQ2.read() * 3300); - ADC_VALUE[1] = (long)(ADC_MQ3.read() * 3300); - ADC_VALUE[2] = (long)(analog_value.read()* 3300); snprintf(buffer[0],sizeof(buffer[0]), "%2.2fC %6.0fPa",Temperature, Pressure); sendStrXY(buffer[0],0,0); } +//DigitalOut rled(PC_13); +//DigitalOut gled(PC_14); +//DigitalOut bled(PC_15); + + +#define ArrayLenth 25 //times of collection +#define Offset 0.00 +float pHArray[ArrayLenth]; //Store the average value of the sensor feedback +int pHArrayIndex=0; +float pHValue; +Ticker ph_ticker; +float ph_sampleTime = 0.02; + +void PH_ticker() +{ + pHArray[pHArrayIndex++]=analog_value.read(); + if(pHArrayIndex==ArrayLenth)pHArrayIndex=0; +} + +void ph_dat() +{ + char i; + float sum; + for(i=0;i<ArrayLenth;i++) + sum+=pHArray[pHArrayIndex]; + pHValue = (sum/ArrayLenth)*3.5*5.0+Offset; + snprintf(buffer[3],sizeof(buffer[3]), "pH:%2.2f",pHValue); + sendStrXY(buffer[3],3,0); +} + +void adc_dat() +{ + ADC_VALUE[0] = (long)(ADC_MQ2.read() * 3300); + ADC_VALUE[1] = (long)(ADC_MQ3.read() * 3300); + ADC_VALUE[2] = (long)(analog_value.read() * 3300); + snprintf(buffer[2],sizeof(buffer[2]), "%4dmV %4dmV",ADC_VALUE[0], ADC_VALUE[1]); + sendStrXY(buffer[2],2,0); +} + void Stm32f103c8t6_ticker() { - compFilter(); bme280_dat(); + adc_dat(); +// ph_dat(); } /** * Print the message info. @@ -101,7 +131,31 @@ pc.printf(" id=%s", message.id); } pc.printf("\n"); - + /* + switch(message.channel) + { + case 7:if(strstr(message.getValue(j),"0")) + { + gled=0; + } + else if(strstr(message.getValue(j),"1")) + { + gled=1; + } + pc.printf("LED=%s\n", message.getValue(j)); + break; + case 11:if(strstr(message.getValue(j),"0")) + { + bled=0; + } + else if(strstr(message.getValue(j),"1")) + { + bled=1; + } + pc.printf("LED2=%s\n", message.getValue(j)); + break; + } + */ } @@ -161,8 +215,8 @@ // Send device info. Here we just send some example values for the system info. These should be changed to use actual system data, or removed if not needed. mqttClient.publishData(SYS_VERSION_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, CAYENNE_VERSION); mqttClient.publishData(SYS_MODEL_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "mbedDevice"); - //mqttClient.publishData(SYS_CPU_MODEL_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "CPU Model"); - //mqttClient.publishData(SYS_CPU_SPEED_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "1000000000"); + mqttClient.publishData(SYS_CPU_MODEL_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "CPU Model"); + mqttClient.publishData(SYS_CPU_SPEED_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "72000000"); return CAYENNE_SUCCESS; } @@ -198,26 +252,7 @@ } if ((error = mqttClient.publishData(DATA_TOPIC, 1, TYPE_LUMINOSITY, UNIT_LUX, (long)Pressure)) != CAYENNE_SUCCESS) { pc.printf("P:%6.0fPa\n",Pressure); - } - if ((error = mqttClient.publishData(DATA_TOPIC, 2, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL, ax)) != CAYENNE_SUCCESS) { - pc.printf("x:%03.2f\n", ax); - } - if ((error = mqttClient.publishData(DATA_TOPIC, 3, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL, ay)) != CAYENNE_SUCCESS) { - pc.printf("y:%03.2f\n", ay); - } - if ((error = mqttClient.publishData(DATA_TOPIC, 4, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL, az)) != CAYENNE_SUCCESS) { - pc.printf("z:%03.2f\n", az); - } - if ((error = mqttClient.publishData(DATA_TOPIC, 14, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL, gx)) != CAYENNE_SUCCESS) { - pc.printf("X:%03.2f\n", gx); - } - if ((error = mqttClient.publishData(DATA_TOPIC, 15, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL, gy)) != CAYENNE_SUCCESS) { - pc.printf("Y:%03.2f\n", gy); - } - if ((error = mqttClient.publishData(DATA_TOPIC, 16, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL, gz)) != CAYENNE_SUCCESS) { - pc.printf("Z:%03.2f\n", gz); - } - + } if ((error = mqttClient.publishData(DATA_TOPIC, 8, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL, ADC_VALUE[0])) != CAYENNE_SUCCESS) { pc.printf("A0:%4dmV\n", ADC_VALUE[0]); } @@ -227,7 +262,9 @@ if ((error = mqttClient.publishData(DATA_TOPIC, 10, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL, ADC_VALUE[2])) != CAYENNE_SUCCESS) { pc.printf("A2:%4dmV\n", ADC_VALUE[2]); } - + // if ((error = mqttClient.publishData(DATA_TOPIC, 13, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL, pHValue)) != CAYENNE_SUCCESS) { + // pc.printf("PH:%.2f\n",pHValue); + // } // Restart the countdown timer for publishing data every 5 seconds. Change the timeout parameter to publish at a different interval. timer.countdown_ms(5000); } @@ -270,10 +307,8 @@ pc.baud(921600); pc.printf("Stm32f103k3t6-w5500-Cayeme-ethernet\n"); OLED_INIT(); - mpu6050.whoAmI(); // Communication test: WHO_AM_I register reading - mpu6050.calibrate(accelBias,gyroBias); // Calibrate MPU6050 and load biases into bias registers - mpu6050.init(); ticker.attach(&Stm32f103c8t6_ticker, tickerTime); +// ph_ticker.attach(&PH_ticker, ph_sampleTime); // Set the correct SPI frequency for your shield, if necessary. For example, 42000000 for Arduino Ethernet Shield W5500 or 20000000 for Arduino Ethernet Shield W5100. W5500_init(); // Set the default function that receives Cayenne messages.