3
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?

Nintendo Switchの自動制御をして広告スキップデバイスを作りました。

この記事では、この記事での実装からNintendo Switchの操作部分を抜き出したサンプルのメモです。

PlatformIOで作っています。

サンプルの動作 L+R => Aを毎秒押す

こんな感じです。USBシリアルでAtomS3R-CAMとNintendo Switchが繋がっています。

コントローラーとして認識させたあとはAボタンを毎秒押すような挙動です。

実装

メイン

https://github.com/sorasen2020/SwitchControllerESP32 のライブラリでL+RとAを押させています。

src/main.cpp
#include <Arduino.h>
#include "SwitchControllerESP32.h"

void setup() {
  Serial.begin(115200);
  delay(1000);

  Serial.println("\n=================================");
  Serial.println("ATOMS3-CAM Switch Controller");
  Serial.println("=================================\n");

  // Switch コントローラーとして初期化
  switchcontrolleresp32_init();
  USB.begin();  // USBデバイスを開始(重要!)
  switchcontrolleresp32_reset();

  Serial.println("Switch controller initialized!");

  // USB列挙を待つ
  delay(3000);

  // L+Rを同時押し(Switchに認識させる)
  Serial.println("Pressing L+R buttons...");
  pushButton2(Button::L, 200, 0, 1);
  pushButton2(Button::R, 200, 0, 1);
  delay(3000);

  // Aボタンを押して確定
  Serial.println("Pressing A button to confirm...");
  pushButton(Button::A, 100, 1);

  Serial.println("Connect to Nintendo Switch...");
  Serial.println("LED ON - Device is ready!");
}

void loop() {
  // 1秒ごとにAボタンを押す
  Serial.println("Pressing A button...");
  pushButton(Button::A, 100, 1);  // Aボタンを100ms押して離す
  delay(1000);
}

設定

platformio.ini
[env:m5stack-atoms3r]
platform = espressif32
; board = esp32-s3-devkitc-1
board = m5stack-atoms3
framework = arduino

; ★ S3-PICO(AtomS3R) は OPI PSRAM。これが無いと psramFound=0 になります
board_build.arduino.memory_type = qio_opi

; ★ LittleFS領域のあるパーティションに変更
board_build.partitions = default_8MB.csv

build_flags =
    -DESP32S3
    -DBOARD_HAS_PSRAM
    -mfix-esp32-psram-cache-issue
    -DCORE_DEBUG_LEVEL=1
    -DARDUINO_USB_CDC_ON_BOOT=0
    -DARDUINO_USB_MODE=1

lib_deps =
    https://github.com/sorasen2020/SwitchControllerESP32.git
monitor_filters = esp32_exception_decoder, time
monitor_speed = 115200
upload_speed = 921600

GitHub

こちらにあげています。

設定周り

board_build.arduino.memory_type = qio_opiでPSRAMを使えるように、board_build.partitions = default_8MB.csvこっちで領域確保。

この辺はなくても動くかもしれないけど、AtomS3R-CAMでカメラを使いつつ利用したいって場合にはないとメモリ不足でクラッシュしたり、保存領域確保できなくて不安定になる。みたいな事象が試していてありました。

これらの設定はAtomS3R-CAMだと入れておくのが無難かなと思っています。

3
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
3
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?