Skip to content
Shigeru Chiba edited this page Oct 9, 2024 · 4 revisions

Introduction

BlueScript is a small and efficient programming language designed specifically for microcontrollers.
While it currently supports only the ESP32 board, future updates will include support for a wider range of boards.

Get Started

Requirements

To start using BlueScript, you'll need the following:

  • ESP32 board
    • Currently, only the ESP32-WROOM-32 module is supported.
  • A computer running Windows, Linux, or macOS.
  • A USB cable (USB A / micro USB B) to connect your ESP32 to your computer.

Install and Build

Clone the Repository

First, clone the BlueScript repository using Git:

git clone [email protected]:csg-tokyo/bluescript.git

Build and Start the BlueScript Server

  1. Set up Docker and Docker Compose:

  2. Start the BlueScript Local Server

docker compose up -d
  1. Verify that the server has started successfully Open Google Chrome browser and access http://localhost:3000/.
    You can see BlueScript REPL page on the browser.

    You can also run a REPL that executes a program on a PC. You can use this REPL without a microcontroller connected to your PC.

    docker exec -it bluescript_server npm run shell
    

Build and Flash the BlueScript Runtime

  1. Build the BlueScript runtime:
cd ./microcontroller/port/esp32/
docker run --rm -v $PWD:/project -w /project -u $UID -e HOME=/tmp espressif/idf:release-v5.0 idf.py build
  1. Install esptool:
pip install esptool
  1. Connect your microcontroller to the computer via USB and check the serial port.
    Common serial port naming patterns:

    • Windows: Ports start with COM.
    • MacOS: Ports start with /dev/tty.
    • Linux: Ports start with /dev/cu.
  2. Flash the BlueScript runtime to the ESP32 device:

cd ./build
esptool.py --chip esp32 -p $PORT -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 4MB 0x1000 bootloader/bootloader.bin 0x10000 bluescript.bin 0x8000 partition_table/partition-table.bin

Write Your First Program

After setting up BlueScript, follow these steps to write and run a "Hello World" program:

  1. Open Google Chrome browser and access http://localhost:3000/.
    BlueScript REPL communicates with the microcontroller via Bluetooth, so the browser should be Google Chrome browser which only supports Web Bluetooth.

  2. Click the Start button.
    You’ll be prompted to select a Bluetooth device. Choose BLUESCRIPT.

  3. Write the following code in the cell:

print("Hello world!");
  1. Click the execution button on the left side of the cell to run your code in the cell.
    You can see "Hello world!" in the log area on the right side of the page.