物聯網平台開發人才平日班

物聯網平台開發人才平日班
【8/30 物聯網平台開發人才養成班】 僅剩最後2位名額,立即下載106年招生簡章!(待業者限定 平日密集培訓)

2017年8月17日 星期四

嵌入式常用的RS485/Modbus



RS485:
  • 為半雙工(同一時間只能進行傳送/接收的動作),多點通訊之標準
  • 為差動傳輸,使用纜線兩端(D+、D-)的電壓差來表示傳遞訊號
  • 常用於單機傳送(Master),多機接收(Slave)的通訊鏈結。可將數個感應裝置的數值回傳給Master
Modbus over RS485:
  • Modbus是一種串列通訊協定
  • Modbus為master/slave架構。一個裝置為Master節點,其他節點為slave。
  • 每一個slave裝置都有一個唯一的位址/ID (1~247)
  • Since a single byte is normally used to define the slave address and each slave on a network requires a unique address, the number of slaves on a network is limited to 256. The limit defined in the modbus specification is even lower at 247.
  • master和slave之間走的Modbus 協定其封包格式有分ASCII 或RTU兩種
  • ASCII 為文字模式, 用character 傳送, RTU 為binary 模式傳送
  • 封包格式:   Slave ID  | Function Code | Data | CRC
RTU 訊息格式
  • Information is stored in the Slave device in four different tables.
  • Two tables store on/off discrete values (coils) and two store numerical values (registers). The coils and registers each have a read-only table and read-write table.
Coil/Register Numbers
Data Addresses
TypeTable Name
1-9999
0000 to 270E(9999)
Read-WriteDiscrete Output Coils
10001-19999
0000 to 270E
Read-OnlyDiscrete Input Contacts
30001-39999
0000 to 270ERead-OnlyAnalog Input Registers
40001-49999
0000 to 270ERead-WriteAnalog Output Holding Registers

Coil/Register Numbers can be thought of as location names since they do not appear in the actual messages. The Data Addresses are used in the messages.For example, the first Holding Register, number 40001, has the Data Address 0000. The difference between these two values is the offset.
Each table has a different offset. 1, 10001, 30001 and 40001.


What is a function code?

The second byte sent by the Master is the Function code. This number tells the slave which table to access and whether to read from or write to the table.

Function CodeActionTable Name
01 (01 hex)ReadDiscrete Output Coils
05 (05 hex)Write singleDiscrete Output Coil
15 (0F hex)Write multipleDiscrete Output Coils
02 (02 hex)ReadDiscrete Input Contacts
04 (04 hex)ReadAnalog Input Registers
03 (03 hex)ReadAnalog Output Holding Registers
06 (06 hex)Write singleAnalog Output Holding Register
16 (10 hex)Write multipleAnalog Output Holding Registers

Example: 


Read Holding Registers (FC=03)
Request
This command is requesting the content of analog output holding registers # 40108 to
 40110 from the slave device with address 17.
11 03 006B 0003 7687
11: The Slave Address (11 hex = address17 )
03: The Function Code 3 (read Analog Output Holding Registers)
006B: The Data Address of the first register requested.
             ( 006B hex = 107 , + 40001 offset = input #40108 )
0003: The total number of registers requested. (read 3 registers 40108 to 40110)
7687: The CRC (cyclic redundancy check) for error checking.
Response
11 03 06 AE41 5652 4340 49AD
11: The Slave Address (11 hex = address17 )
03: The Function Code 3 (read Analog Output Holding Registers)
06: The number of data bytes to follow (3 registers x 2 bytes each = 6 bytes)
AE41: The contents of register 40108
5652: The contents of register 40109
4340: The contents of register 40110
49AD: The CRC (cyclic redundancy check).


Read Coil Status (FC=01)
Request
This command is requesting the ON/OFF status of discrete coils # 20 to 56
from the slave device with address 17.
11 01 0013 0025 0E84
11: The Slave Address (11 hex = address17 )
01: The Function Code 1 (read Coil Status)
0013: The Data Address of the first coil to read.
             ( 0013 hex = 19 , + 1 offset = coil #20 )
0025: The total number of coils requested.  (25 hex = 37,  inputs 20 to 56 )
0E84: The CRC (cyclic redundancy check) for error checking.
Response
11 01 05 CD6BB20E1B 45E6
11: The Slave Address (11 hex = address17 )
01: The Function Code 1 (read Coil Status)
05: The number of data bytes to follow (37 Coils / 8 bits per byte = 5 bytes)
CD: Coils 27 - 20 (1100 1101)
6B: Coils 35 - 28 (0110 1011)
B2: Coils 43 - 36 (1011 0010)
0E: Coils 51 - 44 (0000 1110)
1B: 3 space holders & Coils 56 - 52 (0001 1011)
45E6: The CRC (cyclic redundancy check).
The more significant bits contain the higher coil variables. This shows that coil 36 is off (0) and 43 is on (1). Due to the number of coils requested, the last data field1Bcontains the status of only 5 coils.  The three most significant bits in this data field are filled in with zeroe


RS485 模組 (MAX485)的Pin 腳定義:


  • pin 1 :RO (receive out)
  • pin 2 RE (receive enable) 
  • pin 3 :DE (data enable) 
  • pin 4 :DI (data in)
  • pin 5, pin 8 :  Gnd  and Vcc onnected
  • pin 6,7 : A and B  the RS485 pair

RO: UART TX
DI UART RX
把/RE and DE 短路, 然後MCU/Pi 用一根GPIO 決定 /RE 或 DE.(即是決定是在送還是在收的狀態, 因為RS485是單工)













2017年8月8日 星期二

[新手教學] Linux Driver 數位課程學習須知



 教學影片內容為Linux Driver 觀念解說與各Linux Driver 技術主題的說明並有講師Demo Pi 3影片


先備知識: 

  1. 具Linux 系統操作能力
  2. 熟悉的C程式設計能力
  3. 會使用gcc, make 的等GNU開發工具
  4. 有Linux 系統程式設計的經驗
Raspberry Pi 3 環境建置:


請先登入學習平台,在[課程公告]處, 點選下載 Pi3_driver_shield3_image_20161223_16G.rar, 此為艾鍗 Linux Driver 上課用 image

請先解開 rar 壓縮檔, 然後再用WinDisk工具寫入至 16G MicroSD 卡中

開機後, root登入, 密碼: 123456


 Driver code only for Pi 3
  1.  目前講師所整理的code 僅以Raspberry Pi 3 搭配艾鍗 Raspberry Pi 3 Shield 版本為主, Pi 2 程式已無更新


Driver 程式目錄結構




2017年8月7日 星期一

常常弄不清楚的 CSS Selector



CSS class definition with multiple identifiers

常常弄不清楚的 CSS Selector
  • .class1.class2 will match only the elements that have both of them classes defined.
    .class1.class2 { background: red; }
    <div class="class1 class2"></div>
  • .class1, .class2 will match the elements with .class1 or .class2
    .class1, .class2 { background: yellow; }
    <div class="class1"></div>
    <div class="class2"></div>
  • .class1 .class2 will match only the elements with class2 within elements with class1.
    .class1 .class2 { background: blue; }
    <div class="class1">
        <div class="class2"></div>
    </div>

善用工具: 

開Chrome瀏覽器 F12 開發者工具偵察現有的網頁 CSS 樣式規則,判斷產生該效果的 CSS 樣式設定來源

2017年8月6日 星期日

使用SSH登入Raspberry Pi




使用SSH登入Raspberry Pi


  1. 先碓認 Pi 和 PC之間網路必須能連通, 可以用 ping <IP位址>
  2. 同時再確認: Pi 本身的SSH 服務必須是開啓的 (一般來說應該都是開啓的), 可以使用 netstat -atn 查看是否SSH有開啓

  3.  接著使用putty (SSH Client)登入

    先下載windows putty 軟體
    32-bit: putty.exe
    64-bit: putty.exe 









   4. 或者用 MobaXterm 的SSH Client登入, 它除了有終端機, 還有SFTP Client 的功能

在Remote host 輸入 Pi 的IP , 按下OK後即可連入 (使用預設SSH的Port: 22 )


   由於MobaXterm 將SFTP 功能整合進來, 所以爾後還方便我們進行PC和Pi之間的檔案傳輸



embeddedlinux



HTML Color Codes


HTML Color Codes

1在CSS中常常須要設定顏色, 例如要設定 background-color: #4CAF50; 常常須要RGB色碼, 可以到這裡去找快速查詢





2) 若是想要知道某一個圖所用的"顏色", 不知道色碼時怎麼辦 ? 可以先 [Print Screen] , ,再用小畫家, 用"點滴"查看color  







2017年8月1日 星期二

About BBC Micro: bit


The Micro Bit (also referred to as BBC Micro Bit, stylized as micro:bit) is an ARM-based embedded system designed by the BBC for use in computer education in the UK.

One of the main aims of the micro:bit is to “help a new generation get creative with technology and take advantage of the opportunities a career in science, technology, engineering and maths offers”.

The micro:bit, measuring just 4cm by 5cm, is a stripped down computer which children can use to code and create anything they set their minds to! It’s intended as a starter device to give children a basic introduction to physical computing and tinkering, so that they can move on to using more advanced devices such as an Arduino or Raspberry Pi.




Key features:

  • A display consisting of 25 red LEDs;
  • Two programmable buttons;
  • An on-board motion sensor or “accelerometer”;
  • A built-in compass or “magnetometer”;
  • Bluetooth Smart Technology;
  • Three input and output (I/O) rings.





Spec:


  • Nordic nRF51822 Multi-protocol Bluetooth® 4.0 low energy/2.4GHz RF SoC
    • 32-bit ARM Cortex M0 processor (16MHz)
    • 16kB RAM
    • 256kB Flash
    • Bluetooth Low Energy Master/Slave capable
  • Input/Output
    • 25 LED Matrix
    • Freescale MMA8652 3-axis Accelerometer
    • Freescale MAG3110 3-axis Magnetometer (e-compass)
    • Push Button x2
    • USB and Edge connector Serial I/O
    • 2/3 reconfigurable PWM outputs
    • 5 x Banana/Croc-clip connectors
    • Edge connector
    • 6 x Analog In
    • 6-17 GPIO (configuration dependent)
    • SPI
    • i2c

There are four official code editors in the BBC micro:bit web site