You're reading ...
Hardware, Software

Arduino used as an S88 occupancy detector board

Past week the Arduino came in. It was kinda funny. I had ordered it at Aliexpress, together with a bunch of additional stuff like sensors, servo’s, breadboards, wires.  Good prices, but not known for the speediest China mail delivery. When it still had not arrived after 2 weeks I used the tracking code. The first few days the package had been on the move, but it seemed it was stuck now in Canada (!?), for 1.5 weeks already. After waiting another week I decided to email the shop. They replied they would look into it. That same day … guess what … the package arrived! Hehe, need to be a bit more patient … I sent out my email just one day too soon 🙂

ArduinoUnoSmdArduino is fun. To get to grips with the IDE, I tried out the usual suspects: led-blink, servo motor sweep, ultrasound distance measurement, IR-sensor. All works great.

What I plan to use it for is to serve as a DCC servo decoder to switch junctions and as an S88 sensor board for occupancy detection. Why? You might ask since those are readily available boards. True, but I just like to see if I can get this to work. If it works … it is a lot cheaper. An average 4x DCC servo decoder or 16x S88 detector boards sets you back some €40,-, while an Arduino is only €6,-!

So … on to try out the DCC monitor that was created by ‘mynabay’. Unfortunately that did not work. Seems the optocoupler I used is too slow. I have some speedier ones on order now. This project is on hold till those arrive.

On to the other project … the Arduino as an S88 occupancy detector. I tried to find some readily available code on the internet. Could not find anything working so I wrote some code myself. It’s working, for the time being as a stand alone 16x detector. Still have to add some software to be able to ‘chain’ multiple Arduino’s such that more than 16 (max 512) sensors can be read out.

For those interested, more details and the download link can be found on the software page.

Advertisements

Discussion

37 thoughts on “Arduino used as an S88 occupancy detector board

  1. Hello Ruud.
    How can i make your solution work if i want to use marklin K rail. For detection i want to use a piece of the rail. so no reed or IR detection. When a marklin loc or wagon enters the block it makes contact to the other rail (Gnd detection). However if i do that with the ecos and the arduino it does not work. if i make contact from an arduino pin to Gnd it does work on ECOS. I think the ECOS gnd is opto islated. but if i make an additional gnd from rail to 1st arduino it normally should work but it does not. any ideas…
    thank you
    danny

    Like

    Posted by Danny Blomme | April 30, 2018, 19:31
    • The ECoS S88 power and GND is indeed a completely isolated separate system. If you connect your rail to the S88 Arduino for GND detection, you should connect your other rail to the Arduino GND … such that it sees a connection between the 2 rails as a logical “0”.

      Like

      Posted by RudyB | May 3, 2018, 10:32
      • Hi Ruud, Yes that’s what i did but the ecos is not detecting it. i measure 5V between the 2 rails, So Arduino pin is high, when i put wagon on the rail i meaure 0V. So that”s ok. However th ecos is behaving strangely. With a high signal on Arduino pin the ECOs shows detection whereas it should not show anything. I did put pin12 to GND. i tried with several arduinos uno and nanos. Is there a possibility for you to try this out. Al you need is a piece of track to isolate from Gnd. thanks a lot. regards Danny

        Like

        Posted by Danny Blomme | May 10, 2018, 07:56
      • I can’t try it out cause over here everything works fine. If the Arduino input goes low then the signal shows on the ECoS. Forget the rails for a while … detach your rails and do a simple test: connect the Arduino to the ECoS S88 bus and by hand, with a short wire, one by one connect inputs to GND … does that show on the ECoS? If not, then something is wrong, but it is hard to tell from a distance what it is.

        Like

        Posted by RudyB | May 10, 2018, 08:09
  2. Dear Rudy, good afernoon,

    Just want to thank you for posting all the information and videos. I’ve just finished trying the Arduino, as an S88, with my Märklin CS2, and it works perfectly!

    I had some issues in finding the right pin configuration for CS2, as I was not sure if it was the same as ECOs, but after watching your videos and searching for some pictures on the web, finally I figured it out, and it’s working.

    Once again, thank you for your generous contribution.

    Best wishes,

    Antonio Lopes

    Like

    Posted by Antonio Setas Lopes | December 17, 2016, 14:50
  3. Best Wishes From India!!
    Sir,I am using Fleischmann Twin Center.
    As I am not good in Computer possible for you to make a couple of Arduino track detectors 16 tracks each and sell it to me for any value you deem fit,I will be happy,because every time I buy from Germany it costs me lots of money.
    Please let me know sir.
    I am always watching your tutorials in YouTube for train controllers.
    Please make a video on Macro sir,I am very confused about making macro and using it!!
    Always following you Sir

    Like

    Posted by Edward | February 20, 2016, 05:44
    • I’m sorry Edward but I can’t accommodate you in this. I bet it should be possible to buy Arduino’s at low price at Aliexpress and have them shipped to you? All you need to do then is download and install the Arduino IDE software and then uploed the S88 program to the Arduino.

      Like

      Posted by RudyB | February 20, 2016, 08:50
  4. Hallo Ruud,

    today I tried to chain 2 Arduinos, 1 x Arduino Duemillanove with AT168 and 1 x Arduino Uno with AT328.
    When I connect this to my Intellibox IR, each one alone works perfect.
    But when I put the Pin13 of 2nd one to Pin12 of 1st one I don`t see any detection when I change to S88 Adress 2
    of 2nd one.

    My questions are as follows:
    -might the reason be the 2 different Arduinos?
    -might the reason be the Intellibox?

    Is there any other possibility?

    When I put the Inputs on GND I can see that LED13 is flickering, so it seems each one is detecting, but only 1st one supplys to Intellibox.

    Thanks in advance for help.

    Carl

    Like

    Posted by Carl Jaeger | February 16, 2016, 19:35
    • It’s hard to tell. Can’t be the software, I have three uno’s chained here and all works well. What I found though is for it to work well is to GND the pin 12 input on the last arduino in the chain. I hope that you feed all the S88 signals to both arduino’s? They both need the S88 clock and reset of course. Also, using differnt kinds of Arduino may lead to problems with the interrupt routine. Not all types have INT 0 (which is used here) at the same pin (with uno that is pin 2). Also not all command Stations have similar timimg for S88. In the software there is a line that gives an option for tinkering with a timing, you may want to play with that a bit to see what value works best.

      Like

      Posted by RudyB | February 16, 2016, 20:33
  5. Hi Rudy I’ve found your articles to be a great inspiration in experimenting with electronics and the Arduino.

    I’m hoping to detect block occupancy by detecting the current flow on a section of isolated track. Can the Arduino inputs be connected directly to the isolated track or will it be fried by the higher track voltages?

    Is there anyway of doing it, for someone like me who knows very little about electronics?

    Like

    Posted by orandaadnaro | February 7, 2016, 21:19
    • O no … don’t connect the Arduino to the track! If you want to detect via current sensing, additional circuitry is needed. You may want to do some googling on that, there are circuits floating around on the internet. Personally I find the ise of reed contacts and a small magnet under the train more convenient, but that is a matter of taste and maybe of requirements.

      Like

      Posted by RudyB | February 7, 2016, 21:36
      • Ok. so the Arduino can’t connect directly to track current. Thanks thats saved me zapping one of my Uno clones

        Is that where the Märklin 60881 differs from the Arduino? In the 60881 product pdf there is a diagram with shows direct connection between it and the track.

        Like

        Posted by orandaadnaro | February 8, 2016, 16:09
      • Any detection module that connects directly to the track has the current sensong electronics on board. Probably with the module you mention you’ll see that you also have to feed DCC to the module.

        Like

        Posted by RudyB | February 8, 2016, 17:53
  6. Hi Rudy… just doing the math here, as I would like to simulate the s88 as well. You say “If it works … it is a lot cheaper. An average 4x DCC servo decoder or 16x S88 detector boards sets you back some €40,-, while an Arduino is only €6,-!” … How many feedback points can the Arduino handle? If it can only handle 1 or 2 then the s88 is cheaper, if it does 3 or more then it is cheaper… I am guessing it does more, but am interested in the maximum it can do and function at optimal output.
    Thanks for posting this!

    Like

    Posted by Mark Philip Venema | January 30, 2016, 00:03
    • Ok… sorry I was not reading closely enough and jumped the gun. You said 16x but are working on chaining them for more… say 256. Please delete my comments. Would be good to hear your update though and I am now following your post. Nonetheless, I’d prefer a delete on the comments. Thanks!

      Like

      Posted by Mark Philip Venema | January 30, 2016, 00:09
      • I see you’ve figured it out. The good news is … an Arduino can be had for just as low as $3,- by now! 16 S88 inputs for that price is unbeatable! I have it running for a year now … never had any missed sensing.

        Like

        Posted by RudyB | January 30, 2016, 11:45
  7. Hi Rudy,

    Yes, that was it. The CH341 driver did install now.
    It last I can start with my train projects.

    Like

    Posted by joop | January 26, 2016, 19:40
  8. Hi Rudy,

    I would like to do some of the Arduino projects you have discribed on these pages.
    So I did orde Arduino at AliExpress (they arrived within 2 weeks).
    But I cant get them working with the IDE of Arduino, it seems that the drivers do not recognize the Arduino.
    I tried all the installation descriptions, but so far no progress (windows 8).
    Could you tell how you did the succeed in getting the Arduino working?
    Thanks,
    Joop

    Like

    Posted by joop | January 24, 2016, 19:51
  9. You probably need to install the proper drivers for the USB-serial chip on the Arduino. Chances are this is the CH341. Just Google for CH341 drivers, there are quite a few downloads available. Don’t forget to do a virus check, you never know which sources are trusted and which not.

    Like

    Posted by Norber | January 14, 2016, 12:53
  10. Hello again,

    Do you know if this will work with the R-Bus (feedback) of the z21 (white) and should I use some kind of cable adapter usb to rj11?

    Now I have a roco 10787 feedback module but I am considering changing to Arduino.

    Thank you,
    Lucian

    Like

    Posted by Lucian | September 17, 2015, 17:18
    • Some kind of s88 / Xnet or Rnet adapter will be needed, the Arduino needs the standard S88 clock and PS pulses to function. Best do some Google search on this … there are plenty of z21 users who faced the same question: how to get S88 connected to z21.

      Like

      Posted by RudyB | September 17, 2015, 18:52
      • Hello Rudy,

        Thank you very much.
        I found only one solution actually, I’m posting here so others who face the same issue may see it.
        The occupancy detector DR4088RB from Dutch company Digikeijs is working with the R-bus of the white z21.
        It replicates the functionality of the Roco 10787 occupancy detector and is actually setup in the same way.
        It has an input for other DR4088RB devices connected in chain but it also has an input for the regular S88 occupancy detectors.
        I’ve connected the Arduino to the DR4088RB S88 connection and then I set it up according to DR4088RB’s manual, using it’s programing button and the z21 maintenance program for Windows. After the setup, the DR4088RB is recognized as a 10787 and the other Arduino S88s are recognized as additional 10787 feedback modules.

        It works great and I can combine block detection with reed or IR switches.

        Thank you,
        Lucian

        Like

        Posted by Lucian | October 30, 2015, 20:23
  11. Great work Rudy!
    I’m taking it as a starting point for my project. Thanks a lot!

    Currently testing your software in my layout, some problem’s appeared. I have 4 feedback modules in a S88 chain for 64 sensors and the new Arduino module is inserted in first place, that is, just between the S88 interface (home made, XpressNet compatible) and the first existing feedback module. Everything goes fine, with the exception of the first Arduino sensor (attached to A0 pin): when triggered LOW it results in two occupancy sensors activated at once in the computer. To be more precise:

    When Arduino A0 pin goes LOW, sensor 512 in RocRail flashes randomly, and sensor 513 goes active. It would rather be that 512 goes on and 513 remains unaffected. If Arduino A1 goes LOW then RocRail 514 sensor goes on, instead of 513, and works as expected. And the same for the rest of the series of sensors: all work right but are shifted one place in the usual order. And the problem is apparently caused by the first sensor of all.

    Have you seen such behaviour? Any hint on what’s wrong?
    Thank you very much.

    Like

    Posted by Norber | August 12, 2015, 15:27
    • Hi Norber. Well, the positive is that you have it almost working. I never saw the behavior you described. What I have seen happen is an issue with the ECoS that at startup the first 8 sensores lghtup, while not trggered. Thos was solved by a sort of startup timer in the sofwrae, that maybe you don’t need and could throw away. Also I found that it helps for stability and avoid strange effects when the DATA in of the finale Arduino in the chain is held to GND. Can’t explain why it would do anything, but I have seen it work here at my own layout.

      Then your issue … mabe you could tune the delay timer in the software a bit? Try some lower and some higher values and see if it makes a difference? Your S88 interface is ‘home made’, maybe the timing of the clock and reset pulses is a bit different than the current Arduino software expects?

      Like

      Posted by RudyB | August 12, 2015, 17:00
      • Hello Rudy:
        1. With my GenLiS88 interface and RocRail there were no need for the trick you made at startup (ECos issue) so I got ride of it in my code.
        2. I’ve tried to tune the delayMicroseconds(16); as you suggested, but nothing changed.
        3. PS and CLOCK are handled by interruptions, so timing should not be an issue…
        4. The most significant modification in my code is that I wanted to free pin2 for other uses, so I’m handling PS through a pinChange interruption on pin4. Let me go back to your original code an see what happens.
        I’ll let you know.

        Like

        Posted by Norber | August 12, 2015, 18:32
      • Hello again Rudy:

        Your software, as is, works perfectly well with my GenLiS88 XpressNetPC interface. I’ve condensed / optimized the code a bit and it’s still OK.
        So the problem I was encountering comes from the usage of pinChange interrupt on pin4 (my amendments) instead of externalInterrupt on pin2 (your original software). But I really need to free up this pin2 as I intend to control DCC through pin2. My plan is to fusion a S88 feeedback module with your DCC function/servo decoder in the same Arduino Nano… In short, I’m preparing an “universal” circuit to cover all the needs for a modular layout: 8 occupancy sensors, 6 signals or servos, S88, XpressNet and DCC buses, 12V and 5V dc. The idea is to have one of these “universal” circuits under each module of a modular layout, and link them in a chain using a 10 wire “universal” bus. The same would apply to any layout of course, even not modular.

        Like

        Posted by Norber | August 13, 2015, 09:46
      • OK, good to know that the S88 is working. Your plan to combine the DCC and S88, it sounds like a challenge. Personally I wouldn’t try it, since both depend on interrupts and timing, things may easily start to conflict. Why not use 2 Arduino’s per module? They set you back only some $3,-.

        Like

        Posted by RudyB | August 13, 2015, 10:14
      • Now my software works too! It just needed a minor adjustment: the pinChange interruption routine was reacting not only when LOAD_PS signal goes ON (good), but also a few µs after when the signal goes OFF (bad). A little if() and it’s solved. I’ll be glad to share my code, (well, not my code, our code). Just tell me how.

        And yes, I must confront some big problem of timing and interrupt conflicts in the next few days. But I’ll do my best to solve it.

        Thanks again Rudy! You made me start!

        Like

        Posted by Norber | August 13, 2015, 13:15
      • After some day’s trying, I’m about to give up. DCC_decoder library is apparently demanding too many resources from Arduino. In addition to Servo library, which uses many Timer interruptions, there’s no room for S88 LOAD_PS and CLOCK interruptions. What I get is that since the moment I plug the Clock signal in, the Arduino won’t react to DCC any more and the servos start jittering. Even the S88 feedback gets distorted…

        That leads me towards using two independent cheap-µcontrolers instead of only one, as you suggested. I’m thinking on it.

        Like

        Posted by Norber | August 17, 2015, 13:20
      • I’m sorry to hear it didn’t work out. Both the DCC and the S88 have need for some precise timing with their interrupts, they probably mess up each other. Well, a separate S88 Arduino per module would not be too bad an investment I gueess? I don’t know of any alternative that gives you 16 S88 inputs for just $3,-.

        Like

        Posted by RudyB | August 17, 2015, 13:26
  12. How long can the cables be before it dosnt work

    Like

    Posted by kasper | April 7, 2015, 18:41
    • It is a 5V TTL signal of moderate frequency that has to be transferred between Arduino’s and finally to the command station S88 input. From what I read, S88 can be rather sensitive. A few meters normally should not give problems though. To be sure, only a test will give you a clue.

      Like

      Posted by rudyb2014 | April 7, 2015, 19:20
  13. Hi Rudy.

    First – best wishes for 2015.

    I like your idea about using the Arduino as occupancy detector board.
    I gave it a try an connected your idea to Rocrail via the LPT Port (set to ECP).
    Based on the Rocrail information I think I got the S88 ports right.
    Do I have to change the settings regarding the timer/clock setting?
    I used both of your codes (the ‘starting’ code for just one Arduino and the one with two boards)

    So far no response – did you try to connect the Arduino to Rocrail?

    Would be really nice hearing from you – bbaehre

    Like

    Posted by bbaehre | January 2, 2015, 07:34
    • Ho bbaehre. Best wishes to you too!

      I have not tried it on Rocrail yet … at least not in the ‘direct’ way you describe where apparently an LPT post is used to send out the S88 signals?

      Since the software works OK with the S88 port on my EcOS2, I reckon it should work with any S88 port. Although the timing of the signals differs some between equipment brands, the sequence is always the same.

      If possible I’d first try to get some certainty if the clock and PS pulses are available the way the Arduino expects them. You probably do not own an oscilloscope? If not, what you can do is write a few lines of code to measure the time (in us) between two rising flanks, using an interrupt on pin 2 or 3. Connect your clock signal to pin 2 and measure the time. Then connect your PS signal and measure the time. There should be 512 clock pulses in one PS cycle. Then at least you know your signals are ok.

      Like

      Posted by rudyb2014 | January 2, 2015, 09:31
  14. This looks really interesting! I’m about to build a layout with block detection and would need a lot of detectors. Your arduino solutions looks verry interesting as I’m quite used to working with the arduino.

    Are you going to fix the code so more arduinos could be linked?

    Like

    Posted by Marcus | October 23, 2014, 12:54

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: