首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

Realtek公司的RTL8195A即将支持MicroPython

Realtek公司的RTL8195A即将支持MicroPython

现在ESP8266因超高性价比非常火热,很多芯片供应商也开始加入这个市场。如台湾的Realtek也加入了这个行列,它推出了RTL8195A模块,性能比ESP8266高一倍,外设更多,价格还要低一些。而且RTL8195A即将支持MicroPython,这对MicroPython爱好者来说又多了一个选择。


下面是它相关的说明,网址是:http://cwyark.github.io/mpiot/rtl8195a/tutorial.html。这个网址可能直接访问不了,所以我将它的一部分内容复制过来,给大家参考。



Tutorial
要使用MicroPython之前,你需要先將MicroPython@RTL8195A 的韌體燒錄至開發板內。

燒錄方式可參考 how_to_install_micropython

Basic Usage
首先將MicroUSB Cable 接上開發板,透過終端機程式, ex: minicom, putty 或 TeraTerm, 設定包率為8N1, 115200,並連進開發板。 試著按幾次Enter,你會在畫面看到:

  • >>>
  • >>>
  • >>>

复制代码

按開發板上的reset鍵,你也可以看到開機畫面。

  • =========================================================
  • ROM Version: 0.2
  • Build ToolChain Version: gcc version 4.8.3 (Realtek ASDK-4.8.3p1 Build 2003)
  • =========================================================
  • Check boot type form eFuse
  • SPI Initial
  • Image1 length: 0x36e4, Image Addr: 0x10000bc8
  • Image1 Validate OK, Going jump to Image1
  • ===== Enter Image 1 ====
  • SDR Controller Init
  • load NEW fw 0
  • Flash Image2:Addr 0xb000, Len 351472, Load to SRAM 0x10006000
  • Image3 length: 0x1beb0, Image3 Addr: 0x30000000
  • Img2 Sign: RTKWin, InfaStart @ 0x10006019
  • ===== Enter Image 2 ====
  • Starting main task
  • Starting executing main.py
  • MicroPython v1.8.1-42-g5a23590-dirty on 2016-06-18; Ameba Board with RT8195A
  • Type "help()" for more information.
  • >>>

复制代码
註解

Ctrl+D 可以reset開發板。

Ctrl+B 可以重啟REPL (不做HW reset)

Ctrl+E 可進入paste mode。在此模式貼上程式碼後輸入Ctrl+D,MicroPython會執行你所貼上的程式碼。


Numerical Operation
目前支援整數及浮點數運算


  • >>> 1 + 1
  • 2
  • >>> 1 * 2
  • 2
  • >>> 4e2
  • 400.0
  • >>> 3 % 2
  • 1
  • >>> 2 / 3
  • 0.6666667
  • >>> 123456/999999
  • 0.1234561
  • >>> 1.3e3
  • 1300.0

复制代码


另也有math 模組可供使用,幫助你做基本數學運算。
  • >>> import math
  • >>> math.
  • __name__        e               pi              sqrt
  • pow             exp             log             cos
  • sin             tan             acos            asin
  • atan            atan2           ceil            copysign
  • fabs            floor           fmod            frexp
  • ldexp           modf            isfinite        isinf
  • isnan           trunc           radians         degrees
  • >>> math.
  • >>> math.pi
  • 3.141593
  • >>> math.sin(math.degrees(90))
  • -0.9540797
  • >>> math.pow(2, 3)
  • 8.0

复制代码


Hardware Control
硬體控制可以參考下圖方格所定義的名稱。ex: PA_1, PA_2, PD_5 ...



  • # To control I/O output
  • >>> from machine import Pin
  • >>> pin1 = Pin("PA_1", dir=Pin.OUT)
  • >>> pin1.toggle()
  • >>> pin1.value(1)
  • >>> pin1.value(0)
  • # To read I/O's value
  • >>> pin2 = Pin("PC_0", dir=Pin.IN, pull=Pin.OPEN_DRAIN)
  • >>> pin2.value()
  • 1

复制代码


Filesystem

RTL8195A 實體上有1MB的Flash空間,micropython 直譯器約略500KB,剩下的500KB 都會被格式化為FATFS,可供使用者存放小量資料及.py檔。

使用者可以使用os 模組及Standard I/O 存取filesystem (硬碟名稱為 /flash)


  • >>> import os
  • >>> os.listdir("/")
  • ['flash']
  • >>> os.listdir("/flash")
  • ['main.py']
  • >>> os.mkdir("test_dir")
  • >>> os.listdir("/flash")
  • ['main.py', 'test_dir']
  • >>> os.chdir("test_dir")         # to change current directory
  • >>> os.getcwd()                  # to get current directory
  • '/flash/test_dir'
  • >>> os.chdir("/flash")
  • >>> os.rename("test_dir", "test_dir2")       # rename file or directory
  • >>> os.listdir("/flash")
  • ['main.py', 'test_dir2']
  • >>> os.rmdir("test_dir2")
  • >>> os.listdir("/flash")
  • ['main.py']
  • Now doing the file open/close/seek/read/write
  • >>> my_file = open("main.py", "r")
  • >>> my_file.readall()
  • '# main.py -- put your code here! The script in main.py will be executed when boot up !\r\n'
  • >>> my_file.readall()
  • ''
  • >>> my_file.seek(0)
  • 0
  • >>> my_file.readall()
  • '# main.py -- put your code here! The script in main.py will be executed when boot up !\r\n'
  • >>> my_file.close()
  • >>> new_file = open("text.txt", "w")
  • >>> new_file.write('hello!!!! this is a test file')
  • 29
  • >>> new_file.close()
  • >>> os.listdir("/flash")
  • ['main.py', 'text.txt']
  • >>> os.remove("/flash/text.txt")

复制代码
继承事业,薪火相传
返回列表