Keyboard Shortcuts
Likes
Search
Locked
Controlling Servos directly connected to Arduino with DCC++ Base Station
#arduino
#dccpp
Hello Group,
I have an Arduino Mega with motor shield running DCC++. I also have a Raspberry Pi running Steve Todd's image. I have upgraded JMRI on the RPi to v4.16 and Java 1.8.0_65. I have the letter "D" as the connection prefix in the JMRI connection preferences. I have a servo connected directly to the Mega with 5V, GND, and PIN15 for control. I checked the wiring and have a good 5V going to the servo. I have created an entry in the JMRI turnout table with hardware address 115 (now shows as DT115) and chose "BSOUTPUT" in the Feedback Mode chooser. I then added an output to the DCC++ base station configuration with Index 115 assigned to PIN 15. I built a quick panel with DT115, and this seems to work OK as the icon moves when clicked, I see "closed/thrown" in the turnout table and I see the Output Cmd "Output ID: 115 low/high" in the DCC++ traffic monitor, but the servo does not move. I have tested the servo by itself using an Arduino servo sketch and it works fine. What have I missed? Thanks for your help, Richard |
|||||||||||||||||||||||||||
¿ªÔÆÌåÓýdo you have enough current available??? The servo draws ~ 150mA when it's moving.?? You can turn it off once it's had a chance to stabilize.?? You may want to put the servo on an auxiliary power supply.On 7/22/2019 6:55 AM, rsauerbrun wrote:
Hello Group, -- Seth Neumann Mountain View, CA |
|||||||||||||||||||||||||||
Hi,
Are you sure that your servo is compatible with DCC++? A standard RC servo requires a pulse width modulated signal, which the arduino servo library will generate, if that's what you have used in your test sketch. ?I'm possibly wrong here but I suspect the DCC++ code just puts out a logic high or low depending on the turnout setting, which won't drive a standard RC servo. Regards Paul |
|||||||||||||||||||||||||||
Thanks Paul,
I started this effort by reading the following section on the JMRI site ¡? If I understand correctly, I should be able to run one servo directly connected to the Arduino's 5V, GND and one digital port (mine is connected to port 7). Of the three methods available with the DCC++ sketch, only the third method using the base station "Output" approach should work. This is what I have done, and everything looks great in JMRI, but the servo never moves. But I get your concern about the PWM. As I watch the DCC++ traffic monitor I see only a "Low" then "High" state for the JMRI turnout. And when I hold the servo next to my ear, I hear a "click" when I send the command in JMRI to go "closed" or "thrown". Is there any way I can overcome this in the DCC++ sketch? Richard |
|||||||||||||||||||||||||||
Hi Richard,
I've not used the DCC++ base station, although I've experimented with using the JMRI interface in conjunction with my own sketch. ?If there's a specialist forum for DCC++ you may get a better informed response there. ?Having said that I downloaded the base station sketch some time ago, which I assume you must have done in order to load it on to your mega. ?The code in Outputs.ccp appears to do a digital write to the output pin - line 85 but this may not be the latest version. ?If so it won't drive an RC servo. ?I've also used the standard Arduino servo library to successfully drive a servo, but on a non model railway related project. ?It may be possible to add the servo library to DCC++. ?It partly depends on your confidence level. ?Also I suspect both the DCC++ code and servo code do 'clever things' with the Arduino timers. ?There's potential for conflict if they are both trying to use the same timer. Paul |
|||||||||||||||||||||||||||
I had a similar problem with an Arduino based servo for turnouts; the servo was only getting a shot of current instead of a significant length of current to move the servo.? You might check how long the current is applied to the servo. Ken Moordigian On Tuesday, July 23, 2019 rsauerbrun <[email protected]> wrote: Thanks Paul, I started this effort by reading the following section on the JMRI site ¡? If I understand correctly, I should be able to run one servo directly connected to the Arduino's 5V, GND and one digital port (mine is connected to port 7). Of the three methods available with the DCC++ sketch, only the third method using the base station "Output" approach should work. This is what I have done, and everything looks great in JMRI, but the servo never moves. But I get your concern about the PWM. As I watch the DCC++ traffic monitor I see only a "Low" then "High" state for the JMRI turnout. And when I hold the servo next to my ear, I hear a "click" when I send the command in JMRI to go "closed" or "thrown". Is there any way I can overcome this in the DCC++ sketch? Richard |
|||||||||||||||||||||||||||
Hello,
?
I may repeat myself but managing the servo directly in the DCC++ sketch is not a good idea. It seems simple but it is not the case, you will have to modify the DCC++ sketch.
?
A simple solution is to use another arduino, which will "listen" to the DCC signal, and act on the servos.
?
As indicated on this link: http://www.mynabay.com/dcc_monitor/_monitor/
?
Have a good day |
|||||||||||||||||||||||||||
Thanks Ken,
This sounds like the issue I am seeing ... So today I am trying a different approach. Rather than connect the servo to the Arduino Mega with the DCC++ sketch, I have ordered a Pi Servo pHAT for the Raspberry Pi that is running JMRI. This $10.95 product has 16 channels that allow for direct connection and management of 16 servos. Here is information on how it works: Has anyone used a this product, or something similar? I am assuming I will be able to configure and operate this within the JMRI environment. Richard |
|||||||||||||||||||||||||||
Just to add another view (which perhaps is an extension of what Richard will soon find with his Pi Servo pHAT approach) ... Les |
|||||||||||||||||||||||||||
(I¡¯ve kept all the below for context, mostly because I don¡¯t understand it enough to quote just part of it)
Could you create a USB connection to the ESP32 chip and then use communications to transfer turnout commands? Bob On Jul 25, 2019, at 8:42 AM, les@... wrote:-- Bob Jacobsen rgj1927@... |
|||||||||||||||||||||||||||
emmanuel ALLAUD
The problem might be that DCC needs precise timing to work correctly and it may be difficult to process something else. For example to smoothly move servo you need to move them degree by degree during a certain amount of time. This may introduce too much latency and mess up the DCC decoding. Le jeu. 25 juil. 2019 16:30, rsauerbrun <richard@...> a ¨¦crit?: Yes, I am trying run this on the same Arduino Mega that is running the DCC++ code. I just assumed that the DCC++ base station code, when configured for the outputs would handle one servo. |
|||||||||||||||||||||||||||
On Thu, Jul 25, 2019 at 04:42 PM, les b49 wrote:
Hence, I'm looking for an easy way for WiThrottle/JMRI to instruct the ESP32 to do something Have a look at MQTT. ?The JMRI implementation of this is described and supports turnouts. ?You will need to run a broker, but your PI should be able to run . ? I'd be surprised if there wasn't some MQTT client implementation available for the ESP32 as it's all about IOT and all the connections can be wireless as long as your garden railway is in range of a wifi router. Paul |
|||||||||||||||||||||||||||
les b49
Thank you, Bob & Paul. ?There's just so much to learn about JMRI (and then all the other bits of software it can interact with...)
Like much of Europe & the US at the moment, a heatwave here means I'm spending most time outside rather than at the computer, so it'll take me a little while to try the 2 suggestions out. ?But just a couple of comments: Bob: ?At present, my iMac, Arduino & motor shield are in my office. ?A 5m USB cable currently runs from the motor shield there to the rails outside. ?The USB connection on the ESP32 (driving the servos) is taken up by the power supply from the 5v "Phone charging" battery. ?I could try using a different 5v source for the ESP32 connected directly to a voltage in on the ESP32 and so free up its USB connection to take input from motor shield as you suggest. Paul: ?Yes, the ESP32 outside is on the house wifi - as are the iMac running JMRI and the iPhone running the WiThrottle app. ?Your suggestion looks feasible and I will try it in due course, but, if possible, I'd prefer not to have to introduce even more s/w elements to the system or interfaces between them, like MQTT and mosquito. ?We'll see... Best regards, Les |
|||||||||||||||||||||||||||
Jason Rausch
Richard,
?
I have a project I have been working off and on with for the last few months using a Raspberry Pi Zero W and custom 16 channel PWM board I created, similar to the one you are using.? The difference is I wanted to make the power interface a little more easy to work with.
?
My general goal is to create 16 channel "nodes" for driving 16 servo turnouts around a layout through an IP/web based control interface.
?
I have linked to a few pictures.? I am working on the code in Python.? So far my limited coding ability has been my major blocking point for really getting this working the way I want it to.? I'm having a hard time getting getting any web access to control the IO pins directly, to talk with the PWM controller.? I'm really a hardware guy, forced to write crummy code :o)
?
?
?
?
?
Jason Rausch
RPC Electronics, LLC |
|||||||||||||||||||||||||||
les b49
Hi, Jason,
As I mentioned in my earlier post above (162059), I've got Arduino code that runs on an ESP32 chip, that creates a wifi server and then responds to client requests by switching servos on points. I think the ESP could support 16 servos as you want, but I'd have to check. ?The HiLetGo ESP I use is ?8.14 on Amazon and cheaper off AliExpress. ?Is that worth considering? ?I'm happy to share the code. ?(I don't know the RPi so don't know if Arduino sketches will run off it.)? (I'm a programmer from the 70s whose now having fun but struggling to learn electronics in my retirement...) Regards, Les |
|||||||||||||||||||||||||||