Thermometer = Nodemcu ESP8266 + DS18B20

Thermometer = Nodemcu ESP8266 + DS18B20

Hi Readers,

Today I would like to show you how we can use our nodemcu as a simple thermometer.

What you need:

  1. Nodemcu (esp8266)
  2. DS18B20
  3. Arduino studio
  4. Serialport monitor (for example the one from Arduino studio)

You can also use:

  1. Breadboard
  2. Couple connectors
  3. 4.7k ohms resistor

How it should be connected?

Untitled Sketch_bb

As you can see on attached picture you need to first connect 3.3V and GND on your breadboard to edge breadboard. Then you simply should connect DS18B20 sensor legs to 3.3V and GND plus its DQ to Nodemcu D4 and also connect it by 4.7k ohm resistor to the 3.3V.

This is how it looked for me

IMG_20160424_191928

I am sure you have manage to connect everything so let’s do some coding.

I have created example code (based on ajaran source code) which you can build and upload by Arduino studio (I used it) and test and use device you have just created! If you haven’t noticed that you have just build basic and simple thermometer :). In example source code gathered temperate I am printing to the serial port. So you can use really any serial monitor to read current temperature.

#include
#include
#include

#define myPeriodic 15 // Seconds
#define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float prevTemp = 0;
const char* MY_SSID = “ssid”;
const char* MY_PWD = “password”;
int sent = 0;
void setup() {
Serial.begin(115200);
}

void loop() {
float temp;
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
Serial.print(String(sent)+” Temperature: “);
Serial.println(temp);
sent++;
int count = myPeriodic;
while(count–)
delay(1000);
}

I have hope you enjoyed this post. I did!

12832321_1215052848518740_5770579544392527095_n

Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

Radek

Lua programming language

Lua programming language

Hi Readers,

Today I would like to tell you another way of programming and controlling ESP8266. This time instead of using ‘AT’ commands I will show you simple application which uses Lua programming language which will be uploaded directly to our ESP8266.

What Lua is? (from ESP8266 wiki)

There are 2 “branches:” of Lua now for ESP8266, and both are now open source. Confusingly, both use the word Node in their name – NodeMCU and NodeLua. As lua.org says, Lua is a powerful, fast, lightweight, embeddable scripting language. Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics.

Lua is small: the Lua interpreter easily fits in under 100 kilobytes including the base libraries.
Lua is fast: independent benchmarks show that Lua is often amongst the fastest interpreted dynamic languages. The Lua interpreter has been extensively tuned for high performance.

What LUA means?

