之前做了不少東西,做完後又懶得紀錄,不知不覺就積了不少,趁有時間在這邊紀錄一下
有需要的就直接照做吧,原理不敘述太多,有些註解寫在程式碼裡面了
要用STM32F103做之前要先參照我之前的那篇將STM32轉成arduino開發方式的文章
電路如下,電阻選12.2也是有用意的,畢竟是微毆姆計,所以當然就是針對很小的阻抗量測所製作的
這個電路的量測範圍是0~23 ohm,至於你想要甚麼範圍就要依你的需求自己去算了
程式碼如下:
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27,16,2); //設定LCD位置0x27,設定LCD大小為16*2
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
lcd.init(); //初始化LCD
lcd.backlight(); //開啟背光
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(PA0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (3.25 / 4096.0);//F103=3.3V & 12bit,mega328=5V
float Rx = (voltage / 0.1)-0.05;//LM317 is 1.25V,R=12.2,so I = 0.101
if (Rx > 23)
{
/*lcd.setCursor(0,0);//前面是左右,後面是上下
lcd.print(" ");*/
lcd.setCursor(0,1);//前面是左右,後面是上下
lcd.print(" ");
Serial.println( " Out of Range ");
lcd.setCursor(0,0);//前面是左右,後面是上下
lcd.print("Out of 23ohm");
delay(1000);
}
if (Rx < 23)
{
lcd.setCursor(4,0);//前面是左右,後面是上下
lcd.print(" ");
lcd.setCursor(0,1);//前面是左右,後面是上下
lcd.print(" ");
Serial.print(Rx);
lcd.setCursor(0,0);//前面是左右,後面是上下
lcd.print(Rx);
Serial.println(" Ohm ");
lcd.setCursor(0,1);//前面是左右,後面是上下
lcd.print("Ohm");
delay(1000);
}
}
下面為程式碼連結 :
https://drive.google.com/file/d/1AEFShW-1SJ9uO3yROORWA4jBYjaDOUxl/view?usp=sharing