今天在FB Arduino-Taipei上看到有人分享了一套由串口取得資料來繪製曲線圖的軟體SerialChat,看起來不錯用就來試用看看。以下是使用完畢後的心得。
使用方式不難。就是設定軟體CONFIG,然後Arduino Code修改成合規則的輸出格式。只是軟體配置文件有一些小地方要注意,不然就會什麼輸出畫面都沒有。
配置設定注意事項︰
- 所有參數後方不可有任何字元(包含//#等備註)。如︰port=COM5 //COM Port Setting
- 每個不同數據設定的[Field1]中間的命名不可有空白。如︰Field 1可設定成Field_1
- Run的時侯同時間不要有其它設備或軟體在存取所使用的COM Port。
- COM Port的值現在的版本好像只支援到COM10以內
我測試時的設定︰
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[_setup_] | |
port=COM5 | |
baudrate=9600 | |
width=10000 | |
height=500 | |
background_color = white | |
display = list | |
display_sep = %09 | |
grid_h_origin = 250 | |
grid_h_step = 10 | |
grid_h_color = #EEE | |
grid_h_origin_color = #CCC | |
grid_v_origin = 0 | |
grid_v_step = 10 | |
grid_v_color = #EEE | |
grid_v_origin_color=#CCC | |
[_default_] | |
min=-1 | |
max=1 | |
type = float | |
precision = 2 | |
format = %n = %f | |
[photocell] | |
color=red | |
min=0 | |
max=1200 | |
[int_Voltage] | |
color=blue | |
min=0 | |
max=6 | |
[int_TEMP] | |
color=green | |
min=0 | |
max=100 |
測試用的Arduino Code︰
第一欄資料是由Arduino A0取得光敏電阻值
第二欄資料是取得Arduino內部電壓值
第三欄資料是取得Arduino內部溫度值
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int photocellPin = 0; | |
int photocellVal = 0; | |
void setup() { | |
Serial.begin(9600); | |
} | |
void loop() { | |
photocellVal = analogRead(photocellPin); | |
Serial.print(photocellVal); | |
Serial.print(","); | |
Serial.print(float(readVcc())/1000); | |
Serial.print(","); | |
Serial.println(GetTemp()); | |
delay(100); | |
} | |
long readVcc() { | |
long result; | |
// Read 1.1V reference against AVcc | |
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); | |
delay(2); // Wait for Vref to settle | |
ADCSRA |= _BV(ADSC); // Convert | |
while (bit_is_set(ADCSRA,ADSC)); | |
result = ADCL; | |
result |= ADCH<<8; | |
result = 1126400L / result; // Back-calculate AVcc in mV | |
return result; | |
} | |
double GetTemp(void) | |
{ | |
unsigned int wADC; | |
double t; | |
// The internal temperature has to be used | |
// with the internal reference of 1.1V. | |
// Channel 8 can not be selected with | |
// the analogRead function yet. | |
// Set the internal reference and mux. | |
ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3)); | |
ADCSRA |= _BV(ADEN); // enable the ADC | |
delay(20); // wait for voltages to become stable. | |
ADCSRA |= _BV(ADSC); // Start the ADC | |
// Detect end-of-conversion | |
while (bit_is_set(ADCSRA,ADSC)); | |
// Reading register "ADCW" takes care of how to read ADCL and ADCH. | |
wADC = ADCW; | |
// The offset of 324.31 could be wrong. It is just an indication. | |
t = (wADC - 324.31 ) / 1.22; | |
// The returned temperature is in degrees Celcius. | |
return (t); | |
} |
沒有留言:
張貼留言