Update examples
This commit is contained in:
parent
9cce0266b1
commit
fc1ed63c29
9 changed files with 596 additions and 482 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -7,3 +7,4 @@
|
|||
test
|
||||
.gitignore
|
||||
.travis.yml
|
||||
lib
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
TTGO-T-Beam
|
||||
=====================
|
||||
|
||||
|
||||

|
||||
|
||||
|
||||
|
|
@ -12,7 +11,9 @@ TTGO-T-Beam
|
|||
| LORA_MISO | 19 | 19 |
|
||||
| LORA_MOSI | 27 | 27 |
|
||||
| LORA_SS | 18 | 18 |
|
||||
| LORA_DI0 | 26 | 26 |
|
||||
| LORA_DIO0 | 26 | 26 |
|
||||
| LORA_DIO1 | 33 | 33 |
|
||||
| LORA_DIO2 | 32 | 32 |
|
||||
| LORA_RST | 23 | 23 |
|
||||
| GPS_RX_PIN | 34 | 12 |
|
||||
| GPS_TX_PIN | 12 | 15 |
|
||||
|
|
@ -37,7 +38,7 @@ TTGO-T-Beam
|
|||
|
||||
|
||||
## Button Function:
|
||||
- Click button 2 will cycle the motherboard function, the default start to enable GPS positioning, the second click will be set to lora send, the third click will be set to lora receive, long press for two seconds and then release, will enter deep sleep
|
||||
- Click button 2 will cycle the user function, the default start to enable GPS positioning, the second click will be set to lora send, the third click will be set to lora receive, long press for two seconds and then release, will enter deep sleep
|
||||
|
||||
## About OLED:
|
||||
- The boot will scan the I2C device. If the OLED is found, all log information will be displayed in the OLED. If not, it will be printed on the serial port.
|
||||
|
|
|
|||
BIN
image/deepsleep.jpg
Normal file
BIN
image/deepsleep.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
BIN
image/product.jpg
Normal file
BIN
image/product.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
|
|
@ -13,10 +13,8 @@ platform = espressif32
|
|||
board = esp32dev
|
||||
framework = arduino
|
||||
|
||||
upload_port = COM11
|
||||
monitor_port = COM11
|
||||
; upload_port = COM8
|
||||
; monitor_port = COM8
|
||||
upload_port = COM26
|
||||
monitor_port = COM26
|
||||
|
||||
monitor_speed = 115200
|
||||
upload_speed = 2000000
|
||||
|
|
@ -26,7 +24,7 @@ lib_deps =
|
|||
AXP202X_Library ;https://github.com/lewisxhe/AXP202X_Library
|
||||
TinyGPSPlus ;https://github.com/mikalhart/TinyGPSPlus
|
||||
ESP8266_SSD1306 ;https://github.com/ThingPulse/esp8266-oled-ssd1306
|
||||
LoRa ;https://github.com/dragino/Lora
|
||||
RadioLib ;https://github.com/jgromes/RadioLib
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
BIN
schematic/T_BeamV1.0.pdf
Normal file
BIN
schematic/T_BeamV1.0.pdf
Normal file
Binary file not shown.
|
|
@ -1,9 +1,13 @@
|
|||
/*
|
||||
* This factory is just to test LilyGo T-Beam series hardware
|
||||
* Created by Lewis he
|
||||
* */
|
||||
|
||||
#include "board_def.h"
|
||||
#include <WiFi.h>
|
||||
#include <Wire.h>
|
||||
#include "axp20x.h"
|
||||
#include <Button2.h>
|
||||
#include <Ticker.h>
|
||||
|
||||
#ifndef AXP192_SLAVE_ADDRESS
|
||||
#define AXP192_SLAVE_ADDRESS 0x34
|
||||
|
|
@ -18,8 +22,6 @@ bool ssd1306_found = false;
|
|||
bool axp192_found = false;
|
||||
bool loraBeginOK = false;
|
||||
|
||||
uint64_t dispMap = 0;
|
||||
String dispInfo;
|
||||
char buff[5][256];
|
||||
|
||||
uint64_t gpsSec = 0;
|
||||
|
|
@ -30,11 +32,19 @@ Button2 *pBtns = nullptr;
|
|||
uint8_t g_btns[] = BUTTONS_MAP;
|
||||
#define ARRARY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
Ticker btnTick;
|
||||
|
||||
String baChStatus = "No charging";
|
||||
String recv = "";
|
||||
|
||||
// flag to indicate that a packet was received
|
||||
bool receivedFlag = false;
|
||||
|
||||
// disable interrupt when it's not needed
|
||||
bool enableInterrupt = true;
|
||||
|
||||
RADIO_TYPE radio = new Module(LORA_SS, LORA_DIO1, LORA_RST, LORA_BUSY);
|
||||
|
||||
|
||||
/************************************
|
||||
* BUTTON
|
||||
* *********************************/
|
||||
|
|
@ -46,6 +56,17 @@ void button_callback(Button2 &b)
|
|||
ui.nextFrame();
|
||||
}
|
||||
program = program + 1 > 2 ? 0 : program + 1;
|
||||
if (program == 2) {
|
||||
Serial.print(F("[RADIO] Starting to listen ... "));
|
||||
int state = radio.startReceive();
|
||||
if (state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -139,21 +160,8 @@ void drawFrame3(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int1
|
|||
display->drawString(64 + x, 35 + y, buff[1]);
|
||||
}
|
||||
|
||||
//PMU
|
||||
void drawFrame4(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
||||
{
|
||||
display->setFont(ArialMT_Plain_10);
|
||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
if (!axp192_found) {
|
||||
display->drawString(64 + x, 22 + y, "PMU Begin FAIL");
|
||||
return;
|
||||
}
|
||||
//TODO::
|
||||
display->drawString(64 + x, 22 + y, "Empty");
|
||||
}
|
||||
|
||||
|
||||
FrameCallback frames[] = {drawFrame1, drawFrame2, drawFrame3, /*drawFrame4*/};
|
||||
FrameCallback frames[] = {drawFrame1, drawFrame2, drawFrame3};
|
||||
OverlayCallback overlays[] = { msOverlay };
|
||||
|
||||
void ssd1306_init()
|
||||
|
|
@ -221,8 +229,6 @@ void scanI2Cdevice(void)
|
|||
Serial.println("done\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void playSound()
|
||||
{
|
||||
#ifdef ENABLE_BUZZER
|
||||
|
|
@ -232,20 +238,38 @@ void playSound()
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
// this function is called when a complete packet
|
||||
// is received by the module
|
||||
// IMPORTANT: this function MUST be 'void' type
|
||||
// and MUST NOT have any arguments!
|
||||
void setFlag(void)
|
||||
{
|
||||
// check if the interrupt is enabled
|
||||
if (!enableInterrupt) {
|
||||
return;
|
||||
}
|
||||
// we got a packet, set the flag
|
||||
receivedFlag = true;
|
||||
}
|
||||
|
||||
void lora_init()
|
||||
{
|
||||
#ifdef ENABLE_LOAR
|
||||
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_SS);
|
||||
LoRa.setPins(LORA_SS, LORA_RST, LORA_DI0);
|
||||
if (!LoRa.begin(BAND))
|
||||
Serial.println("LORA Begin FAIL");
|
||||
else {
|
||||
Serial.print(F("[Radio] Initializing ... "));
|
||||
int state = radio.begin(BAND);
|
||||
if (state == ERR_NONE) {
|
||||
loraBeginOK = true;
|
||||
Serial.println("LORA Begin PASS");
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while (true);
|
||||
}
|
||||
#endif
|
||||
|
||||
// set the function that will be called
|
||||
// when new packet is received
|
||||
radio.setDio1Action(setFlag);
|
||||
|
||||
}
|
||||
|
||||
void setup()
|
||||
|
|
@ -329,13 +353,14 @@ void setup()
|
|||
lora_init();
|
||||
#endif
|
||||
|
||||
btnTick.attach_ms(20, button_loop);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
button_loop();
|
||||
|
||||
static uint32_t loraMap = 0;
|
||||
static uint64_t gpsMap = 0;
|
||||
|
||||
|
|
@ -403,10 +428,47 @@ void loop()
|
|||
}
|
||||
|
||||
if (millis() - loraMap > 3000) {
|
||||
LoRa.beginPacket();
|
||||
LoRa.print("lora: ");
|
||||
LoRa.print(loraMap);
|
||||
LoRa.endPacket();
|
||||
int transmissionState = ERR_NONE;
|
||||
transmissionState = radio.startTransmit(String(loraMap).c_str());
|
||||
// check if the previous transmission finished
|
||||
if (receivedFlag) {
|
||||
// disable the interrupt service routine while
|
||||
// processing the data
|
||||
enableInterrupt = false;
|
||||
// reset flag
|
||||
receivedFlag = false;
|
||||
if (transmissionState == ERR_NONE) {
|
||||
// packet was successfully sent
|
||||
Serial.println(F("transmission finished!"));
|
||||
// NOTE: when using interrupt-driven transmit method,
|
||||
// it is not possible to automatically measure
|
||||
// transmission data rate using getDataRate()
|
||||
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(transmissionState);
|
||||
}
|
||||
// wait a second before transmitting again
|
||||
// delay(1000);
|
||||
|
||||
// send another one
|
||||
Serial.print(F("[RADIO] Sending another packet ... "));
|
||||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
transmissionState = radio.startTransmit(String(loraMap).c_str());
|
||||
|
||||
// you can also transmit byte array up to 256 bytes long
|
||||
/*
|
||||
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
|
||||
0x89, 0xAB, 0xCD, 0xEF};
|
||||
int state = radio.startTransmit(byteArr, 8);
|
||||
*/
|
||||
|
||||
// we're ready to send more packets,
|
||||
// enable interrupt service routine
|
||||
enableInterrupt = true;
|
||||
}
|
||||
snprintf(buff[1], sizeof(buff[1]), "Send %u", loraMap);
|
||||
loraMap = millis();
|
||||
if (!ssd1306_found) {
|
||||
|
|
@ -423,34 +485,65 @@ void loop()
|
|||
return;
|
||||
}
|
||||
snprintf(buff[0], sizeof(buff[0]), "T-Beam Lora Received");
|
||||
if (LoRa.parsePacket()) {
|
||||
recv = "";
|
||||
while (LoRa.available()) {
|
||||
recv += (char)LoRa.read();
|
||||
}
|
||||
if (!ssd1306_found) {
|
||||
Serial.printf("Lora Received:%s - rssi:%d\n", recv.c_str(), LoRa.packetRssi());
|
||||
}
|
||||
|
||||
// check if the flag is set
|
||||
if (receivedFlag) {
|
||||
// disable the interrupt service routine while
|
||||
// processing the data
|
||||
enableInterrupt = false;
|
||||
|
||||
// reset flag
|
||||
receivedFlag = false;
|
||||
|
||||
// you can read received data as an Arduino String
|
||||
int state = radio.readData(recv);
|
||||
|
||||
// you can also read received data as byte array
|
||||
/*
|
||||
byte byteArr[8];
|
||||
int state = radio.readData(byteArr, 8);
|
||||
*/
|
||||
|
||||
if (state == ERR_NONE) {
|
||||
// packet was successfully received
|
||||
Serial.println(F("[RADIO] Received packet!"));
|
||||
|
||||
// print data of the packet
|
||||
Serial.print(F("[RADIO] Data:\t\t"));
|
||||
Serial.println(recv);
|
||||
|
||||
// print RSSI (Received Signal Strength Indicator)
|
||||
Serial.print(F("[RADIO] RSSI:\t\t"));
|
||||
Serial.print(radio.getRSSI());
|
||||
Serial.println(F(" dBm"));
|
||||
snprintf(buff[1], sizeof(buff[1]), "rssi:%.2f dBm", radio.getRSSI());
|
||||
|
||||
// print SNR (Signal-to-Noise Ratio)
|
||||
Serial.print(F("[RADIO] SNR:\t\t"));
|
||||
Serial.print(radio.getSNR());
|
||||
Serial.println(F(" dB"));
|
||||
|
||||
} else if (state == ERR_CRC_MISMATCH) {
|
||||
// packet was received, but is malformed
|
||||
Serial.println(F("CRC error!"));
|
||||
|
||||
} else {
|
||||
// if (!ssd1306_found) {
|
||||
// Serial.println("Wait for received message");
|
||||
// delay(500);
|
||||
// }
|
||||
// some other error occurred
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
|
||||
}
|
||||
|
||||
// put module back to listen mode
|
||||
radio.startReceive();
|
||||
|
||||
// we're ready to receive more packets,
|
||||
// enable interrupt service routine
|
||||
enableInterrupt = true;
|
||||
}
|
||||
snprintf(buff[1], sizeof(buff[1]), "rssi:%d", LoRa.packetRssi());
|
||||
break;
|
||||
}
|
||||
/*
|
||||
if (ssd1306_found) {
|
||||
if (ui.update()) {
|
||||
button_loop();
|
||||
}
|
||||
} else {
|
||||
button_loop();
|
||||
}
|
||||
*/
|
||||
if (ssd1306_found) {
|
||||
if (ui.update()) {
|
||||
}
|
||||
ui.update();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
/*
|
||||
* This factory is just to test LilyGo T-Beam series hardware
|
||||
* Created by Lewis he
|
||||
* */
|
||||
#ifndef BOARD_DEF_H
|
||||
#define BOARD_DEF_H
|
||||
|
||||
|
|
@ -8,8 +12,7 @@
|
|||
#define ENABLE_GPS
|
||||
#define ENABLE_LOAR
|
||||
|
||||
|
||||
#define SSD1306_ADDRESS 0x3c
|
||||
#define SSD1306_ADDRESS 0x3C
|
||||
#ifdef ENABLE_SSD1306
|
||||
#include "SSD1306.h"
|
||||
#include "OLEDDisplayUi.h"
|
||||
|
|
@ -20,9 +23,25 @@
|
|||
#endif
|
||||
|
||||
#ifdef ENABLE_LOAR
|
||||
#include <LoRa.h>
|
||||
#include <RadioLib.h>
|
||||
|
||||
/*
|
||||
Replace the model according to the actual situation
|
||||
|
||||
RADIO_TYPE option:
|
||||
- SX1278
|
||||
- SX1276
|
||||
- SX1262
|
||||
*/
|
||||
#define RADIO_TYPE SX1262
|
||||
|
||||
/*
|
||||
Fill in the frequency according to the actual situation
|
||||
LORA_PERIOD option:
|
||||
- 433,470,868,915
|
||||
*/
|
||||
#define LORA_PERIOD 915
|
||||
|
||||
#define LORA_PERIOD 868
|
||||
|
||||
#define LORA_SCK 5
|
||||
#define LORA_MISO 19
|
||||
|
|
@ -30,10 +49,12 @@
|
|||
#define LORA_SS 18
|
||||
#define LORA_DI0 26
|
||||
#define LORA_RST 23
|
||||
#define LORA_DIO1 33
|
||||
#define LORA_BUSY 32
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
//GPS模块
|
||||
#ifdef ENABLE_GPS
|
||||
#include <TinyGPS++.h>
|
||||
#define UBLOX_GPS_OBJECT() TinyGPSPlus gps
|
||||
|
|
@ -57,13 +78,15 @@ UBLOX_GPS_OBJECT()
|
|||
|
||||
#ifdef ENABLE_LOAR
|
||||
#if LORA_PERIOD == 433
|
||||
#define BAND 433E6
|
||||
#define BAND 433.0
|
||||
#elif LORA_PERIOD == 868
|
||||
#define BAND 868E6
|
||||
#define BAND 868.0
|
||||
#elif LORA_PERIOD == 915
|
||||
#define BAND 915E6
|
||||
#define BAND 915.0
|
||||
#elif LORA_PERIOD == 470
|
||||
#define BAND 470.0
|
||||
#else
|
||||
#define BAND 433E6
|
||||
#define BAND 433.0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
@ -71,8 +94,6 @@ UBLOX_GPS_OBJECT()
|
|||
#define I2C_SDA 21
|
||||
#define I2C_SCL 22
|
||||
#define PMU_IRQ 35
|
||||
#define GPS_POWER_CTRL_CH 3
|
||||
#define LORA_POWER_CTRL_CH 2
|
||||
|
||||
#define ENABLE_BUZZER
|
||||
#define BUZZER_PIN 4
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue