<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Episode 15: Switching screens]]></title><description><![CDATA[<p dir="auto">This example shows how to use multiple GUI-O screens and switch between them.</p>
<p dir="auto">GUI-O supports up to five (5) screens, where widgets can be placed.</p>
<p dir="auto">Switching between screens can be performed in two ways: using the <strong>1. built-in flick functionality</strong> or by creating a <strong>2. flick area widget (FLA)</strong> and reacting to user input on the ESP32 side.<br />
Here, I will only cover only the first option. For the second option, see the GUI-O developer manual (hint: see section <strong>Multiple screen support</strong>).</p>
<p dir="auto"><strong>I will be using GUI-O Bluetooth Low Energy (LE) connection, but the example can be easily be ported to other connection types.</strong></p>
<p dir="auto"><strong>Software prerequisites:</strong></p>
<ul>
<li>
<p dir="auto">Arduino IDE (<a href="https://www.arduino.cc/en/software" rel="nofollow ugc">https://www.arduino.cc/en/software</a>)</p>
</li>
<li>
<p dir="auto">ESP32 Arduino board support, if using ESP32 based board (see <a href="https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html" rel="nofollow ugc">https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html</a>)</p>
</li>
<li>
<p dir="auto">GUI-O design tool (<a href="https://www.gui-o.com/design-tool" rel="nofollow ugc">https://www.gui-o.com/design-tool</a>)</p>
</li>
<li>
<p dir="auto">GUI-O application (<a href="https://play.google.com/store/apps/details?id=com.guio.guioapp" rel="nofollow ugc">https://play.google.com/store/apps/details?id=com.guio.guioapp</a>)</p>
</li>
<li>
<p dir="auto">For additional information about the GUI-O application, download the developer manual from <a href="https://www.gui-o.com/" rel="nofollow ugc">https://www.gui-o.com/</a></p>
</li>
</ul>
<p dir="auto"><strong>Components needed:</strong></p>
<ul>
<li>ESP32-WROOM-32 (or any other Arduino supported Bluetooth Low Energy capable board)</li>
</ul>
<p dir="auto"><strong>The entire tutorial is split into various steps. All necessary information is given in each step</strong>.</p>
<h3>0. DESIGN THE GUI (optional)</h3>
<p dir="auto">The best way to create a GUI layout is to use GUI-O live designer tool.</p>
<p dir="auto">Note that the Arduino source code already includes the necessary commands, so this step is not needed, unless you want to make some visual adjustments. If you make adjustments, please include the generated ASCII code in the Arduino source code (see section 1. UPLOAD THE SOURCE CODE).</p>
<p dir="auto">First, you need to establish a TCP/IP connection between the designer tool and GUI-O application:</p>
<ol>
<li>Determine the local IP address of your PC's network interface (WiFi or Ethernet)</li>
</ol>
<ul>
<li>Under Windows, open the command prompt, enter <code>ipconfig</code> and press Enter</li>
<li>Under Linux, open the terminal, enter <code>ifconfig</code> and press Enter</li>
</ul>
<ol start="2">
<li>
<p dir="auto">Open GUI-O application and open settings menu. Select "Connections -&gt; Ethernet" and create a new device with IP address (determined from 1.) and any port between 49152 - 65535</p>
</li>
<li>
<p dir="auto">Open GUI-O designer and select "TCP/IP connection" tab. Set the IP address and port. Both values must match the device settings created within the GUI-O application. Click "Start server" button.</p>
</li>
<li>
<p dir="auto">Within the GUI-O application, tap the created device and wait for successful connection.</p>
</li>
<li>
<p dir="auto">In the GUI-O designer, select "File -&gt; Load designer file" and load the <a href="https://drive.google.com/uc?export=download&amp;id=1Wibvm1KOTWrDJcXaZLgwXUd9DX0DB3bm" rel="nofollow ugc">SwitchScreen.gdf</a> design file. Make the desired adjustments, if necessary. Copy / replace the GUI-O commands into the Arduino source code (see section 1. UPLOAD THE SOURCE CODE).</p>
</li>
</ol>
<h3>1. UPLOAD THE SOURCE CODE</h3>
<p dir="auto">The source code has inline comments, describing the important parts of the code. You can copy the source code from the snippet below, or download it <a href="https://drive.google.com/uc?export=download&amp;id=1NR_U0IxjOKxjA1hndTNsFEuczgZrUM4a" rel="nofollow ugc">here</a>.</p>
<p dir="auto">Upload the code to your board (make sure that the correct board and upload port are selected). Reset the board after upload.</p>
<pre><code>/*
 * GUI-O Switch screen Bluetooth example (using ESP32-WROOM-32)
 *
 * Copyright (C) 2023, kl3m3n
 * last updated on 01.04.2023
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include &lt;BLEDevice.h&gt;
#include &lt;BLEServer.h&gt;
#include &lt;BLEUtils.h&gt;
#include &lt;BLE2902.h&gt;

namespace uuid {
  static const char *SERVICE_UUID = "6E400001-B5A3-F393-E0A9-E50E24DCCA9E";
  static const char *RX_CHARACTERISTIC_UUID = "6E400002-B5A3-F393-E0A9-E50E24DCCA9E";
  static const char *TX_CHARACTERISTIC_UUID = "6E400003-B5A3-F393-E0A9-E50E24DCCA9E";
} // namespace uuid

// forward declare parser for incoming messages
void parseGuioMsg(const String &amp;msg);

// setup done flag
bool setupDone = false;

// custom handling of server callbacks
class CustomBLEServerCallbacks: public BLEServerCallbacks {
    void onConnect(BLEServer* pServer) {
      Serial.println("Connected!");
    };
    void onDisconnect(BLEServer* pServer) {
      Serial.println("Disconnected!");
      
      // restart advertising after disconnect, otherwise GUI-O cannot re-connect
      if(setupDone) {
        // restart advertising on disconnect
        delay(500);
        pServer-&gt;startAdvertising(); 
      }
    }
};

// custom handling of characteristic callbacks
class CustomBLECharacteristicCallbacks: public BLECharacteristicCallbacks {
  void onWrite(BLECharacteristic *pCharacteristic) {
    std::string msg = pCharacteristic-&gt;getValue();
    
    // parse message string
    parseGuioMsg(String(msg.c_str()));
  }      
};

// global ptr
BLECharacteristic *pTxCharacteristic;

void setup() {
  // debug output
  Serial.begin(115200);

  // create device
  BLEDevice::init("SwitchScreen");
  // create server and register callback
  BLEServer *pServer = BLEDevice::createServer();
  pServer-&gt;setCallbacks(new CustomBLEServerCallbacks());
  // create service
  BLEService *pService = pServer-&gt;createService(uuid::SERVICE_UUID);

  // crate Tx characteristic and add descriptor
  pTxCharacteristic = pService-&gt;createCharacteristic(uuid::TX_CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_NOTIFY);
  pTxCharacteristic-&gt;addDescriptor(new BLE2902());
  
  // crate Rx characteristic and register callback
  BLECharacteristic *pRxCharacteristic = pService-&gt;createCharacteristic(uuid::RX_CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_WRITE_NR);
  pRxCharacteristic-&gt;setCallbacks(new CustomBLECharacteristicCallbacks());

  // start the service and start advertising
  pService-&gt;start();
  pServer-&gt;getAdvertising()-&gt;start();

  // setup done flag
  setupDone = true;
}

void loop() {
  
}

void sendMsg(const String &amp;msg) {
  pTxCharacteristic-&gt;setValue(std::string(msg.c_str()));
  pTxCharacteristic-&gt;notify();
  delay(50);
}

void parseGuioMsg(const String &amp;msg) {
  if(msg.startsWith("@init")) {
    Serial.println("GUI-O app is requesting INITIALIZATION!");

    // clear screen and set background
    sendMsg("@cls\r\n");
    sendMsg("@guis BGC:#FFFFFF PGF:1\r\n");
    delay(100);

    // initialize GUI
    sendMsg("|LB UID:title X:50 Y:20 FSZ:4 FFA:\"font8\" TXT:\"Switch&lt;br&gt;screen\"\r\n");
    sendMsg("|LB UID:home X:50 Y:50 FGC:#607196 SHE:1 SHC:#FFC759 FSZ:5 FFA:\"font1\" TXT:\"HOME SCREEN\"\r\n");
    sendMsg("|LB UID:screen1 X:50 Y:50 FGC:#607196 SHE:1 SHC:#FFC759 FSZ:5 FFA:\"font1\" TXT:\"SCREEN 1\" SCI:1\r\n");
    sendMsg("|LB UID:screen2 X:50 Y:50 FGC:#607196 SHE:1 SHC:#FFC759 FSZ:5 FFA:\"font1\" TXT:\"SCREEN 2\" SCI:2\r\n");
    sendMsg("|LB UID:screen3 X:50 Y:50 FGC:#607196 SHE:1 SHC:#FFC759 FSZ:5 FFA:\"font1\" TXT:\"SCREEN 3 ...\" SCI:3\r\n");
    sendMsg("|LB UID:details X:50 Y:90 FSZ:2 TXT:\"GUI-O switch screen&lt;br&gt;demonstration by kl3m3n\"\r\n");    
  }
}
</code></pre>
<h3>2. ESTABLISH CONNECTION</h3>
<p dir="auto">Open GUI-O application and press <strong>Add</strong> in the upper-right corner of the home screen. Tap on <strong>Bluetooth LE</strong> and search for devices (enable Bluetooth and Location services, if prompted). Tap on the "SwitchScreen" device, select <strong>Nordic UART service</strong> and wait for successful connection (confirm device pairing if prompted).</p>
<p dir="auto">Close the settings menu and press the <strong>Initialize</strong> button (see image below) from the GUI-O application home screen.</p>
<p dir="auto"><img src="https://i.imgur.com/DDEHAR7l.jpg" alt="initialize_button.jpg" class=" img-fluid img-markdown" /></p>
<h3>3. THE RESULT</h3>
<p dir="auto">Image below shows the result (screen capture) on my Android device after pressing the "Initialize" button. The bottom screen indicator indicates the number of screens and the currently active screen. Navigation between screens is possible by flicking left or right at the bottom of the screen. This is shown in the video below.</p>
<p dir="auto"><img src="https://i.imgur.com/3wqnmKql.jpg" alt="screen.jpg" class=" img-fluid img-markdown" /></p>
<p dir="auto"></p><div class="video-embed"><iframe allowfullscreen src="//www.youtube.com/embed/pbN5Mbvrk7U"></iframe></div><p></p>
<hr />
<p dir="auto">If you have any questions or run into any problems, please let me know!</p>
<p dir="auto">Best regards,<br />
kl3m3n</p>
]]></description><link>https://forum.gui-o.com/topic/128/episode-15-switching-screens</link><generator>RSS for Node</generator><lastBuildDate>Fri, 12 Jun 2026 17:28:55 GMT</lastBuildDate><atom:link href="https://forum.gui-o.com/topic/128.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 01 Apr 2023 10:03:50 GMT</pubDate><ttl>60</ttl></channel></rss>