Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan1 智慧電子應用設計導論 (1/3) Communication - Serial Chin-Shiuh Shieh ( 謝欽旭 ) Department of Electronic Engineering National Kaohsiung University of Applied Sciences, Taiwan
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan2 Communication Built-in –UART –SPI –TWI/I2C Software –UART –OneWire –…
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan3 Advanced Communications PC Smart Phone/Bluetooth Internet/ WiFi,Ethernet Wireless UART GSM GPS …
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan4 Serial -Functions if (Serial) available() begin() end() find() findUntil() flush() parseFloat() parseInt()
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan5 Serial –Functions (cont) peek() print() println() read() readBytes() readBytesUntil() setTimeout() write() serialEvent()
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan6 Example – available/read void setup() { Serial.begin(9600);Serial1.begin(9600); } void loop() { Serial1.println("Hello, Arduino!"); delay(500); while(Serial.available()) { Serial.print(char(Serial.read())); } delay(500); }
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan7 Example – find/parse void setup() { Serial.begin(9600); } void loop() { if(Serial.find("Speed=")){ Serial.println(Serial.parseInt()); }
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan8 RS-232 Programming on PC My personal choice –Borland C++ Builder 5.0 –ComPort Library version 2.64 by Paul Doland –TMS Instrumentation Workshop by TMS Software /mc/advanced/index.html#PCChttp://bit.kuas.edu.tw/~csshieh/teach/101A /mc/advanced/index.html#PCC
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan9 Example – TMSIW_02 void setup() { int i; Serial.begin(9600); for(i=0;i<8;i++)pinMode(14+i,OUTPUT); } void loop() { unsigned char x; int i; while(Serial.available()) { x=Serial.read(); for(i=0;i<8;i++){digitalWrite(14+i,bitRead(x,i));} Serial.write(analogRead(A0)/4); delay(100); } dvanced/pcc02.zip on PChttp://bit.kuas.edu.tw/~csshieh/teach/101A/mc/a dvanced/pcc02.zip
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan10 Example – TMSIW_03 void setup() { Serial.begin(9600); } void loop() { Serial.write(analogRead(A0)/4); delay(100); } dvanced/pcc03.zip on PChttp://bit.kuas.edu.tw/~csshieh/teach/101A/mc/a dvanced/pcc03.zip