Giter VIP home page Giter VIP logo

mruby on the ESP32

This is an ESP-IDF project template running mruby on the ESP32 microcontroller.

To get started, you need to install the ESP-IDF, by following the instructions here, for your operating system.

This has been tested on macOS and Ubuntu Linux, using ESP-IDF 5.1.

Usage

Recursively clone this repo to ensure the mruby (3.2.0) submodule gets downloaded:

git clone --recursive https://github.com/mruby-esp32/mruby-esp32.git

The makefile configuration is in main/component.mk. The entry point source file is mruby_main.c. Once that starts, it looks for storage/main.rb and runs it in mruby. You can change the expected filename in mruby_main.c, or simply save your scripts as main.rb inside the storage subfolder.

First Build

idf.py build
idf.py -p $(YOUR_SERIAL_PORT) flash monitor

Your ESP32 should write 2 lines of numbers to the console.

Examples

The folder main/examples includes simple scripts demonstrating functionality.

Once you are familiar with the build process, try them with:

cp main/examples/$(EXAMPLE_FILENAME) main/storage/main.rb
idf.py build
idf.py -p $(YOUR_SERIAL_PORT) flash monitor

Replace EXAMPLE_FILENAME with one of the following:

  • simplest.rb - Prints two strings
  • system.rb - Demonstrates most system APIs
  • gpio.rb - GPIO blink example
  • wifi_connect.rb - Connects to WiFi
  • wifi_socket.rb - Connects to WiFi and makes a TCPSocket connection
  • mqtt_publish.rb - Connects to WiFi and publishes to MQTT broker
  • filesystem.rb - Write/append/read a file on the virtual filesystem
  • ledc_breathe.rb - Gradually fades the brightness of an LED up and down
  • ledc_buzzer.rb - Plays a melody on a piezo-electric buzzer
  • ledc_servo.rb - Controls position of a 180 degree hobby servo motor

Note: Edit GPIO numbers to match ones you are connected to, insert your WiFI credentials, customize MQTT settings etc.

Build Customization

There are multiple gems that can be turned on and off via the mruby configuration file found in components/mruby_component/esp32_build_config.rb:

To get gem changes to reflect in the build, fullclean the previous build, then build again:

idf.py fullclean
idf.py build

All gems are enabled by default, so you can try out the examples, but it's a good idea to disable ones you don't need.

Hardware

Everything works on:

  • Original ESP32: idf.py set-target esp32

Everything except gpio gem works on:

  • ESP32-S2: idf.py set-target esp32s2
  • ESP32-S3: idf.py set-target esp32s3

If you followed the IDF installation instructions correctly for your chip, you can switch the project target with the corresponding command above.

You will not be able to build again until the partition table is reset to partitions.csv. To do this:

idf.py menuconfig
# Partition Table -> Partition Table (1st option) -> Custom partition Table CSV (Last options)
# Enter to select. Q to exit. Y to save

You may also want to manually change other settings like CPU clock speed, watchdog timers, stack sizes etc. Changing the target resets everything to default.

Troubleshooting

The following files and folders are safe to delete when trying to solve build issues:

  • build
  • components/mruby_component/build
  • components/mruby_component/esp32_build_config.rb.lock
  • managed_components
  • dependencies.lock

mruby-esp32's Projects

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.