// Test for GEVINO opto v1.2 / v1.3 / v1.4 // 07/09/2020 Giorgio Evangelista #include "gevino_opto_npn_io.h" #define RS485 Serial1 // 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[6]; IPAddress ip(192, 168, 1, 199); EthernetServer server(80); // RTC #include #include DS3231 clock; RTCDateTime dt; // For 32bit fram // https://github.com/RobTillaart/FRAM_I2C #include "FRAM.h" FRAM32 fram32; FRAM fram16; // TEST_SD #include File myFile; int TestResult; void setup() { testLeds(); SerialUSB.begin(115200); RS485.begin(115200); Serial.begin(115200); // while(!SerialUSB) gevino_io_setup(); mac[0] = 0x02; // unicast, locally administered mac[1] = (*(uint32_t *)0x0080A00C ^ *(uint32_t *)0x0080A044) & 0xFF; mac[2] = ((*(uint32_t *)0x0080A00C ^ *(uint32_t *)0x0080A048) >> 8) & 0xFF; mac[3] = ((*(uint32_t *)0x0080A040 ^ *(uint32_t *)0x0080A044) >> 16) & 0xFF; mac[4] = ((*(uint32_t *)0x0080A040 ^ *(uint32_t *)0x0080A048) >> 24) & 0xFF; mac[5] = (*(uint32_t *)0x0080A00C ^ *(uint32_t *)0x0080A040 ^ *(uint32_t *)0x0080A044 ^ *(uint32_t *)0x0080A048) & 0xFF; // Stampa il MAC address char macStr[18]; sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); SerialUSB.print("MAC Address: "); SerialUSB.println(macStr); // TEST_SD - Write file on SD card. TestResult = SD.begin(SD_CS); if( TestResult ) SerialUSB.println("SD OK"); else SerialUSB.println("SD FAIL"); myFile = SD.open("example.txt", FILE_WRITE); myFile.close(); // Test RTC TestResult = clock.begin(); TestResult = clock.isReady(); if( TestResult ) SerialUSB.println("RTC OK"); else SerialUSB.println("RTC FAIL"); // Test Fram (If before test RTC not work) byte i32 = fram32.begin(0x50); byte i16 = fram16.begin(0x50); if (!i32){ SerialUSB.println("Found 32bit I2C FRAM"); }else if (!i16){ SerialUSB.println("Found 16bit I2C FRAM"); }else{ SerialUSB.println("Not Found I2C FRAM"); } // W5500 Ethernet.init(ETH_CS); 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 RS485.println("AT"); delay(500); RS485.println("ATI"); } 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( RS485.available() ) SerialUSB.write(RS485.read()); if( SerialUSB.available()){ set_Rs485_TxEn; tmp = SerialUSB.read(); Serial.write(tmp); RS485.write(tmp); } if (SERCOM0->USART.INTFLAG.bit.TXC){ //Remove Tx Enable when the last character has been sent out. res_Rs485_TxEn; SERCOM0->USART.INTFLAG.bit.TXC = 1; } 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(); } } }