Search in The Electromania's Blog

Monday, 8 February 2016

How to program ESP8266 ESP-12E NodeMCU using Arduino IDE


This is quick guide/tutorial to get started with Arduino IDE and ESP8266-ESP12E NodeMCU wifi module.
(I believe, this tutorials can be used for other NodeMCU versions too. (or only ESP8266 boards, but with necessary hardware modifications and using FTDI modules) Please note the pin mappings as given at the end of this post.


 

We will be connecting external LED directly to D0 pin (or GPIO16) of NodeMCU (no need of external current limiting resistor). 
         
If you do not have external LED, it can be skipped because there is already one on-board (blue) LED at this pin. I have connected external red LED just as fun.

Boards manager link
http://arduino.esp8266.com/stable/package_esp8266com_index.json

or it can be found on following link-
https://github.com/esp8266/Arduino


Copy the above link and insert it in Arduino IDE using following sequence-
File menu - Preferences-

Paste copied link into the area shown in black box in above image. Close and restart the Arduino IDE.

Now go to Tools Boards manager and search for ESP8266 and install the board libraries. Restart the Arduino IDE once again.


Go to Tools - Boards (scroll down the list of boards) - Select NodeMCU 1.0 ( ESP-12EModule)


Select the Port to which your ESP is connected and upload the examples blink sketch.
I have modified a bit the sketch to blink LED faster, but you can leave it and just upload the sketch to ESP and there you go... the Onboard LED blue and external LED red starts blinking alternately.

Congratulations for successful configuration of Arduino IDE for ESP8266 NodeMCU dev boards.  

Pin mapping between actual GPIO of ESP8266 and NodeMCU board (it might vary if you are using other boards).

NodeMCU ESP8266 GPIO Functions
D0 GPIO16 LED_BUILTIN or BUILTIN_LED
D1 GPIO5 I2C-SCL or CLK
D2 GPIO4 I2C-SDA
D3 GPIO0 SPI-RES or RST
D4 GPIO2 SPI-DC
D5 GPIO14 SPI-SCL or CLK
D6 GPIO12 SPI-MISO
D7 GPIO13 SPI-SDA or MOSI
D8 GPIO15 SPI-CS or SS
D9 GPIO3 Serial RX0
D10 GPIO1 Serial TX0
D11 GPIO9
D12 GPIO10


Note- In case if Arduino IDE version 1.6.7 dosent work for you, try to go back to arduino 1.6.5 or backwards. (I have read that some NodeMCU boards have issues with latest versions of Arduino IDEs).

Helpful links-
https://github.com/esp8266/Arduino/blob/master/variants/nodemcu/pins_arduino.h#L37-L59

http://nodemcu.readthedocs.io/en/dev/en/modules/gpio/ 


Current NodeMCU i am using was from Banggood.com and it says 
DOIT ESP12E DEVKIT V2    www.doit.am



Saturday, 30 January 2016

Arduino - Fan RPM measurement using internal hall effect sensor (Hardware Interrupts and LCD)


I needed to measure rotational speed in RPM for one modified computer 3 pin fan with inbuilt Hall effect sensor.

This project gives quick intro to-

1) Using Interrupts of arduino boards (here arduino Due)
2) Interfacing Hall effect sensor of fan
3) Interfacing and displaying real time information on LCD display (here 16 x 2)
4) Implement basic logic in programming

There are many ways of measuring speed, using IR sensor, Photo diode, HES etc. 
The computer fans have internal hall effect sensor (HES) that can be used to pick up the ticks per revolution of rotor. The measurement algorithm can be also varied depending upon the required accuracy and response time. I am measuring fan speed approx in 1 sec interval using basic microcontroller interrupt driven algorithm, giving acurracy of few 10s or RPM, something I needed for my other project.

Hall effect sensor working principle (Source of image)

Hall effect sensor (HES) works on the principle of interaction of magnetic field with electrons flowing in the conductor and subsequent generation of secondary voltage known as Hall voltage. Read more here.

In three pin fans with internal hall effect sensor, generally yellow colored wire is output of HES. Most of the time it requires external pull-up resistor of few kohm values depending on supply voltage. Instead of external resistor, internal pull-up resistor of our arduino board pins can be used. digitalWrite(pinno, HIGH); in setup() function enables this internal pull-up resistor. With this HES output wire can be directly connected to interrupt pin (here pin 12) without using an external 10kohm pull-up resistor. I have used external pull-up resistor.

With every rotation of rotor, depending on type of fan and number of magnets attached to rotor, with every rotation of rotor, we get 1, 2 or 4 ticks as output signal from HES. We will pick up these ticks by interrupting our arduino program using "hardware interrupts". Interrupts help in letting our arduino do its regular job until some signal is received at interrupt pins. This lets us use arduino perform other tasks while waiting for signal at interrupt pins. 




I have used a RGB LED to provide quick idea about speed range, the LCD displays actual speed in RPM, values updated every second.

Code/Sketch is shown at the end of video or on github page here





Bill of materials:-

1) Arduino due board from Ali-express
2) Resistors - 10k and 470 ohm  (you can use any other resistors in similar ranges)
3) PC fan or any other motor with inbuilt hall effect sensor
4) LCD display with I2C interface  ( you can use parallel LCDs too, but pinout and code needs to be slightly modified)
About installing I2CLibrary and getting I2C address, check my video - https://www.youtube.com/watch?v=SPk8xxSgUxk 
5) Power supply as per used fan/motor  (here it is 12V DC)
6) 3 LEDs or single RGB LED, to use as optical indicator of fan RPM range

In next project i will interface OLED display instead of LCD and try to modify code for faster update and higher accuracy of RPM....

Thanks to - 
http://www.themakersworkbench.com/  for starting code









Contact Electromania

Name

Email *

Message *