Your First Xedge32 Project

An Introduction to Device Management with Lua

As you learned in the Xedge32 introduction, this development environment streamlines IoT projects by seamlessly connecting Lua to the ESP32's extensive features. By enabling all device-specific code to be written in the user-friendly Lua language, Xedge32 makes the development process simpler and faster. In this first tutorial, we'll walk you through a basic example that blinks an LED. We'll connect the LED to a GPIO pin and demonstrate how to control it using Lua.

For this tutorial, all you need is an ESP32 development board (ideally the latest ESP32-S3), a breadboard, and an LED. A beginner-friendly breadboard allows you to create circuits without soldering, making it great for trying out ideas. Starting with an LED is an excellent choice for your first project, as it's easy to use and gives you quick visual feedback. While LEDs often come included in DIY electronics kits, you can also purchase them separately. If you're looking for a one-stop solution, complete kits are available on Amazon.

Once you have all the components, set them up as shown in the diagram below. Although we include a resistor in the design to protect the LED from too much current, we've often set up LEDs without one for simple examples.

ESP32 LED Wiring

Figure 1: How to connect all components using a breadboard.

The connectors in the diagram are just to guide you. In practice, you can use Jumper Wires to connect everything easily. The next image shows how Jumper Wires make setting up the components straightforward, using another ESP32 example for reference.

How to use Jumper Wires to wire an ESP32

Figure 2: An example showing how to use Jumper Wires to connect components.

For wiring the LED on a breadboard, follow these steps:

  1. Connect the LED's negative pin (cathode), typically marked by a flat edge, to a 100Ω resistor. If you prefer not to use a resistor, you can connect it directly to one of the ESP32's ground (GND) pins.
  2. If you used a resistor, attach its free end to one of the ESP32's ground (GND) pins.
  3. Connect the LED's positive pin (anode), usually identified by a rounded edge, to GPIO 4 on the ESP32. The GPIO pins are marked on most ESP32 development boards for easy identification.

This setup will allow you to blink an LED using Xedge32.

The Lua blink LED script:

You only need a few lines of Lua code to blink an LED. Lua is an exceptionally intuitive language, making it easy even for beginners to pick up. If you need a deeper understanding beyond our brief explanation below, you can delve into our online Lua tutorial for more guidance.

local function blink()
   local pin = esp32.gpio(4,"OUT")
   while true do
      pin:value(true) -- On
      coroutine.yield(true) -- Sleep for one timer tick
      pin:value(false) -- Off
      coroutine.yield(true) -- Sleep
timer=ba.timer(blink) -- Create timer
timer:set(1000) -- Timer tick = one second

Here's a step-by-step breakdown of the above code:

  • Function blink:
    The script defines a local function named blink . This function is designated to handle the LED's blinking behavior.

  • Utilizing Coroutines for Timing:
    Within the blink function, an infinite loop ( while true do ) uses the Lua Coroutines concept for its timing mechanism. Specifically, coroutine.yield(true) is employed to make the function "sleep" for a specified duration. In this context, it pauses the loop between LED state changes for one second.

  • LED State Control:
    The loop inside the blink function manages the LED's state. It first turns the LED on with pin:value(true) , sleeps for a second, turns it off with pin:value(false) , and then sleeps for another second. This on-off cycle continues indefinitely, creating the blink effect.

  • GPIO Port 4 Initialization:
    Before the blinking starts, the GPIO port 4 is set up as an output using esp32.gpio(4,"OUT") and is referenced by the pin variable. If your LED is connected to a different GPIO port, you must modify this number.

  • Creating The Timer:
    The code lines 10 and 11 outside the function create the timer and initializes the blinking pattern, setting the timer to trigger the blink function every 1000 milliseconds (every second).

Lua blink LED script References:

