Last active
February 20, 2019 07:46
-
-
Save jscrane/8434935 to your computer and use it in GitHub Desktop.
Sketch to test a TinySensor and commission it by setting its node-id in EEPROM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.lib | |
*.cpp.o | |
*.ino.bin | |
*.ino.elf | |
*.eep | |
.*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BOARD := t84db | |
include arduino-tiny.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <RF24.h> | |
#include <DHT.h> | |
#include <EEPROM.h> | |
#include <SoftwareSerial.h> | |
/* | |
const uint8_t DHT_PIN = 8; | |
const int RX_PIN = 1, TX_PIN = 0; | |
*/ | |
const uint8_t DHT_PIN = 2; | |
const uint8_t RX_PIN = 9, TX_PIN = 10; | |
const uint8_t CE_PIN = 8, CS_PIN = 7; | |
RF24 radio(CE_PIN, CS_PIN); | |
DHT dht; | |
SoftwareSerial serial(RX_PIN, TX_PIN); | |
void setup(void) | |
{ | |
pinMode(RX_PIN, INPUT); | |
pinMode(TX_PIN, OUTPUT); | |
pinMode(A1, INPUT_PULLUP); | |
dht.setup(DHT_PIN); | |
SPI.begin(); | |
radio.begin(); | |
serial.begin(9600); | |
serial.print(F("retries: ")); | |
serial.println(radio.getRetries(), 16); | |
serial.println(F("Sensor Test. Enter node-id and hit return.")); | |
serial.println(F("Status\tHumidity\tTemperature\tLight\tBattery\tID")); | |
} | |
void loop(void) | |
{ | |
uint8_t light = 255 - analogRead(A1) / 4; | |
serial.print(dht.getStatus()); | |
serial.print(F("\t")); | |
serial.print(dht.getHumidity()); | |
serial.print(F("\t\t")); | |
serial.print(dht.getTemperature()); | |
serial.print(F("\t\t")); | |
serial.print((int)light); | |
serial.print(F("\t")); | |
serial.print(analogRead(A0)); | |
serial.print(F("\t")); | |
serial.println(EEPROM.read(0)); | |
uint8_t id = 0; | |
while (serial.available()) { | |
int ch = serial.read(); | |
if (ch == '\n') | |
EEPROM.write(0, id); | |
else if (ch >= '0' && ch < '8') | |
id = (id << 3) | (ch - '0'); | |
} | |
delay(dht.getMinimumSamplingPeriod()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment