OK... Found the bug!
Library code.
Here it is...
In the x10::init() function, Bro has
// Set I/O modes:
pinMode(this->zeroCrossingPin, INPUT);
pinMode(this->dataPin, OUTPUT);
digitalWrite(this->zeroCrossingPin, HIGH);
This is apparently the OLD style of handling configing I/O as inputs with pullups. It places zeroCrossingPin to be in input mode and then the digitalWrite(, HIGH) turns on the input pull up resistor on.
But then later, he has
if (rp>0) {
pinMode(rcve_pin,INPUT); // receive X10 commands - low = 1
pinMode(zcross_pin,INPUT); // zero crossing - 60 Hz square wave
This has the effect of RESETTING the previous digitalWrite(, HIGH) to OFF and therefore No pullup applied.
First, it is a bug to have the pinMode() for that same pin twice. But worse to do it the second time without the corresponding
digitalWrite(, HIGH). Really the right way would be to do it ONCE and use the pinMode(, INPUT_PULLUP) which does both steps at once., and to only have that in once place.
The code is quite messy actually, inconsistent in use of class member values vs automatic variables, where none is needed, Plus the format is ridiculously unreadable. Are there no coding-standards for arduino code???
- No tabs.
- 4 space columns
- No unbracked if / ife-else clauses.
- no single-line if-else clauses.
- No un-debugged, or dead code
Sorry for the rant.
Now, if I can figure out the polite way to submit a cleaned up, debugged library that would be cool. And I have to understand whether a newly-submitted cleaned up librtary can be coded for 1.0.1 IDE's and later, or whether we HAVE to support pre-1.0.1 IDE's. Any suggestions welcomed. Also, I need to learn the social part of whether a newer version of library can be a fully cleaned up version, or whether only logic changes in the diffs are appreciated.
Oh Also... I was wrong about something... No opto isolator needed! Arduino digital inputs (for 5V) are NOT typical TTL levels. A logic 1 is around 2.5 V and a logic 0 is anything less than 2.1V (for 3.3 V 'duinos it appears to be around 1.75V / 1.4V respectively). So the fact that the zeroCrossing pin only goes to about 1.1V at the lowest is no bigge... It is clearly in the safe zone for a logic 0.