I'm trying to get serial1 working from my mega and as far as I can tell it isn't.
Im trying to send serial command to a NCE usb interface (link below) but no commands work. If the usb interface is connected directly to the computer I'm able to send commands without issue through another program.
I've tried to dumb it down to the basics to try to isolate the issue and used the Multi Serial Mega example but nothing happened.
I've seen other people getting it working by using an input_pullup on the rx pin but it didn't work for me.
I've cut an usb cable to plug directly into the usb interface with the tx1 & rx1 pins along with gnd and pwr. I've swapped the rx and tx pins also incase I wired it incorrectly but it still didnt work.
Is there a way to test serial1 without any external board? just to loop tx to rx and print to serial0?
I'm quite stumped so any help would be greatly appreciated.
Your first link drops to an "updating page" for the item you mention.
There are a few train buffs on here so they may be able to help but the rest of the site dedicated to that product all mentioned UTP (CAT) cabling and I really didn't see anything for serial.
There is a thread about loopback testing at the top of this section of the forum.
You should also be able to use that basis for the other serials.
Correct thinking in that normally TX on one device goes to RX on the other and vice versa.
You might also want to look at the "Multi Serial" example in the examples section of the IDE.
Thank you for your reply.
The link seems to work for me. Here is another one that shows some details about it. https://sites.google.com/site/markgurries/home/nce-info/nce-usb-limitations
The usb interface takes a serial binary input via usb and outputs to a rj12 cable. I just want the arduino to act as the computer to input the serial commands.
I tried the multi serial example, I linked it in the original post but it didn't work.
I will try the loopback testing. I guess I will have to mix the code from the multi serial example to test serial1? Only thing is the loop back testing instructions ask for the reset to be grounded. Does this mean no code would work?
That link was a lot better.
It does specifically mention using a "PC" and no mention of an Arduino.
Not seeing any information on the full 232 protocol just two mentions of speed "This is the speed of the USB adapter when set to this jumper configuration. 9600 is slower than 19200"
You would also need to know if it wants LF and or CR and a few other items to ensure any packets sent from an Arduino match those expected by the system.
8 bit or something else ?
Stop bits ?
Flow control ?
Possibly even TX and RX delays as your system could be proprietary ?
BTW does the system work as INTENDED without the Arduino.
EG can you send data from a real PC using that interface you linked to ?
I'm basing it mostly on these pages. He uses 9600.
The usb interface works as intented plugged directly into the pc and using the JMRI software to output the commands.
That has a lot more detail.
Pretty std 8.N.1 serial.
What are you using to monitor the serial out from the Arduino ?
For a better serial monitor I like CoolTerm
Its pretty simple to set up and use.
There are plenty of terminal programs out there and almost all of them are better then the one built into the IDE.
They can show you the output in different formats too which might be useful in your case.
Still wandering those links you provided.
Noticed the age of many sections and how it mentions one type of board and then another without being to specific. Hate to say this but you might have picked up on quite an old project without much support.
Do you have a copy of the sketch you are currently using and if so could you post it here but please use the code tags ( </> ) or the forum might change a few things.
Also followed a couple of links from them pages to a more up to date section on using Arduinos
Linking to it HERE
What struck me was THIS ITEM
Which pretty much makes it plug and play (almost)
I've just been using the arduino IDE to monitor the serial out.
Can Coolterm monitor the serial1 output also?
I've just been using the ralf code, it compiled but didn't do anything so i cut it down to just the command and it still didnt do anything. I then used the working command that I was putting into the JMRI software (which it converts to binary) but again it did nothing.
There are two LEDs on the interface that flash when data is going through but neither of them light up when I'm trying to get the arduino to work. But do if using the correct commands in JMRI.
I'm away for work for a couple of days so I will test that serial1 actually works with the loop test when I'm back home.
It looks like that DCC shield would replace the NCE usb interface. Maybe I should have used one of those instead. But I guess it means that using the arduino should work.
Answer for when you get back.
Coolterm can monitor pretty much any serial device you computer sees.
I think posting your sketch is quite crucial especially if you modified it as it is easier for others to see where any issue may be and to test it themselves.
Simple way to test Serial1.
Disconnect your device from Serial1 and short rx1 and tx1 of the mega. The above code will echo anything received on serial (e.g. from serial monitor) through serial1 back to serial so you should see it in the serial monitor.
Thanks for your help.
The provided code doesn't echo anything back with pin 18 & 19 connected to each other.
I've also tried it with the RX1 pin with a pullup but that also doesnt work.
I see now that it will not even compile; I missed a ( in two places.
Please show your full code. You can write a similar test for e.g. Serial2. If that works, your Serial1 might be damaged while you were experimenting.
Just tested on a Leonardo and the (fixed) code works.
while (!Serial); // required for Leonardo
if (Serial.available() > 0)
if (Serial1.available() > 0)
Haha yeah I added the missing ('s.
I did modify it to try to use serial2 also and no luck. I aslo tried a different baud rate. I noticed in your leonardo code you have serial at 250000 and serial1 at 9600. Could this potentially help?
I presume its meant to repeat whatever is written in the serial monitor back into the monitor? Just checking to make sure I'm not doing something stupid.
Thanks for helping.
No, the baudrate does not matter. The code simply sends what is received from serial to serial1 and what is received on serial1 back to serial.
I'm out of options, sorry.
Maybe time to do some simple tests on the pins themselves. One as output, one as input. Toggle the output and read back the input and send the status to pin 13 (build in led) and/or serial port.
And then I'm out of options