Latest Entries »

TITLE

PIC 12F675 is 8 bit , 8 pin mini and powerful Microcontroller.

It has 1k Bytes of ROM Flash memory , 64 Bytes of RAM ,  128  Bytes of EEPROM , 4 channels of 10 bit ADC , 2 TIMERS one 8 bit and another 16 bit.A comparator and inbuilt oscillator also are provided.

This chip can be programmed using PICKIT3.

IDE used is MPLAB X and compiler is XC 8.

Connection details as below in image.

An LED is connected to pin 3 (GP4) .Short lead of LED is connected to Gnd through a Resistor 470E.

PIC3

MPLAB X IDE is the IDE used here for development.Compiler installed is XC8

https://www.microchip.com/mplabx-ide-windows-installer

https://www.microchip.com/mplabxc8windows

Image 2

Open MPLABX IDE , File  –> New Project

Select  Standalone Project

Image 3

Under Device select PIC12F675

Against TOOL , tick mark Show All and select PICKIT3 from the dropdown list.

Image 4

Next is the selection of Compiler.

Select XC8 .

If not listed , check the installation of XC8 compiler.

Image 5

Provide a Project name and browse to the location of folder created for project location.

Image 6

Now the project files are created.

Right click on SOURCE FILES and click on New –> main.c

If you want rename the file , leave the extension as .c

Click Next to add the .c file to Source files.

Image 7

Click on .c file to see the skeleton C file.

#include <xc.h>

header file for Compiler is added automatically.

We need to set the configuration bits in the code using

#pragma config

Image 17

Settings like Internal oscillator , Watch Dog OFF , Brownout detect OFF can be

used with a comma separator in a single command line.

Image 16

You can also verify correct settings by clicking on Production –> Set Configuration Bits

Image 9

A new Window opens at the bottom.

Here you can do the needed settings and finally click on Generate code.

You can copy and paste the pragma settings inside the C code.

Or to make it simple make a single command line with comma separator.

As we cannot spare 2 GPIO pins for external crystal oscillator , most of the projects are configured for internal oscillator of 4 MHz.

This is set by

# pragma config FOSC=INTRCIO

Image 10

Next we need to define the crystal frequency

#define _XTAL_FREQ 4000000

Without this command delay function will not work.

Data Direction is set by TRISIO Register.

Making a bit 0 will make the corresponding  GPIO pin OUTPUT

and making a bit 1 will configure GPIO as INPUT.

TRISIO=(0<<4);

The above notation can also be used.Here 0 is left shifted 4 times thus making GP4 as OUTPUT.

Under never ending loop we make GP4 initially 0 and after a delay of 1 second we make it 1.

Note the usage of double underscore __ before delay.

Image 11

Before building the project , an important setting to be done to make the Power to Target from PICKIT3.

Click Set Project Configuration and then Customize.

Image 20

Select PICKIT3 and then from the dropdown select POWER.

Image 13

Put a tick mark against Power Target from PICKIT3 and click Apply.

Image 14

Now click on BUILD MAIN PROJECT or F11 Button to Compile.

Image 15

When no errors are found , you can see BUILD SUCCESSFUL.

Image 18

Now click on the DOWN Arrow icon on tool bar to upload the hex file on to chip.

Image 19

Once file is uploaded , you can see the LED connected to GP4 blinking.

IMG_20200624_162228

blog_image

ATTINY85 , a 8 bit AVR Microcontroller provides many features in lesser pins.

With program memory of 8Kbytes the controller has satisfying memory for many applications.

With various POWER SAVE modes it can work on battery operated applications.

 

t1

SPECIFICATIONS :

Number of  Programmable I/O pins   6           Operating Voltage  +2.7 V to +5.5V

Maximum DC Current per I/O Pin 40 mA     Maximum DC Current through VCC and GND Pins 200 mA

Communication Interface

Master/Slave SPI Serial Interface  (5,6,7  PINS)   [Can be used for programming this controller]

I2C or Two-wire Serial Interface  (5,7  PINS)  [Can be used to connect peripheral devices and sensors]

Universal Serial Interface  (5,6,7 PINS)   [Can be used for communicating with other controllers]

 

UART Interface   Not available        ADC Feature  4channels, 10-bit resolution ADC

Analog Comparators 1                    Timer Module   2 x  8-bit counter

PWM outputs  4                              External Oscillator   0-20MHz for ATTINY85

Internal Oscillator   0-8MHz  Calibrated Internal R-C Oscillator

CPU Speed   1 MIPS @ 1MHz

Program Memory or Flash memory size  8Kbytes

RAM size   512Bytes on Internal SRAM

EEPROM size  512Bytes of In-System Programmable EEPROM

Program Lock   Available          Watchdog Timer  Available

Power Save Modes      Three Modes  [Idle ,  ADC Noise Reduction ,  Power-down ]

 

Image 2

 

ATTINY85 can be programmed in many ways.

This post is on programming in AVR mode .

For programming we need an USBASP (also called AVRDUDE)  hardware  which is the same one used for programming 8051 ICs.

 

USBASP1

Connection between ATTINY85 and USBASP is by SPI pins

MOSI to MOSI (pin5)

MISO to MISO (pin 6)

SCK to  SCK (pin 7)

RST to RST (PIN 1)

Vcc to pin 8 & Gnd to pin 4 of ATTINY.

Image 3

For programming we use WINAVR (Programmers Notepad & MFILE)

usbasp driver and winavr can be downloaded from following link.

download link :

http://www.alselectro.com/files/software.zip

After installing driver for usbasp , open the Device Manager to see USBASP under libusb.

 

Image 1

 

Next install WINAVR

t2

Accept default location of installation.

Image 2

Following components must be selected

ADD Directories to PATH

Install Programmers Notepad

Image 3

Install WINAVR as ADMINISTRATOR.

Otherwise Programmers Notepad (PN) will not work.

MFile which makes RULE for programming also installed automatically.

Image 4

In WIN 8 / 10 you need to replace msys.dll file.

Copy the file from the downloaded folder.

Go to C:\WINAVR\utils\bin

and paste.

Image 5

Confirm Replace file.

Image 6

 

Image 7

Open Programmers Notepad.

Always create a separate folder to save your project files.

Image12

Type in the C code to blink LED connected at  PB3 (pin 2 ) of ATTINY.

 

Image 9

Save the file with .c extension.

Image 10

Now you have to create the MAKEFILE in the same project folder.

Click on MFile.

 

Image 12

Select  MCU Type as ATTINY85.

Image 13

Select PORT as usb

Image 14

Programmer to be set as usbasp.

But usbasp is not in Programmer list.

Select any one from the Programmer list and then click on ENABLE EDITING.

Image 15

Change the Programmer as usbasp.

Image 16

Scroll up to find TARGET.

Rename TARGET to the file name of your project.Here it is ledblink.

Do not use the .c extension here.

Image 17

Save the file in the same folder where you stored the .c file.

Image 18

 

Under Tools  —>  click Make All

Image 11

 

Image 22

 

If no error in coding , you get Process Exit Code : 0  and .hex file created in your project folder.

Image 19

Click on Tools  –>  Program

 

Image 20

The .hex file will be loaded on to the ATTINY successfully.

Image 21

The LED starts blinking now.

WINAVR can be used to write C file and program using USBASP.

video :

 

blog_image

 

Image 4

 

In these days of Virus spread , automatic hand sanitizer and auto water tap are the need of the hour.

This is a very simple and low cost effective circuit without a Microcontroller.

Water pump or Water Solenoid can be controlled for dispensing sanitizer or water automatically when hand is brought near the sensor.

Sensor used here is an IR MODULE.

Image 3

 

The IR sensor module is built on  IR Transmitter and Receiver, Opamp, Variable Resistor &  output LED indicator. IR LED Transmitter is white or transparent in colour,and emits infra red light invisible to human eye.IR Receiver is a photo diode black in color to absorb more light.

IR rays reflected from object is sensed by this receiver and current flow is proportional to the amount of Light. This property makes it useful for IR detection.

A LM358 or 386 comparator is on board and gives a LOW signal while detecting IR.

Normally Output pin is HIGH and becomes LOW on any intruder object.The blue trimpot can be adjusted for sensitivity.

The board operates on 5V DC , and we need a 7805 regulator to convert 12v to 5v.

Image 2

 

The main device in the circuit is the 4 leg IC OPTOCOUPLER PC817.

It is the cheapest IC available and price is less than a 555 IC.

images

It has inbuilt  Infrared Emitting Diode (IR LED) and a photo transistor . It is Enclosed in a 4 pin package.

The photo transistor’s base becomes activated when LED conducts and throws light on it. When the current flowing through the LED is interrupted, the infra-red emitted light is cut-off, causing the photo-transistor to cease conducting. The photo-transistor can be used to switch current in the output circuit.

The black DOT is pin 1 which is ANODE of Diode.

PC817-Internal-Pins

The output of OPTO drives a Transistor and in turn the solenoid.

The transistor we use is a NPN  BD139.

 

Image 7

  • Continuous Collector current (IC) is 1.5A
  • Collector-Emitter voltage (VCE) is 80 V
  • Collector-Base voltage (VCB) is 80V
  • Emitter Base Breakdown Voltage (VBE) is 5V
  • DC current gain (hfe) is 40 to 160

To the collector of BD139 is added the load (solenoid or water pump) through supply voltage.

When BD139 conducts , it switches ON the solenoid.

A diode 1n4007 is used across the coil of solenoid.

A    FLY BACK Diode is placed with reverse polarity from the power supply and in parallel to the relay’s inductance coil. The use of a diode in a relay circuit prevents huge voltage spikes from arising when the power supply is disconnected. A flyback diode is sometimes called flywheel diode, relay diode, or snubber diode as a flyback diode circuit is a type of snubber circuit.

The solenoid used for water tap is the one widely used in water coolers.

Normal working voltage is 24v DC , but it works fine on 12v.

Image 5

 

The valve features a solenoid, which is an electric coil with a movable ferromagnetic core (plunger) in its center. In the rest position, the plunger closes off a small passage. An electric current through the coil creates a magnetic field. The magnetic field exerts an upwards force on the plunger opening the passage.

This is the basic principle that is used to open and close solenoid valves.

The hole size of 1/4 , 1/2 inches available.

Smaller size ones used for sanitizer dispenser and the bigger ones for water tap.

Instead of solenoid you can replace with a pump motor also.

Image 6

This is a low cost, small size Submersible Pump Motor which can be operated from a 2.5 ~ 6V power supply. It can take up to 120 liters per hour with very low current consumption of 220mA. Just connect tube pipe to the motor outlet, submerge it in water and power it. Make sure that the water level is always higher than the motor. Dry run may damage the motor due to heating and it will also produce noise.

The final circuit requires a 12v supply .

The IR module used here is sensitive to Sun Light.So always cover the IR LEDs with a black sleeve or tape and adjust sensitivity by turning the blue trimpot.

When hand is brought near the IR circuit , it sends a LOW signal to OPTO coupler.

This conducts the BD139 and in turn operates the solenoid or pump.

 

IMG_20200505_171041

 

VIDEO :

blog_image

CAN – Controller Area Network bus is widely used in Automobile industry and in other industrial applications.

CAN  is like Nervous system in Human body facilitating communication between all parts of body.

In CARs , NODEs or ECUs – Electronic Control Units are connected via CAN bus which acts as a control nervous system.

ECUs can be Engine control unit, Airbag control, Audi System , Door position,Brake system, Sensors & others.Each and every function can be assigned a NODE or ECU.

A modern CAR has upto 100 ECUs.

CAN_CAR

 

CAN allows ECUs to communicate with each other without complex dedicated wiring in between.

Any ECU can communicate with entire system without causing overload to the controller computer.

 

Image 2

 

CAN is MULTI MASTER setup.Any Node can be a MASTER.

CAN works on a MESSAGING TYPE SYSTEM & no slave address is used to communicate with a node.

Every Node receives the message and the related data will be conceived by the receiver node.

It is like public announcement system in  an Airport.Only concerned passengers will take the message.

To balance the CAN BUS and for noise reduction a 120E RESISTOR is used as Terminator.This is must for END NODES. Nodes added in between need not use this Resistor.

In this project we make use of a CAN Board CAN2515.

This board has 2 ICs.  One is the CAN Controller MCP2515 , which communicates with Arduino or any MCU by SPI Protocol.

MCP2515 gives SINGLE ENDED DIGITAL signal (High ,Low).

can2515_se

 

TX-CAN & RX-CAN are at digital levels and are connected to another IC , a TRANSCEIVER.

Here the Transceiver used is TJ1050 . Microchip MCP 2551 is also a transceiver , generally used with Microcontrollers which have inbuilt CAN Controllers.For e.g ESP32 module has in built controller , but it needs TRANSCEIVER like MCP2551 or TJ1050 .Do not confuse with the numbers

2515 IS CONTROLLER , 2551 IS TRANSCEIVER.

TJ1050 receives Digital signal from CAN2515 and converts tp DIFFERENTIAL SIGNAL acceptable on CAN BUS.

Note the connection between TJA1050 and CAN 2515 .

TX-CAN to TXD ,  RX-CAN to RXD ( not reversed).

The module we use has both ICs on board and we need not care about this connection.

 

Image 4

The CAN Message format is as below :

Image 1

The CAN-ID may be 11 bit or 29 bit.

11 BIT can addresses 2048 nodes ( 2 power 11) hex 0x000 to 0x7FF

29 bit Extended can up to 536 million.

DAT length allowed is max 8 BYTES or 64 bits.

To learn more about CAN Message visit here

Following picture shows the Differential signal level of CAN.

Image5

 

