新版的Arduino 1.0 sketch附加檔名已由原來的.pde更改為.ino,以避免與Processing的Sketch混淆。同時無論在IDE或Libraries都有相當程度的更新:Arduino Software Release Note
(Arduino IDE 0.0.22與0.1.00比較)
而NXShield_AVR程式庫也在2011/12/14更新了相容版本(0.0.95),下載點:NXShield_AVR-0.0.95經過測試功能正常。
NXShield所使用的Arduino腳位(IO Pins)
為了讓4個Sensor Ports都可以連接I2C數位裝置,Mindsensors在NXShield的程式庫實作了SoftI2cMaster的功能,以突破Arduino只能有一個Hardware I2C界面的限制,因此UNO版共使用了A0,A1,A2,A4,A5,D2,D4,D7這些Pin以及Hardware Timer 2 (D3,D11),詳細在NXShield Advanced Development Guide中有說明或直接參考API中的常數定義檔(SHDefines.h)。
NXShield的程式開發
Mindsensors替NXShield發展了功能相當齊全的程式庫:NXShield_AVR,以及整理完善的說明文件與範例程式,這些也都包含在下載的程式庫檔案中,事實上這個版本的API也就是以原來的NXTI2CDevice Library為基礎所發展出來,以下為Class的架構圖:
以後如果想要自行擴充標準API的功能或製作新的Device Class,都可以運用以這個程式庫的功能為基礎來開發,比較能事半功倍,因為到底NXShield還算是一個有相當複雜程度的裝置。
結論摘要
Arduino的系統資源比起NXT可以說是差了一大截,不過NXShield卻幾乎移植了NXT主要的 IO裝置功能到Arduino來,而且尚有餘裕的空間可以再擴充NXT所缺的功能,例如TCP/IP的網路通訊。
我想最主要的原因有兩個,首先,NXShield本身無論在Motor Control或類比式感應器等這些處理功能的齊全,分擔了Arduino相當多的工作,事實上,一個NXShield相當於結合兩個NXTMMX再加上許多額外的功能。
其次,API程式庫的功能規劃的相當完善且很容易上手使用,這是個人覺得最值得讚賞的部份。
等到收到產品之後,接下來要測試的重點會是:
(1)有沒有可能成為NXT的有力助手。
(2)附加其他擴充版的應用。
沒有問題, 也歡迎一起研究與分享心得
我自己也訂了兩片, 所以已經有了, 感謝您的好意 : )
Arduino 1.0,
we finally froze the Arduino API, the IDE and the layout of the boards. We’ve made some minor additions to the Arduino connectors to make them more flexible. Tomorrow you will be able to download the release candidate and in 1 month of frantic testing with the community, the platform will be ready and stable.
Arduino Leonardo,
a low cost Arduino board with the Atmega32u4. It has the same shape and connectors as the UNO but it has a simpler circuit. On the software side it has a nifty USB driver able to simulate a mouse , a keyboard, a serial port (with more drivers coming later). As usual for Arduino, everything will be released as open source (Core, Bootloader, Hardware).
UNO的升級版?
Arduino Due,
a major breakthrough for Arduino because we’re launching an Arduino board with a 32bit Cortex-M3 ARM processor on it. We’re using the SAM3U processor from ATMEL running at 96MHz with 256Kb of Flash, 50Kb of Sram, 5 SPI buses, 2 I2C interfaces, 5 UARTS, 16 Analog Inputs at 12Bit resolution and much more.
Instead of just releasing the finished platform we are opening the process to the community early on. We’re going to be demoing the board and giving away some boards to a selected group of developers who will be invited to shape the platform while it’s been created. After Maker Faire, we will begin selling a small batch of Developer Edition boards on the Arduino store (store.arduino,cc) for members of the community who want to be join the development effort. We plan a final and tested release by the end of 2011
Arduino Wifi Shield. It adds Wi-Fi communication capabilities to any Arduino. Instead of using any of the classic WiFi modules on the market we wanted to have something that will provide the maximum level of hackability to the user. The shield is based on a wifi micro module made by H&D Wireless coupled with a powerful AVR32 processor that carries the full TCP-IP stack leaving room to add your own protocols and customisations. We’ve also worked hard to make sure that you will be able to migrate your code from the Ethernet Shield with minor changes.
最期待的是這個Shield,終於有機會能夠讓 NXT 使用無線網路 :-)
在Arduino
I2C Wire.h Multi-Masters功能實作中以Arduino+Gravitech
7-SEG Shield組合成為一個I2C Slave Device,可以提供其它的Arduino使用I2C Master方式控制LED的顯示,藉以驗證Wire.h具備多重I2C Master的處理功能。
而原先的構想是任何可以進行I2C通訊的裝置,應該都可以控制這個I2C Slave Device,包含NXT在內,而事實上NXT對Arduino的I2C通訊也經由實際測試,運作正常。
不過經由多次的測試,NXT始終無法如同Arduino一般能夠正常的存取這個I2C Salve
Device,而比較之前的測試Case,唯一的差別就在於Gravitech 7-SEG
Shield擴充板所內建對於SDA及SCL的4.7k ohm pull-up,實在是百思不解問題真正所在。
Arduino Network Device建構
(Photo)
而為了讓NXT可以使用Gravitech 7-SEG Shield的功能,所以改造原來的I2C Slave
Device成為Network Device。
不再使用I2C而改為Ethernet TCP/IP方式,:
(1). 以Arduino UNO + Gravitech 7-SEG Shield +
Arduino Ethernet
Shield組合成為 Telnet Server。
(2). 另外使用 Arduino UNO + Arduino Ethernet Shield組合成為Telnet Client。
至於NXT則透過I2C傳送指令與資料給Telnet Client,由Client端UNO組合成封包之後經由網路線傳送至Telnet Server接收,而Server端的UNO解析之後再以I2C控制Gravitech 7-SEG Shield執行指定的功能,有點複雜但可玩性十足。
(架構圖)
(Demo Video)
NXT對於Network Device控制流程
整體架構共分成三個部份:
(1). NXT to Telnet Client:
將Telnet Client作為I2C Slave Device,規劃相關功能對應的Register Address及Data需求:
0x00
- 回傳裝置資訊,這是用來測試I2C通訊功能是否正常。
0x41+三色LED顯示指令(R/G/B) -
控制Gravitech 7-SEG
Shield顯示指定顏色。
0x42+英數字串 - 控制Gravitech 7-SEG
Shield將字串顯示在七段式LED。
0x43+整數值字串 - 控制Gravitech 7-SEG
Shield將數字顯示在七段式LED。
因此,NXT即將前述的指令以LowspeedWrite()傳送給Client端的UNO,而對於UNO即會觸發onReceive()的handler進行接收。
(2). Telnet Client to Server:
Client端UNO負責將接收到的NXT
request解析並製作成資料封包後,使用Ethernet.h library的功能,透過Arduino Ethernet Shield以網路線傳送至Server端,而Server端的UNO同樣也是以Ethernet.h的功能接收封包資料。
(3). Telnet Server to Gravitech 7-SEG Shield
Server端經解析來自Client端的資料之後,即分別使用Digital I/O控制三色LED的顏色顯示以及以I2C方式控制七段式LED顯示字串資料。
Gravitech的Arduino
7SEG Shield為具有三個I2C裝置的Arduino擴充板,包含:
(1) 以SAA1064晶片驅動的4位數7段LED (I2C address: 0x38)、
(2) TMP75數位溫度感應器 (I2C address:0x49)、
(3) 24LC128 EEPROM (I2C address:0x50)。
關於各I2C裝置的用法,可參考原廠Datasheet,同時也可以參照Gravitech所提供的Sample
Code ,示範由TMP75讀取溫度值然後顯示在LED的作法。
Arduino多功能I2C裝置實作
在前篇” NXT與Arduino多重I2C Master之實作測試”對於Arduino Wire.h Library I2C Multi-Master功能的實作,這裡再以相同的應用方式改以Arduino UNO加上這個Shield組合而成為一個”多功能I2C裝置”作為實作範例,
並規劃UNO兼具以下之I2C Slave與Master雙角色功能:
※由UNO擔任Slave角色,負責接收與回應來自其他外部裝置對於”多功能I2C裝置”的I2C操作需求。
※當UNO處理外部I2C訊息時,若需要控制擴充板裝置(SAA1064、TMP75)的運作, 則UNO轉換成為Master角色,傳送I2C指令操作指定裝置。
因此就”多功能I2C裝置”而言,UNO就如同擔任代理人(Delegate) 角色,負責處理外部使用需求的介面。
依據這樣的應用,規劃”多功能I2C裝置”的功能如下:
(1) 於UNO Sketch setup()先進行TMP75及SAA1064的初始化設定(Master角色),
完成之後以0x31
address加入I2C bus, 在loop()即進入接收外部I2C通訊的待命狀態(Slave角色)。
(2) 於receiveEvent ()處理外部裝置使用LED顯示數字(Register
address: 0x42) 與 字串(Register
address: 0x43)的功能,包含:數字、字母的LED字型轉換,以及字串以跑馬燈方式顯示。
(3) 於requestEvent()處理回復裝置資訊的需求(Register
address: 0x00)。
(4) 對於TMP75數位溫度計考慮讀取效率,由外部裝置直接以Slave address(0x49)進行讀取(回復2個Bytes),不間接透過UNO處理。
Arduino I2C
Slave Device處理Master request須知
以Arduino UNO作為Slave device,對於處理與回應外部I2C request的Sketch程式碼,需要留意以下注意事項:
(1) 在loop()中,應該專職於Slave的角色,除非是要處理來自Master的要求,不要主動去啟始對其他Slave Device的I2C通訊,否則會造成外部裝置(Master)無法通訊的狀況。
(2) 在receiveEvent ()中,只進行資料的接收,後續的需求處理,應該在接收完成後回到loop()再進行,以免干擾整體的通訊過程。
(3) 在requestEvent()中,只處理資料的回復,必須維持以Slave角色完成通訊過程的完整性,如果要求回復的資料需要去向另一個Slave Device request,就必須拆分成兩次通訊過程來完成。
以NANO作為外部裝置測試
(1) 要求UNO Slave (0x31)
回傳它的裝置資訊 (Register address: 0x00) ,會觸發requestEvent() 回傳”UNO-Ox31”的字串。
(2) 要求TMP75 (0x49)
回傳所測量的溫度值。
(3) 要求UNO Slave (0x31)
在LED顯示數值資料(Register
address: 0x42),會觸發receiveEvent() 接收顯示指令及數值,先判斷設定status flag (isDisplayNumber=true) 之後,回到loop () 即依據status flag啟始對SAA1064的數字顯示要求。
(4) 要求UNO Slave (0x31)
在LED以跑馬燈方式顯示字串(Register
address: 0x43),會觸發receiveEvent () 接收顯示指令及字串,先判斷設定status flag (isDisplayText=true) 之後,回到loop () 即啟始對SAA1064的字串顯示要求。
Sketch程式:
(1) Arduino I2C Slave Device - Arduino_I2C_Device.pde
(2) NANO外部裝置 - NANO_CTRL_4SEG7.pde
byte I2C_req_buf[];
ArrayBuild(I2C_req_buf,
deviceAddress, deviceRegister,
anotherDevice,
anotherRegister, anotherCommand);
while(I2CCheckStatus(I2C_PORT)
== STAT_COMM_PENDING);
LowspeedWrite(I2C_PORT,
0, I2C_req_buf);
}
…
sendTransferCommand(ARDUINO_RED_SEND_ADDRESS,
ARDUINO_TRANSFER_CMD,
ARDUINO_GREEN_ADDRESS,
ARDUINO_COMMAND_REG,
LED_ON);
Arduino新增的Function與呼叫程式碼:
void loop()
{
if
(isTransfer) {
Wire.beginTransmission(anotherAddress);
Wire.send(anotherRegister);
Wire.send(anotherCommand);
Wire.endTransmission();
isTransfer = false;
}
}
void receiveEvent(int howMany)
{
requestRegister = Wire.receive();
if
(requestRegister == 0x42) {
requestCommand = Wire.receive();
if
(requestCommand == LED_ON) {
digitalWrite(LED_PIN, HIGH);
}
else
if (requestCommand == LED_OFF) {
digitalWrite(LED_PIN, LOW);
}
}
else if
(requestRegister == 0x43) {
anotherAddress= Wire.receive();
anotherRegister = Wire.receive();
anotherCommand= Wire.receive();
isTransfer = true;
}