硬件平台:PC机一台,ibox卡片电脑一只,arduino扩展板一个,串口调试板一个 软件平台:WIN7操作系统,android4.0或android4.4系统,串口调试助手 实验目标:通过串口输入控制LED灯的亮与灭 打开arduino的IDE开发工具,依次点击文件->示例->04.Communication->PhysicalPixel,PhysicalPixel的示例程序将会被打开,其源码如下: - const int ledPin = LED1; // the pin that the LED is attached to
- int incomingByte; // a variable to read incoming serial data into
- void setup() {
- // initialize serial communication:
- Serial.begin(115200);
- // initialize the LED pin as an output:
- pinMode(ledPin, OUTPUT);
- }
- void loop() {
- // see if there's incoming serial data:
- if (Serial.available() >= 0) {
- // read the oldest byte in the serial buffer:
- incomingByte = Serial.read();
- // if it's a capital H (ASCII 72), turn on the LED:
- if (incomingByte == 'H') {
- digitalWrite(ledPin, HIGH);
- }
- // if it's an L (ASCII 76) turn off the LED:
- if (incomingByte == 'L') {
- digitalWrite(ledPin, LOW);
- }
- }
- }
复制代码 依次将串口调试板的VDD,TXD,RXD,GND接到ibox转接板的3.3V,TX,RX,GND,打开串口调试助手,将波特率设置得和程序一致,COM口和PC机的串口一致,参考设置如下图所示:
运行arduino程序,在串口调试助手终端输入H或L,点击发送,观察LED灯的状态。
|