[Intel Edison开发板] 05、Edison开发基于MRAA实现IO控制,特别是UART通信

一、前言

下面是本系列文章的前几篇:

前几篇文章中介绍了如何实现软硬件和云的通信:
这篇解决edison开发板控制IO口问题!

二、发现MRAA能解决问题过程:

下面是我发现MRAA能够解决问题的过程:

  1. 爱迪生首页 https://software.intel.com/en-us/iot/hardware/edison/dev-kit
  2. 嵌入式linux接口lib MRAA
  3. 英特尔文档搜索MRAA https://software.intel.com/en-us/iot/documentation?field_topic_tid=20780&value=80494
  4. 基础开发 https://software.intel.com/en-us/node/675522

为什么要提MRAA? 因为Edison开发板的开发包中提供了两种方式控制外设,其一是利用Intel提供封装好的各种常见的传感器模块的驱动,名叫:UPM 。另一种是更底层一点,直接操作UART\SPI\I2C\IO等设备的方法:

三、进一步了解MRAA——GitHub上mraa开源项目

3.1、 介绍:

Linux* Library for low speed IO Communication in C with bindings for C++, Python, Node.js & Java. Supports generic io platforms, as well as Intel® Edison, Intel® Joule, Raspberry Pi and many more. http://mraa.io

LINKhttps://github.com/intel-iot-devkit/mraa
INCLUDE:PWM、IIC等底层操作的库,也有简单demo及文档介绍。

四、浏览基础开发,到实现UART

步骤1、 根据 Blinking an LED using C/C++ 教程可以快速建立一个控制LED闪烁的工程,之前几个都是做过的(没必要看)
步骤2、 在eclipse的help中可以新建更多因特尔工程:控制LED闪烁、模拟输入检测、数字输入、数字输出等...

这些的引脚在板子正面写着,有电源组、模拟输入组和数字输出组,P8 P4等都在数字组。

eclipse中可建的工程

步骤3、 参考github中mraa中的example中的串口例子,实现爱迪生开发板和PC通过串口通信。
LINKhttps://github.com/intel-iot-devkit/mraa/blob/master/examples/java/UartExample.java

串口引脚在数字引脚一排,即P00 P01

public class Main{

    public static void main(String[] args) {
    	   //! [Interesting]
        Uart uart = new Uart(0);

        if (uart.setBaudRate(115200) != Result.SUCCESS) {
            System.err.println("Error setting baud rate");
            System.exit(1);
        }

        if (uart.setMode(8, UartParity.UART_PARITY_NONE, 1) != Result.SUCCESS) {
            System.err.println("Error setting mode");
            System.exit(1);
        }

        if (uart.setFlowcontrol(false, false) != Result.SUCCESS) {
            System.err.println("Error setting flow control");
            System.exit(1);
        }

        uart.writeStr("Hello monkeys");
        //! [Interesting]
    }
}

实现数据读取可以用下面code:

while(true){
    getData=uart.readStr(20);
    System.out.println(getData+"\n");
}

至此,可以实现爱迪生开发板串口读取数据,接下来研究蓝牙平面定位

系列文章:


@beautifulzzzz
智能硬件、物联网,热爱技术,关注产品
博客:http://blog.beautifulzzzz.com
sina:http://weibo.com/beautifulzzzz?is_all=1
posted @ 2016-11-15 01:55  beautifulzzzz  阅读(1943)  评论(0编辑  收藏  举报