SHT31 + W5500 code still in the making
This commit is contained in:
parent
ec9203394a
commit
7275a716bc
@ -0,0 +1,99 @@
|
|||||||
|
// SHT31 configuration
|
||||||
|
#include "Adafruit_SHT31.h"
|
||||||
|
|
||||||
|
Adafruit_SHT31 sht31 = Adafruit_SHT31();
|
||||||
|
|
||||||
|
#define SHT31_RST_PIN 16
|
||||||
|
|
||||||
|
void resetSensor() {
|
||||||
|
pinMode(SHT31_RST_PIN, OUTPUT);
|
||||||
|
digitalWrite(SHT31_RST_PIN, LOW);
|
||||||
|
delay(10);
|
||||||
|
digitalWrite(SHT31_RST_PIN, HIGH);
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// W5500 configuration
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Ethernet3.h>
|
||||||
|
|
||||||
|
// Configure MAC address and IP:
|
||||||
|
byte mac[] = {0x61, 0x2C, 0xF2, 0x09, 0x73, 0xBE};
|
||||||
|
|
||||||
|
// the real one IPAddress ip(10, 11, 1, 22); // Static IP
|
||||||
|
|
||||||
|
|
||||||
|
// Define CS and RST pins:
|
||||||
|
#define W5500_CS_PIN 10 // 8 in E LEGO
|
||||||
|
#define W5500_RST_PIN 9 //10 in E LEGO
|
||||||
|
IPAddress serverIP(10, 44, 1, 238); // Computer
|
||||||
|
IPAddress W5500_ip(10, 11, 1, 22); // Change the last digit
|
||||||
|
|
||||||
|
// Don't change
|
||||||
|
const int port = 5005;
|
||||||
|
EthernetClient client;
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// put your setup code here, to run once:
|
||||||
|
|
||||||
|
// SHT31 First readout
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial);
|
||||||
|
Serial.println ("Looking for SHT31");
|
||||||
|
|
||||||
|
if (!sht31.begin(0X44)) {
|
||||||
|
Serial.println("Couldn't find SHT31");
|
||||||
|
while (1) delay(100);
|
||||||
|
}
|
||||||
|
Serial.println("SHT31 Found");
|
||||||
|
float t = sht31.readTemperature();
|
||||||
|
float h = sht31.readHumidity();
|
||||||
|
|
||||||
|
if (!isnan(t)) {
|
||||||
|
Serial.print("Temperature (C)= "); Serial.println(t);}
|
||||||
|
|
||||||
|
if (!isnan(h)) {
|
||||||
|
Serial.print("Humidity = "); Serial.println(h); }
|
||||||
|
|
||||||
|
|
||||||
|
// W5500 first readout
|
||||||
|
pinMode(W5500_RST_PIN, OUTPUT);
|
||||||
|
digitalWrite(W5500_RST_PIN, HIGH);
|
||||||
|
delay(250);
|
||||||
|
digitalWrite(W5500_RST_PIN, LOW);
|
||||||
|
delay(250);
|
||||||
|
digitalWrite(W5500_RST_PIN, HIGH);
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
|
// Initialize Ethernet:
|
||||||
|
Ethernet.init(W5500_CS_PIN);
|
||||||
|
Ethernet.begin(mac, W5500_ip);
|
||||||
|
delay (1500);
|
||||||
|
|
||||||
|
Serial.print("W5500 IP: ");
|
||||||
|
Serial.println(Ethernet.localIP());
|
||||||
|
|
||||||
|
// Send a message through socket
|
||||||
|
Serial.print("Sending test message");
|
||||||
|
delay (1000);
|
||||||
|
if (client.connect (serverIP, port)) {
|
||||||
|
client.write("test");
|
||||||
|
client.stop();
|
||||||
|
Serial.print("Test Message sent");
|
||||||
|
} else {
|
||||||
|
Serial.print("Connection failed");}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user