kramann.info
© Guido Kramann

Login: Passwort:










kramann.info
© Guido Kramann

Login: Passwort:




Writing a Hello world program

(EN google-translate)

(PL google-translate)

Follow the steps below:

  1. Preparations
  2. Testing a sample project
  3. Hello World project
  4. Hello World project WITHOUT simplified user programming layer

1. Preparations

  1. Install the esp32 Board Library 2.09 under Tools->Board Manager.
  2. Download the TTGO_TWatch_Library V1.4.3 from github (see link below).
  3. Unzip the TTGO_TWatch_Library-1.4.3 library here (Linux): /home/fhbstud/Arduino/libraries/.
  4. Download the sample project TWATCH_PROC023.zip from this page.
  5. Unzip TWATCH_PROC023.zip here: /home/fhbstud/Arduino/.

https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library

TTGO_TWatch_Library-1.4.3.zip -- Copy of the required library.
TWATCH_PROC023.zip -- Sample project.

2. Testing a sample project


  1. Connect the watch to your PC using a USB micro cable.
  2. Start the Arduino IDE (development environment).
  3. Under Tools->ESP32 Arduino, select the "TTGO T-WATCH" board (exactly this spelling).
  4. Adjust the settings under Tools as shown below.
  5. Open the sample project TWATCH_PROC023 and transfer it to the watch using the left arrow ("Upload").

Settings under

Bild 0-1: Settings under "Tools." / "Werkzeuge".


Behavior of the watch after successful upload of the sample software: https://youtu.be/xQJAm8CVC_4

  • In mode, when the IMU data is displayed on the watch, it is transferred to a PC via WiFi.
  • This requires that the PC and smartwatch are logged into a hotspot. Hotspot name: hotspotX, password: 12345678
  • On the PC side, the received data can be visualized with the following processing sketch:

TWATCH_PROC005_hotspot.zip -- Processing sketch, please download and unpack in /home/fhbstud/sketchbook/ (Linux).

https://youtu.be/rJJumsD5vB8 -- Presentation on transferring IMU data to a PC via WiFi.

3. Hello World Project

  • To keep things simple at the beginning, all additional libraries from TWATCH_PROC023 are retained in the Hello World program.
  • The easiest way to do this is to save the TWATCH_PROC023 project with File->Save As under the name TWATCH_Hello_World and then make adjustments.
  • In the main tab, the original source code should be replaced with the following:
#include "twatch.h"
#include "variables.h"
#include "functions.h"

void setup() 
{
    setupTWATCH();
    setFont(1, 255,255,255,  255,0,0);
    backlight(true); 
}

void loop() 
{
    text("Hello World!",width/4,height/4);
    delay(100);  
}

Code 0-1: Neuer Quelltext im Tab "TWATCH_Hello_World".


  • The syntax of this source code is based on that of Processing sketches.

compare to: processing.org

Display of the clock after transferring the Hello World program.

Bild 0-2: Display of the clock after transferring the Hello World program.


Screenshot of the project after customization.

Bild 0-3: Screenshot of the project after customization.


TWATCH_Hello_World.zip -- In addition, the Hello World project itself is also made available in its entirety here.



4. Hello World project WITHOUT simplified user programming layer

Using TTGO_TWatch_Library V1.4.3 directly, a Hello World program could look like this:

//#include "twatch.h"
//#include "variables.h"
//#include "functions.h"

#define LILYGO_WATCH_2020_V3  // To use T-Watch2020 V3, please uncomment this line

//für wav:

// Except T-Watch2020, other versions need to be selected according to the actual situation
#if  !defined(LILYGO_WATCH_2020_V1) && !defined(LILYGO_WATCH_2020_V3)

// T-Watch comes with the default backplane, it uses internal DAC
#define STANDARD_BACKPLANE

// Such as MAX98357A, PCM5102 external DAC backplane
// #define EXTERNAL_DAC_BACKPLANE

#else
// T-Watch2020 uses external DAC
#undef STANDARD_BACKPLANE
#define EXTERNAL_DAC_BACKPLANE

