Arduino & ESP32 - Basic USB
-
GUI-O + Arduino + ESP32
Developer manual: https://www.gui-o.com/assets/gui-o_developer_manual.pdf
A DEMO project to help you quickly get started with GUI-O and USB using Esp32 board. You can expand the example for your specific project.
Download BasicUSB.ino sketch from:
https://drive.google.com/file/d/1IvShiEMM2jK9O2V9xGfT7XTkV95Iwk6m/view?usp=sharingAdditional Boards Manager URLs:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json/* * GUI-O Basic USB example * * Copyright (C) 2021, GUI-O Team * * SPDX-License-Identifier: BSD-3-Clause */ namespace led { static const uint8_t LED_BUILTIN = 2; static const uint8_t LED_CHANNEL = 0; static const double LED_FREQ = 5000.0; static const uint8_t LED_BITS = 8; } // namespace led // forward declare parser for incoming messages void parseGuioMsg(const String &msg); // icoming data buffer String in; void setup() { // setup serial Serial.begin(115200); // setup builtin led ledcSetup(led::LED_CHANNEL, led::LED_FREQ, led::LED_BITS); // channel, freq, resolution_bits ledcAttachPin(led::LED_BUILTIN, led::LED_CHANNEL); } void loop() { while(Serial.available()) { const char c = Serial.read(); in += c; if(c == '\n') { // parse message string parseGuioMsg(in); // clear buffer in = ""; } } } /***************************/ /* IMPLEMENT YOUR GUI HERE */ /***************************/ void parseGuioMsg(const String &msg) { if(msg.startsWith("@init")) { // clear screen and set background Serial.print("@cls\r\n"); Serial.print("@guis BGC:#FFFFFF\r\n"); delay(100); // initialize simple example GUI Serial.print("|LB UID:title X:50 Y:15 TXT:\"Simple light switch\" FFA:\"font8\" FSZ:3.5\r\n"); Serial.print("|LB UID:tap_me X:50 Y:70 TXT:\"TAP ME!\" FFA:\"font8\" FSZ:3 FFA:\"font5\"\r\n"); Serial.print("|CB UID:brightness X:50 Y:50 W:90 BTH:5 HAH:8 HAW:8 VIS:0 STA:135 ENA:45 FGC:#000000 SFGC:#FFFF00 BGC:#CBCBCB\r\n"); Serial.print("|IM UID:light_off X:50 Y:50 IP:\"https://i.imgur.com/3VbsS0Z.png\" VIS:1\r\n"); Serial.print("|IM UID:light_on X:50 Y:50 IP:\"https://i.imgur.com/gNdck9A.png\" VIS:0\r\n"); } else if(msg.startsWith("@light_off")) { // "drive GUI-O app" Serial.print("@light_off VIS:0\r\n"); Serial.print("@light_on VIS:1\r\n"); Serial.print("@brightness VIS:1 VAL:100\r\n"); // led enable ledcWrite(led::LED_CHANNEL, 255); } else if(msg.startsWith("@light_on")) { // "drive GUI-O app" Serial.print("@light_off VIS:1\r\n"); Serial.print("@light_on VIS:0\r\n"); Serial.print("@brightness VIS:0 VAL:0\r\n"); // led disable ledcWrite(led::LED_CHANNEL, 0); } else if(msg.startsWith("@brightness")) { const int idx = msg.indexOf(' '); if(idx > 0) { const int val = msg.substring(idx + 1).toInt(); if(val >= 0 && val <= 100) { // led drive ledcWrite(led::LED_CHANNEL, static_cast<uint8_t>(val * 2.55)); } } } }