Realtek Ameba RTL8195 Technical Workshop Realtek Ameba RTL8195 Technical Workshop Agus Kurniawan 1st Edition, 2018 Copyright © 2018 Agus Kurniawan Table of Contents Realtek Ameba RTL8195 Technical Workshop Preface Preparing Development Environment 1.1 Realtek Ameba RTL8195 1.2 Electronics Components 1.2.1 Arduino Starter Kit 1.2.2 Fritzing 1.2.3 Cooking-Hacks: Arduino Starter Kit 1.2.4 Arduino Sidekick Basic kit v2 1.2.5 Grove - Starter Kit for Arduino 1.2.6 DFRobot - Arduino Kit for Beginner v3 1.3 Development Tools 1.4 Unboxing 1.5 Testing Setting Up Realtek Ameba RTL8195 2.1 Getting Started 2.2 Installing Arduino Software 2.3 Configuring Arduino for Realtek Ameba RTL8195 2.4 Connecting Realtek Ameba RTL8195 board to Computer 2.5 Hello Realtek Ameba RTL8195: Blinking LED 2.6 Updating Program Writing and Reading Digital Data 3.1 Getting Started 3.2 Wiring 3.3 Writing a Program 3.4 Testing Serial Communication (UART) 4.1 Getting Started 4.2 Hello UART 4.2.1 Preparation 4.2.2 Connecting to Realtek Ameba RTL8195 LOG UART 4.2.3 Wiring 4.2.4 Writing a Program 4.2.5 Testing Working with Analog I/O 5.1 Getting Started 5.2 Demo Analog Output (PWM) : RGB LED 5.2.1 Wiring 5.2.2 Writing Program 5.2.3 Testing 5.3 Demo Analog Input: Working with Potentiometer 5.3.1 Wiring 5.3.2 Writing Program 5.3.3 Testing 5.4 Writing Analog Output 5.4.1 Wiring 5.4.2 Writing Program 5.4.3 Testing Working with I2C 6.1 Getting Started 6.2 Writing Program 6.3 Writing Program 6.4 Testing Working with SPI 7.1 Getting Started 7.2 Wiring 7.3 Writing a Program 7.4 Testing Working with EEPROM 8.1 Getting Started 8.2 EEPROM Demo Building Internet of Things Application 91 Getting Started 9.2 Scanning Existing WiFi Hotspot 9.3 Building IoT Application 9.3.1 Wiring 9.3.2 Writing Application 9.3.3 Testing Source Code Contact Preface This book was written to help anyone want to get started with Realtek Ameba RTL8195 board development It describes the basic elements of Realtek Ameba RTL8195 development using Arduino and Mbed software Agus Kurniawan Depok, July 2018 Preparing Development Environment 1.1 Realtek Ameba RTL8195 Realtek Ameba RTL8195 is development board from Realtek This board provides an IoT solution inside the familiar Arduino form factor The Ameba Board supports WiFi, GPIO, NFC, I2C, UART, SPI, PWM and ADC operations, and can support Ethernet via Arduino-compatible headers, providing you a great IoT platform for your next project The following is a list of forms of Realtek Ameba RTL8195 board The following is the board specification: 32-bit ARM Cortex M3 (166MHz) 1MB ROM, 2MB SDRAM and 512KB SRAM Integrated with 802.11 b/g/n 1x1 WiFi NFC Tag with Read/Write Function 10/100 Ethernet MII/ RMII/RGMII Interface USB OTG SDIO Device/SD Card Controller Hardware SSL Engine Maximum 30 GPIOs SPI Interfaces support both master and slave mode UART Interfaces, including HS-UART and one log UART I2C Interfaces support both master and slave mode I2S/PCM Interfaces support both master and slave mode PWM Interfaces ADC Interfaces DAC Interface Officially you can buy this board on https://www.amebaiot.com/en/ameba-arduino-faq/ You also can buy this product on your local electronic store 1.2 Electronics Components We need electronic components to build our testing, for instance, Resistor, LED, sensor devices and etc I recommend you can buy electronic component kit We can use electronics kit from Arduino to be developed on Realtek Ameba RTL8195 The following is a list of electronics kit which can be used in our case 1.2.1 Arduino Starter Kit Store website: http://arduino.cc/en/Main/ArduinoStarterKit 1.2.2 Fritzing Store website: http://shop.fritzing.org/ You can buy Fritzing Starter Kit with Arduino UNO or Fritzing Starter Kit with Arduino Mega Serial.print(mac[1], HEX); Serial.print(":"); Serial.print(mac[2], HEX); Serial.print(":"); Serial.print(mac[3], HEX); Serial.print(":"); Serial.print(mac[4], HEX); Serial.print(":"); Serial.println(mac[5], HEX); } void listNetworks() { // scan for nearby networks: Serial.println("** Scan Networks **"); int numSsid = WiFi.scanNetworks(); if (numSsid == -1) { Serial.println("Couldn't get a wifi connection"); while (true); } // print the list of networks seen: Serial.print("number of available networks:"); Serial.println(numSsid); // print the network number and name for each network found: for (int thisNet = 0; thisNet < numSsid; thisNet++) { Serial.print(thisNet); Serial.print(") "); Serial.print(WiFi.SSID(thisNet)); Serial.print("\tSignal: "); Serial.print(WiFi.RSSI(thisNet)); Serial.print(" dBm"); Serial.print("\tEncryptionRaw: "); printEncryptionTypeEx(WiFi.encryptionTypeEx(thisNet)); Serial.print("\tEncryption: "); printEncryptionType(WiFi.encryptionType(thisNet)); } } void printEncryptionTypeEx(uint32_t thisType) { /* Arduino wifi api use encryption type to mapping to security type * This function demonstrate how to get more richful information of security type */ switch (thisType) { case SECURITY_OPEN: Serial.print("Open"); break; case SECURITY_WEP_PSK: Serial.print("WEP"); break; case SECURITY_WPA_TKIP_PSK: Serial.print("WPA TKIP"); break; case SECURITY_WPA_AES_PSK: Serial.print("WPA AES"); break; case SECURITY_WPA2_AES_PSK: Serial.print("WPA2 AES"); break; case SECURITY_WPA2_TKIP_PSK: Serial.print("WPA2 TKIP"); break; case SECURITY_WPA2_MIXED_PSK: Serial.print("WPA2 Mixed"); break; case SECURITY_WPA_WPA2_MIXED: Serial.print("WPA/WPA2 AES"); break; } } void printEncryptionType(int thisType) { // read the encryption type and print out the name: switch (thisType) { case ENC_TYPE_WEP: Serial.println("WEP"); break; case ENC_TYPE_TKIP: Serial.println("WPA"); break; case ENC_TYPE_CCMP: Serial.println("WPA2"); break; case ENC_TYPE_NONE: Serial.println("None"); break; case ENC_TYPE_AUTO: Serial.println("Auto"); break; } } You also need to connect Realtek Ameba RTL8195 LOG UART using UART tool After compiled and run the program to Realtek Ameba RTL8195, you can open a serial tool Press Reset button if you don't see anything A sample of program output can be seen in Figure below 9.3 Building IoT Application In this section, we build IoT application on Realtek Ameba RTL8195 We need three LEDs We will turn on/off LEDs from a browser 9.3.1 Wiring We connect three LEDs to digital pin 8, and 10 You also need to connect Realtek Ameba RTL8195 LOG UART through UART tool The following is my wiring 9.3.2 Writing Application Now you can open Arduino software Write this program #include int led1 = 8; int led2 = 9; int led3 = 10; char ssid[] = "ssid"; char pass[] = "pass"; int status = WL_IDLE_STATUS; WiFiServer server(80); void setup() { Serial.begin(9600); delay(10); // prepare GPIO5 pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); digitalWrite(led1, 0); digitalWrite(led2, 0); digitalWrite(led3, 0); // Connect to WiFi network while (status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(10000); } Serial.println(""); Serial.println("WiFi connected"); // Start the server server.begin(); Serial.println("Server started"); // Print the IP address char ips[24]; IPAddress ip = WiFi.localIP(); sprintf(ips, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); Serial.println(ips); } void loop() { // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; } // Wait until the client sends some data Serial.println("new client"); while(!client.available()){ delay(1); } // Read the first line of the request String req = client.readStringUntil('\r'); Serial.println(req); client.flush(); // Match the request int val1 = 0; int val2 = 0; int val3 = 0; int ledreq = 0; if (req.indexOf("/gpio1/0") != -1) { val1 = 0; ledreq = 1; } else if (req.indexOf("/gpio1/1") != -1) val1 = 1; ledreq = 1; } else if (req.indexOf("/gpio2/0") != -1) val2 = 0; ledreq = 2; } else if (req.indexOf("/gpio2/1") != -1) val2 = 1; req = 2; } else if (req.indexOf("/gpio3/0") != -1) val3 = 0; ledreq = 3; } else if (req.indexOf("/gpio3/1") != -1) val3 = 1; ledreq = 3; } else { Serial.println("invalid request"); client.stop(); return; } // Set GPIO2 according to the request digitalWrite(led1, val1); digitalWrite(led2, val2); digitalWrite(led3, val3); client.flush(); { { { { { // Prepare the response String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n\r\n"; if(ledreq==1) { s += "LED1 is "; s += (val1)? "ON": "OFF"; }else if(ledreq==2) { s += "LED2 is "; s += (val2)? "ON": "OFF"; }else if(ledreq==3) { s += "LED3 is "; s += (val3)? "ON": "OFF"; } s += "\n"; // Send the response to the client client.print(s); delay(1); client.stop(); Serial.println("Client disonnected"); } Save this program as IoTDemo 9.3.3 Testing Compile and run the program Open serial application so you should see IP Address from Realtek Ameba RTL8195 You can see my board has IP Address: 192.168.0.35 Open a browser and navigate to http:///gpio1/1 This URL will turn on LED You should see LED is lighting You can turn off LED by calling URL http:///gpio1/0 Try to turn on LED On serial application, you can see program output Source Code You can download source code on http://www.makers.id/ak/ameba3451.zip Contact If you have question related to this book, please contact me at aguskur@hotmail.com My blog: http://blog.aguskurniawan.net .. .Realtek Ameba RTL8195 Technical Workshop Realtek Ameba RTL8195 Technical Workshop Agus Kurniawan 1st Edition, 2018 Copyright © 2018 Agus Kurniawan Table of Contents Realtek Ameba RTL8195 Technical. .. Up Realtek Ameba RTL8195 2.1 Getting Started 2.2 Installing Arduino Software 2.3 Configuring Arduino for Realtek Ameba RTL8195 2.4 Connecting Realtek Ameba RTL8195 board to Computer 2.5 Hello Realtek. .. RTL8195 1.4 Unboxing I bought Realtek Ameba RTL8195 from Seeedstudion The following is my unboxing for Realtek Ameba RTL8195 1.5 Testing For testing, I used Realtek Ameba RTL8195 on Windows 10, OS