After one week trying to read a temperature using stm32f103c8t6 and a LM35 I found that the only thing missed was a 10uF electrolitic capacitor between groung and signal pins of the sensor. Now it is working right.
Revision 1:9218b5180bd2, committed 2020-07-12
- Comitter:
- armo
- Date:
- Sun Jul 12 18:18:59 2020 +0000
- Parent:
- 0:aed747a24dcd
- Commit message:
- stm32f103c8t6 using a LM35 sensor. Use a 10uF electrolitic capacitor between groung and signal pns of LM35.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r aed747a24dcd -r 9218b5180bd2 main.cpp --- a/main.cpp Wed May 08 08:57:08 2013 +0000 +++ b/main.cpp Sun Jul 12 18:18:59 2020 +0000 @@ -1,37 +1,45 @@ +/**********************************************************************************************************/ +/* ATTENTION: You have to put a 10uF electrolict capacitor between the ground and signal terminals of LM35*/ +/**********************************************************************************************************/ #include "mbed.h" #include "TextLCD.h" -AnalogIn LM35(p15); +AnalogIn LM35(PA_6); +TextLCD lcd(PA_12,PA_11, PB_6, PB_5, PB_4, PB_3); +Serial pc(PA_9, PA_10); //Create an object of Serial Class PA_9=RX, PA_10=TX no FTDI -TextLCD lcd(p21,p22,p23,p24,p25,p26); +/*TextLCD lcd(p21,p22,p23,p24,p25,p26);*/ int main() { - float tempC,tempF,a[10],avg; + double tempC,tempF,avg;//,a[49]; int i; - + unsigned short a[99]; while(1) { - avg=0; -for(i=0;i<10;i++) +avg=0; +for(i=0;i<99 ;i++) { -a[i]=LM35.read(); +a[i]=LM35.read_u16(); wait(.02); } -for(i=0;i<10;i++) +for(i=0;i<99;i++) { -avg=avg+(a[i]/10); +avg=avg+(a[i]/100); } -tempC=(avg*3.685503686*100); -tempF=(9.0*tempC)/5.0 + 32.0; +tempC=(((avg*3.3)/65535)*100);//3.685503686 + + +//tempF=(9.0*tempC)/5.0 + 32.0; + lcd.locate(0,0); -lcd.printf(" Temperature "); +//lcd.printf(" Temperature "); lcd.locate(0,1); -lcd.printf("%.2f C %.2f F",tempC,tempF); - +lcd.printf("%.2f \n %.0f",tempC,avg); +pc.printf("%.2f \n\r",tempC);/*This line is to monitoring de temp values on a Terminal*/ wait(.5); } } \ No newline at end of file
diff -r aed747a24dcd -r 9218b5180bd2 mbed.bld --- a/mbed.bld Wed May 08 08:57:08 2013 +0000 +++ b/mbed.bld Sun Jul 12 18:18:59 2020 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/7e6c9f46b3bd \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file