Showing posts with label T-Watch 2020. Show all posts
Showing posts with label T-Watch 2020. Show all posts

Wednesday, March 10, 2021

LilyGo T-Watch 2020 goes Back to The Future



The LilyGo T-Watch 2020 hit the market in May 2020. A programmable watch with reasonably small size (looking somehow like the Apple watch), based on the ESP32 processor with an accelerometer, plus Wifi and Bluetooth connectivity at a price of only $30-$40.

When I bought mine in December 2020, I thought I was already late to the party. But then, I started to search the web for great watch faces for the T_Watch and I did not find much. So, I decided to make my own, and share this. Being a fan of the "Back to the Future" trilogy, in which the topic of "time" is omnipresent, I decided to make a Back-to-the-Future fun watch - and to share this.

This watch is not a smart watch! It does neither use the Wifi nor Bluetooth connectivity of the watch (I wouldn't know what I would use this for anyway). This watch will just be fun to look at, and without WiFi and Bluetooth, but with a good power management, the watch will be able to run three or four days without charging.

T-Watch 2020 with Back-to-the-Future Time Circuits watch face

Setting up the programming environment

The very first step is to install and set up the Arduino IDE. I have described this in detail in another blog post: Lilygo TTGO T-Watch 2020: Getting Started / The Software Framework.


References

While I did not find many great watches, I found plenty of good information and example codes that helped me to understand specific details of the watch. The power management, in particular, is very important, in order to get a watch that does not have to be charged every day. Here I'm listing some references that were valuable and from which I benefited a lot when writing my code.

  • The SimpleWatch example that comes with the TTGO T-Watch library
  • A series of articles at diyprojects.io (also check the links to their other articles)
  • The code for "aGoodWatch" from Alex Goodyear
  • The article and code at instructables.com by Dan Geiger
  • An interesting "Wordclock" by instructable.com user ArduinoAndy

Requirements

As mentioned above, I wanted this to be a fun watch that can be used in every day life, which means that it needs a very efficient power management. Therefore, in this project I am not using the WiFi and Bluetooth which helps a lot to save power. It allows to reduce the CPU frequency of the watch (from nominal 80MHz out of a max of 240MHz) down to 30MHz. The graphics are all programmed using the TFT_eSPI library. In contrast to many common example codes that have tiny buttons in their settings menus, the Back-to-the-Future watch has large buttons which can easily accessed. 


Features

My Back-to-the-Future watch code features five different watchfaces, a stop watch, and a settings menu with four screens (two to customize the display, and two to set time and date). The different categories can be thought of as three rows: The middle one has the watch faces, to top one the stopwatch, and the bottom row the settings menu.
The watch can be in three states: 
  1.  Full operation with the display on 
  2.  After a few seconds of full operation, it turns to light sleep from which it can be quickly awakened. This is done either by a press on the button at the top right - a quick(!) double tap - or by rapidly moving the watch upwards and rotating it towards you.
  3. To save power (e.g. over night) the watch can be set to deep sleep, by pressing the button for 5 seconds. It takes another (approx. 2 sec) press of this button to wake it up, which takes about 5 seconds.
In a very bright environment, you can use a double tap on the screen to get the maximum screen brightness. The next time when the watch returns from light sleep, the brightness is back at the normal value.

Watchfaces

The watchfaces, include a fluxing flux capacitor, the time circuits (with the current date/time in the middle row, plus typical movie dates in the top/bottom rows), the speedometer plus the plutonium gauges, the SID spectrometer, and the entrance sign to the Mall (which randomly appears as either "Twin Pines Mall" or "Lone Pine Mall"). 


T-Watch 2020 with Back-to-the-Future watch faces

T-Watch 2020 with Back-to-the-Future watch faces

The user can cycle through those with horizontal swipes. There are three different modes of operation: Whenever the watch returns from light sleep it either presents you with a random face (a: random), the next face (b: cycle), or the same face that was displayed before it went to sleep (c: "fixed").

Stopwatch

If you swipe to the top row, you get the stopwatch, which is modeled after the one Doc Brown uses in his experiment with Einstein (except for the display color, since yellow is much brighter than red).


Menu with Settings

When, starting from the watchfaces, you swipe to the bottom row, you get an "entry" screen: "Enter the Settings - swipe" from which you can swipe into the settings. The additional entry screen prevents you from erroneously entering the actual settings and from unwanted changes of your setup.

Swiping to the right, you get to part one of the display settings where you can select 
  • how the watchfaces are diplayed (random, cycle, fixed - as described above) 
  • the format in which the time is displayed: 12h, 12h plus seconds, or 24h format
  • if the stepcounter is shown in the top left corner (on/off)
  • if the remaining battery percentage is dislayed in the top right corner (on/off) 


On part two of the display settings you can select
  • how long the watch stays on: 7 sec, 12 sec, or 20 sec (I prefer 7 sec which is long enough for me to read the time. I used 20 sec to make the video, without the watch turning off all the time. I also use the 20 sec setting if I just enjoy looking at the watch...)
  • three levels of brightness (low, med, high)
  • if you want the display to dim at night (between 10pm and 7am).
On the next two screens, you can set the time and date. Any changes that are made with the "+" and "-" buttons are only stored when the "SET TIME" and "SET DATE" buttons are pressed.  


Swiping to the row above brings you back to the watchfaces.

Installing the Code

The code can be obtained from my github repository https://github.com/mawob/bttfWatch.
From the green "Code" pulldown menu, select "Download ZiP"


Unzipping the file creates a folder "bttfWatch-main" which has all the relevant files. Rename the folder from "bttfWatch-main" to "bttfWatch" and move this into the Sketchbook folder of your Arduino IDE. Then open it from the File menu, connect your watch, upload, and enjoy your new watchface!
 


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.