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' : all - request to send all available sensor data to host. - 'l' : set led color - set the sensor led color. Three bytes of data (RGB). It is also possible to broadcast a message to all sensors by sending to address 255 (0xFF) 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