From 81434a39b56eb36a8427fc6833637b8fa440e70d Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sat, 26 Aug 2023 11:31:28 +0700 Subject: [PATCH 01/10] update --- Template Project/lib/ESPMegaPRO/ESPMegaPRO.h | 4 ++-- Template Project/platformio.ini | 4 +++- Template Project/src/i2c_scanner.cpp.disabled | 3 +-- Template Project/src/input_test.cpp | 17 +++++++++++++++++ Template Project/src/main.cpp | 9 --------- 5 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 Template Project/src/input_test.cpp delete mode 100644 Template Project/src/main.cpp diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h index 054af53..c699d02 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h @@ -6,8 +6,8 @@ #include #include -#define INPUT_BANK_A_ADDRESS 0x20 -#define INPUT_BANK_B_ADDRESS 0x21 +#define INPUT_BANK_A_ADDRESS 0x21 +#define INPUT_BANK_B_ADDRESS 0x20 #define OUTPUT_BANK_ADDRESS 0x21 #define EEPROM_ADDRESS 0x22 diff --git a/Template Project/platformio.ini b/Template Project/platformio.ini index 66bd033..9bb78fe 100644 --- a/Template Project/platformio.ini +++ b/Template Project/platformio.ini @@ -12,5 +12,7 @@ platform = espressif32 board = wt32-eth01 framework = arduino +;siwats/ESPMegaPROR3@1.0.1 lib_deps = adafruit/Adafruit PWM Servo Driver Library@^2.4.1 - robtillaart/PCF8574@^0.3.7 \ No newline at end of file + robtillaart/PCF8574@^0.3.7 +monitor_speed = 115200 \ No newline at end of file diff --git a/Template Project/src/i2c_scanner.cpp.disabled b/Template Project/src/i2c_scanner.cpp.disabled index a22a3a5..74263cc 100644 --- a/Template Project/src/i2c_scanner.cpp.disabled +++ b/Template Project/src/i2c_scanner.cpp.disabled @@ -35,8 +35,7 @@ void setup() { Wire.begin(14,33); - Serial.begin(9600); - while (!Serial); // Leonardo: wait for serial monitor + Serial.begin(115200); // Leonardo: wait for serial monitor Serial.println("\nI2C Scanner"); } diff --git a/Template Project/src/input_test.cpp b/Template Project/src/input_test.cpp new file mode 100644 index 0000000..51e34ae --- /dev/null +++ b/Template Project/src/input_test.cpp @@ -0,0 +1,17 @@ +#include "ESPMegaPRO.h" + +void setup() { + ESPMega_begin(); + Serial.begin(115200); +} + +void loop() { + if(ESPMega_digitalRead(7)) { + ESPMega_digitalWrite(8, HIGH); + Serial.println("7HIGH"); + } else { + ESPMega_digitalWrite(8, LOW); + Serial.println("7LOW"); + } + ESPMega_loop(); +} \ No newline at end of file diff --git a/Template Project/src/main.cpp b/Template Project/src/main.cpp deleted file mode 100644 index 98f2bb3..0000000 --- a/Template Project/src/main.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -void setup() { - ESPMega_begin(); -} - -void loop() { - ESPMega_loop(); -} \ No newline at end of file From 81f0e80f8c2e1904fb58de11950496c298f0f020 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sat, 26 Aug 2023 12:47:28 +0700 Subject: [PATCH 02/10] change bank address --- Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp | 8 +++++++- Template Project/lib/ESPMegaPRO/ESPMegaPRO.h | 7 ++++--- Template Project/src/input_test.cpp | 6 +++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp index 5f04603..a64a058 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp @@ -5,7 +5,7 @@ uint8_t inputBufferB; PCF8574 inputBankA(INPUT_BANK_A_ADDRESS); PCF8574 inputBankB(INPUT_BANK_B_ADDRESS); -Adafruit_PWMServoDriver pwmBank = Adafruit_PWMServoDriver(0x5F); +Adafruit_PWMServoDriver pwmBank = Adafruit_PWMServoDriver(PWM_BANK_ADDRESS); void ESPMega_begin() { @@ -15,7 +15,13 @@ void ESPMega_begin() inputBankB.begin(); pwmBank.begin(); + // ESPMegaPRO v3 use the PWMBank to drive Half Bridge + // Push Pull Output is required. + pwmBank.setOutputMode(true); + #ifdef USE_INTERRUPT + pinMode(INPUT_BANK_A_INTERRUPT, INPUT_PULLUP); + pinMode(INPUT_BANK_B_INTERRUPT, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(INPUT_BANK_A_INTERRUPT),refreshInputBankA,FALLING); attachInterrupt(digitalPinToInterrupt(INPUT_BANK_B_INTERRUPT),refreshInputBankB,FALLING); #endif diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h index c699d02..23e8288 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h @@ -7,13 +7,14 @@ #include #define INPUT_BANK_A_ADDRESS 0x21 -#define INPUT_BANK_B_ADDRESS 0x20 +#define INPUT_BANK_B_ADDRESS 0x22 +#define PWM_BANK_ADDRESS 0x5F #define OUTPUT_BANK_ADDRESS 0x21 #define EEPROM_ADDRESS 0x22 //#define USE_INTERRUPT -//#define INPUT_BANK_A_INTERRUPT 35 -//#define INPUT_BANK_B_INTERRUPT 39 +#define INPUT_BANK_A_INTERRUPT 36 +#define INPUT_BANK_B_INTERRUPT 39 /** * Initiate ESPMega PRO Internal Components diff --git a/Template Project/src/input_test.cpp b/Template Project/src/input_test.cpp index 51e34ae..c2e2915 100644 --- a/Template Project/src/input_test.cpp +++ b/Template Project/src/input_test.cpp @@ -6,12 +6,12 @@ void setup() { } void loop() { - if(ESPMega_digitalRead(7)) { + if(ESPMega_digitalRead(11)) { ESPMega_digitalWrite(8, HIGH); - Serial.println("7HIGH"); + Serial.println("11HIGH"); } else { ESPMega_digitalWrite(8, LOW); - Serial.println("7LOW"); + Serial.println("11LOW"); } ESPMega_loop(); } \ No newline at end of file From 94443393d08f56ddca7f47470890fced73add53b Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sat, 26 Aug 2023 23:16:51 +0700 Subject: [PATCH 03/10] analog input capability --- .../lib/ESPMegaPRO/ESPMegaPRO.cpp | 56 +++++++++++++------ Template Project/lib/ESPMegaPRO/ESPMegaPRO.h | 17 +++++- Template Project/platformio.ini | 4 ++ Template Project/src/analogdemo.cpp | 10 ++++ ...input_test.cpp => input_test.cpp.disabled} | 0 5 files changed, 68 insertions(+), 19 deletions(-) create mode 100644 Template Project/src/analogdemo.cpp rename Template Project/src/{input_test.cpp => input_test.cpp.disabled} (100%) diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp index a64a058..914e82c 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp @@ -6,6 +6,10 @@ uint8_t inputBufferB; PCF8574 inputBankA(INPUT_BANK_A_ADDRESS); PCF8574 inputBankB(INPUT_BANK_B_ADDRESS); Adafruit_PWMServoDriver pwmBank = Adafruit_PWMServoDriver(PWM_BANK_ADDRESS); +#ifdef ANALOG_CARD_ENABLE +Adafruit_ADS1115 analogInputBankA; +Adafruit_ADS1115 analogInputBankB; +#endif void ESPMega_begin() { @@ -17,39 +21,44 @@ void ESPMega_begin() // ESPMegaPRO v3 use the PWMBank to drive Half Bridge // Push Pull Output is required. - pwmBank.setOutputMode(true); + pwmBank.setOutputMode(true); - #ifdef USE_INTERRUPT +#ifdef USE_INTERRUPT pinMode(INPUT_BANK_A_INTERRUPT, INPUT_PULLUP); pinMode(INPUT_BANK_B_INTERRUPT, INPUT_PULLUP); - attachInterrupt(digitalPinToInterrupt(INPUT_BANK_A_INTERRUPT),refreshInputBankA,FALLING); - attachInterrupt(digitalPinToInterrupt(INPUT_BANK_B_INTERRUPT),refreshInputBankB,FALLING); - #endif + attachInterrupt(digitalPinToInterrupt(INPUT_BANK_A_INTERRUPT), refreshInputBankA, FALLING); + attachInterrupt(digitalPinToInterrupt(INPUT_BANK_B_INTERRUPT), refreshInputBankB, FALLING); +#endif + +#ifdef ANALOG_CARD_ENABLE + analogInputBankA.begin(ANALOG_INPUT_BANK_A_ADDRESS); + analogInputBankA.begin(ANALOG_INPUT_BANK_B_ADDRESS); +#endif } -void ESPMega_loop() { - +void ESPMega_loop() +{ } bool ESPMega_digitalRead(int id) { if (id >= 0 && id <= 7) { - #ifndef USE_INTERRUPT - refreshInputBankA(); //Only poll if interrupt is not enabled - #endif +#ifndef USE_INTERRUPT + refreshInputBankA(); // Only poll if interrupt is not enabled +#endif - return ((inputBufferA>>id)&1); //Extract bit from buffer + return ((inputBufferA >> id) & 1); // Extract bit from buffer } if (id >= 8 && id <= 15) { - id-=8; + id -= 8; - #ifndef USE_INTERRUPT - refreshInputBankB(); //Only poll if interrupt is not enabled - #endif +#ifndef USE_INTERRUPT + refreshInputBankB(); // Only poll if interrupt is not enabled +#endif - return ((inputBufferB>>id)&1); //Extract bit from buffer + return ((inputBufferB >> id) & 1); // Extract bit from buffer } return false; } @@ -61,7 +70,7 @@ void ESPMega_analogWrite(int id, int value) void ESPMega_digitalWrite(int id, bool value) { - if(value) + if (value) pwmBank.setPin(id, 4095); else pwmBank.setPin(id, 0); @@ -75,4 +84,15 @@ void IRAM_ATTR refreshInputBankA() void IRAM_ATTR refreshInputBankB() { inputBufferB = inputBankB.read8(); -} \ No newline at end of file +} + +#ifdef ANALOG_CARD_ENABLE +uint16_t ESPMega_analogRead(int id) +{ + if (id >= 0 && id <= 3) + return analogInputBankA.readADC_SingleEnded(id); + else if (id >= 4 && id <= 7) + return analogInputBankB.readADC_SingleEnded(id - 4); + return 0; +} +#endif \ No newline at end of file diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h index 23e8288..9383d21 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h @@ -1,16 +1,21 @@ #ifndef ESPMEGA #define ESPMEGA - +#define ANALOG_CARD_ENABLE #include #include #include #include +#ifdef ANALOG_CARD_ENABLE +#include +#endif #define INPUT_BANK_A_ADDRESS 0x21 #define INPUT_BANK_B_ADDRESS 0x22 #define PWM_BANK_ADDRESS 0x5F #define OUTPUT_BANK_ADDRESS 0x21 #define EEPROM_ADDRESS 0x22 +#define ANALOG_INPUT_BANK_A_ADDRESS 0x60 +#define ANALOG_INPUT_BANK_B_ADDRESS 0x61 //#define USE_INTERRUPT #define INPUT_BANK_A_INTERRUPT 36 @@ -59,4 +64,14 @@ void ESPMega_digitalWrite(int id, bool value); void IRAM_ATTR refreshInputBankA(); void IRAM_ATTR refreshInputBankB(); +#ifdef ANALOG_CARD_ENABLE +/** + * Read one of the ESPMega Analog Card's Analog Input pins (A0-A7) + * + * @param id The number of the pin to be read + * @return The value of the pin (0-4095) +*/ +uint16_t ESPMega_analogRead(int id); +#endif + #endif \ No newline at end of file diff --git a/Template Project/platformio.ini b/Template Project/platformio.ini index 9bb78fe..670c7cb 100644 --- a/Template Project/platformio.ini +++ b/Template Project/platformio.ini @@ -14,5 +14,9 @@ board = wt32-eth01 framework = arduino ;siwats/ESPMegaPROR3@1.0.1 lib_deps = adafruit/Adafruit PWM Servo Driver Library@^2.4.1 + adafruit/Adafruit ADS1X15@^2.4.0 + adafruit/Adafruit BusIO robtillaart/PCF8574@^0.3.7 + arduino-libraries/Arduino_BuiltIn@^1.0.0 + SPI monitor_speed = 115200 \ No newline at end of file diff --git a/Template Project/src/analogdemo.cpp b/Template Project/src/analogdemo.cpp new file mode 100644 index 0000000..45f908c --- /dev/null +++ b/Template Project/src/analogdemo.cpp @@ -0,0 +1,10 @@ +#include +void setup() { + ESPMega_begin(); + Serial.begin(115200); +} + +void loop() { + int a0 = ESPMega_analogRead(0); + Serial.println(a0); +} \ No newline at end of file diff --git a/Template Project/src/input_test.cpp b/Template Project/src/input_test.cpp.disabled similarity index 100% rename from Template Project/src/input_test.cpp rename to Template Project/src/input_test.cpp.disabled From 1e4e8f7347724a84822a0fba8b4ed8187aad2b57 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sun, 27 Aug 2023 23:42:08 +0700 Subject: [PATCH 04/10] add Analog Functionality --- .../lib/ESPMegaPRO/ESPMegaPRO.cpp | 35 ++++++++++++++++--- Template Project/lib/ESPMegaPRO/ESPMegaPRO.h | 19 ++++++++-- Template Project/platformio.ini | 1 + Template Project/src/analogdemo.cpp | 14 +++++--- 4 files changed, 57 insertions(+), 12 deletions(-) diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp index 914e82c..e7a50a8 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp @@ -9,6 +9,10 @@ Adafruit_PWMServoDriver pwmBank = Adafruit_PWMServoDriver(PWM_BANK_ADDRESS); #ifdef ANALOG_CARD_ENABLE Adafruit_ADS1115 analogInputBankA; Adafruit_ADS1115 analogInputBankB; +MCP4725 DAC0(DAC0_ADDRESS); +MCP4725 DAC1(DAC1_ADDRESS); +MCP4725 DAC2(DAC2_ADDRESS); +MCP4725 DAC3(DAC3_ADDRESS); #endif void ESPMega_begin() @@ -32,7 +36,11 @@ void ESPMega_begin() #ifdef ANALOG_CARD_ENABLE analogInputBankA.begin(ANALOG_INPUT_BANK_A_ADDRESS); - analogInputBankA.begin(ANALOG_INPUT_BANK_B_ADDRESS); + analogInputBankB.begin(ANALOG_INPUT_BANK_B_ADDRESS); + DAC0.begin(); + DAC1.begin(); + DAC2.begin(); + DAC3.begin(); #endif } @@ -87,12 +95,31 @@ void IRAM_ATTR refreshInputBankB() } #ifdef ANALOG_CARD_ENABLE -uint16_t ESPMega_analogRead(int id) +int16_t ESPMega_analogRead(int id) { if (id >= 0 && id <= 3) - return analogInputBankA.readADC_SingleEnded(id); + return analogInputBankA.readADC_SingleEnded(3-id); else if (id >= 4 && id <= 7) - return analogInputBankB.readADC_SingleEnded(id - 4); + return analogInputBankB.readADC_SingleEnded(7-id); return 0; } +void ESPMega_dacWrite(int id, int value) { + switch (id) + { + case 0: + DAC0.setValue(value); + break; + case 1: + DAC1.setValue(value); + break; + case 2: + DAC2.setValue(value); + break; + case 3: + DAC3.setValue(value); + break; + default: + break; + } +} #endif \ No newline at end of file diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h index 9383d21..813f0d5 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h @@ -7,6 +7,7 @@ #include #ifdef ANALOG_CARD_ENABLE #include +#include #endif #define INPUT_BANK_A_ADDRESS 0x21 @@ -14,8 +15,12 @@ #define PWM_BANK_ADDRESS 0x5F #define OUTPUT_BANK_ADDRESS 0x21 #define EEPROM_ADDRESS 0x22 -#define ANALOG_INPUT_BANK_A_ADDRESS 0x60 -#define ANALOG_INPUT_BANK_B_ADDRESS 0x61 +#define ANALOG_INPUT_BANK_A_ADDRESS 0x48 +#define ANALOG_INPUT_BANK_B_ADDRESS 0x49 +#define DAC0_ADDRESS 0x60 +#define DAC1_ADDRESS 0x61 +#define DAC2_ADDRESS 0x62 +#define DAC3_ADDRESS 0x63 //#define USE_INTERRUPT #define INPUT_BANK_A_INTERRUPT 36 @@ -71,7 +76,15 @@ void IRAM_ATTR refreshInputBankB(); * @param id The number of the pin to be read * @return The value of the pin (0-4095) */ -uint16_t ESPMega_analogRead(int id); +int16_t ESPMega_analogRead(int id); +/** + * Write a True Analog Signal to one of the ESPMega Analog Card's + * Analog Output pins (AO0-AO3) + * + * @param id The number of the pin to write to + * @param value the analog value of the pin (0-4095) +*/ +void ESPMega_dacWrite(int id, int value); #endif #endif \ No newline at end of file diff --git a/Template Project/platformio.ini b/Template Project/platformio.ini index 670c7cb..01f71d0 100644 --- a/Template Project/platformio.ini +++ b/Template Project/platformio.ini @@ -19,4 +19,5 @@ lib_deps = adafruit/Adafruit PWM Servo Driver Library@^2.4.1 robtillaart/PCF8574@^0.3.7 arduino-libraries/Arduino_BuiltIn@^1.0.0 SPI + robtillaart/MCP4725@^0.3.7 monitor_speed = 115200 \ No newline at end of file diff --git a/Template Project/src/analogdemo.cpp b/Template Project/src/analogdemo.cpp index 45f908c..2ae38a2 100644 --- a/Template Project/src/analogdemo.cpp +++ b/Template Project/src/analogdemo.cpp @@ -1,10 +1,14 @@ #include -void setup() { - ESPMega_begin(); + +void setup() +{ Serial.begin(115200); + ESPMega_begin(); + ESPMega_dacWrite(0,2000); + ESPMega_dacWrite(1,2000); } -void loop() { - int a0 = ESPMega_analogRead(0); - Serial.println(a0); +void loop() +{ + delay(100); } \ No newline at end of file From a927c74393adb71ce98771931ba65d41a2ff3b9f Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sat, 9 Sep 2023 22:44:08 +0700 Subject: [PATCH 05/10] update base code to rev3.3a --- Template Project/.vscode/settings.json | 6 ++- .../lib/ESPMegaPRO/ESPMegaPRO.cpp | 48 +++++++++++++++---- Template Project/lib/ESPMegaPRO/ESPMegaPRO.h | 9 +++- Template Project/platformio.ini | 4 +- ...analogdemo.cpp => analogdemo.cpp.disabled} | 0 Template Project/src/i2c_scanner.cpp.disabled | 2 +- Template Project/src/rtc_demo.cpp | 8 ++++ 7 files changed, 61 insertions(+), 16 deletions(-) rename Template Project/src/{analogdemo.cpp => analogdemo.cpp.disabled} (100%) create mode 100644 Template Project/src/rtc_demo.cpp diff --git a/Template Project/.vscode/settings.json b/Template Project/.vscode/settings.json index de67d8b..ef8ef5e 100644 --- a/Template Project/.vscode/settings.json +++ b/Template Project/.vscode/settings.json @@ -7,6 +7,8 @@ "unordered_set": "cpp", "vector": "cpp", "string_view": "cpp", - "initializer_list": "cpp" - } + "initializer_list": "cpp", + "adafruit_ads1x15.h": "c" + }, + "cmake.configureOnOpen": true } \ No newline at end of file diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp index e7a50a8..59cc5c6 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp @@ -6,6 +6,7 @@ uint8_t inputBufferB; PCF8574 inputBankA(INPUT_BANK_A_ADDRESS); PCF8574 inputBankB(INPUT_BANK_B_ADDRESS); Adafruit_PWMServoDriver pwmBank = Adafruit_PWMServoDriver(PWM_BANK_ADDRESS); +I2C_eeprom ESPMega_EEPROM(EEPROM_ADDRESS); #ifdef ANALOG_CARD_ENABLE Adafruit_ADS1115 analogInputBankA; Adafruit_ADS1115 analogInputBankB; @@ -18,11 +19,11 @@ MCP4725 DAC3(DAC3_ADDRESS); void ESPMega_begin() { Wire.begin(14, 33); - inputBankA.begin(); inputBankB.begin(); pwmBank.begin(); - + ESPMega_RTC.begin(); + ESPMega_EEPROM.begin(); // ESPMegaPRO v3 use the PWMBank to drive Half Bridge // Push Pull Output is required. pwmBank.setOutputMode(true); @@ -56,23 +57,28 @@ bool ESPMega_digitalRead(int id) refreshInputBankA(); // Only poll if interrupt is not enabled #endif - return ((inputBufferA >> id) & 1); // Extract bit from buffer + return ((inputBufferA >> (7 - id)) & 1); // Extract bit from buffer } if (id >= 8 && id <= 15) { - id -= 8; #ifndef USE_INTERRUPT refreshInputBankB(); // Only poll if interrupt is not enabled #endif - - return ((inputBufferB >> id) & 1); // Extract bit from buffer + if (id >= 8 && id <= 11) + return ((inputBufferB >> (15 - id)) & 1); // Extract bit from buffer + else if (id >= 12 && id <= 15) + return ((inputBufferB >> (id - 12)) & 1); } return false; } void ESPMega_analogWrite(int id, int value) { + if (id >= 0 && id <= 7) + id += 8; + else if (id >= 8 && id <= 15) + id -= 8; pwmBank.setPin(id, value); } @@ -98,12 +104,13 @@ void IRAM_ATTR refreshInputBankB() int16_t ESPMega_analogRead(int id) { if (id >= 0 && id <= 3) - return analogInputBankA.readADC_SingleEnded(3-id); + return analogInputBankA.readADC_SingleEnded(3 - id); else if (id >= 4 && id <= 7) - return analogInputBankB.readADC_SingleEnded(7-id); + return analogInputBankB.readADC_SingleEnded(7 - id); return 0; } -void ESPMega_dacWrite(int id, int value) { +void ESPMega_dacWrite(int id, int value) +{ switch (id) { case 0: @@ -114,7 +121,7 @@ void ESPMega_dacWrite(int id, int value) { break; case 2: DAC2.setValue(value); - break; + break; case 3: DAC3.setValue(value); break; @@ -122,4 +129,25 @@ void ESPMega_dacWrite(int id, int value) { break; } } + +/* void ESPMega_rtcNTPUpdate() +{ + ntpTimeClient.update(); + if (ntpTimeClient.updated()) + { + int day = ntpTimeClient.getDay(); + int month = ntpTimeClient.getMonth(); + int year = ntpTimeClient.getYear(); + int hours = ntpTimeClient.getHours(); + int minutes = ntpTimeClient.getMinutes(); + int seconds = ntpTimeClient.getSeconds(); + ESPMega_RTC.setYear(year); + ESPMega_RTC.setMonth(month); + ESPMega_RTC.setDay(day); + ESPMega_RTC.setHour(hours); + ESPMega_RTC.setMinute(minutes); + ESPMega_RTC.setSecond(seconds); + } +} */ + #endif \ No newline at end of file diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h index 813f0d5..07ec186 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h @@ -8,23 +8,28 @@ #ifdef ANALOG_CARD_ENABLE #include #include +#include +#include #endif #define INPUT_BANK_A_ADDRESS 0x21 #define INPUT_BANK_B_ADDRESS 0x22 #define PWM_BANK_ADDRESS 0x5F -#define OUTPUT_BANK_ADDRESS 0x21 -#define EEPROM_ADDRESS 0x22 +#define RTC_ADDRESS 0x68 #define ANALOG_INPUT_BANK_A_ADDRESS 0x48 #define ANALOG_INPUT_BANK_B_ADDRESS 0x49 #define DAC0_ADDRESS 0x60 #define DAC1_ADDRESS 0x61 #define DAC2_ADDRESS 0x62 #define DAC3_ADDRESS 0x63 +#define EEPROM_ADDRESS 0x70 + +#define ESPMega_RTC rtc //#define USE_INTERRUPT #define INPUT_BANK_A_INTERRUPT 36 #define INPUT_BANK_B_INTERRUPT 39 +extern I2C_eeprom ESPMega_EEPROM; /** * Initiate ESPMega PRO Internal Components diff --git a/Template Project/platformio.ini b/Template Project/platformio.ini index 01f71d0..d6420ce 100644 --- a/Template Project/platformio.ini +++ b/Template Project/platformio.ini @@ -18,6 +18,8 @@ lib_deps = adafruit/Adafruit PWM Servo Driver Library@^2.4.1 adafruit/Adafruit BusIO robtillaart/PCF8574@^0.3.7 arduino-libraries/Arduino_BuiltIn@^1.0.0 - SPI + SPI@^2.0.0 robtillaart/MCP4725@^0.3.7 + robtillaart/I2C_EEPROM@^1.7.3 + sparkfun/SparkFun DS1307 Real-Time Clock (RTC)@^1.0.1 monitor_speed = 115200 \ No newline at end of file diff --git a/Template Project/src/analogdemo.cpp b/Template Project/src/analogdemo.cpp.disabled similarity index 100% rename from Template Project/src/analogdemo.cpp rename to Template Project/src/analogdemo.cpp.disabled diff --git a/Template Project/src/i2c_scanner.cpp.disabled b/Template Project/src/i2c_scanner.cpp.disabled index 74263cc..7f1f5e7 100644 --- a/Template Project/src/i2c_scanner.cpp.disabled +++ b/Template Project/src/i2c_scanner.cpp.disabled @@ -1,4 +1,4 @@ -#include +#include // -------------------------------------- // i2c_scanner // diff --git a/Template Project/src/rtc_demo.cpp b/Template Project/src/rtc_demo.cpp new file mode 100644 index 0000000..0fdadee --- /dev/null +++ b/Template Project/src/rtc_demo.cpp @@ -0,0 +1,8 @@ +#include +void setup() { + ESPMega_begin(); +} + +void loop() { + delay(5000); +} \ No newline at end of file From 63d9bfb5240196d2f76c4ba8e7a01cd2bb990def Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sat, 16 Sep 2023 16:44:07 +0700 Subject: [PATCH 06/10] working RTC --- .../lib/ESPMegaPRO/ESPMegaPRO.cpp | 26 +++++++++++++++- Template Project/lib/ESPMegaPRO/ESPMegaPRO.h | 31 +++++++++++++++++-- Template Project/platformio.ini | 3 +- Template Project/src/rtc_demo.cpp | 6 +++- 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp index 59cc5c6..6675142 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp @@ -7,6 +7,7 @@ PCF8574 inputBankA(INPUT_BANK_A_ADDRESS); PCF8574 inputBankB(INPUT_BANK_B_ADDRESS); Adafruit_PWMServoDriver pwmBank = Adafruit_PWMServoDriver(PWM_BANK_ADDRESS); I2C_eeprom ESPMega_EEPROM(EEPROM_ADDRESS); + #ifdef ANALOG_CARD_ENABLE Adafruit_ADS1115 analogInputBankA; Adafruit_ADS1115 analogInputBankB; @@ -22,7 +23,6 @@ void ESPMega_begin() inputBankA.begin(); inputBankB.begin(); pwmBank.begin(); - ESPMega_RTC.begin(); ESPMega_EEPROM.begin(); // ESPMegaPRO v3 use the PWMBank to drive Half Bridge // Push Pull Output is required. @@ -100,6 +100,30 @@ void IRAM_ATTR refreshInputBankB() inputBufferB = inputBankB.read8(); } +rtctime_t ESPMega_getTime() { + tmElements_t timeElement; + RTC.read(timeElement); + rtctime_t time; + time.hours = timeElement.Hour; + time.minutes = timeElement.Minute; + time.seconds = timeElement.Second; + time.day = timeElement.Day; + time.month = timeElement.Month; + time.year = timeElement.Year+1970; + return time; +} + +void ESPMega_setTime(int hours,int minutes, int seconds, int day, int month, int year) { + tmElements_t timeElement; + timeElement.Hour = hours; + timeElement.Minute = minutes; + timeElement.Second = seconds; + timeElement.Day = day; + timeElement.Month = month; + timeElement.Year = year-1970; + RTC.write(timeElement); +} + #ifdef ANALOG_CARD_ENABLE int16_t ESPMega_analogRead(int id) { diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h index 07ec186..d6e67bc 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h @@ -9,7 +9,8 @@ #include #include #include -#include +#include +#include #endif #define INPUT_BANK_A_ADDRESS 0x21 @@ -24,12 +25,18 @@ #define DAC3_ADDRESS 0x63 #define EEPROM_ADDRESS 0x70 -#define ESPMega_RTC rtc - //#define USE_INTERRUPT #define INPUT_BANK_A_INTERRUPT 36 #define INPUT_BANK_B_INTERRUPT 39 extern I2C_eeprom ESPMega_EEPROM; +struct rtctime_t { + uint8_t hours; + uint8_t minutes; + uint8_t seconds; + uint8_t day; + uint8_t month; + uint16_t year; +}; /** * Initiate ESPMega PRO Internal Components @@ -74,6 +81,24 @@ void ESPMega_digitalWrite(int id, bool value); void IRAM_ATTR refreshInputBankA(); void IRAM_ATTR refreshInputBankB(); +/** + * Get time from the onboard RTC as a struct + * + * @return Time Element Struct +*/ +rtctime_t ESPMega_getTime(); +/** + * Set the onboard RTC's time + * + * @param hours + * @param minutes + * @param seconds + * @param day Day of the month + * @param month Month in numerical form + * @param year Years in AD +*/ +void ESPMega_setTime(int hours,int minutes, int seconds, int day, int month, int year); + #ifdef ANALOG_CARD_ENABLE /** * Read one of the ESPMega Analog Card's Analog Input pins (A0-A7) diff --git a/Template Project/platformio.ini b/Template Project/platformio.ini index d6420ce..d1ddcbe 100644 --- a/Template Project/platformio.ini +++ b/Template Project/platformio.ini @@ -21,5 +21,6 @@ lib_deps = adafruit/Adafruit PWM Servo Driver Library@^2.4.1 SPI@^2.0.0 robtillaart/MCP4725@^0.3.7 robtillaart/I2C_EEPROM@^1.7.3 - sparkfun/SparkFun DS1307 Real-Time Clock (RTC)@^1.0.1 + paulstoffregen/Time@^1.6.1 + paulstoffregen/DS1307RTC monitor_speed = 115200 \ No newline at end of file diff --git a/Template Project/src/rtc_demo.cpp b/Template Project/src/rtc_demo.cpp index 0fdadee..c0146a0 100644 --- a/Template Project/src/rtc_demo.cpp +++ b/Template Project/src/rtc_demo.cpp @@ -1,8 +1,12 @@ #include void setup() { ESPMega_begin(); + Serial.begin(115200); + ESPMega_setTime(16,35,0,16,9,2023); } void loop() { - delay(5000); + delay(1000); + rtctime_t tm = ESPMega_getTime(); + Serial.printf("%02d:%02d:%02d %02d/%02d/%04d\n", tm.hours,tm.minutes,tm.seconds,tm.day,tm.month,tm.year); } \ No newline at end of file From cf35e07c2fad900019d0720e0c6a0cf9e20e55dc Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 28 Sep 2023 13:57:51 +0700 Subject: [PATCH 07/10] pre --- .../lib/ESPMegaPRO/ESPMegaPRO.cpp | 41 ++++++++++--------- Template Project/lib/ESPMegaPRO/ESPMegaPRO.h | 18 ++++++-- Template Project/platformio.ini | 2 +- Template Project/src/fram_demo.cpp.disabled | 0 ...c_scanner.cpp.disabled => i2c_scanner.cpp} | 3 +- Template Project/src/rtc_demo.cpp | 12 ------ Template Project/src/rtc_demo.cpp.disabled | 30 ++++++++++++++ 7 files changed, 68 insertions(+), 38 deletions(-) create mode 100644 Template Project/src/fram_demo.cpp.disabled rename Template Project/src/{i2c_scanner.cpp.disabled => i2c_scanner.cpp} (98%) delete mode 100644 Template Project/src/rtc_demo.cpp create mode 100644 Template Project/src/rtc_demo.cpp.disabled diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp index 6675142..57d9457 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp @@ -100,7 +100,8 @@ void IRAM_ATTR refreshInputBankB() inputBufferB = inputBankB.read8(); } -rtctime_t ESPMega_getTime() { +rtctime_t ESPMega_getTime() +{ tmElements_t timeElement; RTC.read(timeElement); rtctime_t time; @@ -109,18 +110,19 @@ rtctime_t ESPMega_getTime() { time.seconds = timeElement.Second; time.day = timeElement.Day; time.month = timeElement.Month; - time.year = timeElement.Year+1970; + time.year = timeElement.Year + 1970; return time; } -void ESPMega_setTime(int hours,int minutes, int seconds, int day, int month, int year) { +void ESPMega_setTime(int hours, int minutes, int seconds, int day, int month, int year) +{ tmElements_t timeElement; timeElement.Hour = hours; timeElement.Minute = minutes; timeElement.Second = seconds; timeElement.Day = day; timeElement.Month = month; - timeElement.Year = year-1970; + timeElement.Year = year - 1970; RTC.write(timeElement); } @@ -154,24 +156,23 @@ void ESPMega_dacWrite(int id, int value) } } -/* void ESPMega_rtcNTPUpdate() +bool ESPMega_updateTimeFromNTP() { - ntpTimeClient.update(); - if (ntpTimeClient.updated()) + struct tm timeinfo; + if (getLocalTime(&timeinfo)) { - int day = ntpTimeClient.getDay(); - int month = ntpTimeClient.getMonth(); - int year = ntpTimeClient.getYear(); - int hours = ntpTimeClient.getHours(); - int minutes = ntpTimeClient.getMinutes(); - int seconds = ntpTimeClient.getSeconds(); - ESPMega_RTC.setYear(year); - ESPMega_RTC.setMonth(month); - ESPMega_RTC.setDay(day); - ESPMega_RTC.setHour(hours); - ESPMega_RTC.setMinute(minutes); - ESPMega_RTC.setSecond(seconds); + rtctime_t rtctime = ESPMega_getTime(); + if (rtctime.hours != timeinfo.tm_hour || rtctime.minutes != timeinfo.tm_min || + rtctime.seconds != timeinfo.tm_sec || rtctime.day != timeinfo.tm_mday || + rtctime.month != timeinfo.tm_mon + 1 || rtctime.year != timeinfo.tm_year + 1900) + { + ESPMega_setTime(timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, + timeinfo.tm_mday, timeinfo.tm_mon + 1, timeinfo.tm_year + 1900); + + } + return true; } -} */ + return false; +} #endif \ No newline at end of file diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h index d6e67bc..e552741 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h @@ -5,12 +5,13 @@ #include #include #include -#ifdef ANALOG_CARD_ENABLE -#include -#include #include #include #include +#include +#ifdef ANALOG_CARD_ENABLE +#include +#include #endif #define INPUT_BANK_A_ADDRESS 0x21 @@ -23,12 +24,13 @@ #define DAC1_ADDRESS 0x61 #define DAC2_ADDRESS 0x62 #define DAC3_ADDRESS 0x63 -#define EEPROM_ADDRESS 0x70 +#define EEPROM_ADDRESS 0x5A //#define USE_INTERRUPT #define INPUT_BANK_A_INTERRUPT 36 #define INPUT_BANK_B_INTERRUPT 39 extern I2C_eeprom ESPMega_EEPROM; +#define ESPMega_configNTP configTime struct rtctime_t { uint8_t hours; uint8_t minutes; @@ -99,6 +101,14 @@ rtctime_t ESPMega_getTime(); */ void ESPMega_setTime(int hours,int minutes, int seconds, int day, int month, int year); +/** + * Update the onboard RTC's time + * by using time from the NTP server + * configured with ESPMega_configNTP(); + * @return true when updated successfully. +*/ +bool ESPMega_updateTimeFromNTP(); + #ifdef ANALOG_CARD_ENABLE /** * Read one of the ESPMega Analog Card's Analog Input pins (A0-A7) diff --git a/Template Project/platformio.ini b/Template Project/platformio.ini index d1ddcbe..71dcb86 100644 --- a/Template Project/platformio.ini +++ b/Template Project/platformio.ini @@ -22,5 +22,5 @@ lib_deps = adafruit/Adafruit PWM Servo Driver Library@^2.4.1 robtillaart/MCP4725@^0.3.7 robtillaart/I2C_EEPROM@^1.7.3 paulstoffregen/Time@^1.6.1 - paulstoffregen/DS1307RTC + paulstoffregen/DS1307RTC@0.0.0-alpha+sha.c2590c0033 monitor_speed = 115200 \ No newline at end of file diff --git a/Template Project/src/fram_demo.cpp.disabled b/Template Project/src/fram_demo.cpp.disabled new file mode 100644 index 0000000..e69de29 diff --git a/Template Project/src/i2c_scanner.cpp.disabled b/Template Project/src/i2c_scanner.cpp similarity index 98% rename from Template Project/src/i2c_scanner.cpp.disabled rename to Template Project/src/i2c_scanner.cpp index 7f1f5e7..be6d04e 100644 --- a/Template Project/src/i2c_scanner.cpp.disabled +++ b/Template Project/src/i2c_scanner.cpp @@ -33,8 +33,9 @@ void setup() { + Wire.setClock(50000); Wire.begin(14,33); - + Serial.begin(115200); // Leonardo: wait for serial monitor Serial.println("\nI2C Scanner"); } diff --git a/Template Project/src/rtc_demo.cpp b/Template Project/src/rtc_demo.cpp deleted file mode 100644 index c0146a0..0000000 --- a/Template Project/src/rtc_demo.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include -void setup() { - ESPMega_begin(); - Serial.begin(115200); - ESPMega_setTime(16,35,0,16,9,2023); -} - -void loop() { - delay(1000); - rtctime_t tm = ESPMega_getTime(); - Serial.printf("%02d:%02d:%02d %02d/%02d/%04d\n", tm.hours,tm.minutes,tm.seconds,tm.day,tm.month,tm.year); -} \ No newline at end of file diff --git a/Template Project/src/rtc_demo.cpp.disabled b/Template Project/src/rtc_demo.cpp.disabled new file mode 100644 index 0000000..9e8990e --- /dev/null +++ b/Template Project/src/rtc_demo.cpp.disabled @@ -0,0 +1,30 @@ +#include +#include + +uint8_t utc_offset = 7; + +IPAddress IP(192, 168, 0, 241); +IPAddress SUBNET(255, 255, 255, 0); +IPAddress GATEWAY(192, 168, 0, 1); +IPAddress DNS(10, 192, 1, 1); + +void setup() +{ + ESPMega_begin(); + Serial.begin(115200); + ETH.begin(); + ETH.config(IP, GATEWAY, SUBNET, DNS, DNS); + delay(5000); + char ntp[19]; + DNS.toString().toCharArray(ntp, 19); + ESPMega_configNTP(utc_offset * 3600, 0, ntp); + ESPMega_updateTimeFromNTP(); + //ESPMega_setTime(0,10,52,9,11,2008); +} + +void loop() +{ + rtctime_t time = ESPMega_getTime(); + Serial.printf("RTC: %02d:%02d:%02d %02d/%02d/%04d\n", time.hours, time.minutes, time.seconds, time.day, time.month, time.year); + delay(1000); +} \ No newline at end of file From 35cbbbf2955d71e8448e5f0d986497eca4ff945f Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 28 Sep 2023 14:22:19 +0700 Subject: [PATCH 08/10] fram --- .../lib/ESPMegaPRO/ESPMegaPRO.cpp | 4 +- Template Project/lib/ESPMegaPRO/ESPMegaPRO.h | 6 +-- Template Project/platformio.ini | 2 +- Template Project/src/fram_demo.cpp | 37 +++++++++++++++++++ Template Project/src/fram_demo.cpp.disabled | 0 ...c_scanner.cpp => i2c_scanner.cpp.disabled} | 0 6 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 Template Project/src/fram_demo.cpp delete mode 100644 Template Project/src/fram_demo.cpp.disabled rename Template Project/src/{i2c_scanner.cpp => i2c_scanner.cpp.disabled} (100%) diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp index 57d9457..2db5186 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.cpp @@ -6,7 +6,7 @@ uint8_t inputBufferB; PCF8574 inputBankA(INPUT_BANK_A_ADDRESS); PCF8574 inputBankB(INPUT_BANK_B_ADDRESS); Adafruit_PWMServoDriver pwmBank = Adafruit_PWMServoDriver(PWM_BANK_ADDRESS); -I2C_eeprom ESPMega_EEPROM(EEPROM_ADDRESS); +FRAM ESPMega_FRAM; #ifdef ANALOG_CARD_ENABLE Adafruit_ADS1115 analogInputBankA; @@ -23,7 +23,7 @@ void ESPMega_begin() inputBankA.begin(); inputBankB.begin(); pwmBank.begin(); - ESPMega_EEPROM.begin(); + ESPMega_FRAM.begin(FRAM_ADDRESS); // ESPMegaPRO v3 use the PWMBank to drive Half Bridge // Push Pull Output is required. pwmBank.setOutputMode(true); diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h index e552741..c11688e 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h +++ b/Template Project/lib/ESPMegaPRO/ESPMegaPRO.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include @@ -24,12 +24,12 @@ #define DAC1_ADDRESS 0x61 #define DAC2_ADDRESS 0x62 #define DAC3_ADDRESS 0x63 -#define EEPROM_ADDRESS 0x5A +#define FRAM_ADDRESS 0x56 //#define USE_INTERRUPT #define INPUT_BANK_A_INTERRUPT 36 #define INPUT_BANK_B_INTERRUPT 39 -extern I2C_eeprom ESPMega_EEPROM; +extern FRAM ESPMega_FRAM; #define ESPMega_configNTP configTime struct rtctime_t { uint8_t hours; diff --git a/Template Project/platformio.ini b/Template Project/platformio.ini index 71dcb86..fc695a6 100644 --- a/Template Project/platformio.ini +++ b/Template Project/platformio.ini @@ -20,7 +20,7 @@ lib_deps = adafruit/Adafruit PWM Servo Driver Library@^2.4.1 arduino-libraries/Arduino_BuiltIn@^1.0.0 SPI@^2.0.0 robtillaart/MCP4725@^0.3.7 - robtillaart/I2C_EEPROM@^1.7.3 + robtillaart/FRAM_I2C@^0.6.1 paulstoffregen/Time@^1.6.1 paulstoffregen/DS1307RTC@0.0.0-alpha+sha.c2590c0033 monitor_speed = 115200 \ No newline at end of file diff --git a/Template Project/src/fram_demo.cpp b/Template Project/src/fram_demo.cpp new file mode 100644 index 0000000..bd77c2b --- /dev/null +++ b/Template Project/src/fram_demo.cpp @@ -0,0 +1,37 @@ +#include +void setup() +{ + ESPMega_begin(); + Serial.begin(115200); + uint8_t a = 35; + uint8_t b = 42; + uint8_t c = 66; + uint8_t d = 251; + + // ESPMega_FRAM.write8(0,a); + // ESPMega_FRAM.write8(1,b); + // ESPMega_FRAM.write8(2,c); + // ESPMega_FRAM.write8(3,d); + + uint8_t e = ESPMega_FRAM.read8(0); + uint8_t f = ESPMega_FRAM.read8(1); + uint8_t g = ESPMega_FRAM.read8(2); + uint8_t h = ESPMega_FRAM.read8(3); + Serial.println(e); + Serial.println(f); + Serial.println(g); + Serial.println(h); + char ll[2000] = "Everyone has a dream they strive to achieve, and so does the musically talented Kanon Shibuya. However, due to her stage fright, Kanon fails to make it into Yuigaoka Girls' High School's music program and instead ends up in the general curriculum. Even though Kanon makes the conscious decision to quit music altogether, her classmate Tang Keke rekindles Kanon's passion for music with her own: a passion for school idols."; + + // ESPMega_FRAM.write(4,(uint8_t*)ll,2000); + + char llr[2000]; + ESPMega_FRAM.read(4,(uint8_t*)llr,2000); + Serial.println(llr); + + +} + +void loop() +{ +} \ No newline at end of file diff --git a/Template Project/src/fram_demo.cpp.disabled b/Template Project/src/fram_demo.cpp.disabled deleted file mode 100644 index e69de29..0000000 diff --git a/Template Project/src/i2c_scanner.cpp b/Template Project/src/i2c_scanner.cpp.disabled similarity index 100% rename from Template Project/src/i2c_scanner.cpp rename to Template Project/src/i2c_scanner.cpp.disabled From 46ec54355a0b2489fd7cab2f526d20363d991581 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 12 Oct 2023 19:36:47 +0700 Subject: [PATCH 09/10] analog SDK --- Template Project/.vscode/settings.json | 3 ++- Template Project/src/analogdemo.cpp | 16 ++++++++++++++++ Template Project/src/analogdemo.cpp.disabled | 14 -------------- .../{fram_demo.cpp => fram_demo.cpp.disabled} | 0 4 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 Template Project/src/analogdemo.cpp delete mode 100644 Template Project/src/analogdemo.cpp.disabled rename Template Project/src/{fram_demo.cpp => fram_demo.cpp.disabled} (100%) diff --git a/Template Project/.vscode/settings.json b/Template Project/.vscode/settings.json index ef8ef5e..9de6690 100644 --- a/Template Project/.vscode/settings.json +++ b/Template Project/.vscode/settings.json @@ -10,5 +10,6 @@ "initializer_list": "cpp", "adafruit_ads1x15.h": "c" }, - "cmake.configureOnOpen": true + "cmake.configureOnOpen": true, + "cmake.sourceDirectory": "D:/Git/ESPMegaPRO-v3-SDK/Template Project/.pio/libdeps/wt32-eth01/Adafruit BusIO" } \ No newline at end of file diff --git a/Template Project/src/analogdemo.cpp b/Template Project/src/analogdemo.cpp new file mode 100644 index 0000000..a796b6e --- /dev/null +++ b/Template Project/src/analogdemo.cpp @@ -0,0 +1,16 @@ +#include + +void setup() +{ + Serial.begin(115200); + ESPMega_begin(); +} + +void loop() +{ + for(int i=0;i<4096;i++) { + ESPMega_dacWrite(0,i); + double dac_val_sine = 2047.5*sin(i*2*PI/2047.5)+2047.5; + ESPMega_dacWrite(1,(int)dac_val_sine); + } +} \ No newline at end of file diff --git a/Template Project/src/analogdemo.cpp.disabled b/Template Project/src/analogdemo.cpp.disabled deleted file mode 100644 index 2ae38a2..0000000 --- a/Template Project/src/analogdemo.cpp.disabled +++ /dev/null @@ -1,14 +0,0 @@ -#include - -void setup() -{ - Serial.begin(115200); - ESPMega_begin(); - ESPMega_dacWrite(0,2000); - ESPMega_dacWrite(1,2000); -} - -void loop() -{ - delay(100); -} \ No newline at end of file diff --git a/Template Project/src/fram_demo.cpp b/Template Project/src/fram_demo.cpp.disabled similarity index 100% rename from Template Project/src/fram_demo.cpp rename to Template Project/src/fram_demo.cpp.disabled From 8bb4a2ff554bf081c0318c6be17ffec4c2259e54 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 12 Oct 2023 19:40:50 +0700 Subject: [PATCH 10/10] Update analogdemo.cpp --- Template Project/src/analogdemo.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Template Project/src/analogdemo.cpp b/Template Project/src/analogdemo.cpp index a796b6e..7627678 100644 --- a/Template Project/src/analogdemo.cpp +++ b/Template Project/src/analogdemo.cpp @@ -1,4 +1,5 @@ #include +#define ADC void setup() { @@ -8,9 +9,14 @@ void setup() void loop() { + #ifdef DAC for(int i=0;i<4096;i++) { ESPMega_dacWrite(0,i); double dac_val_sine = 2047.5*sin(i*2*PI/2047.5)+2047.5; ESPMega_dacWrite(1,(int)dac_val_sine); } + #endif + #ifdef ADC + Serial.printf("A0: %d",ESPMega_analogRead(0)); + #endif } \ No newline at end of file