WHAT'S NEW?
Loading...
Showing posts with label Ameba arduino. Show all posts
Showing posts with label Ameba arduino. Show all posts
材料準備
範例說明
在前個例子
"I2C - 利用I2C讓Ameba與Arduino UNO溝通"
裡,Ameba 是 I2C master, 而Arduino UNO 是 I2C slave,並且讓 Ameba 送資料給 Arduino UNO。
在這個範例裡, Ameba 一樣是 I2C master, Arduino UNO 是 I2C slave, 但是改成資料從 Arudino UNO 傳給 Ameba。
準備Arduino Uno為 I2C Slave
首先我們先準備 Arduino,先將Arduino IDE選成Arduino, “Tools” -> “Board” -> “Arduino/Genuino Uno”:
接著打開 Slave Sender 的範例,"Examples" -> "Wire" -> "slave_sender"
然後點選 “Sketch” -> “Upload” 將程式編譯並上傳到 Arduino Uno。
準備Ameba 為 I2C Master
我們額外再開一個Arduino IDE,確定板子是 Ameba, “Tools” -> “Board” -> “Arduino Ameba”
然後打開 Master Reader 的範例, “File” -> “Examples” -> “AmebaWire” -> “master_reader”
然後點選 “Sketch” -> “Upload” 將程式編譯並上傳到 Ameba。
接線
Arduino的範例裡,使用A4當作I2C SCL, A5為I2C SDA。這些接腳與Ameba一樣。
另外很重要的是,兩塊板子的GND要互接。
接著我們要從Serial Monitor視窗來看Ameba印出讀到的數據 首先我們要找到Ameba的Serial Port, 點Windows的[開始] 按鈕 、[控制台]、[系統及安全性],然後在 [系統] 下方按一下 [裝置管理員],開啟 [裝置管理員]。 會看到Ports那邊有個mbed Serial Port(COM15), 這邊COM15就是就是Ameba的Port Number
接著我們將Arduino的Port選到COM15, 它在 “Tools” -> “Port” -> COM15 (Ameba目前的Mbed Serial Port)。
每當我們要從Arduino IDE看Ameba印出的訊息, 都要設定成正確的port:
打開包含Ameba的Arduino IDE,開啟Serial Monitor, “Tools” -> “Serial Monitor”, 會出現Serial Monitor的視窗,這個視窗可以讓你看到Ameba印出來的訊息。
接著按下Arduino Uno的Reset按鈕,讓Arduino Uno等待I2C master連接。
再按下Ameba的Reset按鈕,讓Ameba開始接收從Arduino Uno傳過來的訊息。這時候會看到Serial Monitor每隔0.5秒出現 "hello " 的訊息,這樣就代表成功了。
(NOTE: 如果發現 Ameba 的 Serial Monitor沒出現訊息,請試試看重開 Serial Monitor)
在這個範例裡, Ameba 一樣是 I2C master, Arduino UNO 是 I2C slave, 但是改成資料從 Arudino UNO 傳給 Ameba。
首先我們先準備 Arduino,先將Arduino IDE選成Arduino, “Tools” -> “Board” -> “Arduino/Genuino Uno”:
接著打開 Slave Sender 的範例,"Examples" -> "Wire" -> "slave_sender"
然後點選 “Sketch” -> “Upload” 將程式編譯並上傳到 Arduino Uno。
我們額外再開一個Arduino IDE,確定板子是 Ameba, “Tools” -> “Board” -> “Arduino Ameba”
然後打開 Master Reader 的範例, “File” -> “Examples” -> “AmebaWire” -> “master_reader”
然後點選 “Sketch” -> “Upload” 將程式編譯並上傳到 Ameba。
Arduino的範例裡,使用A4當作I2C SCL, A5為I2C SDA。這些接腳與Ameba一樣。
另外很重要的是,兩塊板子的GND要互接。
接著我們要從Serial Monitor視窗來看Ameba印出讀到的數據 首先我們要找到Ameba的Serial Port, 點Windows的[開始] 按鈕 、[控制台]、[系統及安全性],然後在 [系統] 下方按一下 [裝置管理員],開啟 [裝置管理員]。 會看到Ports那邊有個mbed Serial Port(COM15), 這邊COM15就是就是Ameba的Port Number
接著我們將Arduino的Port選到COM15, 它在 “Tools” -> “Port” -> COM15 (Ameba目前的Mbed Serial Port)。
每當我們要從Arduino IDE看Ameba印出的訊息, 都要設定成正確的port:
打開包含Ameba的Arduino IDE,開啟Serial Monitor, “Tools” -> “Serial Monitor”, 會出現Serial Monitor的視窗,這個視窗可以讓你看到Ameba印出來的訊息。
接著按下Arduino Uno的Reset按鈕,讓Arduino Uno等待I2C master連接。
再按下Ameba的Reset按鈕,讓Ameba開始接收從Arduino Uno傳過來的訊息。這時候會看到Serial Monitor每隔0.5秒出現 "hello " 的訊息,這樣就代表成功了。
(NOTE: 如果發現 Ameba 的 Serial Monitor沒出現訊息,請試試看重開 Serial Monitor)
程式碼說明
Ameba使用同樣的Arduino範例,Ardunio官方網站的範例說明可以參考這裡:
https://www.arduino.cc/en/Tutorial/MasterReader
首先Wire.begin()會先設定address, 如果是Master可以不用設定address:
https://www.arduino.cc/en/Reference/WireBegin
接著Master使用Wire.requestFrom()來設定要從哪一個Slave接收資料:
https://www.arduino.cc/en/Reference/WireRequestFrom
https://www.arduino.cc/en/Tutorial/MasterReader
首先Wire.begin()會先設定address, 如果是Master可以不用設定address:
https://www.arduino.cc/en/Reference/WireBegin
接著Master使用Wire.requestFrom()來設定要從哪一個Slave接收資料:
https://www.arduino.cc/en/Reference/WireRequestFrom
... Under construction ...
Arduino內建許多Example, 底下的列表是Ameba支援的內建範例
| Category | Name | Comment |
| 01. Basics | AnalogReadSerial | |
| Blink | ||
| DititalReadSerial | ||
| Fade | ||
| ReadAnalogVoltage | ||
| 02. Digital | Button | |
| DigitalInputPullup | ||
| StateChangeDetection | ||
| 03. Analog | AnalogInOutSerial | |
| AnalogInput | ||
| Fading | ||
| Smoothing | ||
| 04. Communication | ASCIITable | |
| Graph | ||
| Midi | ||
| 05. Control | Arrays | |
| ForLoopIteration | ||
| IfStatementConditional | ||
| switchCase | ||
| 07. Display | barGraph | |
| RowColumnScanning | ||
| 08. Strings | StringCaseChanges | |
| StringCharacters | ||
| StringIndexOf | ||
| StringLengthTrim | ||
| StringReplace | ||
| StringStartsWithEndsWith | ||
| StringSubstring |
There are many built-in examples in Arduino. In the table below, we list all examples that are compatible with Ameba.
| Category | Name | Comment |
| 01. Basics | AnalogReadSerial | |
| Blink | ||
| DititalReadSerial | ||
| Fade | ||
| ReadAnalogVoltage | ||
| 02. Digital | Button | |
| DigitalInputPullup | ||
| StateChangeDetection | ||
| 03. Analog | AnalogInOutSerial | |
| AnalogInput | ||
| Fading | ||
| Smoothing | ||
| 04. Communication | ASCIITable | |
| Graph | ||
| Midi | ||
| 05. Control | Arrays | |
| ForLoopIteration | ||
| IfStatementConditional | ||
| switchCase | ||
| 07. Display | barGraph | |
| RowColumnScanning | ||
| 08. Strings | StringCaseChanges | |
| StringCharacters | ||
| StringIndexOf | ||
| StringLengthTrim | ||
| StringReplace | ||
| StringStartsWithEndsWith | ||
| StringSubstring |
材料準備
Ameba x 1
Laptop(可與Ameba連到相同網域,並安裝tcp工具)
範例說明
這個範例裡,我們使用 Ameba 連上 WiFi,作為 Server,與連接過來的 Client 進行對話。
首先確定板子是 Ameba, “Tools” -> “Board” -> “Arduino Ameba”
然後打開 Simple WiFi Server的範例, “File” -> “Examples” -> “AmebaWiFi” -> “SimpleServerWiFi”
將 WiFi 連線的相關訊息進行修改,將下圖中黃色標註的地方進行對應的修改。
上傳程式碼之後,按下 Ameba 的 Reset 按鈕, 這時會看到 WiFi 連線後的信息。
在 laptop 上的 socket 工具上(本示例中使用的工具為 “sokit” )通過獲取的IP地址以及範例中設定的 port 5000 來進行連線。
選取 Client 模式,填寫 Server IP 和 port 信息,點擊 “TCP Connect”
連接成功后會顯示 ”A client connected to this Server”,以及Client的IP和port訊息。
從 Client 發送一個字串過來,Ameba收到後,會將這個字串再發給 Client。

