2021/07/25

Arduino #27 AsyncWifimanager ElegantOTA ESP32 (WiFi Password Mgnt. + WiFi Firmware Update)

*** If you are using the ESP8266, Please see this: ESP8266

It would be great if every IoT device deployed with OTA capability with Wifimanager.  Then the IoT device would be able to change SSID & password without connecting the device to the computer to update SSID and password as well as FOTA at any time when you wanted.

In this tutorial, let’s combine ESPAsync_Wifimanager and AsyncElegantOTA into a code base to become a handy tool for future IoT projects! 

I have made WiFiManager & AsyncElegantOTA tutorial videos. If you don't know what they are and how they work for IoT projects, I strongly recommend you to watch these videos first.

This time, I used ESPAsync_WiFiManager library, it's because WiFiManager does not work with AsyncElegnatOTA together. We have to change to ESPAsync_WiFiManager.  The main reason for this is that AsnycWiFiManager is using Asynchronous technology. Which means it can accept connections from different sources at the same time. So, while WiFiManager is running on the device, the device can also be a FOTA server to allow firmware to be remotely updated!

        Watch these videos first, if haven't heard about these.

        GitHub Library:

        Sample code:


For those of you do not have the time to watch the entire video, here is the Video Timeline 00:00 Project introduction 00:16 Arduino libraries used in this project 00:29 Short Wifimanager briefing (Check out my previous video) 00:59 Short AsyncElegnatOTA briefing (Check out my previous video) 01:34 Tutorial begin 02:04 Copy ESPAsyncWifimanager sample code to your editor 02:44 Check AsyncElegantOTA sample code 02:50 Start to merge the two libraries 05:16 Setup your IoT AP name 05:58 Copy AsyncElegantOTA code & modify 06:20 Modify server variables 07:05 What does webServer.on do? 07:35 Upload sketch 08:11 Test AsyncWifimanager and setup SSID & Password 09:10 Access ESP32 from browser 09:44 Access ESP32 OTA page

The End.

2021/07/11

Android control color RGB LED (Revised for ESP32)

ESP32 Source code on the bottom of this article! 

See the original complete project tutorial here: Android RGB LED Arduino Controller




In September 2014, I created this project with Arduino Mini Pro Mini and Android APP loved by so many readers!  There are more than 100,000 App downloads by now!  Since then, quite of few readers asked me how to change the sketch to be used on ESP32 with built-in Bluetooth.  Here it is!! 😀


Be aware that LED PWM pins used on ESP32 were completely different, since Arduino Mini Pro and ESP32 have different architectures. 

For ESP32, I used following pins:

  • Pin 13 = Red
  • Pin 12 = Green
  • Pin 14 = Blue
Caution: ESP32 does not allow to use pin 6, 7, 8, 9, 10, 11 or it will crash and reboot. I tried...😂


Also, there is no analogWrite() function in ESP32, so I need to change analogWrite() to ledcWrite() with 
  • Channel definition for PWM
    • R channel = 0
    • G channel = 1
    • B channel = 2
  • Setup PWM frequency: 5000
  • Setup PWM resolution: 8 (8bit = 255 colors)
Then I need to setup LED with:
  • ledcSetup( channel, frequency, resolution)
And then attach LED pins to channel
  • ledcAttachPin(Pin, channel)
Then write to LED pins with
  • ledcWrite( channel, value for resolution(0~255));


END

2021/07/10

ESP8266/ESP32 AsyncElegantOTA Wi-Fi OTA

It's always troublesome to update firmware for your IoT projects? Tried Arduino BasicOTA examples, but never get it to work? Then you must try AsyncElegantOTA! It's very easy to use and I've succeed the first time I try it. 



For those of you do not have time to watch it all, here is the video timeline for your quick reference.

Video Timeline:

00:13 Tutorial summary 00:53 What's OTA & Why 01:25 Tutorial begin 01:36 Install AsyncElegantOTA library 02:32 Download ESPAsyncWebServer & ESPAsyncTCP 02:57 Ensure Arduino board is capable of OTA 03:41 Where to place downloaded libraries 04:09 Open sample AsyncElegantOTA sketch 04:52 Upload sketch 05:05 Open serial monitor to see ESP8266 IP address 05:36 Access to ESP8266 from browser 06:10 Update ESP8266 firmware from browser 06:31 Where to find .bin file in VS Code 06:54 How to create .bin file in Arduino IDE 08:16 OTA update ESP8266 firmware 09:01 Next video tutorial - How to combine ESP8266 project with AsyncElegantOTA library


Library URL:

2021/06/20

VS Code - One of the best Arduino IDE


In recent years, Microsoft VS Code is considered the one of the best Arduino IDE!! 
I've made a video to show you how to use VS Code to write your Arduino codes, in Chinese only...

2021/02/17

Arduino - No more SSID and password with Wifimanager



NOTICE: If you encountered problems in compiling the code, see this updated video.

ESP8226:  https://youtu.be/NLRuqjhArg8

ESP32-CAM: https://youtu.be/TTdMKW6HhXM​

Have you met this problem before? You were making an fantastic Arduino IoT project. However, in the code, Wi-Fi SSID and Password were hard-coded and the only way to change these is to edit the code and re-upload the code to Arduino. At home, this is okay, since you were experimenting things here and there anyway.

Let’s say you bring this project to a friend place or a venue to demo. And you didn’t know the Wi-Fi SSID nor the password beforehand. Then, you need to bring your computer to change SSID and password and re-upload to Arduino.  

Is there a way to get rid this problem? Yes. The answer is use Arduino Wifimanager library. 


Start

Open Arduino IDE. From Tools and select Manager Library
in space here type Wi-Fi Manager to search

Arduino  IDE will filter keywords with Wi-Fi manager. Scroll down until you find a Wi-Fi manager by author Zabu. The current version 0.14 just click and install.  Ok, install completed. Click close.




Upload "Auto Connect" sketch to NodeMCU

Next, let's get a Wi-Fi Manager code. example from Files-> Example, scroll down and find Wi-Fi manager. Let's open "Auto Connect" in a new window.


In the "Auto Connect" code., let's not make any change and upload this code directly to NODEMCU to understand how it worked.

Now, let me compile the code and upload this code to my NODEMCU Compiled sketch.


This will take a while depending on your computer configuration. You can see the progress bar is showing here it's uploading the flashing LED indicates the program is uploading. Let's wait until upload complete. Okay.


Set it up on your smartphone


Upload completed. Let's look at the Arduino  Serial port right now. It says: using last saved values, should be faster. Since this is a new NODEMCU and I haven't set anything to it in the program code. There's neither Wi-Fi SSID nor password setting. The "AutoConnectAP"  is AP name that you could define yourself.

Let's see the serial monitor NODEMCU now acts as Wi-Fi AP named AutoConnectAP and waiting for Wi-Fi client connection. As I said this NODEMCU is now in Wi-Fi AP mode with IP address 192.168.4.1 What I need to do now is to input this IP address in a browser either smartphone or a computer. Let me enter this IP address into my smartphone browser.


Type IP here 192.168.4.1
Remember to connect the phone to  NODEMCU Wi-Fi AutoConnectAP first.

Swipe down and click Wi-Fi symbol and then click AutoConnectAP from available Wi-Fi list.  It's connected to AutoConnectAP. 



The Wi-Fi manager AP page will show up on your smartphone now. 



On this page let's,  click configure Wi-Fi. Wi-Fi Manager will scan adjacent available Wi-Fi AP and show them here.  Let me click my home Wi-Fi AP named stonez24 and and type in Wi-Fi password. Password entered and click Save. 


it shows Credential saved.  Let's look here NODEMCU you will now connect tostonez24 AP automatically.



Ready to go!


Okay, connection result shows connected. Great!! We have connected NODEMCU to Stonez24 AP. In the future when you visit a new place or venue, there's no need to Hard-Code SSID or password in Arduino code let Wifimanager do the hard work for you!



That's all for today's tutorial. I hope you find this useful! 

The YouTube video is here:




2020/06/14

3D Print - iPAD Holder for Treadmill

Tired of using tape to glue the iPad to the treadmill, my wife asked me to design and print an iPad holder for her. Here it is! 


This is a multiple weekends project, since the 3D design took me many weeks to complete. Hope you could also get some inspiration from this and design your own.


STL file on Thingverse:  https://www.thingiverse.com/thing:4459427




2020/04/24

Smartphone mount for camera tripod [3D Print]

I needed a smartphone mount for my tripod, so I designed this from a sketch using Fusion 360. I know there are relatively cheaper smartphone mounts for tripod out there in the market, but I just can't help to make one myself to learn.

STL file is available here: https://www.thingiverse.com/thing:4309896

In fill: 70% for the middle part and 20% for rest
Nozzle: 0.4 mm
Layer high: 0.2 mm

For people who like to use this STL file, please be aware that not each tripod mount base has the same dimension, so, I highly recommend you to measure the base before 3D print.

Also, for the middle part, please use 70% infill to make the clip part stronger.



After couple of days struggling with Fusion 360, I was able to make the thing!! :)

My draft sketch about the mount design.

For the base, I printed 3-4 times to perfectly match my camera tripod. I think this is due to the precision of my Ender 3 Pro printer or PLA material.
After assembled the 3 parts together

Mount smartphone on the printed mount, perfect!

Place the smartphone mount on the camera tripod