2017年1月6日 星期五

ESP8266 – Upload code from Arduino IDE – No Arduino Board Required

源自於
https://alselectro.wordpress.com/2016/11/07/esp8266-upload-code-from-arduino-ide-no-arduino-board-required/

ESP8266 – Upload code from Arduino IDE – No Arduino Board Required

The ESP8266 by itself hosts a 32 bit Microcontroller on it & you can now program your ESP using Arduino IDE. Best part is that NO Arduino board is required.You can upload your code from Arduino IDE , as if you were upgrading the Firmware on ESP.
You can pretty much write any code  for an Arduino and run it on the ESP8266. Of course there is a limit to the I/O on some of the modules, but the Flash on the ESP-12E (Black) module is 4MB and the RAM is 80kB! Add to that the 80MHz 32-bit processor and you have a pretty impressive little cute Arduino.
A sample Blink example program on the ESP8266 turns out to be around 225kB, but that includes the core code.So it’s advisable to use an ESP8266 with more FLASH Memory.Generally the BLACK ones are with higher memory than the Blue ones.The new ESP12E has a Flash of whooping 4MB !!  The Arduino UNO has just 32k Flash & Mega 256k.
esp_blue_black

esp12e_bl_black

Program uploading is done at 115,200 Baud, the default for the module. But It still takes a while to upload a sketch to the module , unlike a regular Arduino.
To begin, you must install the ESP8266 board files in the Arduino IDE.
That is easy enough to do. Make sure that your Arduino IDE is latest
Open the Arduino preferences from File  —> Preferences
Image 1

Add the following URL to the “Additional Boards Manager URLs” seen at the bottom of Preferences Window
Image 2

Click OK to close the Preferences Window.
Click on TOOLS –. BOARDS—> BOARDS MANAGER
Image 4
When the Boards Manager opens, scroll to the bottom. You should see the esp8266 entry.
Select the latest version & then click on INSTALL button.
Image5
It takes a while to download & install .

Image 6
Once installation is over , close the IDE & start again,
Under Tools –> Boards you can now see a new list of ESP8266 Modules.
Image 7
Its time to test some example code.
While using the ESP module make sure that
Power source is 3.3v DC
CH_PD & RESET pins pulled HIGH through resistor.
You can use a development board available at
Image26
An LED is connected to GPIO4 through a resistor.
Image 22
An USB-TTL board is used to connect ESP with USB port of PC.
Rx of USB-TTL board goes to Tx of ESP board
Tx of USB-TTL goes to Rx (3.3v level) of ESP board
GND is made common.
5v of USB-TTL is connected to Vcc of ESP board.As the ESP board has a built in 3.3v regulator we can connect to 5v safely.
Connect the GPIO0 pin to GND.
IMG_20161107_080700

Open the Arduino IDE & select the COM port allotted to the USB-TTL board.
Other settings are done under Tools tab as seen in screenshot below :
Image23
From File —> Examples —> ESP8266 select the BLINK sketch.
As we’ve connected an LED at GPIO4 pin , change the pinMode & digitalWrite pin to 4.
Ensure that GPIO0 is connected to GND & click on UPLOAD button.
It takes a while to compile & then uploading starts.
Image25
Once the Uploading is done the LED connected at pin 4 , starts blinking.
Remember to upload another sketch, you need to ground GPIO0 and push the reset switch. The ESP8266 will be put in UPLOAD mode.
When the upload is done, the sketch will start running. If you reset with GPIO0 still grounded, the sketch will not start running because the ESP8266 will be in PROGRAMMING mode. To exit programming mode, remove the ground from GPIO0.
WATCH THIS VIDEO :


In the next post we shall see how to use the built in WIFI library in your code.

ESP8266–WiFi library on Arduino IDE

源自於
https://alselectro.wordpress.com/2016/11/29/esp8266-wifi-library-on-arduino-ide/

ESP8266–WiFi library on Arduino IDE


In the previous post we’ve seen how to program ESP8266 using Arduino IDE by installing the Boards Manager.
This post is on using the powerful ESP8266 WiFi Library which is automatically installed while using the Boards Manager.When you proceed with the  board package for the ESP8266,as explained in previous post, the ESP8266 WiFi library is automatically installed for you.
             Now, any time you want to use the classes and the functions from that ESP8266 WiFi library,  use the Include statement at the top of the program first, followed by the header name
#include <ESP8266WiFi.h>
at the starting of Arduino code & start using the Classes associated with this library.
ESP8266 WiFi library is designed after the the standard Arduino WiFi library but has even more functionality than the standard Arduino library .The standard Arduino WiFi library is used for the WiFi shield or with the Arduino boards like YUN with inbuilt WiFi.
With the introduction of ESP8266 , the WiFi functionality has become much cheaper & easy to use.
The WiFi library has many classes that you can use. Each class has functions in it that are specific to that class. There’s the WiFi class, the IP address class, the server class, the client class and the UDP class.

class1

In this post we’re going to explore the WiFi class & its functions.
The WiFi class allows to establish a connection with an access point.
What’s cool about the WiFi class is that we don’t  have to create an instance of this class. We can  go ahead and start using it. It’s like the serial library of Arduino. We don’t need to create an instance of the serial library.
class2

First Function of the library is WiFi.begin().
The usage of this function is similar to our Serial.begin().
Just like Serial.begin() , we use WiFi.begin() .WiFi.begin() requires 2 strings as arguments. You need to pass the SSID and the password of the Access point you wish to connect.You need to pass the arguments as character arrays or strings with a lower case s.
WiFi.begin(ssid,pass);
The possible return values are
WL_CONNECTED      after successful connection is established with the Access Point
WL_IDLE_STATUS       when Wi-Fi is in process of changing between statuses
WL_NO_SSID_AVAIL     in case configured SSID cannot be reached
WL_CONNECT_FAILED  if password is incorrect
WL_DISCONNECTED        if module is not configured in station mode

The status function in the WiFi class, doesn’t take any arguments but it returns stuff depending on the status of the network that you’re connected to.
Usually, first, you call WiFi.begin, you pass the SSID and the password because you’re trying to establish a connection with the network. Then, what you do is you wait in a loop until WiFi.status returns the value WL_CONNECTED.
——————————
WiFi.begin(ssid,password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(“.”);
}
——————————

WiFi.SSID();
WiFi.SSID doesn’t take any arguments but it returns the name of the SSID that you’re connected to.

WiFi.RSSI()
Returns the current signal strength in  dB

WiFi.scanNetworks()
Returns the number of discovered networks.It will not list the network names , but returns the number of networks.
WiFi.macAddress()
Returns the MAC address of the ESP device
There is a specific function available to print out key Wi-Fi diagnostic information:
WiFi.printDiag(Serial);
Here is a sample sketch to demonstrate the WiFi library.
—————————————————-
#include <ESP8266WiFi.h>
void setup()
{
  Serial.begin(115200);
  Serial.println();
//disconnect any previous connections
  WiFi.disconnect();
  delay(1000);
//scan for number of nearby networks & print SSIDs
  Serial.print("Nearbyorks found  :");
  Serial.println(WiFi.scanNetworks());
  delay(500);
Serial.println("List of surrounding Network SSIDs…:");
  int n = WiFi.scanNetworks();
  for (int i = 0; i < n; i++)
{
  Serial.println(WiFi.SSID(i));
}
  Serial.println();
//connect to preferred SSID
  
  WiFi.begin("SARAVANA-ACTypass123");
  Serial.println("Connecting");
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
// print SSID name,local IP allotted ,MAC address & signal strength
  Serial.println();
  Serial.print("ConnectedSID          : ");
  Serial.println(WiFi.SSID());
  Serial.print("IPess allotted to ESP : ");
  Serial.println(WiFi.localIP());
 
  Serial.print("MACess of ESP         : ");
  Serial.println(WiFi.macAddress());
  Serial.print("Signalngth is         : ");
  Serial.println(WiFi.RSSI());
  }
void loop()
{
}
——————————————————–
The screenshot shows the result in the serial monitor of Arduino IDE
scan3

The Client & Server classes & their methods are shown in screen shots below :
class3


class4
Download PDF tutorial file for the WiFi library from

IOT Demo with ESP8266 WiFi IOT ESP8266 ESP-12 Test Board

源自於
https://alselectro.wordpress.com/2016/06/27/home-automation-iot-demo-with-esp8266-wifi-iot-test-board/

Home Automation–IOT Demo with ESP8266 WiFi IOT Test Board


Image 2

Image 1

Introducing a new ESP8266 Development Board with an ESP-12, a 3x AA battery holder, a voltage regulator, an RGB LED, several red LEDs, and a light sensor LDR on the ADC input all on one board.
The board can be controlled by an open source Android App which is available from the AI-THINKER Website.
GPIO pins are extended with berg pins for easy external connections. RXD,TXD & GND pins are provided for programming / firmware upgrading. A yellow jumper is provided to pull GPIO0 pin to GND during programming. During normal operation this jumper must be removed.
The board is powered by 3 nos AA batteries , for which a battery box is already wired. On board 3.3v regulator is provided for a stable power supply.
No power switch or Reset switch is provided. To switch off you need to pull out one of the batteries.
The board comes pre-loaded with a demo which does actually seem to work.  If you have an Android based phone or tablet you can download AI-Thinker’s app to control and mix the color balance on the RGB LED and to switch the other LEDs on and off.
The Android Application can be downloaded from :

