Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to Modbus an AltSoftSerial "flush" or "end" function, to set pins low #140

Closed
aufdenkampe opened this issue May 4, 2018 · 5 comments

Comments

@aufdenkampe
Copy link
Member

aufdenkampe commented May 4, 2018

The problem is that when AltSoftSerial pins 5 & 6 are left HIGH, and power is shut down to our RS485 converter, there seems to be a bleed of 2.28V into the switched power lines.

Because Modbus Stop bits are HIGH, these pins are always left HIGH when the sensors shut down.

Let's figure out a way to get them to set low, before the power shuts down.

Unfortunately, if I set the pins to low in the loop using the following statements, then the AltSoftSerial streams seem to get shut down and I don't get any Modbus data.

    digitalWrite(5, LOW);   // Reset AltSoftSerial Tx pin to low, because Modbus Stop bit is HIGH
    digitalWrite(6, LOW);   // Reset AltSoftSerial Rx pin to low, because Modbus Stop bit is HIGH

Note that these statements kill the AltSoftSerial regardless of whether I put them before or after the EnviroDIYLogger.systemSleep() function.

@aufdenkampe
Copy link
Member Author

AltSoftSerial has flushInput(), flushOutput(), and end() functions, but I'm not sure they do what we want them to do. @SRGDamia1, any wisdom?
https://github.com/PaulStoffregen/AltSoftSerial/blob/master/AltSoftSerial.cpp

Would we put these statements at the end of the sleep() functions for the Yosemitech & Keller parent .cpp files?

@SRGDamia1
Copy link
Contributor

We can't put the functions in the Yosemitech/Keller files because they take an input of a "stream" not an AltSoftSerial. The begin and end functions are from serial objects, not their parent streams. Those two flush functions are fairly unique to AltSoftSerial. I definitely do not want to force people to use AltSoftSerial; I want people to have the option of any type of stream they want (ie, HardwareSerial, SoftwareSerial, NeoSWSerial, etc).

I'm guessing that when you set the pins low, it also deactivates the capture/compare functions on the pins that AltSoftSerial depends on. That's also what the end function explicitly does, along with running both flushes. (Though I'm not sure if the pins go low after being deactivated.) Try moving the begin function for AltSoftSerial from you setup() to the start of your loop so it can regain control of the pins again at the start of each loop.

@SRGDamia1
Copy link
Contributor

Did adding the begin for AltSoftSerial to the start of the loop work?

@aufdenkampe
Copy link
Member Author

aufdenkampe commented May 16, 2018

@SRGDamia1, your idea worked!

I expanded out the EnviroDIYLogger.log() function (see LoggerEnviroDIY.cpp for code in that function), as was done in baro_rho_correction.ino and still in data_saving.ino examples.

I then added this line:

    // Restart the stream for the modbus sensors, because we set pins LOW, below
    modbusSerial.begin(9600);

just before:

    // Send power to all of the sensors
    EnviroDIYLogger.sensorsPowerUp();

Also, just after this:

    EnviroDIYLogger.sensorsPowerDown();

I added

    // Reset AltSoftSerial pins to LOW, to reduce power bleed on sleep, 
    // because Modbus Stop bit leaves these pins HIGH
    digitalWrite(5, LOW);   // Reset AltSoftSerial Tx pin to LOW
    digitalWrite(6, LOW);   // Reset AltSoftSerial Rx pin to LOW

Power saving accomplished!
This should address one of the two issues in #148.

@SRGDamia1
Copy link
Contributor

Great! I'm looking into the I2C problem. It looks like dallasTemp/one wire already explicitly leaves the data pin low at the end, so that does not need improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants