Category Archives: Electronics

Problems with ESP32 configures as both Client and AP

In one project I had an ESP32 configured both as Access Point (AP) and as a Wifi Client. Everything was fine, until I changed my home Wifi password.

After changing the home Wifi password I wanted to change the Wifi password set on the device through the Web UI I made and hosted on the device. The problem started there. I was unable to access the UI.

Reviewing the code realised that the Wifi Client is continuously trying to re-establish the connection in a loop. And hence is unable to process the incoming request and process the page.

So either need to stop the scanning from time to time or stop the scanning when an AP client is connected. For short and fast resolution I stopped the wifi connection retry when a client is connected to AP.

WiFi.softAPgetStationNum()

FASTLed Library and RGB Led

Recently I was trying to make a device that will indicate different status through different light colors.

Now after developing everything a strange thing started to happen – the RGB LED was not showing the colors properly. For example – suppose the current color is Green and then I put Red. It is not glowing pure RED, the Green pixel (the individual green pixel of the LED) is still faintly on.

After some thoughts and searches found the solution is to first turn of the LED fully

leds[0] = CRGB::Black;
FastLED.show();

and then show the new color.

Hope this helps someone.

 

Humidity sensor

There are many Humidity sensors available. DHT-11/DHT-20/DHT-22 from Aosong are the cheapest and easily available in India.

DHT-11 is the cheapest. DHT-22 or AM2302 is a good choice for hobby purposes or college projects. DHT20 has replaced DHT22 but still DHT22 is still the most available one.

DHT20 is colored black and DHT22 is white.

DHt-20 DHT-22

There are many manufacturers, even nameless ones.  But sensor from Aosong is the preferred.

The module needs a pullup resistor. 10K will do. They can be put at a distance from the controller. The length of the cable depends on the voltage. With 5v it can be upto 3mts and for 3.3v the max is 1 meter.

Best library in my opinion is the one from Adafruit, which is available here.

The library can be downloaded from here also DHT-sensor-library by Adafruit

Some other Humidity sensors are SHT20D, HTU21D-F, BME280. The HTU21D-F has protective cover or membrane on the sensor. SHT2x or SHT3x also has protective caps available.

ESP-01 Serial.println() or Serial.print() not working

I went crazy, mad trying to understand why the module is not printing anything to the Serial Monitor or receiving any AT commands.

I went through lots of articles on the internet and was on the verge of throwing the module away. Just that my mind was not willing to believe that it is dead – because I was able to burn OS / Firmware to the module every time I tried and the status showed success. And my suspicion was confirmed accidentally – I put some Serial.print code in loop instead of setup and it did throw output to serial monitor. It confirmed that something is wrong with the settings of Arduino IDE.

After lots of tweaking and trials I found that – the “Built In Led” settings of Arduino that mattered.  The built in LED is on the TX line of the module, hence just after printing some output when I toggled the LED, the print function didn’t get enough time to write to the monitor. To solve the matter a delay can be used also.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("");
  Serial.println("Hello");
  delay(1000);
  pinMode(1, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(1, LOW); // turn the LED on (HIGH is the voltage     level)
  delay(500); // wait for a second
  digitalWrite(1, HIGH); // turn the LED off by making the voltage LOW
  delay(300); 
  digitalWrite(1, LOW); 
  delay(500); // wait for a second
  digitalWrite(1, HIGH); 
  delay(2000); 
}

In my module the LED is on PIN 1.

ESP-01 and ESP-01S Burning AT ROM- New and Updated

Few years back I had posted an article on burning ROM on ESP-01. The method worked good on my older boards but not working on the newer chips.

I needed to spend quite some hours to figure out the problem. And then it turned out that it is the SPI mode that is the matter. Also the new Flash tool (v 3.9.2 ) is not robust. It often becomes unresponsive.

  • Upload a blank sketch to Arduino Uno
  • The new ones need DOUT, 26 Mhz Xtal (check the board), SPI Speed 40 Mhz, 8Mbit. Burning with other modes may result in success but the chip will not work and will end up with boot errors. I got reset reason: 2, boot(3,7)
  • Connect RX to RX and TX to TX
  • GPIO_0 will go to GND
  • VCC and CH_PD will go to the 3.3v supply line
  • Select the appropriate ESP8266 board from Tools > Board menu.
  • Select the appropriate Flash mode (Only DOUT works for new chips. Old chips work with both QIO and DOUT)
  • Select baudrate as 115200
  • Start upload
  • RESET the module. This is a critical step and the timing matters. It may need a few tries to get it perfect.

The new Flash tool (v 3.9.2 ) is not robust. It often becomes unresponsive. The quick fix solution I found is pressing enter in the console (black window that it opens) and then disconnecting and reconnecting the Arduino (USB cable).

Wrong flashing may cause boot problems. To correct ERASE and FLASH OR FLASH all memory locations like shown below

The appropriate addresses can be found in the folder \ESP8266_AT_Bin_V1.6\bin\at\README.md

Please note – DoNotChgBin is unchecked.

After flashing Firmware version 1.6

AT+GMR
AT version:1.6.0.0(Feb 3 2018 12:00:06)
SDK version:2.2.0(f28eaf2)
compile time:Feb 6 2018 14:36:23
Bin version(Wroom 02):1.6.0
OK

All diagnostic messages  are sent at 74880 Bauds.
But AT commands are available only at 115200 Bauds.

After flashing disconnect GPIO_0 from GND and RESET

On proper flashing it will show ready like below

 

Here is the latest flash tool
Here is the ROM Version 1.6
Here is the ROM Version 1.6.2

NOTES:

  • Adequate power supply is needed for burning. I am using a buck convertor capable of delivering upto 1 amp.
  • Burning new chips with QIO will result in a successful burning but the code will not run.

 

 

ESP8266 Programming Using Arduino IDE

The ESP8266 can be programmed using the Arduino IDE. The best part is the codes are similar to Arduino. To start programming a ESP8266 using Arduino IDE follow the below steps

Prerequisites

Steps

  • Start Arduino and goto File-> Preferences.
  • In the “Additional Boards Manager URLs” Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json  (You can add multiple URLs, separating them with commas)
  • Click “OK”
  • Open Boards Manager from Tools -> Board menu and find esp8266 platform.
  • Select the version you need from drop-down box.
  • Click install button.
  • ——————————————–
  • Upload a blank sketch to the Arduino.
  • Connect RX to RX and TX to TX
  • GPIO_0 will go to GND
  • VCC and CH_PD will go to the 3.3v supply line
  • Select the appropriate ESP8266 board from Tools > Board menu.
  • Select the appropriate Flash mode (DOUT or QIO. See notes below)
  • Other parameters works mostly as it is – but still check once.
  • Start upload
  • RESET the module. This is a critical step and the timing matters. It may need a few tries to get it perfect.

After the code uploaded

  • Disconnect GPIO_0
  • Reset

 

For further details please check http://esp8266.github.io/Arduino/versions/2.3.0/

Please see this article for a basic code (Blinking LED that is the Hello World of micro-controllers)

Notes

  • While uploading codes through Arduino IDE select DOUT for new chip and either DOUT or QIO for old chips.
  • Keeping it to DOUT will work for both New and Old chips.
  • Burning new chips with QIO (or inappropriate modes) will result in a successful burning but the code will not run.

 

Here is a Troubleshooting Guide and parameters that worked for me.

Flashing guide for new chips.