Petit4Send

Last modified on Jun 26 2020.

File transfer program between Windows PC and Smile Basic 4 on Nintendo Switch, using Arduino(Pro Micro).

Abstract

File Transfer program from Windows PC to Smile Basic 4 of Nintendo Switch.

Some hardwares(Pro Micro and UART device) are required to use this software.

Screen Shot

動作イメージ
動作イメージ

Environment

Specification

Download

Smile Basic 4

public key [4BKXWKAE]

PC

  1. Ver. 1.2.2
  2. Ver. 1.2.1
  3. Ver. 1.2.0*
  4. Ver. 1.1.1
  5. Ver. 1.1.0*
  6. Ver. 1.0.0

Device

Device kit is distributed on Booth.

Notice

License, Charge, Donation

License

This software is free of charge. You can use it personally or commercially. You are also allowed to distribute secondary, fix/alter, do reverse-engineering.

Donation

You can donate via BitCoin / gumroad / PayPal.

BitCoin

Address:16NMv1dX4hNpjvnqvRYgXS4neqHHpa6P3Y
16NMv1dX4hNpjvnqvRYgXS4neqHHpa6P3Y

gumroad

PayPal

Description

プチコンは4になっても相変わらず外部ファイルが読めないので、 データを読み込むためのプログラムを作りました。

プチコン4は音声入力がないため、残念ながら音声転送は使えません。 検討した結果、USBのHIDデバイスを自作して、USBキーボードをエミュレートし、 地道に転送するのが一番よさげということになりました。 なので、残念ながらハードウェアが必要になります。

なるべく安く、お手軽に、ということで、 簡単にUSBデバイスを自作できる「Pro Micro」を用いました。 2019年5月現在、amazonで互換機が最安600円程度で入手できます。 これだけでUSBデバイスが作れるのですが、Pro Microにデータを送る手段が必要です。 UARTという簡単なシリアル通信手法があるので、これを使います。 が、PCからUARTで出力するのに、UARTインターフェースが必要になります。 私はこれもPro Microで作りましたが、専用のハードでも構いません。 このページの使用方法などは2台のProMicroをそれぞれ「USBキーボード」「UARTインタフェース」として使うことを前提に書いています。

Pro MicroをSwitchにつないだ際、エミュレートされたUSBキーボードはInterrupt転送を行っており、 Switchからは8msec毎に情報の送信要請がきます。 USBキーボードは要請があるたびにその時点でのキーの押下情報やマウスの移動量をSwitchに送っています。 USBキーボードは同時に6キーの押下+8つの修飾キー(左右のSHIFT、CTRL、ALT、APP(WIN))が判定できます。 キーコードは1バイトですが、一部の値は使えず、また押下データの6つに重複した値は使えません。 プチコン4ではおおよそ180種のキーコードが使え、また修飾キーは4つまで使えます。 押下キー情報は、「180種の内から6つ選ぶ組み合わせ」だけあるので180C6=43424719800通り、おおよそ35bit。 修飾キーは4つで4bit。合計で39bitの情報があります。

SWITCHのクロックとProMicroのクロックとは正確に同期していないため、データを送る際には同期をとる必要があります。 1つのbitをON/OFFすることで同期をとります。 また、同期の「抜け」を確認するために、更に1bitを追加し、2bitのパケット番号としています。

キーボードを用いて転送するため、送る際のコードが「Ctrl+C」だったり「F5」だとプログラムが止まってしまいます。 他のサブプログラムを起動するようなキーでもダメです。 こういった制限を避けるのに、「Ctrlキー」「ファンクションキー」等を回避します。

Ver.1.2.0からはマウスのボタンの情報を追加しました。 チャタリング防止の為か、高速でオンオフすると正常に取得できないので、VSync2回に5bit分の情報を送っています。

プチコン4側では、伝統通り、入力の情報はVSYNC≒16.7msec単位でしか更新されません。 またSwitchとの通信は8msec間隔なので、24msec単位で転送するか、タイミングを制御して転送する必要があります。

以上のようなことから、Ver.1.2.0現在は、 1転送にかかる時間は16.7msec(高速モード)もしくは24msec(低速モード)で、 1転送あたり39.5bit転送しています。

エラー検出はCRC16を用いました。 私の測定では、適切な条件を選べばパケット抜けは1/10000以下で、 3連続抜ける確率はほぼ考慮する必要がなく、 更にCRC16でのエラー見逃し率は1/60000以下です。 ですので、正常に転送された場合はほぼ間違いなくデータは破損していません。

また、転送レートが遅いのでLZSSによる圧縮を適用できるようにしています。

画像転送

PetitModemと同様に、画像によるファイル転送を実装しました。 十分な解像度があるので、2bit/pixel、白黒のみとしています。 いろいろな制限を考慮して1画像あたり181kByte程度転送できるようにしています。

キーボードリレー・自動タイプ

PCと同時にプチコン4をいじるとキーボードがいくつもあって混乱するので、 PCのキーボード入力をそのままプチコン4用に送る、リレー機能を搭載しています。

また、コピペや短いテキストの転送がしやすいよう、自動タイピング機能があります。

How to make

  1. buy parts
    • Pro Micro 5V/16MHz x2

      one is for Virtual Keyboard, one is UART

      ProMicroの写真
    • Breadboard
      ブレッドボードの写真
    • cables
      OTGケーブル
  2. assemble
    • Solder ProMicro
    • Put two ProMicro on the Bread Board
    • Connect pins.
      Pro Micro(Switch side)Pro Micro(PC side)
      TXORXI
      RXITXO
      GNDGND
      ProMicro pin asign
  3. install ProMicro driver to PC
    • Windows10 case
      1. connect ProMicro and PC with USB cable
    • Windows7 case
      1. download Driver on SparkFun
      2. install "sparkfun\avr\signed_driver"
      3. connect ProMicro and PC with USB cable
  4. Write Firmware of Petit4Send to ProMicro(Switch Side)
    • Connect Pro Micro(Switch Side) with USB cable
    • Boot Petit4Send
    • push [File] -> [Write Firmware] and open [Write Firmware for Pro Micro] dialog.
    • select port to which ProMicro is connected, and select "Petit4Send.ino.promicro.hex" file.
    • push [Write]
    • wait untill "Success" dialog is shown. if it fails, remove cable and try again.
    • remove ProMicro from PC.
    Firm書き込みの写真
  5. Write firmware of UART to ProMicro(PC Side)
    • Connect Pro Micro(Switch Side) with USB cable
    • Boot Petit4Send
    • push [File] -> [Write Firmware] and open [Write Firmware for Pro Micro] dialog.
    • select port to which ProMicro is connected, and select "USBUART.ino.promicro.hex" file.
    • push [Write]
    • wait untill "Success" dialog is shown. if it fails, remove cable and try again.
    • remove ProMicro from PC.
  6. Finish
    ProMicroの写真

Usage

File Transfer

  1. Connect ProMicro(PC side) to PC.
  2. Connect ProMicro(Switch side) to Switch.
  3. Boot Petit4Send on SmileBasic4.
  4. Boot Petit4Send on PC.
    • Fast Mode
      1. Select [DETECT SYNC KEY] on SmileBasic4.
      2. Press [Send]->[DETECT] button on PC.
      3. Wait about 10 sec.
      4. [SYNC KEY] is displayed on SmileBasic4, enter it to [Sync Key] field of PC. if it is not displayed, confirm connection and try again.
    • Slow Mode
      1. Enter "-1" to [Sync Key] field of PC.
  5. Select [USB RECEIVE] on SmileBasic4
  6. Select a file which you want to send and file type in which you want to send, then press [Send]
  7. File Transfer will be started around 5 sec.
  8. At the end of transfer, Petit4Send wait your confirmation. Press "A" of JoyCon.
  9. Save and finish.

Image Transfer

  1. Boot Petit4Send on SmileBasic4.
  2. Select [SCREENSHOT SEND] on SmileBasic4
  3. Select File. it should be inside the Project.
  4. Encoded Image will be shown. Save it by Screenshot button of Switch. if there are some image, save all images.
  5. Send it to PC.
  6. Boot Petit4Send on PC.
  7. Drop Images to [Decode Image] tab.
  8. Select folders in which you want to save.
  9. press [Convert] button.

Keyboard Relay

  1. Connect ProMicro(PC side) to PC.
  2. Connect ProMicro(Switch side) to Switch.
  3. Boot Petit4Send on PC.
  4. Open [Keyboard] Tab on PC
  5. Press [Start] button.
  6. During Petit4Send has a Focus, PC keyboard inputs are sent to Switch as keyboard inputs.

Auto typing

  1. Connect ProMicro(PC side) to PC.
  2. Connect ProMicro(Switch side) to Switch.
  3. Boot Petit4Send on PC.
  4. Open [Typing Send] Tab on PC
  5. Write or Copy&Paste text sentence you want to send in textbox.
  6. press [Start].
  7. the Text in textbox are sent to Switch as keyboard inputs.

Notice

Hex file contained in ZIP is for "Pro Micro 5V 16MHz" If you use "3V 8MHz" type or other Arduino, you need to re-compile from source.

[Sync Key] must be correct. If you enter "-1" as sync key, it become "Slow Mode"(206Bytes/sec). [Sync Key] is valid until USB connector is removed or Switch enters sleep mode.