BROHogan's X-10 Receive code is NON-FUNCTIONAL

I would also like to confirm what anothe poster found.. that BROHogan's code DOES NOT WORK to receive X10 commands with a known-working PSC05 and known working TW523. I'm using a 16 Mhz Arduino Nano.

http://playground.arduino.cc/X10/ReceiveX10

SIgnals are plenty strong, I see pulses received on D4 (which is the default-assigned Rx Data pin) and the 60 HZ square wave for ZeroCrossing pin D2

One thing I noticed is that the ZC line does not drop below 1.1V . This is not a happy state. I've put in a Opto Isolator and the D2 (Zero Crossing) is now a perfect .2 to ~5V... It is in perfect phase with the original.

Either way... This code is NOT WORKING to receive X-10 signals. It DOES work Sending, however.

User BEWARE.

I'll probably try the X10 CM11A next.

Has anyone had any different results?

-A

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???

  1. No tabs.
  2. 4 space columns
  3. No unbracked if / ife-else clauses.
  4. no single-line if-else clauses.
  5. 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.

Oh my ears!

I didn't write the lib you mention.
I wrote the code that is listed in the Playground. It was later turned into a lib.

That code was functional when I posted it, and IIRC, the lib written by "creatrope" was too.
In that light, I'm not sure any of your 5 points apply to what I wrote, but frankly Scarlet . . .

Back then (2009) I worked darned hard on that receive routine. I don't expect any thanks, but geez!

Based on the tone of your post I find it a bit ironic that you are looking for a "polite way" to submit a new version.
However, unless it's changed, as a member you should be able to post to the Playground.

John