diff --git a/PCBs/Wemos Lolin D32/README.md b/PCBs/Wemos Lolin D32/README.md index 2587c28..79f133c 100644 --- a/PCBs/Wemos Lolin D32/README.md +++ b/PCBs/Wemos Lolin D32/README.md @@ -17,8 +17,7 @@ ## Prerequisites * If no [headphone-pcb](https://github.com/biologist79/Tonuino-ESP32-I2S/tree/master/PCBs/Headphone%20with%20PCM5102a%20and%20TDA1308) is connected, make sure `HEADPHONE_ADJUST_ENABLE` is not active. -* Make sure to change values of voltage divider's restors. They can be configured in `settings.h` as `rdiv1` and `rdiv2` and need to be set to 100k/100k. -* Change `VOLTAGE_READ_PIN` to 35. +* Make sure to edit `settings.h` according your needs. ## Things to mention * Better don't solder Lolin D32 directly to the PCB. I recommend to make use of female connectors instead (link below). diff --git a/PCBs/Wemos Lolin32/README.md b/PCBs/Wemos Lolin32/README.md index 79e56e4..c2c1c84 100644 --- a/PCBs/Wemos Lolin32/README.md +++ b/PCBs/Wemos Lolin32/README.md @@ -16,7 +16,8 @@ After I've been asked many times to provide a PCB, I finally did so :-) It makes ## Prerequisites * If no [headphone-pcb](https://github.com/biologist79/Tonuino-ESP32-I2S/tree/master/PCBs/Headphone%20with%20PCM5102a%20and%20TDA1308) is connected, make sure `HEADPHONE_ADJUST_ENABLE` is not active. -* I used 390/130 kOhms-resistors as voltage-divider. However, make sure to use a multimeter to determine their exact values in order to achieve a better battery-measurement. They can be configured in `settings.h` as `rdiv1` and `rdiv2`. Hint: for Lolin D32's battery-measurement 100k+100k were used. However, I decided to change the ratio from 50/50% to 25/75% to have a "better" signal. 100/100 might be work as well; didn't test it. +* I used 390/130 kOhms-resistors as voltage-divider. However, make sure to use a multimeter to determine their exact values in order to achieve a better battery-measurement. They can be configured in `settings-lolin32.h` as `rdiv1` and `rdiv2`. Hint: for Lolin D32's battery-measurement 100k+100k were used. However, I decided to change the ratio from 50/50% to 25/75% to have a "better" signal. 100/100 might be work as well; didn't test it. +* Make sure to edit `settings.h` according your needs. ## Things to mention * RFID: In order to avoid buying a 6pin-JST-PH-connector I used 2x3pin instead. This is because I already had ten of them (see link below). diff --git a/README.md b/README.md index 49c90f7..0371681 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Finally, the long announced Tonuino-PCB for Wemos' Lolin32 is [there](https://gi * 18.12.2020: Added support for RFID-reader PN5180 (`RFID_READER_TYPE_PN5180`). PN5180 has better RFID-range/sensitivity and can read ISO-15693 / iCode SLIX2-tags aka 'Tonies' (thanks @tueddy for contribution!) * 20.12.2020: Due to memory-issues with webstreams, FTP needs to be activated by pressing pause+next-button now
More to come... +* 23.12.2020: User-config is now split into general part (settings.h) and develboard-specific part (e.g. settings-lolin32.h) ## Known bugs * Some webstreams don't run. Guess it's a combination of saturated connection-pool and lack of heap-memory. Works probably better if ESP32-WROVER is used, as this chip has PSRAM. Advice: Don't enable modules (e.g. MQTT) if you don't need them as this could save memory. @@ -41,7 +42,7 @@ The core of my implementation is based on the popular [ESP32 by Espressif](https The basic idea of Tonuino is to provide a way, to use the Arduino-platform for a music-control-concept that supports locally stored music-files without DRM-restrictions. This basically means that RFID-tags are used to direct a music-player. Even for kids this concept is simple: place an RFID-object (card, character) on top of a box and the music starts to play. Place another RFID-object on it and anything else is played. Simple as that. ## Hardware-setup -The heart of my project is an ESP32 on a [Wemos Lolin32 development-board](https://www.ebay.de/itm/4MB-Flash-WEMOS-Lolin32-V1-0-0-WIFI-Bluetooth-Card-Based-ESP-32-ESP-WROOM-32/162716855489). If ordered in China (Aliexpress, eBay e.g.) it's pretty cheap (around 4€) but even in Europe it's only around 8€. Make sure to install the drivers for the USB/Serial-chip (CP2102 e.g.). +The heart of my project is an ESP32 on a [Wemos Lolin32 development-board](https://www.ebay.de/itm/4MB-Flash-WEMOS-Lolin32-V1-0-0-WIFI-Bluetooth-Card-Based-ESP-32-ESP-WROOM-32/162716855489). If ordered in China (Aliexpress, eBay e.g.) it's pretty cheap (around 4€) but even in Europe it's only around 8€. Make sure to install the drivers for the USB/Serial-chip (CP2102 e.g.). But probably it's besser to use it's successor: [Wemos Lolin D32](https://de.aliexpress.com/item/32808551116.html). * [MAX98357A (like Adafruit's)](https://de.aliexpress.com/item/32999952454.html) * [uSD-card-reader; 3.3V only; supports SPI + SD-MMC](https://www.ebay.de/itm/Micro-SPI-Kartenleser-Card-Reader-2GB-SD-8GB-SDHC-Card-3-3V-ESP8266-Arduino-NEU/333796577968) * [RFID-reader](https://www.amazon.de/AZDelivery-Reader-Arduino-Raspberry-gratis/dp/B074S8MRQ7) @@ -52,8 +53,7 @@ The heart of my project is an ESP32 on a [Wemos Lolin32 development-board](https * [Speaker](https://www.visaton.de/de/produkte/chassiszubehoer/breitband-systeme/fr-7-4-ohm) * uSD-card: doesn't have to be a super-fast one; uC is limiting the throughput. Tested 32GB without any problems. * uSD in SD-MMC (1 Bit) mode: Several devkits with onboard SD slot have support for this mode, e.g.: (https://de.aliexpress.com/item/4001229463219.html) -* optional replace the RFID-reader with a the better one: PN5180 comes with better RFID range, less power consumption and support for ISO-15693 / iCode SLIX2 tags (https://www.bing.com/shop?q=pn5180&FORM=SHOPTB) -Most of them can be ordered cheaper directly in China. It's just a give an short impression of the hardware; feel free to order where ever you want to. These are not affiliate-links. +* optional replace the RFID-reader with a the better one: PN5180 comes with better RFID-range, less power-consumption and support for ISO-15693 / iCode SLIX2 tags (https://www.bing.com/shop?q=pn5180&FORM=SHOPTB) ## Getting Started @@ -65,11 +65,12 @@ Most of them can be ordered cheaper directly in China. It's just a give an short * Now, that the git-repository is saved locally, import this folder into Platformio as a project. * There's a file called `platformio.ini`, that contains the configuration for different develboards (e.g. env:lolin32). Platformio supports hundrets of boards out of the box. So probably you need to change/extend that configuration. Guess Lolin32 is described in platformio.ini but you need Lolin D32, then lookup Platformio's [documentation](https://docs.platformio.org/en/latest/boards/espressif32/lolin_d32.html) to know what to change. * Depending on your operating system (Windows, Mac OS, Linux), you probably need to change `upload_port`and `monitor_port` as well. -* Edit `src/settings.h` according your needs. Especially GPIO-configuration is really important. +* Edit `src/settings.h` according your needs. Especially don't forget to set `HAL` depending on your develboard. +* Edit board-specific (`HAL`) config-file (e.g. `settings-lolin32.h` for Lolin32 or `settings-lolin_d32.h` for Lolin D32). If you're running a board that is not listed there: start with `settings-lolin32.h`. Specific means: it was successfully tested. Said this I want to outline in many cases it can used with other boards (with no or just a few tweaks). * Connect your develboard via USB, click the alien-head to the left and run `Upload and Monitor`. All libraries necessary should be fetched in background now followed by code-compilation. After that, your ESP32 is flashed with the firmware. * Now have a look at the serial-output at the bottom of Visual Studio Code's windows. -* If everything ran fine, at the first run, Tonuino should open an access-point with the name "Tonuino". Connect to this WiFi with your computer (or mobile) and enter `192.168.4.1` to your webbrowser. Enter WiFi-credentials and the hostname. After saving the configuraton, restart Tonuino. -* Now Tonuino tries to join your WiFi. If that was successful, an IP is shown in the serial-console of Visual Studio Code. You can call Tonuino's GUI via this IP. If mDNS-feature is active in `src/settings.h`, you can use the hostname configured extended by .local. So if you configured `tonuino` as hostname, you can use `tonuino.local` for webgui and FTP. +* If everything ran fine, at the first run, Tonuino should open an access-point with the name "Tonuino". Join this WiFi with your computer (or mobile) and enter `192.168.4.1` to your webbrowser. Enter WiFi-credentials and the hostname. After saving the configuraton, restart Tonuino. +* Now Tonuino tries to join your WiFi (with the credentials previously entered). If that was successful, an IP is shown in the serial-console of Visual Studio Code. You can call Tonuino's GUI via this IP. If mDNS-feature is active in `src/settings.h`, you can use the hostname configured extended by .local. So if you configured `tonuino` as hostname, you can use `tonuino.local` for webgui and FTP. * Via FTP you can upload data (don't expect it to be super fast). It's round about 185 kb/s if SD is in SPI-mode and 300 kB/s if SD is in MMC-mode. * Via webbrowser you can configure various settings and pair RFID-tags with actions. @@ -78,9 +79,11 @@ Most of them can be ordered cheaper directly in China. It's just a give an short * choose if optional modules (e.g. MQTT, FTP, Neopixel) should be compiled/enabled * For debugging-purposes serialDebug can be set to ERROR, NOTICE, INFO or DEBUG. * If MQTT=yes, set the IP or hostname of the MQTT-server accordingly and check the MQTT-topics (states and commands) +* Advice: don't enable MQTT if there's no broker around because network-timeouts can really be a PITA. * If Neopixel enabled: set NUM_LEDS to the LED-number of your Neopixel-ring and define the Neopixel-type using `#define CHIPSET` * If you're using Arduino-IDE please make sure to change ESP32's partition-layout to `No OTA (2MB APP/2MB Spiffs)` as otherwise the sketch won't fit into the flash-memory. -* If you want to monitor battery's voltage, make sure to enable `MEASURE_BATTERY_VOLTAGE`. Use a voltage-divider as voltage of a LiPo is way too high for ESP32 (only 3.3V supported!). For my tests I connected VBat with a serial connection of 130k + 390k resistors (VBat(+)--130k--X--390k--VBat(-)). X is the measure-point where to connect the GPIO to. If using Lolin D32 or Lolin D32 pro, make sure to adjust both values to 100k each and change GPIO to 35 as this is already integrated and wired fixed. +* Open board-specific config-file +* If you want to monitor battery's voltage, make sure to enable `MEASURE_BATTERY_VOLTAGE`. Use a voltage-divider as voltage of a LiPo is way too high for ESP32 (only 3.3V supported!). For my tests I connected VBat with a serial connection of 130k + 390k resistors (VBat(+)--130k--X--390k--VBat(-)). X is the measure-point where to connect the GPIO to. If using Lolin D32 or Lolin D32 pro, make sure to leave both resistor-values unchanged at 100k. Same for GPIO: unchanged at 35. Please note: via GUI upper and lower voltage cut-offs for visualisation of battery-voltage (Neopixel) is available. Additional GUI-configurable values are interval (in minutes) for checking battery voltage and the cut off-voltage below whose a warning is shown via Neopixel. * If you're using a headphone-pcb with a [headphone jack](https://www.conrad.de/de/p/cliff-fcr1295-klinken-steckverbinder-3-5-mm-buchse-einbau-horizontal-polzahl-3-stereo-schwarz-1-st-705830.html) that has a pin to indicate if there's a plug, you can use this signal along with the feature `HEADPHONE_ADJUST_ENABLE` to limit the maximum headphone-voltage automatically. As per default you have to invert this signal (with a P-channel MOSFET) and connect it to GPIO22. * Enabling `SHUTDOWN_IF_SD_BOOT_FAILS` is really recommended if you run your Tonuino in battery-mode without having a restart-button exposed to the outside of Tonuino's enclosure. Because otherwise there's no way to restart your Tonuino and the error-state will remain until battery is empty (or you open the enclosure, hehe). diff --git a/platformio.ini b/platformio.ini index d692917..6ae8c7a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -85,8 +85,8 @@ lib_deps = https://github.com/biologist79/rfid.git https://github.com/tueddy/PN5180-Library.git extra_scripts = ${env:common.extra_scripts} -upload_port = /dev/cu.SLAB_USBtoUART -monitor_port = /dev/cu.SLAB_USBtoUART +upload_port = /dev/cu.wchusbserial1410 +monitor_port = /dev/cu.wchusbserial1410 [env:nodemcu-32s] platform = espressif32 diff --git a/src/main.cpp b/src/main.cpp index dd3abc0..1eda696 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,8 @@ #include "settings-espa1s.h" // Contains all user-relevant settings for ESP32-A1S Audiokit #elif (HAL == 3) #include "settings-lolin_D32.h" // Contains all user-relevant settings for Wemos Lolin D32 +#elif (HAL == 4) + #include "settings-lolin_D32_pro.h" // Contains all user-relevant settings for Wemos Lolin D32 pro #endif #include @@ -3775,8 +3777,11 @@ void setup() { #endif #ifdef RFID_READER_TYPE_MFRC522_SPI - //SPI.begin(RFID_SCK, RFID_MISO, RFID_MOSI); - SPI.begin(); + #if (HAL == 4) + SPI.begin(RFID_SCK, RFID_MISO, RFID_MOSI, RFID_CS); // ToDo: Not sure if this should be the default-case + #else + SPI.begin(); + #endif SPI.setFrequency(1000000); #endif diff --git a/src/settings-espa1s.h b/src/settings-espa1s.h index 4c7d2dc..16e93d5 100644 --- a/src/settings-espa1s.h +++ b/src/settings-espa1s.h @@ -6,7 +6,7 @@ Has a lot of stuff already onboard but needs some soldering rework as there are not all GPIOs exposed PCB: Not necessary. Infos: https://github.com/Ai-Thinker-Open/ESP32-A1S-AudioKit - Status: tested by kkloesner + Status: untested */ diff --git a/src/settings-lolin32.h b/src/settings-lolin32.h index 95d1458..f570d17 100644 --- a/src/settings-lolin32.h +++ b/src/settings-lolin32.h @@ -5,7 +5,10 @@ Lolin32 is the predecessor of Lolin D32. PCB: https://github.com/biologist79/Tonuino-ESP32-I2S/tree/master/PCBs/Wemos%20Lolin32 Infos: https://arduino-projekte.info/wemos-lolin32/ - Status: tested (by biologist79) + Caveats: None + Status: + tested with 2x SPI, RC522, SD (by biologist79) + tested with 1x SPI, PN5180, MMC (by biologist79) */ //################## GPIO-configuration ############################## @@ -18,11 +21,11 @@ // MISO 2 // hardware pullup may required #else // uSD-card-reader (via SPI) - #define SPISD_CS 15 // GPIO for chip select (SD) + #define SPISD_CS 15 // GPIO for chip select (SD) #ifndef SINGLE_SPI_ENABLE - #define SPISD_MOSI 13 // GPIO for master out slave in (SD) => not necessary for single-SPI - #define SPISD_MISO 16 // GPIO for master in slave ou (SD) => not necessary for single-SPI - #define SPISD_SCK 14 // GPIO for clock-signal (SD) => not necessary for single-SPI + #define SPISD_MOSI 13 // GPIO for master out slave in (SD) => not necessary for single-SPI + #define SPISD_MISO 16 // GPIO for master in slave ou (SD) => not necessary for single-SPI + #define SPISD_SCK 14 // GPIO for clock-signal (SD) => not necessary for single-SPI #endif #endif diff --git a/src/settings-lolin_d32.h b/src/settings-lolin_d32.h index cabc012..e60f31f 100644 --- a/src/settings-lolin_d32.h +++ b/src/settings-lolin_d32.h @@ -5,6 +5,8 @@ Lolin D32 is the successor of Lolin32 and the "little brother" of Wemos Lolin D32 pro. PCB: https://github.com/biologist79/Tonuino-ESP32-I2S/tree/master/PCBs/Wemos%20Lolin%20D32 Infos: https://www.wemos.cc/en/latest/d32/d32.html + Schematics: https://www.wemos.cc/en/latest/_static/files/sch_d32_v1.0.0.pdf + Caveats: GPIO35 (battery monitoring) can't be changed, it's built in Status: untested */ @@ -19,11 +21,11 @@ // MISO 2 // hardware pullup may required #else // uSD-card-reader (via SPI) - #define SPISD_CS 15 // GPIO for chip select (SD) + #define SPISD_CS 15 // GPIO for chip select (SD) #ifndef SINGLE_SPI_ENABLE - #define SPISD_MOSI 13 // GPIO for master out slave in (SD) => not necessary for single-SPI - #define SPISD_MISO 16 // GPIO for master in slave ou (SD) => not necessary for single-SPI - #define SPISD_SCK 14 // GPIO for clock-signal (SD) => not necessary for single-SPI + #define SPISD_MOSI 13 // GPIO for master out slave in (SD) => not necessary for single-SPI + #define SPISD_MISO 16 // GPIO for master in slave ou (SD) => not necessary for single-SPI + #define SPISD_SCK 14 // GPIO for clock-signal (SD) => not necessary for single-SPI #endif #endif @@ -66,11 +68,10 @@ // (optional) Monitoring of battery-voltage via ADC #ifdef MEASURE_BATTERY_VOLTAGE - #define VOLTAGE_READ_PIN 35 // GPIO used to monitor battery-voltage. Change to 35 if you're using Lolin D32 or Lolin D32 pro as it's hard-wired there! + #define VOLTAGE_READ_PIN 35 // Cannot be changed, it's built in #endif -// (optional) For measuring battery-voltage. No need to change here, it's built in #ifdef MEASURE_BATTERY_VOLTAGE - uint8_t rdiv1 = 100; - uint16_t rdiv2 = 100; + uint8_t rdiv1 = 100; // Cannot be changed, it's built in + uint16_t rdiv2 = 100; // Cannot be changed, it's built in #endif \ No newline at end of file diff --git a/src/settings-lolin_d32_pro.h b/src/settings-lolin_d32_pro.h new file mode 100644 index 0000000..cc4d50f --- /dev/null +++ b/src/settings-lolin_d32_pro.h @@ -0,0 +1,78 @@ +#include "Arduino.h" + +//######################### INFOS #################################### +/* This is a develboard-specific config-file for *Wemos Lolin32*. Specific doesn't mean it's only working with this board. + Lolin32 is the predecessor of Lolin D32. + PCB: None so far + Infos: https://www.wemos.cc/en/latest/d32/d32_pro.html + Schematics: https://www.wemos.cc/en/latest/_static/files/sch_d32_pro_v2.0.0.pdf + Caveats: GPIO35 (battery monitoring) + SD can't be changed, it's built in + Status: + tested with 2xSPI & RC522 (by biologist79) +*/ + +//################## GPIO-configuration ############################## +#ifdef SD_MMC_1BIT_MODE + // uSD-card-reader (via SD-MMC 1Bit) + // + // SD_MMC uses fixed pins + // MOSI 15 + // SCKK 14 + // MISO 2 // hardware pullup may required +#else + // uSD-card-reader (via SPI) => Cannot be changed, it's built in! + #define SPISD_CS 4 // GPIO for chip select (SD) + #ifndef SINGLE_SPI_ENABLE + #define SPISD_MOSI 23 // GPIO for master out slave in (SD) => not necessary for single-SPI + #define SPISD_MISO 19 // GPIO for master in slave ou (SD) => not necessary for single-SPI + #define SPISD_SCK 18 // GPIO for clock-signal (SD) => not necessary for single-SPI + #endif +#endif + +// RFID (via SPI) +#define RST_PIN 99 // Not necessary but has to be set anyway; so let's use a dummy-number +#define RFID_CS 21 // GPIO for chip select (RFID) +#define RFID_MOSI 13 // GPIO for master out slave in (RFID) +#define RFID_MISO 15 // GPIO for master in slave out (RFID) +#define RFID_SCK 14 // GPIO for clock-signal (RFID) + +#ifdef RFID_READER_TYPE_PN5180 + #define RFID_BUSY 16 // PN5180 BUSY PIN + #define RFID_RST 22 // PN5180 RESET PIN +#endif +// I2S (DAC) +#define I2S_DOUT 25 // Digital out (I2S) +#define I2S_BCLK 27 // BCLK (I2S) +#define I2S_LRC 26 // LRC (I2S) + +// Rotary encoder +#define DREHENCODER_CLK 34 // If you want to reverse encoder's direction, just switch GPIOs of CLK with DT (in software or hardware) +#define DREHENCODER_DT 39 // 39 = 'VN' +#define DREHENCODER_BUTTON 32 // Button is used to switch Tonuino on and off + +// Control-buttons +#define PAUSEPLAY_BUTTON 5 // GPIO to detect pause/play +#define NEXT_BUTTON 33 // GPIO to detect next +#define PREVIOUS_BUTTON 2 // GPIO to detect previous (Important: as of 19.11.2020 changed from 33 to 2) + +// (optional) Power-control +#define POWER 17 // GPIO used to drive transistor-circuit, that switches off peripheral devices while ESP32-deepsleep + +// (optional) Neopixel +#define LED_PIN 12 // GPIO for Neopixel-signaling + +// (optinal) Headphone-detection +#ifdef HEADPHONE_ADJUST_ENABLE + #define HP_DETECT 22 // GPIO that detects, if there's a plug in the headphone jack or not +#endif + +// (optional) Monitoring of battery-voltage via ADC +#ifdef MEASURE_BATTERY_VOLTAGE + #define VOLTAGE_READ_PIN 35 // GPIO used to monitor battery-voltage. Cannot be changed, it's built in +#endif + +// (optional) For measuring battery-voltage a voltage-divider is already onboard. Connect a LiPo and use it! +#ifdef MEASURE_BATTERY_VOLTAGE + uint8_t rdiv1 = 100; // Cannot be changed, it's built in + uint16_t rdiv2 = 100; // Cannot be changed, it's built in +#endif \ No newline at end of file diff --git a/src/settings.h b/src/settings.h index 246e203..e511e57 100644 --- a/src/settings.h +++ b/src/settings.h @@ -6,12 +6,13 @@ //################## HARDWARE-PLATFORM ############################### /* Make sure to also edit the configfile, that is specific for your platform. If in doubts (your develboard is not listed) use HAL 1 - 1: Wemos Lolin32 => settings-lolin32.h - 2: ESP32-A1S Audiokit => settings-espa1s.h - 3: Wemos Lolin D32 => settings-lolin_D32.h + 1: Wemos Lolin32 => settings-lolin32.h + 2: ESP32-A1S Audiokit => settings-espa1s.h + 3: Wemos Lolin D32 => settings-lolin_D32.h + 4: Wemos Lolin D32 pro => settings-lolin_D32_pro.h more to come... */ - #define HAL 1 // HAL 1 = LoLin32, 2 = AI AudioKit, 3 = Lolin D32 + #define HAL 1 // HAL 1 = LoLin32, 2 = ESP32-A1S-AudioKit, 3 = Lolin D32, 4 = Lolin D32 pro //########################## MODULES #################################