Вы находитесь на странице: 1из 8
10672015 atuinonfo- SefwareSeridRSABSExample SoftwareSerialRS485Example (/SoftwareSerialRS485Example) # Edit ® 0 (/SoftwareSerialRS485Example#discussion) © 13 (/page/history/SoftwareSerialRS485Example) . (ipage/menu/SoftwareSerialRS485Example) SoftwareSerialRS485Example RS485 isa physical connection standard for Serial data transfer. It can be used ipssiard.ino-irfomikspaces.com/SotwareSerialRS485Exarle 8 sas2015 sr fidefine SSerialRX 18 //Serial Receive pin fidefine SSerialTX 11 //Serial Transmit pin ipssitard.ino-irfomikspaces.com/SowareSerialRSA85Exar ple 101820°5 atuinonfo- SefwareSeridRSABSExample fidefine SSerialTxControl 3 //RS485 Direction control fidefine RS485Transmit HIGH fidefine RS485Receive LOW. fidefine Pini3LED B [*-----( Declare objects )-----*/ SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX /*-----( Declare Variables )- int byteReceived; int byteSend; +) void setup() /****** SETUP: RUNS ONCE *****#/ t // Start the built-in serial port, probably to Serial Monitor Serial.begin(3600) ; Serial.print1n("YourDuino.com SoftwareSerial remote loop example"); Serial.println("Use Serial Monitor, type in upper window, ENTER"); pinMode(Pin13LED, OUTPUT); pinMode(SSerialTxControl, OUTPUT); digitalwrite(sserialTxControl, RS485Receive); // Init Transceiver // Start the software serial port, to another device RS485Serial.begin(48e8); // set the data rate }//--(end setup )--- void loop() /*#**** LOOP: RUNS CONSTANTLY *###**/ t digitalWrite(Pin13LED, HIGH); // Show activity if (Serial.available()) { bytereceived Serial.read(); digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit Rs4a5Serial .write(byteReceived) ; // Send byte to Remote Arduino digitalWrite(Pin13LeD, LOW); // Show activity delay(10); digitalWrite(sSerialTxControl, RS485Receive); // Disable RS485 Transmit if (RS485Serial.available()) //Look for data from other Arduino ipssitard.ino-irfomikspaces.com/SowareSerialRSA85Exar ple 101820°5 atuinonfo- SefwareSeridRSABSExample digitalWrite(Pin13LeD, HIGH); // Show activity byteReceived = RS4asserial.read(); // Read received byte Serial write(byteReceived); // Show on Serial Monitor delay(1@); digitalWrite(Pin13LeD, LO); // Show activity ? }//--(end main loop )--- -( Declare User-written Functions ) You are not a member ofthis wiki. Join now (hitpsiarduino- info wtigpaces convspacefoin) Dismiss //#eeeeeeRe( THE END eet tte eeee ee Remote Arduino Sketch: 7* YourDuino SoftwareSerialExampleiRenote - Used with YD_SoftwareSerialexampleRS485_1 on another Arduino = Remote: Receive data, loop it back... - Connect this unit Pins 10, 11, Gnd - To other unit Pins 11,10, Gnd (Cross over) - Pin 3 used for RS485 direction control - Pin 13 LED blinks when data is received Questions: terry@yourduino.com +" /*-----( Inport needed Libraries ) include /*-----( Declare Constants and Pin Numbers ) define sserialRx 10 //Serial Receive pin ‘define sserialtx 11 //Serial Transmit pin */ */ fidefine SSerialTxcontrol 3 //RS485 Direction control fidefine RS485STransmit HIGH define RSAB5Receive LOW define Pini3LED B /*-----( Declare objects )-----*/ ipssitard.ino-irfomikspaces.com/SowareSerialRSA85Exar ple 101820°5 atuinonfo- SefwareSeridRSABSExample SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX /*-----( Declare Variables )-----*/ int byteReceived; int byteSend; Void setup() /*#**** SETUP: RUNS ONCE **=*54/ { // Start the built-in serial port, probably to Serial Nonitor Serial .begin(3600); Serial.println("SerialRemot // Can be ignored pinMode(Pin13LED, OUTPUT); pinMode(sSerialTxControl, OUTPUT); digitalwrite(sserialTxControl, RS485Receive); // Init Transceiver // Start the software serial port, to another device RS485Serial.begin(48e0); // set the data rate W/--(end setup )--- void loop() — /*##*** LOOP: RUNS CONSTANTLY *####*/ { 7/Copy input data to output if (RS485Serial.available()) { byteSend = Rs485Serial.read(); // Read the byte digitalWrite(Pin13LeD, HIGH); // Show activity delay(10); digitalWrite(Pin13LED, LOW); digitalwrite(sserialTxControl, RS4a5Transmit); // Enable RS485 Transmit RSaBsserial.write(byteSend); // Send the byte back delay (10); digitalWrite(sserialTxControl, RS4a5Receive); // Disable RS485 Transmit JJ delay(188); J// End TF RS485SerialAvailable W/--(end main loop )--~ I* ZINONE ( Declare User-written Functions ) J /#eeeseee( THE END )eettEEESe ipssitard.ino-irfomikspaces.com/SowareSerialRSA85Exar ple 718 101820°5 atuinonfo- SefwareSeridRSABSExample Help « About - Blog « Pricing : Privacy - Terms - Support Contributions to https://arduino-info.wikispaces.com/ are licensed under a Creative Commons Attribution Non-Commercial 3.0 License. Portions not contributed by visitors are Copyright 2015 Tangient LLC ipssiard.ino-irfomikspaces.com/SotwareSerialRS485Exarle

Вам также может понравиться