commit a410b03909209883aae0741733ecf3bea8bc8a38 Author: tom Date: Tue Jan 28 21:44:32 2025 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53fac65 --- /dev/null +++ b/.gitignore @@ -0,0 +1,97 @@ +# Created by https://www.toptal.com/developers/gitignore/api/macos,platformio,visualstudiocode,c++ +# Edit at https://www.toptal.com/developers/gitignore?templates=macos,platformio,visualstudiocode,c++ + +### C++ ### +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### PlatformIO ### +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json +.pio + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# End of https://www.toptal.com/developers/gitignore/api/macos,platformio,visualstudiocode,c++ \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..29950a5 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,44 @@ +// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY +// +// PlatformIO Debugging Solution +// +// Documentation: https://docs.platformio.org/en/latest/plus/debugging.html +// Configuration: https://docs.platformio.org/en/latest/projectconf/sections/env/options/debug/index.html + +{ + "version": "0.2.0", + "configurations": [ + { + "type": "platformio-debug", + "request": "launch", + "name": "PIO Debug", + "executable": "/home/tom/Bastleni/Hello_World_RadioLib_Heltec-V3_SX1262/.pio/build/esp32dev/firmware.elf", + "projectEnvName": "esp32dev", + "toolchainBinDir": "/home/tom/.platformio/packages/toolchain-xtensa-esp32s3/bin", + "internalConsoleOptions": "openOnSessionStart", + "preLaunchTask": { + "type": "PlatformIO", + "task": "Pre-Debug" + } + }, + { + "type": "platformio-debug", + "request": "launch", + "name": "PIO Debug (skip Pre-Debug)", + "executable": "/home/tom/Bastleni/Hello_World_RadioLib_Heltec-V3_SX1262/.pio/build/esp32dev/firmware.elf", + "projectEnvName": "esp32dev", + "toolchainBinDir": "/home/tom/.platformio/packages/toolchain-xtensa-esp32s3/bin", + "internalConsoleOptions": "openOnSessionStart" + }, + { + "type": "platformio-debug", + "request": "launch", + "name": "PIO Debug (without uploading)", + "executable": "/home/tom/Bastleni/Hello_World_RadioLib_Heltec-V3_SX1262/.pio/build/esp32dev/firmware.elf", + "projectEnvName": "esp32dev", + "toolchainBinDir": "/home/tom/.platformio/packages/toolchain-xtensa-esp32s3/bin", + "internalConsoleOptions": "openOnSessionStart", + "loadMode": "manual" + } + ] +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5885b80 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Julian Schiller + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8385273 --- /dev/null +++ b/README.md @@ -0,0 +1,67 @@ +# Hello_World_RadioLib_Heltec-V3_SX1262 +Hello World example code for the new Heltec WiFi LoRa 32 (V3) board with LoRa SX1262 chip + +## Setup +I use, as metioned, the [Heltec WiFi LoRa 32 (V3)](https://heltec.org/project/wifi-lora-32-v3/) and vsc with the platformio plugin. +My PlatformIO Configuration looks like this and can be found [her](platformio.ini). + +```ini +[env:esp32dev] +platform = espressif32 +board = esp32-s3-devkitc-1 +framework = arduino +lib_deps = + olikraus/U8g2@^2.34.13 + jgromes/RadioLib@^5.6.0 +``` +Note: i don't use a heltec board, as you can see here (```board = esp32-s3-devkitc-1```) and, because of that i didn't rely on the ```pins_arduino.h```in ```platformio\packages\framework-arduinoespressif32\variants\heltec_WIFI_LoRa_32_V3```. + + +## Pins for LoRa Chip and OLED on Heltec WiFi LoRa 32 (V3) +### According to the [schematic Diagram](https://resource.heltec.cn/download/WiFi_LoRa32_V3/HTIT-WB32LA(F)_V3_Schematic_Diagram.pdf) (WORKS) +#### LoRa sx1262 +```cpp +lora_nss: 8 //same as cs +lora_rst: 12 //same as nrst +dio1: 14 //same as irq, first interrupt/GPIO +lora_busy: 13 //same as gpio Pin, second interrupt/GPIO +lora_sck: 9 +lora_miso: 11 +lora_mosi: 10 + ``` + +#### OLED +``` +oled_scl: 18 +oled_sda: 17 +oled_rst: 21 + +// new u8g2 library +U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/18, /* data=*/17, /* reset=*/21); + +// old u8x8 library +U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(scl, sda, rstOlcd); +``` + +### According to [scan](examples/helper) and [pins_arduino.h](https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series/blob/master/esp32/variants/WIFI_LoRa_32_V3/pins_arduino.h) (WRONG) ++ **NOTE**: pins_arduino.h got [changed](https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series/commit/b624b342921ac69caf7fb4fa8ca8c4e38e02748f) + +``` +MOSI: 11 +MISO: 13 +SCK: 12 +SS: 10 +``` + +### Pins from the RadioLib Example +``` +SX1262 has the following connections: +NSS pin: 10 (cs Pin) +DIO1 pin: 2 (irq Pin) +NRST pin: 3 (rst pin) +BUSY pin: 9 (gpio Pin) +SX1262 radio = new Module(10, 2, 3, 9); +Module(cs, irq, rst, gpio) +``` + +hmu if you have any questions, maybe i can help (:: \ No newline at end of file diff --git a/examples/LoRa_Receiver_Serial/radioLib_SX1262_rx_example.cpp b/examples/LoRa_Receiver_Serial/radioLib_SX1262_rx_example.cpp new file mode 100644 index 0000000..afc7ee4 --- /dev/null +++ b/examples/LoRa_Receiver_Serial/radioLib_SX1262_rx_example.cpp @@ -0,0 +1,99 @@ +/* + Code Base from RadioLib: https://github.com/jgromes/RadioLib/tree/master/examples/SX126x + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +#include +#include +#include +#include + +#define LoRa_MOSI 10 +#define LoRa_MISO 11 +#define LoRa_SCK 9 + +#define LoRa_nss 8 +#define LoRa_dio1 14 +#define LoRa_nrst 12 +#define LoRa_busy 13 + +SX1262 radio = new Module(LoRa_nss, LoRa_dio1, LoRa_nrst, LoRa_busy); + +void setup() +{ + Serial.begin(9600); + SPI.begin(LoRa_SCK, LoRa_MISO, LoRa_MOSI, LoRa_nss); + + // initialize SX1262 with default settings + Serial.print(F("[SX1262] Initializing ... ")); + int state = radio.begin(); + if (state == RADIOLIB_ERR_NONE) + { + Serial.println(F("success!")); + } + else + { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true) + ; + } +} + +void loop() +{ + Serial.print(F("[SX1262] Waiting for incoming transmission ... ")); + + // you can receive data as an Arduino String + // NOTE: receive() is a blocking method! + // See example ReceiveInterrupt for details + // on non-blocking reception method. + String str; + int state = radio.receive(str); + + // you can also receive data as byte array + /* + byte byteArr[8]; + int state = radio.receive(byteArr, 8); + */ + + if (state == RADIOLIB_ERR_NONE) + { + // packet was successfully received + Serial.println(F("success!")); + + // print the data of the packet + Serial.print(F("[SX1262] Data:\t\t")); + Serial.println(str); + + // print the RSSI (Received Signal Strength Indicator) + // of the last received packet + Serial.print(F("[SX1262] RSSI:\t\t")); + Serial.print(radio.getRSSI()); + Serial.println(F(" dBm")); + + // print the SNR (Signal-to-Noise Ratio) + // of the last received packet + Serial.print(F("[SX1262] SNR:\t\t")); + Serial.print(radio.getSNR()); + Serial.println(F(" dB")); + } + else if (state == RADIOLIB_ERR_RX_TIMEOUT) + { + // timeout occurred while waiting for a packet + Serial.println(F("timeout!")); + } + else if (state == RADIOLIB_ERR_CRC_MISMATCH) + { + // packet was received, but is malformed + Serial.println(F("CRC error!")); + } + else + { + // some other error occurred + Serial.print(F("failed, code ")); + Serial.println(state); + } +} \ No newline at end of file diff --git a/examples/LoRa_Transmitter/radioLib_SX1262_tx_example.cpp b/examples/LoRa_Transmitter/radioLib_SX1262_tx_example.cpp new file mode 100644 index 0000000..8ab2cbe --- /dev/null +++ b/examples/LoRa_Transmitter/radioLib_SX1262_tx_example.cpp @@ -0,0 +1,80 @@ +/* + Code Base from RadioLib: https://github.com/jgromes/RadioLib/tree/master/examples/SX126x + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +#include +#include +#include +#include + +#define LoRa_MOSI 10 +#define LoRa_MISO 11 +#define LoRa_SCK 9 + +#define LoRa_nss 8 +#define LoRa_dio1 14 +#define LoRa_nrst 12 +#define LoRa_busy 13 + +SX1262 radio = new Module(LoRa_nss, LoRa_dio1, LoRa_nrst, LoRa_busy); + +void setup() +{ + Serial.begin(9600); + SPI.begin(LoRa_SCK, LoRa_MISO, LoRa_MOSI, LoRa_nss); + + // initialize SX1262 with default settings + Serial.print(F("[SX1262] Initializing ... ")); + int state = radio.begin(); + if (state == RADIOLIB_ERR_NONE) + { + Serial.println(F("success!")); + } + else + { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true) + ; + } +} + +void loop() +{ + Serial.print(F("[SX1262] Transmitting packet ... ")); + + int state = radio.transmit("Hello World!"); + + if (state == RADIOLIB_ERR_NONE) + { + // the packet was successfully transmitted + Serial.println(F("success!")); + + // print measured data rate + Serial.print(F("[SX1262] Datarate:\t")); + Serial.print(radio.getDataRate()); + Serial.println(F(" bps")); + } + else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) + { + // the supplied packet was longer than 256 bytes + Serial.println(F("too long!")); + } + else if (state == RADIOLIB_ERR_TX_TIMEOUT) + { + // timeout occured while transmitting packet + Serial.println(F("timeout!")); + } + else + { + // some other error occurred + Serial.print(F("failed, code ")); + Serial.println(state); + } + + // wait for a second before transmitting again + delay(1000); +} \ No newline at end of file diff --git a/examples/OLED/test_u8g2_oled.cpp b/examples/OLED/test_u8g2_oled.cpp new file mode 100644 index 0000000..c23eb35 --- /dev/null +++ b/examples/OLED/test_u8g2_oled.cpp @@ -0,0 +1,36 @@ +/* + + OLED examples + +*/ + +#include +#include +#include + +#define oled_scl 18 +#define oled_sda 17 +#define oled_rst 21 + +U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/oled_scl, /* data=*/oled_sda, /* reset=*/oled_rst); +// U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display +// U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 16, /* data=*/ 17, /* reset=*/ U8X8_PIN_NONE); // ESP32 Thing, pure SW emulated I2C + +void setup() +{ + Serial.begin(9600); + while (!Serial) + ; + Serial.println("OLED Test"); + u8g2.begin(); +} + +void loop() +{ + u8g2.firstPage(); + do + { + u8g2.setFont(u8g2_font_ncenB10_tr); + u8g2.drawStr(0, 24, "Hello World (::"); + } while (u8g2.nextPage()); +} diff --git a/examples/README b/examples/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/examples/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/examples/helper/scan_i2c.cpp b/examples/helper/scan_i2c.cpp new file mode 100644 index 0000000..81102cd --- /dev/null +++ b/examples/helper/scan_i2c.cpp @@ -0,0 +1,55 @@ +/********* + Rui Santos + Complete project details at https://randomnerdtutorials.com +*********/ +#include +#include +#include + +void setup() +{ + Wire.begin(); + Serial.begin(9600); + Serial.println("\nI2C Scanner"); +} + +void loop() +{ + byte error, address; + int nDevices; + Serial.println("Scanning..."); + nDevices = 0; + for (address = 1; address < 127; address++) + { + Wire.beginTransmission(address); + error = Wire.endTransmission(); + if (error == 0) + { + Serial.print("I2C device found at address 0x"); + if (address < 16) + { + Serial.print("0"); + } + Serial.println(address, HEX); + nDevices++; + } + else if (error == 4) + { + Serial.print("Unknow error at address 0x"); + if (address < 16) + { + Serial.print("0"); + } + Serial.println(address, HEX); + } + } + if (nDevices == 0) + { + Serial.println("No I2C devices found\n"); + } + else + { + Serial.println("done\n"); + } + delay(5000); +} diff --git a/examples/helper/scan_spi.cpp b/examples/helper/scan_spi.cpp new file mode 100644 index 0000000..bb3219f --- /dev/null +++ b/examples/helper/scan_spi.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + +/* + Rui Santos + Complete project details at https://RandomNerdTutorials.com/esp32-spi-communication-arduino/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files. + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. +*/ + +// Find the default SPI pins for your board +// Make sure you have the right board selected in Tools > Boards +void setup() +{ + // put your setup code here, to run once: + Serial.begin(9600); + Serial.print("MOSI: "); + Serial.println(MOSI); + Serial.print("MISO: "); + Serial.println(MISO); + Serial.print("SCK: "); + Serial.println(SCK); + Serial.print("SS: "); + Serial.println(SS); +} + +void loop() +{ + // put your main code here, to run repeatedly: +} \ No newline at end of file diff --git a/include/README b/include/README new file mode 100644 index 0000000..e0a33d8 --- /dev/null +++ b/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..455114c --- /dev/null +++ b/platformio.ini @@ -0,0 +1,17 @@ +; 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:esp32dev] +platform = espressif32 +board = esp32-s3-devkitc-1 +framework = arduino +lib_deps = + olikraus/U8g2@^2.34.13 + jgromes/RadioLib@^5.6.0 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..34c6b20 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,30 @@ +#include +#include +#include + +#define oled_scl 18 +#define oled_sda 17 +#define oled_rst 21 + +U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/oled_scl, /* data=*/oled_sda, /* reset=*/oled_rst); +// U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display +// U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 16, /* data=*/ 17, /* reset=*/ U8X8_PIN_NONE); // ESP32 Thing, pure SW emulated I2C + +void setup() +{ + Serial.begin(9600); + while (!Serial) + ; + Serial.println("OLED Test"); + u8g2.begin(); +} + +void loop() +{ + u8g2.firstPage(); + do + { + u8g2.setFont(u8g2_font_ncenB10_tr); + u8g2.drawStr(0, 24, "Hello World (::"); + } while (u8g2.nextPage()); +}