[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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM