Monday, March 8, 2021

Lilygo TTGO T-Watch 2020: Getting Started / The Software Framework


Since quite a few years, I liked the idea of a programmable watch. So far, however, all programmable watches were in a price range beyond what I was willing to pay. Then, ten months ago, in May 2020 the company LilyGo released the T-Watch-2020, which you can get at around $30-$40. This is a game changer!

The T-Watch 2020 is the successor of their 2019 model (which was 20 mm thick) with a width of only 13 mm (= 1/2"), and it somehow resembles the shape of the Apple watch. At this price, of course, you don't expect it to be a competitor for the Apple Watch. But you will find that it's really usable in everyday life. And you can have a lot a fun with it, whether you plan to write your own code to run on the watch, or if you just plan to install other people's code (below, I am offering code for this purpose).

In these instructions, I show you how to set up the programming framework and how to run an example program on the T-Watch.


The Watch

 I ordered my watch at Banggood.com, and this is what I found in the package.


The bottom, with the open lid that covers the micro USB connector.


Removing the bottom plate gives a view on the 3.7V 380mAh battery.


And removing the battery shows some of the electronics.


An Arduino on your Wrist

The heart of the T-Watch is the ESP32 microcontroller. This is kind of a (much!!) improved Arduino. This means that it can be programmed via the Arduino IDE and if you have any experience in programming the Arduino, you can directly apply this to the coding of the T-Watch. Most of your Arduino sketches will also run on it. As compared to the Arduino. the ESP32 is much faster (up to 240MHz), has much more memory (16MB of flash memory), plus it has WiFi and bluethooth connectivity built in. In the T-Watch, the ESP32 is connected to an accelerometer, a 240x240 touchscreen, and a 3.7V Li-Ion battery with a capacity of 380mAh. Some of the simple T-Watch codes out there will empty this battery in a few hours, while some (with better power management) can run for a few days without charging.

Setting up the Programming Environment

The programming environment is set up in four small steps.

1. Installing the Arduino IDE

If you have programmed an Arduino before, you already have this, and you can skip to step 3. 
You download the Arduino IDE at https://www.arduino.cc/en/software using the link on the right side for your operating system (Linux, Windows, or Mac) and follow the simple instructions at https://www.arduino.cc/en/Guide.

2. Creating the Sketchbook Folder

After installing the IDE, create a folder "Sketchbook" on your computer. Inside the "Sketchbook" folder, create another folder "libraries" (which you will need later in step 4). Then you start the Arduino IDE, and in the File pull-down menu under Preferences you enter the location of your Sketchbook folder in the box: "Sketchbook location".

 


3. Adding the ESP32 Board in the Board Manager

Initially, the Arduino IDE only knows the details of all Arduino boards, but not the ESP32. Still in the "Preferences", insert the address "https://dl.espressif.com/dl/package_esp32_index.json" (as in the image above), and press "O.k.".
From the Tools menu, hover over the Boards item, and click on the "Boards Manager".


In the search box on the top, search for "ESP32". The pull down menu offers different versions. Pick the latest one and click "Install".


When the ESP32 board manager is installed, click "close".


Now that the information for the ESP32 board in your watch is installed, let's select it. Under Tools and  Board you find a new category "ESP32 Arduino". In there, scroll down until you find "TTGO T-Watch" and select this.


4. Getting the The TTGO T-Watch Library 

Now we get the library that supports the T-Watch from here: https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library


A click on the green "code" button give the option to "Download the .zip [file]". That's what we do - and we store the .zip file in the "libraries" folder that we created inside the Sketchbook folder, in step 2. To make it available to the Arduino IDE, we enter the Sketch menu, and under Include Library select Add ZIP Library.


In the following dialogue we select the .zip file that we stored in the "libraries" folder.

Running the First Example: SimpleWatch

Now that the programming framework is set up, we can upload the first example code onto the T-Watch. From the File menu, select Examples, then go all the way down to TTGO TWatch Library, and under LVGL, select the SimpleWatch example.


The SimpleWatch example code opens (probably in a new window). At the top there are four tabs. Click on the "config.h" tab and uncomment the line "#define LILYGO_WATCH_2020_V1" (by "uncomment" we mean to remove the two "//" on the left).


Now, connect your T-Watch with the USB cable to the USB port of your computer. Then, check to see if the Arduino IDE automatically recognized the port to which the watch is connected.
Click on the Tools menu and hold your mouse over the "Port" item. Now you should see in pop-up that a port is selected.



When you are done, click on the "upload" button (the arrow to the right). This compiles the SimpleWatch example code, and uploads it onto your T-Watch (see below how to fix a frequent error on Linux systems). 

If everything worked, this is what you will see:


Or a closer look, revealing the 240x240 pixels (however, please note that under typical viewing conditions, you do not notice the individual pixels).


Don't expect too much. The SimpleWatch example is rather boring (it's mainly intended to demonstrate some of the library functions). 

But now you know how to use the Arduino IDE to upload any code into the LilyGo T-Watch 2020.






Appendix: Fix for a Frequent Error on Linux Systems

If you are a Linux user (like me), it may happen that you get an error message when trying to upload the code onto your watch for the first time. This is what I got on the very first attempt:

avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied
ioctl("TIOCMGET"): Inappropriate ioctl for device

The solution is to do the following: 

sudo usermod -a -G dialout <user>
sudo chmod a+rw /dev/ttyACM0

where <user> is replaced with your username and "/dev/ttyACM0" is replaced with the port to which your watch is connected. This worked for me.

5 comments:

Anonymous said...

Markus, great tutorial, everything worked like a charm! I had one compile time error cropping up "ImportError: no module named serial", which was easily enough fixed by installing python-serial. I'll make sure to check out your YouTube posts!

Markus said...

I'm glad that it worked for you! Thank you for the feedback. I have no idea how installing a Python module would affect the Arduino IDE - but it's great that you found this bug fix.

Anonymous said...

Markus, without that module, the IDE can't communicate with the watch.

Unknown said...

Hi Marcus. After my own attempts, the screen was black, and I was afraid of not getting the clock running again. But after following your instructions, the clock works again. :-)
Thank you very much.
Greetings Åke B.

Markus said...

Thanbs! Good to hear that I could help to save your watch - and your day!