#endif

#include <LilyGoWatch.h>

#pragma mark - Depend ESP8266Audio and ESP8266_Spiram libraries


//UDP:
#include "AsyncUDP.h"
#include <WiFi.h>

//RTC time
#include <soc/rtc.h>
#include <time.h>

//Tongenerator
#include <HTTPClient.h>         //Remove Audio Lib error
#include "AudioOutputI2S.h"
#include "AudioFileSourceFunction.h"
#include "AudioGeneratorWAV.h"
#include "AudioOutputI2S.h"

AudioFileSourceFunction* file_wav;
AudioOutputI2S *output_wav;
AudioGeneratorWAV* wav_generator;

AsyncUDP udp;
TTGOClass *watch;
TFT_eSPI *tft;
BMA *sensor;
BackLight *hintergrundlicht; //Um es manipulieren zu können!!!

RTC_Date tnow;

float sine_wave(const float time) {
  float tremolo = 110.f*sin(TWO_PI * 4.f * time);
  float v = sin(TWO_PI * (440.f + tremolo) * time);  // C
//  v=v*v*v;
  v *= fmod(time, 1.f);               // change linear
  v *= 0.5;                           // scale
  return v;
}

void setup() 
{
    watch = TTGOClass::getWatch();
    watch->begin();
    // Turn on the backlight .. aber nicht nur das!!!!
    watch->openBL();
    
    tft = watch->tft;
    sensor = watch->bma;
    hintergrundlicht = watch->bl; //Hintergrundlicht als Objekt verfügbar machen!

    // Accel parameter structure (siehe Kommentare in Originalbeispiel!)
    Acfg cfg;
    cfg.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
    cfg.range = BMA4_ACCEL_RANGE_2G;
    cfg.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
    cfg.perf_mode = BMA4_CONTINUOUS_MODE;

    // Configure the BMA423 accelerometer
    sensor->accelConfig(cfg);

    // Enable BMA423 accelerometer
    sensor->enableAccel();


    // Configure the BMA423 accelerometer
    sensor->accelConfig(cfg);

    // Enable BMA423 accelerometer
    sensor->enableAccel();

    // You can also turn it off
    // sensor->disableAccel();

    // Some display settings
    //tft->setTextColor(random(0xFFFF));
    tft->setTextColor(TFT_GREEN, TFT_BLACK);
    //tft->drawString("BMA423 accel",  25, 50, 4);
    tft->setTextFont(4);
    //tft->setTextColor(TFT_WHITE, TFT_BLACK); 

    //Check if the RTC clock matches, if not, use compile time
    watch->rtc->check();

    //Synchronize time to system time
    watch->rtc->syncToSystem();
    // Get the current data
    
    tnow = watch->rtc->getDateTime();

    //wav Tongenerator
    watch->enableAudio();
    watch->enableLDO3();
    file_wav = new AudioFileSourceFunction(1.);
    file_wav->addAudioGenerators(sine_wave);
    #if defined(STANDARD_BACKPLANE)
        output_wav = new AudioOutputI2S(0, 1);
    #elif defined(EXTERNAL_DAC_BACKPLANE)
        output_wav = new AudioOutputI2S();
    //External DAC decoding
        output_wav->SetPinout(TWATCH_DAC_IIS_BCK, TWATCH_DAC_IIS_WS, TWATCH_DAC_IIS_DOUT);
    #endif
    wav_generator = new AudioGeneratorWAV();
    wav_generator->begin(file_wav, output_wav);
    
    //backlight(true); 
    hintergrundlicht->on();
}

void loop() 
{
    //text("Hello World!",width/4,height/4);
        tft->drawString("Hello world!",  50, 50, 1);     
    //else if(TEXT_ALIGN==CENTER)
    //    tft->drawCentreString(text,  x, y, FONT_NUMBER);     
    
    delay(100);  
}

Code 0-2: Source code for a Hello World project WITHOUT simplified user programming layer.

TWATCH_Hello_World2.zip -- Hello World project WITHOUT simplified user programming layer.