How to create the Xedge blink LED app:

  1. Install the Xedge32 IDE.
  2. When the Xedge32-powered ESP is running, use a browser, navigate to the ESP32's IP address, and click the Xedge IDE link to start the Xedge IDE.
  3. Create a new Xedge app as follows:
    1. Right-click Disk and click New Folder on the context menu.
    2. Enter blink as the new folder name and click Enter.
    3. Expand Disk , right-click the blink directory, and click New App in the context menu.
    4. Click the Running button and click Save.
  4. Expand the blink app now visible in the left pane tree view. The blink app should be green, indicating the app is running.
  5. Right-click the blink app and click New File on the context menu.
  6. Type blinkled.xlua and click Enter.
  7. Click the new blinkled.xlua file to open the file In Xedge.
  8. Select all and delete the template code.
  9. Copy the above blink LED Lua code and paste the content into the Xedge editor.
  10. Click the Save & Run button to save and start the blink LED example.

The following video includes additional information on how to create Xedge applications:

Understanding the Xedge32 Ecosystem: How It Fits with Barracuda App Server and Xedge

Xedge32 is comprised of three components:

  • The Barracuda App Server serves as a comprehensive foundation for developing embedded systems and IoT applications, providing features like web server capabilities, data encryption, and multiple protocol support. It sets the stage for creating secure and scalable IoT solutions.
  • Xedge builds upon this foundation as a generic, non-ESP32-specific Lua development platform. It accelerates the development process by allowing rapid prototyping without requiring full compile and deploy cycles.
  • Finally, Xedge32 is explicitly tailored for the ESP32 microcontroller. It utilizes the Xedge framework, which in turn is built upon the Barracuda App Server. By leveraging the Lua programming language, Xedge32 enables easy access to ESP32's hardware capabilities, such as its GPIOs, and provides a smooth development experience for both professionals and hobbyists. This makes it particularly useful for ESP32 IoT projects that integrates with systems like Home Assistant, Azure, and Amazon.

To summarize, the Barracuda App Server is the foundational layer, Xedge offers a versatile Lua development environment, and Xedge32 is the specialized version for the ESP32 platform.

Xedge32 Documentation:

What's Next?

You can find more Xedge32 examples on GitHub to help you learn. However, please note that Xedge32 is a new tool, and currently, the examples are not supported by full tutorials. Stay tuned for more detailed guides as we find time to create them.

Discover More:

No matter what your background or project goals, we're here to help you find the perfect solution! Are you a maker looking for the right tools? A startup trying to get off the ground? A large business seeking new software solutions? We've got you covered.

If you have any questions or just aren't sure which product is right for you, don't hesitate to reach out. Our team is dedicated to helping you overcome your hardware/software challenges and find the best solution for your needs. Let us know how we can help - we'd love to lend a hand!


OPC-UA Client & Server

An easy to use OPC UA stack that enables bridging of OPC-UA enabled industrial products with cloud services, IT, and HTML5 user interfaces.

Edge Controller

Edge Controller

Use our user programmable Edge-Controller as a tool to accelerate development of the next generation industrial edge products and to facilitate rapid IoT and IIoT development.

On-Premises IoT

On-Premises IoT Platform

Learn how to use the Barracuda App Server as your On-Premises IoT Foundation.

Embedded Web Server

Barracuda Embedded Web Server

The compact Web Server C library is included in the Barracuda App Server protocol suite but can also be used standalone.

WebSocket Server

Microcontroller Friendly

The tiny Minnow Server enables modern web server user interfaces to be used as the graphical front end for tiny microcontrollers. Make sure to check out the reference design and the Minnow Server design guide.

WebDAV Server

Network File System

Why use FTP when you can use your device as a secure network drive.

HTTP Client

Secure HTTP Client Library

PikeHTTP is a compact and secure HTTP client C library that greatly simplifies the design of HTTP/REST style apps in C or C++.

WebSocket Client

Microcontroller Friendly

The embedded WebSocket C library lets developers design tiny and secure IoT applications based on the WebSocket protocol.

SMTP Client

Secure Embedded SMTP Library

Send alarms and other notifications from any microcontroller powered product.

Crypto Library

RayCrypto C Library

The RayCrypto engine is an extremely small and fast embedded crypto library designed specifically for embedded resource-constrained devices.

Embedded PKI Service

Automatic SSL Certificate Management for Devices

Real Time Logic's SharkTrust™ service is an automatic Public Key Infrastructure (PKI) solution for products containing an Embedded Web Server.


Modbus TCP client

The Modbus client enables bridging of Modbus enabled industrial products with modern IoT devices and HTML5 powered HMIs.

Posted in Xedge32