Arduino USB interface for sensor feedback to Rocrail

Moderator: Moderators

Arduino USB interface for sensor feedback to Rocrail

Postby rozsaheg » 13.09.2015, 18:29

I have made this program to collect and send sensor signals with Arduino Mega 2560 by USB to Rocrail. It is a "lex minimi" solution, continually scanning the sensors status, if finds a change, sends the info to Rocrail. Speed is higher than the S88 bus because no other units on this USB line. Very easy to test. Just put a micro switch to any pin, if you push it, you will see the sensor change on the Rocrail plane and in the Sensor Monitor table.
If you need more sensor to manage, you can multiple the interface as many times as you want. Feel free to any comment or advice.

Laszlo
You do not have the required permissions to view the files attached to this post.
rozsaheg
 

Re: Arduino USB interface for sensor feedback to Rocrail

Postby John Hoek » 09.10.2015, 19:18

Hi,
How to setup ROCRAIL to use this solution?
John Hoek
 

Re: Arduino USB interface for sensor feedback to Rocrail

Postby smitt48 » 09.10.2015, 20:16

Hi John,

/* This program try to implement a kind of sensor management using Arduino Mega 2560,
sending the appropriate info directly to Rocrail by USB. Define an MCS2 controller in
Rocrail. In the controller's properties select "serial" and the Arduino "comport".
It is working with any micro switch or IR module, connected to Mega 2560 digital pins.
With a minor modification you can include the 16 analogue pins as well. No any shield
or other elements are needed. The idea is inspired by Bert Havinga and Joerg Pleumann */


This is what it says in the notes.
Use MCS2 controller.

Tom
Kind regards,
Tom Smit
Kralendijk, Bonaire - Dutch Caribbean

Märklin M & K-rails with ECoS2 (4.2.0) - WinXP as server, 10
RoSoft: S88n & WDD switch & SDD signal decoders
Display: Tri-ang from 1950's, Märklin from early 1960's
In build phase
smitt48
 

Re: Arduino USB interface for sensor feedback to Rocrail

Postby rozsaheg » 11.10.2015, 08:27

Hi John,

If you have difficulties with the Rocrail setup, I can give you more detailed instructions.

Regards

Laszlo
rozsaheg
 

Re: Arduino USB interface for sensor feedback to Rocrail

Postby rozsaheg » 15.11.2015, 11:47

On the first picture you can see the Rocrail controller setup for the Arduino Mega 2560. The other shows the Rocrail sensor monitor window after you start the skeleton_ultimate program.

Feel free to any question or suggestion.

Laszlo

Skel_ult1.PNG

Skel_ult2.PNG
You do not have the required permissions to view the files attached to this post.
rozsaheg
 

Re: Arduino USB interface for sensor feedback to Rocrail

Postby sv1iw » 21.12.2015, 01:07

Hi Lazlo, good idea. Just a clarification, by the micro switch push you are actually pull the digital pins to ground to emulate sensor state?

Regards Manos 8)
sv1iw
 

Re: Arduino USB interface for sensor feedback to Rocrail

Postby rozsaheg » 21.12.2015, 16:37

Hi Manos,

Yes.

This can be the very first and simple test.

Feel free to questions or suggestions.

Regards

Laszlo
rozsaheg
 

Re: Arduino USB interface for sensor feedback to Rocrail

Postby sv1iw » 25.12.2015, 00:16

Hi Lazlo
I had a MEGA lying here so I said to try it out. I have declared and set the new interface on my computer (on com4) and I grounded digital pin 22 on the MEGA. This pin has been declared as the sensor in front of my block #10
The RR server reports:
Serial {COM4} error= 0X0000
device error.

To me it seems that it RR sees action from the MEGA but has not associated the sensor in front of Block 10 to pin 22 on Mega. So the question is how do I address the pins on the Mega with sensor addresses on sensor properties or elsewhere in my layout?

Taking the opportunity May I wish you and yours Merry Christmas and a Happy New year...
Regards
Manos Sv1IW
sv1iw
 

Re: Arduino USB interface for sensor feedback to Rocrail

Postby rozsaheg » 25.12.2015, 11:58

Hi Manos,

In a first step no declaration needed. Start the RR and open the Sensor monitor window. Connect the MEGA. After one-two second the sensors status will appear row by row in the monitor window. If you not changed the program I provided, it will write 48 row, independent how many sensor or micro switches connected. If there is no grounded pin, every status has to show "1". If you ground pin 22, the 19th row status will change to "0". So the RR automatically numbering the pins (sensors), you can add ID to them when you want. Based on that ID, you can see the sensor changes on the plan as well.

There is a shift in the numbering because pins 0-3 not used.

If the problem persist try to check the last *.trc file.

Good luck

Laszlo
rozsaheg
 

Re: Arduino USB interface for sensor feedback to Rocrail

Postby sv1iw » 26.12.2015, 00:15

Ok Lazlo everything understood but perhaps my set up is not appropriate. The RR is not actually connected to a layout I have only declared the VCS1 interface and the Mega one. As you understand locos are virtually auto moved and expecting to see the real actions only from the sensor interface. When everything has been set and sensor table opens it will only show the entry sensor which has been defined in it's properties (Interface tab) belonging to Interface ID named MEGA (the name of the Mega board).
The reported error it tells me that RR for some reason doesn't communicate serially with the Mega but I have no clues on why.
Probably it will be a good idea the Mega to report also in it's serial port just for debugging reasons...

The Arduino sketch has been uploaded unaltered. Since my MEGA is reported as a CH340 virtual com port perhaps there is an issue with the driver and I shall check on this as I have no other place to look for a clue...

Regards
Manos SV1IW

P.S. Just noticed that all 48 sensors are reported on RR server screen (Dos) and Controller window or RR viewer. This happens only once. Could that be a Chinese Mega board issue?
sv1iw
 

Re: Arduino USB interface for sensor feedback to Rocrail

Postby rozsaheg » 26.12.2015, 09:51

Manos,

If the 48 sensors status reported, te communication probably OK. CH340 is the right driver. No real plan needed for the test.
Is the CS2 declared, as I suggested ?
Push the microswitch continually and send me the DOS window screenshot's last five row.

Do not give up, you are very close.

Laszlo
rozsaheg
 

Re: Arduino USB interface for sensor feedback to Rocrail

Postby sv1iw » 27.12.2015, 00:40

Hi Lazlo
After a couple tries now I am sure that the Mega board and sketch works as expected. I am able to see the grounded pins reported in server window. There is only one mystery to solve and that is why the sensors are not reported in the sensor monitor...

Wrong again, as I was writing this I loaded RR and with surprise I saw all 48 sensors appear on sensor monitor as well. And I had not started the virtual emulation on the system yet.
Unfortunately the whole behavior does not make sense. Because I was not able after reloading to see them all again on sensor monitor.

So to sum it up:
I Load RR server and Viewer for the fist time. I Open sensor monitor. Nothing shows but if I ground the mega pins I can see them reported on monitor and with the correct state (o or 1).
I start the auto mode and power, I can still see pins with their correct state on server but they do not follow in sensor monitor.
I start the virtual loco run, nothing changes I can see pins correctly on server screen but not on sensor monitor.
Also sensor occupancy makes no difference on the movement of locos, a sensor maybe active (grounded) in front of a block but the loco enters it happily (perhaps in virtual run makes no difference).

So this is what I have for the moment...

Regards
Manos SV1IW
sv1iw
 

Re: Arduino USB interface for sensor feedback to Rocrail

Postby sv1iw » 27.12.2015, 00:56

Lazlo the behavior of the sensor monitor was due to the Mega was partially blocked for some reason.
I reload the Mega and I think the behavior is now normal. All 48 sensors are reported and all of them re-reported if one changes from to 0 and vice versa. So now I know the behavior on various issues I think I can handle the operation. Funny thing is that as long as you test only the Mega board, things are going well. When you start using the Layout and start power and auto mode many issues happen on the reporting of sensors. Besides that now I have to associate a sensor with a sensor in my plan and see it going red from green on grounding (hypothetical occupancy). Still operations seems very unstable when I engage my layout.

What say?

Enough for the day, cul (see you later)

Manos SV1IW
sv1iw
 

Re: Arduino USB interface for sensor feedback to Rocrail

Postby rozsaheg » 27.12.2015, 19:25

Hi Manos,

Happy to hear the things start to work.
Clarifying one point. If you ground a pin, only that pin correspondent's sensor status change, other are not reporting anything ? Check the DOS window, please.
On my system there is no any instability, does not matter what is on or off. I have no idea what can cause that in you case.
So, I am waiting what is going on ?

Regards

Laszlo
rozsaheg
 

Re: Arduino USB interface for sensor feedback to Rocrail

Postby sv1iw » 28.12.2015, 02:15

Hi Lazlo
This is what I have come up with, so far.
1. When the Mega board operated with RR alone (no power on, no automode on) everything seems normal. I can ground various pins, see them changing state, reported (first the one that is grounded) and then and all 48 are reported every time there is a single change, end of case.

2. When I give "power on" (fake as it runs on virtual cs) it will run one or two times with the following messages on screen
02:57:37 Output 15 a (mm) on
02:57:19 Output 15 a (mm) off
02:56:38 Output 15 a (mm) on
02:56:38 sensor 1:28 state=1
Communication with Mega will stop after that...

You may notice that the sensor which is grounded is 28, I really do not know why it also outputs the messages like this :Output 15 a (mm) on

3. When I start both auto mode and power on, with the first try on any sensor, it will turn the power off on the rail off and the usb port communication with Mega is blocked.

In both 2 and 3 the further sensor change states are kept in buffer because if I unplug the Mega Board and re-plug it in, all previous missed reports (after the stop) are send back to the RR.

So this is the situation up to know, any clues, ideas on what to try? Can I try the sketch on a UNO with some modification? The number of digital pins is irrelevant for the moment as long we can see if this is also happens on UNO as well...

Regards
sv1iw
 

Next

Return to DIY Hardware