0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Node-RED MCU EditionのNode作成のテンプレート

Last updated at Posted at 2025-10-19

はじめに

これは生成AIで効率よくNode-RED MCU Edition用のノードを作成するためのもので人間向けではありません。

Node-RED MCU Edition用のNodeはexportされNode-RED MCUでJavascriptに変換されたのちModdableSDKで解釈される。

Node-RED MCUのリポジトリは https://github.com/phoddie/node-red-mcu
Moddable SDKのリポジトリは https://github.com/Moddable-OpenSource/moddable
Moddableの中でも、https://github.com/Moddable-OpenSource/moddable/blob/public/tools/nodered2mcu.js は、Node-REDをModdableで解釈する大事な部分

動いている、コミュニティのNode例を参考にするとよい

Githubのリポジトリ名

コミュニティが提供するリポジトリ名は名前と同じにしたほうが良いので、基本的に、node-red-contrib-hogehoge とする。

Node-RED MCU Editionの作成方法

下記URLを見る
https://github.com/phoddie/node-red-mcu?tab=readme-ov-file#compatibility-node
ここもよく読んで。
https://github.com/404background/node-create-guidelines/tree/dadab98cf93d926f5bffa12d6b8dfc8080edfa0c

I2Cを使う場合のプロパティ

デバイスのmanifest.jsonから設定される場合が多いが、個別のI2Cを使うこともあるので、PINでも選べるようにする。Speedも指定できるようにする。

公式のI2Cinノードの例

image.png

RED.nodes.registerType('mcu_i2c_in',{
		category: mcuHelper.category,
		color: mcuHelper.color,
		defaults: {
			name: { value:"" },
			options: { value:{ bus:"default" } },
			command: { },
			bytes: { value:1 },
			moddable_manifest: {value: {include: "$(NODEREDMCU)/nodes/mcu/i2c/manifest.json"}},
		},
		inputs:1,
		outputs:1,
		icon: "mcu.png",
		paletteLabel: 'I²C in',
		label: function() {
			return this.name || "I²C in";
		},
		oneditprepare: function() {
			const io = { type:"I2C" };
			$(`#button-group-io-bus`).on("click", function() {
				mcuHelper.toggleIO(false, "io", io);
			})			
			$(`#button-group-io-pins`).on("click", function() {
				mcuHelper.toggleIO(true, "io", io);
			})			
			const div = $("#node-mcu-rows");
			mcuHelper.appendProperties.I2C(div, "io", io);
			mcuHelper.toggleIO(false, "io", io);
			mcuHelper.restoreProperties.I2C(this.options, "io", io);
		},
		oneditsave: function() {
 			const options = {};
			mcuHelper.saveProperties.I2C(options, "io");
			this.options = options;
		},
	});
<script type="text/html" data-template-name="mcu_i2c_in">
	<div class="form-row">
		<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
		<input type="text" id="node-input-name" placeholder="I²C in">
	</div>
	<div class="form-row">
		<label>Options</label>
		<span class="button-group">
			<button type="button" class="red-ui-button toggle selected" id="button-group-io-bus">Bus</button><button type="button" class="red-ui-button toggle" id="button-group-io-pins">Pins</button>
		</span>
	</div>
	<div id="node-mcu-rows">
	</div>
	<div class="form-row">
		<div class="red-ui-help">
			See the <a class="" href="https://419.ecma-international.org/#-10-io-classes-ic" target="_blank">ECMA-419 specification</a>.
		</div>
   </div>
	<div class="form-row">
		<hr/>
		<label for="node-input-command">Command</label>
		<input type="text" id="node-input-command" style="display:inline-block; width:70%; vertical-align:baseline;" placeholder="[msg.command]">
	</div>
	<div class="form-row">
		<label for="node-input-bytes">Bytes</label>
		<input type="number" id="node-input-bytes" min="0" max="31" style="display:inline-block; width:70%; vertical-align:middle;">
	</div>
</script>

デバイスのmanifest.json例

{
	"build":{
		"ESP32_SUBCLASS": "esp32s3",
		"USE_USB": "2",
		"SDKCONFIGPATH": "./sdkconfig",
		"PARTITIONS_FILE_FOR_TARGET": "./sdkconfig/partitions.csv",
		"PROGRAMMING_MODE_MESSAGE": "INSTRUCTIONS: Press and hold the button until the LED lights.",
		"BEFORE_DEBUGGING_MESSAGE": "Press and release the Reset button."
	},
	"include": [
		"$(MODDABLE)/modules/io/manifest.json",
		"$(MODDABLE)/modules/drivers/ili9341/manifest.json",
		"$(MODULES)/drivers/button/manifest.json"
	],
	"modules": {
		"*": [
			"../m5stack_fire/m5button"
		],
		"setup/target": "./setup-target"
	},
	"preload": [
		"setup/target",
		"m5button"
	],
	"config": {
		"screen": "ili9341",
		"touch": ""
	},
	"creation": {
		"static": 0,
		"chunk": {
			"initial": 78848,
			"incremental": 0
		},
		"heap": {
			"initial": 4928,
			"incremental": 0
		},
		"stack": 512
	},
	"defines": {
		"i2c": {
			"sda_pin": 45,
			"scl_pin": 0
		},
		"spi": {
			"mosi_pin":21,
			"sck_pin": 15
		},
		"ili9341": {
			"hz": 27000000,
			"width": 128,
			"height": 128,
			"cs_pin": 14,
			"rst_pin": 48,
			"dc_pin": 42,
			"column_offset": 0,
			"row_offset": 32,
			"spi_port": "SPI3_HOST",
			"registers": [
				"0xFE, 0,",
				"kDelayMS, 10,",
				"0xEF, 0,",
				"kDelayMS, 10,",
				"0x36, 1, 0x08,",
				"0xB0, 1, 0xC0,",
				"0xB2, 1, 0x2F,",
				"0xB3, 1, 0x03,",
				"0xB6, 1, 0x19,",
				"0xB7, 1, 0x01,",
				"0xAC, 1, 0xCB,",
				"0xAB, 1, 0x0E,",
				"0xB4, 1, 0x04,",
				"0xA8, 1, 0x19,",
				"0x3A, 1, 0x05,",
				"0xB8, 1, 0x08,",
				"0xE8, 1, 0x24,",
				"0xE9, 1, 0x48,",
				"0xEA, 1, 0x22,",
				"0xC6, 1, 0x30,",
				"0xC7, 1, 0x18,",
				"0xF0, 14, 0x1F,0x28,0x04,0x3E,0x2A,0x2E,0x20,0x00,0x0C,0x06,0x00,0x1C,0x1F,0x0F,",
				"0xF1, 14, 0x00,0x2D,0x2F,0x3C,0x6F,0x1C,0x0B,0x00,0x00,0x00,0x07,0x0D,0x11,0x0F,",
				"0x20, 0,",
				"0x11, 0,",
				"kDelayMS, 120,",
				"0x29, 0,",
				"kDelayMS, 20,",
				"kDelayMS, 0"
			]
		}
	}
}

参考:公式のNode

参考:コミュニティのNode

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?