客戶端會顯示收到這個字串
首先確定板子是 Ameba, “Tools” -> “Board” -> “Arduino Ameba”
然後打開 Simple WiFi Server的範例, “File” -> “Examples” -> “AmebaWiFi” -> “SimpleServerWiFi”
將 WiFi 連線的相關訊息進行修改,將下圖中黃色標註的地方進行對應的修改。
上傳程式碼之後,按下 Ameba 的 Reset 按鈕, 這時會看到 WiFi 連線後的信息。
在 laptop 上的 socket 工具上(本示例中使用的工具為 “sokit” )通過獲取的IP地址以及範例中設定的 port 5000 來進行連線。
選取 Client 模式,填寫 Server IP 和 port 信息,點擊 “TCP Connect”
連接成功后會顯示 ”A client connected to this Server”,以及Client的IP和port訊息。
從 Client 發送一個字串過來,Ameba收到後,會將這個字串再發給 Client。

客戶端會顯示收到這個字串
程式碼說明
在連線WiFi時會使用到WiFi.begin();
https://www.arduino.cc/en/Reference/WiFiBegin
連線成功后會讀取WiFi的信息:
顯示WiFi的名稱WiFi.SSID()
https://www.arduino.cc/en/Reference/WiFiSSID
顯示WiFi的訊號強度WiFi.RSSI()
https://www.arduino.cc/en/Reference/WiFiRSSI
顯示Ameba的IP信息WiFi.localIP()
https://www.arduino.cc/en/Reference/WiFiLocalIP
設定服務器的端口號WiFiServer server(5000)
https://www.arduino.cc/en/Reference/WiFiServer
開始服務器的監聽server.begin();
https://www.arduino.cc/en/Reference/WiFiServerBegin
判斷是否有客戶端連線server.available()
https://www.arduino.cc/en/Reference/WiFiServerAvailable
從Server讀取數據client.read()
https://www.arduino.cc/en/Reference/WiFiClientRead
對Server發送數據client.write()
https://www.arduino.cc/en/Reference/WiFiClientWrite
與Server斷開連線client.stop();
https://www.arduino.cc/en/Reference/WiFIClientStop
https://www.arduino.cc/en/Reference/WiFiBegin
連線成功后會讀取WiFi的信息:
顯示WiFi的名稱WiFi.SSID()
https://www.arduino.cc/en/Reference/WiFiSSID
顯示WiFi的訊號強度WiFi.RSSI()
https://www.arduino.cc/en/Reference/WiFiRSSI
顯示Ameba的IP信息WiFi.localIP()
https://www.arduino.cc/en/Reference/WiFiLocalIP
設定服務器的端口號WiFiServer server(5000)
https://www.arduino.cc/en/Reference/WiFiServer
開始服務器的監聽server.begin();
https://www.arduino.cc/en/Reference/WiFiServerBegin
判斷是否有客戶端連線server.available()
https://www.arduino.cc/en/Reference/WiFiServerAvailable
從Server讀取數據client.read()
https://www.arduino.cc/en/Reference/WiFiClientRead
對Server發送數據client.write()
https://www.arduino.cc/en/Reference/WiFiClientWrite
與Server斷開連線client.stop();
https://www.arduino.cc/en/Reference/WiFIClientStop
Materials
Ameba x 1
Laptop(Make sure it is connected to the same network domain as Ameba, and tcp tools are installed.)
Procedure
In this example, we first connect Ameba to WiFi, then we use Ameba as server to communicate with client.
First, we make sure the board is set to Ameba in “Tools” -> “Board” -> “Arduino Ameba”
Then, open up the Simple WiFi Server example in “File” -> “Examples” -> “AmebaWiFi” -> “SimpleServerWiFi”
In the sample code, we modify the parameters concerning the WiFi connection, please set the parameters according to your WiFi connection.
Next, upload the code, then press the reset button on Ameba. At this moment, you will see the connection information is displayed in the console.
Next, we use the socket tool in the laptop to be the client, and connect to the Ameba server via the IP and port we set in the code. (Note: The socket tool we used in this example is "sokit".)
Click on the "Client" tab to choose the client mode, specify the IP and port of the server, then click "TCP Connect".
If the connection is established successfully, the server shows a message: "A client connected to this Server", and the IP and port of the connected client.
In this example, when the client and server are connected and the client sends a string to Ameba server, the Ameba server returns the identical string back to the client.

