12 | #define I2C_sht 0x45 // SHT31 の I2C アドレス
13 |
14 | float _i2c_sht31_hum;
15 |
16 | float getTemp(){
17 | int temp,hum;
18 | _i2c_sht31_hum=-999.;
19 | Wire.beginTransmission(I2C_sht);
20 | Wire.write(0x2C);
21 | Wire.write(0x06);
22 | if(Wire.endTransmission()) return -998.;
23 | delay(18); // 15ms以上
24 | Wire.requestFrom(I2C_sht,6);
25 | if(Wire.available() != 6) return -997.0;
26 | temp = Wire.read();
27 | temp <<= 8;
28 | temp += Wire.read();
29 | Wire.read();
30 | hum = Wire.read();
31 | hum <<= 8;
32 | hum += Wire.read();
33 | Wire.read(); // 未使用 not used
34 | _i2c_sht31_hum = (float)hum / 65535. * 100.;
35 | return (float)temp / 65535. * 175. - 45.;
36 | }
37 |
38 | float getHum(){
39 | return _i2c_sht31_hum;
40 | }
41 |
42 | void shtSetup(){
43 | delay(2); // 1ms以上
44 | Wire.begin(); // I2Cインタフェースの使用を開始
45 | delay(18); // 15ms以上
46 | }
47 |
--------------------------------------------------------------------------------
/1_practice/practice35_sw/practice35_sw.ino:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | Practice 35(Practice 3+32): スイッチ入力
3 |
4 | GPIO 0 へ スイッチを、
5 | GPIO 2 へ LEDを接続してください。
6 | Copyright (c) 2016-2019 Wataru KUNINO
7 | *******************************************************************************/
8 |
9 | #define PIN_SW 0 // IO 0にスイッチを接続
10 | #define PIN_LED 2 // IO 2にLEDを接続
11 | int prev = 0; // 整数型変数prevを定義し、初期値0を代入
12 |
13 | void setup() { // 起動時に一度だけ実行される関数
14 | pinMode(PIN_SW,INPUT_PULLUP); // スイッチを接続したポートを入力に設定
15 | pinMode(PIN_LED,OUTPUT); // LEDを接続したポートを出力に設定する
16 | Serial.begin(115200); // シリアル通信速度を115200bpsに設定する
17 | }
18 |
19 | void loop() { // setup実行後に繰り返し実行される関数
20 | int in; // 整数型変数inを定義
21 |
22 | in = digitalRead(PIN_SW); // デジタル入力値を変数inに代入
23 |
24 | if( in == 0 ){ // in値が0、すなわちLレベル(0V)入力の時
25 | digitalWrite(PIN_LED,1); // ポートをHレベル(3.3V)に設定(点灯)
26 | }else{ // そうでは無い時
27 | digitalWrite(PIN_LED,0); // ポートをLレベル(0V)に設定(点灯)
28 | }
29 |
30 | if( in != prev ){ // inの値がprevと異なる時
31 | Serial.println(in); // inの値をシリアル出力
32 | prev = in; // prevにin値を代入
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/5_learn32/esp32_03_sw/esp32_03_sw.ino:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | Practice 3: スイッチ入力
3 | Copyright (c) 2016-2019 Wataru KUNINO
4 | *******************************************************************************/
5 |
6 | #define PIN_LED 2 // IO 2にLEDを接続
7 | #define PIN_SW 0 // IO 0にスイッチを接続
8 |
9 | boolean button=1; // スイッチ状態を保存するための変数
10 |
11 | void setup() { // 起動時に一度だけ実行される関数
12 | pinMode(PIN_SW,INPUT_PULLUP); // スイッチを接続したポートを入力に設定
13 | pinMode(PIN_LED,OUTPUT); // LEDを接続したポートを出力に設定する
14 | Serial.begin(115200); // シリアル通信速度を115200bpsに設定する
15 | }
16 |
17 | void loop() { // setup実行後に繰り返し実行される関数
18 | boolean b=button; // 前回のスイッチ状態を変数bに保持
19 |
20 | while(b==button){ // 前回の値bと同じ値の間に繰り返し実行
21 | button = digitalRead(PIN_SW); // スイッチ状態の読み取り
22 | } // 異なる値となったときに繰り返しを終了
23 | if(button==0){ // スイッチが押されLOWレベルだった時
24 | Serial.println("Ping"); // シリアルへPingを出力表示
25 | digitalWrite(PIN_LED,1); // ポートをHレベル(3.3V)に設定(点灯)
26 | }else{
27 | Serial.println("Pong"); // そうでないときに「Pong」を出力表示
28 | digitalWrite(PIN_LED,0); // ポートをLレベル(0V)に設定(点灯)
29 | }
30 | delay(10); // 10msの時間待ち(チャタリング防止策)
31 | }
32 |
--------------------------------------------------------------------------------
/1_practice/practice07_led.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # 天気をLEDの状態で表示する
3 |
4 | IP_LED="192.168.0.2" # ワイヤレスLEDのIP
5 |
6 | city_id=130000 # 気象庁=130000(東京地方など)
7 | # 大阪管区気象台=270000(大阪府など)
8 | # 京都地方気象台=260000(南部など)
9 | # 横浜地方気象台=140000(東部など)
10 | # 銚子地方気象台=120000(北西部など)
11 | # 名古屋地方気象台=230000(西部など)
12 | # 福岡管区気象台=400000(福岡地方など)
13 |
14 | #WEATHER=`curl -s rss.weather.yahoo.co.jp/rss/days/43.xml\
15 | #|cut -d'<' -f17|cut -d'>' -f2|tail -1\
16 | #|cut -d' ' -f5|cut -c1-3` # 天気を取得する
17 | WEATHER=`curl -s https://www.jma.go.jp/bosai/forecast/data/forecast/{$city_id}.json\
18 | |tr "," "\n"|grep weathers|head -1|cut -d'"' -f4|sed "s/ /\t/g"|cut -f1`
19 | echo -n `date "+%Y/%m/%d %R"`", "$WEATHER", " # テキスト表示
20 | case $WEATHER in # 天気に応じた処理
21 | "晴" ) LED=1;; # 晴の時は明るく点灯
22 | "くもり" ) LED=-1;; # 曇の時は暗く点灯
23 | * ) LED=5;; # その他の時は点滅
24 | esac # caseの終了
25 | curl -s $IP_LED -XPOST -d"L=$LED"|grep ""|grep -v "http"\
26 | |cut -d'>' -f2|cut -d'<' -f1 # ワイヤレスLED制御
27 |
--------------------------------------------------------------------------------
/1_practice/practice04_var/practice04_var.ino:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | Practice 4: 変数の使い方
3 | Copyright (c) 2015-2019 Wataru KUNINO
4 | *******************************************************************************/
5 |
6 | void setup() { // 起動時に一度だけ実行される関数
7 | Serial.begin(9600); // シリアル通信速度を9600bpsに設定する
8 | }
9 |
10 | void loop() { // setup実行後に繰り返し実行される関数
11 | int a = 12345; // 整数型の変数aを定義
12 | char c = 'R'; // 文字変数cを定義
13 | char s[] = "Hello, world!"; // 文字列変数sを定義
14 | float v = 1.2345; // 浮動小数点数型変数v
15 | int size; // 変数sizeを定義
16 |
17 | Serial.println("Practice 03"); // 「Practice 03」を表示
18 |
19 | Serial.print("a=");
20 | Serial.println(a,DEC); // 整数値変数aの値を表示
21 |
22 | Serial.print("c=");
23 | Serial.write(c); // 文字変数cの値を表示
24 | Serial.println(); // 改行する
25 |
26 | Serial.print("s=");
27 | Serial.println(s); // 文字列変数sの値を表示
28 |
29 | size = sizeof(s); // sのサイズをsizeに代入
30 | Serial.print("sizeof(s)=");
31 | Serial.println(size,DEC); // sizeの値を表示して改行
32 |
33 | Serial.print("v=");
34 | Serial.println(v,3); // 浮動小数点数型変数vの値を表示
35 |
36 | for(a=0;a<10;a++) delay(100); // 1秒の待ち時間処理
37 | Serial.println();
38 | }
39 |
--------------------------------------------------------------------------------
/2_example/example20_camG/README.md:
--------------------------------------------------------------------------------
1 | # トラブルシューティング
2 |
3 | ## 電源が安定しているかどうか
4 | 電源が不安定だと、ESPモジュールが起動しない、または起動しても
5 | 正しく動作しないことがあります。
6 | 起動時やWi-Fi接続時、カメラ動作時は、多くの電流を消費するので、
7 | 目安として600mA程度の電流が流せる電源回路を使用してください。
8 |
9 | ## シリアルのTXDとRXDはクロス接続
10 | カメラのTXDをESPモジュールのRXD(本サンプルではIO12(4番ピン))に、
11 | カメラのRXDをESPモジュールのTXD(本サンプルではIO14(3番ピン))に
12 | 接続してください。
13 |
14 | ## LCDに「Example 20 cam」が表示されたまま動作しない①
15 | Wi-Fiアクセスポイントとの接続に失敗しています。
16 | 無線LANアクセスポイントのSSIDとパスワードをプログラム内の
17 | #define SSIDとPASSに設定して下さい。
18 |
19 | ## LCDに「Example 20 cam」が表示されたまま動作しない②
20 | カメラとの通信に失敗しています。
21 | カメラの電源電圧、シリアル配線などを確認してください。
22 |
23 |
24 | ## ブラウザに「防犯カメラ STATUS」の画面が表示されない
25 | ネットワーク内のDHCPサーバが動作していない、
26 | 異なる無線LANアクセスポイントへ接続されている、
27 | 異なるIPアドレスが設定されている、
28 | 無線LANアクセスポイントやRaspberry Piのファイヤーウォール等で
29 | パケットが破棄されているなどが考えられます。
30 |
31 | ## ブラウザに画面は表示されるが、写真データが(得られるが)表示できない/ノイズが入る
32 | コンパイル時に「ツール」メニュー内の「CPU Frequency」で160MHz
33 | を設定してください。
34 | ただし、CPU(マイコン)の周波数を160MHzすることで、消費電力が
35 | 増大し、電源によっては電流容量が不足することがあります。
36 | 致命的な問題が無い限り、80MHzで使用することをお奨めします。
37 | CPUの周波数変更で改善できない場合は、シリアル接続や電源などに
38 | ノイズが混入している可能性が考えられます。
39 |
40 | ## ブラウザの互換性・ブラウザのセキュリティ対策
41 | ブラウザのバージョンアップやセキュリティ対策により、表示でき
42 | なくなることがあります。
43 | また、ブラウザのバージョンアップで表示できるようになることも
44 | あります。
45 | 例えば、IPアドレスによるアクセスを危険と見なす場合もあれば、
46 | 同一LAN内のコンテンツは安全と見なす場合など、ブラウザや、その
47 | バージョン、設定、ブラウザを開発する会社の方針などによって
48 | 状況が変化します。
49 | 一例として、以下のような複数のブラウザで試してみて下さい。
50 | (IE、Edge、Safari、Chrome、FireFoxなど)
51 |
52 | ## 動作ログの確認方法(ご参考)
53 | Arduino IDEのウィンドウ右上にある虫眼鏡のアイコンをクリックし、
54 | 「シリアルモニタ」を起動し、シリアルモニタの右下のボーレートを
55 | 9600bpsに設定すると、動作ログが表示されます。
56 |
--------------------------------------------------------------------------------
/2_example/example15_camL/README.md:
--------------------------------------------------------------------------------
1 | # トラブルシューティング
2 |
3 | ## 電源が安定しているかどうか
4 | 電源が不安定だと、ESPモジュールが起動しない、または起動しても
5 | 正しく動作しないことがあります。
6 | 起動時やWi-Fi接続時、カメラ動作時は、多くの電流を消費するので、
7 | 目安として600mA程度の電流が流せる電源回路を使用してください。
8 |
9 | ## カメラの電源電圧は5V
10 | Adafruit 1386 の電源入力電圧は5Vです。古いバージョンの基板には
11 | 「3.3V」と書かれていますが、基板上にLDOが実装されているので、
12 | およそ4~5V程度を入力する必要があります。
13 |
14 | ## シリアルのTXDとRXDはクロス接続
15 | カメラのTXDをESPモジュールのRXD(本サンプルではIO12(4番ピン))に、
16 | カメラのRXDをESPモジュールのTXD(本サンプルではIO14(3番ピン))に
17 | 接続してください。
18 |
19 | ## LCDに「Example 15 Cam」が表示されたまま動作しない
20 | SPIFFSが無効になっています。
21 | コンパイル時に128KB以上のSPIFFS(最新SDKではFSと表示)を設定して
22 | ください。
23 |
24 | ## LCDに「Cam Init」が表示されたまま動作しない①
25 | Wi-Fiアクセスポイントとの接続に失敗しています。
26 | 無線LANアクセスポイントのSSIDとパスワードをプログラム内の
27 | #define SSIDとPASSに設定して下さい。
28 |
29 | ## LCDに「Cam Init」が表示されたまま動作しない②
30 | カメラとの通信に失敗しています。
31 | カメラの電源電圧、シリアル配線などを確認してください。
32 |
33 | ## 写真データが(得られるが)表示できない/ノイズが入る
34 | コンパイル時に「ツール」メニュー内の「CPU Frequency」で160MHz
35 | を設定してください。
36 | ただし、CPU(マイコン)の周波数を160MHzすることで、消費電力が
37 | 増大し、電源によっては電流容量が不足することがあります。
38 | 致命的な問題が無い限り、80MHzで使用することをお奨めします。
39 | CPUの周波数変更で改善できない場合は、シリアル接続や電源などに
40 | ノイズが混入している可能性が考えられます。
41 |
42 | ## Raspberry Piで受信できない
43 | しばらく待って、LCDに「Sleeping」「zzz...」と表示されることを
44 | 確認してください。表示されたら、ENボタンを押して、再送信して
45 | みて下さい。
46 | それでも、動作しない場合は、
47 | ネットワーク内のDHCPサーバが動作していない、
48 | 異なる無線LANアクセスポイントへ接続されている、
49 | 異なるIPアドレスが設定されている、
50 | 無線LANアクセスポイントやRaspberry Piのファイヤーウォール等で
51 | パケットが破棄されているなどが考えられます。
52 |
53 | ## 動作ログの確認方法(ご参考)
54 | Arduino IDEのウィンドウ右上にある虫眼鏡のアイコンをクリックし、
55 | 「シリアルモニタ」を起動し、シリアルモニタの右下のボーレートを
56 | 9600bpsに設定すると、動作ログが表示されます。
57 |
--------------------------------------------------------------------------------
/2_example/example15f_camL/README.md:
--------------------------------------------------------------------------------
1 | # トラブルシューティング
2 |
3 | ## 電源が安定しているかどうか
4 | 電源が不安定だと、ESPモジュールが起動しない、または起動しても
5 | 正しく動作しないことがあります。
6 | 起動時やWi-Fi接続時、カメラ動作時は、多くの電流を消費するので、
7 | 目安として600mA程度の電流が流せる電源回路を使用してください。
8 |
9 | ## カメラの電源電圧は5V
10 | Adafruit 1386 の電源入力電圧は5Vです。古いバージョンの基板には
11 | 「3.3V」と書かれていますが、基板上にLDOが実装されているので、
12 | およそ4~5V程度を入力する必要があります。
13 |
14 | ## シリアルのTXDとRXDはクロス接続
15 | カメラのTXDをESPモジュールのRXD(本サンプルではIO12(4番ピン))に、
16 | カメラのRXDをESPモジュールのTXD(本サンプルではIO14(3番ピン))に
17 | 接続してください。
18 |
19 | ## LCDに「Example 15 Cam」が表示されたまま動作しない
20 | SPIFFSが無効になっています。
21 | コンパイル時に128KB以上のSPIFFS(最新SDKではFSと表示)を設定して
22 | ください。
23 |
24 | ## LCDに「Cam Init」が表示されたまま動作しない①
25 | Wi-Fiアクセスポイントとの接続に失敗しています。
26 | 無線LANアクセスポイントのSSIDとパスワードをプログラム内の
27 | #define SSIDとPASSに設定して下さい。
28 |
29 | ## LCDに「Cam Init」が表示されたまま動作しない②
30 | カメラとの通信に失敗しています。
31 | カメラの電源電圧、シリアル配線などを確認してください。
32 |
33 | ## 写真データが(得られるが)表示できない/ノイズが入る
34 | コンパイル時に「ツール」メニュー内の「CPU Frequency」で160MHz
35 | を設定してください。
36 | ただし、CPU(マイコン)の周波数を160MHzすることで、消費電力が
37 | 増大し、電源によっては電流容量が不足することがあります。
38 | 致命的な問題が無い限り、80MHzで使用することをお奨めします。
39 | CPUの周波数変更で改善できない場合は、シリアル接続や電源などに
40 | ノイズが混入している可能性が考えられます。
41 |
42 | ## Raspberry Piで受信できない
43 | しばらく待って、LCDに「Sleeping」「zzz...」と表示されることを
44 | 確認してください。表示されたら、ENボタンを押して、再送信して
45 | みて下さい。
46 | それでも、動作しない場合は、
47 | ネットワーク内のDHCPサーバが動作していない、
48 | 異なる無線LANアクセスポイントへ接続されている、
49 | 異なるIPアドレスが設定されている、
50 | 無線LANアクセスポイントやRaspberry Piのファイヤーウォール等で
51 | パケットが破棄されているなどが考えられます。
52 |
53 | ## 動作ログの確認方法(ご参考)
54 | Arduino IDEのウィンドウ右上にある虫眼鏡のアイコンをクリックし、
55 | 「シリアルモニタ」を起動し、シリアルモニタの右下のボーレートを
56 | 9600bpsに設定すると、動作ログが表示されます。
57 |
--------------------------------------------------------------------------------
/tools/udp_logger_plus.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # UDPを受信し、保存する
3 | # Copyright (c) 2016 Wataru KUNINO
4 |
5 | echo "UDP Logger (usage: ${0} port)" # タイトル表示
6 | if [ ${#} = 1 ] # 入力パラメータ数の確認
7 | then # 1つだった時
8 | if [ ${1} -ge 1 ] && [ ${1} -le 65535 ] # ポート番号の範囲確認
9 | then # 1以上65535以下の時
10 | PORT=${1} # ポート番号を設定
11 | else # 範囲外だった時
12 | PORT=1024 # UDPポート番号を1024に
13 | fi # ifの終了
14 | else # 1つでは無かった時
15 | PORT=1024 # UDPポート番号を1024に
16 | fi # ifの終了
17 | echo "Listening UDP port "${PORT}"..." # ポート番号表示
18 | while true # 永久に
19 | do # 繰り返し
20 | UDP=`nc -luw0 ${PORT}|tr -d [:cntrl:]|\
21 | tr -d "\!\"\$\%\&\'\(\)\*\+\;\<\=\>\?\[\\\]\^\{\|\}\~/"`
22 | # UDPパケットを取得
23 | DATE=`date "+%Y/%m/%d %R"` # 日時を取得
24 | DEV=${UDP#,*} # デバイス名を取得(前方)
25 | DEV=${DEV%%,*} # デバイス名を取得(後方)
26 | echo -E $DATE, $UDP|tee -a log_${DEV}.csv # 取得日時とデータを表示
27 | done # 繰り返しここまで
28 |
--------------------------------------------------------------------------------
/2_example/example64_photo/license_Adafruit-SSD1331.txt:
--------------------------------------------------------------------------------
1 | Software License Agreement (BSD License)
2 |
3 | Copyright (c) 2012, Adafruit Industries
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 | 1. Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | 2. Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 | 3. Neither the name of the copyright holders nor the
14 | names of its contributors may be used to endorse or promote products
15 | derived from this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 |
--------------------------------------------------------------------------------
/5_learn32/esp32_26_photof/license_Adafruit-SSD1331.txt:
--------------------------------------------------------------------------------
1 | Software License Agreement (BSD License)
2 |
3 | Copyright (c) 2012, Adafruit Industries
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 | 1. Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | 2. Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 | 3. Neither the name of the copyright holders nor the
14 | names of its contributors may be used to endorse or promote products
15 | derived from this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 |
--------------------------------------------------------------------------------
/tools/aquestalk_setup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # AQUEST社の AquesTalkをダウンロードし、インストールします。
3 | #
4 | # http://www.a-quest.com/products/aquestalkpi.html
5 |
6 | if [ ! -e "./aquestalkpi/AquesTalkPi" ]; then
7 | echo "AquesTalkのウェブサイトにアクセスして、ライセンスを確認してください。"
8 | echo "http://www.a-quest.com/products/aquestalkpi.html"
9 | echo "上記のライセンスに同意する場合は「yes」を入力してください。"
10 | echo -n "yes/no >"
11 | read yes
12 | case $yes in
13 | yes)
14 | echo "ダウンロードを実行中です。"
15 | # wget http://www.a-quest.com/download/package/aquestalkpi-20130827.tgz
16 | # wget https://www.a-quest.com/archive/package/aquestalkpi-20130827.tgz
17 | wget https://www.a-quest.com/archive/package/aquestalkpi-20201010.tgz
18 | echo "インストールを実行中です。"
19 | tar xzvf aquestalkpi-*.tgz
20 | echo "セットアップ完了です。"
21 | echo "詳細はこちら:http://blog-yama.a-quest.com/?eid=970157"
22 | ;;
23 | *)
24 | echo "ダウンロードをキャンセルしました。"
25 | ;;
26 | esac
27 | fi
28 | echo "時報をセットします。セットしたくない場合は「no」を入力してください。"
29 | echo -n "yes/no >"
30 | read yes
31 |
32 | #if [ ! -e "/etc/cron.daily/talk_time_signal" ]; then
33 | if [ $yes != "no" ]; then
34 | DIR=`pwd`
35 | EXIST=`grep aquestalk_tsig.sh /etc/crontab`
36 | if [ -z "$EXIST" ]; then
37 | echo "0 * * * * pi "${DIR}"/aquestalk_tsig.sh" | sudo tee -a /etc/crontab
38 | sleep 0.1
39 | sudo /etc/init.d/rsyslog restart
40 | echo "/etc/crontab へ aquestalk_tsig.sh を設定しました。"
41 | # cat /etc/crontab
42 | fi
43 | echo "再生テストを行います。"
44 | aquestalkpi/AquesTalkPi -f aquestalkpi/test.txt |aplay
45 | echo "再生できればセットアップ完了です。"
46 | fi
47 | echo "終了"
48 | exit
49 |
--------------------------------------------------------------------------------
/1_practice/practice36_var/practice36_var.ino:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | Practice 4: 変数の使い方
3 |
4 | シリアルモニタのビット・レート設定を115200 bpsに設定してください。
5 | Copyright (c) 2015-2019 Wataru KUNINO
6 | *******************************************************************************/
7 |
8 | void setup() { // 起動時に一度だけ実行される関数
9 | Serial.begin(115200); // シリアル通信速度を115200bpsに設定する
10 | }
11 |
12 | void loop() { // setup実行後に繰り返し実行される関数
13 | int a = 12345; // 整数型の変数aを定義
14 | char c = 'R'; // 文字変数cを定義
15 | char s[] = "Hello, world!"; // 文字列変数sを定義
16 | float v = 1.2345; // 浮動小数点数型変数v
17 | int size; // 変数sizeを定義
18 |
19 | Serial.println("Practice 03"); // 「Practice 03」を表示
20 |
21 | Serial.print("a=");
22 | Serial.println(a,DEC); // 整数値変数aの値を表示
23 |
24 | Serial.print("c=");
25 | Serial.write(c); // 文字変数cの値を表示
26 | Serial.println(); // 改行する
27 |
28 | Serial.print("s=");
29 | Serial.println(s); // 文字列変数sの値を表示
30 |
31 | size = sizeof(s); // sのサイズをsizeに代入
32 | Serial.print("sizeof(s)=");
33 | Serial.println(size,DEC); // sizeの値を表示して改行
34 |
35 | Serial.print("v=");
36 | Serial.println(v,3); // 浮動小数点数型変数vの値を表示
37 |
38 | for(a=0;a<10;a++) delay(100); // 1秒の待ち時間処理
39 | Serial.println();
40 | }
41 |
--------------------------------------------------------------------------------
/tools/udp_logger.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # UDPを受信する
3 | # Copyright (c) 2016 Wataru KUNINO
4 |
5 | echo "UDP Logger (usage: ${0} port)" # タイトル表示
6 | if [ ${#} = 1 ] # 入力パラメータ数の確認
7 | then # 1つだった時
8 | if [ ${1} -ge 1 ] && [ ${1} -le 65535 ] # ポート番号の範囲確認
9 | then # 1以上65535以下の時
10 | PORT=${1} # ポート番号を設定
11 | else # 範囲外だった時
12 | PORT=1024 # UDPポート番号を1024に
13 | fi # ifの終了
14 | else # 1つでは無かった時
15 | PORT=1024 # UDPポート番号を1024に
16 | fi # ifの終了
17 | echo "Listening UDP port "${PORT}"..." # ポート番号表示
18 | while true # 永遠に
19 | do # 繰り返し
20 | if [ ${PORT} -lt 1024 ] # ポート番号を確認
21 | then # 1024未満の時
22 | UDP=`sudo netcat -luw0 ${PORT}` # UDPパケットを取得
23 | else # ポート番号が1024以上の時
24 | UDP=`netcat -luw0 ${PORT}` # UDPパケットを取得
25 | fi # ifの終了
26 | DATE=`date "+%Y/%m/%d %R"` # 日時を取得
27 | echo -E $DATE, $UDP # 取得日時とデータを表示
28 | done # 繰り返しここまで
29 |
--------------------------------------------------------------------------------
/5_learn32/esp32_23_rtr_lcd/lcdisp4.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | LCDへの4分割表示用関数
6 |
7 | Copyright (c) 2018 Wataru KUNINO
8 | https://bokunimo.net/bokunimowakaru/
9 | *********************************************************************/
10 |
11 | void lcdisp4(const char *s,int num){ // LCDへの4分割表示用関数の定義
12 | char lc[7]; // LCD表示用の6文字配列変数lcの定義
13 | strncpy(lc,s,6); // 文字列を6文字まで変数lcへコピー
14 | if(lc[5]=='_') lc[5]=s[6]; // 6文字目が_のときは7文字目をコピー
15 | for(int i=strlen(lc);i<6;i++) lc[i]=' ';// 6文字に満たない場合に空白を代入
16 | lc[6]='\0'; // 文字列の終端(文字列の最後は'\0')
17 | lcd.setCursor(8*((num/2)%2),(num%2)); // num=0:左上,1:左下,2:右上,3:右下
18 | lcd.print(num+1); // num+1の値を表示
19 | lcd.print(':'); // 「:」を表示
20 | lcd.print(lc); // 文字列を表示
21 | }
22 |
23 | void lcdisp4(int val,int num){ // 整数1値入力時の表示用関数の定義
24 | char lc[7]; // LCD表示用の6文字配列変数lcの定義
25 | itoa(val,lc,10); // 数値valを文字列変数lcへ代入
26 | lcdisp4(lc,num); // 前記lcdisp4を呼び出す
27 | }
28 |
29 | void lcdisp4(int val1,int val2,int num){ // 整数2値入力時の表示用関数の定義
30 | char lc[7]; // LCD表示用の6文字配列変数lcの定義
31 | snprintf(lc,7,"%d,%d",val1,val2); // 数値val1と2を文字列変数lcへ代入
32 | lcdisp4(lc,num); // 前記lcdisp4を呼び出す
33 | }
34 |
--------------------------------------------------------------------------------
/2_example/example59_env/i2c_sht31.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | I2C接続の温湿度センサの値を読み取る
6 | SENSIRION社 SHT31
7 | Copyright (c) 2017-2019 Wataru KUNINO
8 | https://bokunimo.net/bokunimowakaru/
9 | *********************************************************************/
10 |
11 | #include
12 | #define I2C_sht 0x45 // SHT31 の I2C アドレス
13 | // #define I2C_sht 0x44 // M5用SHT30 の I2C アドレス
14 |
15 | float _i2c_sht31_hum;
16 |
17 | float sht31_getTemp(){
18 | int temp,hum;
19 | _i2c_sht31_hum=-999.;
20 | Wire.beginTransmission(I2C_sht);
21 | Wire.write(0x2C);
22 | Wire.write(0x06);
23 | delay(18); // 15ms以上
24 | if( Wire.endTransmission() ) return -999.;
25 | if( Wire.requestFrom(I2C_sht,6) >= 5){
26 | temp = Wire.read();
27 | temp <<= 8;
28 | temp += Wire.read();
29 | Wire.read();
30 | hum = Wire.read();
31 | hum <<= 8;
32 | hum += Wire.read();
33 | Wire.read();
34 | _i2c_sht31_hum = (float)hum / 65535. * 100.;
35 | return (float)temp / 65535. * 175. - 45.;
36 | }else return -999.;
37 | }
38 |
39 | float sht31_getHum(){
40 | return _i2c_sht31_hum;
41 | }
42 |
43 | boolean sht31_Setup(){
44 | delay(2); // 1ms以上
45 | Wire.begin(); // I2Cインタフェースの使用を開始
46 | delay(18); // 15ms以上
47 | float temp = sht31_getTemp();
48 | if(temp >= -45) return true; else return false;
49 | }
50 |
--------------------------------------------------------------------------------
/2_example/example20_camL/README.md:
--------------------------------------------------------------------------------
1 | # トラブルシューティング
2 |
3 | ## 電源が安定しているかどうか
4 | 電源が不安定だと、ESPモジュールが起動しない、または起動しても
5 | 正しく動作しないことがあります。
6 | 起動時やWi-Fi接続時、カメラ動作時は、多くの電流を消費するので、
7 | 目安として600mA程度の電流が流せる電源回路を使用してください。
8 |
9 | ## カメラの電源電圧は5V
10 | Adafruit 1386 の電源入力電圧は5Vです。古いバージョンの基板には
11 | 「3.3V」と書かれていますが、基板上にLDOが実装されているので、
12 | およそ4~5V程度を入力する必要があります。
13 |
14 | ## シリアルのTXDとRXDはクロス接続
15 | カメラのTXDをESPモジュールのRXD(本サンプルではIO12(4番ピン))に、
16 | カメラのRXDをESPモジュールのTXD(本サンプルではIO14(3番ピン))に
17 | 接続してください。
18 |
19 | ## LCDに「Example 20 cam」が表示されたまま動作しない①
20 | Wi-Fiアクセスポイントとの接続に失敗しています。
21 | 無線LANアクセスポイントのSSIDとパスワードをプログラム内の
22 | #define SSIDとPASSに設定して下さい。
23 |
24 | ## LCDに「Example 20 cam」が表示されたまま動作しない②
25 | カメラとの通信に失敗しています。
26 | カメラの電源電圧、シリアル配線などを確認してください。
27 |
28 |
29 | ## ブラウザに「防犯カメラ STATUS」の画面が表示されない
30 | ネットワーク内のDHCPサーバが動作していない、
31 | 異なる無線LANアクセスポイントへ接続されている、
32 | 異なるIPアドレスが設定されている、
33 | 無線LANアクセスポイントやRaspberry Piのファイヤーウォール等で
34 | パケットが破棄されているなどが考えられます。
35 |
36 | ## ブラウザに画面は表示されるが、写真データが(得られるが)表示できない/ノイズが入る
37 | コンパイル時に「ツール」メニュー内の「CPU Frequency」で160MHz
38 | を設定してください。
39 | ただし、CPU(マイコン)の周波数を160MHzすることで、消費電力が
40 | 増大し、電源によっては電流容量が不足することがあります。
41 | 致命的な問題が無い限り、80MHzで使用することをお奨めします。
42 | CPUの周波数変更で改善できない場合は、シリアル接続や電源などに
43 | ノイズが混入している可能性が考えられます。
44 |
45 | ## ブラウザの互換性・ブラウザのセキュリティ対策
46 | ブラウザのバージョンアップやセキュリティ対策により、表示でき
47 | なくなることがあります。
48 | また、ブラウザのバージョンアップで表示できるようになることも
49 | あります。
50 | 例えば、IPアドレスによるアクセスを危険と見なす場合もあれば、
51 | 同一LAN内のコンテンツは安全と見なす場合など、ブラウザや、その
52 | バージョン、設定、ブラウザを開発する会社の方針などによって
53 | 状況が変化します。
54 | 一例として、以下のような複数のブラウザで試してみて下さい。
55 | (IE、Edge、Safari、Chrome、FireFoxなど)
56 |
57 | ## 動作ログの確認方法(ご参考)
58 | Arduino IDEのウィンドウ右上にある虫眼鏡のアイコンをクリックし、
59 | 「シリアルモニタ」を起動し、シリアルモニタの右下のボーレートを
60 | 9600bpsに設定すると、動作ログが表示されます。
61 |
--------------------------------------------------------------------------------
/2_example/example09_hum/i2c_hdc.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | I2C接続の温湿度センサの値を読み取る
6 | TI社 HDC1000
7 | Copyright (c) 2015-2019 Wataru KUNINO
8 | https://bokunimo.net/bokunimowakaru/
9 | *********************************************************************/
10 |
11 | #include
12 | #define I2C_hdc 0x40 // HDC1000 の I2C アドレス
13 |
14 | float getTemp(){
15 | int ret;
16 | Wire.beginTransmission(I2C_hdc);
17 | Wire.write(0x00); // 温度レジスタ 00
18 | if( Wire.endTransmission() == 0){
19 | delay(9); // 6.5ms以上
20 | Wire.requestFrom(I2C_hdc,2);
21 | if(Wire.available()==0) return -999.;
22 | ret = Wire.read();
23 | ret <<= 8;
24 | if(Wire.available()==0) return -999.;
25 | ret += Wire.read();
26 | return (float)ret / 65536. * 165. - 40.;
27 | }else return -999.;
28 | }
29 |
30 | float getHum(){
31 | int ret;
32 | Wire.beginTransmission(I2C_hdc);
33 | Wire.write(0x01); // 湿度レジスタ 01
34 | if( Wire.endTransmission() == 0){
35 | delay(9); // 6.5ms以上
36 | Wire.requestFrom(I2C_hdc,2);
37 | if(Wire.available()==0) return -999.;
38 | ret = Wire.read();
39 | ret <<= 8;
40 | if(Wire.available()==0) return -999.;
41 | ret += Wire.read();
42 | return (float)ret / 65536. * 100.;
43 | }else return -999.;
44 | }
45 |
46 | void hdcSetup(){
47 | Wire.begin(); // I2Cインタフェースの使用を開始
48 | delay(18); // 15ms以上
49 | Wire.beginTransmission(I2C_hdc);
50 | Wire.write(0x02); // 設定レジスタ 02
51 | Wire.write(0x00);
52 | Wire.write(0x00);
53 | Wire.endTransmission();
54 | }
55 |
--------------------------------------------------------------------------------
/2_example/example09c_hum/i2c_hdc.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | I2C接続の温湿度センサの値を読み取る
6 | TI社 HDC1000
7 | Copyright (c) 2015-2019 Wataru KUNINO
8 | https://bokunimo.net/bokunimowakaru/
9 | *********************************************************************/
10 |
11 | #include
12 | #define I2C_hdc 0x40 // HDC1000 の I2C アドレス
13 |
14 | float getTemp(){
15 | int ret;
16 | Wire.beginTransmission(I2C_hdc);
17 | Wire.write(0x00); // 温度レジスタ 00
18 | if( Wire.endTransmission() == 0){
19 | delay(9); // 6.5ms以上
20 | Wire.requestFrom(I2C_hdc,2);
21 | if(Wire.available()==0) return -999.;
22 | ret = Wire.read();
23 | ret <<= 8;
24 | if(Wire.available()==0) return -999.;
25 | ret += Wire.read();
26 | return (float)ret / 65536. * 165. - 40.;
27 | }else return -999.;
28 | }
29 |
30 | float getHum(){
31 | int ret;
32 | Wire.beginTransmission(I2C_hdc);
33 | Wire.write(0x01); // 湿度レジスタ 01
34 | if( Wire.endTransmission() == 0){
35 | delay(9); // 6.5ms以上
36 | Wire.requestFrom(I2C_hdc,2);
37 | if(Wire.available()==0) return -999.;
38 | ret = Wire.read();
39 | ret <<= 8;
40 | if(Wire.available()==0) return -999.;
41 | ret += Wire.read();
42 | return (float)ret / 65536. * 100.;
43 | }else return -999.;
44 | }
45 |
46 | void hdcSetup(){
47 | Wire.begin(); // I2Cインタフェースの使用を開始
48 | delay(18); // 15ms以上
49 | Wire.beginTransmission(I2C_hdc);
50 | Wire.write(0x02); // 設定レジスタ 02
51 | Wire.write(0x00);
52 | Wire.write(0x00);
53 | Wire.endTransmission();
54 | }
55 |
--------------------------------------------------------------------------------
/2_example/example09m_hum/i2c_hdc.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | I2C接続の温湿度センサの値を読み取る
6 | TI社 HDC1000
7 | Copyright (c) 2015-2019 Wataru KUNINO
8 | https://bokunimo.net/bokunimowakaru/
9 | *********************************************************************/
10 |
11 | #include
12 | #define I2C_hdc 0x40 // HDC1000 の I2C アドレス
13 |
14 | float getTemp(){
15 | int ret;
16 | Wire.beginTransmission(I2C_hdc);
17 | Wire.write(0x00); // 温度レジスタ 00
18 | if( Wire.endTransmission() == 0){
19 | delay(9); // 6.5ms以上
20 | Wire.requestFrom(I2C_hdc,2);
21 | if(Wire.available()==0) return -999.;
22 | ret = Wire.read();
23 | ret <<= 8;
24 | if(Wire.available()==0) return -999.;
25 | ret += Wire.read();
26 | return (float)ret / 65536. * 165. - 40.;
27 | }else return -999.;
28 | }
29 |
30 | float getHum(){
31 | int ret;
32 | Wire.beginTransmission(I2C_hdc);
33 | Wire.write(0x01); // 湿度レジスタ 01
34 | if( Wire.endTransmission() == 0){
35 | delay(9); // 6.5ms以上
36 | Wire.requestFrom(I2C_hdc,2);
37 | if(Wire.available()==0) return -999.;
38 | ret = Wire.read();
39 | ret <<= 8;
40 | if(Wire.available()==0) return -999.;
41 | ret += Wire.read();
42 | return (float)ret / 65536. * 100.;
43 | }else return -999.;
44 | }
45 |
46 | void hdcSetup(){
47 | Wire.begin(); // I2Cインタフェースの使用を開始
48 | delay(18); // 15ms以上
49 | Wire.beginTransmission(I2C_hdc);
50 | Wire.write(0x02); // 設定レジスタ 02
51 | Wire.write(0x00);
52 | Wire.write(0x00);
53 | Wire.endTransmission();
54 | }
55 |
--------------------------------------------------------------------------------
/2_example/example41_hum/i2c_hdc.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | I2C接続の温湿度センサの値を読み取る
6 | TI社 HDC1000
7 | Copyright (c) 2015-2019 Wataru KUNINO
8 | https://bokunimo.net/bokunimowakaru/
9 | *********************************************************************/
10 |
11 | #include
12 | #define I2C_hdc 0x40 // HDC1000 の I2C アドレス
13 |
14 | float getTemp(){
15 | int ret;
16 | Wire.beginTransmission(I2C_hdc);
17 | Wire.write(0x00); // 温度レジスタ 00
18 | if( Wire.endTransmission() == 0){
19 | delay(9); // 6.5ms以上
20 | Wire.requestFrom(I2C_hdc,2);
21 | if(Wire.available()==0) return -999.;
22 | ret = Wire.read();
23 | ret <<= 8;
24 | if(Wire.available()==0) return -999.;
25 | ret += Wire.read();
26 | return (float)ret / 65536. * 165. - 40.;
27 | }else return -999.;
28 | }
29 |
30 | float getHum(){
31 | int ret;
32 | Wire.beginTransmission(I2C_hdc);
33 | Wire.write(0x01); // 湿度レジスタ 01
34 | if( Wire.endTransmission() == 0){
35 | delay(9); // 6.5ms以上
36 | Wire.requestFrom(I2C_hdc,2);
37 | if(Wire.available()==0) return -999.;
38 | ret = Wire.read();
39 | ret <<= 8;
40 | if(Wire.available()==0) return -999.;
41 | ret += Wire.read();
42 | return (float)ret / 65536. * 100.;
43 | }else return -999.;
44 | }
45 |
46 | void hdcSetup(){
47 | Wire.begin(); // I2Cインタフェースの使用を開始
48 | delay(18); // 15ms以上
49 | Wire.beginTransmission(I2C_hdc);
50 | Wire.write(0x02); // 設定レジスタ 02
51 | Wire.write(0x00);
52 | Wire.write(0x00);
53 | Wire.endTransmission();
54 | }
55 |
--------------------------------------------------------------------------------
/2_example/example26_tftp/README.md:
--------------------------------------------------------------------------------
1 | Example 26:
2 | # センサデバイス用 TFTPクライアント 設定
3 |
4 | TFTPサーバ上から設定ファイルをダウンロードし、モジュール内の設定を変更します。
5 | 本サンプルではESP-WROOM-02モジュールのディープスリープ時間を設定することが出来ます。
6 |
7 | ## TFTPとは
8 |
9 | TFTPはネットワーク機器などの設定ファイルやファームウェアを転送するときなどに使用されているデータ転送プロトコルです。
10 | 使い勝手が簡単で、プロトコルも簡単なので、機器のメンテナンスに向いています。
11 | 認証や暗号化は行わないので、転送時のみ有効にする、もしくは侵入・ファイル転送されても問題の無い用途で利用します。
12 |
13 | TFTPについて、より詳しいサンプルも公開しました(2021/01/16)
14 | 複数ブロック受信,SDカードへの保存に対応:
15 | https://github.com/bokunimowakaru/tftp
16 |
17 | ## 本サンプルの仕様
18 |
19 | 「SLEEP_SEC=時間(秒)」をTFTPで受信すると、ESPモジュールのスリープ間隔を変更することが出来ます。
20 |
21 | ## Raspberry PiへのTFTPサーバのインストール方法
22 |
23 | $ sudo apt-get install tftpd-hpa
24 |
25 | ## 設定ファイル(/etc/default/tftpd-hpa) の例
26 |
27 | # /etc/default/tftpd-hpa
28 | TFTP_USERNAME="tftp"
29 | TFTP_DIRECTORY="/srv/tftp"
30 | TFTP_ADDRESS="0.0.0.0:69"
31 |
32 | ## TFTPサーバの起動と停止
33 |
34 | $ chmod 755 /srv/tftp
35 | $ sudo /etc/init.d/tftpd-hpa start
36 | $ sudo /etc/init.d/tftpd-hpa stop
37 |
38 | ## 転送用のファイルを保存
39 |
40 | $ sudo echo "; Hello! This is from RasPi" | sudo tee /srv/tftp/tftpc_1.ini
41 | $ sudo echo "SLEEP_SEC=50" | sudo tee -a /srv/tftp/tftpc_1.ini
42 | $ sudo chmod 644 /srv/tftp/tftpc_1.ini
43 | $ cat /srv/tftp/tftpc_1.ini
44 | ; Hello! This is from RasPi
45 | SLEEP_SEC=50
46 |
47 | ## 注意事項
48 |
49 | * TFTPクライアント(ESP側)やTFTPサーバ(PCやRaspberry Pi側)起動すると、各機器がセキュリティの脅威にさらされた状態となります。
50 | * また、ウィルスやワームが侵入すると、同じネットワーク上の全ての機器へ感染する恐れが高まります。
51 | * インターネットに接続すると外部からの侵入される場合があります。
52 | * TFTPクライアントは少なくともローカルネット内のみで動作させるようにして下さい。
53 | * TFTPが不必要なときは、停止させてください。
54 |
55 | Copyright (c) 2016-2021 Wataru KUNINO
56 |
57 |
--------------------------------------------------------------------------------
/2_example/example29_dash/promiscuous.h:
--------------------------------------------------------------------------------
1 | /*
2 | 下記の情報およびソースコードを利用させていただきました(2017/9/16)。
3 |
4 | プロミスキャスモードを用いたESP8266でのAmazon Dash Buttonのイベント取得
5 | http://qiita.com/kat-kai/items/3b1d5c74138d77a27c4d
6 |
7 | ライセンス:Qiita利用規約に基づく
8 | 権利者:kat-kai http://qiita.com/kat-kai (2016年12月29日~2017年01月08日)
9 | */
10 |
11 | struct RxControl {
12 | signed rssi:8;
13 | unsigned rate:4;
14 | unsigned is_group:1;
15 | unsigned:1;
16 | unsigned sig_mode:2;
17 | unsigned legacy_length:12;
18 | unsigned damatch0:1;
19 | unsigned damatch1:1;
20 | unsigned bssidmatch0:1;
21 | unsigned bssidmatch1:1;
22 | unsigned MCS:7;
23 | unsigned CWB:1;
24 | unsigned HT_length:16;
25 | unsigned Smoothing:1;
26 | unsigned Not_Sounding:1;
27 | unsigned:1;
28 | unsigned Aggregation:1;
29 | unsigned STBC:2;
30 | unsigned FEC_CODING:1;
31 | unsigned SGI:1;
32 | unsigned rxend_state:8;
33 | unsigned ampdu_cnt:8;
34 | unsigned channel:4;
35 | unsigned:12;
36 | };
37 |
38 | struct LenSeq {
39 | uint16_t length;
40 | uint16_t seq;
41 | uint8_t address3[6];
42 | };
43 |
44 | struct sniffer_buf {
45 | struct RxControl rx_ctrl;
46 | uint8_t buf[36];
47 | uint16_t cnt;
48 | struct LenSeq lenseq[1];
49 | };
50 |
51 | struct sniffer_buf2{
52 | struct RxControl rx_ctrl;
53 | uint8_t buf[112];
54 | uint16_t cnt;
55 | uint16_t len;
56 | };
57 |
58 | struct MAC_header {
59 | uint16_t frameControl;
60 | uint16_t duration;
61 | uint8_t addr1[6];
62 | uint8_t addr2[6];
63 | uint8_t addr3[6];
64 | uint16_t sequenceControl;
65 | uint8_t addr4[6];
66 | uint16_t qos;
67 | uint8_t hit[4];
68 | };
69 |
--------------------------------------------------------------------------------
/2_example/example29u_dash/promiscuous.h:
--------------------------------------------------------------------------------
1 | /*
2 | 下記の情報およびソースコードを利用させていただきました(2017/9/16)。
3 |
4 | プロミスキャスモードを用いたESP8266でのAmazon Dash Buttonのイベント取得
5 | http://qiita.com/kat-kai/items/3b1d5c74138d77a27c4d
6 |
7 | ライセンス:Qiita利用規約に基づく
8 | 権利者:kat-kai http://qiita.com/kat-kai (2016年12月29日~2017年01月08日)
9 | */
10 |
11 | struct RxControl {
12 | signed rssi:8;
13 | unsigned rate:4;
14 | unsigned is_group:1;
15 | unsigned:1;
16 | unsigned sig_mode:2;
17 | unsigned legacy_length:12;
18 | unsigned damatch0:1;
19 | unsigned damatch1:1;
20 | unsigned bssidmatch0:1;
21 | unsigned bssidmatch1:1;
22 | unsigned MCS:7;
23 | unsigned CWB:1;
24 | unsigned HT_length:16;
25 | unsigned Smoothing:1;
26 | unsigned Not_Sounding:1;
27 | unsigned:1;
28 | unsigned Aggregation:1;
29 | unsigned STBC:2;
30 | unsigned FEC_CODING:1;
31 | unsigned SGI:1;
32 | unsigned rxend_state:8;
33 | unsigned ampdu_cnt:8;
34 | unsigned channel:4;
35 | unsigned:12;
36 | };
37 |
38 | struct LenSeq {
39 | uint16_t length;
40 | uint16_t seq;
41 | uint8_t address3[6];
42 | };
43 |
44 | struct sniffer_buf {
45 | struct RxControl rx_ctrl;
46 | uint8_t buf[36];
47 | uint16_t cnt;
48 | struct LenSeq lenseq[1];
49 | };
50 |
51 | struct sniffer_buf2{
52 | struct RxControl rx_ctrl;
53 | uint8_t buf[112];
54 | uint16_t cnt;
55 | uint16_t len;
56 | };
57 |
58 | struct MAC_header {
59 | uint16_t frameControl;
60 | uint16_t duration;
61 | uint8_t addr1[6];
62 | uint8_t addr2[6];
63 | uint8_t addr3[6];
64 | uint16_t sequenceControl;
65 | uint8_t addr4[6];
66 | uint16_t qos;
67 | uint8_t hit[4];
68 | };
69 |
--------------------------------------------------------------------------------
/5_learn32/esp32_21_bell_lcd/lcdisp.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | UTF8の制御コードを除去して(UTF8をASCIIカナ文字へ変換するときに使用)
6 | LCD(16文字2桁)へ表示します
7 |
8 | Copyright (c) 2014-2019 Wataru KUNINO
9 | https://bokunimo.net/bokunimowakaru/
10 | *********************************************************************/
11 |
12 | void _utf_del_uni(char *s){
13 | unsigned int i=0;
14 | unsigned int j=0;
15 | while(s[i]!='\0'){
16 | if((byte)s[i]==0xEF){
17 | if((byte)s[i+1]==0xBE) s[i+2] += 0x40;
18 | i+=2;
19 | }
20 | if(isprint(s[i]) || ((byte)s[i] >=0xA0 && (byte)s[i] <= 0xDF)){
21 | s[j]=s[i];
22 | j++;
23 | }
24 | i++;
25 | }
26 | s[j]='\0';
27 | }
28 |
29 | void lcdisp(const char *s){
30 | lcdisp(s,0);
31 | }
32 |
33 | void lcdisp(const char *s,int y){
34 | char lc[17]; // LCD表示用の文字列変数
35 | char utf[129];
36 | int i;
37 | memset(lc,0,17); // 文字列変数lcの初期化(17バイト)
38 | memset(utf,0,129);
39 | strncpy(utf,s,128);
40 |
41 | if(y<0 || y>1)return;
42 | _utf_del_uni(utf);
43 | strncpy(lc,utf,16);
44 | lcd.setCursor(0,y); // カーソル位置を左へ
45 | lcd.print(lc); // 液晶へ転送
46 | for(i=strlen(utf);i<16;i++)lcd.print(' ');
47 | if( strlen(utf)<=16) return;
48 | strncpy(lc,utf+16,16);
49 | lcd.setCursor(0,1);
50 | lcd.print(lc); // 液晶へ転送
51 | for(i=strlen(utf+16);i<16;i++)lcd.print(' ');
52 | }
53 |
--------------------------------------------------------------------------------
/5_learn32/esp32_22_sens_lcd/lcdisp.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | UTF8の制御コードを除去して(UTF8をASCIIカナ文字へ変換するときに使用)
6 | LCD(16文字2桁)へ表示します
7 |
8 | Copyright (c) 2014-2019 Wataru KUNINO
9 | https://bokunimo.net/bokunimowakaru/
10 | *********************************************************************/
11 |
12 | void _utf_del_uni(char *s){
13 | unsigned int i=0;
14 | unsigned int j=0;
15 | while(s[i]!='\0'){
16 | if((byte)s[i]==0xEF){
17 | if((byte)s[i+1]==0xBE) s[i+2] += 0x40;
18 | i+=2;
19 | }
20 | if(isprint(s[i]) || ((byte)s[i] >=0xA0 && (byte)s[i] <= 0xDF)){
21 | s[j]=s[i];
22 | j++;
23 | }
24 | i++;
25 | }
26 | s[j]='\0';
27 | }
28 |
29 | void lcdisp(const char *s){
30 | lcdisp(s,0);
31 | }
32 |
33 | void lcdisp(const char *s,int y){
34 | char lc[17]; // LCD表示用の文字列変数
35 | char utf[129];
36 | int i;
37 | memset(lc,0,17); // 文字列変数lcの初期化(17バイト)
38 | memset(utf,0,129);
39 | strncpy(utf,s,128);
40 |
41 | if(y<0 || y>1)return;
42 | _utf_del_uni(utf);
43 | strncpy(lc,utf,16);
44 | lcd.setCursor(0,y); // カーソル位置を左へ
45 | lcd.print(lc); // 液晶へ転送
46 | for(i=strlen(utf);i<16;i++)lcd.print(' ');
47 | if( strlen(utf)<=16) return;
48 | strncpy(lc,utf+16,16);
49 | lcd.setCursor(0,1);
50 | lcd.print(lc); // 液晶へ転送
51 | for(i=strlen(utf+16);i<16;i++)lcd.print(' ');
52 | }
53 |
--------------------------------------------------------------------------------
/5_learn32/esp32_23_rtr_lcd/lcdisp.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | UTF8の制御コードを除去して(UTF8をASCIIカナ文字へ変換するときに使用)
6 | LCD(16文字2桁)へ表示します
7 |
8 | Copyright (c) 2014-2019 Wataru KUNINO
9 | https://bokunimo.net/bokunimowakaru/
10 | *********************************************************************/
11 |
12 | void _utf_del_uni(char *s){
13 | unsigned int i=0;
14 | unsigned int j=0;
15 | while(s[i]!='\0'){
16 | if((byte)s[i]==0xEF){
17 | if((byte)s[i+1]==0xBE) s[i+2] += 0x40;
18 | i+=2;
19 | }
20 | if(isprint(s[i]) || ((byte)s[i] >=0xA0 && (byte)s[i] <= 0xDF)){
21 | s[j]=s[i];
22 | j++;
23 | }
24 | i++;
25 | }
26 | s[j]='\0';
27 | }
28 |
29 | void lcdisp(const char *s){
30 | lcdisp(s,0);
31 | }
32 |
33 | void lcdisp(const char *s,int y){
34 | char lc[17]; // LCD表示用の文字列変数
35 | char utf[129];
36 | int i;
37 | memset(lc,0,17); // 文字列変数lcの初期化(17バイト)
38 | memset(utf,0,129);
39 | strncpy(utf,s,128);
40 |
41 | if(y<0 || y>1)return;
42 | _utf_del_uni(utf);
43 | strncpy(lc,utf,16);
44 | lcd.setCursor(0,y); // カーソル位置を左へ
45 | lcd.print(lc); // 液晶へ転送
46 | for(i=strlen(utf);i<16;i++)lcd.print(' ');
47 | if( strlen(utf)<=16) return;
48 | strncpy(lc,utf+16,16);
49 | lcd.setCursor(0,1);
50 | lcd.print(lc); // 液晶へ転送
51 | for(i=strlen(utf+16);i<16;i++)lcd.print(' ');
52 | }
53 |
--------------------------------------------------------------------------------
/5_learn32/esp32_24_ntp_lcd/lcdisp.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | UTF8の制御コードを除去して(UTF8をASCIIカナ文字へ変換するときに使用)
6 | LCD(16文字2桁)へ表示します
7 |
8 | Copyright (c) 2014-2019 Wataru KUNINO
9 | https://bokunimo.net/bokunimowakaru/
10 | *********************************************************************/
11 |
12 | void _utf_del_uni(char *s){
13 | unsigned int i=0;
14 | unsigned int j=0;
15 | while(s[i]!='\0'){
16 | if((byte)s[i]==0xEF){
17 | if((byte)s[i+1]==0xBE) s[i+2] += 0x40;
18 | i+=2;
19 | }
20 | if(isprint(s[i]) || ((byte)s[i] >=0xA0 && (byte)s[i] <= 0xDF)){
21 | s[j]=s[i];
22 | j++;
23 | }
24 | i++;
25 | }
26 | s[j]='\0';
27 | }
28 |
29 | void lcdisp(const char *s){
30 | lcdisp(s,0);
31 | }
32 |
33 | void lcdisp(const char *s,int y){
34 | char lc[17]; // LCD表示用の文字列変数
35 | char utf[129];
36 | int i;
37 | memset(lc,0,17); // 文字列変数lcの初期化(17バイト)
38 | memset(utf,0,129);
39 | strncpy(utf,s,128);
40 |
41 | if(y<0 || y>1)return;
42 | _utf_del_uni(utf);
43 | strncpy(lc,utf,16);
44 | lcd.setCursor(0,y); // カーソル位置を左へ
45 | lcd.print(lc); // 液晶へ転送
46 | for(i=strlen(utf);i<16;i++)lcd.print(' ');
47 | if( strlen(utf)<=16) return;
48 | strncpy(lc,utf+16,16);
49 | lcd.setCursor(0,1);
50 | lcd.print(lc); // 液晶へ転送
51 | for(i=strlen(utf+16);i<16;i++)lcd.print(' ');
52 | }
53 |
--------------------------------------------------------------------------------
/5_learn32/esp32_25_wtr_lcd/lcdisp.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | UTF8の制御コードを除去して(UTF8をASCIIカナ文字へ変換するときに使用)
6 | LCD(16文字2桁)へ表示します
7 |
8 | Copyright (c) 2014-2019 Wataru KUNINO
9 | https://bokunimo.net/bokunimowakaru/
10 | *********************************************************************/
11 |
12 | void _utf_del_uni(char *s){
13 | unsigned int i=0;
14 | unsigned int j=0;
15 | while(s[i]!='\0'){
16 | if((byte)s[i]==0xEF){
17 | if((byte)s[i+1]==0xBE) s[i+2] += 0x40;
18 | i+=2;
19 | }
20 | if(isprint(s[i]) || ((byte)s[i] >=0xA0 && (byte)s[i] <= 0xDF)){
21 | s[j]=s[i];
22 | j++;
23 | }
24 | i++;
25 | }
26 | s[j]='\0';
27 | }
28 |
29 | void lcdisp(const char *s){
30 | lcdisp(s,0);
31 | }
32 |
33 | void lcdisp(const char *s,int y){
34 | char lc[17]; // LCD表示用の文字列変数
35 | char utf[129];
36 | int i;
37 | memset(lc,0,17); // 文字列変数lcの初期化(17バイト)
38 | memset(utf,0,129);
39 | strncpy(utf,s,128);
40 |
41 | if(y<0 || y>1)return;
42 | _utf_del_uni(utf);
43 | strncpy(lc,utf,16);
44 | lcd.setCursor(0,y); // カーソル位置を左へ
45 | lcd.print(lc); // 液晶へ転送
46 | for(i=strlen(utf);i<16;i++)lcd.print(' ');
47 | if( strlen(utf)<=16) return;
48 | strncpy(lc,utf+16,16);
49 | lcd.setCursor(0,1);
50 | lcd.print(lc); // 液晶へ転送
51 | for(i=strlen(utf+16);i<16;i++)lcd.print(' ');
52 | }
53 |
--------------------------------------------------------------------------------
/5_learn32/esp32_18_voice/uspeech_phoneme.cpp:
--------------------------------------------------------------------------------
1 | #include "uspeech.h"
2 | /**
3 | * The recognizer function: takes 1-4ms to execute
4 | */
5 | char signal::getPhoneme()
6 | {
7 | #ifdef ARDUINO_ENVIRONMENT
8 | sample();
9 | #endif
10 | unsigned int pp =power();
11 | //Serial.print(F("pp=")); Serial.println(pp);
12 | // if (pp>SILENCE) {
13 | if (pp > micPowerThreshold * 32) {
14 | //Perform Division
15 | int k = complexity(pp);
16 | //Low pass filter for noise removal
17 | overview[6] = overview[5];
18 | overview[5] = overview[4];
19 | overview[4] = overview[3];
20 | overview[3] = overview[2];
21 | overview[2] = overview[1];
22 | overview[1] = overview[0];
23 | overview[0] = k;
24 |
25 | int coeff = 0;
26 | for (uint8_t f=0; f<6; f++) {
27 | coeff += overview[f];
28 | }
29 | coeff /= 7;
30 |
31 | micPower = 0.05 * maxPower() + (1 - 0.05) * micPower;
32 |
33 | testCoeff = coeff;
34 | //Serial.print(F("coeff: ")); Serial.println(coeff); //Use this for debugging
35 |
36 | //Twiddle with the numbers here if your getting false triggers
37 | //This is the main classifier part
38 |
39 | if (coeff fconstant) {
54 | return 'f';
55 | }
56 | }
57 |
58 | return phoneme;
59 |
60 | }
61 | else{
62 | micPower = 0;
63 | testCoeff = 0;
64 | return ' ';
65 | }
66 | }
67 |
68 |
--------------------------------------------------------------------------------
/2_example/example16w_led/html.ino:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | HTMLコンテンツ LEDの輝度制御
3 |
4 | Copyright (c) 2016-2019 Wataru KUNINO
5 | *******************************************************************************/
6 |
7 | void getHtml(char *html, int target){
8 | char s[65],s_ip[16];
9 | uint32_t ip = WiFi.localIP();
10 |
11 | sprintf(s_ip,"%d.%d.%d.%d",
12 | ip & 255,
13 | ip>>8 & 255,
14 | ip>>16 & 255,
15 | ip>>24
16 | );
17 | snprintf(html,2047,"\n\nWi-Fi コンシェルジェ 照明担当\n\n\n\nLED STATUS
\n");
18 | if(target==0) sprintf(s,"0 (LED OFF)
");
19 | if(target==1) sprintf(s,"1 (LED ON)
");
20 | if(target>1) sprintf(s,"%d (キャンドル)
",target);
21 | if(target<0) sprintf(s,"%d (輝度=%d%%)
",target,-target*10);
22 | snprintf(html,2047,"%s\n%s\n
\nHTTP GET
\nhttp://%s/?L=n
\n(n: 0=OFF, 1=ON, 2~10=キャンドル, -1~-10=輝度)
",html,s,s_ip);
23 | sprintf(s,"\n",html,s);
25 | snprintf(html,2047,"%s\n%s\n\n\n\n\n",html,s);
26 | sprintf(s,"LED=%d",target); // 変数sに「LED=」とtarget値を代入
27 | Serial.println(s); // シリアルへコンテンツを出力
28 | }
29 |
--------------------------------------------------------------------------------
/2_example/example48w_led/html.ino:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | HTMLコンテンツ LEDの輝度制御
3 |
4 | Copyright (c) 2016-2019 Wataru KUNINO
5 | *******************************************************************************/
6 |
7 | void getHtml(char *html, int target){
8 | char s[65],s_ip[16];
9 | uint32_t ip = WiFi.localIP();
10 |
11 | sprintf(s_ip,"%d.%d.%d.%d",
12 | ip & 255,
13 | ip>>8 & 255,
14 | ip>>16 & 255,
15 | ip>>24
16 | );
17 | snprintf(html,2047,"\n\nWi-Fi コンシェルジェ 照明担当\n\n\n\nLED STATUS
\n");
18 | if(target==0) sprintf(s,"0 (LED OFF)
");
19 | if(target==1) sprintf(s,"1 (LED ON)
");
20 | if(target>1) sprintf(s,"%d (キャンドル)
",target);
21 | if(target<0) sprintf(s,"%d (輝度=%d%%)
",target,-target*10);
22 | snprintf(html,2047,"%s\n%s\n
\nHTTP GET
\nhttp://%s/?L=n
\n(n: 0=OFF, 1=ON, 2~10=キャンドル, -1~-10=輝度)
",html,s,s_ip);
23 | sprintf(s,"\n",html,s);
25 | snprintf(html,2047,"%s\n%s\n\n\n\n\n",html,s);
26 | sprintf(s,"LED=%d",target); // 変数sに「LED=」とtarget値を代入
27 | Serial.println(s); // シリアルへコンテンツを出力
28 | }
29 |
--------------------------------------------------------------------------------
/5_learn32/esp32_18_voice_ok/uspeech_phoneme.cpp:
--------------------------------------------------------------------------------
1 | #include "uspeech.h"
2 | /**
3 | * The recognizer function: takes 1-4ms to execute
4 | */
5 | char signal::getPhoneme()
6 | {
7 | #ifdef ARDUINO_ENVIRONMENT
8 | sample();
9 | #endif
10 | unsigned int pp =power();
11 | //Serial.print(F("pp=")); Serial.println(pp);
12 | // if (pp>SILENCE) {
13 | if (pp > micPowerThreshold * 32) {
14 | //Perform Division
15 | int k = complexity(pp);
16 | //Low pass filter for noise removal
17 | overview[6] = overview[5];
18 | overview[5] = overview[4];
19 | overview[4] = overview[3];
20 | overview[3] = overview[2];
21 | overview[2] = overview[1];
22 | overview[1] = overview[0];
23 | overview[0] = k;
24 |
25 | int coeff = 0;
26 | for (uint8_t f=0; f<6; f++) {
27 | coeff += overview[f];
28 | }
29 | coeff /= 7;
30 |
31 | micPower = 0.05 * maxPower() + (1 - 0.05) * micPower;
32 |
33 | testCoeff = coeff;
34 | //Serial.print(F("coeff: ")); Serial.println(coeff); //Use this for debugging
35 |
36 | //Twiddle with the numbers here if your getting false triggers
37 | //This is the main classifier part
38 |
39 | if (coeff fconstant) {
54 | return 'f';
55 | }
56 | }
57 |
58 | return phoneme;
59 |
60 | }
61 | else{
62 | micPower = 0;
63 | testCoeff = 0;
64 | return ' ';
65 | }
66 | }
67 |
68 |
--------------------------------------------------------------------------------
/2_example/example18_lcd/trUri2txt.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。
3 | HTTPクエリ内のコードを文字に戻す
4 | Copyright (c) 2016-2019 Wataru KUNINO
5 | *********************************************************************/
6 |
7 |
8 | int ahex2i(char c){
9 | if(c>='0' && c<='9') return c-'0';
10 | if(c>='a' && c<='f') return c-'a'+10;
11 | if(c>='A' && c<='F') return c-'A'+10;
12 | return -1;
13 | }
14 |
15 | int trUri2txt(char *s){
16 | int i,j;
17 | int len;
18 |
19 | for(i=0;i j=5 s[3]=s[5]
44 | len=7 -> len=5
45 | s[5]=null
46 |
47 | test
48 | !"#$%&'() ok
49 | |@`[{}]; ok
50 | :+*<>?_, ok
51 | ./~^-= ok
52 |
53 | 0!!!!!!78!!!!!!F OK
54 | 0!!!!!!78!!!!!!F0!!!! OK
55 |
56 | 64バイトの場合
57 | 記号だけのとき=64バイト÷3=21文字まで
58 | カタカナの場合=64バイト÷12=5文字まで
59 | */
60 |
--------------------------------------------------------------------------------
/2_example/example18t_lcd/trUri2txt.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。
3 | HTTPクエリ内のコードを文字に戻す
4 | Copyright (c) 2016-2019 Wataru KUNINO
5 | *********************************************************************/
6 |
7 |
8 | int ahex2i(char c){
9 | if(c>='0' && c<='9') return c-'0';
10 | if(c>='a' && c<='f') return c-'a'+10;
11 | if(c>='A' && c<='F') return c-'A'+10;
12 | return -1;
13 | }
14 |
15 | int trUri2txt(char *s){
16 | int i,j;
17 | int len;
18 |
19 | for(i=0;i j=5 s[3]=s[5]
44 | len=7 -> len=5
45 | s[5]=null
46 |
47 | test
48 | !"#$%&'() ok
49 | |@`[{}]; ok
50 | :+*<>?_, ok
51 | ./~^-= ok
52 |
53 | 0!!!!!!78!!!!!!F OK
54 | 0!!!!!!78!!!!!!F0!!!! OK
55 |
56 | 64バイトの場合
57 | 記号だけのとき=64バイト÷3=21文字まで
58 | カタカナの場合=64バイト÷12=5文字まで
59 | */
60 |
--------------------------------------------------------------------------------
/2_example/example21_talk/trUri2txt.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。
3 | HTTPクエリ内のコードを文字に戻す
4 | Copyright (c) 2016-2019 Wataru KUNINO
5 | *********************************************************************/
6 |
7 |
8 | int ahex2i(char c){
9 | if(c>='0' && c<='9') return c-'0';
10 | if(c>='a' && c<='f') return c-'a'+10;
11 | if(c>='A' && c<='F') return c-'A'+10;
12 | return -1;
13 | }
14 |
15 | int trUri2txt(char *s){
16 | int i,j;
17 | int len;
18 |
19 | for(i=0;i j=5 s[3]=s[5]
44 | len=7 -> len=5
45 | s[5]=null
46 |
47 | test
48 | !"#$%&'() ok
49 | |@`[{}]; ok
50 | :+*<>?_, ok
51 | ./~^-= ok
52 |
53 | 0!!!!!!78!!!!!!F OK
54 | 0!!!!!!78!!!!!!F0!!!! OK
55 |
56 | 64バイトの場合
57 | 記号だけのとき=64バイト÷3=21文字まで
58 | カタカナの場合=64バイト÷12=5文字まで
59 | */
60 |
--------------------------------------------------------------------------------
/2_example/example50_lcd/trUri2txt.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。
3 | HTTPクエリ内のコードを文字に戻す
4 | Copyright (c) 2016-2019 Wataru KUNINO
5 | *********************************************************************/
6 |
7 |
8 | int ahex2i(char c){
9 | if(c>='0' && c<='9') return c-'0';
10 | if(c>='a' && c<='f') return c-'a'+10;
11 | if(c>='A' && c<='F') return c-'A'+10;
12 | return -1;
13 | }
14 |
15 | int trUri2txt(char *s){
16 | int i,j;
17 | int len;
18 |
19 | for(i=0;i j=5 s[3]=s[5]
44 | len=7 -> len=5
45 | s[5]=null
46 |
47 | test
48 | !"#$%&'() ok
49 | |@`[{}]; ok
50 | :+*<>?_, ok
51 | ./~^-= ok
52 |
53 | 0!!!!!!78!!!!!!F OK
54 | 0!!!!!!78!!!!!!F0!!!! OK
55 |
56 | 64バイトの場合
57 | 記号だけのとき=64バイト÷3=21文字まで
58 | カタカナの場合=64バイト÷12=5文字まで
59 | */
60 |
--------------------------------------------------------------------------------
/2_example/example53_talk/trUri2txt.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。
3 | HTTPクエリ内のコードを文字に戻す
4 | Copyright (c) 2016-2019 Wataru KUNINO
5 | *********************************************************************/
6 |
7 |
8 | int ahex2i(char c){
9 | if(c>='0' && c<='9') return c-'0';
10 | if(c>='a' && c<='f') return c-'a'+10;
11 | if(c>='A' && c<='F') return c-'A'+10;
12 | return -1;
13 | }
14 |
15 | int trUri2txt(char *s){
16 | int i,j;
17 | int len;
18 |
19 | for(i=0;i j=5 s[3]=s[5]
44 | len=7 -> len=5
45 | s[5]=null
46 |
47 | test
48 | !"#$%&'() ok
49 | |@`[{}]; ok
50 | :+*<>?_, ok
51 | ./~^-= ok
52 |
53 | 0!!!!!!78!!!!!!F OK
54 | 0!!!!!!78!!!!!!F0!!!! OK
55 |
56 | 64バイトの場合
57 | 記号だけのとき=64バイト÷3=21文字まで
58 | カタカナの場合=64バイト÷12=5文字まで
59 | */
60 |
--------------------------------------------------------------------------------
/2_example/example18t_lcd_ntp/trUri2txt.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。
3 | HTTPクエリ内のコードを文字に戻す
4 | Copyright (c) 2016-2019 Wataru KUNINO
5 | *********************************************************************/
6 |
7 |
8 | int ahex2i(char c){
9 | if(c>='0' && c<='9') return c-'0';
10 | if(c>='a' && c<='f') return c-'a'+10;
11 | if(c>='A' && c<='F') return c-'A'+10;
12 | return -1;
13 | }
14 |
15 | int trUri2txt(char *s){
16 | int i,j;
17 | int len;
18 |
19 | for(i=0;i j=5 s[3]=s[5]
44 | len=7 -> len=5
45 | s[5]=null
46 |
47 | test
48 | !"#$%&'() ok
49 | |@`[{}]; ok
50 | :+*<>?_, ok
51 | ./~^-= ok
52 |
53 | 0!!!!!!78!!!!!!F OK
54 | 0!!!!!!78!!!!!!F0!!!! OK
55 |
56 | 64バイトの場合
57 | 記号だけのとき=64バイト÷3=21文字まで
58 | カタカナの場合=64バイト÷12=5文字まで
59 | */
60 |
--------------------------------------------------------------------------------
/2_example/example28_lcdkey/trUri2txt.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。
3 | HTTPクエリ内のコードを文字に戻す
4 |
5 | Copyright (c) 2016-2019 Wataru KUNINO
6 | *********************************************************************/
7 |
8 |
9 | int ahex2i(char c){
10 | if(c>='0' && c<='9') return c-'0';
11 | if(c>='a' && c<='f') return c-'a'+10;
12 | if(c>='A' && c<='F') return c-'A'+10;
13 | return -1;
14 | }
15 |
16 | int trUri2txt(char *s){
17 | int i,j;
18 | int len;
19 |
20 | for(i=0;i j=5 s[3]=s[5]
45 | len=7 -> len=5
46 | s[5]=null
47 |
48 | test
49 | !"#$%&'() ok
50 | |@`[{}]; ok
51 | :+*<>?_, ok
52 | ./~^-= ok
53 |
54 | 0!!!!!!78!!!!!!F OK
55 | 0!!!!!!78!!!!!!F0!!!! OK
56 |
57 | 64バイトの場合
58 | 記号だけのとき=64バイト÷3=21文字まで
59 | カタカナの場合=64バイト÷12=5文字まで
60 | */
61 |
--------------------------------------------------------------------------------
/2_example/example60_lcdkey/trUri2txt.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。
3 | HTTPクエリ内のコードを文字に戻す
4 | Copyright (c) 2016-2019 Wataru KUNINO
5 | *********************************************************************/
6 |
7 |
8 | int ahex2i(char c){
9 | if(c>='0' && c<='9') return c-'0';
10 | if(c>='a' && c<='f') return c-'a'+10;
11 | if(c>='A' && c<='F') return c-'A'+10;
12 | return -1;
13 | }
14 |
15 | int trUri2txt(char *s){
16 | int i,j;
17 | int len;
18 |
19 | for(i=0;i j=5 s[3]=s[5]
44 | len=7 -> len=5
45 | s[5]=null
46 |
47 | test
48 | !"#$%&'() ok
49 | |@`[{}]; ok
50 | :+*<>?_, ok
51 | ./~^-= ok
52 |
53 | 0!!!!!!78!!!!!!F OK
54 | 0!!!!!!78!!!!!!F0!!!! OK
55 |
56 | 64バイトの場合
57 | 記号だけのとき=64バイト÷3=21文字まで
58 | カタカナの場合=64バイト÷12=5文字まで
59 | */
60 |
--------------------------------------------------------------------------------
/tools/udp_logger.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | # coding: utf-8
3 | # UDPを受信する
4 | # Copyright (c) 2018-2019 Wataru KUNINO
5 |
6 | from __future__ import print_function
7 | import sys
8 | import socket
9 | import datetime
10 |
11 | buf_n= 128 # 受信バッファ容量(バイト)
12 | argc = len(sys.argv) # 引数の数をargcへ代入
13 | print('UDP Logger (usage: '+sys.argv[0]+' port)') # タイトル表示
14 | if argc == 2: # 入力パラメータ数の確認
15 | port = int(sys.argv[1]) # ポート番号を設定
16 | if port < 1 or port > 65535: # ポート1未満or65535超の時
17 | port = 1024 # UDPポート番号を1024に
18 | else:
19 | port = 1024
20 | print('Listening UDP port', port, '...') # ポート番号表示
21 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # ソケットを作成
22 | sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)# オプション設定
23 | if sock: # 作成に成功したとき
24 | sock.bind(('', port)) # ソケットに接続
25 | while sock: # 永遠に繰り返す
26 | udp=sock.recv(buf_n).decode() # UDPパケットを取得
27 | str='' # 表示用の文字列変数str
28 | for c in udp: # UDPパケット内
29 | if ord(c) >= ord(' '): # 表示可能文字
30 | str += c # 文字列strへ追加
31 | date=datetime.datetime.today() # 日付を取得
32 | print(date.strftime('%Y/%m/%d %H:%M'), end='') # 日付を出力
33 | print(', '+str) # 受信データを出力
34 | sock.close() # ソケットの切断
35 |
--------------------------------------------------------------------------------
/1_practice/practice05_calc/practice05_calc.ino:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | Practice 5: 良く使う演算子
3 | Copyright (c) 2015-2019 Wataru KUNINO
4 | *******************************************************************************/
5 |
6 | void setup() { // 起動時に一度だけ実行される関数
7 | Serial.begin(9600); // シリアル通信速度を9600bpsに設定する
8 | }
9 |
10 | void loop() { // setup実行後に繰り返し実行される関数
11 | int a = 12345; // 整数型の変数aを定義
12 | float v; // 浮動小数点数型変数v
13 |
14 | Serial.println("Practice 04"); // 「Practice 04」を表示
15 |
16 | Serial.print(a,DEC); // 整数値変数aの値を表示
17 | a = a - 345; // a-345を計算してaに代入
18 | Serial.print(" - 345 = ");
19 | Serial.println(a,DEC); // 整数値変数aの値を表示
20 |
21 | Serial.print(a,DEC); // 整数値変数aの値を表示
22 | a = a / 1000; // a÷1000をaに代入
23 | Serial.print(" / 1000 = ");
24 | Serial.println(a,DEC); // 整数値変数aの値を表示
25 |
26 | v = (float) a; // 浮動小数変数vにaを代入
27 | Serial.print("(int) ");
28 | Serial.print(a,DEC); // 整数値変数aの値を表示
29 | a = a / 10; // a÷10をaに代入
30 | Serial.print(" / 10 = ");
31 | Serial.println(a,DEC); // 整数値変数aの値を表示
32 |
33 | Serial.print("(float) ");
34 | Serial.print(v,3); // 浮動小数点数型変数vの値を表示
35 | v = v / 10; // v÷10をvに代入
36 | Serial.print(" / 10 = ");
37 | Serial.println(v,3); // 浮動小数点数型変数vの値を表示
38 |
39 | for(a=0;a<10;a++) delay(100); // 1秒の待ち時間処理
40 | Serial.println();
41 | }
42 |
--------------------------------------------------------------------------------
/2_example/example64_photo_m5/README_Adafruit-ILI9341.md:
--------------------------------------------------------------------------------
1 | # Adafruit ILI9341 Arduino Library [](https://travis-ci.org/adafruit/Adafruit_ILI9341)
2 |
3 | This is a library for the Adafruit ILI9341 display products
4 |
5 | This library works with the Adafruit 2.8" Touch Shield V2 (SPI)
6 | * http://www.adafruit.com/products/1651
7 |
8 | Adafruit 2.4" TFT LCD with Touchscreen Breakout w/MicroSD Socket - ILI9341
9 | * https://www.adafruit.com/product/2478
10 |
11 | 2.8" TFT LCD with Touchscreen Breakout Board w/MicroSD Socket - ILI9341
12 | * https://www.adafruit.com/product/1770
13 |
14 | 2.2" 18-bit color TFT LCD display with microSD card breakout - ILI9340
15 | * https://www.adafruit.com/product/1480
16 |
17 | TFT FeatherWing - 2.4" 320x240 Touchscreen For All Feathers
18 | * https://www.adafruit.com/product/3315
19 |
20 | Check out the links above for our tutorials and wiring diagrams.
21 | These displays use SPI to communicate, 4 or 5 pins are required
22 | to interface (RST is optional).
23 |
24 | Adafruit invests time and resources providing this open source code,
25 | please support Adafruit and open-source hardware by purchasing
26 | products from Adafruit!
27 |
28 | Written by Limor Fried/Ladyada for Adafruit Industries.
29 | MIT license, all text above must be included in any redistribution
30 |
31 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_ILI9341. Check that the Adafruit_ILI9341 folder contains Adafruit_ILI9341.cpp and Adafruit_ILI9341.
32 |
33 | Place the Adafruit_ILI9341 library folder your arduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE
34 |
35 | Also requires the Adafruit_GFX library for Arduino.
36 |
--------------------------------------------------------------------------------
/5_learn32/esp32_05_i2c/i2c_sht31.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | I2C接続の温湿度センサの値を読み取る
6 | SENSIRION社 SHT31
7 | Copyright (c) 2017-2019 Wataru KUNINO
8 | https://bokunimo.net/bokunimowakaru/
9 | *********************************************************************/
10 |
11 | #include
12 | #define I2C_sht 0x45 // SHT31 の I2C アドレス
13 |
14 | float _i2c_sht31_hum;
15 |
16 | float getTemp(){
17 | int temp,hum;
18 | _i2c_sht31_hum=-999.;
19 | Wire.beginTransmission(I2C_sht);
20 | Wire.write(0x2C);
21 | Wire.write(0x06);
22 | delay(18); // 15ms以上
23 | if( Wire.endTransmission() == 0){
24 | Wire.requestFrom(I2C_sht,6);
25 | if(Wire.available()==0) return -999.;
26 | temp = Wire.read();
27 | temp <<= 8;
28 | if(Wire.available()==0) return -999.;
29 | temp += Wire.read();
30 | if(Wire.available()==0) return -999.;
31 | Wire.read();
32 | if(Wire.available()==0) return -999.;
33 | hum = Wire.read();
34 | hum <<= 8;
35 | if(Wire.available()==0) return -999.;
36 | hum += Wire.read();
37 | if(Wire.available()==0) return -999.;
38 | Wire.read();
39 | _i2c_sht31_hum = (float)hum / 65535. * 100.;
40 | return (float)temp / 65535. * 175. - 45.;
41 | }else return -999.;
42 | }
43 |
44 | float getHum(){
45 | return _i2c_sht31_hum;
46 | }
47 |
48 | void shtSetup(){
49 | delay(2); // 1ms以上
50 | Wire.begin(); // I2Cインタフェースの使用を開始
51 | delay(18); // 15ms以上
52 | }
53 |
--------------------------------------------------------------------------------
/5_learn32/esp32_16_hum/i2c_sht31.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | I2C接続の温湿度センサの値を読み取る
6 | SENSIRION社 SHT31
7 | Copyright (c) 2017-2019 Wataru KUNINO
8 | https://bokunimo.net/bokunimowakaru/
9 | *********************************************************************/
10 |
11 | #include
12 | #define I2C_sht 0x45 // SHT31 の I2C アドレス
13 |
14 | float _i2c_sht31_hum;
15 |
16 | float getTemp(){
17 | int temp,hum;
18 | _i2c_sht31_hum=-999.;
19 | Wire.beginTransmission(I2C_sht);
20 | Wire.write(0x2C);
21 | Wire.write(0x06);
22 | delay(18); // 15ms以上
23 | if( Wire.endTransmission() == 0){
24 | Wire.requestFrom(I2C_sht,6);
25 | if(Wire.available()==0) return -999.;
26 | temp = Wire.read();
27 | temp <<= 8;
28 | if(Wire.available()==0) return -999.;
29 | temp += Wire.read();
30 | if(Wire.available()==0) return -999.;
31 | Wire.read();
32 | if(Wire.available()==0) return -999.;
33 | hum = Wire.read();
34 | hum <<= 8;
35 | if(Wire.available()==0) return -999.;
36 | hum += Wire.read();
37 | if(Wire.available()==0) return -999.;
38 | Wire.read();
39 | _i2c_sht31_hum = (float)hum / 65535. * 100.;
40 | return (float)temp / 65535. * 175. - 45.;
41 | }else return -999.;
42 | }
43 |
44 | float getHum(){
45 | return _i2c_sht31_hum;
46 | }
47 |
48 | void shtSetup(){
49 | delay(2); // 1ms以上
50 | Wire.begin(); // I2Cインタフェースの使用を開始
51 | delay(18); // 15ms以上
52 | }
53 |
--------------------------------------------------------------------------------
/tools/get_photo.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # カメラからの配信画像を取得する
3 | # Copyright (c) 2016 Wataru KUNINO
4 |
5 | DEVICE="cam_a_1" # 配信デバイス名(必須)
6 | PORT=1024 # UDPポート番号を1024に
7 |
8 | echo "UDP Logger (usage: ${0} port)" # タイトル表示
9 | if [ ${#} = 1 ]; then # 入力パラメータ数が1つ
10 | if [ ${1} -ge 1 ] && [ ${1} -le 65535 ]; then # ポート番号の範囲確認
11 | PORT=${1} # ポート番号を設定
12 | fi # ifの終了
13 | fi # ifの終了
14 | echo "Listening UDP port "${PORT}"..." # ポート番号表示
15 | mkdir photo >& /dev/null # 写真保存用フォルダ作成
16 | while true # 永遠に
17 | do # 繰り返し
18 | UDP=`sudo netcat -luw0 ${PORT}|tr -d [:cntrl:]|\
19 | tr -d "\!\"\$\%\&\'\(\)\*\+\-\;\<\=\>\?\[\\\]\^\{\|\}\~"`
20 | # UDPパケットを取得
21 | DATE=`date "+%Y/%m/%d %R"` # 日時を取得
22 | DEV=${UDP#,*} # デバイス名を取得(前方)
23 | DEV=${DEV%%,*} # デバイス名を取得(後方)
24 | echo -E $DATE, $UDP|tee -a log_${DEV}.csv # 取得日時とデータを保存
25 | if [ ${DEVICE} = ${DEV} ]; then # カメラからの配信画像時
26 | DATE=`date "+%Y%m%d-%H%M"` # 日時を取得
27 | URL=`echo -E $UDP|cut -d' ' -f2` # スペース区切りの2番目
28 | echo -n "Get "${URL} # 画像取得t実行表示
29 | wget -qT10 ${URL} -Ophoto/${DEVICE}"_"${DATE}.jpg # wget実行
30 | echo " Done" # 終了表示
31 | fi
32 | done # 繰り返し範囲:ここまで
33 |
--------------------------------------------------------------------------------
/2_example/example41_hum_sht31/i2c_sht31.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | I2C接続の温湿度センサの値を読み取る
6 | SENSIRION社 SHT31
7 | Copyright (c) 2017-2019 Wataru KUNINO
8 | https://bokunimo.net/bokunimowakaru/
9 | *********************************************************************/
10 |
11 | #include
12 | #define I2C_sht 0x45 // SHT31 の I2C アドレス
13 |
14 | float _i2c_sht31_hum;
15 |
16 | float getTemp(){
17 | int temp,hum;
18 | _i2c_sht31_hum=-999.;
19 | Wire.beginTransmission(I2C_sht);
20 | Wire.write(0x2C);
21 | Wire.write(0x06);
22 | delay(18); // 15ms以上
23 | if( Wire.endTransmission() == 0){
24 | Wire.requestFrom(I2C_sht,6);
25 | if(Wire.available()==0) return -999.;
26 | temp = Wire.read();
27 | temp <<= 8;
28 | if(Wire.available()==0) return -999.;
29 | temp += Wire.read();
30 | if(Wire.available()==0) return -999.;
31 | Wire.read();
32 | if(Wire.available()==0) return -999.;
33 | hum = Wire.read();
34 | hum <<= 8;
35 | if(Wire.available()==0) return -999.;
36 | hum += Wire.read();
37 | if(Wire.available()==0) return -999.;
38 | Wire.read();
39 | _i2c_sht31_hum = (float)hum / 65535. * 100.;
40 | return (float)temp / 65535. * 175. - 45.;
41 | }else return -999.;
42 | }
43 |
44 | float getHum(){
45 | return _i2c_sht31_hum;
46 | }
47 |
48 | void shtSetup(){
49 | delay(2); // 1ms以上
50 | Wire.begin(); // I2Cインタフェースの使用を開始
51 | delay(18); // 15ms以上
52 | }
53 |
--------------------------------------------------------------------------------
/2_example/example64_photo/README_Adafruit-SSD1331.txt:
--------------------------------------------------------------------------------
1 | /*
2 | 本ソースリストは2017/11/2に下記からダウンロードしたものを、国野亘が改変したものです。
3 |
4 | https://learn.adafruit.com/096-mini-color-oled/wiring
5 |
6 | ダウンロード時点ではESP32に対応していませんでしたので、ESP32で動作するように修正しました。
7 | 将来的には元の権利者であるAdafruitによってESP32対応が図られると思われるため、最小限度の
8 | 修正に止めています。動作に問題が生じる可能性もあります。
9 |
10 | Adafruitによる最新の情報は、下記に掲載されると思います。
11 |
12 | https://github.com/adafruit/Adafruit-SSD1331-OLED-Driver-Library-for-Arduino/issues/10
13 |
14 | 2017/11/2 国野 亘
15 | */
16 | --------------------------------------------------------------------------------
17 |
18 | This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip
19 |
20 | Pick one up today in the adafruit shop!
21 | ------> http://www.adafruit.com/products/684
22 |
23 | These displays use SPI to communicate, 4 or 5 pins are required to
24 | interface
25 |
26 | Adafruit invests time and resources providing this open source code,
27 | please support Adafruit and open-source hardware by purchasing
28 | products from Adafruit!
29 |
30 | Written by Limor Fried/Ladyada for Adafruit Industries.
31 | BSD license, check license.txt for more information
32 | All text above must be included in any redistribution
33 |
34 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_SSD1131. Check that the Adafruit_SSD1331 folder contains Adafruit_SSD1331.cpp and Adafruit_SSD1331.h
35 |
36 | Place the Adafruit_SSD1331 library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
37 |
38 | You will also have to download the Adafruit GFX Graphics core which does all the circles, text, rectangles, etc. You can get it from
39 | https://github.com/adafruit/Adafruit-GFX-Library
40 | and download/install that library as well
41 |
--------------------------------------------------------------------------------
/5_learn32/esp32_26_photof/README_Adafruit-SSD1331.txt:
--------------------------------------------------------------------------------
1 | /*
2 | 本ソースリストは2017/11/2に下記からダウンロードしたものを、国野亘が改変したものです。
3 |
4 | https://learn.adafruit.com/096-mini-color-oled/wiring
5 |
6 | ダウンロード時点ではESP32に対応していませんでしたので、ESP32で動作するように修正しました。
7 | 将来的には元の権利者であるAdafruitによってESP32対応が図られると思われるため、最小限度の
8 | 修正に止めています。動作に問題が生じる可能性もあります。
9 |
10 | Adafruitによる最新の情報は、下記に掲載されると思います。
11 |
12 | https://github.com/adafruit/Adafruit-SSD1331-OLED-Driver-Library-for-Arduino/issues/10
13 |
14 | 2017/11/2 国野 亘
15 | */
16 | --------------------------------------------------------------------------------
17 |
18 | This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip
19 |
20 | Pick one up today in the adafruit shop!
21 | ------> http://www.adafruit.com/products/684
22 |
23 | These displays use SPI to communicate, 4 or 5 pins are required to
24 | interface
25 |
26 | Adafruit invests time and resources providing this open source code,
27 | please support Adafruit and open-source hardware by purchasing
28 | products from Adafruit!
29 |
30 | Written by Limor Fried/Ladyada for Adafruit Industries.
31 | BSD license, check license.txt for more information
32 | All text above must be included in any redistribution
33 |
34 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_SSD1131. Check that the Adafruit_SSD1331 folder contains Adafruit_SSD1331.cpp and Adafruit_SSD1331.h
35 |
36 | Place the Adafruit_SSD1331 library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
37 |
38 | You will also have to download the Adafruit GFX Graphics core which does all the circles, text, rectangles, etc. You can get it from
39 | https://github.com/adafruit/Adafruit-GFX-Library
40 | and download/install that library as well
41 |
--------------------------------------------------------------------------------
/tools/get_sound.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # マイクからの音声データを取得する
3 | # Copyright (c) 2016-2019 Wataru KUNINO
4 |
5 | DEVICE="sound_1" # 配信デバイス名(必須)
6 | PORT=1024 # UDPポート番号を1024に
7 |
8 | echo "UDP Logger (usage: ${0} port)" # タイトル表示
9 | if [ ${#} = 1 ]; then # 入力パラメータ数が1つ
10 | if [ ${1} -ge 1 ] && [ ${1} -le 65535 ]; then # ポート番号の範囲確認
11 | PORT=${1} # ポート番号を設定
12 | fi # ifの終了
13 | fi # ifの終了
14 | echo "Listening UDP port "${PORT}"..." # ポート番号表示
15 | mkdir sound >& /dev/null # 音声保存用フォルダ作成
16 | while true # 永遠に
17 | do # 繰り返し
18 | UDP=`sudo netcat -luw0 ${PORT}|tr -d [:cntrl:]|\
19 | tr -d "\!\"\$\%\&\'\(\)\*\+\-\;\<\=\>\?\[\\\]\^\{\|\}\~"`
20 | # UDPパケットを取得
21 | DATE=`date "+%Y/%m/%d %R"` # 日時を取得
22 | DEV=${UDP#,*} # デバイス名を取得(前方)
23 | DEV=${DEV%%,*} # デバイス名を取得(後方)
24 | echo -E $DATE, $UDP|tee -a log_${DEV}.csv # 取得日時とデータを保存
25 | if [ ${DEVICE} = ${DEV} ]; then # マイクからの配信画像時
26 | DATE=`date "+%Y%m%d-%H%M"` # 日時を取得
27 | URL=`echo -E $UDP|cut -d' ' -f2` # スペース区切りの2番目
28 | echo -n "Get "${URL} # 音声取得実行表示
29 | wget -qT10 ${URL} -Osound/${DEVICE}"_"${DATE}.wav # wget実行
30 | echo " Done" # 終了表示
31 | fi
32 | done # 繰り返し範囲:ここまで
33 |
--------------------------------------------------------------------------------
/1_practice/practice37_calc/practice37_calc.ino:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | Practice 5: 良く使う演算子
3 |
4 | シリアルモニタのビット・レート設定を115200 bpsに設定してください。
5 | Copyright (c) 2015-2019 Wataru KUNINO
6 | *******************************************************************************/
7 |
8 | void setup() { // 起動時に一度だけ実行される関数
9 | Serial.begin(115200); // シリアル通信速度を115200bpsに設定する
10 | }
11 |
12 | void loop() { // setup実行後に繰り返し実行される関数
13 | int a = 12345; // 整数型の変数aを定義
14 | float v; // 浮動小数点数型変数v
15 |
16 | Serial.println("Practice 04"); // 「Practice 04」を表示
17 |
18 | Serial.print(a,DEC); // 整数値変数aの値を表示
19 | a = a - 345; // a-345を計算してaに代入
20 | Serial.print(" - 345 = ");
21 | Serial.println(a,DEC); // 整数値変数aの値を表示
22 |
23 | Serial.print(a,DEC); // 整数値変数aの値を表示
24 | a = a / 1000; // a÷1000をaに代入
25 | Serial.print(" / 1000 = ");
26 | Serial.println(a,DEC); // 整数値変数aの値を表示
27 |
28 | v = (float) a; // 浮動小数変数vにaを代入
29 | Serial.print("(int) ");
30 | Serial.print(a,DEC); // 整数値変数aの値を表示
31 | a = a / 10; // a÷10をaに代入
32 | Serial.print(" / 10 = ");
33 | Serial.println(a,DEC); // 整数値変数aの値を表示
34 |
35 | Serial.print("(float) ");
36 | Serial.print(v,3); // 浮動小数点数型変数vの値を表示
37 | v = v / 10; // v÷10をvに代入
38 | Serial.print(" / 10 = ");
39 | Serial.println(v,3); // 浮動小数点数型変数vの値を表示
40 |
41 | for(a=0;a<10;a++) delay(100); // 1秒の待ち時間処理
42 | Serial.println();
43 | }
44 |
--------------------------------------------------------------------------------
/5_learn32/esp32_02_led2t/esp32_02_led2t.ino:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | Practice 2: 磁界や温度に応じて2個のLEDを点滅させる
3 |
4 | ・温度が上昇するとLED1が点灯し、下降すると消灯する
5 | ・N極の磁石を近づけると点灯し、S極だと点滅する
6 |
7 | Copyright (c) 2017-2019 Wataru KUNINO
8 | ***********************************************************************/
9 |
10 | #define PIN_LED1 2 // IO 2にLED1を接続
11 | #define PIN_LED2 23 // IO 23にLED2を接続
12 |
13 | float temp=99.9; // 温度を保持するための変数定義
14 |
15 | void setup() { // 起動時に一度だけ実行される関数
16 | pinMode(PIN_LED1,OUTPUT); // LEDを接続したポートを出力に設定
17 | pinMode(PIN_LED2,OUTPUT); // LEDを接続したポートを出力に設定
18 | }
19 |
20 | void loop() { // 繰り返し実行される関数
21 | float tp=temperatureRead(); // 内蔵の温度センサから値を取得
22 | int hall=hallRead(); // 内蔵のホールセンサから値を取得
23 | if( tp - temp > 1.0 ){ // 1℃を超える温度上昇があったとき
24 | digitalWrite(PIN_LED1,HIGH);// LED1をHレベル(3.3V)に設定(点灯)
25 | temp=tp; // 今回の測定温度を保存
26 | }
27 | if( temp - tp > 1.0 ){ // 1℃を超える温度下降があったとき
28 | digitalWrite(PIN_LED1,LOW); // LED1をLレベル(0V)に設定(消灯)
29 | temp=tp; // 今回の測定温度を保存
30 | }
31 | if( hall < 30 ){ // 磁石のN極を近づけたとき(磁界-)
32 | digitalWrite(PIN_LED2,HIGH);// LED2をHレベル(3.3V)に設定(点灯)
33 | }else if( hall > 60 ){ // 磁石のS極を近づけたとき(磁界+)
34 | digitalWrite(PIN_LED2,HIGH);// LED2をHレベル(3.3V)に設定(点灯)
35 | delay(100); // 時間待ち(100ms)
36 | digitalWrite(PIN_LED2,LOW); // LED2をLレベル(0V)に設定(消灯)
37 | }else{ // 磁石が近くに無いとき
38 | digitalWrite(PIN_LED2,LOW); // LED2をLレベル(0V)に設定(消灯)
39 | }
40 | delay(100); // 時間待ち(100ms)
41 | }
42 |
--------------------------------------------------------------------------------
/2_example/example27_env/README.md:
--------------------------------------------------------------------------------
1 | Example 27:
2 | # 乾電池駆動可能なCO2センサ AMS CCS811+温度・湿度・気圧センサ Bosch BME280
3 |
4 | 二酸化炭素や有機ガスなどによる室内の空気環境状態を測定するガスセンサ ams製 CCS811と、温度・湿度・気圧を測定する環境センサ Bosch製 BME280を使った、乾電池駆動が可能なワイヤレスCO2センサです。
5 |
6 | ## 解決した課題
7 |
8 | ガスセンサの課題は、消費電力が大きいことです。
9 | 一例として、一般的なガスセンサにはヒーターが内蔵されており、ヒーターの過熱のために 500mW くらいの電力を消費します。また、適正値が得られるまでの加熱時間も必要です。
10 | 一方、単4電池3本で3か月間の動作をさせようとすると、ガスセンサの消費電力を約 0.3mW 以下にする必要があります。
11 |
12 | ## 間欠駆動
13 |
14 | 本例では、超小型で超低消費電力なガスセンサams製のCCS811を使用します。
15 | しかし、それでも 20mW~60mW 程度の電力を消費します。また、適正値が得られるまで電源を入れっぱなしにしておく必要があり、0.3mW以下にすることは困難です。
16 | そこで、本サンプルでは、センサをONしてから測定を開始し、測定値の変化が5%以内となったときの値を測定結果とする方法を用いました。多くの場合、10秒以内に測定を完了し、次の測定まで電源を切った状態にすることが出来ます。
17 | また、Wi-Fi接続を開始する前に、センサの初期化を開始し、Wi-Fi接続処理中にもセンサを加熱するようにして、駆動時間が短くなるように配慮しました。
18 | 環境センサBME280についても、ドライバbme280.ino内のbme280_stop関数により省エネ待機させました。
19 |
20 | ## 制約事項
21 |
22 | 測定精度と起動後の測定継続時間は、トレードオフの関係になります。本来のセンサの測定精度を得ることは出来ません。
23 |
24 | ## 製作に必要なデバイス
25 |
26 | * Wi-Fiモジュール ESP-WROOM-02
27 | * CO2センサ AMS CCS811
28 | * 温湿度・気圧センサ BME280
29 | * その他、周辺部品など
30 |
31 | ## 回路の製作方法
32 |
33 | ESP-WROOM-02のIO4(10番ピン)を各センサのI2CのSDAへ、IO5(14番ピン)をI2CのSCLへ接続してください。また、省電力駆動のために使用するCCS811のWAK信号をESP-WROOM-02のIO2(7番ピン)へ、ハードウェアエラー時の復帰用のRST信号をIO0(8番ピン)へ接続します。本CCS811センサを間欠駆動したときに、エラーが発生する場合があったので、自動でリセットするようにしました。
34 |
35 | ## 動作方法
36 |
37 | ソースリスト中の#define部へ無線LANアクセスポイントのSSIDとパスワード(PASS)を設定して下さい。
38 | また、SLEEP_Pに測定間隔を約10分から60分の範囲内で設定します。初期値 59*60*1000000 は59分です。
39 |
40 | ## 製作例
41 |
42 |
43 |
44 | ## むすび
45 |
46 | CCS811の消費電流が4000μAほどありましたが、ディープスリープ時にCCS811をOFFすることで、平均の消費電流70μA程度(BME280、ESPモジュール、レギュレータ込・実測値)まで下げることが出来、乾電池による長時間の駆動が可能になりました。
47 | 起動後、データが得られるまでに要する時間を考慮すると、ディープスリープの間隔が約3.7分以上のときに省エネ効果があります。約4分以下の間隔で測定したい場合は、CCS811の電源を入れっぱなしにした方が良いでしょう。
48 |
49 | Copyright (c) 2017-2019 Wataru KUNINO
50 |
51 |
--------------------------------------------------------------------------------
/2_example/example58_tftp/README.md:
--------------------------------------------------------------------------------
1 | Example 58(=32+26):
2 | # センサデバイス用 TFTPクライアント 設定
3 |
4 | TFTPサーバ上から設定ファイルをダウンロードし、モジュール内の設定を変更します。
5 | 本サンプルではESP32-WROOM-32のADCの入力ピンとディープスリープ時間を設定することが出来ます。
6 |
7 | ## TFTPとは
8 |
9 | TFTPはネットワーク機器などの設定ファイルやファームウェアを転送するときなどに使用されているデータ転送プロトコルです。
10 | 使い勝手が簡単で、プロトコルも簡単なので、機器のメンテナンスに向いています。
11 | 認証や暗号化は行わないので、転送時のみ有効にする、もしくは侵入・ファイル転送されても問題の無い用途で利用します。
12 |
13 | TFTPについて、より詳しいサンプルも公開しました(2021/01/16)
14 | 複数ブロック受信,SDカードへの保存に対応:
15 | https://github.com/bokunimowakaru/tftp
16 |
17 | ## 本サンプルの仕様
18 |
19 | 「ADC_PIN=ピン番号」をTFTPで受信すると、ESPモジュールのADC入力ピンを変更することが出来ます。また、「SLEEP_SEC=時間(秒)」を受信すると、ESPモジュールのスリープ間隔を変更することも出来ます。
20 |
21 | ## Raspberry PiへのTFTPサーバのインストール方法
22 |
23 | $ sudo apt-get install tftpd-hpa
24 |
25 | ## 設定ファイル(/etc/default/tftpd-hpa) の例
26 |
27 | # /etc/default/tftpd-hpa
28 | TFTP_USERNAME="tftp"
29 | TFTP_DIRECTORY="/srv/tftp"
30 | TFTP_ADDRESS="0.0.0.0:69"
31 |
32 | ## TFTPサーバの起動と停止
33 |
34 | $ chmod 755 /srv/tftp
35 | $ sudo /etc/init.d/tftpd-hpa start
36 | $ sudo /etc/init.d/tftpd-hpa stop
37 |
38 | ## 転送用のファイルを保存
39 |
40 | $ sudo echo "; Hello! This is from RasPi" | sudo tee /srv/tftp/tftpc_1.ini
41 | $ sudo echo "ADC_PIN=32" | sudo tee -a /srv/tftp/tftpc_1.ini
42 | $ sudo echo "SLEEP_SEC=50" | sudo tee -a /srv/tftp/tftpc_1.ini
43 | $ sudo chmod 644 /srv/tftp/tftpc_1.ini
44 | $ cat /srv/tftp/tftpc_1.ini
45 | ; Hello! This is from RasPi
46 | ADC_PIN=32
47 | SLEEP_SEC=50
48 |
49 | ## 注意事項
50 |
51 | * TFTPクライアント(ESP側)やTFTPサーバ(PCやRaspberry Pi側)起動すると、各機器がセキュリティの脅威にさらされた状態となります。
52 | * また、ウィルスやワームが侵入すると、同じネットワーク上の全ての機器へ感染する恐れが高まります。
53 | * インターネットに接続すると外部からの侵入される場合があります。
54 | * TFTPクライアントは少なくともローカルネット内のみで動作させるようにして下さい。
55 | * TFTPが不必要なときは、停止させてください。
56 |
57 | Copyright (c) 2016-2021 Wataru KUNINO
58 |
59 |
--------------------------------------------------------------------------------
/5_learn32/esp32_18_voice/uspeech_README.md:
--------------------------------------------------------------------------------
1 | # uSpeech library #
2 | The uSpeech library provides an interface for voice recognition using the Arduino. It currently produces phonemes, often the library will produce junk phonemes. Please bare with it for the time being. A noise removal function is underway.
3 | ## Minimum Requirements ##
4 | The library is quite intensive on the processor. Each sample collection takes about 3.2 milliseconds so pay close attention to the time. The library has been tested on the Arduino Uno (ATMega32). Each signal object uses up 160bytes. No real time scheduler should be used with this.
5 |
6 | ## Features ##
7 | - Letter based recognition
8 | - Small memory footprint
9 | - Arduino Compatible
10 | - Up to 80% accuracy with words
11 | - Novel algorithm based on simple calculus
12 | - Plugs directly into an ``analogRead()`` port
13 |
14 | ## Documentation ##
15 |
16 | Head over to the [wiki](https://github.com/arjo129/uSpeech/wiki) and you will find most of the documentation required.
17 |
18 | ## Algorithm ##
19 | The library utilizes a special algorithm to enable speech detection. First the complexity of the signal is determined by taking
20 | the absolute derivative of the signal multiplying it by a fixed point saclar and then dividing it by the absolute integral of the signal.
21 | Consonants (other than R,L,N and M) have a value above 40 and vowels have a value below 40. Consonants, they can be divided into frictaves and plosives. Plosives are like p or b whereas frictaves are like
22 | s or z. Generally each band of the complexity coeficient (abs derivative over abs integral) can be matched to a small set of frictaves
23 | and plosives. The signal determines if it is a plosive or a frictave by watching the length of the utterance (plosives occur over short periods while frictaves over long).
24 | Finally the most appropriate character is chosen.
25 |
26 | - [Return to main page](http://arjo129.github.com)
27 |
--------------------------------------------------------------------------------
/5_learn32/esp32_18_voice_ok/uspeech_README.md:
--------------------------------------------------------------------------------
1 | # uSpeech library #
2 | The uSpeech library provides an interface for voice recognition using the Arduino. It currently produces phonemes, often the library will produce junk phonemes. Please bare with it for the time being. A noise removal function is underway.
3 | ## Minimum Requirements ##
4 | The library is quite intensive on the processor. Each sample collection takes about 3.2 milliseconds so pay close attention to the time. The library has been tested on the Arduino Uno (ATMega32). Each signal object uses up 160bytes. No real time scheduler should be used with this.
5 |
6 | ## Features ##
7 | - Letter based recognition
8 | - Small memory footprint
9 | - Arduino Compatible
10 | - Up to 80% accuracy with words
11 | - Novel algorithm based on simple calculus
12 | - Plugs directly into an ``analogRead()`` port
13 |
14 | ## Documentation ##
15 |
16 | Head over to the [wiki](https://github.com/arjo129/uSpeech/wiki) and you will find most of the documentation required.
17 |
18 | ## Algorithm ##
19 | The library utilizes a special algorithm to enable speech detection. First the complexity of the signal is determined by taking
20 | the absolute derivative of the signal multiplying it by a fixed point saclar and then dividing it by the absolute integral of the signal.
21 | Consonants (other than R,L,N and M) have a value above 40 and vowels have a value below 40. Consonants, they can be divided into frictaves and plosives. Plosives are like p or b whereas frictaves are like
22 | s or z. Generally each band of the complexity coeficient (abs derivative over abs integral) can be matched to a small set of frictaves
23 | and plosives. The signal determines if it is a plosive or a frictave by watching the length of the utterance (plosives occur over short periods while frictaves over long).
24 | Finally the most appropriate character is chosen.
25 |
26 | - [Return to main page](http://arjo129.github.com)
27 |
--------------------------------------------------------------------------------
/2_example/example09_hum_si7021/i2c_si7021.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | 本ソースリストおよびソフトウェアは、ライセンスフリーです。(詳細は別記)
3 | 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
4 |
5 | I2C接続の温湿度センサの値を読み取る
6 | SILICON LABS社 Si7021
7 | Copyright (c) 2017-2019 Wataru KUNINO
8 | https://bokunimo.net/bokunimowakaru/
9 | *********************************************************************/
10 |
11 | #include
12 | #define I2C_si7021 0x40 // Si7021 の I2C アドレス
13 |
14 | float _i2c_si7021_hum;
15 |
16 | float getTemp(){
17 | int temp,hum;
18 | _i2c_si7021_hum=-999.;
19 | Wire.beginTransmission(I2C_si7021);
20 | Wire.write(0xF5);
21 | if(Wire.endTransmission()) return -999.;
22 |
23 | delay(30); // 15ms以上
24 | Wire.requestFrom(I2C_si7021,2);
25 | if(Wire.available()!=2) return -999.;
26 | hum = Wire.read();
27 | hum <<= 8;
28 | hum += Wire.read();
29 |
30 | delay(18); // 15ms以上
31 | Wire.beginTransmission(I2C_si7021);
32 | Wire.write(0xE0);
33 | if(Wire.endTransmission()) return -989.;
34 |
35 | delay(30); // 15ms以上
36 | Wire.requestFrom(I2C_si7021,2);
37 | if(Wire.available()!=2) return -999.;
38 | temp = Wire.read();
39 | temp <<= 8;
40 | temp += Wire.read();
41 |
42 | _i2c_si7021_hum = (float)hum / 65536. * 125. - 6.;
43 | return (float)temp / 65535. * 175.72 - 46.85;
44 | }
45 |
46 | float getHum(){
47 | return _i2c_si7021_hum;
48 | }
49 |
50 | void si7021Setup(){
51 | delay(2); // 1ms以上
52 | Wire.begin(); // I2Cインタフェースの使用を開始
53 | delay(18); // 15ms以上
54 | Wire.beginTransmission(I2C_si7021);
55 | Wire.write(0xE6);
56 | Wire.write(0x3A);
57 | Wire.endTransmission();
58 | delay(18); // 15ms以上
59 | }
60 |
--------------------------------------------------------------------------------