九鼎创展论坛

标题: arduino ibox项目实战31-PhysicalPixel实验 [打印本页]

作者: armeasy    时间: 2014-10-29 09:11
标题: arduino ibox项目实战31-PhysicalPixel实验
硬件平台:PC机一台,ibox卡片电脑一只,arduino扩展板一个,串口调试板一个
软件平台:WIN7操作系统,android4.0android4.4系统,串口调试助手
实验目标:通过串口输入控制LED灯的亮与灭
打开arduino的IDE开发工具,依次点击文件->示例->04.Communication->PhysicalPixel,PhysicalPixel的示例程序将会被打开,其源码如下:
  1. const int ledPin = LED1; // the pin that the LED is attached to
  2. int incomingByte;      // a variable to read incoming serial data into

  3. void setup() {
  4.   // initialize serial communication:
  5.   Serial.begin(115200);
  6.   // initialize the LED pin as an output:
  7.   pinMode(ledPin, OUTPUT);
  8. }

  9. void loop() {
  10.   // see if there's incoming serial data:
  11.   if (Serial.available() >= 0) {
  12.     // read the oldest byte in the serial buffer:
  13.     incomingByte = Serial.read();
  14.     // if it's a capital H (ASCII 72), turn on the LED:
  15.     if (incomingByte == 'H') {
  16.       digitalWrite(ledPin, HIGH);
  17.     }
  18.     // if it's an L (ASCII 76) turn off the LED:
  19.     if (incomingByte == 'L') {
  20.       digitalWrite(ledPin, LOW);
  21.     }
  22.   }
  23. }
复制代码
       依次将串口调试板的VDD,TXD,RXD,GND接到ibox转接板的3.3VTXRXGND,打开串口调试助手,将波特率设置得和程序一致,COM口和PC机的串口一致,参考设置如下图所示:

运行arduino程序,在串口调试助手终端输入HL,点击发送,观察LED灯的状态。






欢迎光临 九鼎创展论坛 (http://bbs.9tripod.com/) Powered by Discuz! X3.2