Arduino Forum

Using Arduino => Interfacing w/ Software on the Computer => Topic started by: tscheipel on Aug 08, 2019, 01:24 pm

Title: COM data only visible in Arduino IDE Serial Monitor
Post by: tscheipel on Aug 08, 2019, 01:24 pm
Hello,

I have a problem when using other terminals/programs than the built-in Serial Monitor of the Arduino IDE.
My program is the following:
Code: [Select]

void setup() {
  Serial.begin(9600);
  sensors.begin();
  sensors.getAddress(sensorAddress, 1);
  sensors.setResolution(sensorAddress, TEMPERATURE_PRECISION);
}

void loop() {
  sensors.requestTemperatures();
  Serial.println(sensors.getTempC(sensorAddress)); 
  delay(500);
}


It does what it should, but only when using the Serial Monitor.
I've used hterm, another COM sniffer and my own C# program to try to get the values but didn't succeed. Settings were correct.

Using Windows 10, latest updates.

Any opinions? Driver settings?

Best,
Tobias
Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: Robin2 on Aug 08, 2019, 03:03 pm
If it works with the Serial Monitor then you must have incorrect settings in the other programs.

You need to select the correct COM port and the serial settings should be 8 bits, no parity and 1 stop bit (8N1). And, of course the correct baud rate.


If you need more help please post your complete Arduino program.

...R
Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: Hiddenvision on Aug 08, 2019, 03:04 pm
Hi Tobias,

To be honest if you can see the data in the serial monitor then any terminal program should do exactly the same as long as you are opening the same port.

Make sure you close the serial monitor.!!

It maybe one of the control lines holding the device in reset or slipping it into program mode.
I forget if it was DTR or RTS.

Just make sure the port is opening, and that you are not sending char(0) too much.
Does the device respond to outgoing serial commands even if you can't see any incoming data.
You can also just short RX and TX on the board to see if a simple loopback test works.


Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: tscheipel on Aug 08, 2019, 03:23 pm

If it works with the Serial Monitor then you must have incorrect settings in the other programs.

You need to select the correct COM port and the serial settings should be 8 bits, no parity and 1 stop bit (8N1). And, of course the correct baud rate.


If you need more help please post your complete Arduino program.

...R
If I hadn't double, triple, quadruple checked all you just said, I wouldn't be posting.
As I said, I suppose the program works correctly, as I get results in the IDE, so posting "all of it" wouldn't make any difference. But it is in attachment.

Hi Tobias,

To be honest if you can see the data in the serial monitor then any terminal program should do exactly the same as long as you are opening the same port.

Make sure you close the serial monitor.!!

It maybe one of the control lines holding the device in reset or slipping it into program mode.
I forget if it was DTR or RTS.

Just make sure the port is opening, and that you are not sending char(0) too much.
Does the device respond to outgoing serial commands even if you can't see any incoming data.
You can also just short RX and TX on the board to see if a simple loopback test works.
I know, that's exactly why I'm asking. It is a really odd and weird behaviour.


Is the code of the Serial Monitor open source, so I can reverse engineer this?
Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: Robin2 on Aug 08, 2019, 08:01 pm
Is the code of the Serial Monitor open source, so I can reverse engineer this?
It is. But it would be a complete waste of your time studying it.

There is nothing in your program that would prevent it working with any other Terminal program.

I don't have your sensors. You might like to try this simple program which works with minicom on my Linux PC.
Code: [Select]
void setup() {
  // put your setup code here, to run once:

  // Serial port
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.println("Hello World");

  delay(1000);
}


I can only conclude that there is something wrong with your Terminal settings. Or maybe you don't have some Operating System permission?

...R
Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: tscheipel on Aug 09, 2019, 07:42 am
Ya, no. But thanks for your effort. Also works when mapping the device in a VirtualBox and using Linux.
Seems to be a Windows issue, but no idea what it is. I'll keep you updated, if I find something.
Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: Robin2 on Aug 09, 2019, 08:46 am
Seems to be a Windows issue, but no idea what it is.
Just switch permanently to Linux :)

...R
Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: tscheipel on Aug 09, 2019, 10:40 am
Just switch permanently to Linux :)

...R
Would like to, not possible due to policies  ;)
Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: sumguy on Aug 09, 2019, 03:58 pm
You didn't show the C# code you tried but here is one of the options I would use as an interface, it's simply a form that contains a rich text box control and the baud and com should be configured to match your arduino.

Code: [Select]
using System;
using System.Windows.Forms;
using System.IO.Ports;

namespace ArduinoMonitor
{
    public partial class Form1 : Form
    {
        SerialPort myport = new SerialPort();
        public delegate void StringDelegate(string sData);
       

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            myport.PortName = "COM7";
            myport.BaudRate = 9600;
            myport.NewLine = "\r\n";
            myport.DtrEnable = true;
            myport.Open();
            myport.ReadExisting();
            myport.DataReceived += new SerialDataReceivedEventHandler(myport_DataReceived);
           
        }


        private void myport_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)

        {

            myport.ReadTimeout = 50;

            try
            {
                string str = myport.ReadLine();
                this.BeginInvoke((new StringDelegate(StringDebug)), str);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

            private void StringDebug(string sData)
            {
                richTextBox1.AppendText(sData + "\n");
            }

    }
}
Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: tscheipel on Aug 13, 2019, 01:00 pm
You didn't show the C# code you tried but here is one of the options I would use as an interface, it's simply a form that contains a rich text box control and the baud and com should be configured to match your arduino.

Code: [Select]
using System;
using System.Windows.Forms;
using System.IO.Ports;

namespace ArduinoMonitor
{
    public partial class Form1 : Form
    {
        SerialPort myport = new SerialPort();
        public delegate void StringDelegate(string sData);
       

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            myport.PortName = "COM7";
            myport.BaudRate = 9600;
            myport.NewLine = "\r\n";
            myport.DtrEnable = true;
            myport.Open();
            myport.ReadExisting();
            myport.DataReceived += new SerialDataReceivedEventHandler(myport_DataReceived);
           
        }


        private void myport_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)

        {

            myport.ReadTimeout = 50;

            try
            {
                string str = myport.ReadLine();
                this.BeginInvoke((new StringDelegate(StringDebug)), str);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

            private void StringDebug(string sData)
            {
                richTextBox1.AppendText(sData + "\n");
            }

    }
}

That was the lead. It is simply the DTR you need to enable.
Thanks everyone.

Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: Robin2 on Aug 13, 2019, 03:03 pm
That was the lead. It is simply the DTR you need to enable.
That was in Reply #2

...R
Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: meltDown on Aug 15, 2019, 02:08 pm
I thought usb cables had only 2x data and 2x power wires. Where does dtr fit into the scheme of things?

Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: Robin2 on Aug 15, 2019, 02:32 pm
I thought usb cables had only 2x data and 2x power wires. Where does dtr fit into the scheme of things?
It's done in software behind the scenes.

...R
Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: Hiddenvision on Aug 15, 2019, 02:35 pm
The extra DTR and RTS signals are generated on the USB ic on the external board.
Arduinos and others use those pins to either reset or reset into flash mode.

Some USB devices do not offer the pins to external headers so don't be angry if your USB convertor does not have them. The Chip will.!!
Some being CP201x or CH340 IC's
There is a post in the Hacking section I think that shows how to mod one of the popular converters if desired.
Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: meltDown on Aug 15, 2019, 02:36 pm
Ah I saw the phrase "was the lead" and thought that was "lead" as in "cable" doh.

I thought it meant the lead as in cable was duff.

Thanks.
Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: Hiddenvision on Aug 15, 2019, 02:44 pm
lead as in Pointer I think.
Title: Re: COM data only visible in Arduino IDE Serial Monitor
Post by: meltDown on Aug 15, 2019, 02:48 pm
lead as in Pointer I think.

Yes I twigged to that eventually, lead as in clue.

(But not *this kind of pointer....)