Initial commit

This commit is contained in:
tom
2025-01-28 21:44:32 +01:00
commit a410b03909
15 changed files with 687 additions and 0 deletions

View 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);
}
}

View 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);
}

View 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
View 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

View 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);
}

View 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:
}