Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add esp support #2

Merged
merged 7 commits into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add ESP8266 and ESP32 support
  • Loading branch information
Erriez committed Aug 21, 2022
commit cb28f58b2c844538e491c2645325e0233895f5c4
100 changes: 72 additions & 28 deletions .auto-build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
#/bin/bash
#
# MIT License
#
# Copyright (c) 2022 Erriez
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

# Automatic build script
#
Expand All @@ -8,56 +31,77 @@
# Exit immediately if a command exits with a non-zero status.
set -e

DOXYGEN_PDF="ErriezOregonTHN128.pdf"

echo "Starting auto-build script..."

function setup_virtualenv()
{
if [ ! -d ".venv" ]; then
virtualenv .venv
source .venv/bin/activate
pip3 install platformio==6.1.4
deactivate
fi

source .venv/bin/activate
}

function autobuild()
{
# Set environment variables
BOARDS_AVR="--board uno --board pro16MHzatmega328 --board pro8MHzatmega328"
BOARDS_ESP8266="--board d1_mini --board nodemcuv2"
BOARDS_ESP32="--board lolin_d32"

echo "Installing library dependencies"
# Install library dependency LowPower.h for example DHT22LowPower.ino
platformio lib --global install "Low-Power"
platformio lib --global install https://github.com/arduino-libraries/SD
platformio lib --global install "OneWire"
platformio lib --global install "DallasTemperature"
platformio lib --global install "adafruit/Adafruit GFX Library"
platformio lib --global install "adafruit/Adafruit SSD1306"
platformio lib --global install "adafruit/Adafruit BusIO"
# Install library dependency LowPower.h for AVR examples
pio pkg install --global --library "Low-Power"
pio pkg install --global --library https://github.com/arduino-libraries/SD
pio pkg install --global --library "OneWire"
pio pkg install --global --library "DallasTemperature"
pio pkg install --global --library "adafruit/Adafruit GFX Library"
pio pkg install --global --library "adafruit/Adafruit SSD1306"
pio pkg install --global --library "adafruit/Adafruit BusIO"

echo "Building examples..."
platformio ci --lib="." ${BOARDS_AVR} examples/ErriezOregonTHN128Receive/ErriezOregonTHN128Receive.ino
platformio ci --lib="." ${BOARDS_AVR} examples/ErriezOregonTHN128ReceiveSSD1306/ErriezOregonTHN128ReceiveSSD1306.ino
platformio ci --lib="." ${BOARDS_AVR} examples/ErriezOregonTHN128Transmit/ErriezOregonTHN128Transmit.ino
platformio ci --lib="." ${BOARDS_AVR} examples/ErriezOregonTHN128TransmitDS1820/ErriezOregonTHN128TransmitDS1820.ino

# Use option -O "lib_ldf_mode=chain+" to parse defines
platformio ci -O "lib_ldf_mode=chain+" --lib="." ${BOARDS_AVR} examples/ErriezOregonTHN128Receive/ErriezOregonTHN128Receive.ino
platformio ci -O "lib_ldf_mode=chain+" --lib="." ${BOARDS_AVR} examples/ErriezOregonTHN128ReceiveSSD1306/ErriezOregonTHN128ReceiveSSD1306.ino
platformio ci -O "lib_ldf_mode=chain+" --lib="." ${BOARDS_AVR} examples/ErriezOregonTHN128Transmit/ErriezOregonTHN128Transmit.ino
platformio ci -O "lib_ldf_mode=chain+" --lib="." ${BOARDS_AVR} examples/ErriezOregonTHN128TransmitDS1820/ErriezOregonTHN128TransmitDS1820.ino

platformio ci -O "lib_ldf_mode=chain+" --lib="." ${BOARDS_ESP8266} ${BOARDS_ESP32} examples/ErriezOregonTHN128Receive/ErriezOregonTHN128Receive.ino
platformio ci -O "lib_ldf_mode=chain+" --lib="." ${BOARDS_ESP8266} ${BOARDS_ESP32} examples/ErriezOregonTHN128ReceiveSSD1306/ErriezOregonTHN128ReceiveSSD1306.ino
platformio ci -O "lib_ldf_mode=chain+" --lib="." ${BOARDS_ESP8266} ${BOARDS_ESP32} examples/ErriezOregonTHN128Transmit/ErriezOregonTHN128Transmit.ino
platformio ci -O "lib_ldf_mode=chain+" --lib="." ${BOARDS_ESP8266} ${BOARDS_ESP32} examples/ErriezOregonTHN128TransmitDS1820/ErriezOregonTHN128TransmitDS1820.ino
}

function generate_doxygen()
{
echo "Generate Doxygen HTML..."

DOXYGEN_PDF="ErriezOregonTHN128.pdf"
if [ ! -f Doxyfile ]; then
return
fi

# Cleanup
rm -rf html latex
echo "Generate Doxygen HTML..."

# Generate Doxygen HTML and Latex
doxygen Doxyfile

# Allow filenames starting with an underscore
echo "" > html/.nojekyll
# Allow filenames starting with an underscore
echo "" > docs/html/.nojekyll

# Generate PDF when script is not running on Travis-CI
if [[ -z ${TRAVIS_BUILD_DIR} ]]; then
# Generate Doxygen PDF
make -C latex
# Generate Doxygen PDF
make -C docs/latex

# Copy PDF to root directory
cp latex/refman.pdf ./${DOXYGEN_PDF}
fi
# Copy PDF to root directory
cp docs/latex/refman.pdf ./${DOXYGEN_PDF}

# Cleanup
#rm -rf docs
}

setup_virtualenv
autobuild
generate_doxygen

generate_doxygen
4 changes: 2 additions & 2 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Erriez Oregon THN128 433MHz temperature sensor library
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.0.0
PROJECT_NUMBER = 1.0.1

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand All @@ -58,7 +58,7 @@ PROJECT_LOGO = extras/OregonTHN128.png
# entered, it will be relative to the location where doxygen was started. If
# left blank the current directory will be used.

OUTPUT_DIRECTORY =
OUTPUT_DIRECTORY = docs

# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
# directories (in 2 levels) under the output directory of each output format and
Expand Down
Binary file modified ErriezOregonTHN128.pdf
Binary file not shown.
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,33 @@ This microcontroller is available on Arduino UNO and `Pro Mini 3.3V 8MHz` boards
* Genuine DS18B20 temperature sensor.
* STX802 low-power 433MHz transmitter.

**Receiver on on the right breadboard:**
**Receiver on the right breadboard:**

* SRX882 low-power 433MHz receiver.
* SSD1306 I2C 128x64 OLED display.
* Pro-Mini 3V3 8MHz.

### Hardware notes

* For low-power transmitters, a `Pro Mini 3V3 8MHz` bare board with ATMega328 microcontroller is highly recommended. The board has no serial interface chip which reduces continuous power consumption. An external FTDI232 - USB serial interface should be connected for serial console / programming. (See red PCB on the picture)
Supported hardware:
* AVR designed for low-power
* ESP8266
* ESP32

* For low-power transmitters, a `Pro Mini 3V3 8MHz` bare board with ATMega328 microcontroller is highly recommended. The
board has no serial interface chip which reduces continuous power consumption. An external FTDI232 - USB serial
interface should be connected for serial console / programming. (See red PCB on the picture)
The SMD power LED should be desoldered from the Pro Mini to reduce continuous power consumption.
* A transmitter with (protected) 1500mA 18650 battery can operate for at least 6 months with `LowPower.h` functionality implemented. (By sending the temperature every 30 seconds)
* Changing the BOD (Brown Out Detection) fuse to 1.8V allows operation between 1.8 and 4.2V 18650 battery. (Explanation beyond the scope of this project)
* A transmitter with (protected) 1500mA 18650 battery can operate for at least 6 months with `LowPower.h` functionality
implemented. (By sending the temperature every 30 seconds)
* Changing the BOD (Brown Out Detection) fuse to 1.8V allows operation between 1.8 and 4.2V 18650 battery. (Explanation
beyond the scope of this project)
* 1 to 3 temperature transmitters are supported, similar to the original Oregon THN128 temperature transmitters.
* Check [list of counterfeit DS18B20 chips](https://github.com/cpetrich/counterfeit_DS18B20) , because this makes a huge difference in accuracy and read errors at 3.3V. Many DS18B20 chips from Aliexpress are counterfeit and won't work reliable at voltages below 3.3V.
* [NiceRF Wireless Technology Co., Ltd.](https://nl.aliexpress.com/store/934254) sells high quality 433MHz transmit (STX802) and receiver modules (STX882) with a good range.
* Check [list of counterfeit DS18B20 chips](https://github.com/cpetrich/counterfeit_DS18B20) , because this makes a huge
difference in accuracy and read errors at 3.3V. Many DS18B20 chips from Aliexpress are counterfeit and won't work
reliable at voltages below 3.3V.
* [NiceRF Wireless Technology Co., Ltd.](https://nl.aliexpress.com/store/934254) sells high quality 433MHz transmit
(STX802) and receiver modules (STX882) with a good range.
* A 18650 battery (with protection circuit) should be connected directly to the VCC pin (not VIN).
* The voltage regulator can be desoldered from the pro-micro board when not used for more power reduction.

Expand Down
41 changes: 25 additions & 16 deletions examples/ErriezOregonTHN128Receive/ErriezOregonTHN128Receive.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,24 @@
*/

#include <Arduino.h>
#include <LowPower.h> // https://github.com/LowPowerLab/LowPower
#include <ErriezOregonTHN128Receive.h>
#include <ErriezOregonTHN128Receive.h> // https://github.com/Erriez/ErriezOregonTHN128

// Connect RF receive to Arduino pin 2 (INT0) or pin 3 (INT1)
#define RF_RX_PIN 2
#if defined(ARDUINO_ARCH_AVR)
#include <LowPower.h> // https://github.com/LowPowerLab/LowPower
#define RF_RX_PIN 2 // Connect RF receive pin to Arduino pin 2 (INT0) or pin 3 (INT1)
#elif defined(ARDUINO_ARCH_ESP8266)
#define RF_RX_PIN 14 // GPIO14 NodeMCU D5
#elif defined(ARDUINO_ARCH_ESP32)
#define RF_RX_PIN 19 // GPIO19
#else
#error "May work, but not tested on this target"
#endif


void printReceivedData(OregonTHN128Data_t *data)
{
bool negativeTemperature = false;
static uint32_t rxCount = 0;
static unsigned long rxCount = 0;
int16_t tempAbs;
char msg[80];

Expand All @@ -48,7 +55,7 @@ void printReceivedData(OregonTHN128Data_t *data)
rxCount++,
data->rollingAddress, data->channel,
(negativeTemperature ? "-" : ""), (tempAbs / 10), (tempAbs % 10), data->lowBattery,
data->rawData);
(unsigned long)data->rawData);
Serial.println(msg);
}

Expand Down Expand Up @@ -81,20 +88,22 @@ void loop()
// Print received data
printReceivedData(&data);

#if 0
// Wait ~30 seconds before receiving next temperature from one transmitter
// Works only when using one channel
Serial.flush();
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
LowPower.powerDown(SLEEP_2S, ADC_OFF, BOD_OFF);
#endif
//#if defined(ARDUINO_ARCH_AVR)
// // Wait ~30 seconds before receiving next temperature from one transmitter
// // Works only when using one channel
// Serial.flush();
// LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
// LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
// LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
// LowPower.powerDown(SLEEP_2S, ADC_OFF, BOD_OFF);
//#else
// delay(30 * 60);
//#endif

// Turn LED off
digitalWrite(LED_BUILTIN, LOW);

// Enable receive
OregonTHN128_RxEnable();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,27 @@
*/

#include <Arduino.h>
#include <LowPower.h> // https://github.com/LowPowerLab/LowPower
#include <ErriezOregonTHN128Receive.h>
#include <ErriezOregonTHN128Receive.h> // https://github.com/Erriez/ErriezOregonTHN128
#include <Wire.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_I2CDevice.h> // https://github.com/adafruit/Adafruit_BusIO
#include <Adafruit_GFX.h> // https://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_SSD1306.h> // https://github.com/adafruit/Adafruit_SSD1306
#include <Fonts/FreeSerif9pt7b.h>

// Connect RF receive to Arduino pin 2 (INT0) or pin 3 (INT1)
#define RF_RX_PIN 2
#if defined(ARDUINO_ARCH_AVR)
#include <LowPower.h> // https://github.com/LowPowerLab/LowPower
#define RF_RX_PIN 2 // Connect RF receive pin to Arduino pin 2 (INT0) or pin 3 (INT1)
#elif defined(ARDUINO_ARCH_ESP8266)
// GPIO5 NodeMCU D1 SCL
// GPIO4 NodeMCU D2 SDA
#define RF_RX_PIN 14 // GPIO14 NodeMCU D5
#elif defined(ARDUINO_ARCH_ESP32)
// GPIO22 SCL
// GPIO21 SDA
#define RF_RX_PIN 19 // GPIO19
#else
#error "May work, but not tested on this target"
#endif

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Expand Down Expand Up @@ -245,7 +256,7 @@ const GFXfont Lato_Black_24 PROGMEM = {
void printReceivedData(OregonTHN128Data_t *data)
{
bool negativeTemperature = false;
static uint32_t rxCount = 0;
static unsigned long rxCount = 0;
int16_t tempAbs;
char msg[80];

Expand All @@ -260,7 +271,7 @@ void printReceivedData(OregonTHN128Data_t *data)
rxCount++,
data->rollingAddress, data->channel,
(negativeTemperature ? "-" : ""), (tempAbs / 10), (tempAbs % 10), data->lowBattery,
data->rawData);
(unsigned long)data->rawData);
Serial.println(msg);
}

Expand Down
Loading