The string sent to server is returned and showed at the client side.
First, we make sure the board is set to Ameba in “Tools” -> “Board” -> “Arduino Ameba”
Then, open up the Simple WiFi Server example in “File” -> “Examples” -> “AmebaWiFi” -> “SimpleServerWiFi”
In the sample code, we modify the parameters concerning the WiFi connection, please set the parameters according to your WiFi connection.
Next, upload the code, then press the reset button on Ameba. At this moment, you will see the connection information is displayed in the console.
Next, we use the socket tool in the laptop to be the client, and connect to the Ameba server via the IP and port we set in the code. (Note: The socket tool we used in this example is "sokit".)
Click on the "Client" tab to choose the client mode, specify the IP and port of the server, then click "TCP Connect".
If the connection is established successfully, the server shows a message: "A client connected to this Server", and the IP and port of the connected client.
In this example, when the client and server are connected and the client sends a string to Ameba server, the Ameba server returns the identical string back to the client.

The string sent to server is returned and showed at the client side.
Code reference
Use WiFi.begin() to establish WiFi connection;
https://www.arduino.cc/en/Reference/WiFiBegin
To get the information of a WiFi connection:
Use WiFi.SSID() to get SSID of the current connected network.
https://www.arduino.cc/en/Reference/WiFiSSID
Use WiFi.RSSI() to get the signal strength of the connection.
https://www.arduino.cc/en/Reference/WiFiRSSI
Use WiFi.localIP() to get the Ameba WiFi shield's IP address.
https://www.arduino.cc/en/Reference/WiFiLocalIP
Create server and transmitting data:
Use Server(port) to create a server that listens on the specified port.
https://www.arduino.cc/en/Reference/WiFiServer
Use server.begin() to tell the server to begin listening for incoming connections.
https://www.arduino.cc/en/Reference/WiFiServerBegin
Use server.available() to get a client that is connected to the server and has data available for reading.
https://www.arduino.cc/en/Reference/WiFiServerAvailable
Use client.read() to read the next byte received from the server.
https://www.arduino.cc/en/Reference/WiFiClientRead
Use client.write() to write data to the server.
https://www.arduino.cc/en/Reference/WiFiClientWrite
Use client.stop() to disconnect from the server.
https://www.arduino.cc/en/Reference/WiFIClientStop
https://www.arduino.cc/en/Reference/WiFiBegin
To get the information of a WiFi connection:
Use WiFi.SSID() to get SSID of the current connected network.
https://www.arduino.cc/en/Reference/WiFiSSID
Use WiFi.RSSI() to get the signal strength of the connection.
https://www.arduino.cc/en/Reference/WiFiRSSI
Use WiFi.localIP() to get the Ameba WiFi shield's IP address.
https://www.arduino.cc/en/Reference/WiFiLocalIP
Create server and transmitting data:
Use Server(port) to create a server that listens on the specified port.
https://www.arduino.cc/en/Reference/WiFiServer
Use server.begin() to tell the server to begin listening for incoming connections.
https://www.arduino.cc/en/Reference/WiFiServerBegin
Use server.available() to get a client that is connected to the server and has data available for reading.
https://www.arduino.cc/en/Reference/WiFiServerAvailable
Use client.read() to read the next byte received from the server.
https://www.arduino.cc/en/Reference/WiFiClientRead
Use client.write() to write data to the server.
https://www.arduino.cc/en/Reference/WiFiClientWrite
Use client.stop() to disconnect from the server.
https://www.arduino.cc/en/Reference/WiFIClientStop
材料準備
Ameba x 1
範例說明
WPA加密模式的WiFi連線
打開 Connect With WPA 的範例, “File” -> “Examples” -> “AmebaWiFi” -> “ConnectWithWPA”
在SSID後修改“yourNetwork”為要連線的WiFi名稱, “secretPassword”改為對應的密碼。
修改之後上傳程式碼,按下Ameba的Reset按鈕, 這時候會看到You’re connected to the networkSSID: XXXXX,以及後面會每十秒列印出WiFi信息。
WEP加密模式的WiFi連線
打開 Connect With WEP 的範例, “File” -> “Examples” -> “AmebaWiFi” -> “ConnectWithWEP”

在SSID後修改“yourNetwork”為要連線的WiFi名稱, key改為對應的十六進制的密碼,keyIndex 修改為對應的數字。
修改之後上傳程式碼,按下Ameba的Reset按鈕, 這時候會看到You’re connected to the networkSSID: XXXXX,以及後面會每十秒列印出WiFi信息。
常見的WiFi有三種加密方式,一種為OPEN,即沒有密碼,第二種為WPA,即我們通常使用的密碼,第三種為WEP,會需要十六進制的密碼以及一個初向量(keyindex)。
下面我們將分別介紹這三種加密方式的WiFi連線方法。
首先確定板子是 Ameba, “Tools” -> “Board” -> “Arduino Ameba”

Open (即無密碼的WiFi連線)
打開 Connect No Encryption 的範例, “File” -> “Examples” -> “AmebaWiFi” -> “ConnectNoEncryption”

在SSID後修改“yourNetwork”為要連線的WiFi名稱。

修改之後上傳程式碼,按下Ameba的Reset按鈕, 這時候會看到You’re connected to the networkSSID: XXXXX,以及後面會每十秒列印出WiFi信息。
下面我們將分別介紹這三種加密方式的WiFi連線方法。
首先確定板子是 Ameba, “Tools” -> “Board” -> “Arduino Ameba”


在SSID後修改“yourNetwork”為要連線的WiFi名稱。

修改之後上傳程式碼,按下Ameba的Reset按鈕, 這時候會看到You’re connected to the networkSSID: XXXXX,以及後面會每十秒列印出WiFi信息。
在SSID後修改“yourNetwork”為要連線的WiFi名稱, “secretPassword”改為對應的密碼。
修改之後上傳程式碼,按下Ameba的Reset按鈕, 這時候會看到You’re connected to the networkSSID: XXXXX,以及後面會每十秒列印出WiFi信息。

在SSID後修改“yourNetwork”為要連線的WiFi名稱, key改為對應的十六進制的密碼,keyIndex 修改為對應的數字。
修改之後上傳程式碼,按下Ameba的Reset按鈕, 這時候會看到You’re connected to the networkSSID: XXXXX,以及後面會每十秒列印出WiFi信息。
程式碼說明
在連線WiFi時會使用到WiFi.begin();
https://www.arduino.cc/en/Reference/WiFiBegin
連線成功后會讀取WiFi的信息:
顯示WiFi的名稱WiFi.SSID()
https://www.arduino.cc/en/Reference/WiFiSSID
顯示WiFi的訊號強度WiFi.RSSI()
https://www.arduino.cc/en/Reference/WiFiRSSI
顯示WiFi的加密方式WiFi.encryptionType()
https://www.arduino.cc/en/Reference/WiFiEncryptionType
顯示連線的路由器的物理地址即BSSID WiFi.BSSID()
https://www.arduino.cc/en/Reference/WiFiBSSID
也會讀取Ameba自己的信息:
顯示Ameba的MAC信息WiFi.macAddress()
https://www.arduino.cc/en/Reference/WiFiMACAddress
顯示Ameba的IP信息WiFi.localIP()
https://www.arduino.cc/en/Reference/WiFiLocalIP
顯示子網掩碼WiFi.subnetMask()
https://www.arduino.cc/en/Reference/WiFiSubnetMask
顯示網關信息WiFi.gatewayIP()
https://www.arduino.cc/en/Reference/WiFiGatewayIP
https://www.arduino.cc/en/Reference/WiFiBegin
連線成功后會讀取WiFi的信息:
顯示WiFi的名稱WiFi.SSID()
https://www.arduino.cc/en/Reference/WiFiSSID
顯示WiFi的訊號強度WiFi.RSSI()
https://www.arduino.cc/en/Reference/WiFiRSSI
顯示WiFi的加密方式WiFi.encryptionType()
https://www.arduino.cc/en/Reference/WiFiEncryptionType
顯示連線的路由器的物理地址即BSSID WiFi.BSSID()
https://www.arduino.cc/en/Reference/WiFiBSSID
也會讀取Ameba自己的信息:
顯示Ameba的MAC信息WiFi.macAddress()
https://www.arduino.cc/en/Reference/WiFiMACAddress
顯示Ameba的IP信息WiFi.localIP()
https://www.arduino.cc/en/Reference/WiFiLocalIP
顯示子網掩碼WiFi.subnetMask()
https://www.arduino.cc/en/Reference/WiFiSubnetMask
顯示網關信息WiFi.gatewayIP()
https://www.arduino.cc/en/Reference/WiFiGatewayIP
與Arduino的差異
Arduino在完成WiFi的操作時,需要另外使用WiFi Shield來作為WiFi模塊,因此在使用WiFi是需要#include 來使用SPI與WiFi模塊進行通訊。
但是Ameba自身就具有WiFi模塊的功能,因此,不需要#include。若想要使用Arduino的範例,要先刪掉這一項。
但是Ameba自身就具有WiFi模塊的功能,因此,不需要#include
Materials
Ameba x 1
Procedure
WiFi connection with WPA encryption
Open the "ConnectWithWPA" exmaple, "File" -> "Examples" -> "AmebaWiFi" -> "ConnectWithWPA"
In the sample code, modify "SSID" to the SSID to be connected, "secretPassword" to be the passwrd.
Next, upload the sample code, and press the reset button on Ameba. Then you will see a message says "You’re connected to the networkSSID: XXXXX", and the information of this WiFi connection is printed in the IDE every 10 seconds.
WiFi connection with WEP encryption
Open the "ConnectWithWEP" example, "File" -> "Examples" -> "AmebaWiFi" -> "ConnectWithWEP"

In the sample code, modify "SSID" to the SSID to be connected, "key" to the hexadecimal password, "keyIndex" to your key index number.
Next, upload the sample code, and press the reset button on Ameba. Then you will see a message says "You’re connected to the networkSSID: XXXXX", and the information of this WiFi connection is printed in the IDE every 10 seconds.
There three common encryption type in WiFi connection. The first one is "OPEN", which means there is no password needed to connect to this network. The second type of encryption is WPA, which requires the correct password to access. The third type is WEP, which requires a hexadecimal password and a keyindex.
In the following, we will give a brief introduction on how to establish WiFi connection with these three types of encryption on Ameba.
First, make sure the current board is Ameba, select "Tools" -> "Board" -> "Arduino Ameba".

Open (WiFi connection without password)
Open the "ConnectNoEncryption" example, “File” -> “Examples” -> “AmebaWiFi” -> “ConnectNoEncryption”

In the sample code, modify "SSID" to the SSID to be connected.

Next, upload the sample code, and press the reset button on Ameba. Then you will see a message says "You’re connected to the networkSSID: XXXXX", and the information of this WiFi connection is printed in the IDE every 10 seconds.
In the following, we will give a brief introduction on how to establish WiFi connection with these three types of encryption on Ameba.
First, make sure the current board is Ameba, select "Tools" -> "Board" -> "Arduino Ameba".


In the sample code, modify "SSID" to the SSID to be connected.

Next, upload the sample code, and press the reset button on Ameba. Then you will see a message says "You’re connected to the networkSSID: XXXXX", and the information of this WiFi connection is printed in the IDE every 10 seconds.
In the sample code, modify "SSID" to the SSID to be connected, "secretPassword" to be the passwrd.
Next, upload the sample code, and press the reset button on Ameba. Then you will see a message says "You’re connected to the networkSSID: XXXXX", and the information of this WiFi connection is printed in the IDE every 10 seconds.

In the sample code, modify "SSID" to the SSID to be connected, "key" to the hexadecimal password, "keyIndex" to your key index number.
Next, upload the sample code, and press the reset button on Ameba. Then you will see a message says "You’re connected to the networkSSID: XXXXX", and the information of this WiFi connection is printed in the IDE every 10 seconds.
Code Reference
Use WiFi.begin() to establish WiFi connection;
https://www.arduino.cc/en/Reference/WiFiBegin
To get the information of a WiFi connection:
Use WiFi.SSID() to get SSID of the current connected network.
https://www.arduino.cc/en/Reference/WiFiSSID
Use WiFi.RSSI() to get the signal strength of the connection.
https://www.arduino.cc/en/Reference/WiFiRSSI
Use WiFi.encryptionType() to get the encryption type of the WiFi connection.
https://www.arduino.cc/en/Reference/WiFiEncryptionType
Use WiFi.BSSID() to get the MAC address of the router you are connected to.
https://www.arduino.cc/en/Reference/WiFiBSSID
To get the information of Ameba:
Use WiFi.macAddress() to get the MAC address of Ameba.
https://www.arduino.cc/en/Reference/WiFiMACAddress
Use WiFi.localIP() to get the IP address of Ameba.
https://www.arduino.cc/en/Reference/WiFiLocalIP
Use WiFi.subnetMask() to get the subnet mask.
https://www.arduino.cc/en/Reference/WiFiSubnetMask
Use WiFi.gatewayIP() to get the WiFi shield's gateway IP address.
https://www.arduino.cc/en/Reference/WiFiGatewayIP
https://www.arduino.cc/en/Reference/WiFiBegin
To get the information of a WiFi connection:
Use WiFi.SSID() to get SSID of the current connected network.
https://www.arduino.cc/en/Reference/WiFiSSID
Use WiFi.RSSI() to get the signal strength of the connection.
https://www.arduino.cc/en/Reference/WiFiRSSI
Use WiFi.encryptionType() to get the encryption type of the WiFi connection.
https://www.arduino.cc/en/Reference/WiFiEncryptionType
Use WiFi.BSSID() to get the MAC address of the router you are connected to.
https://www.arduino.cc/en/Reference/WiFiBSSID
To get the information of Ameba:
Use WiFi.macAddress() to get the MAC address of Ameba.
https://www.arduino.cc/en/Reference/WiFiMACAddress
Use WiFi.localIP() to get the IP address of Ameba.
https://www.arduino.cc/en/Reference/WiFiLocalIP
Use WiFi.subnetMask() to get the subnet mask.
https://www.arduino.cc/en/Reference/WiFiSubnetMask
Use WiFi.gatewayIP() to get the WiFi shield's gateway IP address.
https://www.arduino.cc/en/Reference/WiFiGatewayIP
Comparison with Arduino
In the Arduino platform, we need to add an extra WiFi shield to be the WiFi module to realize the WiFi connection. And we have to #include to use SPI to communicate with WiFi module.
However, Ameba is already equipped with WiFi module. Therefore, #include is not needed.
However, Ameba is already equipped with WiFi module. Therefore, #include is not needed.
材料準備
Ameba x 1
天線 x 1
範例說明
程式碼說明
首先使用的是顯示Ameba自己的物理地址WiFi.macAddress(mac):
https://www.arduino.cc/en/Reference/WiFiMACAddress
然後開始搜索周圍WiFi環境的WiFi.scanNetworks()
https://www.arduino.cc/en/Reference/WiFiScanNetworks
在打印WiFi具體訊息時使用到的有
顯示WiFi的名稱WiFi.SSID(thisNet):
https://www.arduino.cc/en/Reference/WiFiSSID
顯示WiFi的訊號強度WiFi.RSSI(thisNet):
https://www.arduino.cc/en/Reference/WiFiRSSI
顯示WiFi的加密方式WiFi.encryptionType(thisNet):
https://www.arduino.cc/en/Reference/WiFiEncryptionType
https://www.arduino.cc/en/Reference/WiFiMACAddress
然後開始搜索周圍WiFi環境的WiFi.scanNetworks()
https://www.arduino.cc/en/Reference/WiFiScanNetworks
在打印WiFi具體訊息時使用到的有
顯示WiFi的名稱WiFi.SSID(thisNet):
https://www.arduino.cc/en/Reference/WiFiSSID
顯示WiFi的訊號強度WiFi.RSSI(thisNet):
https://www.arduino.cc/en/Reference/WiFiRSSI
顯示WiFi的加密方式WiFi.encryptionType(thisNet):
https://www.arduino.cc/en/Reference/WiFiEncryptionType
與Arduino的差異
Arduino在完成WiFi的操作時,需要另外使用WiFi Shield來作為WiFi模塊,因此在使用WiFi是需要#include 來使用SPI與WiFi模塊進行通訊。
但是Ameba自身就具有WiFi模塊的功能,因此,不需要#include。若想要使用Arduino的範例,要先刪掉這一項。
但是Ameba自身就具有WiFi模塊的功能,因此,不需要#include
Materials
Ameba x 1
Procedure
In this example, we use Ameba to scan available WiFi hotspots in the surroundings, and prints the SSID, encryption type, signal strngth information of each detected hotspot.
First, make sure Ameba is selected in Arduino IDE: "Tools" -> "Board" -> "Arduino Ameba"
Open the "ScanNetworks" example in "File" -> "Examples" -> "AmebaWiFi" -> "ScanNetworks":
Then upload the sample code, and press the reset button on Ameba. Afterwards, you can see "**Scan Networks**" message appears, with the detected WiFi hotspots and the information of each hotspot.
First, make sure Ameba is selected in Arduino IDE: "Tools" -> "Board" -> "Arduino Ameba"
Open the "ScanNetworks" example in "File" -> "Examples" -> "AmebaWiFi" -> "ScanNetworks":
Then upload the sample code, and press the reset button on Ameba. Afterwards, you can see "**Scan Networks**" message appears, with the detected WiFi hotspots and the information of each hotspot.
Code Reference
First we use WiFi.macAddress(mac) to getthe MAC address of Ameba:
https://www.arduino.cc/en/Reference/WiFiMACAddress
Then we use WiFi.scanNetworks() to detect WiFi hotspots:
https://www.arduino.cc/en/Reference/WiFiScanNetworks
To get information of detected WiFi hotspot:
We use WiFi.SSID(thisNet) to retrieve SSID of a network:
https://www.arduino.cc/en/Reference/WiFiSSID
We use WiFi.RSSI(thisNet) to get the signal strength of the connection to the router:
https://www.arduino.cc/en/Reference/WiFiRSSI
We use WiFi.encryptionType(thisNet) to get the encryption type of the network:
https://www.arduino.cc/en/Reference/WiFiEncryptionType
https://www.arduino.cc/en/Reference/WiFiMACAddress
Then we use WiFi.scanNetworks() to detect WiFi hotspots:
https://www.arduino.cc/en/Reference/WiFiScanNetworks
To get information of detected WiFi hotspot:
We use WiFi.SSID(thisNet) to retrieve SSID of a network:
https://www.arduino.cc/en/Reference/WiFiSSID
We use WiFi.RSSI(thisNet) to get the signal strength of the connection to the router:
https://www.arduino.cc/en/Reference/WiFiRSSI
We use WiFi.encryptionType(thisNet) to get the encryption type of the network:
https://www.arduino.cc/en/Reference/WiFiEncryptionType
Comparison with Arduino
In the Arduino platform, we need to add an extra WiFi shield to be the WiFi module to realize the WiFi connection. And we have to #include to use SPI to communicate with WiFi module.
However, Ameba is already equipped with WiFi module. Therefore, #include is not needed.
However, Ameba is already equipped with WiFi module. Therefore, #include is not needed.
UART介紹
UART使用了兩條線讓雙方可以同時傳送資料。其中一條是Transmitting, 另一條則是Receiving,雙方使用約定好的頻率(baud rate)來傳資料。
Arduino 稱呼 UART 為Serial, 在Arduino Uno上只有一組硬體UART,並且這組UART主要被當作印出訊息使用(即Log UART),所以當Arduino要使用硬體的UART時,就會占用Log UART的資源。為了提供多組UART, Arduino Uno利用軟體將Serial Pin模擬成UART的行為,稱之為Software Serial。
Ameba除了Log UART之外,還提供多組硬體的UART。為了相容於Arudino的Software Serial API,Ameba在取名上沿用Software Serial,但底層是硬體而不是軟體模擬。
Arduino 稱呼 UART 為Serial, 在Arduino Uno上只有一組硬體UART,並且這組UART主要被當作印出訊息使用(即Log UART),所以當Arduino要使用硬體的UART時,就會占用Log UART的資源。為了提供多組UART, Arduino Uno利用軟體將Serial Pin模擬成UART的行為,稱之為Software Serial。
Ameba除了Log UART之外,還提供多組硬體的UART。為了相容於Arudino的Software Serial API,Ameba在取名上沿用Software Serial,但底層是硬體而不是軟體模擬。
材料準備
Ameba x 1
USB to TTL Adapter x 1
範例說明
這個範例裡,我們使用USB to TTL Adapter伴演UART的其中一端,另一端則是Ameba。
USB to TTL Adapter送出資料給Ameba,Ameba回傳相同的資料,最後顯示在螢幕上。
安裝USB to TTL Adapter
USB to TTL Adapter是個將USB轉成Seral介面的晶片。它一般會有4根腳,分別是3V3(或5V), GND, TX, RX。在使用USB to TTL Adapter時,通常都需要安裝驅動程式。如果你的晶片是FTDI的,Windows會上網找驅動程式並自動安裝,或者也可以自己找驅動程式。
安裝完驅動程式之後, 會在裝置管理員找到對應的Serial Port, 像圖中我的FTDI USB to TTL Adapter在COM8, 而Silicon USB to TTL Adapter則在COM6:
USB to TTL Adapter送出資料給Ameba,Ameba回傳相同的資料,最後顯示在螢幕上。
安裝完驅動程式之後, 會在裝置管理員找到對應的Serial Port, 像圖中我的FTDI USB to TTL Adapter在COM8, 而Silicon USB to TTL Adapter則在COM6:
首先先打開SoftwareSerialExamle範例, 它在 “File” -> “Examples” -> “AmebaSoftwareSerial” -> “SoftwareSerialExample”:

並且我們這樣接線, USB to TTL Adapter的TX接到Ameba的D0(即RX), USB to TTL Adapter的RX接到 Ameba的D1(即TX):
接著我們打開Serial Port Terminal, 常見的Serial Port Terminal有Putty, Tera Term。
我們以Putty說明如何設定, 先將 Connection Type選擇 Serial, 並且將 Serial line填入 USB to TTL Adapter所在的Port, (Ex. COM8)。
Speed指的就是USB的baud rate,需要與Serial的另一端做搭配,這個在範例裡為4800,所以我們設定4800。
接著我們切換左邊的Category到 Serial的頁面,其中Data bits為8, Stop bits為1, Stop bits為1, Parity為None, Flow control為None。
設定完之後按下Open, 並且按下Ameba的Reset按鈕,Putty就會出現 “Hello, world?” 的訊息, 這時候你在鍵盤上敲字,會經由USB to TTL Adapter的TX送到Ameba的Serial RX, 在程式碼裡面再送到Ameba的Serial TX, 最後由USB to TTL Adapter的RX接收並印出來。所以如果我們敲這個訊息 “I am fine”, 就會出現這樣:
程式碼說明
首先需要設定UART的Baurd rate, 使用SoftwareSerial:Begin():
https://www.arduino.cc/en/Reference/SoftwareSerialBegin
使用write送出資料, 並且使用Software:available()來檢查是否有資料送進來:
https://www.arduino.cc/en/Reference/SoftwareSerialAvailable
如果有資料進來, 就使用read將資料讀進來。
https://www.arduino.cc/en/Reference/SoftwareSerialBegin
使用write送出資料, 並且使用Software:available()來檢查是否有資料送進來:
https://www.arduino.cc/en/Reference/SoftwareSerialAvailable
如果有資料進來, 就使用read將資料讀進來。
Introduction of UART
UART uses two wirelines, one for transmitting and the other one for receiving, so as to make the data transmission bidirectional. The commnication use a predefined frequency (baud rate) to transmit data.
In Arduino, UART is called "Serial". There is only one hardware UART on Arduino Uno, and is primarily used to read the log and messages printed by arduino (so it's also called "Log UART"). If we use the hardware UART for other purposes, the Log UART does not have resources to do its job. To provide more UART connections, Arduino UNO uses Serial Pin to simulate the behavior of UART by a software approach, this is called Software Serial.
However, Ameba is equipped with a number of hardware UART. But to be compatible with the Software Serial API of Arduino, Ameba follows the name "Software Serial"
In Arduino, UART is called "Serial". There is only one hardware UART on Arduino Uno, and is primarily used to read the log and messages printed by arduino (so it's also called "Log UART"). If we use the hardware UART for other purposes, the Log UART does not have resources to do its job. To provide more UART connections, Arduino UNO uses Serial Pin to simulate the behavior of UART by a software approach, this is called Software Serial.
However, Ameba is equipped with a number of hardware UART. But to be compatible with the Software Serial API of Arduino, Ameba follows the name "Software Serial"
Materials
Ameba x 1
USB to TTL Adapter x 1
Procedure
In this example, we use UART to connect USB to TTL Adapter to Ameba.
USB to TTL Adapter sends data to Ameba, the data would be returned by Ameba, and showed on the screen.
Install USB to TTL Adapter
USB to TTL Adapter converts USB to Serial interface. Normally, there are 4 pins on the adapter, that is 3V3 (or 5V), GND, TX and RX.
Gernerally, installing the driver for the USB to TTL Adapter would be required before using it. If the adapter uses the chip of FTDI, Windows would search and install the driver automatically, otherwise, you may need to install corresponding driver yorself.
Afterwards, open the Device Manager. You can find corresponding Serial Port of the USB to TTL Adapter:
USB to TTL Adapter sends data to Ameba, the data would be returned by Ameba, and showed on the screen.
Afterwards, open the Device Manager. You can find corresponding Serial Port of the USB to TTL Adapter:
Open the "SoftwareSerialExample" example in "File" -> "Examples" -> "AmebaSoftwareSerial" -> "SoftwareSerialExample":

Connect the wirelines as the diagram. The TX pin of USB to TTL Adapter is connected to D0 (which is its RX) of Ameba, and the RX pin of USB to TTL Adapter is connected to D1 (which is its TX) of Ameba.
Next, open the Serial Port Terminal, such as Putty, Tera Term. (We use Putty in this example.)
Open the Putty window, choose "Serial" in Connection Type, and specify the port of USB to TTL Adapter in Serial line field (Ex. COM8).
In Speed field, fill in the baud rate of this connection. (Note that both sides of the connection should use the same baud rate.) In this example we se baud rate 4800.
Next, click "Serial" on the left side. We set Data bits to 8, Stop bits to 1, Parity to None, and Flow control to None.
Then click Open, and press the reset button on Ameba. You can see the "Hello, world?" message appears in Putty. If insert characters in Putty, the input characters would be sent to Serial RX of Ameba by TX of USB to TTL Adapter, and returned by Serial TX of Ameba. Finally, RX of USB to TTL Adapter receives the returned characters and prints them in Putty. Therefore, if you insert "I am fine", you would get something like this:
Code Reference
First, use SoftwareSerial: begin(speed) to set the baud rate for the serial communication:
https://www.arduino.cc/en/Reference/SoftwareSerialBegin
Use write() to send data, and use SoftwareSerial: available() to get the number of bytes available for reading from a software serial port:
https://www.arduino.cc/en/Reference/SoftwareSerialAvailable
If there are data available to read, use read() to read from serial port.
https://www.arduino.cc/en/Reference/SoftwareSerialBegin
Use write() to send data, and use SoftwareSerial: available() to get the number of bytes available for reading from a software serial port:
https://www.arduino.cc/en/Reference/SoftwareSerialAvailable
If there are data available to read, use read() to read from serial port.












