Added new platform: Wemos ESP8266 D1 mini pro. Now radio starts but still does not send any clock information.
This commit is contained in:
parent
59a0170b85
commit
672d5baf23
|
@ -0,0 +1,41 @@
|
||||||
|
|
||||||
|
This directory is intended for the project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link to executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in separate directory, like
|
||||||
|
"lib/private_lib/[here are source files]".
|
||||||
|
|
||||||
|
For example, see how can be organized `Foo` and `Bar` libraries:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional, custom build options, etc) http://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- readme.txt --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
Then in `src/main.c` you should use:
|
||||||
|
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
// rest H/C/CPP code
|
||||||
|
|
||||||
|
PlatformIO will find your libraries automatically, configure preprocessor's
|
||||||
|
include paths and build them.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- http://docs.platformio.org/page/librarymanager/ldf.html
|
|
@ -8,6 +8,11 @@
|
||||||
; Please visit documentation for the other options and examples
|
; Please visit documentation for the other options and examples
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:d1_mini_pro]
|
||||||
|
platform = espressif8266
|
||||||
|
board = d1_mini_pro
|
||||||
|
framework = arduino
|
||||||
|
|
||||||
[env:heltec_wifi_kit_8]
|
[env:heltec_wifi_kit_8]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = heltec_wifi_kit_8
|
board = heltec_wifi_kit_8
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
#ifndef config_h_included
|
#ifndef config_h_included
|
||||||
#define config_h_included
|
#define config_h_included
|
||||||
|
|
||||||
#define PIN_MASTER_CLIENT_SELECT 2
|
#define PIN_NRF24_CE 2 /*10*/
|
||||||
#define ROLE_MASTER LOW
|
#define PIN_NRF24_CSN 15 /*8*/
|
||||||
#define ROLE_CLIENT HIGH
|
|
||||||
#define PIN_NRF24_CE 10
|
|
||||||
#define PIN_NRF24_CSN 8
|
|
||||||
|
|
||||||
#define PIN_RELAY1 5
|
#define PIN_RELAY1 5
|
||||||
#define PIN_RELAY2 6
|
#define PIN_RELAY2 6
|
||||||
|
|
|
@ -6,7 +6,10 @@
|
||||||
|
|
||||||
|
|
||||||
// display
|
// display
|
||||||
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 5, /* data=*/ 4);
|
//U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 5, /* data=*/ 4);
|
||||||
|
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=16*/ -1, /* clock=*/ 5, /* data=*/ 4);
|
||||||
|
//U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0);
|
||||||
|
//U8X8_SH1106_128X64_NONAME_4W_HW_SPI u8g2(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
|
||||||
|
|
||||||
#define LOGO16_GLCD_HEIGHT 16
|
#define LOGO16_GLCD_HEIGHT 16
|
||||||
#define LOGO16_GLCD_WIDTH 16
|
#define LOGO16_GLCD_WIDTH 16
|
||||||
|
|
123
src/main.cpp
123
src/main.cpp
|
@ -9,11 +9,11 @@
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <RF24.h>
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "fastclock.h"
|
#include "fastclock.h"
|
||||||
|
#include "radio.h"
|
||||||
|
|
||||||
#define AUTOSTART_CLOCK_AFTER_ms 10000
|
#define AUTOSTART_CLOCK_AFTER_ms 10000
|
||||||
|
|
||||||
|
@ -30,14 +30,12 @@ char static_sn[16] = "255.255.255.0";
|
||||||
//flag for saving data
|
//flag for saving data
|
||||||
bool shouldSaveConfig = false;
|
bool shouldSaveConfig = false;
|
||||||
|
|
||||||
RF24 radio(PIN_NRF24_CE, PIN_NRF24_CSN);
|
|
||||||
byte addresses[][6] = {NETWORK_ADDRESS_MASTER_SEND, NETWORK_ADDRESS_MASTER_RECEIVE};
|
|
||||||
|
|
||||||
// FastClock
|
// FastClock
|
||||||
bool isMaster = true;
|
bool isMaster = true;
|
||||||
|
|
||||||
Display display;
|
Display display;
|
||||||
Fastclock fastclock(&display);
|
Fastclock fastclock(&display);
|
||||||
|
Radio radio(&display, true /*isMaster*/);
|
||||||
|
|
||||||
//callback notifying us of the need to save config
|
//callback notifying us of the need to save config
|
||||||
void saveConfigCallback () {
|
void saveConfigCallback () {
|
||||||
|
@ -205,23 +203,7 @@ void setup() {
|
||||||
|
|
||||||
// setupWifiConnection();
|
// setupWifiConnection();
|
||||||
|
|
||||||
// setting up RF24
|
|
||||||
#if 0
|
|
||||||
display.addLogMessage("Start RF24 radio");
|
|
||||||
radio.begin();
|
radio.begin();
|
||||||
// Open a writing and reading pipe on each radio, with opposite addresses
|
|
||||||
if (isMaster){
|
|
||||||
radio.openWritingPipe(addresses[1]);
|
|
||||||
radio.openReadingPipe(1,addresses[0]);
|
|
||||||
} else {
|
|
||||||
radio.openWritingPipe(addresses[0]);
|
|
||||||
radio.openReadingPipe(1,addresses[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the radio listening for data
|
|
||||||
radio.startListening();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
fastclock.begin();
|
fastclock.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,105 +230,4 @@ void loop(void)
|
||||||
fastclock.loop();
|
fastclock.loop();
|
||||||
display.showDashboard();
|
display.showDashboard();
|
||||||
|
|
||||||
#if 0
|
|
||||||
// put your main code here, to run repeatedly:
|
|
||||||
/****************** Ping Out Role ***************************/
|
|
||||||
if (isMaster) {
|
|
||||||
|
|
||||||
radio.stopListening();
|
|
||||||
|
|
||||||
Serial.println(F("Now sending"));
|
|
||||||
|
|
||||||
unsigned long start_time = micros();
|
|
||||||
if (!radio.write(&start_time, sizeof(unsigned long))) {
|
|
||||||
Serial.println(F("failed"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
radio.startListening();
|
|
||||||
|
|
||||||
unsigned long started_waiting_at = micros();
|
|
||||||
boolean timeout = false;
|
|
||||||
|
|
||||||
while (!radio.available()) {
|
|
||||||
if (micros() - started_waiting_at > 200000 ) { // If waited longer than 200ms, indicate timeout and exit while loop
|
|
||||||
timeout = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (timeout) {
|
|
||||||
Serial.println(F("Failed, response timed out."));
|
|
||||||
} else {
|
|
||||||
unsigned long got_time;
|
|
||||||
radio.read( &got_time, sizeof(unsigned long) );
|
|
||||||
unsigned long end_time = micros();
|
|
||||||
|
|
||||||
// Spew it
|
|
||||||
Serial.print(F("Sent "));
|
|
||||||
Serial.print(start_time);
|
|
||||||
Serial.print(F(", Got response "));
|
|
||||||
Serial.print(got_time);
|
|
||||||
Serial.print(F(", Round-trip delay "));
|
|
||||||
Serial.print(end_time-start_time);
|
|
||||||
Serial.println(F(" microseconds"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try again 1s later
|
|
||||||
delay(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/****************** Pong Back Role ***************************/
|
|
||||||
|
|
||||||
if (!isMaster)
|
|
||||||
{
|
|
||||||
unsigned long got_time;
|
|
||||||
|
|
||||||
if( radio.available()){
|
|
||||||
// Variable for the received timestamp
|
|
||||||
while (radio.available()) { // While there is data ready
|
|
||||||
radio.read( &got_time, sizeof(unsigned long) ); // Get the payload
|
|
||||||
}
|
|
||||||
|
|
||||||
radio.stopListening(); // First, stop listening so we can talk
|
|
||||||
radio.write( &got_time, sizeof(unsigned long) ); // Send the final one back.
|
|
||||||
radio.startListening(); // Now, resume listening so we catch the next packets.
|
|
||||||
Serial.print(F("Sent response "));
|
|
||||||
Serial.println(got_time);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#ifdef RF_RadioHead
|
|
||||||
if (!Datagram.init()) {
|
|
||||||
LOG(LL_ERROR, ("*** Datagram init failed"));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef RF_RF24
|
|
||||||
radio.begin();
|
|
||||||
if (radio.isChipConnected()) { LOG(LL_INFO, ("*** RF chip found")); }
|
|
||||||
else { LOG(LL_ERROR, ("*** ERROR: RF chip not found!")); }
|
|
||||||
radio.setChannel(1);
|
|
||||||
radio.setPALevel(RF24_PA_MAX);
|
|
||||||
radio.setDataRate(RF24_2MBPS);
|
|
||||||
radio.setAutoAck(0);
|
|
||||||
//radio.setRetries(2,15); // Optionally, increase the delay between retries & # of retries
|
|
||||||
radio.setCRCLength(RF24_CRC_8);
|
|
||||||
radio.openWritingPipe(pipes[0]);
|
|
||||||
radio.openReadingPipe(1,pipes[1]);
|
|
||||||
radio.startListening();
|
|
||||||
radio.printDetails();
|
|
||||||
// @TODO: real random seed!
|
|
||||||
//randomSeed(analogRead(0));
|
|
||||||
//randomSeed(22);
|
|
||||||
radio.powerUp();
|
|
||||||
LOG(LL_INFO, ("*** RF payload size=%d bytes", radio.getPayloadSize()));
|
|
||||||
if (radio.testCarrier() || radio.testRPD()) { LOG(LL_INFO, ("*** Carrier/RPD seen on radio")); }
|
|
||||||
if (radio.failureDetected) { LOG(LL_ERROR, ("*** Radio error detected!")); }
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -0,0 +1,124 @@
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <nRF24L01.h>
|
||||||
|
#include <RF24.h>
|
||||||
|
#include "config.h"
|
||||||
|
#include "radio.h"
|
||||||
|
|
||||||
|
static RF24 rf24(PIN_NRF24_CE, PIN_NRF24_CSN); // 10, 8
|
||||||
|
static byte addresses[][6] = {NETWORK_ADDRESS_MASTER_SEND, NETWORK_ADDRESS_MASTER_RECEIVE};
|
||||||
|
|
||||||
|
void Radio::begin(void) {
|
||||||
|
display->addLogMessage("Start RF24 radio");
|
||||||
|
pinMode(PIN_NRF24_CSN, OUTPUT);
|
||||||
|
pinMode(PIN_NRF24_CE, OUTPUT);
|
||||||
|
return;
|
||||||
|
rf24.begin();
|
||||||
|
if (rf24.isChipConnected()) { display->addLogMessage("*** RF chip found"); }
|
||||||
|
else { display->addLogMessage("*** ERROR: RF chip not found!"); }
|
||||||
|
rf24.setChannel(1);
|
||||||
|
rf24.setPALevel(RF24_PA_MAX);
|
||||||
|
rf24.setDataRate(RF24_2MBPS);
|
||||||
|
rf24.setAutoAck(0);
|
||||||
|
//radio.setRetries(2,15); // Optionally, increase the delay between retries & # of retries
|
||||||
|
rf24.setCRCLength(RF24_CRC_8);
|
||||||
|
rf24.openWritingPipe(addresses[0]);
|
||||||
|
rf24.openReadingPipe(1, addresses[1]);
|
||||||
|
rf24.startListening();
|
||||||
|
rf24.printDetails();
|
||||||
|
// @TODO: real random seed!
|
||||||
|
//randomSeed(analogRead(0));
|
||||||
|
//randomSeed(22);
|
||||||
|
rf24.powerUp();
|
||||||
|
Serial.print("*** RF payload size="); Serial.print(rf24.getPayloadSize()); Serial.println(" bytes");
|
||||||
|
if (rf24.testCarrier() || rf24.testRPD()) { display->addLogMessage("*** Carrier/RPD seen on radio"); }
|
||||||
|
if (rf24.failureDetected) { display->addLogMessage("*** Radio error detected!"); }
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// Open a writing and reading pipe on each radio, with opposite addresses
|
||||||
|
if (isMaster){
|
||||||
|
rf24.openWritingPipe(addresses[1]);
|
||||||
|
rf24.openReadingPipe(1,addresses[0]);
|
||||||
|
} else {
|
||||||
|
rf24.openWritingPipe(addresses[0]);
|
||||||
|
rf24.openReadingPipe(1,addresses[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Start the radio listening for data
|
||||||
|
rf24.startListening();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Radio::loop(void) {
|
||||||
|
#if 0
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
/****************** Ping Out Role ***************************/
|
||||||
|
if (isMaster) {
|
||||||
|
|
||||||
|
radio.stopListening();
|
||||||
|
|
||||||
|
Serial.println(F("Now sending"));
|
||||||
|
|
||||||
|
unsigned long start_time = micros();
|
||||||
|
if (!radio.write(&start_time, sizeof(unsigned long))) {
|
||||||
|
Serial.println(F("failed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
radio.startListening();
|
||||||
|
|
||||||
|
unsigned long started_waiting_at = micros();
|
||||||
|
boolean timeout = false;
|
||||||
|
|
||||||
|
while (!radio.available()) {
|
||||||
|
if (micros() - started_waiting_at > 200000 ) { // If waited longer than 200ms, indicate timeout and exit while loop
|
||||||
|
timeout = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
Serial.println(F("Failed, response timed out."));
|
||||||
|
} else {
|
||||||
|
unsigned long got_time;
|
||||||
|
radio.read( &got_time, sizeof(unsigned long) );
|
||||||
|
unsigned long end_time = micros();
|
||||||
|
|
||||||
|
// Spew it
|
||||||
|
Serial.print(F("Sent "));
|
||||||
|
Serial.print(start_time);
|
||||||
|
Serial.print(F(", Got response "));
|
||||||
|
Serial.print(got_time);
|
||||||
|
Serial.print(F(", Round-trip delay "));
|
||||||
|
Serial.print(end_time-start_time);
|
||||||
|
Serial.println(F(" microseconds"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try again 1s later
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/****************** Pong Back Role ***************************/
|
||||||
|
|
||||||
|
if (!isMaster)
|
||||||
|
{
|
||||||
|
unsigned long got_time;
|
||||||
|
|
||||||
|
if( radio.available()){
|
||||||
|
// Variable for the received timestamp
|
||||||
|
while (radio.available()) { // While there is data ready
|
||||||
|
radio.read( &got_time, sizeof(unsigned long) ); // Get the payload
|
||||||
|
}
|
||||||
|
|
||||||
|
radio.stopListening(); // First, stop listening so we can talk
|
||||||
|
radio.write( &got_time, sizeof(unsigned long) ); // Send the final one back.
|
||||||
|
radio.startListening(); // Now, resume listening so we catch the next packets.
|
||||||
|
Serial.print(F("Sent response "));
|
||||||
|
Serial.println(got_time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef radio_h_included
|
||||||
|
#define radio_h_included
|
||||||
|
#include "config.h"
|
||||||
|
#include "display.h"
|
||||||
|
|
||||||
|
class Radio {
|
||||||
|
public:
|
||||||
|
Radio(Display *d, bool _isMaster):display(d), isMaster(_isMaster) { };
|
||||||
|
void begin(void);
|
||||||
|
void loop(void);
|
||||||
|
private:
|
||||||
|
Display *display;
|
||||||
|
bool isMaster;
|
||||||
|
};
|
||||||
|
#endif
|
Loading…
Reference in New Issue