Preface –Getting Started..................................................................................................................... 1 Par t1 Modules Introdu ction ......................................................................................................4 1. Crowta il - ES P826 6 Node MCU .................................................................................... 4 2. Crowta il - LED ...............................................................................................
Lesson17: TWO NodeMCU Communication.............................................................................33 Lesson18: DHT11 Temperature Display System........................................................................35 Lesson19: Wireless Toliet Led Indicator....................................................................................
Preface –Getting Started Welcome to the world of ESP8266 NodeMCU. It’s an ESP8266 WiFi module with Crowtail interface. We will use it to make some simple application of fun with various Crowtail modules . 1: How to use ESP8266 NodeMCU 1) Before you use the micro USB cable to connect the ESP8266 NodeMCU with your computer, you need to install the cp2012 USB driver. you can download it from there: https: //www.sil abs .com /product s/mc u/P age s/ US Bto UARTBridge VC PDrive rs .
Also, you can use some of the function which display on the right side of Lualoader interface. Baud rate setting: set the baud rate that you need ,normally set at 9600.
port. Chip information check: check the information about the chip or restart the NodeMCU. Wireless network connect: Enter the wireless network account and password, you can connect it and get the IP. Compile and download program: First, click “Upload File…”upload the .lua file that you want to download. Secondly click “compile” to compile the .lua file, through the compile can click “Download” to download the program. This site: http://w w w. benlo.c om/es p826 6/ has its detail introduction.
Part1 Modules Introduction 1. Crowtail- ESP8266 Node MCU Des c rip tion Crowtail- ESP8266 NodeMCU adds six crowtail interface on the board (one I2C port, one UART port, one analog port and three digital port). Wired up a USB-Serial chip that can upload code. We also provide a connector for 3.7V Lithium polymer batteries and built battery charging. 2. Crowtail- LED Des c rip tion The Crowtail-LED is designed for the beginners of Arduino. It is the best way to step into the Aduino from it’s I/O pins.
Description The Crowtail- Buzzer module is a piezo buzzer which can be connected to digital outputs, and will emit a tone when the output is HIGH. 5. Crowtail- Relay Description The Crowtail- Relay module is a digital normally-open switch. Through it, you can control circuit of high voltage with low voltage, say 5V on the controller. 6.
7. Crowtail- Temperature& Humidity Sensor Description The Crowtail- Temperature& Humidity Sensor is based on DH11 which is a complex sensor with a calibrated digital signal out.It used to detect the temperature & humidity. 8. Crowtail- Light Sensor Description The Crowtail- Light Sensor module incorporates a light dependent resistor (LDR), is a commonly used sensor in a wide variety of applications from DIY projects to industrial automation.
10. Crowtail- Hall Sensor Description The Crowtail- Hall Sensor uses the Allegro Hall-effects switches are next generation for the population Allegro 312x and 314x lines of unipolar switches. It switches HIGH(turn off) when the magnetic field disappears. 11.Crowtail- Tilt Switch Description The Crowtail- Tilt Switch is the equivalent of a button, and is used as a digital input. Inside the tilt switch is a pair of balls that make contact with the pins when the case is upright.
Description The Crowtail- RFB-LED module with 4 pcs of WS2812B which is a Chainable & Addressable LED. Users can control all the LED with only one microcontroller pin! Besides, the LED bar can be also chainable, that is, you can connect more than one LED bar together to make your project more dreamful. In this module you can control every LED with different color at the same time. 14.
17. Crowtail- MOSFET Description Crowtail- MOSFET enables you to control higher voltage project, say 50VDC, with low voltage, say 5V, on microcontroller. MOSFET is also a kind of switch. There are two screw terminals on the board. One for input power source and the other for device you want to control. CrowtailMOSFET will pass the power from one end to another when closed. 28.
Description This is a high resolution digital accelerometer providing you at max 3.9mg/LSB resolution and large ±16g measurement range. It's base on an advanced 3-axis IC ADXL345. Have no worry to implement it into your free-fall detection project, cause it's robust enough to survive up to 10,000g shock. Meanwhile, it's agile enough to detect single and double taps. It's ideal for motion detection, Gesture detection as well as robotics. 21.
Description The Crowtail- Magnetic Sensor is a double-ended type and may be actuated with an electromagnet, a permanent magnet or a combination of both. The magnetic switch is a wonderful tool for designers who would like to turn a circuit on and off based on proximity 24.Crowtail- Protoboard Description This Crowtail allows you to add your own circuitry or components to your Crowtail system prototypes. 25.Crowtail- Switch Description The Crowtail- Switch is a Latching switch.
Part2 Crowtail Application Lesson1: LED Control LED control is bas ic on NodeMC U. In this lesson we will learn how to control the LED, you can make the led blink and control the last time it shines or the brightness. Material: Cro wtai l- ES P8 266 NodeM CU x 1 Cro wtai l- LED x 1 Cro wtai l- Cable x 1 US B C abl e x 1 Hardware Connection Plu g the Crow tai l-L ED to the D1 port on NodeM CU by a 3pin Crow tai l-C able as fol lowin g. Open the LuaL oader.
Open the LuaL oader and fol low the below steps before downl oad pro gram. First, cli ck “Upload File …” to choo se ES P8 266 NodeMC U kit demo code -> P01_LED _Control -> init.lua Secondly, cli ck “compile ” to compi le the .lua file and then clic k “ Dow nloa d ” to downl oad the .
The Crowtail- LED will be blink every 0.2 second. Why th e led blin k every 0.2 secon d? How to control it keep li ghti ng mo re longer? Now let me tell you. In thi s demo code, first def ine the gpi o1 into output port , then let the gpio 1 co nstantly switc h between high and low level , set the ti me inter val as 0.2 second and make it cyc le. You can chan ge the tmr.delay( ) param eter in the program to chan ge the inter val. Demo code: fu n c t io n in i t _L E D ( ) gp i o . m o de ( 1 , gp i o .
to realize it. When pressed the button, the led was lighten and turn off when released. Material: Crowtail- LED x 1 Crowtail- Button x 1 Crowtail- ESP8266 NodeMCU x 1 Hardware Connection Open the LuaLoader, click the “Upload File…” and choo se ESP826 6 NodeM CU kit dem o code -> P02_Button_Control_Led -> init.lua. After the upload completed then click “Download ” to download the init.lua file. Demo code: gpio.mode(1,gpio.OUTPUT) --Setup the port mode gpio.mode(2,gpio.INPUT) while(1) do gpio.
Open the LuaLoader, click the “Upload File…”choo se ESP8 266 NodeM CU kit demo code -> P03_ Moisture_sensor -> init.lua. After the upload completed then click “Download ” to download the init.lua file. Demo code: while(1) do b=adc.read(0) -- analog read A0 print (b) tmr.delay(2000000) --delay 2s end you can see the sensor value in the LuaLoader debug window. Lesson4: Vibration Motor Tilt Switch is the equivalent of a button, it can output different signal when it upright and tilt.
code -> P04_Vibration_Motor -> init.lua. After the upload completed then click “Download ” to download the init.lua file. Demo code: gpio.mode(1,gpio.OUTPUT) -- set port1 output mode gpio.mode(2,gpio.INPUT) -- set port2 input mode while(1) do gpio.read(2) tmr.delay(200000) --delay 2s if (gpio.read(2)==1) then gpio.write(1,gpio.HIGH) end if (gpio.read(2)==0) then gpio.write(1,gpio.LOW) end end When the tilt switch slope, the vibration motor vibrating.
Demo code: while (1) do b=adc.read(0) --Analog read A0 if (b<100) then gpio.write(1,gpio.HIGH) else gpio.write(1,gpio.LOW) end end Under the environment of light, blocking light sensor , led will turn on. No block ,led turn off. Lesson6: Raining detect In our daily life, we play computer game or watch TV all-possessed indoor,sometime raining, our clothes usually be wetted in the outdoor, but if there is a sensor that it can remind us that when it begin to rain outside, tragedy will not happen to us.
Lesson7: Flame detect Have you seen the fire-fighting robots? Why it can find the source of fire?In this lesson, we will tell you the principle about it and you can make a robot like that. Material: Crowtail- ESP8266 NodeMCU x 1 Crowtail- Flame Sensor x 1 Crowtail- buzzer x 1 Hardware Connection Open the LuaLoader, click the “Upload File…”choo se ESP8 266 NodeM CU kit demo code -> P07_Flame_detect -> init.lua. After the upload completed then click “Download ” to download the init.lua file.
Open the LuaLoader, click the “Upload File…”choo se ESP8 266 NodeM CU kit demo code -> P08_Motion_detect -> init.lua. After the upload completed then click “Download ” to download the init.lua file. Demo code: while(1) do b=gpio.read(2) print (b) tmr.delay(2000000) if(b==1) then gpio.write(1,gpio.HIGH) else gpio.write(1,gpio.LOW) end After successfully download the code, you will observed that: when there is a motive object in the detection range of the sensor , the buzzer will alarm.
Open the LuaLoader, click the “Upload File…”choo se ESP8 266 NodeM CU kit demo code -> P9_Hall_Switch -> init.lua. After the upload completed then click “Download ” to download the init.lua file. Demo code: while(1) do a=gpio.read(1) print (b) tmr.delay(2000000) --delay 2s if(a==1) then gpio.write(2,gpio.HIGH) else gpio.write(2,gpio.LOW) end end If there is a magnetic material approaching the hall sensor, the relay will start to work, on the contrary, the relay will be disconnected.
Open the LuaLoader, click the “Upload File…”choo se ESP8 266 NodeM CU kit demo code -> P10_Breathing_Lamp -> init.lua. After the upload completed then click “Download ” to download the init.lua file. Demo Code: print("Breathing Lamp Start") pwm.setup(1,1000,1023); tmr.alarm(2,100,1,function() -- set pot 1 PWM mode frequency 1000hz and the duty cycle 1023pwm.start(1); --Timer 2 using the timing 100ms Repeatability local r=adc.
gpio.write(1,gpio.LOW) end end Lesson12: One Wire Waterproof Temperature Sensor This sealed digital temperature probe lets you precisely measure temperatures in wet environments with a simple 1-Wire interface. Material: Crowtail- ESP8266 NodeMCU x 1 Crowtail- One wire Waterproof Temperature Sensor x 1 Hardware Connection Open the LuaLoader, click the “Upload File…” to choo se ES P8 266 NodeM CU kit demo code -> P12_DS18B20_One_Wire_Waterproof_Temperature_Sensor -> ds18b20.lua.
lo c a l ow = ow -- Tim er mo d u l e lo c a l tm r = tm r -- Li m i te d to lo c a l en v ir o n m e nt se t fe nv ( 1 , M ) -- -- - -- - -- - -- - -- - -- -- - -- - -- - -- - -- - -- -- - -- - -- - -- - -- - -- -- - -- - -- - -- - -- - -- -- - -- - -- - -- Im p l em en ta t io n -- -- - -- - -- - -- - -- - -- -- - -- - -- - -- - -- - -- -- - -- - -- - -- - -- - -- -- - -- - -- - -- - -- - -- -- - -- - -- - C = 0 F = 1 K = 2 fu n c t io n se t u p( d q ) pi n = dq if ( p i n == ni l ) th e n pi n = de fa u
un t il ( ( a d d r ~= ni l ) or (co u n t > 10 0 ) ) ow. re s e t_ s e a r c h( p i n ) en d if ( a dd r == ni l ) th e n re t ur n re s u lt en d crc = ow.c r c 8 ( st r i n g .s u b ( a dd r, 1 , 7 ) ) if (c r c == add r : by te ( 8 ) ) th e n if (( a d dr : b y te ( 1 ) == 0x 1 0 ) or (a d d r : b y t e( 1 ) == 0x 2 8 ) ) th e n -- pr in t ( " D ev i c e is a DS 1 8 S 2 0 fa m i l y de v i c e ." ) ow. re s e t( p in ) ow. se l e c t ( p i n , ad d r ) ow.w r i t e( p i n, 0x 4 4 , 1) -- tm r.
-- pr in t ( " D ev i c e fa m il y is no t re c o g ni ze d . " ) en d el s e -- pr in t ( " C R C is no t va li d ! " ) en d re t ur n re s ul t en d fu n c t io n re a d ( a d dr, un i t ) t1 , t2 = re a d N u m b e r ( a d d r, un i t) if ( ( t 1 == ni l ) or (t2 == n i l ) ) th e n re t ur n ni l el s e re t ur n t1 . . " ." .. st r i n g .fo r m at ( " % 0 4 u " , t2 ) en d en d -- Re tu r n mo d u l e ta b le re t ur n M In i t .
pr in t ( " Te m p t3 Mi dd l e : ". .t 3 .. " de g C" ) pr in t ( " Te m p t4 Top. . .: "..t 4 . ." de g C" ) pr in t ( " Te m p t5 Fl ow. .: "..t 5 . ." de g C" ) pr in t ( " Te m p t6 Re t u r n : "..t 6 . ." de g C" ) -- Cl e a n u p t = ni l ds 1 8 b2 0 = ni l pa c ka g e .l o a d e d [" d s 1 8 b2 0 " ] =n i l en d tm r.a la r m ( 2 , 10 0 0 , 1, fu n c t io n ( ) get D S d at a ( ) en d ) Lesson13: Rainbow Light Do you want to make a RGB-LED like a colorful rainbow.
WHITE = string.char(ON, ON, ON) BLACK = string.char( 0, 0, 0) function colourWheel(index) if index < 85 then return string.char(index * 3 * BRIGHT, (255 - index * 3) * BRIGHT, 0) elseif index < 170 then index = index - 85 return string.char((255 - index * 3) * BRIGHT, 0, index * 3 * BRIGHT) else index = index - 170 return string.char(0, index * 3 * BRIGHT, (255 - index * 3) * BRIGHT) end end rainbow_speed = 8 function rainbow(index) buffer = "" for pixel = 0, 7 do buffer = buffer ..
14.Lesson14 MOSFET Control Fan The MOSFET is a kind of switch. It enables you to control higher voltage project with low voltage. There are two screw terminals on the board. One for input power source and the other for device you want to control. In this lesson we will teach you how to use the MOSFET to control a fan.
Lesson15: Read Data From ADXL345 Digital Accelerometer Sensor In this lesson ESP8266 is used to read data from ADXL345 Digital Accelerometer Sensor, It easy to use and obviously observe the result from the debug window. There is also some application of ADXL345 accelerometer in our daily life, likes free-hall detection and so on.
i2c.write(id,0x2C) --BW rate register i2c.write(id,0x0A) --Data rate 100Hz i2c.stop(id) i2c.start(id) i2c.address(id, dev_addr,i2c.TRANSMITTER) i2c.write(id,0x2D) --Power control register i2c.write(id,0x08) --Activate measure mode i2c.stop(id) -- user defined function: read from reg_addr content of dev_addr function read_reg(reg_addr) i2c.start(id) i2c.address(id, dev_addr,i2c.TRANSMITTER) i2c.write(id,reg_addr) i2c.start(id) i2c.address(id, dev_addr,i2c.RECEIVER) c=i2c.read(id,1) i2c.
Xn=bit.band(0x1000, Xaxis) Yn=bit.band(0x1000, Yaxis) Zn=bit.band(0x1000, Zaxis) --If negative, convert twos complement number to decimal(-8193=-8192-1) if Xn==4096 then Xaxis=Xaxis-8193 end if Yn==4096 then Yaxis=Yaxis-8193 end if Zn==4096 then Zaxis=Zaxis-8193 end --4mg/LSB, multiply by 4, should divide by 1000 Xaxis=Xaxis*4 Yaxis=Yaxis*4 Zaxis=Zaxis*4 print(Xaxis) print(Yaxis) print(Zaxis) end tmr.
Hardware Connection Open the LuaLoader, click the “Upload File…”cho ose ESP826 6 No deMC U kit demo code -> P16_Servo_Remote_Control -> init.lua. After the upload completed then click “Download ” to download the init.lua file. Forward rotation: for i=1,100,1 do tmr.alarm(0,20,1,function () -- 50Hz gpio.write(1, gpio.HIGH) tmr.delay(2000) --Forward gpio.write(1, gpio.LOW) end) end Reversion for i=1,100,1 do tmr.alarm(0,20,0,function () -- 50Hz gpio.write(1, gpio.HIGH) tmr.delay(500) --Reversion gpio.
Open the LuaLoader, set one serial port which connect the NodeMCU (“AP mode”) and connecting , then click the “Upload File…” after connecting successful, choo se ESP826 6 NodeM CU ki t demo code -> P17_NodeMCU_Communication ->TCP Server-> init.lua. After the upload completed then click “Download ” to download the init.lua file.
tmr.stop(1) print("Connected!") print("Client IP Address:",wifi.sta.getip()) cl=net.createConnection(net.TCP, 0) cl:connect(80,"192.168.4.1") tmr.alarm(2, 5000, 1, function() if(wifi.sta.getip()==nil) then wifi.sta.disconnect() wifi.sta.config("test","12345678") -- connecting to server wifi.sta.connect() print("Looking for a connection") tmr.start(1) end cl:send("Hello World!") cl:send(i) i=i+1 end) else print("Connecting...
Open the LuaLoader, click the “Upload File…”cho ose ESP826 6 No deMC U kit demo code -> P18_DHT11_Temperature_OLED_Display-> TCP Server->init.lua. After the upload completed then click “Download ” to download the init.lua file. Then Click “Upload File”, Choose the”main.lua” in the same folder, download it.
srv:close() end srv=net.createServer(net.TCP) srv:listen(80,function(conn) conn:on("receive",function(conn,payload) print(payload) i=i+1 disp:firstPage() repeat disp:drawStr(0,0,payload) --Print the data out disp:drawStr(15,15,i) --Print the data out until disp:nextPage() == false conn:send("
Hello, NodeMCU!!!
") end) conn:on("sent",function(conn) conn:close() end) end) DHT11: --init.lua -- tcp client print("ESP8266 Client1") wifi.sta.disconnect() tmr.delay(100) wifi.setmode(wifi.STATION) wifi.--dht11.lua--- Measure temperature, humidity and post data to thingspeak.com -- 2014 OK1CDJ -- DHT11 code is from esp8266.com ---Sensor DHT11 is conntected to GPIO0 pin = 1 Humidity = 0 HumidityDec=0 Temperature = 0 TemperatureDec=0 Checksum = 0 ChecksumTest=0 function getTemp() Humidity = 0 HumidityDec=0 Temperature = 0 TemperatureDec=0 Checksum = 0 ChecksumTest=0 --Data stream acquisition timing is critical. There's --barely enough speed to work with to make this happen. --Pre-allocate vars used in loop.
--acquisition loop for j = 1, 40, 1 do while (gpio_read(pin)==1 and bitlength<10 ) do bitlength=bitlength+1 end bitStream[j]=bitlength bitlength=0 --bus will always let up eventually, don't bother with timeout while (gpio_read(pin)==0) do end end --DHT data acquired, process.
print ("ChecksumTest: "..ChecksumTest) end --- Get temp and send data to thingspeak.com function sendData() getTemp() tmr.stop(2) -- conection to thingspeak.com print("Sending data to TCP Server") conn=net.createConnection(net.TCP, 0) conn:on("receive", function(conn, payload) print(payload) end) -- api.thingspeak.com 184.106.153.149 conn:connect(80,'192.168.4.1') conn:send("T="..Temperature.."."..TemperatureDec.." H="..Humidity.."."..HumidityDec..
there is not occupied. This lesson is designed primarily a remote indicator toilet, do not need to go to the toilet can also know whether someone is using the toilet, this greatly facilitates our daily life. Of course, this design idea can be applied in many other occasions of life.
cl=net.createConnection(net.TCP, 0) cl:connect(80,"192.168.4.1") tmr.alarm(2,1000, 1, function() if(wifi.sta.getip()==nil) then wifi.sta.disconnect() wifi.sta.config("test","12345678") -- connecting to server wifi.sta.connect() print("reconnection") tmr.start(1) tmr.stop(2) end pin_value=gpio.read(pin) if(pin_value==0) then cl:send("10") print("send 10") else cl:send("11") print("send 11") end end) else print("Connecting...") end end) Server: -- ESP8266 Server print("ESP8266 Server") wifi.setmode(wifi.
print("inter tmr") if(pin_value=="10") then gpio.write(pin, gpio.HIGH) gpio.write(pin1, gpio.LOW) elseif(pin_value=="11") then gpio.write(pin, gpio.LOW) gpio.write(pin1, gpio.HIGH) end end) end) conn:on("sent", function(conn) collectgarbage() end) end) The lessons are over here, and you have learned the basic application of ESP8266 NodeMCU, but the usage of ESP8266 is not only these.
44