Skip to content

Commit 866bee8

Browse files
committed
port to ttgo t-beam
The T-Beam has only one builtin button, so disable zero feature for now. We also have no buzzer, so also disable that. Maybe we can mimick the buzzer with an LED.
1 parent 3e0082a commit 866bee8

File tree

3 files changed

+52
-45
lines changed

3 files changed

+52
-45
lines changed

platformio.ini

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
[env:sender]
1212
platform = espressif32
13-
board = ttgo-lora32-v1
13+
board = ttgo-t-beam
1414
framework = arduino
1515
src_filter = +<sender.cpp>
1616
lib_deps =
@@ -21,8 +21,8 @@ lib_deps =
2121
monitor_speed = 115200
2222

2323
[env:receiver]
24-
platform = espressif8266
25-
board = d1_mini
24+
platform = espressif32
25+
board = ttgo-t-beam
2626
framework = arduino
2727
src_filter = +<receiver.cpp>
2828
lib_deps =

src/receiver.cpp

+18-15
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ static const uint32_t GPSBaud = 9600;
2020
2121
*/
2222

23-
#define SS D0
24-
#define RST D0
25-
#define DI0 D8
23+
#define SCK 5
24+
#define MISO 19
25+
#define MOSI 27
26+
#define SS 18
27+
#define RST 23
28+
#define DI0 26
2629

2730

2831
#define spreadingFactor 9
@@ -34,12 +37,12 @@ static const uint32_t GPSBaud = 9600;
3437
TinyGPSPlus gps;
3538

3639
// The serial connection to the GPS device
37-
HardwareSerial receiverSerial(1);
38-
HardwareSerial GPSserial(2);
40+
HardwareSerial GPSserial(1);
41+
//HardwareSerial receiverSerial(1);
3942

4043
#define FREQUENCY 868.9E6
4144

42-
#define LEDPIN 5
45+
//#define LEDPIN 5
4346

4447

4548
double retFrequency;
@@ -118,7 +121,7 @@ void receivingMessage () {
118121
StaticJsonBuffer<500> jsonBuffer;
119122
char json[500];
120123
Serial.println("HIGH");
121-
digitalWrite(LEDPIN, LOW);
124+
//digitalWrite(LEDPIN, LOW);
122125

123126
// Receive Message
124127

@@ -153,7 +156,7 @@ void receivingMessage () {
153156
recMessage.printTo(Serial);
154157
// Serial.println();
155158
Serial.println("LOW");
156-
digitalWrite(LEDPIN, HIGH);
159+
//digitalWrite(LEDPIN, HIGH);
157160
delay(200);
158161

159162
// Send packet back
@@ -169,14 +172,14 @@ void receivingMessage () {
169172
}
170173

171174
void initLoRa() {
172-
SPI.begin();
173-
LoRa.setPins(D0, D0, D8);
175+
SPI.begin(SCK, MISO, MOSI, SS);
176+
LoRa.setPins(SS, RST, DI0);
174177
if (!LoRa.begin(FREQUENCY)) {
175178
Serial.println("Starting LoRa failed!");
176179
while (1) {
177-
digitalWrite(LEDPIN, 1);
180+
//digitalWrite(LEDPIN, 1);
178181
delay(200);
179-
digitalWrite(LEDPIN, 0);
182+
//digitalWrite(LEDPIN, 0);
180183
delay(200);
181184
}
182185
}
@@ -194,10 +197,10 @@ void initLoRa() {
194197

195198
void setup() {
196199
Serial.begin(115200);
197-
pinMode(LEDPIN, OUTPUT);
198-
digitalWrite(LEDPIN, 1);
200+
//pinMode(LEDPIN, OUTPUT);
201+
//digitalWrite(LEDPIN, 1);
199202
delay(1000);
200-
digitalWrite(LEDPIN, 0);
203+
//digitalWrite(LEDPIN, 0);
201204
GPSserial.begin(GPSBaud);
202205
initLoRa();
203206
}

src/sender.cpp

+31-27
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ static const uint32_t GPSBaud = 9600;
1515

1616
//GPIO16 OLED RESET
1717

18-
18+
#define SCK 5
19+
#define MISO 19
20+
#define MOSI 27
1921
#define SS 18
20-
#define RST 14
22+
#define RST 23
2123
#define DI0 26
2224

23-
#define STARTPIN 25
24-
#define BUZZERPIN 13
25-
#define ZEROPIN 2
25+
#define STARTPIN 38
26+
//#define BUZZERPIN 13
27+
//#define ZEROPIN 2
2628

2729

2830
#define spreadingFactor 9
@@ -43,8 +45,7 @@ int power = 7;
4345
float average;
4446
float zero = 0;
4547

46-
// SSD1306 display(0x3c, 21, 22); // TTGOV2
47-
SSD1306 display(0x3c, 4, 15); // TTGo V1
48+
SSD1306 display(0x3c, 21, 22); // TTGOV2
4849

4950
// The serial connection to the GPS device
5051
HardwareSerial GPSserial(1);
@@ -203,9 +204,9 @@ double calculateCourse(double senderLat, double senderLng, double receiverLat, d
203204
senderLng);
204205
return courseTo;
205206
}
206-
void initLoRa() {
207207

208-
SPI.begin(5, 19, 27, 18);
208+
void initLoRa() {
209+
SPI.begin(SCK, MISO, MOSI, SS);
209210
LoRa.setPins(SS, RST, DI0);
210211
if (!LoRa.begin(FREQUENCY)) {
211212
Serial.println("Starting LoRa failed!");
@@ -225,9 +226,20 @@ void initLoRa() {
225226

226227
void buzz(int duration, int number) {
227228
for (int i = 0; i < number; i++) {
228-
digitalWrite(BUZZERPIN, 1);
229229
delay(duration);
230-
digitalWrite(BUZZERPIN, 0);
230+
231+
void do_zero() {
232+
zero = average;
233+
Serial.print("Zero ");
234+
Serial.println(zero);
235+
display.clear();
236+
display.setTextAlignment(TEXT_ALIGN_CENTER);
237+
display.setFont(ArialMT_Plain_24);
238+
display.drawString(64, 0, "Zero");
239+
display.drawString(64, 35, "Button");
240+
display.display();
241+
//if (digitalRead(ZEROPIN) == 0);
242+
}
231243
}
232244
}
233245

@@ -239,9 +251,9 @@ void setup()
239251
digitalWrite(16, HIGH);
240252
initDisplay();
241253
pinMode(STARTPIN, INPUT_PULLUP);
242-
pinMode(ZEROPIN, INPUT_PULLUP);
243-
pinMode(BUZZERPIN, OUTPUT);
244-
digitalWrite(BUZZERPIN, 0);
254+
//pinMode(ZEROPIN, INPUT_PULLUP);
255+
//pinMode(BUZZERPIN, OUTPUT);
256+
//digitalWrite(BUZZERPIN, 0);
245257
getPosition();
246258
initLoRa();
247259
display.clear();
@@ -309,20 +321,12 @@ void loop()
309321
display.drawString(64, 35, "Button");
310322
display.display();
311323

312-
while ((digitalRead(STARTPIN) == 1) && (digitalRead(ZEROPIN) == 1)) {
324+
//while ((digitalRead(STARTPIN) == 1) && (digitalRead(ZEROPIN) == 1)) {
325+
while ((digitalRead(STARTPIN) == 1)) {
313326
// Serial.print(digitalRead(ZEROPIN));
314327
delay(50);
315-
if (digitalRead(ZEROPIN) == 0) {
316-
zero = average;
317-
Serial.print("Zero ");
318-
Serial.println(zero);
319-
display.clear();
320-
display.setTextAlignment(TEXT_ALIGN_CENTER);
321-
display.setFont(ArialMT_Plain_24);
322-
display.drawString(64, 0, "Zero");
323-
display.drawString(64, 35, "Button");
324-
display.display();
325-
if (digitalRead(ZEROPIN) == 0);
326-
}
328+
//if (digitalRead(ZEROPIN) == 0) {
329+
//do_zero();
330+
//}
327331
}
328332
}

0 commit comments

Comments
 (0)