programming – Blog eTechPath https://blog.etechpath.com Sun, 23 Apr 2023 21:03:56 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.3 https://blog.etechpath.com/wp-content/uploads/2017/08/BrandLogo12-150x150.png programming – Blog eTechPath https://blog.etechpath.com 32 32 DIY Weighing Scale using HX711, OLED i2c display and ESP8266 NodeMCU with Zero Calibration Function https://blog.etechpath.com/diy-weighing-scale-using-hx711-oled-i2c-display-and-esp8266-nodemcu-with-zero-calibration-function/ https://blog.etechpath.com/diy-weighing-scale-using-hx711-oled-i2c-display-and-esp8266-nodemcu-with-zero-calibration-function/#respond Sun, 23 Apr 2023 21:03:26 +0000 https://blog.etechpath.com/?p=1254 Introduction:

In this tutorial you will learn how to interface HX711 loadcell amplifier module with ESP8266 NodeMCU board and getting output on i2c OLED display. Also, we will learn how to add zero push button function to adjust scale offset.

Loadcell:

Load cell is a sensor which converts mechanical force into electronic signal. Where the mechanical force can be tension, pressure, compression or torque. There are many types of load cells are available in the market which can be used as per required application. In this example we are going to use strain gauge load cell for converting mechanical force into electrical signal.

Loadcell consist of several resistive strain gauge sensor elements which changes its resistance when the load is applied and gives output in milli volts when input or excitation voltage is applied to it.
This milli volt output is then amplified to voltage signal to make it compatible with controllers to read and convert to load units.

Things You Will Need:

  • ESP8266 NodeMCU
  • HX711 Amplifier Board
  • 10kg Loadcell
  • i2c OLED Display
  • Connecting Cables

Circuit Diagram:

Code:

Example 1: ln this example we will use Arduino IDE serial monitor window to get output values from the loadcell.

/**
 *
 * Interfacing 10kg loadcell and HX711 amplifier board with ESP8266 NodeMCU
 * Author: Pranay Sawarkar
 * Website: www.eTechPath.com
 * Link: https://blog.etechpath.com/diy-weighing-scale-using-hx711-oled-i2c-display-and-esp8266-nodemcu-with-zero-calibration-function/
 * 
 *
**/

#include <Arduino.h>
#include "HX711.h"

// HX711 circuit wiring
const int Dout_Pin = 14;
const int SCK_Pin = 12;
const int pb1 = 13;            //push button input 
int tarepb = 0;
int newread = 0;
#define CalFactor 235.5    //enter your calibration factor here

HX711 scale;

void setup() {
  Serial.begin(115200);
  scale.begin(Dout_Pin, SCK_Pin);
  pinMode(pb1, INPUT_PULLUP);
  
  Serial.println("Initialization..."); 
  
  scale.set_scale(CalFactor);
  scale.tare();
  delay (200);
  Serial.println("Ready");
  delay (100);
}

void loop() {
  
  tarepb = digitalRead(pb1);
  delay(10);
  if (tarepb == LOW) 
  {
    scale.tare();
    Serial.println("TareDONE");
  }
  else
  { 
  newread = scale.get_units(5);
  Serial.println("Weight: ");
  Serial.println(newread);
  delay(10);
   }
}

Circuit Diagram:

Example 2: In this example we will interface oled display with the existing circuit and print loadcell output values on display.

/**
 *
 * DIY Weighing Scale using HX711, OLED i2c display and ESP8266 NodeMCU with Zero Calibration Function
 * Author: Pranay Sawarkar
 * Website: www.eTechPath.com
 * Link: https://blog.etechpath.com/diy-weighing-scale-using-hx711-oled-i2c-display-and-esp8266-nodemcu-with-zero-calibration-function/
 * 
 *
**/

#include <Arduino.h>
#include <U8g2lib.h>
#include "HX711.h"

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

//select your oled display size
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

// HX711 circuit wiring
const int Dout_Pin = 14;
const int SCK_Pin = 12;
const int pb1 = 13;
//const int pb2 = 5;
int tarepb = 0;
int newread = 0;
#define CalFactor 235.5

//235.5


HX711 scale;

void setup() {
  Serial.begin(115200);
  u8g2.begin();
  scale.begin(Dout_Pin, SCK_Pin);
  pinMode(pb1, INPUT_PULLUP);
  
  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.drawStr(0, 20, "Initializing...");
  u8g2.sendBuffer();
  
  scale.set_scale(CalFactor);
  scale.tare();
  delay (500);
  u8g2.clearBuffer();
  u8g2.drawStr(0, 20, "Ready");
  u8g2.sendBuffer();
  delay (100);
 
}

void loop() {
  
  tarepb = digitalRead(pb1);
  delay(10);
  if (tarepb == LOW) 
  {
    scale.tare();
    u8g2.clearBuffer();
    u8g2.drawStr(0, 20, "Tare Done");
    Serial.println("TareDONE");
    u8g2.sendBuffer();
  }
  else
  {
  
  newread = scale.get_units(5);
  Serial.println(newread);
  delay(10);

      u8g2.clearBuffer();
      u8g2.setFont(u8g2_font_6x10_tf);
      u8g2.drawStr(0, 20, "Weight: ");
      u8g2.setCursor(45, 20);
      u8g2.print(newread);
      u8g2.sendBuffer();
      delay(10);
    
   }
}

Prototype:

]]>
https://blog.etechpath.com/diy-weighing-scale-using-hx711-oled-i2c-display-and-esp8266-nodemcu-with-zero-calibration-function/feed/ 0
DIY OLED Weighing Scale using 10kg Loadcell with HX711 and Arduino Uno https://blog.etechpath.com/diy-oled-weighing-scale-using-10kg-loadcell-with-hx711-and-arduino-uno/ https://blog.etechpath.com/diy-oled-weighing-scale-using-10kg-loadcell-with-hx711-and-arduino-uno/#respond Fri, 21 Apr 2023 13:00:06 +0000 https://blog.etechpath.com/?p=1240 Introduction:

In this tutorial you will learn how to interface HX711 loadcell amplifier board with Arduino uno and getting output on i2c oled display. Also, we will learn how to add calibration push button to zeroing the scale.

Loadcell:

Load cell is a sensor which converts mechanical force into electronic signal. Where the mechanical force can be tension, pressure, compression or torque. There are many types of load cells are available in the market which can be used as per required application. In this example we are going to use strain gauge load cell for converting mechanical force into electrical signal.

Loadcell consist of several resistive strain gauge sensor elements which changes its resistance when the load is applied and gives output in milli volts when input or excitation voltage is applied to it.
This milli volt output is then amplified to voltage signal to make it compatible with controllers to read and convert to load units.

Things You Will Need:

  • Arduino Uno
  • 10kg Loadcell
  • HX711 ADC amplifier board
  • i2c OLED display

Circuit Diagram:

Code:

Example 1: In this example we will use arduino serial window to get output values from the loadcell.

/**
 *
 * Interfacing 10kg loadcell and HX711 amplifier board with Arduino Uno
 * Author: Pranay Sawarkar
 * Website: www.eTechPath.com
 * Link: https://blog.etechpath.com/diy-oled-weighing-scale-using-10kg-loadcell-with-hx711-and-arduino-uno/
 * 
 *
**/

#include <Arduino.h>
#include "HX711.h"

// HX711 circuit wiring
const int Dout_Pin = 2;
const int SCK_Pin = 3;
const int pb1 = 4;
int tarepb = 0;
int newread = 0;
#define CalFactor 235.5    //enter your calibration factor here

HX711 scale;

void setup() {
  Serial.begin(115200);
  scale.begin(Dout_Pin, SCK_Pin);
  pinMode(pb1, INPUT_PULLUP);
  
  Serial.println("Initialization..."); 
  
  scale.set_scale(CalFactor);
  scale.tare();
  delay (200);
  Serial.println("Ready");
  delay (100);
}

void loop() {
  
  tarepb = digitalRead(pb1);
  delay(10);
  if (tarepb == LOW) 
  {
    scale.tare();
    Serial.println("TareDONE");
  }
  else
  { 
  newread = scale.get_units(5);
  Serial.println("Weight: ");
  Serial.println(newread);
  delay(10);
   }
}

Circuit Diagram:

Example 2: In this example we will interface oled display with the existing circuit and print loadcell output values on it.

/**
 *
 * DIY Weighing scale using 10kg loadcell and HX711 amplifier board with Arduino Uno and OLED display
 * Author: Pranay Sawarkar
 * Website: www.eTechPath.com
 * Link: https://blog.etechpath.com/diy-oled-weighing-scale-using-10kg-loadcell-with-hx711-and-arduino-uno/
 * 
 *
**/

#include <Arduino.h>
#include <U8g2lib.h>
#include "HX711.h"

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

//select your oled display type and size
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

// HX711 circuit wiring
const int Dout_Pin = 2;
const int SCK_Pin = 3;
const int pb1 = 4;
int tarepb = 0;
int newread = 0;
#define CalFactor 235.5   //enter your calibration factor here

HX711 scale;

void setup() {
  Serial.begin(115200);
  u8g2.begin();
  scale.begin(Dout_Pin, SCK_Pin);
  pinMode(pb1, INPUT_PULLUP);
  
  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.drawStr(0, 20, "Initializing...");
  u8g2.sendBuffer();
  
  scale.set_scale(CalFactor);
  scale.tare();
  delay (500);
  u8g2.clearBuffer();
  u8g2.drawStr(0, 20, "Ready");
  u8g2.sendBuffer();
  delay (100);
 
}

void loop() {
  
  tarepb = digitalRead(pb1);
  delay(10);
  if (tarepb == LOW) 
  {
    scale.tare();
    u8g2.clearBuffer();
    u8g2.drawStr(0, 20, "Tare Done");
    Serial.println("TareDONE");
    u8g2.sendBuffer();
  }
  else
  {
  
  newread = scale.get_units(5);
  Serial.println(newread);
  delay(10);

      u8g2.clearBuffer();
      u8g2.setFont(u8g2_font_6x10_tf);
      u8g2.drawStr(0, 20, "Weight: ");
      u8g2.setCursor(45, 20);
      u8g2.print(newread);
      u8g2.sendBuffer();
      delay(10);
    
   }
}

Prototype:

]]>
https://blog.etechpath.com/diy-oled-weighing-scale-using-10kg-loadcell-with-hx711-and-arduino-uno/feed/ 0
Interfacing SHARP 2Y0A21 Distance Sensor with Arduino https://blog.etechpath.com/interfacing-sharp-2y0a21-distance-sensor-with-arduino/ https://blog.etechpath.com/interfacing-sharp-2y0a21-distance-sensor-with-arduino/#respond Tue, 21 Feb 2023 08:44:53 +0000 https://blog.etechpath.com/?p=1201 Introduction:

In this tutorial, I will explain how to interface SHARP 2Y0A21 infrared distance sensor with Arduino board and display the output in serial monitor.

SHARP 2Y0A21

SHARP 2Y0A21 sensor works on infrared technology, it consists of a transmitter and a receiver diode which calculates the distance between the sensor and the target by measuring time interval between transmitted and received wave.

SHARP infrared distance sensor
SHARP 2Y0A21 Sensor Specifications:
  1. Working voltage: 4.5 – 5.5 Vdc
  2. Distance measuring range: 10cm – 80cm (10cm dead band)
  3. Output type: Analog (voltage)
  4. Output: 0 to 3.1v (3.1v at 10cm to 0.3v at 80cm)
  5. Operating Temperature: -10 to +60 °C (Storage: -40 to +70 °C)

Circuit Diagram:

Code:

//SHARP 2Y0A21 IR Distance Sensor Test (10-80cm) 
// Author: Pranay Sawarkar
// www.eTechPath.com

#define sensor A2 

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{
  float volts = analogRead(sensor)*0.0048828125;
  int distance = 30*pow(volts, -1.173);
  delay(1000); 
  
  if ((distance >=10)&&(distance <=80))
  {
    Serial.print("Distance:");
    Serial.println(distance);
    Serial.print("Volts:");
    Serial.println(volts);   
  }
  else
  Serial.println("Out of range");
}
]]>
https://blog.etechpath.com/interfacing-sharp-2y0a21-distance-sensor-with-arduino/feed/ 0
How to flash USB bootloader in STM32 black-pill board to program it with Arduino IDE https://blog.etechpath.com/how-to-flash-usb-bootloader-in-stm32-black-pill-board-to-program-it-with-arduino-ide/ https://blog.etechpath.com/how-to-flash-usb-bootloader-in-stm32-black-pill-board-to-program-it-with-arduino-ide/#comments Mon, 12 Nov 2018 10:59:39 +0000 https://blog.etechpath.com/?p=665 About:

STM32 is a 32bit ARM cortex microcontroller and normally we need USB to TTL module or ST-link stick to dump program to its memory. So, here in this project i will teach you how to flash USB bootloader in STM32 microcontroller so that we can program it with direct USB port from Arduino IDE.

Things you will need:

  1. STM32 board. (Black pill or Blue pill)

2. USB to serial converter ( TTL module) (3.3v compatible)

3. 3.3v power supply to power the board (or separate 5v micro USB cable would work )

Circuit Diagram:

Procedure:

Windows

  1. Download the suitable boot-loader binary file from given download link. If you don’t know which binary file will suits your black-pill, then simply trace its LED pin track and notice its pin number. This same pin number binary file you will have to flash into your board.
  2. Put your black-pill board on serial programming mode by setting boot0 pin high and boot1 pin low.
  3. Connect black-pill board to serial converter as shown in circuit diagram and connect serial connector to your computer USB port.
  4. Download Flash Loader Demonstrator program to flash the boot-loader into black-pill.
  5. Open up Flash Loader Demonstrator and follow the steps. Reference snapshots are as shown bellow..
  6. After finishing flashing process you will get conformation message as shown in the reference image. After that you need to change the board programming mode to normal by replacing the jumpers as previous, without switching off the board power.

Linux

Follow step 1 to 3 same as windows procedure and then use the following command to flash the boot-loader binary into your board. Change the path and file name according to your binary file.

Change the serial programming mode to normal by changing the jumper setting as previous, without switching of the power supply.

Reference Images:

Downloads:

]]>
https://blog.etechpath.com/how-to-flash-usb-bootloader-in-stm32-black-pill-board-to-program-it-with-arduino-ide/feed/ 2
How to interface Nextion HMI with Arduino Mega2560 and learn how to use Nextion editor and program tags in Arduino https://blog.etechpath.com/how-to-interface-nextion-hmi-with-arduino-mega2560-and-learn-how-to-use-nextion-editor-and-program-tags-in-arduino/ https://blog.etechpath.com/how-to-interface-nextion-hmi-with-arduino-mega2560-and-learn-how-to-use-nextion-editor-and-program-tags-in-arduino/#comments Wed, 14 Feb 2018 07:00:18 +0000 https://blog.etechpath.com/?p=513 About:
Nextion is a smart hardware HMI (Human Machine Interface) solution published by ITEAD that provides visualization and control interface between human and machine. Nextion HMI comes with simple serial interface and can be easily communicate with Arduino, raspberry pi and other serial Interface compatible hardware’s.
In this post, I will explain how to draw basic HMI screens, setting tag names and reading tags using Arduino.



Circuit Diagram:

NextionHMI_Arduino Mega2560
Circuit Diagram



Nextion HMI Arduino Mega 2560
Prototype




Nextion HMI Designing:
Watch bellow video for complete tutorial on how to operate Nextion HMI graphic designing software.






Arduino Code:
Note: I am using common anode RGB LED for output testing purpose. So I have written this code to operate common anode LED as output. If you want to drive relays instead of LED, you will need to change the code a bit.

/***************************************************************************************************************
*    Nextion HMI Basic Example : Three Buttons
*    Version 1.0
*    Created By: Pranay Sawarkar
*         Email: admin@blog.etechpath.com
*    All Rights Reserved © 2018 www.etechpath.com
*    
*    Download necessary libraries from the links mentioned in download section in the post,
*    Post Link: https://blog.etechpath.com/how-to-interface-nextion-hmi-with-arduino-mega2560-and-learn-how-to-use-nextion-editor-and-program-tags-in-arduino
*
*************************************************************************************************************************/

#include "Nextion.h"
 
int S1 = 2, S2 = 3, S3 = 4;

NexDSButton bt0 = NexDSButton(0, 2, "bt0");
NexDSButton bt1 = NexDSButton(0, 3, "bt1");
NexDSButton bt2 = NexDSButton(0, 4, "bt2");
 
char buffer[100] = {0};
 
NexTouch *nex_listen_list[] = 
{
    &bt0, &bt1, &bt2,
    NULL
};
void setup(void)
{    
    pinMode(2,OUTPUT);
    pinMode(3,OUTPUT);
    pinMode(4,OUTPUT);
    digitalWrite(S1, HIGH);
    digitalWrite(S2, HIGH);
    digitalWrite(S3, HIGH);
    nexInit();
    bt0.attachPop(bt0PopCallback, &bt0);
    bt1.attachPop(bt1PopCallback, &bt1);
    bt2.attachPop(bt2PopCallback, &bt2);
    dbSerialPrintln("setup done"); 
}
void loop(void)
{   
    nexLoop(nex_listen_list);
}
 
void bt0PopCallback(void *ptr)
{
    uint32_t dual_state;
    NexDSButton *btn = (NexDSButton *)ptr;
    dbSerialPrintln("Callback");
    dbSerialPrint("ptr=");
    dbSerialPrintln((uint32_t)ptr); 
    memset(buffer, 0, sizeof(buffer)); 
    bt0.getValue(&dual_state);
    if(dual_state){digitalWrite(S1, LOW);}else{digitalWrite(S1, HIGH);}
}
void bt1PopCallback(void *ptr)
{
    uint32_t dual_state;
    NexDSButton *btn = (NexDSButton *)ptr;    
    dbSerialPrintln("Callback");
    dbSerialPrint("ptr=");
    dbSerialPrintln((uint32_t)ptr); 
    memset(buffer, 0, sizeof(buffer));   
    bt1.getValue(&dual_state); 
    if(dual_state){digitalWrite(S2, LOW);}else{digitalWrite(S2, HIGH);}
}
void bt2PopCallback(void *ptr)
{
    uint32_t dual_state;
    NexSButton *btn = (NexDSButton *)ptr;
    dbSerialPrintln("Callback");
    dbSerialPrint("ptr=");
    dbSerialPrintln((uint32_t)ptr); 
    memset(buffer, 0, sizeof(buffer));
    bt2.getValue(&dual_state);
    if(dual_state){digitalWrite(S3, LOW);}else{digitalWrite(S3, HIGH);}
}





HMI with Arduino working video:

https://www.youtube.com/watch?v=2RTYilN8xvs



Downloads :

Nextion Library

Nextion HMI file

Nextion TFT file

HMI Images

Arduino Code

 

 

]]>
https://blog.etechpath.com/how-to-interface-nextion-hmi-with-arduino-mega2560-and-learn-how-to-use-nextion-editor-and-program-tags-in-arduino/feed/ 7
How to setup Arduino IDE board manager & library for ESP8266 module programming https://blog.etechpath.com/how-to-setup-arduino-ide-board-manager-library-for-esp8266-module-programming/ https://blog.etechpath.com/how-to-setup-arduino-ide-board-manager-library-for-esp8266-module-programming/#respond Fri, 19 Jan 2018 06:34:03 +0000 https://blog.etechpath.com/?p=489 About:

In this post i will explain you how to program your ESP8266 board using Arduino IDE software.

 

Things you will need:

  1. ESP8266 Node MCU or any Generic ESP8266
  2. USB to Serial TTL adapter. (CH340, CP2102, FTDI )
  3. 3.3v voltage source.
  4. A computer with Arduino IDE

 

Procedure:

Part 1 : Make your Arduino IDE ready for ESP boards

  1. Install Arduino IDE in your computer if you are using it for first time. (Arduino IDE)
  2. Open Arduino IDE, go to File – Preferences – find Additional board manager URL input box and copy paste below link to it and hit OK button.
    http://arduino.esp8266.com/stable/package_esp8266com_index.json esp8266-Arduino1
  3. Then go to Tools – Board – Board Manager and search for ESP8266, select latest version form the drop-down list and hit install button.
  4. You are done with setting Arduino IDE now, here is a simple video tutorial if you have any doubt with the above procedure..


Part 2 : Installing USB driver for your USB to Serial/TTL adapter

Depending on what adapter you are using for connecting ESP8266 serially with your computer, download and install respective drivers in your computer. Here i am linking some address of widely used programming adapters.

  1. CH340
  2. FTDI
  3. CP2102 

If you are unsure about the present driver ic on your ESP8266 or adapter board, then you can conform it visually form bellow picture.

Part 3 : Connection and uploading your first code to ESP8266

Connect esp8266 board to USB port of your computer and check its COM port (here’s how to) in device manager. Then select your ESP board type and COM port in Arduino IDE, that’s it you are ready to upload your first code.

 

 

 

 

]]>
https://blog.etechpath.com/how-to-setup-arduino-ide-board-manager-library-for-esp8266-module-programming/feed/ 0
How to control RGB LED wirelessly using ESP8266 WiFi web interface https://blog.etechpath.com/how-to-control-rgb-led-wirelessly-using-esp8266-wifi-web-interface/ https://blog.etechpath.com/how-to-control-rgb-led-wirelessly-using-esp8266-wifi-web-interface/#comments Tue, 21 Nov 2017 22:59:50 +0000 https://blog.etechpath.com/?p=476 About:

In this project we are going to control 1 watt RGB full color LED diode using WiFi module ESP8266-01. You can use any WiFi enabled device to access web interface to control this RGB LED. Watch video at the bottom of this page.




Things you will need: 

  • 1W RGB LED
  • ESP-01  WiFi module
  • 10Ω Resistance
  • ASM1117 3.3v  (or any 3.3v voltage source)
  • USB to TTL converter (for programming esp-01)
  • Momentary push button (optional)
  • Android / Apple / Windows  Phone or any WiFi enabled Laptop / Desktop (to control RGB LED)

Circuit Diagram for programming ESP-01 : 

esp-01_circuit

Steps :

    1. Connect the circuit on breadboard as shown in above circuit diagram for programming ESP-01 WiFi module. You must use only 3.3v logic setting in TTL device.
    2. In this tutorial we will used Arduino IDE to download code into ESP module. So, install Arduino IDE and add supporting board manager and ESP library into it. (Download links are given in download section)



  1. Download and save source code on your computer and open it up using Arduino IDE.
  2. Connect USB to TTL module to your computer.
  3. Open Arduino IDE – Select board ‘Generic ESP8266 Module’ – Select Port of your TTL device (Here’s How to)
  4. Open downloaded code.ino file into arduino and upload the code into ESP module by pressing upload button.
  5. After uploading, Disconnect the ESP module from USB-TTL module and connect it to RGB LED as shown in bellow diagram.

Circuit Diagram for connecting RGB LED:

Steps: 

    1. Connect the final circuit as shown in above diagram and power it up using 5v battery or wall adapter.
    2. ESP module will boot up and LED light will show fade effect in all three colors at startup.



  1. Then open your device WiFi in discovery mode and you will see a new WiFi access point, named as RGB in discovery list.
  2. Connect that WiFi access point, Open any web browser in that device and open ip address 192.168.1.1 , thats it, you will see a colorful RGB control screen to control your wireless RGB LED.
        Note: Do not feed more than 3.3v to ESP-01 module

Source Code : 

/* RGB web server with ESP8266-01 (ESP-01)
* There are only 2 GPIOs available in ESP-01: 0 and 2
* but RX and TX can also be used as: 3 and 1
* Wiring Circuit 
* 0=Red (GPIO0) D3
* 2=Green (GPIO2) D4
* 3=Blue (GPIO3) Rx
* www.etechpath.com
*/

#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>

const char *ssid = "RGB";
//Uncomment below line if you wish to set a password for ESP wifi network...
// const char *password = "87654321";  

const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);   //IP address of your ESP 
DNSServer dnsServer;
ESP8266WebServer webServer(80);

//Webpage html Code
String webpage = ""
"<!DOCTYPE html><html><head><title>RGB control eTechPath.com</title><meta name='mobile-web-app-capable' content='yes' />"
"<meta name='viewport' content='width=device-width' /></head><body style='margin: 0px; padding: 0px;'>"
"<canvas id='colorspace'></canvas>"
"</body>"
"<script type='text/javascript'>"
"(function () {"
" var canvas = document.getElementById('colorspace');"
" var ctx = canvas.getContext('2d');"
" function drawCanvas() {"
" var colours = ctx.createLinearGradient(0, 0, window.innerWidth, 0);"
" for(var i=0; i <= 360; i+=10) {"
" colours.addColorStop(i/360, 'hsl(' + i + ', 100%, 50%)');"
" }"
" ctx.fillStyle = colours;"
" ctx.fillRect(0, 0, window.innerWidth, window.innerHeight);"
" var luminance = ctx.createLinearGradient(0, 0, 0, ctx.canvas.height);"
" luminance.addColorStop(0, '#ffffff');"
" luminance.addColorStop(0.05, '#ffffff');"
" luminance.addColorStop(0.5, 'rgba(0,0,0,0)');"
" luminance.addColorStop(0.95, '#000000');"
" luminance.addColorStop(1, '#000000');"
" ctx.fillStyle = luminance;"
" ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);"
" }"
" var eventLocked = false;"
" function handleEvent(clientX, clientY) {"
" if(eventLocked) {"
" return;"
" }"
" function colourCorrect(v) {"
" return Math.round(1023-(v*v)/64);"
" }"
" var data = ctx.getImageData(clientX, clientY, 1, 1).data;"
" var params = ["
" 'r=' + colourCorrect(data[0]),"
" 'g=' + colourCorrect(data[1]),"
" 'b=' + colourCorrect(data[2])"
" ].join('&');"
" var req = new XMLHttpRequest();"
" req.open('POST', '?' + params, true);"
" req.send();"
" eventLocked = true;"
" req.onreadystatechange = function() {"
" if(req.readyState == 4) {"
" eventLocked = false;"
" }"
" }"
" }"
" canvas.addEventListener('click', function(event) {"
" handleEvent(event.clientX, event.clientY, true);"
" }, false);"
" canvas.addEventListener('touchmove', function(event){"
" handleEvent(event.touches[0].clientX, event.touches[0].clientY);"
"}, false);"
" function resizeCanvas() {"
" canvas.width = window.innerWidth;"
" canvas.height = window.innerHeight;"
" drawCanvas();"
" }"
" window.addEventListener('resize', resizeCanvas, false);"
" resizeCanvas();"
" drawCanvas();"
" document.ontouchmove = function(e) {e.preventDefault()};"
" })();"
"</script></html>";
void handleRoot() 
{
// Serial.println("handle root..");
String red = webServer.arg(0); // read RGB arguments
String green = webServer.arg(1);  // read RGB arguments
String blue = webServer.arg(2);  // read RGB arguments

//for common anode
analogWrite(0, red.toInt());
analogWrite(2, green.toInt());
analogWrite(3, blue.toInt());
//for common cathode
//analogWrite(0,1023 - red.toInt());
//analogWrite(2,1023 - green.toInt());
//analogWrite(3,1023 - blue.toInt());
webServer.send(200, "text/html", webpage);
}
void setup() 
{
pinMode(0, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);

analogWrite(0, 1023);
analogWrite(2, 1023);
analogWrite(3, 1023);
delay(1000);
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(ssid);
dnsServer.start(DNS_PORT, "rgb", apIP);
webServer.on("/", handleRoot);
webServer.begin();
testRGB();
}
void loop() 
{
dnsServer.processNextRequest();
webServer.handleClient();
}
void testRGB() 
{ 
// fade in and out of Red, Green, Blue
analogWrite(0, 1023); // Red off
analogWrite(2, 1023); // Green off
analogWrite(3, 1023); // Blue off

fade(0); // Red fade effect
fade(2); // Green fade effect
fade(3); // Blue fade effect
}
void fade(int pin) 
{
for (int u = 0; u < 1024; u++) 
{
analogWrite(pin, 1023 - u);
delay(1);
}
for (int u = 0; u < 1024; u++) 
{
analogWrite(pin, u);
delay(1);
}
}

 





Downloads:

  1. Code.ino
  2. Arduino IDE
  3. ESP8266 Board link for IDE board manager
  4. ESP8266 Arduino Library

 

]]>
https://blog.etechpath.com/how-to-control-rgb-led-wirelessly-using-esp8266-wifi-web-interface/feed/ 6
How to program XS3868 audio bluetooth module using USB TTL module https://blog.etechpath.com/how-to-program-xs3868-audio-bluetooth-module-using-usb-ttl-module/ https://blog.etechpath.com/how-to-program-xs3868-audio-bluetooth-module-using-usb-ttl-module/#comments Mon, 04 Sep 2017 22:48:48 +0000 https://blog.etechpath.com/?p=205 About :

XS3868 is based on OVC3860 RF transceiver. OCV3860 is low voltage single chip Bluetooth RF transceiver providing Bluetooth stereo solution. OVC3860 is a 2.4GHz transceiver with Bluetooth V2 baseband and can transfer 20bit high quality audio codec. OVC3860 is fetured with inbuilt power management and support advance lithium ion batteries with switch regulator.




In this project we are going to learn how to program XS3868 audio Bluetooth module using TTL USB module. Here you will learn how to change the costume Bluetooth device name and the security password of XS3868 device.

 

Requirments :

  1. XS3868 module
  2. USB TTL serial module
  3. 3.7v li-ion battery or any 3.6v-4.2v voltage source
  4. LED with 470 Ohm resistor (optional)
  5. Compute (to communicate with the device)

 

Circuit Diagram :

xs3868_bluetooth_UART

 

Steps:

    1. Connect xs3868 with battery then wire its reset terminal with 1.8v output terminal of xs3868.
    2. As shown in diagram connect TX of xs3868 to RX of UART module and RX of xs3868 to TX of UART  module.
    3. At last connect UART module GND terminal to common ground of xs3868.



  1. Download  “OVC3860 RevD Develop” tool from link given bellow at download section.
  2. Connect UART module to your computer USB port and check the COM port number for UART device, if it is other than COM-1 then change it to COM-1 first. [Here’s How To]
  3. Open OVC3860 RevD Develop tool with administrative rights, you will see the window similar as below,OVC3860_RevD_Develop_tool
  4. Now reset xs3868 module from reset pin and you will see the your device connected in tool window with green circle on the top.
  5. Now scroll down to item Local Name and Pincode, this is your Bluetooth name and password.
  6. Change it to desired Bluetooth name and password as you want.
  7. Click Write ALL button in tool and if everything went right, you will get Success message pop up on screen.

 

Download Section:

  1. OVC3860 RevD Development tool
  2. OCV3860 AT-Command Set



]]>
https://blog.etechpath.com/how-to-program-xs3868-audio-bluetooth-module-using-usb-ttl-module/feed/ 5
Getting Started with ESP8266 WiFi Module https://blog.etechpath.com/getting-started-with-esp8266-wifi-module/ https://blog.etechpath.com/getting-started-with-esp8266-wifi-module/#respond Thu, 31 Aug 2017 01:59:00 +0000 https://blog.etechpath.com/?p=100 ESP8266 :

ESP8266 is advance WiFi chip with complete and standalone networking capabilities. This can be use ether as a standalone or the slave to a host microcontroller. ESP8266 is integrated with advance Tensilica’s L106 diamond series 32 bit micro-processor and on-chip SRAM with CPU clock speed 80MHz. We can also interface external input devices with this chip though provided GPIO’s (general purpose input/output).

For detailed information you can download ESP8266 datasheet here.

 

ESP8266 Modules:

There are several esp8266 modules available in market but only some of them are famous and commonly used. The most commonly used esp modules are ESP-01, ESP-07ESP-12  & ESP-32. Nowadays  ESP-32 is most famous module amongs all of them because ESP-32 is the only version  of ESP which combines WiFi and Bluetooth in single module. You can download datasheets of these modules from attachments.

 

ESP-01 Basic Circuit:

 

ESP-01 Pinout

ESP-01 Pinout

 

How to flash ESP-01 using Flash tools:

  1. Gather all component shown in above circuit and wire your esp to serial module as shown.
  2. Download ESP flash download tool from  the link given at the bottom of the page. You will not need to install this tool in your system, this tool will run directly without installation.
  3. Extract the rar file which we have downloaded in last step and run application file in it and select ESP8266 form selection buttons.
    ESP-flash-tools
    ESP-flash-tools
  4. After selecting ESP8266 download tool button, Flash tool screen will appear like bellow picture.
    ESP-flash-tools2
    ESP-flash-tools
  5. Now go back to your circuit and put jumper JP1 on. For setting ESP-01 into programming mode, you have to short GPIO0 to ground terminal of connected source.
  6. Connect serial module to your computer USB port and check the COM port for this device in device manger. You will need the correct COM port number of the connected device which you want to flash.   ( learn how to check COM port )
  7. That’s it, You are ready to go. Now select the bin files you want to burn into your ESP, select com port at the bottom of the flash tool and hit START. Ongoing process and success message will show in download panel dialog box.
  8. For beginner level you can burn NodeMCU firmware in your ESP-01 for general use.

 

How to Flash NodeMCU firmware in ESP-01:

  1. Download ESP8266 Flasher form the link given bellow at the bottom of this page.
  2. Run the flasher application file. You will see the tool as shown in bellow picture,
    ESP_flasher
    ESP_flasher
  3. Now setup your ESP-01 in programming mode as i described in previous steps. and select the COM port of your serial module.
  4. Do not change any other settings in flasher, setting right port is enough.
  5. Now hit Flash button provided just beside com port and your ESP will start receiving data from flasher. At the same time  AP MAC and STA MAC will appears on flasher as shown in picture bellow,
    NodeMCU flasher
    Programming ESP….
  6.  After successfully completing flashing process green indication will appear at the bottom, This means your ESP is programmed successfully and ready to use.

 

 



Downloads:

  1. ESP Flash Download Tools
  2. ESP Flasher win32
  3. ESP Flasher win6

 

]]>
https://blog.etechpath.com/getting-started-with-esp8266-wifi-module/feed/ 0