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

2020/01/08

3D Print; Howto remove broken filament

Problem to solve for 3D printer:

Filament was broken inside the Bowden tube during a print.

My printer is Creality Ender 3s (or Ender 3 Pro). Maybe the tension on the filament spool was so tight caused filament broken inside the tube.

How to remove the broken filament:


  1. Turn on Ender 3s 
  2. Adjust nozzle temperature to 210 degree Celsius (keep it at 210 degree the whole time)

    From main menu -> Control -> Temperature -> Set it to 210
  3. Raise the Z axis to see the nozzle from below
  4. Remove the nozzle with a wrench. Remember the nozzle is heated at 210 degree; it's super hot!  It's better to use a socket wrench to remove the nozzle.


  5. Cut the end of filament flat and then push it through Bowden tube, until the broken filament is pushed out of the Bowden tube.
  6. Use the socket wrench to screw the nozzle back to the printer. 
  7. Be sure the nozzle is really tight and level the bed before try to return nozzle back to home.  Here is what happened to my magnetic bed! (see below)  I forgot to level the bed and hit the HOME command, then the nozzle scratched it badly! (The photo shown was after I cut the scratched part off the bed.)
  8. Readjust the bed with paper method
  9. Done.

References:


==== 中文版 ====

3D印表機要解決的問題:

在3D列印過程中,線材在送料管中間斷掉了

我的3D印表機是 Creality Ender 3s(或Ender 3 Pro)。 可能是我把線材軸上放在地上, 造成它的張力過,導致線材在送料管內斷裂。

如何取出折斷的線材:

  1. 打開 Ender 3s 電源
  2. 將噴嘴溫度調到210度(一直保持在210度)

    從主選單—>控制—>溫度—>設定為210
  3. 用手旋轉Z軸,從下方看噴嘴
  4. 用扳手慢慢的轉下噴嘴。 注意: 噴嘴已加熱到210度,超級熱! 最好使用套筒扳手轉下噴嘴。


  5. 將新的線材剪平,然後將它推入送料管中,用新的線材推出斷的線材,一直到把斷掉的線材從送料管裡面推出來。
  6. 使用套筒扳手將噴嘴擰回到印表機上。
  7. 請確保將噴嘴確實擰緊並請整印表磁床的水平。
    我在還沒有調整水平時, 就去按下HOME 的指令! 然後噴嘴就嚴重刮傷了我的磁床!
    (照片是我從磁床上割下來劃傷的部分,右邊沒受傷的部份繼續用,哈!
  8. 採用紙張的方式重新調整磁床水平
  9. 大功告成

參考資料: