Skip to content

Commit f49c0a6

Browse files
Add Wireless Stick Lite board definetion
1 parent 6dedcfa commit f49c0a6

File tree

3 files changed

+141
-6
lines changed

3 files changed

+141
-6
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
2+
/*.........................................................................................
3+
* HelTec Automation(TM) WIFI_LoRa_32 factory test code, witch includ
4+
* follow functions:
5+
*
6+
* - Basic serial port test(in baud rate 115200);
7+
*
8+
* - LED blink test;
9+
*
10+
* - WIFI join and scan test;
11+
*
12+
* - LoRa Ping-Pong test(DIO0 -- GPIO26 interrup check the new incoming messages;
13+
*
14+
* - Timer test and some other Arduino basic functions.
15+
*
16+
*by Aaron.Lee from HelTec AutoMation, ChengDu, China
17+
*成都惠利特自动化科技有限公司
18+
*www.heltec.cn
19+
*
20+
*this project also realess in GitHub:
21+
*https://github.com/HelTecAutomation/Heltec_ESP32
22+
*/
23+
#include "Arduino.h"
24+
#include "heltec.h"
25+
#include "WiFi.h"
26+
27+
String packet;
28+
uint64_t chipid;
29+
bool receiveflag = false; // software flag for LoRa receiver, received data makes it true.
30+
31+
void WIFISetUp(void)
32+
{
33+
//WIFI初始化 + 扫描演示
34+
// Set WiFi to station mode and disconnect from an AP if it was previously connected
35+
WiFi.disconnect(true);
36+
delay(1000);
37+
WiFi.mode(WIFI_STA);
38+
WiFi.setAutoConnect(true);
39+
WiFi.begin("WiFi SSID","WiFi password");
40+
delay(100);
41+
42+
byte count = 0;
43+
Serial.print("Connecting.");
44+
while(WiFi.status() != WL_CONNECTED && count < 5)
45+
{
46+
count ++;
47+
Serial.print(".");
48+
delay(500);
49+
}
50+
51+
if(WiFi.status() == WL_CONNECTED)
52+
{
53+
Serial.println("\r\nConnecting...OK.");
54+
}
55+
else
56+
{
57+
Serial.println("Connecting...Failed");
58+
//while(1);
59+
}
60+
Serial.println("WIFI Setup done");
61+
}
62+
63+
void setup()
64+
{
65+
Heltec.begin(false /*DisplayEnable Enable*/, true /*LoRa Enable*/, true /*Serial Enable*/, true /*LoRa use PABOOST*/, 868E6 /*LoRa RF working band*/);
66+
67+
pinMode(25,OUTPUT);
68+
69+
pinMode(Vext,OUTPUT);
70+
digitalWrite(Vext, LOW); //// OLED USE Vext as power supply, must turn ON Vext before OLED init
71+
delay(50);
72+
73+
WIFISetUp();
74+
75+
LoRa.beginPacket();
76+
LoRa.print(WiFi.scanNetworks());
77+
LoRa.print(" networks found");
78+
LoRa.endPacket();
79+
Serial.printf("LoRa data sent success!\r\n");
80+
81+
// register the receive callback
82+
LoRa.onReceive(onReceive);
83+
84+
// put the radio into receive mode
85+
LoRa.receive();
86+
}
87+
88+
void loop()
89+
{
90+
if(receiveflag)
91+
{
92+
chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).
93+
Serial.printf("ESP32ChipID=%04X",(uint16_t)(chipid>>32));//print High 2 bytes
94+
Serial.printf("%08X\r\n",(uint32_t)chipid);//print Low 4bytes.
95+
96+
receiveflag = false;
97+
}
98+
//delay(1000);
99+
}
100+
101+
void onReceive(int packetSize)//LoRa receiver interrupt service
102+
{
103+
packet = "";
104+
105+
while (LoRa.available())
106+
{
107+
packet += (char) LoRa.read();
108+
}
109+
if((packet[0] == 'a')&&(packet[1] == 'b')&&(packet[2] == 'c'))
110+
{
111+
digitalWrite(25,HIGH);
112+
receiveflag = true;
113+
}
114+
}

src/heltec.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ Heltec_ESP32::Heltec_ESP32(){
1414
}
1515

1616
Heltec_ESP32::~Heltec_ESP32(){
17+
#if defined( WIFI_Kit_32 ) || defined( WIFI_LoRa_32 ) || defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick )
1718
delete display;
19+
#endif
1820
}
1921

2022
void Heltec_ESP32::begin(bool DisplayEnable, bool LoRaEnable, bool SerialEnable, bool PABOOST, long BAND) {
2123

22-
#if defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick )
24+
#if defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick ) || defined( Wireless_Stick_Lite )
2325

2426
VextON();
2527
#endif
@@ -33,7 +35,16 @@ void Heltec_ESP32::begin(bool DisplayEnable, bool LoRaEnable, bool SerialEnable,
3335
}
3436

3537
// OLED
36-
if (DisplayEnable){
38+
if (DisplayEnable)
39+
{
40+
#if defined( Wireless_Stick_Lite )
41+
if(SerialEnable && Wireless_Stick_Lite)
42+
{
43+
Serial.print("The Wireless Stick Lite not have an on board display, Display option must be FALSE!!!\r\n");
44+
}
45+
#endif
46+
47+
#if defined( WIFI_Kit_32 ) || defined( WIFI_LoRa_32 ) || defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick )
3748
display->init();
3849
display->flipScreenVertically();
3950
display->setFont(ArialMT_Plain_10);
@@ -43,6 +54,7 @@ void Heltec_ESP32::begin(bool DisplayEnable, bool LoRaEnable, bool SerialEnable,
4354
if (SerialEnable){
4455
Serial.print("you can see OLED printed OLED initial done!\r\n");
4556
}
57+
#endif
4658
}
4759

4860
// LoRa INIT
@@ -55,7 +67,7 @@ void Heltec_ESP32::begin(bool DisplayEnable, bool LoRaEnable, bool SerialEnable,
5567
#endif
5668

5769

58-
#if defined( WIFI_LoRa_32 ) || defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick )
70+
#if defined( WIFI_LoRa_32 ) || defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick ) || defined( Wireless_Stick_Lite )
5971
//LoRaClass LoRa;
6072

6173
SPI.begin(SCK,MISO,MOSI,SS);
@@ -65,23 +77,28 @@ void Heltec_ESP32::begin(bool DisplayEnable, bool LoRaEnable, bool SerialEnable,
6577
if (SerialEnable){
6678
Serial.print("Starting LoRa failed!\r\n");
6779
}
80+
#if defined( WIFI_Kit_32 ) || defined( WIFI_LoRa_32 ) || defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick )
6881
if(DisplayEnable){
6982
display->clear();
7083
display->drawString(0, 0, "Starting LoRa failed!");
7184
display->display();
7285
delay(300);
7386
}
87+
#endif
7488
while (1);
7589
}
7690
if (SerialEnable){
7791
Serial.print("LoRa Initial success!\r\n");
7892
}
93+
#if defined( WIFI_Kit_32 ) || defined( WIFI_LoRa_32 ) || defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick )
7994
if(DisplayEnable){
8095
display->clear();
8196
display->drawString(0, 0, "LoRa Initial success!");
8297
display->display();
8398
delay(300);
8499
}
100+
#endif
101+
85102
#endif
86103
}
87104
pinMode(LED,OUTPUT);

src/heltec.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
#if defined(ESP32)
77

88
#include <Arduino.h>
9+
#if defined( WIFI_Kit_32 ) || defined( WIFI_LoRa_32 ) || defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick )
910
#include <Wire.h>
10-
1111
#include "oled/SSD1306Wire.h"
12-
#if defined( WIFI_LoRa_32 ) || defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick )
12+
#endif
13+
14+
#if defined( WIFI_LoRa_32 ) || defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick ) || defined( Wireless_Stick_Lite )
1315
#include <SPI.h>
1416
#include "lora/LoRa.h"
1517
#endif
@@ -22,11 +24,13 @@ class Heltec_ESP32 {
2224
~Heltec_ESP32();
2325

2426
void begin(bool DisplayEnable=true, bool LoRaEnable=true, bool SerialEnable=true, bool PABOOST=true, long BAND=470E6);
25-
#if defined( WIFI_LoRa_32 ) || defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick )
27+
#if defined( WIFI_LoRa_32 ) || defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick ) || defined( Wireless_Stick_Lite )
2628
LoRaClass LoRa;
2729
#endif
2830

31+
#if defined( WIFI_Kit_32 ) || defined( WIFI_LoRa_32 ) || defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick )
2932
SSD1306Wire *display;
33+
#endif
3034

3135
/*wifi kit 32 and WiFi LoRa 32(V1) do not have vext*/
3236
void VextON(void);

0 commit comments

Comments
 (0)