// Test for GEVINO opto v1.2 / v1.3 / v1.4 // 07/09/2020 Giorgio Evangelista #include "gevino_opto_npn_io.h" // Install https://github.com/sandeepmistry/arduino-CAN/Also from Arduino Library Manager // Change on MCP2515.h byte MCP2515_DEFAULT_CS_PIN = 10; byte MCP2515_DEFAULT_INT_PIN = -1; #include byte CanOk = 0; // LoRa #include const int csPin = 10; // LoRa radio chip select const int resetPin = 11; // LoRa radio reset const int irqPin = -1; // change for your board; must be a hardware interrupt pin // W5500 #include #include byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192, 168, 1, 199); EthernetServer server(80); // RTC #include #include DS3231 clock; RTCDateTime dt; // TEST_SD #include File myFile; // Test DHT22 #include #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 #define DHTPIN 20 DHT dht(DHTPIN, DHTTYPE); int TestResult; void setup() { testLeds(); SerialUSB.begin(115200); while (!SerialUSB) { ; // wait for serial port to connect. Needed for native USB port only } Serial1.begin(115200); Serial.begin(115200); // while(!SerialUSB) gevino_io_setup(); // TEST_SD - Write file on SD card. TestResult = SD.begin(SD_CS); if( TestResult ) SerialUSB.println("SD OK"); else SerialUSB.println("SD FAIL"); // Test RTC TestResult = clock.begin(); TestResult = clock.isReady(); if( TestResult ) SerialUSB.println("RTC OK"); else SerialUSB.println("RTC FAIL"); // W5500 TestResult = Ethernet.begin(mac, 5000); if( TestResult ) SerialUSB.println("ETH OK"); else SerialUSB.println("ETH FAIL"); if (!CAN.begin(500E3)) SerialUSB.println("CAN FAIL"); else{ SerialUSB.println("CAN Ok"); CanOk = 1; } // LoRa at 433Mhz if (!LoRa.begin(433E6)) SerialUSB.println("LoRa FAIL"); else SerialUSB.println("LoRa OK"); gevino_io_setup(); // LoRa change In10 (D9) on output. // Test ESP Serial.println("AT"); delay(500); Serial.println("ATI"); delay(500); Serial.println("AT+GMR"); // Test SIM800 su Serial1 Serial1.println("AT"); delay(500); Serial1.println("ATI"); //Test DHT22 dht.begin(); updateDHTSensor(); } unsigned long TimerForSec; void loop() { byte tmp; if( In1 ) setLed; else resLed; if( In1 || In7 ) setOut1; else resOut1; if( In2 || In8 ) setOut2; else resOut2; if( In3 || In9 ) setOut3; else resOut3; if( In4 || In10 ) setOut4; else resOut4; if( In5 || In11 ) setOut5; else resOut5; if( In6 || In12 ) setOut6; else resOut6; if( Serial.available() ) SerialUSB.write(Serial.read()); if( Serial1.available() ) SerialUSB.write(Serial1.read()); if( SerialUSB.available()){ tmp = SerialUSB.read(); Serial.write(tmp); Serial1.write(tmp); } if( millis() - TimerForSec > 1000 ){ TimerForSec = millis(); if(CanOk){ CAN.beginPacket(0x12); CAN.write('h'); CAN.write('e'); CAN.write('l'); CAN.write('l'); CAN.write('o'); CAN.endPacket(); } } //updateDHTSensor(); } void updateDHTSensor() { //delay(1000); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); // Read temperature as Celsius (the default) float t = dht.readTemperature(); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t)) { SerialUSB.println("Failed to read from DHT sensor!"); return; } //modbusTCPServer.inputRegisterWrite(0, (int)(h * 100)); //modbusTCPServer.inputRegisterWrite(1, (int)(t * 100)); //modbusTCPServer.inputRegisterWrite(2, (int)(hic * 100)); SerialUSB.print("Humidity: "); SerialUSB.print(h); SerialUSB.print("% "); SerialUSB.println((int)(h * 100)); SerialUSB.print("Temperature: "); SerialUSB.print(t); SerialUSB.print("°C "); SerialUSB.println((int)(t * 100)); }