« XIAO/M5Atom/Wio-Terminalでneopixelsを制御する(Arduino版) | トップページ | XIAO/M5Atom/Wio-TerminlでCardKB(I2C)を使用する(Arduino版) »

2020年10月17日 (土)

Wio-TermianlのHardwareTest(Arduino版)

2020/10/17
初版

Wio-Terminal Hardware Test

概要

Wio-TermianlのHardwareTest(Arduino版)
Wio-Terminalのハードウェアのチェック用スケッチのいくつかを動作確認し、ひとつにまとめた。 先頭の#defineをコメントアウトすることで切り替えてテストできる。 ビルド用のツールとしてはPlatformIOを利用した。

platformioのインストールについては以下を参照のこと:
開発ツールPlatformIOをcli(comand line interface)で使う(v2:Seeeduino-Wio-Terminal/Arduino版)

platformio.ini

以下のものを使用する:

; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html [env:seeed_wio_terminal] platform = atmelsam board = seeed_wio_terminal framework = arduino build_flags = -DWIO_TERMINAL lib_deps = adafruit/Adafruit Zero DMA Library@^1.0.8 https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_USBDISP/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_IR.git https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_atWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_atUnified/archive/master.zip https://github.com/Seeed-Studio/esp-at-lib/archive/develop.zip https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_atWiFiClientSecure/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_atHTTPClient/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_atWebServer/archive/master.zip lib_ldf_mode = deep+

テスト用スケッチhwtest.ino

src/hwtest.ino

//#define QSPI_RW //#define SD_RW //#define IR_SEND #define LIGHT_SENSOR //#define SW5 //#define SW3 //#define MIC_SER //#define BUZZER //#define BUZZER_PLAY //--------------------- #ifdef QSPI_RW //Wio TerminalでQSPIを使ってFlashにアクセスする #include <sfud.h> #define SFUD_DEMO_TEST_BUFFER_SIZE 1024 static uint8_t sfud_demo_test_buf[SFUD_DEMO_TEST_BUFFER_SIZE]; static void sfud_demo(uint32_t addr, size_t size, uint8_t *data); #define SERIAL Serial void setup() { SERIAL.begin(115200); while(!SERIAL) {}; while(!(sfud_init() == SFUD_SUCCESS)); #ifdef SFUD_USING_QSPI sfud_qspi_fast_read_enable(sfud_get_device(SFUD_W25Q32_DEVICE_INDEX), 4); #endif sfud_demo(0, sizeof(sfud_demo_test_buf), sfud_demo_test_buf); } void loop() { } /** * SFUD demo for the first flash device test. * * @param addr flash start address * @param size test flash size * @param size test flash data buffer */ static void sfud_demo(uint32_t addr, size_t size, uint8_t *data) { sfud_err result = SFUD_SUCCESS; const sfud_flash *flash = sfud_get_device_table() + 0; size_t i; /* prepare write data */ for (i = 0; i < size; i++) { data[i] = i; } /* erase test */ result = sfud_erase(flash, addr, size); if (result == SFUD_SUCCESS) { SERIAL.println("Erase the flash data finish"); } else { SERIAL.println("Erase flash data failed"); return; } /* write test */ result = sfud_write(flash, addr, size, data); if (result == SFUD_SUCCESS) { SERIAL.println("Write the flash data finish"); } else { SERIAL.println("Write the flash data failed"); return; } /* read test */ size_t BaseTime = micros(); result = sfud_read(flash, addr, size, data); size_t CostTime = micros() - BaseTime; if (result == SFUD_SUCCESS) { SERIAL.println("Read the flash data success."); SERIAL.println("Offset (h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\r\n"); for (i = 0; i < size; i++) { if (i % 16 == 0) { SERIAL.print("0x"); SERIAL.print(addr + i,HEX); SERIAL.print("\t"); } SERIAL.print(data[i],HEX); SERIAL.print("\t"); if (((i + 1) % 16 == 0) || i == size - 1) { SERIAL.println(""); } } SERIAL.println(" "); } else { SERIAL.println("Read the flash data failed."); } /* data check */ for (i = 0; i < size; i++) { if (data[i] != i % 256) { SERIAL.println("Read and check write data has an error."); break; } } if (i == size) { SERIAL.println("The flash test is success.\r\n"); SERIAL.print("read costTime: "); SERIAL.print(CostTime); SERIAL.println(" us"); } } #endif #ifdef SD_RW //#include <SPI.h> #include <Seeed_FS.h> #include "SD/Seeed_SD.h" File myFile; void setup() { Serial.begin(115200); while (!Serial) { } Serial.print("Initializing SD card..."); if (!SD.begin(SDCARD_SS_PIN, SDCARD_SPI)) { Serial.println("initialization failed!"); while (1); } Serial.println("initialization done."); // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. myFile = SD.open("test.txt", FILE_WRITE); // if the file opened okay, write to it: if (myFile) { Serial.print("Writing to test.txt..."); myFile.println("testing 1, 2, 3, 4, 5, 6, 7, 8. 9."); // close the file: myFile.close(); Serial.println(""); Serial.println("done."); } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } // re-open the file for reading: myFile = SD.open("test.txt", FILE_READ); if (myFile) { Serial.println(""); Serial.println("test.txt:"); // read from the file until there's nothing else in it: while (myFile.available()) { Serial.write(myFile.read()); } // close the file: myFile.close(); Serial.println(""); Serial.println("done."); } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } } void loop() { // nothing happens after setup } #endif #ifdef IR_SEND /* send.ino Example sketch for IRLib2 * Illustrates how to send a code. */ #include <IRLibSendBase.h> // First include the send base //Now include only the protocols you wish to actually use. //The lowest numbered protocol should be first but remainder //can be any order. #include <IRLib_P01_NEC.h> #include <IRLib_P02_Sony.h> #include <IRLibCombo.h> // After all protocols, include this // All of the above automatically creates a universal sending // class called "IRsend" containing only the protocols you want. // Now declare an instance of that sender. IRsend mySender; void setup() { Serial.begin(115200); delay(2000); while (!Serial); //delay for Leonardo Serial.println(F("Every time you press a key is a serial monitor we will send.")); } void loop() { if (Serial.read() != -1) { //send a code every time a character is received from the // serial port. You could modify this sketch to send when you // push a button connected to an digital input pin. //Substitute values and protocols in the following statement // for device you have available. mySender.send(SONY,0xa8bca, 20);//Sony DVD power A8BCA, 20 bits //mySender.send(NEC,0x61a0f00f,0);//NEC TV power button=0x61a0f00f Serial.println(F("Sent signal.")); } } #endif #ifdef LIGHT_SENSOR void setup() { pinMode(WIO_LIGHT, INPUT); Serial.begin(115200); } void loop() { int light = analogRead(WIO_LIGHT); Serial.print("Light value: "); Serial.println(light); delay(200); } #endif #ifdef SW5 void setup() { Serial.begin(115200); pinMode(WIO_5S_UP, INPUT_PULLUP); pinMode(WIO_5S_DOWN, INPUT_PULLUP); pinMode(WIO_5S_LEFT, INPUT_PULLUP); pinMode(WIO_5S_RIGHT, INPUT_PULLUP); pinMode(WIO_5S_PRESS, INPUT_PULLUP); } void loop() { // put your main code here, to run repeatedly: if (digitalRead(WIO_5S_UP) == LOW) { Serial.println("5 Way Up"); } else if (digitalRead(WIO_5S_DOWN) == LOW) { Serial.println("5 Way Down"); } else if (digitalRead(WIO_5S_LEFT) == LOW) { Serial.println("5 Way Left"); } else if (digitalRead(WIO_5S_RIGHT) == LOW) { Serial.println("5 Way Right"); } else if (digitalRead(WIO_5S_PRESS) == LOW) { Serial.println("5 Way Press"); } delay(200); } #endif #ifdef SW3 void setup() { Serial.begin(115200); pinMode(WIO_KEY_A, INPUT_PULLUP); pinMode(WIO_KEY_B, INPUT_PULLUP); pinMode(WIO_KEY_C, INPUT_PULLUP); } void loop() { // put your main code here, to run repeatedly: if (digitalRead(WIO_KEY_A) == LOW) { Serial.println("A Key pressed"); } else if (digitalRead(WIO_KEY_B) == LOW) { Serial.println("B Key pressed"); } else if (digitalRead(WIO_KEY_C) == LOW) { Serial.println("C Key pressed"); } delay(200); } #endif #ifdef MIC_SER void setup() { pinMode(WIO_MIC, INPUT); Serial.begin(115200); } void loop() { int val = analogRead(WIO_MIC); Serial.println(val); delay(200); } #endif #ifdef BUZZER void setup() { pinMode(WIO_BUZZER, OUTPUT); } void loop() { analogWrite(WIO_BUZZER, 128); delay(1000); analogWrite(WIO_BUZZER, 0); delay(1000); } #endif #ifdef BUZZER_PLAY /* Macro Define */ #define BUZZER_PIN WIO_BUZZER /* sig pin of the buzzer */ int length = 15; /* the number of notes */ char notes[] = "ccggaagffeeddc "; int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 }; int tempo = 300; //Play tone void playTone(int tone, int duration) { for (long i = 0; i < duration * 1000L; i += tone * 2) { digitalWrite(BUZZER_PIN, HIGH); delayMicroseconds(tone); digitalWrite(BUZZER_PIN, LOW); delayMicroseconds(tone); } } void playNote(char note, int duration) { char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' }; int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 }; // play the tone corresponding to the note name for (int i = 0; i < 8; i++) { if (names[i] == note) { playTone(tones[i], duration); } } } void setup() { //set buzzer pin as output pinMode(BUZZER_PIN, OUTPUT); } void loop() { for(int i = 0; i < length; i++) { if(notes[i] == ' ') { delay(beats[i] * tempo); } else { playNote(notes[i], beats[i] * tempo); } delay(tempo / 2); /* delay between notes */ } } #endif

参考情報

Wio Terminalをはじめよう(ピン配置、データシート、回路図など)

wio-terminalのファームウェア・アップデートについて(linux版)

Platform/Wio Terminal/Network/Overview

PlatformIO Core (CLI)

https://wiki.seeedstudio.com/Wio-Terminal-Wi-Fi/

# ESP8266ライブラリと互換性があるので以下が参考になる:
https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/readme.html
https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/udp-examples.html

以上

|

« XIAO/M5Atom/Wio-Terminalでneopixelsを制御する(Arduino版) | トップページ | XIAO/M5Atom/Wio-TerminlでCardKB(I2C)を使用する(Arduino版) »

Wio Terminal」カテゴリの記事

コメント

コメントを書く



(ウェブ上には掲載しません)




« XIAO/M5Atom/Wio-Terminalでneopixelsを制御する(Arduino版) | トップページ | XIAO/M5Atom/Wio-TerminlでCardKB(I2C)を使用する(Arduino版) »