2020年3月2日 星期一

@ Getting started with the WeMos D1 ESP8266 WiFi Board

The WeMos D1 is a ESP8266 WiFi based board that uses the Arduino layout with a operating voltage of 3.3V. As the documentation of this board online can be a little confusing, the purpose of this tutorial is to combine and simplify the steps needed to setup this board for development. With that, let’s proceed on with the specifications of the board.



Note: This is NOT an Arduino board, it only uses the Arduino Uno layout for the board design!


Specification: 
Here are the specification of the board:
MicrocontrollerESP-8266EX
Operating Voltage3.3V
Digital I/O Pins11
Analog Input Pins1
Clock Speed80MHz/160MHz
Flash4M bytes
Length68.6mm
Width53.4mm
Weight25g
In summary, the board is controlled by the ESP8266 chip (a 32-Bit processor) and has a larger flash memory compared to an Arduino Uno. It consists of 11 digital I/O pins and 1 analogue (input) pin. the board can be connected using a Micro-B type USB cable.

Pinouts

All the I/O pins:
  • Runs at 3.3V
  • Have interrupt/PWM/I2C/one-wire support except D0IDE

There are 2 IDE that can be used to program the ESP8266:
  • The Arduino IDE
  • The NodeMCU IDE
In this tutorial, we’ll be looking at how to setup the board with the Arduino IDE on Windows. (For installation on a Linux-based system, you can visit this website, though the installation instructions are very similar: https://www.wemos.cc/tutorial/get-started-arduino.html)

Software Requirements

Installation

Create a new folder esp8266com/esp8266 in your Arduino sketch directory. (The Arduino sketch location should be located in “My Documents > Arduino” by default).
Next, download the library/driver file (as zip) from Github: https://github.com/esp8266/Arduino
After the download has completed, copy the zip file over to the [Arduino sketch]/hardware/esp8266com/esp8266 directory & extract the contents. A Arduino-Master folder will be created.
Next, enter the directory and drag all the content into the main directory. Finally, remove both the Arduino-master.zip and the Arduino-master folder. Your directory now should look like this:
Open the terminal and enter the esp8266/tools folder. (e.g. [Arduino sketch]/hardware/esp8266com/esp8266/tools) After that, exceute the get.py script via the python command.
C:\Users\[username]\My Documents\Arduino\hardware\esp8266com\esp8266\tools> python get.py
This will download the Binary Tools required to program the board. Once the installation has completed, it should look like that:
With that, you are ready to test out your WeMos D1 board!


Examples

Blink

To test out whether the hardware library/driver is properly installed, we’ll be testing out the sample program Blink, an equivalent to the Hello World! example in the Hardware environment. To do so, start the Arduino IDE and open the sketch at the following location:
C:\Users\[username]\Documents\Arduino\hardware\esp8266com\esp8266\libraries\esp8266\examples\Blink
If you are lazy, just copy the code below:
/*
 ESP8266 Blink by Simon Peter
 Blink the blue LED on the ESP-01 module
 This example code is in the public domain
 
 The blue LED on the ESP-01 module is connected to GPIO1 
 (which is also the TXD pin; so we cannot use Serial.print() at the same time)
 
 Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
*/

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
                                    // but actually the LED is on; this is because 
                                    // it is active low on the ESP-01)
  delay(1000);                      // Wait for a second
  digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
}
After opening the sketch file, go to Tools > Board and select the “WeMos D1 R2 & Mini” option. Connect the WeMos Board & upload the code. The LED on the ESP8266 will start to blink. (If the LED on the ESP8266 is blinking when a USB is plugged, you can try modifying the “delay” values to see whether it updates accordingly.)

Checking out the Chip ID

To check the ID of the chip, copy the code below & upload into the WeMos D1 board.
/* 
 *  Get Chip ID
 */

void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.println("");
  Serial.println("");
  Serial.println("Check ID in:");
  Serial.println("https://www.wemos.cc/verify_products");
  Serial.printf("Chip ID = %08Xn", ESP.getChipId());
  Serial.println("");
  Serial.println("");
  delay(5000);
}
After the code has been uploaded, open up the Serial Monitor and set the baudrate to 115200. The ID should be printed in the monitor.

Running a Simple Web Server

For this section, the ESP8266 will be ran as a simple server in a local network, hosting a simple HTML file at port 80. Go to the following directory & open up HelloServer.ino.
C:\Users\[username]\Documents\Arduin\ohardware\esp8266com\esp8266\libraries\ESP8266WebServerexamples\HelloServer
Alternatively, you can copy the code below:
#include 
#include 
#include 
#include 

const char* ssid = "........";
const char* password = "........";

ESP8266WebServer server(80);

const int led = 13;

void handleRoot() {
  digitalWrite(led, 1);
  server.send(200, "text/plain", "Hello from esp8266!");
  digitalWrite(led, 0);
}

void handleNotFound(){
  digitalWrite(led, 1);
  String message = "File Not Foundnn";
  message += "URI: ";
  message += server.uri();
  message += "nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "nArguments: ";
  message += server.args();
  message += "n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "n";
  }
  server.send(404, "text/plain", message);
  digitalWrite(led, 0);
}

void setup(void){
  pinMode(led, OUTPUT);
  digitalWrite(led, 0);
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (MDNS.begin("esp8266")) {
    Serial.println("MDNS responder started");
  }

  server.on("/", handleRoot);

  server.on("/inline", [](){
    server.send(200, "text/plain", "this works as well");
  });

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
}

void loop(void){
  server.handleClient();
}
Before uploading the code, you have to change 2 variable value: ssid and password. Replace them with your router’s ssid (or connection name) and the password accordingly. For example, if the router name is “router-17” and password “1234”, the variables would look something like this:
const char* ssid = "VegaN450";
const char* password = "8xxxxxxx";
After changing the variable values, upload the code and open up the Serial Monitor. (Set the baud rate to 115200) If the board is connected to the network, it will display it’s IP address. Assuming that your computer is connected to the same network, copy the IP address of the server and paste it over at your preferred web browser. The webpage would display a simple “Hello from esp8266!” webpage.






2018年5月13日 星期日

@ 2.4inch TFT Touch Screen Shield Module for Arduino UNO R3 LCD Display Modules (Midas Test on 2018)




Followed the instructions of Hugatry's HackVlog on https://www.youtube.com/watch?v=Js4wykWY6zg

1.Current version of the library has support for ILI9342.

   This TFT shield has a display which includes ILI9342 controller. We had go      
   through the steps needed to make this shield work with Arduino Uno or other 
   compatible boards.

2.Libraries that are needed for the display
   (can be installed using Library Manager on Arduino IDE): 

   https://github.com/prenticedavid/MCUFRIEND_kbv

   https://github.com/adafruit/Adafruit-GFX-Library

   We can install the libraries inside the Arduino IDE as:

   _By Sketch run “include Library / Manage Libraries…”
   _Search “MCUFREIND_kbv” and install it.
   _Search “adafruit gfx: library and install it.

3.Project open

_Open the “graphictest_kbv.ino” project

[C:\Users\Midaslu\Documents\Arduino\libraries\MCUFRIEND_kbv\examples\graphictest_kbv]

Due to firmware of Midas purchased hardware it should be added/changed ID to MCUFRIEND_kbv.cpp file.

(If the serial port monitor reported “Serial took 0ms to start / ID = 0x4747,the value should be different

On other LCD modules, Midas got ID = 0x4747).

_Well I change the code inside MCUFRIEND_kbv.cpp file :

The line "//#define SUPPORT_8347D" near the top... and uncomment that by removing "//", save the file and then compile + upload the sketch again. Compiling the firmware and upload code, then it works

Test Snaps :

Library needed for the touch, needs to be downloaded and moved to the folder that includes your Arduino libraries.... 
Rename the folder that is in ZIP file to "TouchScreen": 

https://github.com/adafruit/Touch-Scr... 

The display was sent to me ICStation.com and I didn't need to pay for it.

"2.4inch TFT Touch Screen Shield for Arduino UNO R3": http://www.icstation.com/24inch-touch...

ILI9342 TFT display driver library

The ILI9342 and ILI9342C display controllers are supported by the RAMTEX S6D0129 display driver library package.

Full GUI display driver C source code. Processor and C compiler independent.


ILI9342 display controller characteristics

Below is a brief introduction to the main characteristics for the ILI9342 RGB display controller (seen from a software driver design viewpoint).
For information about the ILI9342 driver software support please go to the library description.

