ESP-WROOM-32 Breakout Board “Unopuino32S” (CP2102 version)

Uno shaped ESP-WROOM-32 Breakout Board “Unopuino32S″ (CP2102 version)

top

<概要>

  • ピン配置及び取り付け穴位置がUnoと同一
    • pinout設定用のヘッダファイルはこちら
  • Arduino IDEからの自動書込み対応
  • IO電圧: 3.3V
  • USB-SerialにCP2102を使用

<主な特徴>

  • 5V系デバイス接続用に全入力に入力分割用抵抗パターンを配置
    • 5V系のデバイス(モジュール)を接続する為に、全入力に入力分割用の抵抗パターンを配置。半田付け作業を考えて基板裏面に実装できる様にしています。
  • ESP-WROOM-32のアンテナを基板の内側に向けて配置する事でAnalog入力配線を最短化
    • これによりWifi動作等によるアナログ入力へのノイズを極力低減
    • 上記の対応の為、ESP-WROOM-32のアンテナと周辺パターンとのクリアランスを5mm以上確保する事により受信感度を維持
  • 0.96′ OLED取り付け用コネクタ(I2C接続用4pin)を搭載

<仕様>

CPU: ESP-WROOM-32 (技適取得済)

USB-Serial: CP2102 (Silicon Labs.)

ESP32_Uno_v04So_schema

Schematics

ESP32uno_v04So_pinout

PINOUT

<開発環境の準備 (Windows)>

  1. CP2102 ドライバーをインストールする
  2. “Arduino core for the ESP32″をダウンロードし解凍
  3. Arduino インストールフォルダの hardware フォルダに、espressif フォルダを作成
  4. espressif フォルダの中に esp32 フォルダを作成
  5. 解凍した”Arduino core for the ESP32″の中身を esp32 フォルダ内にコピー
  6. espressif\esp32\tools にある get.exe を管理者権限で実行しコマンドプロンプトが消えるまでじっと待つ
  7. Arduino IDEを立ち上げると”ツール”->”ボード”でESP32が選択できる

<関連リンク>

Design Data (Open Source Hardware)

GitHub : https://github.com/tomorrow56/Unopuino32s

CP2102 Drivers (Silicon Labs)

http://jp.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers

<お願い>
NT金沢2017で頒布したバージョンでシリアルポート以外のデバイスと認識する場合があるとの報告をいただきました。
その場合はお手数ですが手動で”Silicon Labs CP210x USB to UART Bridge”を割り当てください。(Windowsの場合はデバイスマネジャーのドライバの更新で出来ます)
もしうまく動かない場合はCP2102のFW書き換えが必要となりますので、以下のFacebookページからメッセージを下さい。
https://www.facebook.com/thousandiy/

CP2102_driverUpdate

ESP-WROOM-32 Information (ESPRESSIF web site)

ESP-WROOM-32 Datasheet

ESP-WROOM-32 Schematic and layout 

Arduino core for the ESP32

<Tips for ESP32 programming>

//ESP32 Servo Control sample

//use first channel of 16 channels (started from zero)
#define LEDC_CHANNEL_0 0
//use 10 bit precission for LEDC timer
#define LEDC_TIMER_BIT 10
//use 50 Hz as a LEDC base frequency
#define LEDC_BASE_FREQ 50
//ServoPWM pin
#define SRV_PIN 13

int min = 26; // (26/1024)*20ms = 0.5 ms (-90deg)
int max = 122; // (122/1024)*20ms = 2.4 ms (+90deg)

void setup() {

// Setup timer and attach timer to a led pin
 ledcSetup(LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_BIT);
 ledcAttachPin(SRV_PIN, LEDC_CHANNEL_0);

ledcWrite(0, min);

}

void loop() {

ledcWrite(0, min);

for(int n = min; n <= max; n++){
 ledcWrite(0, n);
 delay(20);
 }
  • I2C

    •  I2Cを使う時はESP32標準のwire関数の引数にピンを指定する
    • Unopuino32の場合は以下のピンを割り当てている
      • int SDA32 = 22;
      • int SCL32 = 23;
      • Wire.begin(SDA32, SCL32);
    • I2C OLED(SSD1306)用のライブラリ
      • https://github.com/squix78/esp8266-oled-ssd1306
      • Unopuino32用であればI2Cピン指定を以下の様に修正
        • SSD1306 display(0x3c, 22, 23); // slvAdr, SDA, SCL
      • 小型OLEDはaitendoやebayから数百円で購入する事が可能。但し、ピンの並び順が”VCC-GND-SCL-SDA”になっている必要あり。

OLEDへの表示例

  • タイマー割り込み

    •  タイマー割り込みを使う場合は、ESP32 example sketchの”RepeatTimer”を参考に以下のコードを追加
// Timer Interrupt setting
hw_timer_t * timer = NULL;

volatile SemaphoreHandle_t timerSemaphore;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

void IRAM_ATTR onTimer(){
  // Increment the counter and set the time of ISR
  portENTER_CRITICAL_ISR(&timerMux);

  /*** ここにタイマー割り込みで実行するコードを記載 ***/

  portEXIT_CRITICAL_ISR(&timerMux);
  // Give a semaphore that we can check in the loop
  xSemaphoreGiveFromISR(timerSemaphore, NULL);
  // It is safe to use digitalRead/Write here if you want to toggle an output
}

void setup() {
  // Create semaphore to inform us when the timer has fired
  timerSemaphore = xSemaphoreCreateBinary();

  // Use 1st timer of 4 (counted from zero).
  // Set 80 divider for prescaler (see ESP32 Technical Reference Manual for more info).
  timer = timerBegin(0, 80, true);

  // Attach onTimer function to our timer.
  timerAttachInterrupt(timer, &onTimer, true);

  // Set alarm to call onTimer function every second (value in microseconds).
  // Repeat the alarm (third parameter)
  timerAlarmWrite(timer, 1000, true);

  // Start an alarm
  timerAlarmEnable(timer);
}

  • ハードウエア割り込み NEW

    • digitalPinToInterrupt()関数でデジタルピンを割り込みピンに割り当てる
      #define INTPIN 18
      
      void setup() {
       ~省略~
      // 割り込み設定
      // function: 割り込み発生時に呼び出す関数 
      // mode: 割り込みを発生させるトリガ 
      // LOW:ピンがLOWのとき発生
      // CHANGE:ピンの状態が変化したときに発生
      // RISING:ピンの状態がLOWからHIGHに変わったときに発生
      // FALLING:ピンの状態がHIGHからLOWに変わったときに発生
       attachInterrupt(digitalPinToInterrupt(INTPIN), [function], [mode]);
       ~省略~
      }
  • analogWrite()問題

    •  “Arduino core for the ESP32″ではanalogWrite()関数をサポートしていない(2017/10/10時点)
    • 代わりに、ledcWrite()関数を使用する事でPWM出力が可能
    • ESP32の場合LEDCは任意のピンに割り当てることが出来る
    • ESP32 example sketchの”LEDCSoftwareFade”を参考に以下の様に記述する
const int LED_PIN = 27; // PWM出力するPin No.
// use first channel of 16 channels (started from zero)
#define LEDC_CHANNEL_0 0
// use 13 bit precission for LEDC timer
#define LEDC_TIMER_13_BIT 13
// use 5000 Hz as a LEDC base frequency
#define LEDC_BASE_FREQ 5000

// Arduino like analogWrite
// value has to be between 0 and valueMax
void ledcAnalogWrite(uint8_t channel, uint32_t value, uint32_t valueMax = 255) {
// calculate duty, 8191 from 2 ^ 13 - 1
uint32_t duty = (8191 / valueMax) * min(value, valueMax);

// write duty to LEDC
ledcWrite(channel, duty);
}

void setup() {
// Setup timer and attach timer to a led pin
ledcSetup(LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_13_BIT);
ledcAttachPin(LED_PIN, LEDC_CHANNEL_0);
}

void loop(){
for(int i=0; i<256; i++){
ledcAnalogWrite(LEDC_CHANNEL_0, i);
delay(10); // change delay time can breath faster or slower
}
}

<ESP32の開発で参考になるサイト>

<サンプルプログラム>

広告

2件のコメント

  1. このUNO互換ボードは、5Vで動作するArduinoUNOシールド対応のボードを動作させることが出来るのでしょうか?

    いいね

    • 一般的な、となりますが。
      5V入力は抵抗分割で受けることが出来ますが改造(定数変更)が必要です。出力は3.3Vですが5Vのシールドであれば実力で通信できるはずです。

      いいね

コメントは停止中です。