/*// This sketch allows manual setting of the RS485-connected pins via serial terminal commands Commands are: r+ – enable read mode (^RE ← LOW) r- – disable read mode (^RE ← HIGH) w+ – enable write mode (DE ← HIGH) w- – disable write mode (DE ← LOW) h – send HIGH level on DI l – send LOW level on DI //*/ #if defined(ARDUINO_AVR_UNO) #define RS485_RO 5 #define RS485_RE 4 #define RS485_DE 3 #define RS485_DI 2 #define BOARD "Arduino Uno" #endif #if defined(ARDUINO_AVR_NANO) #define RS485_RO 3 #define RS485_RE 2 #define RS485_DE 4 #define RS485_DI 5 #define BOARD "Arduino Nano" #endif String command = ""; bool doPrint = false; // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(RS485_RO, INPUT); pinMode(RS485_RE, OUTPUT); pinMode(RS485_DE, OUTPUT); pinMode(RS485_DI, OUTPUT); digitalWrite(RS485_RE,LOW); digitalWrite(RS485_DE,LOW); digitalWrite(RS485_DI,LOW); Serial.begin(115200); Serial.println(F("this is Projekte/Arduino/MAX485/ManualSend")); Serial.println(F("send any of the followning commands:")); Serial.println(F("- r+ (enable read)\n- r- (disable read)\n- w+ (enable write)\n- w- (disable write)\n- h (for high)\n- l (for low)")); } // the loop function runs over and over again forever void loop() { while (Serial.available()){ char inChar = (char)Serial.read(); if (inChar == '\n') { process(command); command = ""; doPrint = true; } else { command += inChar; } } if (doPrint){ printState(); delay(1000); } } void printState(){ Serial.print("RE = "); Serial.print(1-digitalRead(RS485_RE)); Serial.print(", DE = "); Serial.print(digitalRead(RS485_DE)); Serial.print(", DI = "); Serial.print(digitalRead(RS485_DI)); Serial.print(", RO = "); Serial.println(digitalRead(RS485_RO)); } void process(String command){ Serial.print(F("received:")); Serial.println(command); if (command == "r+") digitalWrite(RS485_RE,LOW); if (command == "r-") digitalWrite(RS485_RE,HIGH); if (command == "w+") digitalWrite(RS485_DE,HIGH); if (command == "w-") digitalWrite(RS485_DE,LOW); if (command == "h") digitalWrite(RS485_DI,HIGH); if (command == "l") digitalWrite(RS485_DI,LOW); printState(); }