Hey Rob,
I greatly appreciate that you’re taking the time to help me, especially with some thoughts on the code. As I understand his code better, I’ve started to think too that it might be more complicated than needed. I’m not as skilled a programmer though to know how to simplify it so easily. I did try some, but wasn’t met with complete success.
This morning I put together some photos to show you to help you understand the setup and what’s going on. After I read your reply last night, I did some further test and made some interesting observations. The problems I have with his code, they seem inconsistent in how they malfunction, and I’m not sure why that is. I do change things around a lot as I go though, so that’s likely a cause.
So, firstly some images, and then I’ll give some thoughts.
This is the setup I have. The CS2 is the controller, up in the right you can see a real S88. It connects via a ribbon cable. Below I have my Arduin which I’ve connected with jumper cables.
This is one of the switches. It’s directional and has two outputs.
They don’t have documentation that explains these settings, but I think they relate to the clock and load. I’d venture to guess that the interval is the clock intervals and that the query is the load intervals.
This shows what I see on the screen. With his code it’ll switch back and forth between the first and the second, so the bits get shifted over. They’re being shifted to the right.
Okay, so that’s the images.
Changing the S88 Interval and S88 Interval Query settings affects it. I had problems with it crashing when I used faster values. That was with the Arduino attached, with a real S88 it doesn’t cause such issues. I’ve also had issues where it causes the system to slow down, or hang. I’m not sure why though. If I select slower values, it seems to work better.
I did get his code working, but I couldn’t do it with 10 shift registers like he had, I had to cut it down to only 2 and it’d start working then. If there was any more than that, it’d start shifting one over, back and forth. It’s weird, it’s behaving differently than it did the other day. The other day the shift was slow, it’d be 10-20 seconds between the shifts. Also, it did it regardless if I had 10 shift registers or just one. Last night, it’d do it immediately. Maybe that’s why it was causing it to crash? It couldn’t handle having so many inputs change so quickly at the same time? I don’t know. At faster settings, it’ll shift one bit over, at slower settings it seems to work like it should.
I wish I could give a better explanation. I kind of threw this information together in a rush as I was getting ready for work.
The S88DATAIN isn’t being utilized. I don’t know if it needs to be. For completeness sake, I guess one would want to implement it. The Data out of a real S88 would connect into the S88DATAIN on the Arduino. Or, another Arduino could be connected.
S88DATAOUT is sending the data to the CS2. The CS2 controls the S88Clock and S88LOAD.
I have to read through it again, so I’m not sure if I’m correct in this statement. I believe what’s happening is that a signal gets sent over S88LOAD, which causes the 4014N Shift Register chip to load in the data that’s being stored in the 4044N chips. At some point here, after it’s loaded, it sends a signal down the Reset line that causes the 4044N chips to reset and wait for new input. The Data is shifted down the line towards the controller, the CS2 in this case. And after that, it starts all over again.
So in GuyA’s code, in the Load function, it’s loading the data into the shiftregisters. On the Clock function, it’s shifting it down. The LOAD Function will get called once, at the start, and then the Clock function will get called until all the data has been loaded in. I’m guessing the Clock function will trigger 64 times (the limit to the amount of modules that the CS2 supports), before it triggers the load signal again.
I believe on the real S88, when it sends data to the CS2, it’s only sending 8 bits at a time. Makes sense. There’s two shift register chips in the S88, but the data from one chip is being sent to the CS2, while the data from the other chip is being loaded into the first chip, so it can be sent down the line. In GuyA’s code, he’s sending 16 bits with each shift.
Thanks again for the help. I’m trying hard to wrap my head around everything.
Someone made a sketch for an Arduino that can pull in input from an S88. I’d venture to say you don’t have the hardware I do (The CS2, or other similar device), but if you’re curious to see if your code works, you could do it with two Arduinos. The railunio library has the ability to interface with the S88 modules. Below is a link to the code, and a link to Desktop Station, a program you could use to monitor the inputs. They interface with Marklin’s system via Can-Bus, but that’s not needed for the S88 connection.
In this setup, you’d have an Arduino with Railunio acting as the controller, in place of a CS2 (Like I have). On a second Arduino, you could load in GuyA’s code and see what happens.
https://code.google.com/p/railuino/
http://yaasan.mints.ne.jp/index.html
http://yaasan.mints.ne.jp/ready.html#S88 <-- the information for connecting the S88.
I understand you’re helping me out of kindness, and if you’re anything like me, you’re wall to wall busy as it is. So, because of that, I don’t expect you to go through the trouble of dealing with setting up a couple of Arduinos to help work out some of the code. I provide that information for information’s sake. The thoughts you’ve provided and your first snippet of code has provided me a lot to think about and has helped my understanding greatly. I think my greatest limitation right now is my limited programming knowledge.
Just a FYI, in case you’re curious. The reason I’m doing this is a two part problem. The first is that it’s difficult to find S88 modules in the states. They’re usually pretty expensive too, more so than I think they should be considering how basic they are. The second is that I want to build a wireless system up around it so I don’t have to run cables all over the place.
The added benefit is that I can write conditional state information into it, so I can have more complex triggers than I’m afforded with using the standard system. I could, in theory, handle that part through the use of a computer and software that is freely available, but I’m also very keen on not having to connect to a computer. It’s all about having as compact and contained of a system as I can get. It’s also about reducing the wires to as few as I can get away with.