ILI9342 device type

  • COG RGB color display controller for use in small embedded systems with on-chip frame buffer and TFT screen driver.
  • The ILI9342 supports TFT screens with a size up to 320 x 240 pixels (WxH)
  • On-chip TFT driver with voltage generator

Frame buffer

  • RGB pixel resolution (bits per pixel): 16-bit, 18-bit.
  • ILI9342 frame buffer organization: 320 RGB pixels on scan line, 240 lines.

Processor interfaces on ILI9342

  • ILI9342 parallel bus interface
    • Parallel bus types: 8080 bus type
    • Parallel bus size: 8-bit, 16-bit, 18 (32)-bit.
    • Addressing concept: Indexed bus interface (1 chip select pin + 1 address bit pin (Data/Command))
  • Serial bus interfaces on ILI9342
    • SPI bus: 4-wire: /CS,DC, SDIN, SCLK.
    • SPI bus: 3-wire: /CS, SDIN, SCLK. SPI-3 uses a 9 bit byte frame where first bit is DC
  • The bus interfaces are all supported by the ILI9342 display driver software package.

Special ILI9342 hardware features:

  • Special bus support: DSI transmitter receiver interface, MDDI Interface (Mobile Display Digital Interface).
  • 0-180, 90-270 degree frame buffer rotation with hardware support. Portrait mode, landscape mode.
  • Full driver software support.

Display controller vendor

  • ILI TECHNOLOGY CORP. http://www.ilitek.com

2017年1月4日 星期三

@ 我是腸子

( 透漏一時爽-整天火葬場 )

愛默生說 : 人的意義決定他每天在想什麼.

昔日白晝天,絞盡腦汁想如何解決工作上棘手的問題,
即之追夜晚,在想能讓我舒躺的柔床在何時可以觸躺,

今朝太陽日,盡全力伸展筋骨以對抗日漸萎縮的四肢肌肉,
夜幕如魅臨,降低因抽筋驚痛醒的次數就是我美夢的提升,

告訴自己不要思慮太多

開著燈,昏睡著,開始我的模擬白癡夢.....
果其然,愛默生前輩啊,
我成了一條腸子,每天在重複的進出蠕動著!

有時候又像瞎眼蛙在馬路上顢頇走竄,
探照燈偶而在我癡喜的臉上留下一點欣喜的痕跡 !






2017年1月1日 星期日

@ 2017 新年

誰給我無限的力量,,因此透視到自己的想望 !
於是建構了一個寂靜的世界, 它無聲無言,
二條平行線已經看見的最遠的風景,

但我仍用最寂靜的力量,
幻想打造了一座舞台,改造一座城市.

有限的我無限的遠方,這座標被抽離一個愛的方向,
我迷失在這座城市,
我如何說服自己再建構另一種真實 !

誰發明了機械座鐘,度量時間與空間 安排相遇非偶然.

是誰勇敢上了發條,
從此思念未歇,沙漏計時著所剩時間.

昔日的咖啡豆不再續磨了,
威士忌琥珀色, 崇高 純淨 濃烈 乾杯後,
是誰 有勇氣將它調回原來的時間 !




2016年12月26日 星期一

@ Psalms 144:1 & 2


Be not thou far from me, O - Lord.
All my strength ! Haste Thee to help me.
Oh my God, I trust in Thee.
Let me net be ashamed. Let not my enemies triumph over me.
Blessed be the Lord my strength, which teaches my hands to war
And my fingers to fight.
My goodness and my fortress. My high tower and deliverer.
My shield and He in whom I trust.

上帝,求您別遠離我, 
您是我的力量, 求您幫助我,
上帝, 我信任依靠您,
別讓我蒙羞, 別讓疾病敵人戰勝我,
您是我的力量磐石, 教導我的雙手去征戰,
教導我的手指去戰鬥,
是我的堡壘避難所、我的高塔、我的解脫者,
是我的盾牌, 和我所依靠的.

Psalm 144:1

A Psalm of David. Blessed be the LORD, my rock, Who trains my hands for war, 
And my fingers for battle;

Psalm 144:2

My lovingkindness and my fortress, My stronghold and my deliverer, 
My shield and He in whom I take refuge, 
Who subdues my people under me.


2016年12月25日 星期日

® Initialized

Eins..Zwei..Drei..Vier..Funf..Sechs..Sieben..Acht..Neun...Get ready to fart !