“Lua” (pronounced LOO-ah) means “Moon” in Portuguese. (from https://www.lua.org/about.html)

More about Lua?

If you want to know more about LUA language it’s history, strong and weak points and everything you also would like to know you can visit lua homepage: http://www.lua.org

What editors should I use?

You can use number of tools to user Lua and upload it to ESP8266 I used free tools:

LuaLoader: https://gettoknowthebob.wordpress.com/2016/04/11/lualoader-unknown-but-surprisingly-useful-tool/

ESplorer: https://gettoknowthebob.wordpress.com/2016/04/17/esplorer-probably-best-lua-editor/

And arduino studio, this one I liked the most. Also I have just tried Atom so I don’t want to give you my opinion on it after couple minutes spend together but I believe after spending some time on configuration it. It maybe coolest IDE I ever used for ESP8266.

Of course if you didn’t change your firmware from orginal ATfirmware you will need to replace it with another firmware which you can find with whole description on my blog: https://gettoknowthebob.wordpress.com/2016/04/08/flashing-esp8266-nodemcu-with-latest-firmware/

Examples!

First and the basic example I used is this simple code which turns on and off Nodemcu LED. Here you can see how clear and easy this code looks like. Pin number, Pin mode, Write 1 or 0 and fine. It works!

lighton=0
pin=4
gpio.mode(pin,gpio.OUTPUT)
tmr.alarm(1,3000,1,function()
if lighton==0 then
lighton=1
gpio.write(pin,gpio.HIGH)
else
lighton=0
gpio.write(pin,gpio.LOW)
end
end)

But you can do much more. As we know that all about ESP8266 is Wifi then let’s try connect our board with one or another network:

wifi.setmode(wifi.STATION)
wifi.sta.config("ssid","password")
wifi.sta.connect()
print(wifi.sta.getip())

Or from nodemcu simplest http server:

srv=net.createServer(net.TCP) 
srv:listen(80,function(conn) 
    conn:on("receive",function(conn,payload) 
    print(payload) 
    conn:send("

Hello, NodeMCU.

)
    end) 
end)

I hope you had nice time playing with Lua language as I did 🙂

Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

Radek

ESPlorer – probably best Lua editor

ESPlorer – probably best Lua editor

Hi Readers,

Today I would like to present you ESPlorer. If you read my previous post about LuaLoader. I believe that this is another tool which is worth to be used and learned by everybody who somehow starts his journey with ESP8266.

 

So first interesting thing I was surprised to see was Basic AT Commands Panel.

esplorer2

It contains common wifi commands which you can use to set up Station or Access point mode, HDHCP or not. You can simply query list of around WiFi networks (AT+CWLAP).

 

Second and the main feature is Lua editor. Basic, with nice syntax coloring.

esplorer6

 

You can of course save, compile, run and upload code. It also contains Commands panel which can restart your ESP8266 and do couple more things.

esplorer5

 

I didn’t spend much time using it as most of this what this tool offer I tried before with other or my own tools (ATManager on my Github repository). But if you are beginner or even you are not this is useful tool to control ESP8266 module plus offers everything we need to programmer ESP8266 with Lua programming language.

 

Also as you probable have noticed. There is Frankenstein tab. I am really curious what author of ESPlorer has in mind but it is not yet ready and we will need to wait.

esplorer3

 

Try it, test it and play with it. Really nice tool.

 

You can download it from here: http://esp8266.ru/esplorer/

 

Github repository: https://goo.gl/ii9xsz

 

Be positive and stay calm!

Cheers,

Radek

LuaLoader – Unknown but surprisingly useful tool!

LuaLoader – Unknown but surprisingly useful tool!

Hi Readers,

Today I would like to present LuaLoader. Surprisingly useful tool which I wasn’t aware for too long. To be honest I believe everybody who starts his journey with ESP8266 should at least try LuaLoader.

Of course after testing and learning basic ESP8266 functionality using AT commands. And after changing ESP8266 firmware from AT command firmware to Lua firmware. (Which you can find on my blog).

 

123456
LuaLoader

 

As you can see on attached picture LuaLoader has many different interesting features.

(Skin colour section) Starting with interactive real-time main console window. You will see there everything incoming from ESP8266 board and you can still type this what you want to send to the board.

(Blue section) You can change GPIO settings or check current settings.

(Green section) You get restart it get chip Id or more.

(Orange section) You will be also able to create Access point or get list of other access points near your module.

(Yellow section) You can do everything related to Lua programming language. You can upload source code file, download existing file. Compile. Format. Remove, cat or any toher

Try it. Play with it. Hopefully it will make ESP8266 more easy for you!

 

Apologize Readers I am so brief today but yesterday I tried LuaLoader and as you know really I liked it! But I didn’t had much time to work on a new post. I planned to do it today and guess what it doesn’t work for me. I tried everything but it have a problem to connect LuaLoader connecting with my Nodemcu. I am able to connect to the board with other tools but not LuaLoader.

 

Still I hope you will like LuaLoader and you will have fun a bit with it before my next lesson which will be about another Lua tool which I am planning to test tomorrow.

 

Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

Radek

 

 

 

AtManager (Cool AT commands software with some Reactive Extension)

AtManager (Cool AT commands software with some Reactive Extension)

Hi Readers,

Today I would like to introduce application I have created to tests and learn how to control ESP8266 using AT commands. It is software tool written in C#.

I called it “AtManager”.

Based on AtManager I have created two basic tools PCoordinator and PEndDevice both are basically AtManager with new sequence of first commands send to ESP8266.

What is cool about this application what I tried to achieve is having really basic application which simply sends AT commands and after that is waiting for response. Response which returns as enumerate within response string.

I called it AtCommandService class. It contains SendCommand() command which sends AT command string we want to send and has a timeoutPeriod in which will wait for response.

What could be interesting for you instead of registering SerialDataReceivedEventHandler function I used Reactive Observable to which later I am Subscribing ProcessIncomingData() function which is processing the incoming data. It could be done in classic easy C# way but I have decided it would be cool doing it with reactive a bit simplifying the source code.

      private IObservable<object> _dataReceivedSubscription
{
get
{
return Observable
.FromEventPattern<SerialDataReceivedEventHandler, SerialDataReceivedEventArgs>(x => _serialPort.DataReceived += x, x => _serialPort.DataReceived -= x)
.Select(x => x.Sender);
}
}

Have fun with it. It should make your testing and learning ESP8266 module much easier.

Whole project you can find on my github repository.

 

Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

Radek

Flashing ESP8266 & Nodemcu with latest firmware

Flashing ESP8266 & Nodemcu with latest firmware

Hi Readers,

Today I would like to show you how you can flash ESP8266 boards.

Most of ESP8266 boards have AT firmware installed when are leaving factory. To use Lue we will need to change AT firmware to nodemcu firmware. You can download it from here:

https://github.com/nodemcu/nodemcu-firmware/releases

To change firmware you need flasher tool which you can find here:

https://github.com/nodemcu/nodemcu-flasher

How to do that?

First thing you need to run nodemcu flasher tool (32bit or 64bit depends on your operating system). Then you need to connect nodemcu. After connection you need to select right COM port number.

687474703a2f2f693635392e70686f746f6275636b65742e636f6d2f616c62756d732f75753331362f766f77737461722f4e6f64654d43552d466c61736865722d426567696e2e706e67

Then you need to go to config section and select new firmware I have selected ‘nodemcu_integer_0.9.6-dev_20150704.bin’ but you can select latest one as at time you are reading it there could be newest version.

687474703a2f2f693635392e70686f746f6275636b65742e636f6d2f616c62756d732f75753331362f766f77737461722f4e6f64654d43552d466c61736865722d53657474696e672e706e67

After that you need to go back to Operation section and simply click Flash.

687474703a2f2f693635392e70686f746f6275636b65742e636f6d2f616c62756d732f75753331362f766f77737461722f4e6f64654d43552d466c61736865722d50726f6772616d6d696e672e706e67

After that flashing process will start but if you will have trouble during flashing and you are flashing for example Nodemcu prototype ESP6288 board then you need to click flash button on the board Nodemcu board.

687474703a2f2f693635392e70686f746f6275636b65742e636f6d2f616c62756d732f75753331362f766f77737461722f4e6f64654d43552d466c61736865722d537563636573732e706e67

And that’s all folks! Should work now!

porkey

Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

Radek

ESP8266 Server and Client (TCP & UDP)

ESP8266 Server and Client (TCP & UDP)

Hi Readers,

Today I would like to present you how we can create TCP Server and Client on ESP8266 modules. For purposes of this post we are assuming that an Access point will be also a TCP Server and a Station will be also a Client.

We will reuse commands from my previous posts with list of commands needed to create a Station and an Access point.

Server

So let’s start with the Server. To do that first we need to set one of the modules to work as an Access point to create Wifi network on which we could operate, send commands and etc.

 // Creating Access point – described here:  https://gettoknowthebob.wordpress.com/2016/04/02/second-contact-esp8266-access-point/

AT+RST

AT+CWMODE=2

AT+CWSAP=””,””,,

AT+CIFSR

// Creating TCP Server

AT+CIPMUX=1 – This commands prepares ESP8266 to work with multiple connections. But also we need to remember that if this settings is not set to 1 then Server will not work.

AT+CIPSERVER=1, – Creating and starting Server you can set port number bnut if you don’t want to set it default port number will be set to 333.

Example:

 // Creating Access point

AT+RST

AT+CWMODE=2

AT+CWSAP=”TestNetworkSSID”,”TestPassword”,5,3

AT+CIFSR

// Creating TCP Server

AT+CIPMUX=1

AT+CIPSERVER=1,80

TCP/UDP Client

We need to set second module to work as an Station which will connect to our example Access point and Server.

 // Creating Station – described here:  https://gettoknowthebob.wordpress.com/2016/04/02/second-contact-esp8266-access-point/

AT+RST

AT+CWMODE=1

AT+CWLAP

AT+CWJAP=””,””

AT+CIFSR

// Creating TCP Client

AT+CIPSTART=”TCP”,””, – This command starts the TCP Client (you can replace TCP with UDP)

Example:

 // Creating Station

AT+RST

AT+CWMODE=1

AT+CWLAP

AT+CWJAP=”TestNetworkSSID”,”TestPassword”

AT+CIFSR

// Creating TCP Client

AT+CIPSTART=”TCP”,”192.168.4.1″,80

Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

Radek