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?

M5Stack(UIFLOW)とProcessingとのシリアル通信メモ

Posted at

M5はUIFLOWで開発する派な人向けシリアル通信の方法

参考:Qiita【Unity】M5Stackというデバイスを、UIFlowでUnityとシリアル通信してみました

M5Stack(UIFLOW)

ss_img 2025-06-19 20.11.56.png

送信ピンを1、受信ピンを3に設定するとUSBシリアルになるらしい。

Processing

import processing.serial.*;
Serial myPort;

String strData = "";
int data = 0;

void setup() {  
  String portNames[] = Serial.list();
  for (int i=0; i< portNames.length; i++) {
    println("[", i, "] ", portNames[i]);
  }
  myPort = new Serial(this, portNames[0], 115200);//シリアル通信の設定、通信速度をArduino側と合わせる
  myPort.bufferUntil('\n');//改行が来たら serialEvent()を呼び出す
}

void draw() {
}


void serialEvent(Serial myPort) { //シリアル通信を受信した時の処理
  strData = trim(myPort.readStringUntil('\n'));  //改行まで読み込み
  data = int(strData);  // 数値に変換
  println(data);
}

portNamesの番号は、自身の環境に合わせてM5の接続ポートの番号を入れてください。

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?