Home › Forums › Mayfly Data Logger › RS485 without auto direction control › Reply To: RS485 without auto direction control
I have ordered a module with automatic flow c
I have ordered a module with automatic flow control from Amazon but I didn’t want to wait for it to arrive so I started with what I had.
The module I have has been working nicely before but this time I can’t get it to work. In the past the timing turning the Enable pin low has been tricky for me. For simple programs I’ve used delays but I tried something like Nick Gammon’s solution under “Flushing the output” RS485 communications. But not in this case.
I using the “logging_to_ThingSpeak”-example with one Yosemitech Y504, AltSoftSerial (pins 5&6) and RE/DE on pin 4.
On my module the RE/DE are coupled together so you only need one pin. The restart happens even if I disconnect everything from the Mayfly logger. And the only way to stop it from happen is to set the “max485EnablePin” to -1. I will try some more examples to see if I can get it right with my coding.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
// ========================================================================== // Settings for Additional Serial Ports // ========================================================================== // AltSoftSerial by Paul Stoffregen (https://github.com/PaulStoffregen/AltSoftSerial) // is the most accurate software serial port for AVR boards. // AltSoftSerial can only be used on one set of pins on each board so only one // AltSoftSerial port can be used. // Not all AVR boards are supported by AltSoftSerial. #include <AltSoftSerial.h> AltSoftSerial altSoftSerial; // ========================================================================== // Yosemitech Y504 Dissolved Oxygen Sensor // ========================================================================== #include <sensors/YosemitechY504.h> // Create a reference to the serial port for modbus // Extra hardware and software serial ports are created in the "Settings for Additional Serial Ports" section #if defined ARDUINO_ARCH_SAMD || defined ATMEGA2560 HardwareSerial &modbusSerial = Serial2; // Use hardware serial if possible #else AltSoftSerial &modbusSerial = altSoftSerial; // For software serial if needed // // NeoSWSerial &modbusSerial = neoSSerial1; // For software serial if needed #endif byte y504ModbusAddress1 = 0x01; // The modbus address of the Y504 //byte y504ModbusAddress2 = 0x05; // The modbus address of the Y504 const int8_t rs485AdapterPower = sensorPowerPin; // Pin to switch RS485 adapter power on and off (-1 if unconnected) const int8_t modbusSensorPower = -1; // Pin to switch sensor power on and off (-1 if unconnected) TODO Change pin const int8_t max485EnablePin = -1; // Pin connected to the RE/DE on the 485 chip (-1 if unconnected) const uint8_t y504NumberReadings = 10; // The manufacturer recommends averaging 10 readings, but we take 5 to minimize power consumption // Create a Yosemitech Y504 dissolved oxygen sensor object YosemitechY504 y504_1(y504ModbusAddress1, modbusSerial, rs485AdapterPower, modbusSensorPower, max485EnablePin, y504NumberReadings); //YosemitechY504 y504_2(y504ModbusAddress2, modbusSerial, rs485AdapterPower, modbusSensorPower, max485EnablePin, y504NumberReadings); |