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.
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.
For wiring the LED on a breadboard, follow these steps:
This setup will allow you to blink an LED using Xedge32.
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 end end timer=ba.timer(blink) -- Create timer timer:set(1000) -- Timer tick = one second
Here's a step-by-step breakdown of the above code:
The script defines a local function named
blink . This function is designated to handle the LED's blinking behavior.
Utilizing Coroutines for Timing:
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).
New Folderon the context menu.
blinkas the new folder name and click Enter.
Disk, right-click the
blinkdirectory, and click New App in the context menu.
Runningbutton and click Save.
blinkapp now visible in the left pane tree view. The
blinkapp should be green, indicating the app is running.
blinkapp and click
New Fileon the context menu.
blinkled.xluaand click Enter.
blinkled.xluafile to open the file In Xedge.
Save & Runbutton to save and start the blink LED example.
The following video includes additional information on how to create Xedge applications:
Xedge32 is comprised of three components:
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.
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.
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!
Expedite your IoT and edge computing development with the "Barracuda App Server Network Library", a compact client/server multi-protocol stack and toolkit with an efficient integrated scripting engine. Includes Industrial Protocols, MQTT client, SMQ broker, WebSocket client & server, REST, AJAX, XML, and more. The Barracuda App Server is a programmable, secure, and intelligent IoT toolkit that fits a wide range of hardware options.
SharkSSL is the smallest, fastest, and best performing embedded TLS stack with optimized ciphers made by Real Time Logic. SharkSSL includes many secure IoT protocols.
SMQ lets developers quickly and inexpensively deliver world-class management functionality for their products. SMQ is an enterprise ready IoT protocol that enables easier control and management of products on a massive scale.
SharkMQTT is a super small secure MQTT client with integrated TLS stack. SharkMQTT easily fits in tiny microcontrollers.
An easy to use OPC UA stack that enables bridging of OPC-UA enabled industrial products with cloud services, IT, and HTML5 user interfaces.
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.
Learn how to use the Barracuda App Server as your On-Premises IoT Foundation.
The compact Web Server C library is included in the Barracuda App Server protocol suite but can also be used standalone.
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.
Why use FTP when you can use your device as a secure network drive.
PikeHTTP is a compact and secure HTTP client C library that greatly simplifies the design of HTTP/REST style apps in C or C++.
The embedded WebSocket C library lets developers design tiny and secure IoT applications based on the WebSocket protocol.
Send alarms and other notifications from any microcontroller powered product.
The RayCrypto engine is an extremely small and fast embedded crypto library designed specifically for embedded resource-constrained devices.
Real Time Logic's SharkTrust™ service is an automatic Public Key Infrastructure (PKI) solution for products containing an Embedded Web Server.
The Modbus client enables bridging of Modbus enabled industrial products with modern IoT devices and HTML5 powered HMIs.