JD Brain RP2040 and Jacdac Modules for DeviceScript Platforms
If you are familiar with or have used MicroPython, you would know that MicroPython is a lightweight version of the Python programming language specifically designed for embedded systems and microcontrollers.
DeviceScript, initiated by Microsoft, is a TypeScript-based language for hardware development. It is a scripting language suited for embedded devices and IoT applications, offering features such as simplicity, cross-platform support, device management, network communication, and scalability.
DeviceScript brings a TypeScript developer experience to resource-constrained devices based on microcontrollers. DeviceScript code is compiled into custom VM bytecode that can run under highly constrained conditions.
If you are a TypeScript developer looking to venture into hardware, you don't want to miss out on DeviceScript!
Hardware for DeviceScriptDeviceScript supports mainstream hardware devices
Jacdac is a platform for quick and easy prototyping of new electronic experiences.
Brief Introduction- The following tutorial uses JD Brain RP2040 as the main controller and Jacdac KitA as the module for demonstration.
- It will guide you on how to set up DeviceScript configuration.
- And with a simple keyboard example, it will show you how to download the program to the hardware.
You need to download and install the software, which is an easy process.
Installing the DeviceScript ExtensionOpen VScode, search for "Devicescript" in the Extensions sidebar, and click on "Install" to install it.
The DeviceScript extension has been successfully installed.
I've been stuck at this part for a long time...
From the command palette (Ctrl+Shift+P)!!!, type DeviceScript: Create New Project...
The creation is completed.
You will see the newly created "src" folder in your directory, which contains the "main.ts" file. You can start programming by editing this "main.ts" file.
Before using the Brain RP2040, you need to update it with DeviceScript firmware.
Connect the Brain RP2040 to your computer using a data cable.
1、Open the webpage:MSR RP2040 Brain 124 v0.1 | DeviceScript (microsoft.github.io)
2、Download the firmware.
3、Drag and drop the firmware onto the U-disk of RPI-RP2. Once the update is complete, the mainboard will automatically restart.
Go back to VSCode and select "Connect Device" -> "Serial".
Connection successful.
You can connect the Jacdac module either through a Jacdac connection cable
or by using screws and brass pillars.
In VSCode, you should see that the Jacdac KeycapButton is online.
1、Open src/main.ts
file.
2、Copy and paste the following code into main.ts
. This code allows the BrainPad 2040 to act as an HID keyboard and send the Backspace key when a button is pressed
import { pins, board } from "@dsboard/msr124"
import { startHidKeyboard} from "@devicescript/servers"
import { Button } from "@devicescript/core"
import * as ds from "@devicescript/core"
const button = new Button()
const keyboard = startHidKeyboard({
})
button.down.subscribe(async ()=>{
const selector=ds.HidKeyboardSelector.Backspace
const modifier = ds.HidKeyboardModifiers.None
const action = ds.HidKeyboardAction.Press
await keyboard.key(selector,modifier,action)
})
3、Click on "Run" to download the program to the hardware. Also, open the simulator to see the triggered effect.
When KeycapButton is pressed, the keyboard triggers a Backspace.
Customize key bindings
You can use auto-completion to select different key bindings. VSCode is awesome!
Combination keys, such as Ctrl+V.
This tutorial aims to help you get started with DeviceScript quickly.
For more learning resources, you can refer to:
DeviceScript | DeviceScript (microsoft.github.io)
For TypeScript syntax documentation related to Jacdac, you can refer to:
Comments
Please log in or sign up to comment.