-
Notifications
You must be signed in to change notification settings - Fork 0
/
NuggeTastic.ino
executable file
·128 lines (108 loc) · 2.64 KB
/
NuggeTastic.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <SPI.h>
#include <LoRa.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Adafruit_NeoPixel.h>
#include <EEPROM.h>
#include "mt-lite.h"
#include "picopb.h"
#define RXD 38
#define TXD 40
#define RY_RESET 3
#define LED 15
#define CS_LORA 13
#define MOSI 10
#define MISO 8
#define SCK 6
#define RESET 5
#define IO0 16
#define LED_COUNT 4
#define LED_PIN 12
#define i2c_Address 0x3c
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
mt_lite mt;
void display_start()
{
delay(250);
display.begin(i2c_Address,true);
display.setTextSize(1);
display.setTextColor(SH110X_WHITE);
display.setCursor(0, 0);
display.clearDisplay();
display.display();
}
void setup() {
uint8_t aeskey[16] = {0xd4, 0xf1, 0xbb, 0x3a, 0x20, 0x29, 0x07, 0x59, 0xf0, 0xbc, 0xff, 0xab, 0xcf, 0x4e, 0x69, 0x01};
Serial.begin(9600);
//while(!Serial);
display_start();
mt.init(0x11223344);
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
mt.set_aeskey(aeskey,sizeof(aeskey));
SPI.begin(SCK,MISO,MOSI,-1);
LoRa.setPins(CS_LORA,RESET,IO0);
Serial.println("LoRa Receiver");
display.println("LoRa Receiver");
display.display();
while(!LoRa.begin(906875000)) {
Serial.println("Starting LoRa failed!");
}
LoRa.setSpreadingFactor(11);
LoRa.setSignalBandwidth(250E3);
LoRa.setCodingRate4(5);
LoRa.setPreambleLength(16);
LoRa.setSyncWord(0x2b);
Serial.println("LoRa started");
display.println("LoRa started");
display.display();
}
uint8_t rxdata[256];
size_t rxsize = 0;
uint8_t txdata[256];
size_t txsize = 0;
void loop() {
mt.update();
if((rxsize = mt.packet_available())>0)
{
strip.setPixelColor(0,strip.Color(0,20,0));
strip.show();
mt.read_packet(rxdata);
for(int i = 0; i < rxsize;i++)
{
Serial.printf("%02X",rxdata[i]);
}
Serial.println();
}
if(Serial.available() >= 1)
{
if(Serial.peek() == '\n')
{
strip.setPixelColor(0,strip.Color(0,0,20));
strip.show();
Serial.printf("%s(%d)\n",__FILE__,__LINE__);
Serial.read();
mt.write_packet(txdata,txsize);
txsize = 0;
}
}
if(Serial.available()>1)
{
uint8_t rxbyte;
uint8_t rx[3];
rx[0] = Serial.read();
rx[1] = Serial.read();
rx[2] = 0;
rxbyte = strtol((char *)rx,0,16);
if(txsize<256)
{
txdata[txsize++] = rxbyte;
Serial.printf("%s(%d)\n",__FILE__,__LINE__);
}
}
}