Exanh Gardener soil moisture sensor support. Copyright 2017 Nathael Pajani /* **************************************************************************** * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * *************************************************************************** */ This code handles the v0.2 and v0.3 versions of the Exanh Gardener soil moisture sensor. The code also provides support of all three sensors found on exanh sensor board in version 0.2 : - BME280 I2C temperature, humidity and pressure sensor - TSL256x I2C luminosity and IR sensor - VEML6070 I2C UV sensor The default behavior for the sensor does nothing (should enter sleep, but not implemented yet). When the sensor is not configured (no address set), then all data received on serial is silently dropped. Pressing the "Mode" button on the sensor for more than 4 seconds sends a "c" request on the serial line, changes address to 0 (nul), and enters the "address requested" state. The host should then send a message to the sensor on it's temporary address, containing it's new address. The message is three bytes long and it's format is : # 0 addr 0x23 0x00 (0x01 to 0x1F) Addresses are between 1 and 31, allowing up to 30 sensors on one link. Once the address is set, the host can request samples data by sending a message addressed to the sensor. The message is three or more bytes long (depending on the type) and it's format is : # addr type [other data] 0x23 (0x01 to 0x1F) (0x00 to 0xFF) [....] Valid types are : - 'a' : get all - request to send all available sensor data to host, no data. - 'l' : set led color - set the sensor led color. Three bytes of data (RGB). - 'c' : get compensation data from BME280 sensor. (TO BE DEFINED) It is also possible to broadcast a message to all sensors by sending to address 255 (0xFF) The response for the "get all" request has the following format : # (addr | sensors) data 0x23 1 byte 18 bytes The second byte holds the address on the fist 5 bits (LSB), and information on available sensors on the three top bits : addr | sensors : (0x01 to 0x1F) | (got_tsl << 5) | (got_veml << 6) | (got_bme << 7) got_tsl : Set if TSL256x sensor is present and configured got_veml : Set if VEML6070 sensor is present and configured got_bme : Set if BME280 sensor is present and configured data is a set of nine 16bits values, in network (big) endian order, with the following meaning, in this order : - raw_humidity from soil moisture sensor - lux value from TSL256x - ir value from TSL256x - uv value from VEML6070 - pressure from BME280 - comp_temp from BME280 - humidity from BME280 - unused - should be 0 (nul) - unused - should be 0 (nul) The response for the "get compensation data" request has to be defined. To set the sensor address using a serial line from a linux host, you can use these commands (sensor connected to ttyUSB0) : # For device address 1 (0x01) : echo -ne "#\x00\x01" > /dev/ttyUSB0 # For device address 2 (0x02) : echo -ne "#\x00\x02" > /dev/ttyUSB0 # and so on ... [...] # To check what these command send if you are not sure : echo -ne "#\x00\x01" | hexdump -C When debug is set at compile time, then debug data is sent on UART0