When no information is on BUS , both CAN-H & CAN-L are at half the supply volt  (here 2.5 volt on a 5v system).

This is RECESSIVE State or BIT 1.

When CAN-H goes to 5v and CAN-L to 0 v , it is DOMINANT State or BIT 0.

 

To start with the project , connect a potentiometer ( center pin) to A0 of Arduino.

One end of pot is connected to 5v and other end to Gnd.

The CAN board connections are as shown SPI connections between Arduino and CAN board.

 

Image22

 

Before starting we need a good Library for CAN to work with.

SEEED Studio has a Library which works fine with their Shield.

Also a modified version on it is available from Cryjfowler.

I prefer to use one from AUTOWP

arduino-mcp2515

which uses STRUCT  for message sending.This is very simple and easy to use.

 

Image13

 

Please note , the Seed studio library and that of coryjfowler both have the same header file name mcp_can.h. If you install both these libraries , then there is clash on object declarations arising errors.Use any one only.

In this demo we use arduino-mcp2515 library.Download it as ZIP file.

CAN library

https://github.com/autowp/arduino-mcp2515

From Arduino IDE   Sketch –> Include Library –> Add ZIP Library

and browse to the location of the downloaded library.Select it to install.

It will be copied to Documents/Arduino/Libraries

On the Receiver side we use an I2C LCD.

The library for the same can be downloaded and installed from :

i2c library :

https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library

 

ARDUINO CODE used in this project can be downloaded from :

http://www.alselectro.com/files/CAN_2515.zip

 

Following picture shows the Transmitter side connections.

Potentiometer to A0 of Arduino , CAN board to SPI connections.

 

IMG_20200428_113532

The code for the Transmitter side is :

tx

 

Here we include the mcp2515.h header file.

We create an un initialized struct can_frame variable called canMsg.

can_frame is the STRUCT Type name

canMsg is the Variable name.

Data members of struct is assigned using dot operator.

As seen from the library documentation , there are 3 members , can_id , can_dlc & data[].

 

Image 3

mcp2515 object is initiated from class MCP2515 by passing the CS pin chip select pin 10 , as argument.

MCP2515 mcp2515(10);

Under set up we call the functions of object mcp2515

First reset() function is called.

Then setBitrate()  to set the CAN spped at 500KBPS & frequency 8 MHZ.

setNormalMode() to set the module function in Normal mode.

 

mcp2515.reset();
mcp2515.setBitrate(CAN_500KBPS,MCP_8MHZ);

  mcp2515.setNormalMode();

 

Using dot operator the members to STRUCT are added.

can_id is HEX ID which is user given.You can provide your own id in HEX.

can_dlc is the length of data.Maximum 8 BYTES allowed.Here we give data length as only one BYTE.

Under loop() , the analog pot value is mapped to value between 0 – 255

and the data sent over CAN bus using sendMessage() function of mcp2515.

 

Following is the Receiver side connection picture.

I2C LCD has 2 pins apart from Vcc & Gnd

SDA is connected to A4 ,  SCL is connected to A5.

 

IMG_20200428_113556

 

The CAN board of Tx is connected to CAN board of Rx

CAN_H to CAN_H

CAN_L to CAN_L

Generally a twisted pair wire with shield is used.The shield is connected to GND.

Max length of 40 mtrs can be used.

 

Following is the Receiver side code :

rx

 

Here we include the I2C LCD header.

While creating lcd object we pass on the I2C address and the size of LCD ( 16 X 2)

To know the I2C address you can use  i2c scanner from here

Under void loop

we use the readMessage() function of mcp2515 to verify the incoming message

& then we compare the id , then extract the message to display on LCD.

 

IMG_20200428_123314

 

More sensors can be added to the project.

A LM35 temperature sensor at A3 and a Door ON/OFF switch can be added at D6.

SENSORS_CAN

 

ARDUINO CODE used in this project can be downloaded from :

http://www.alselectro.com/files/CAN_2515.zip

 

IMG_20200428_151048

video  :

 

 

blog_image

For HOME AUTOMATION project we use a 4 channel Relay board of 5v Relays.

This is LOW enabled , a LOW at input makes the RELAY ON.

So on start up these input pins must be pulled HIGH.

NodeMCU is loaded with ESPEASY FIRMWARE . You can check this post on how to load.

The Relay board requires a separate power source of 5 volt.

The GND of 5v supply to be made common with the GND of Nodemcu.

RELAY BOARD   NODEMCU

IN1     ——- GPIO 16

IN2     ——- GPIO 14

IN3    ——- GPIO 12

IN4    ——- GPIO 13

 

 

hat

 

DOMOTICZ Service is running on Raspberry PI which is on the same LAN as my PC.

The Domoticz server is accessed by typing in the RPI’s IP address followed by port no. 8080

192.168.0.150:8080

Click on Setup – > Hardware and create Type DUMMY for Relay 1 , name it as RL1.Click ADD

Same way create 3 more Type Dummy for other 3 Relays RL2, RL3 & RL4.

Image 10

 

 

Image 12

On top a list of Types created is displayed.

 

Image 8

Click on Create Virtual Sensor for RL1.

Image 15

Select Sensor type as SWITCH and name it as RL1.

Image 13

Similarly create Sensor type Switches for other 3 ,  RL2,RL3 & RL4

Image 14

Under setup –> Devices all the 4 switches are listed out with INDEX (IDX) numbers.

Note these IDX numbers , as we have to set the same IDX number in ESPEASY Setup.

Image 9

Under SWITCHES tab you can see the VIRTUAL SWITCHES created.

Image 3

Click on EDIT button on RL1

Switch ICON is a bulb by default.You can select any one from the drop down list.

Under ON Action feed in the IP address of ESPEASY with HTTP command

http//192.168.0.110/control?cmd=gpio,16,0

Note the usage of 0 for ON , as the relay board is LOW enabled.

Against OFF action

http://192.168.0.110/command?cmd=gpio,16,1

Click SAVE

Image 4

Same way click on other Relay switches EDIT button and feed in the HTTP command including the correct GPIO number.

 

Image 5

 

Image 6

 

 

Image 7

Once the HTTP commands are saved , you can go to ESPEASY Dashboard by typing in the IP address on browser.

Here mine is 192.168.0.110

 

Under CONTROLLERS select the protocol as DOMOTICZ HTTP

Provide the IP address of DOMOTICZ and its port no. 8080

Click ENABLED.

Image 7

 

Under HARDWARE make the GPIO pins used to OUTPUT HIGH on Boot.

As the RELAY Board is LOW enabled , this is necessary.

GPIO16 by default is HIGH on Boot , so there is no settings for GPIO 16.

Image 8

 

Under DEVICES select the DEVICE as SWITCH INPUT – SWITCH

Provide a name RL1

Click ENABLED.

RL1 is connected to GPIO 16 , select it.

Provide the IDX number as 1.

Internal pull up is similar to OUTPUT HIGH , not needed for GPIO 16.

Image 2

 

As done for RL1 repeat for other relays

RL2 –GPIO14 , iNTERNAL PULL UP –Yes, IDX 2

Image 3

 

Image 4

RL3 –GPIO12 , iNTERNAL PULL UP –Yes, IDX 3

Image 5

RL2 –GPIO13 , iNTERNAL PULL UP –Yes, IDX 4

Image 6

 

Now all the settings are done.

Image 1

Go to DOMOTICZ Dashboard and click on SWITCHES tab.

From here you can Switch ON OFF the relays and the load connected to it.

 

Image 11

VIDEO :

 

blog_image

DHT11 module can sense both Temperature and Humidity data.

As a module it has 3 pins .Vcc can be connected to 3.3v , as it can work with 3.3v.

Gnd to Gnd.

Data pin is connected to GPIO 13.

DHT_ESP

DOMOTICZ service is running on Raspberry PI which is on the same WIFI network as my PC.

 

rpi8

 

Domoticz Dashboard can be accessed from a browser by typing in the address followed by port number

192.168.0.150:8080

 

Image 3

Click on Setup –> Hardware

Select Type as DUMMY and provide a name

Image 4

 

Image 5

When you click ADD it appears on the list.

Image 6

Click on Create Virtual Sensors

Select Sensor Type as Temp+Hum

ans provide a name.

Image 7

 

Image 8

 

Click on OK .

The Virtual Sensor is visible under TEMPERATURE tab.

 

Image 11

If you want a description to be added , click on Edit and add description.

 

Image 12

 

Now go to ESP EASY by typing in the IP address 192.168.0.110

Under Controllers select protocol DOMOTICZ HTTP.

Image 13

Provide the IP address of DOMOTICZ Service and the port number.

Click Enabled.

Image 15

 

Under Devies click ADD.

Image 16

Select a device Environment DHT11

Image 17

 

Click Enabled and select the GPIO pin as GPIO 13.

 

Image 18

Interval is the REFRESH rate of DHT11.

DHT11 has a refresh rate of 1 sec , meaning every second it can send out data.

On DOMOTICZ Virtual Sensor you can see the display of Temperature and Humidity.

Image 20

video :

 

blog_image

In the previous post we installed ESPEASY over NODEMCU.

This post is on controlling an LED connected to GPIO 12 of NODEMCU from DOMOTICZ Service.

 

LED_NODE

 

My Raspberry PI and PC both are on same Local Area Network , i.e connected to same WIFI Router .

Domoticz is installed on RPI

 

rpi1

 

 

Image 21

The IP address of RPI connected to the Router over WIfI is 192.168.0.150 & the DOMOTICZ dashboard is accessed by URL

192.168.0.150:8080

 

rpi7

 

On Domoticz dashboard click on Setup –> Hardware

 

Image 28

 

Create a Type  “Dummy “ (select from the drop down list) and provide a name as LED.

Image 29

 

Click on ADD

 

Image 30

Now click on  “ Create Virtual Sensors “

Image 31

Select a Sensor type as SWITCH and provide a name.

 

Image 32

 

The Virtual Switch is visible under SWITCHES tab.

Image 33

Click on EDIT

Against On Action , type in this HTTP command

http ://192.168.0.110/control?cmd=gpio,12,1

192.168.0.110  is the IP address of ESPEASY NODEMCU.

LED is at gpio12 & 1 for switching ON , 0  for Switching Off.

Image 34

Now go to the dashboard of ESPEASY by typing in 192.168.0.110 in the browser.

Under Controllers select a Protocol Domoticz HTTP

Provide the IP address of DOMOTICZ and the port no. as 8080

Click on Enabled & Submit.

Image 35

Under Devices select from the drop down Switch Input –Switch

Provide a Name and click Enabled.

Select the GPIO as GPIO 12.

Image 36

Click on SUBMIT.

Now you can switch On / Off the LED by clicking bulb icon on Domoticz.

 

Image 3

VIDEO:

 

blog_image

ESP EASY IOT OS ON NODEMCU

Video :

 

ESP module can be turned into an IOT MULTIFUNCTION Sensor device by  installing  ESP EASY Firmware on to the module.

For HOME AUTOMATION projects it suits well and can be easily controlled from application servers like DOMOTICZ.

Configuration of the ESP EASY is entirely web based , so once the firmware is loaded , you just need a common web browser to work with.

Older version of ESP EASY is R120. Mega is the newer version.

https://github.com/letscontrolit/ESPEasy/releases

documentation :

https://espeasy.readthedocs.io/en/latest/

 

supported Hardware ESP modules :

https://www.letscontrolit.com/wiki/index.php?title=ESP_Hardware

The NodeMCU or WeMOS D1 mini are recommended , as they have inbuilt USB.

Sensors supported :

https://www.letscontrolit.com/wiki/index.php?title=Devices

Only the list of sensors are supported.You need not write any code separately for sensors.Just connect the Sensor and configure on Dash board. Display or control it from DOMOTICZ over HTTP or MQTT protocols.

Download the MEGA version of ESP EASY.

Under dist folder Flasher application is provided.Double click on that.

Image 1

 

Select the COM port where Nodemcu is connected.

Before selecting a .bin firmware file click on the update button.

Latest .bin files will be downloaded from Github repository.

 

Image 2

Select the relevant .bin file for your hardware.Here I’m selecting ESP8266 4MB version, as my hardware is NODEMCU with 4096 flash memory.

Test beta version supports Nextion display hardware.

Image 3

Setting of WIFI & fixed IP can be done later. For now Flash ESP EASY.

It takes approx 2 minutes to upload.

 

Image 5

Once uploaded , close the flasher and reset Nodemcu.

It starts in AP mode and the WI FI access point name is ESP_EASY.

Connect your PC to this AP using password  configesp

When a fresh ESP Easy module boots up, it has no Wifi config and it will start as an Access Point.

Use a Wifi enabled device (Laptop, Smartphone,..) to search for Wifi access and try to find an access point with the name ESP_Easy.

Connect to this access point with default password:

configesp

 

Image 6

 

Once connected , open your browser and type in ip address   192.168.4.1

You should get a  welcome screen:

Select your SSID and provide password.Click on CONNECT .

Now your NodeMcu connects with your SSID.

If the connection succeeded, you will see a screen, listing it’s new local IP address.

You can now reconnect your laptop or other device back to your private Wifi network.

Then click the “proceed” link to contact the ESP module on it’s private IP address:

Image 7

ESP EASY Nodemcu is offered an IP ADDRESS by your Router.

Use this address on a browser to access the DASHBOARD of ESP EASY.

Under MAIN tab is the SYSTEM INFO.

Image 8

 

Click on CONFIG tab.

Here you can change the AP password from configesp , if you need.

At the bottom is the IP Settings.

You can provide an IP address to make it STATIC.

The IP Address must be in the range of your Gateway IP.

Gateway IP is the IP of your ROUTER.When any client connects with the Router , it provides an IP address by its DHCP method.This IP will be in range of Gateway IP , only the last octet changes.

Finally click SUBMIT to effect changes.

Image 9

Next tab is CONTROLLERS tab.

Under this you select a PROTOCOL .

HTTP,MQTT,UDP all are supported.

In this demo we control an LED from browser commands.So select STANDALONE.

 

Image 10

Under HARDWARE tab you can set any GPIO pin to be High or Low on Boot up.

It is not needed in this demo , so we move on to next tab DEVICES.

Click on ADD from the list of devices.

Select SWITCH INPUT – SWITCH from the drop down.

Provide a name , like LED and then click the ENABLED .

Under GPIO , select GPIO 12 (D6) where we’ve connected an LED.

Click on SUBMIT.

Image 11

Now from your browser use this command to control LED.

Image 12

 

Image 13

Instead of GPIO you can use PWM to control brightness of LED.

gpio, pwm can be in small or capital letters.

Image 14

 

blog_image

 

title_h

DHT11 humidity and temperature sensor is available as a sensor and as a module. The difference between this sensor and module is the pull-up resistor and a power-on LED.

DHT11 is a relative humidity sensor.  To measure the surrounding air this sensor uses a thermistor and a capacitive humidity sensor.For measuring temperature this sensor uses a Negative Temperature coefficient thermistor, which causes a decrease in its resistance value with increase in temperature.

The temperature range of DHT11 is from 0 to 50 degree Celsius with a 2-degree accuracy. Humidity range of this sensor is from 20 to 80% with 5% accuracy. The sampling rate of this sensor is 1Hz .i.e. it gives one reading for every second.  DHT11 is small in size with operating voltage from 3 to 5 volts. The maximum current used while measuring is 2.5mA.

DHT11 sensor has four pins- VCC, GND, Data Pin and a not connected pin. A pull-up resistor of 5k to 10k ohms is provided for communication between sensor and micro-controller.As amodule it has only 3 pins , pull up resistor provided on board.

Connect DATA pin of DHT11 to D2 of Arduino , Vcc to 5v & Gnd to Gnd.

Open NEXTION EDITOR and start a new project with .HMI file name.

Generate a FONT file and add to the project.

Click on Picture tab at bottom left corner and then + symbol to import a back ground picture.This picture resolution must match that of your NEXTION model

In this demo I’m using 4024T032 ( 400 X 240 pixel 3.2 inch size)

Use IRFANVIEW or INKSCAPE to match the resolution 400 x 240 of the image.

Click on PICTURE tool .It appears p0 on canvas.

At the right side window you can set the attributes for this object.Leave the object name as p0.

Click browse against pic attribute and select the image to be loaded as back ground.

Now the image appears on canvas.

Image 12

Add 2 TEXT objects  .One for Temperature and the other for Humidity.

As Nextion editor cannot handle fraction numbers , we use Text instead of Number object.

Following are the attribute settings for these 2 Text objects.

t0 objname can be changed to Temperature

vscope to global.All objects that is controlled through SERIAL to be set to global.

sta attribute by default is solid color.Change this to crop image.

Also select the browse against picc attribute and select the back ground image.

This creates a Transparent effect to the object.

Text color can be changed by the pco attribute. 65535 means White & 0 means Black.

You can click on Select against pco to select a color.

Same way repeat for the t1 object Humidity.

Image 13              Image 15

 

Next add on 4 more Text objects for display purpose.You need to change the txt attribute to change the display name .

txt – to change display name

pco – to change color of text.

sta -crop image  to give transparent effect so that background image is visible through this object.

Image 16

Click on DEBUG to start the Simulator.

You can test the display by sending STRING Commands.

temperature.txt=”32.0”

changes the Temperature display to 32.0.

Note the usage of double quotes for data to be displayed.While typing the code the interpreter of Nextion editor gives options to select (intellisense).

The commands can be sent as STRING from Arduino and to be followed by 3 bytes of 0xFF.

 

Image 17

Upload the following sketch on to Arduino.

Here we use the library for DHT Sensor by including the header file DHT.h

We define the DHT data pin connection as 2 (D2 of Arduino) and type as DHT11.

The variables temperature and humidity are initialized with float literal constants.

Reading of sensor is by calling functions readHumidity()  & readTemperature() from the Class dht.

The assigned data is sent to Nextion as a STRING command.

Image 1

 

Sending data.
Data to Nextion should be sent in the following format:

    • String command

=”humidity.txt=\””+String(humidity,1)+”\””;

  • name of the receiving element     humidity
  • sign “.”
  • field name of the receiving element    txt
  • sign “=”
  • data, and if it is String, then in quotation marks, and if it is digital information, then four bytes of data
  • three bytes 0xff
    Notice the use of ESCAPE character backslash \ before double quote “.
    This is how to send double quotes from Arduino Serially.

Nextion does not work with float. So all to be sent as – String

 

To upload the .tft file on to Nextion we use USB-TTL device.Connect Nextion to USB-TTL

Tx to Rx

Rx to Tx

Gnd – Gnd

5v to 5v

Click on UPLOAD button and select the COM port of USB device and a faster baudrate.

Once uploaded , remove USB device and connect Arduino with Nextion with same configuration as above.

The result is displayed on NEXTION DISPLAY.

The DHT sensor requires 1 second refresh rate for each reading.This is provided by 1 sec delay in Arduino code.

VIDEO :

 

blog_image

 

This post is on displaying potentiometer reading from Arduino to Nextion display.

 

IMG_20200413_180125

 

Open Nextion Editor and File –> New  to create a project file with extension .hmi

Always keep your project files in a separate folder.

In the next screen select your Nextion model display , mine is 4024T032 which is 400 x 240 pixel & 3.2 inch size Basic model.Also select the direction of display as Horizontal.

 

Image 1

Using Fonts Generator create a font file by selecting font size and font type.It is saved as .zi file.Click Yes to add font file to project.

The font file appears under font tab.

Image 3

Next to Fonts tab you see a Picture tab.

Click on that and then click on the + symbol seen on top f this window.

Browse to the location of the background image you want to import.

Remember the image must match the resolution of the display model.Here mine is 400 x 240 , so I’ve converted the image to 400 x 240 pixels using IRFANVIEW Software.

 

Image 4

Drag PICTURE tool from toolbox on to canvas or just click on Picture under tool box.

Picture component appears on canvas as p0 object name.

Click on that p0 , to modify attributes for object p0.

Against pic attribute click on browse and select the background picture from the list.

The back ground image appears on workspace canvas.

Image 6

 

Click on  SLIDER tool and then a NUMBER.

Slider appears as object h0   & number appears as object n0.

You may rename it from attribute section.But we shall leave it to default names.

 

Image 1

Following is the attribute window for the object h0.

The mode by default is Horizontal , if required can be changed to Vertical.

Color of the slider by default is Green , by clicking against bc0 attribute and select color , you can change it. pc0 is the color of slider knob, Red by default & can be changed.

Set the maxvalue to 1023 , as Analog read of Arduino ranges from 0-1023.

Image 2 - Copy

n0 Number attributes

bc0 , pc0 to change color of number.

vscope can be changed from local to global. If global it is available for all pages and if you control it from Arduino through Serial , make it GLOBAL.

 

Image 26

 

Click on DEBUG to start the Simulator.

Under simulator you can feed in the code to change value of n0 object.

n0.val=524 will change the n0 value to 524.

 

Image 3

Close the Simulator.

Now to upload the .tft file (after Compile you get this file)  on to Nextion , we use a USB-TTL device.

Connect Tx of Usb device to Rx of Nextion , Rx to Tx , Gnd to Gnd and Vcc to 5v.

 

IMG_20200414_155643

Plug in usb device to pc and note the COM port allotted to it.

Click on UPLOAD,

Select COM port and baud rate & click GO.

Image 21

To Arduino we have to upload the following sketch.

Image 6

 

analogRead of A0 pin where pot pin is connected is assigned to a integer variable value.

A string  n0.val is sent to serial along with this value .

The string is followed by 3 times 0xff hex value.This is the standard format Nextion will accept on its Serial.

Do not use any other Serial commands here.For e.g if you use Serial.println() , then Nextion will not display the value.

Once sketch is uploaded on to Arduino , connect Arduino to Nextion

Tx to Rx, Rx to Tx , 5v to 5v , Gnd to Gnd

Potentiometer Center pin to A0, one end of pot to +5v and other end to Gnd.

Now turning the potentiometer will vary the number on Display from 0 to 1023.

 

IMG_20200413_180125

Now let us modify the Arduino code so that Slider moves according to number value.

Serial.print(“click n0,1);

click n0,1 means  activate Press Event of object n0

upload this code on to Arduino.

Image 10

Now on Nextion Editor  click on n0 number object.

Under Touch Press Event feed in

h0.val=n0.val

The touch press event is activated by Arduin code , as if we were physically touching n0.

Now the event code is triggered where we assign value of slider to be same as value of number.

 

Image20

compile and upload the file to Nextion using USB-TTL.

Image34

Connect Nextion with Arduino nd see the result.

On varying the potentiometer the number value changes from 0 to 1023 .Accordingly the slider changes position.

Image 5

VIDEO :

 

 

 

blog_image