Build a mruby development environment for ESP32 (Linux)

Overview

Build a mruby development environment for ESP32 on Linux.

Building a mruby development environment for ESP32 on Mac --Qiita Before writing, I couldn't find an article written for Mac, so I actually tried it on Linux.

I couldn't build it on the way, so I tried it on a Mac, but in the end I got stuck for the same reason and solved it. Since it is a good idea, we will also release the Linux version. (The flow is the same, but the commands etc. are slightly different)

Prerequisites

I'm building a Linux virtual machine in Parallels and building it on top of it.

The Linux distribution and version used.

$ cat /etc/lsb-release
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=19.2
DISTRIB_CODENAME=tina
DISTRIB_DESCRIPTION="Linux Mint 19.2 Tina"

The target device is M5Stack.

procedure

Linux mint virtual machine creation

I don't usually use Linux, so I tried using Linux mint, which I had never installed before, by referring to the site below.

[By purpose] 7 recommended Linux distributions for beginners

Just follow the Parallels Installation Assistant and select your distribution and it will create it almost automatically.

I didn't know that there is also a free version called Parallels Lite, which also seems to be able to create a virtual environment for Linux.

Image from Gyazo

ESP-IDF development environment construction

The cross development environment called ESP-IDF is used as in the case of Mac.

We will proceed according to the official document, but it is necessary to prepare various commands in advance.

Get Started — ESP-IDF Programming Guide v4.1-dev-1066-g93a8603c5 documentation

Installation of commands

@GORO_Neko wrote the necessary commands in the article below, so I will refer to that.

Run an application made from Ruby language code on ESP-WROOM-32 (ESP32) using mruby-esp32 --Qiita

However, when I run `sudo apt install`, I get 404 Not Found``` and I have to update apt.

$ sudo apt update

Install the necessary commands as shown below. (The one that was not included and the one that was upgraded.) These days it's not apt get but ```apt install `` `.

$ sudo apt install git
$ sudo apt install libncurses-dev
$ sudo apt install gperf
$ sudo apt install python-pip
$ sudo apt install python-serial
$ sudo apt install python-dev
$ sudo apt install grep
$ sudo apt install automake
$ sudo apt install texinfo
$ sudo apt install help2man
$ sudo apt install libtool
$ sudo apt install libtool-bin
$ sudo apt install cmake
$ sudo apt install ruby

ESP-IDF source code set Clone

From here on down is roughly the same as the Mac version. Clone from github into the esp directory according to the documentation.

$ mkdir ~/esp
$ cd ~/esp
$ git clone --recursive https://github.com/espressif/esp-idf.git

ESP-IDF setup

$ cd ~/esp/esp-idf
$ ./install.sh

~/.Add the following line to bashrc.



. $HOME/esp/esp-idf/export.sh


 Restart the terminal or run `` `source ~ / .profile``` to reflect.


### hello world copy of sample project

 Copy the hello world sample provided by esp-idf.

$ cd ~/esp $ cp -r $IDF_PATH/examples/get-started/hello_world .


 Configuration

 Launch menuconfig prior to building.

$ cd ~/esp/hello_world $ idf.py menuconfig


 When it starts normally, the following screen will appear.
 If this screen appears, the work up to this point has been completed without any problems.

 ![Image from Gyazo](https://i.gyazo.com/3f103b64419f8f92094202d301e90d9f.png)

 It seems that various conditions are set on this screen, but here it ends once with the ESC key.
 Press Y in the exit dialog just in case to save.


### Build

 The command below will build the hello world project.

$ idf.py build


### Upload to the actual machine

 Connect [M5Stack](https://www.switch-science.com/catalog/3647/) with a USB cable.
 Check the connected port. Usually it looks like ``` / dev / ttyUSB0```.

$ ls /dev/ttyU* /dev/ttyUSB0


 To upload the program, execute the command below.

$ idf.py -p /dev/ttyUSB0 flash


 However, I got an Error with Permission denied.

serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'



#### **`The user who is logged in to the dialout group because it is dialout and does not seem to have access rights.(parallels)To add.`**
```/dev/ttyusb0 owner is root

$ sudo usermod -aG dialout parallels


 Reboot now. (Maybe you just have to log in again.)



#### **`It will be reset to dialout, so you will have to chown every time, so it is better to put it in a group.`**
```/dev/I could have changed the owner of ttyusb0, but when I plug in and unplug the device, the owner becomes root.

 I will upload it again.

$ idf.py -p /dev/ttyUSB0 flash


 This time it worked.

### Program operation check

 You can check the output of the program with monitor.

idf.py -p /dev/ttyUSB0 monitor


 You can see that Hello world! And chip information are output.

Hello world! This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 2MB external flash Restarting in 10 seconds... Restarting in 9 seconds... Restarting in 8 seconds...


 Now you can check from project build to execution with ESP-IDF.


## mruby build

### Clone the source code

 Clone the source code according to the documentation on [GitHub mruby-esp32](https://github.com/mruby-esp32/mruby-esp32)

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


### Build

 Build with make as documented.
 MRUBY_EXAMPLE = simplest_mrb.rb seems to specify the mruby file to use from some samples.

 As with the Mac version, an error will occur when checking the -W option, so set CFLAGS to disable the check before making.

$ export CFLAGS="-Wno-error=format-overflow=" $ make MRUBY_EXAMPLE=simplest_mrb.rb


### Communication port settings

```menuconfig```Sets the port used for communication with, but the default is```/dev/ttyusb0```Since it is set to, you do not usually need to set it.

 If the communication port is not `` `/ dev / ttyUSB0```, set it according to the procedure below.

$ make menuconfig


```menuconfig```When is started, set as follows.

 1. Select __Serial flasher config ---> __
 2. Select __ (/ dev / ttyUSB0) Default serail port) __
 3. Enter the port you want to use.
 4. Press __ESC__ twice and then press __Y__ in the dialog to save.

### Program writing and operation check

 [simplest_mrb.rb](https://github.com/mruby-esp32/mruby-esp32/blob/master/main/examples/simplest_mrb.rb) If you check the files, you will see 1234 and 4321 as shown below. It is designed to output two lines.

puts "1234" puts "4321"


 Run the flash and monitor tasks to write and verify the program.

$ make MRUBY_EXAMPLE=simplest_mrb.rb flash monitor


 When I check the output, it seems to be working normally.

I (542) cpu_start: Starting scheduler on PRO CPU. I (0) cpu_start: Starting scheduler on APP CPU. I (370) mruby_task: Loading binary... 1234 4321 I (390) mruby_task: Success


 So the mruby program was executed safely like the Mac version.


# Relation

 Mac version.

 -[Building a mruby development environment for ESP32 on Mac --Qiita](https://qiita.com/katsuyoshi/items/dc0aed3aeb35d8a0ebcb)


# reference

 I referred to the following site. (Although it looks like a summary site ...)
 Thank you very much.


 -[Run an application made from Ruby language code on ESP-WROOM-32 (ESP32) using mruby-esp32 --Qiita](https://qiita.com/GORO_Neko/items/12967d5c8f84975db221)
- [GitHub - mruby-esp32/mruby-esp32: mruby application template for ESP32](https://github.com/mruby-esp32/mruby-esp32)




Recommended Posts

Build a mruby development environment for ESP32 (Linux)
Build a Kubernetes environment for development on Ubuntu
How to build a development environment for TensorFlow (1.0.0) (Mac)
[Memo] Build a development environment for Django + Nuxt.js with Docker
Easily build a development environment with Laragon
[Linux] Build a jenkins environment with Docker
Building a Python development environment for AI development
Creating a development environment for machine learning
[Linux] Build a Docker environment with Amazon Linux 2
Build a local development environment for Lambda + Python using Serverless Framework
[DynamoDB] [Docker] Build a development environment for DynamoDB and Django with docker-compose
Build a C language development environment with a container
[Python] Build a Django development environment with Docker
Build a Python development environment on your Mac
Build a Django development environment with Doker Toolbox
Build a Minecraft plugin development environment in Eclipse
Build a Python development environment on Raspberry Pi
Build a local development environment with WSL + Docker Desktop for Windows + docker-lambda + Python
Set up a development environment for natural language processing
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Build a Django development environment using pyenv-virtualenv on Mac
Build a python environment for each directory with pyenv-virtualenv
[Linux] WSL2 Build an environment for laravel7 with Ubuntu 20.04
Build a GVim-based Python development environment on Windows 10 (1) Installation
I want to easily build a model-based development environment
Build a Python development environment on Mac OS X
Build a machine learning application development environment with Python
Build a Python development environment using pyenv on MacOS
How to build a Python environment on amazon linux 2
Cross development environment (developing programs for windows on linux)
Build a Django environment for Win10 (with virtual space)
Build a lightweight Fast API development environment using Docker
Linux Kernel Build for DE10nano
Build a LAMP environment [CentOS 7]
[ev3dev × Python] Build ev3dev development environment
Build a machine learning environment
[For organizing] Python development environment
Build a Python environment offline
Install LAMP on Amazon Linux 2 and build a WordPress environment.
Build a Django development environment with Docker! (Docker-compose / Django / postgreSQL / nginx)
Build Azure Pipelies with Azure DevOps in a Linux self-hosted environment
Build a Go development environment with VS Code's Remote Containers
Create a VS Code + Docker development environment on a Linux VM
Build a Python development environment in Eclipse (add HTML editor)
[Django] Build a Django container (Docker) development environment quickly with PyCharm
Build a GVim-based Python development environment on Windows 10 (2) Basic settings
Build a comfortable development environment with VSCode x Remote Development x Pipenv
How to build a python2.7 series development environment with Vagrant
Build a Flask development environment at low cost using Docker
Build a LAMP environment with Vagrant (Linux + Apache + MySQL + PHP)
Build a PyData environment for a machine learning study session (January 2017)
Build a python environment on CentOS 7.7 for your home server
[Linux] [Initial Settings] Table of Contents for Development Environment Setup
Build a go environment using Docker
[For beginners] Django -Development environment construction-
Python development environment options for May 2020
Emacs settings for Python development environment
Build a python3 environment on CentOS7
Build and test a CI environment for multiple versions of Python
Build a Selenium environment on Amazon Linux 2 in the shortest time
Try using virtualenv, which can build a virtual environment for Python