Convert Firmware to PlatformIO Project
This commit is contained in:
parent
a51fd4714d
commit
4c934e5882
14 changed files with 169 additions and 27 deletions
18
README.md
18
README.md
|
@ -1,8 +1,4 @@
|
|||
# ATTNode v3 Firmware (WiP)
|
||||
|
||||
## Disclaimer
|
||||
|
||||
THIS IS STILL WORK IN PROGRESS!
|
||||
# ATTNode v3 Firmware
|
||||
|
||||
## Documentation
|
||||
|
||||
|
@ -10,17 +6,15 @@ THIS IS STILL WORK IN PROGRESS!
|
|||
|
||||
## Configuration and Programming
|
||||
|
||||
This is the Work in Progress Repository for ATTNode v3 compatible firmware. At the moment it supports LoRa communication using OTAA and a BME280 or SHT21 sensor, as well as deep sleep between measurements.
|
||||
This is the Repository for ATTNode v3 compatible firmware. At the moment it supports LoRa communication using OTAA and a BME280 or SHT21 sensor, as well as deep sleep between measurements.
|
||||
|
||||
As there is no PlatformIO Support for the ATTiny3216 yet, it is (for now) developed using Arduino IDE and the [MegaTinyCore](https://github.com/SpenceKonde/megaTinyCore). You also need to set the correct Settings for programming the ATTiny3216 in ArduionIDE. Here is a screenshot of the settings I use:
|
||||
The Firmware is developed using [PlatformIO](https://platformio.org/). At least Version 5.1.0 is needed for ATTiny3216 Support.
|
||||
|
||||
![ArduinoIDE Settings](ide_settings.png)
|
||||
To Set the Fuses for Clock Speed, BOD Levels etc., use the "Set Fuses" Operation in PlatformIO. This has to be done once for a "fresh" Node or when the Board Config in PlatformIO was changed. Afterwards it is enough to use the normal "Upload" function for Code or config.h changes.
|
||||
|
||||
You also need to install the MCCI Arduino LMIC Library form the IDEs Library Manager or from https://github.com/mcci-catena/arduino-lmic
|
||||
Before Programming Node, copy src/config.h.example to src/config.h and set the used sensor, LoRaWAN keys and other options as needed.
|
||||
|
||||
Before Compiling and Flashing make sure to copy config.h.example to config.h and set your LoRa OTAA Keys there. You can also set the Sending Interval and used Sensors there.
|
||||
|
||||
Programming is done using a [MicroUPDI Programmer](https://github.com/MCUdude/microUPDI) - for other pogramming variants see the MegaTinyCore documentation.
|
||||
Programming is done using a [MicroUPDI Programmer](https://github.com/MCUdude/microUPDI), settings in platformio.ini are set to use it. For other pogrammer options see the PlatformIO Documentation
|
||||
|
||||
## Configuring via Downlink
|
||||
|
||||
|
|
BIN
ide_settings.png
BIN
ide_settings.png
Binary file not shown.
Before Width: | Height: | Size: 155 KiB |
38
include/README
Normal file
38
include/README
Normal file
|
@ -0,0 +1,38 @@
|
|||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
46
lib/README
Normal file
46
lib/README
Normal file
|
@ -0,0 +1,46 @@
|
|||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
18
lib/SG112A/SG112A.cpp
Normal file
18
lib/SG112A/SG112A.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <Arduino.h>
|
||||
#include "SG112A.h"
|
||||
|
||||
void GA112A(void) {
|
||||
|
||||
}
|
||||
|
||||
uint16_t getPPM(void) {
|
||||
|
||||
}
|
||||
|
||||
void SG112A::sendCmd(uint8_t *cmd, uint8_t len) {
|
||||
|
||||
}
|
||||
|
||||
uint16_t SG112A::crc16(uint8_t *cmd, uint8_t len){
|
||||
|
||||
}
|
13
lib/SG112A/SG112A.h
Normal file
13
lib/SG112A/SG112A.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef SG112A_H
|
||||
#define SG112A_H
|
||||
|
||||
class SG112A {
|
||||
private:
|
||||
void sendCmd(uint8_t *cmd, uint8_t len);
|
||||
uint16_t crc16(uint8_t *cmd, uint8_t len);
|
||||
public:
|
||||
SG112A(void);
|
||||
uint16_t getPPM(void);
|
||||
};
|
||||
|
||||
#endif
|
41
platformio.ini
Normal file
41
platformio.ini
Normal file
|
@ -0,0 +1,41 @@
|
|||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:ATtiny3216]
|
||||
platform = atmelmegaavr
|
||||
board = ATtiny3216
|
||||
framework = arduino
|
||||
|
||||
# Board Config
|
||||
board_build.f_cpu = 5000000L
|
||||
board_hardware.oscillator = internal
|
||||
board_hardware.bod = disabled
|
||||
|
||||
# Debug Port Config
|
||||
monitor_speed = 115200
|
||||
|
||||
# LMIC Config via Build Flags
|
||||
build_flags =
|
||||
-D CFG_eu868
|
||||
-D CFG_sx1276_radio
|
||||
-D DISABLE_PING
|
||||
-D DISABLE_BEACONS
|
||||
-D ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS
|
||||
|
||||
# Programmer Config (MicroUPDI)
|
||||
upload_port = usb
|
||||
upload_protocol = xplainedmini_updi
|
||||
upload_flags =
|
||||
-p$BOARD_MCU
|
||||
-P$UPLOAD_PORT
|
||||
-c$UPLOAD_PROTOCOL
|
||||
|
||||
lib_deps =
|
||||
mcci-catena/MCCI LoRaWAN LMIC library @ ^3.3.0
|
|
@ -17,13 +17,6 @@
|
|||
// Actual Sleep Time is SLEEP_TIME*2*32 Seconds due to the 32s sleep intervals of the ATTiny3216
|
||||
uint16_t sleep_time = 10;
|
||||
|
||||
// Specify TTN EU Bandplan and LoRa Chip for the LMIC as well as Disabling some unused functions
|
||||
// See LMIC documentation / project_config.h for more options
|
||||
#define CFG_eu868 1
|
||||
#define CFG_sx1276_radio 1
|
||||
#define DISABLE_PING
|
||||
#define DISABLE_BEACONS
|
||||
|
||||
// Keys for OTAA Mode
|
||||
// APPEUI and DEVEUI from TTN, LSB!
|
||||
static const u1_t PROGMEM APPEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include <Arduino.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
@ -6,13 +5,12 @@
|
|||
#include <Wire.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
#include <lmic.h>
|
||||
#include <hal/hal.h>
|
||||
|
||||
// Keep Track of used EEPROM Addresses
|
||||
#define ADDR_SLP 0 // Sleep Interval, 2 Bytes
|
||||
|
||||
// Use the local config.h for LMIC Configuration
|
||||
#define ARDUINO_LMIC_PROJECT_CONFIG_H config.h
|
||||
#include <lmic.h>
|
||||
#include <hal/hal.h>
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
@ -34,12 +32,12 @@ void blink(uint8_t num) {
|
|||
#endif
|
||||
|
||||
#ifdef HAS_BME280
|
||||
#include "BME280.h"
|
||||
#include <BME280.h>
|
||||
BME280 sensor;
|
||||
#endif
|
||||
|
||||
#ifdef HAS_SHT21
|
||||
#include "SHT21.h"
|
||||
#include <SHT21.h>
|
||||
SHT21 sensor;
|
||||
#endif
|
||||
|
||||
|
@ -54,6 +52,7 @@ void os_getDevKey (u1_t* buf) {
|
|||
memcpy_P(buf, APPKEY, 16);
|
||||
}
|
||||
static osjob_t sendjob;
|
||||
void do_send(osjob_t* j);
|
||||
|
||||
// Pin-Mapping for ATTNode v3
|
||||
const lmic_pinmap lmic_pins = {
|
||||
|
@ -214,7 +213,7 @@ void setup()
|
|||
DEBUG_PRINT("Initializing LMIC...")
|
||||
os_init();
|
||||
LMIC_reset(); // Reset LMIC state and cancel all queued transmissions
|
||||
LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100); // Compensate for Clock Skew
|
||||
LMIC_setClockError(MAX_CLOCK_ERROR * 10 / 100); // Compensate for Clock Skew
|
||||
LMIC.dn2Dr = DR_SF9; // Downlink Band
|
||||
LMIC_setDrTxpow(DR_SF7, 14); // Default to SF7
|
||||
DEBUG_PRINTLN("Done");
|
Loading…
Reference in a new issue