Skip to content

Commit

Permalink
Merge pull request #11 from aattww/dev
Browse files Browse the repository at this point in the history
Merge dev to master
  • Loading branch information
aattww committed Jun 7, 2020
2 parents 7a78a7e + da6bd14 commit 9801b32
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 18 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Sensors requires a few external components to work: libraries provide functions
**RadioHead Packet Radio library for embedded microprocessors** provides support for RFM95W/RFM96W radios (and many others as well). Download from [airspayce.com](https://www.airspayce.com/mikem/arduino/RadioHead/). After extracting the library to your Arduino IDE libraries folder you will have to do one adjustment. In the beginning of *RadioHead/RH_RF95.h* change line
`#define RH_RF95_FIFO_SIZE 255`
to
`#define RH_RF95_FIFO_SIZE 100`
`#define RH_RF95_FIFO_SIZE 64`
Communication will not work without this change. You also risk running out of SRAM without this adjustment.

**Arduino Cryptography Library** includes support for encryption. If you do not plan to encrypt traffic, you will not need this library. Download from [github.com](https://github.com/rweather/arduinolibs). You will need to download the ZIP and extract contents of *libraries* to your Arduino IDE libraries folder. Also remember to uncomment the following line at the very end of *RadioHead/RadioHead.h* to enable encryption:
Expand Down Expand Up @@ -241,7 +241,7 @@ Some notes:

I have successfully ordered PCBs from Seeed Studio. You can get boards for 10 gateways/pulse nodes and 10 battery nodes for $9.80 plus postage. Of course any prototype PCB factory will work. PCBs are designed not to have any tight spacings or need for strict tolerances. For gateway and pulse node, select 1.6mm thickness (the enclosure will hold the PCB better). With battery nodes, boards can be thinner (for example 1.2mm works well). Other options should be okay with defaults.

Boards are designed to fit the enclosures mentioned in the table. [Bud Industries DMB-4771](https://www.budind.com/view/Plastic+Boxes/DIN+Rail+Mount+Multi-Board+Box) is a 35mm DIN rail mounted box, while [Supertronic PP42](http://www.supertronic.com/en/cajas_de_plastico/sensors/29/pp42/50) is a simple wall mounted enclosure (use double-sided tape). In the *schematics* folder there is also *AP9_holder.stl* which is a 3D model of a simple holder to fix a battery node into an [ABB AP9 junction box](https://new.abb.com/products/2TKA140012G1/ap9-junction-box-ip65). This is especially handy if you install a node outside and have access to a 3D printer. You will need two holders and a set of small screws. You will also need to have a way to make the box rain-proof but still let humidity and temperature in. Poking some holes into membrane cable entries is one way, or if you want to go professional, use a sintered protective cover. [This](https://www.ebay.com/itm/Protective-Cover-SHT10-SHT20-Soil-Temperature-Humidity-Moisture-Sensor-Shell/173940209491) has been proven to work: a BME280 breakout board will *just* fit inside if you solder wires to the board as [shown here](images/bme280.jpg). Remember to wrap the breakout board (but not the sensor itself) with some insulating tape or use heat shrink to prevent short circuits. [This image](images/si7021_wired.jpg) shows an Si7021 breakout board prepared for outdoor sensor use. You will also need to drill off the plastic inside with the connectors of the protective cover. Use some imagination here. A ready-made weatherproofed sensor looks something like [this](images/weatherproof_node.jpg).
Boards are designed to fit the enclosures mentioned in the table. [Bud Industries DMB-4771](https://www.budind.com/view/Plastic+Boxes/DIN+Rail+Mount+Multi-Board+Box) is a 35mm DIN rail mounted box, while [Supertronic PP42](http://www.supertronic.com/en/cajas_de_plastico/sensors/29/pp42/50) is a simple wall mounted enclosure (use double-sided tape). In the *schematics* folder there is also *AP9_holder.stl* which is a 3D model of a simple holder to fix a battery node into an [ABB AP9 junction box](https://new.abb.com/products/2TKA140012G1/ap9-junction-box-ip65). This is especially handy if you install a node outside and have access to a 3D printer. You will need two holders and a set of small screws. You will also need to have a way to make the box rain-proof but still let humidity and temperature in. Poking some holes into membrane cable entries is one way, or if you want to go professional, use a sintered protective cover. [This](https://www.ebay.com/itm/Protective-Cover-SHT10-SHT20-Soil-Temperature-Humidity-Moisture-Sensor-Shell/173940209491) has been proven to work: a BME280 breakout board will *just* fit inside if you solder wires to the board as [shown here](images/bme280.jpg). Remember to wrap the breakout board (but not the sensor itself) with some insulating tape or use heat shrink to prevent short circuits. [This image](images/si7021_wired.jpg) shows an Si7021 breakout board prepared for outdoor sensor use. You will also need to drill off the plastic inside with the connectors of the protective cover. Use some imagination here. A ready-made weatherproofed sensor looks something like [this](images/weatherproof_node.jpg). Connecting an NTC thermistor with sufficiently long wire will make a nice water temperature node as shown [here](images/water_temperature_node.jpg).

## BOM

Expand Down Expand Up @@ -425,7 +425,7 @@ During normal operation button triggers instant send with full power. Use to qui

## 1. Solder boards

Refer to [Schematics and PCB](#schematics-and-pcb) for detailed instructions for manufacturing boards. All the chips are through hole packages for easier hand soldering. Smaller components are mostly SMD but they are sufficiently large so that even unexperienced solderers should be able to hand solder them.
Refer to [Schematics and PCB](#schematics-and-pcb) for detailed instructions and ideas for manufacturing boards. All the chips are through hole packages for easier hand soldering. Smaller components are mostly SMD but they are sufficiently large so that even unexperienced solderers should be able to hand solder them.

## 2. Download this repository

Expand Down Expand Up @@ -474,6 +474,12 @@ Start logging measurements to a MySQL database ([*save_modbus_to_db.py*](save_mo

# Version history

## v1.1.2 (2020-06-07)

* Fixed 23K256 SRAM handler transactions. [#8](https://github.com/aattww/sensors/issues/8)
* Fixed initial transmit power of battery and pulse type nodes.
* Fixed RFM95W transmit powers to address changes made in the RadioHead library.

## v1.1.1 (2020-03-31)

* Fix and refine NTC sensor reading and calculations in NTCSensor.
Expand Down
8 changes: 4 additions & 4 deletions SensorsBattery/SensorsBattery.ino
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
*/


#define VERSION 2
#define VERSION 3

#include <RH_RF95.h>
#include <RHReliableDatagram.h>
Expand Down Expand Up @@ -123,8 +123,8 @@

#define PAYLOAD_LEN 11
#define GATEWAYID 254
#define TX_MAX_PWR 23
#define TX_MIN_PWR 5
#define TX_MAX_PWR 20
#define TX_MIN_PWR 2

const float frequency = FREQUENCY; // Radio transmit frequency (depends on module in use and legislation)
#ifdef ENCRYPT_KEY
Expand Down Expand Up @@ -178,7 +178,7 @@ int16_t sensor2Value = 0;
int16_t sensor3Value = 0;

uint16_t batteryVoltage = 0;
uint8_t transmitPower = (TX_MIN_PWR + TX_MAX_PWR) / 4; // Set initial transmit power to low medium
int8_t transmitPower = ((TX_MAX_PWR - TX_MIN_PWR) / 4) + TX_MIN_PWR; // Set initial transmit power to low medium
uint8_t transmitPowerRaw = 25;


Expand Down
6 changes: 3 additions & 3 deletions SensorsGateway/SensorsGateway.ino
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@


#define MAJOR_VERSION 1
#define MINOR_VERSION 4
#define MINOR_VERSION 5

#include <SimpleModbusAsync.h>
#include <RH_RF95.h>
Expand All @@ -100,8 +100,8 @@
#define SRAM_NSS 9

#define GATEWAYID 254 // Gateway ID in radio network, DO NOT CHANGE!
#define TX_MAX_PWR 23 // Radio dependant, this is for RFM95
#define TX_MIN_PWR 5 // Radio dependant, this is for RFM95
#define TX_MAX_PWR 20 // Radio dependant, this is for RFM95
#define TX_MIN_PWR 2 // Radio dependant, this is for RFM95
#define MAX_PAYLOAD_BUF 50 // This needs to be at least 50 to be on the safe side!
#define PULSE_MIN 1000 // How many ms between pulses at least
#define EEPROM_SAVE 3600000 // How often in ms to save pulse values to EEPROM
Expand Down
8 changes: 4 additions & 4 deletions SensorsPulse/SensorsPulse.ino
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
*/


#define VERSION 3
#define VERSION 4

#if defined NODE_TYPE_MULTICAL
#include <SimpleModbusAsync.h>
Expand Down Expand Up @@ -116,8 +116,8 @@
#endif

#define GATEWAYID 254
#define TX_MAX_PWR 23
#define TX_MIN_PWR 5
#define TX_MAX_PWR 20
#define TX_MIN_PWR 2
#define PULSE_MIN 1000
#define EEPROM_SAVE 3600000

Expand Down Expand Up @@ -159,7 +159,7 @@ bool isDebugMode = false;
volatile bool forceSend = false;
uint8_t nodeId; // Node ID

uint8_t transmitPower = (TX_MIN_PWR + TX_MAX_PWR) / 4; // Set initial transmit power to low medium
int8_t transmitPower = ((TX_MAX_PWR - TX_MIN_PWR) / 4) + TX_MIN_PWR; // Set initial transmit power to low medium
uint8_t transmitPowerRaw = 25;

volatile uint32_t pulse1 = 0;
Expand Down
Binary file added images/water_temperature_node.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 31 additions & 4 deletions libraries/SensorsMemoryHandler/Sensors23K256Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
* interfacing with 23K256 by providing abstraction to save and restore node data.
*/

/*
* Version history
* ---------------
*
* 1.1 2020-04-21 (CURRENT)
* - Add beginTransaction() and endTransaction() to prevent interrupts interfering
* with transmissions.
* - Stop using transfer16() and use transfer() instead.
*
* 1.0 2019-12-26
* Initial public release
*/

#include "Sensors23K256Handler.h"

/*
Expand Down Expand Up @@ -102,10 +115,12 @@ void Sensors23K256Handler::setOperatingMode(uint8_t newMode) {
}

if (newMode != _currentOperatingMode) {
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
digitalWrite(_slaveSelectPin, LOW);
SPI.transfer(SMH_WRSR);
SPI.transfer(newMode);
digitalWrite(_slaveSelectPin, HIGH);
SPI.endTransaction();
_currentOperatingMode = newMode;
}
}
Expand All @@ -126,11 +141,14 @@ uint8_t Sensors23K256Handler::readByte(uint16_t address) {
// Make sure we are in correct operating mode
setOperatingMode(SMH_BYTE_MODE);

SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
digitalWrite(_slaveSelectPin, LOW);
SPI.transfer(SMH_READ);
SPI.transfer16(address);
SPI.transfer(address >> 8);
SPI.transfer(address);
uint8_t readByte = SPI.transfer(0);
digitalWrite(_slaveSelectPin, HIGH);
SPI.endTransaction();

return readByte;
}
Expand All @@ -152,11 +170,14 @@ void Sensors23K256Handler::writeByte(uint16_t address, uint8_t writeByte) {
// Make sure we are in correct operating mode
setOperatingMode(SMH_BYTE_MODE);

SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
digitalWrite(_slaveSelectPin, LOW);
SPI.transfer(SMH_WRITE);
SPI.transfer16(address);
SPI.transfer(address >> 8);
SPI.transfer(address);
SPI.transfer(writeByte);
digitalWrite(_slaveSelectPin, HIGH);
SPI.endTransaction();
}

/*
Expand All @@ -177,15 +198,18 @@ void Sensors23K256Handler::readSequence(uint16_t address, uint16_t length, uint8
// Make sure we are in correct operating mode
setOperatingMode(SMH_SEQUENTIAL_MODE);

SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
digitalWrite(_slaveSelectPin, LOW);
SPI.transfer(SMH_READ);
SPI.transfer16(address);
SPI.transfer(address >> 8);
SPI.transfer(address);

for (uint16_t i = 0; i < length; i++) {
buffer[i] = SPI.transfer(0);
}

digitalWrite(_slaveSelectPin, HIGH);
SPI.endTransaction();
}

/*
Expand All @@ -206,9 +230,11 @@ void Sensors23K256Handler::writeSequence(uint16_t address, uint16_t length, uint
// Make sure we are in correct operating mode
setOperatingMode(SMH_SEQUENTIAL_MODE);

SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
digitalWrite(_slaveSelectPin, LOW);
SPI.transfer(SMH_WRITE);
SPI.transfer16(address);
SPI.transfer(address >> 8);
SPI.transfer(address);

for (uint16_t i = 0; i < length; i++) {
if (buffer) {
Expand All @@ -220,6 +246,7 @@ void Sensors23K256Handler::writeSequence(uint16_t address, uint16_t length, uint
}

digitalWrite(_slaveSelectPin, HIGH);
SPI.endTransaction();
}

/*
Expand Down
13 changes: 13 additions & 0 deletions libraries/SensorsMemoryHandler/Sensors23K256Handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
* interfacing with 23K256 by providing abstraction to save and restore node data.
*/

/*
* Version history
* ---------------
*
* 1.1 2020-04-21 (CURRENT)
* - Add beginTransaction() and endTransaction() to prevent interrupts interfering
* with transmissions.
* - Stop using transfer16() and use transfer() instead.
*
* 1.0 2019-12-26
* Initial public release
*/

#ifndef SENSORS23K256HANDLER_H
#define SENSORS23K256HANDLER_H

Expand Down

0 comments on commit 9801b32

Please sign in to comment.