Skip to main content


Showing posts from 2017

A simple ESP-01 USB adapter with toggle switch for reprogramming

ESP-01 is a simple ESP8266 module which can be purchased cheaply from Aliexpress. At one of promotion, I purchased an ESP-01 for just S$1.97. That's very cheap for a wifi enabled microcontroller. An ESP-01 can be a WIFI bridge for non-connected microcontroller such as Arduino UNO, Mega, Nano etc. Communication between the microcontroller can be done using the serial link between them.

I have written a post on this using ESP-Link to connect to an Arduino Pro Mini. Together with the client library provided, the Pro Mini can easily transfer sensor data via MQTT.

For the most part, once the firmware is in place, normally I will use OTA to update. Sometimes, I wanted to reuse the same controller for another firmware and I have rewired up the controller for reflashing. This makes it very inconvenient to use.

Recently, I bought a USB ESP-01 adapter thinking that my problem is solved. When I received it and realised…

Google Cloud IoTCore with UDOO Quad

UDOO Quad is a maker SBC board from UDOO. It has a built-in Arduino microcontroller and can run Linux on the SBC. On the web, most of the Google IoT Core samples have been focused using Mongoose OS and I have written a post on "Journey into Google Cloud IoT Core with ESP8266 and Mongoose OS". Recently, Google releases code samples which make the initial handshaking with Cloud IoTCore simpler.  For UDOO, the tedious part is to get all supporting tools to work with a particular version of Linux Distribution.

UDOO supports a few Linux distributions (Ubuntu, Debian and others). I have installed Ubuntu and the current version supported by UDOO is 14.04 LTS. For this demo, I wanted to work on Python 3.5 and I have compiled the Python from source. This is step may not be necessary if you use the version that is installed (Python 3.4).

The idea for this project is to read the temperature and humidity reading from UDOO Arduino side, transfer the data to Linux side and forward the dat…

Using ESP-Link transparent bridge (ATmega2560+ESP8266 board)

I have found this interesting board selling on Aliexpress website. It is an Arduino Mega 2650 with a built-in ESP8266 which allows the Mega to connect to wifi. This board has cut down a lot of wiring and bring out interesting possibilities. One of this is to connect up both the microcontrollers using ESP-link firmware. I have an earlier blog post that described how to wire up an ESP-01 and Arduino Pro Mini.

One of the tricky parts in this setup is the sequence of flashing the ESP firmware. Flashing the onboard ESP8266 requires some setting changes to the dip switches. The following are the sequences which I get both the microcontrollers to talk to each other.
Set the jumper 5,6,7 to ON and the rest OFF. This will set the ESP to update mode.I am using version 3.0.14 and flashed the ESP using the following parameters:
esptool --port com26 --baud 230400 write_flash -fm dio -fs 4MB -ff 80m 0x0 boot_v1.6.bin 0x1000 user1.bin 0x3fc000 esp_init_data_default.bin 0x3fe000 blank.bin After flash…

Import CSV file from Google Drive to Big Query

I have written about using App Scripts to collect telemetry data and the ease of integrating it to Google Sheet to chart the temperature and humidity reading. In this post, I shall describe the approach using a CSV uploaded via Google File Stream and a scheduled job which is written in App Script to load the data into Big Query. This approach is very good for integrating the transactional capability of ERP system and the Analtyics capability of Visualisation system (Data Studio).

ERP system has rich built-in business process workflow and transactional control, When performing Dashboard and Data Analytics functionality, it will slow down the entire system. In this case, it maybe better for analytics features to be performed by another system. Fortunately, most ERP system is capable of auto execute a query to export CSV data. I ahve make use of this capability to import the daily files generated by ERP to Big Query via Google Drive. This CSV file is picked up by an App Script to import …

Source Control for Google App Scripts

Google App Script (GAS) is a very versatile tool for writing scripts to control many of the GSuites and Google Cloud services. One can build many small applications using GAS and hosts it seamlessly on GDriver for free. It has a built-in editor, debugging tool and logging of logs to StackDriver. The main drawback I had with GAS is the difficulty to create save the scripts to source control like Github.

Fortunately, danthareja shared his tools to read/write app script into GDrive seamlessly, but the script has a limitation, it can only handle a single project. This is because it is writing the OAuth information into %UserProfile%\.gapp.

I wrote a simple wrapper script pull.bat and push.bat that synchronous the App Script.

copy .gapps %UserProfile%\.gapps gapps init [REPLACE YOU PROJECTID] -o Copy the local version of the ".gapps" to the %UserProfile% directory and overwrite the local copy of the script file.

copy .gapps %UserProfile%\.gapps gapps push C…

Journey into Google Cloud IoT Core with ESP8266 and Mongoose OS

Google recently take the IoT Core to Public Beta. IoT Core is one of the product lines of Google entry to the IoT arena. It is a device registry for controlling and tracking the IoT devices. On top of this, it provides connectivity to the rest of the Google services. Below is the standard diagram provided by Google for the IoT Core.

As we can see, there are 10 big parts in this entire chain (including the edge devices). Some parts are more complicated than the others. For this article, I will start the journey by exploring the following path.
I will be using an ESP8266 running on the Mongoose OS because Mongoose OS has native support for Cloud IoT Core. This will reduce the work required to perform the authentication between the device and the IoT Core.
ESP 8266 & Mongoose IoT Core setup Mongoose OS website has a set of setup instructions on configuring the devices to connect to IoTCore. The Mongoose OS example stopped at when the message is successfully delivered to PubSub. The P…

A new chapter has begun

Just moved into the Co-Working space in LaunchPad. LaunchPad is Singapore version of Silicon Valley.

A new chapter has begun.

ESP Easy

ESP Easy is an interesting piece of firmware, it really makes interfacing to an ESP 8266 a breeze. It has a very comprehensive user interface to configure practically everything:

MQTT setupAll the GPIO pins behaviour.Configure the supported sensors setting.Configure the OLED to display the value of the sensors.and more... In this setup, I used my custom Wemos D1 Mini shield extender to connect to additional I2C devices. I have connected to a BMP280 temperature/pressure sensor and a TSL2561 luminosity sensor. For fun, I have also connected the DHT11 temperature/humidity sensor.

All this setup is done without writing a single line of code. Amazing. Kudos to ESP Easy. One interesting observation, the temperature reading from DHT11 and BMP280 differs by abt 1.5 to 2 C. I wonder which sensor is accurate?

Using ESP-Link transparent bridge (ESP-01 and Arduino Pro Mini)

Recently stumbled across an interesting open source project ESP-Link. Its main purpose is to network-enable a non-network microcontroller (MCU) such as Arduino Uno, Pro mini or Nano using ESP8266. The author termed it as "Transparent Bridge". The ESP and MCU  communicate via the serial link and there is a companion Arduino library EL-Client for the MCU to connect up the network using MQTT, REST, TCP and UDP.
Setup I have put together an ESP-01 and an Arduino Pro Mini for this experiment. I have chosen a 3.3 version Pro mini so that I do not need to do any voltage level shifting between the I/O pins. In order to have a stable voltage source, the ESP8266 is powered by Pro Mini and the Pro Mini "RAW" pin is connected to a 5v USB power source. The RAW pin can take voltage up to 12V. The reset pin of Pro Mini is connected to GPIO 0 of ESP-01. This enables the ESP-01 to reset the Pro Mini.

I have linked up an APDS 9960 sensor to it and periodically send the luminosity a…

Using Google App Scripts to collect telemetry data - part 2 (ESP32 and Mongoose OS setup)

There are many ESP32 form factor breakout boards that can be purchased cheaply. In this mini project, I am using a form factor that looks like Wemos D1 Mini, so that I can reuse my shield without any wiring. Although no wiring is required, the pinout is different from Wemos D1 Mini. The DHT11 GPIO is 16 in ESP32 instead of 2 (note that Mongoose is using port pin definition. in Arduino, it is defined as D4 but it is mapped IO2).

ESP32 mini board is quite warm when in operation. I have put a dummy shield in between to reduce the interference it may cause to the DHT11 temperature reading.

The source code for the mongoose-os javascript can be found on github.

The setup of Mongoose OS is straightforward. Go to Mongoose site and download the binary, select the board type and change the init.js.

Part 1 Using Google App Scripts to collect telemetry data

Using Google App Scripts to collect telemetry data - part 1

This is one of Google best-kept secrets, Google App Script (GAS). GAS is a Javascript engine that can link various Google front and back end services together. e.g. Periodic scanning a GDrive folder, detect a CSV file and insert into MySQL. The best part of this, it is FREE !!!

Having said that, is there a limit? Yes, there is. Quotas for App Scripts

In the next few articles, I am going to demonstrate how we can collect the IoT data into Google Sheet and dynamically visualise the data using Google Sheet and/or Data Studio.

For this simple demo, I will use an ESP32 and runs Mongoose OS to act as the bridge between GAS and local MQTT server and send temperature/humidity data from DHT11 to Google Sheet.

As written in my previous article on Mongoose OS, the connectivity aspect of Mongoose is very powerful. it provides simple and easy to use Javascript APIs which glued the underlying C/C++ library. To read the sensor value and to Google Apps Script, it needs less than 20 lines of code. The…

Mongoose OS

Recently I was experimenting on the Mongoose OS. It is an open source IoT platform for developing applications on ESP32, ESP8266, STM32, TI CC3200 and TI CC3220 microcontrollers. It supports a simplified version of Javascript (mJS) and C/C++ as the development language for calling the OS APIs.
What are the features that impressed me?
1. Installation There is only 1 executable. (mos.exe) to be downloaded. Just clicked on the EXE and the web based IDE is displayed. Then I connect up ESP32 using the selected serial port, flashed the firmware and connect to my WIFI network. That's it! The MCU is setup! Amazingly simple.

2. Connection to MQTT After the initial setup, the connection to MQTT is only a few clicks away and the ESP32 is setup to send/receive message from MQTT server. Zero code for this entire process. Super impressed!!

Publishing to the MQTT is only a single line of code.
load('api_mqtt.js'); let topic = 'myesp32/topic'; let res =, JSON.stringify…

A Super IR Transmitter

One of the difficulties I had with the common IR transmitter module block from Arduino kit is it is not powerful. It can only transmit from a distance of about 1 m and the angle is very narrow. I need an effective distance of more than 3m and a wider angle and I wanted to use Tasmota as the bridge so that I can send the IR commands from my PC or another remote non-IR device.

The circuit for the super IR transmitter is as follows. On the web, I have found 2 approaches: connect multiple IR LEDs in series or parallel. The parallel configuration will provide more current to the LEDs and the series configuration will provide less current. I chose the series circuit because the resistance in the parallel circuit cannot be matched properly and the LED with the lowest resistance will get more power than the other which may result in 1 IR Led brighter than the other.

I managed to find a super bright IR transmitter LED in Aliexpress. The LED has a blueish tint compared to the normal white LED. 

WIFI switch

Lately, I have been experimenting on how to DIY a simple WIFI switch which can switch on/off a remote device. I can use OpenHAB to design a screen and use it on my mobile phone to do the job but I wanted a physical switch. I have put together the switch using a Wemos D1 mini and a capacitive touch switch. The capacitive touch switch has a nice blue glow when it is turned on. A NPN transistor is used as a switch to pull the D1 mini GPIO to the ground when activated.

Tasmota has a configuration for Switch mode. When a switch is toggled, it will send out a MQTT message. I have made both the Sonoff RF Switch and DIY switch listened to the same queue. When the switch is touched, it will turn on/off the Sonoff RF Switch. Cool !!!

UPDATE 1: DIY Sonoff RF Bridge with Sonoff RF

The Sonoff RF I have ordered arrived. It is similar to Sonoff Basic in term of the layout. Flashing the device with Tasmota firmware is easy. In Tasmota website, the instruction recommended soldering a jumper at R21. I discovered that this is not necessary. To start up the ESP in programming mode, I only need to short the inner pin of R21 to ground when powering up the ESP.

After I have flashed the device, I was trying to pair with my RF433 with pre-defined code but it does not go into pairing mode and I also noticed the ESP01 randomly throws errors. I suspected that the FTDI serial adapter may not have enough current to power both the ESP and the RF board. I put back the casing, powered the device using AC and cleared the existing code. I paired the Sonoff RF with my fixed code RF433 transmitter and using the DIY Sonoff bridge Web UI to trigger. Presto! The bridge is able to switch on/off the Sonoff RF.
That is a promising start for the DIY bridge. More exciting integrations with oth…

DIY Sonoff RF Bridge

Tasmota recently supported the RF bridge by iTead which allowed for RF 433 remote devices to be controlled/controlling using Sonoff products. e.g A handphone can be used to control a remote RF device or an RF remote control can use to control a WIFI enabled device.

By using Tasmota, I can control the device using MQTT. This idea fits exactly to my smart home plan. Here is the schematic:

I cheated a bit by having ESP01 mounted on a breakout board. This breakout board converts all the external pins to 5v which simplified the wiring and I do not need to use a voltage level shifter. Moreover, the Arduino 3.3v power does not have enough current to power the ESP reliably and I have to power it via the 5V from Arduino Uno. Next, I used an Arduino Uno prototype shield with a tiny breadboard to hold all the components together. For the RF 433 transmitter/receiver, I am using the development kits when I purchased the all-in-one Arduino development kits. An antenna is added for more sensitivity.