Initial commit
This commit is contained in:
97
.gitignore
vendored
Normal file
97
.gitignore
vendored
Normal file
@@ -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++
|
||||||
10
.vscode/extensions.json
vendored
Normal file
10
.vscode/extensions.json
vendored
Normal file
@@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
44
.vscode/launch.json
vendored
Normal file
44
.vscode/launch.json
vendored
Normal file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -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.
|
||||||
67
README.md
Normal file
67
README.md
Normal file
@@ -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 (::
|
||||||
99
examples/LoRa_Receiver_Serial/radioLib_SX1262_rx_example.cpp
Normal file
99
examples/LoRa_Receiver_Serial/radioLib_SX1262_rx_example.cpp
Normal file
@@ -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 <Arduino.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <RadioLib.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
}
|
||||||
80
examples/LoRa_Transmitter/radioLib_SX1262_tx_example.cpp
Normal file
80
examples/LoRa_Transmitter/radioLib_SX1262_tx_example.cpp
Normal file
@@ -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 <Arduino.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <RadioLib.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
36
examples/OLED/test_u8g2_oled.cpp
Normal file
36
examples/OLED/test_u8g2_oled.cpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
OLED examples
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <U8g2lib.h>
|
||||||
|
|
||||||
|
#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());
|
||||||
|
}
|
||||||
11
examples/README
Normal file
11
examples/README
Normal file
@@ -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
|
||||||
55
examples/helper/scan_i2c.cpp
Normal file
55
examples/helper/scan_i2c.cpp
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/*********
|
||||||
|
Rui Santos
|
||||||
|
Complete project details at https://randomnerdtutorials.com
|
||||||
|
*********/
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
35
examples/helper/scan_spi.cpp
Normal file
35
examples/helper/scan_spi.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
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:
|
||||||
|
}
|
||||||
39
include/README
Normal file
39
include/README
Normal file
@@ -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
|
||||||
46
lib/README
Normal file
46
lib/README
Normal file
@@ -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 <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
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
|
||||||
17
platformio.ini
Normal file
17
platformio.ini
Normal file
@@ -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
|
||||||
30
src/main.cpp
Normal file
30
src/main.cpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <U8g2lib.h>
|
||||||
|
|
||||||
|
#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());
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user