There are also 6 red LEDs fixed with the necessary resistors connected to GPIO16, GPIO14, GPIO5, GPIO4, GPIO0 and GPIO2. A BLUE LED is always ON if the board is powered.
The GPIO13, GPIO12 and GPIO15 are connected to a RGB LED which allows you color mixing using PWM.
ADC
The analog-digital converter is also available on a pin & connected to a light resistor. This lets you quickly test the ADC and you still can clip the resistor off if you want to measure another analog source.Remember the range of ADC is max 1v & not 0 to 3.3v
If you don’t want to use the light sensor or the LEDs you can simply clip them off. Then you’ll just have an  ESP8266 with 3xAA power supply, 9 available GPIO pins and one ADC.
On the playstore of your Android device search for  IOT DEMO App & install it.
Open the Settings & enable WIFI of the Android phone.Now power on the ESP board to see the AI-THINKER SSID on your mobile.
PAIR this with the ESP board using password ai-thinker
Now open the app & touch on LED 1 to 6 , to see the corresponding light glowing on the ESP board.Onthe top you can see 3 icons with sliders in the App. Use this to mix colors on the 3 color LED of ESP board.
Once the functioning of board is verified , you can proceed to connect the GPIO pins of ESP board with a 4 channel Relay board.
The 4 channel relay board used requires a separate power source of 5V, 1amp.For demo 2 of the GPIO pins are connected to relay 1 & relay 3.The GND pins of both ESP & the Relay. board to be made common.
You can watch this video to learn the home automation basics with ESP board :

2017年1月2日 星期一

過關考試學科

過關考試學科

將答案 mail  至  alex9ufo@gmail.com 

1
2
3
4
5





6
7
8
9
10








1.有一電阻,色碼標示是紅紅棕金,請求出電阻值。(A) 220KΩ (B) 221KΩ (C) 330KΩ (D)220Ω

2.有一四色電阻,其色碼為橙橙紅金,請求出電阻值。(A)332KΩ (B)3.3KΩ (C) 330KΩ (D)223MΩ

3. 一般色碼電阻的色環顏色依序為「棕、黑、紅、金」,該電阻值為何? (A) 1KΩ (B) 10KΩ (C) 100KΩ (D) 1MΩ

4.35歐姆誤差1%色碼電阻如何用四個顏色表示(A) 綠黑棕 (B) 橙綠黑黑 (C) 橙綠黑棕 (D)橙紫黑棕

 

5.有一色碼電阻器,其色帶顏色依序為黃、紫、紅、金,則該電阻器之電阻值為何?(A) 4.6 KΩ±5%
  
(B) 3.7 KΩ±5% (C) 4.7 KΩ±10% (D) 4.7 KΩ±5%

 

6.電阻器之色碼依次為橙、綠、黃、銀,則此電阻器之電阻值可能為 (A)35 kΩ (B)65 kΩ (C)220 kΩ

 (D)350kΩ

 

7.四色帶之色碼電阻器,其色碼藍灰金金標示時,請問所表示之電阻值為何? (A)6.8Ω±5% (B)0.68Ω ±10% (C)68Ω±20% (D)680Ω±5%

8. 某電阻色碼為棕、黑、紅、銀,則該電阻器可能之最高電阻值為(A)900Ω (B)1000Ω (C)1100Ω (D)1200Ω
9. 有一個1kΩ的標準電阻器,當輸入電壓為12伏特時,其電流為多少?(A)12mA (B)12A (C)12kA (D)0.12A
10.在電路中,有4A的電流流過一個的電阻,試求電阻消耗的電功率為多少?(A)20W (B)40W (C)80W (D)100W


2017年1月1日 星期日

ESP8266 ESP-12E Test Boards A0 ADC Test

0V-1V ==> 0-1024 10bit ADC 
ESP8266 ESP-12E Test Boards A0 ADC

ADC Specifications

When referring to the ESP ADC pin you will often hear these different terms interchangeably:
  • ADC (Analog-to-digital Converter)
  • TOUT
  • Pin6
  • A0
  • Analog Pin 0
All these terms refer to the same pin in the ESP8266 that is highlighted in the next section.
Currently, TOUT (Pin6) has a 10-bit precision and its input voltage range is 0 to 1.0 V when TOUT is connected to an external circuit.
參考 http://randomnerdtutorials.com/esp8266-adc-reading-analog-values-with-nodemcu/









//Tools -> Board -> Generic ESP8266 Module

//ESP8266 ESP-12E Test Boards A0 ADC Test Program
// The CDS (LDR is cutted off) on Active
//AO input Voltage Rabge 0-1V 
const int LDR = A0;

void setup() 
{
    Serial.begin(9600);
    pinMode(LDR, INPUT);
}

void loop()
{
    Serial.print("LDR: ");
    Serial.println(analogRead(LDR));   // 0V-1V ==> 0-1024 10bit ADC 
    delay(500);
}

MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構

MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構 這張圖片展示了一個 結合 MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構 (主要透過 Node-RED 進行資料整合)。 系統包含三個核心部分,其運作功能說明如下: 1. ESP32 終端設備(硬體控制層...