Increase Serial port USB baud rate

Nick_Pyner:
I take that the OP's experience is definitive - apparently not rubbish..

When we see what the OP has actually done, and how he did it, we will be able to comment.

Like 99.999% of laptops this one that I use with Linux was supplied with Windows 10 - the hardware is identical for both operating systems.

...R

Thank you all for your replies,

I made another test, I used serial pins from the Mega connected to a TTL-USB adapter with PL2303 Chip, which should be suitable for higher baudrates than 115200bps. I tried on different values (taken from the dataseet) and tested in the serial pin ports (Serial.println()) and via SoftwareSerial on digital pins. And this time I used Real Term as Terminal.
The results were:
-Serial pins: Same result than using USB arduino cable (and its internal converter.)
-Digital pins with TTL adapter-Software Serial: Lower Baudrates than Serial pins and arduino cable.

regarding your replies:

Nick_Pyner:
OK, it sounds like I'm right about windows then? but if you had asked me "who the hell fed you that rubbish?"

Yes, after previous tests, this last test I have explained in this post, some COM device configuration changes, I am still thinking is a Windows limitation. But I think too, there sould be any kind of solution.

Nick_Pyner:
Define: hardware.

In this case: Hardware should be something that I can plug to the computer, acquire data, analyze and manage over there the obtained data.
For this requirements, should be some kind of microcontroller, with SPI/I2C connection for connectiong an accelerometer and obtain the data from X, Y and Z axis; and a Serial connection (Whith an TTL-USB as CH340/PL2303.......included inside-or not).
I decided to start this task with an Arduino (I have Raspberry, PIC microcontrollers, ATMEL...), so due it's an university project, I decided to use Arduino due it's for educational purposes.

Nick_Pyner:
The HC-05 has an AT config command for 1382400. The HC-06 is "only" good for 115200.

The NodeMCU is an ESP8266 development board. All ESPs are faster and have more memory than an Arduino - even a Mega.

I thought using HC-05 or ESP-01, but I think I will have the same issue at the time I receive the data to the PC. If it is not capable to reach that baudrates wired, unwired and in the same ports I directly tested, some data will be lost.
I will take a look to the NodeMCU on more detail, thank you very much for the information.

Paul_KD7HB:
Perhaps you are not aware that you can set any program in Windows, Linux, etc. to run at a higher priority than the standard mid-range priority. Increase the priority of your PC program and see if that helps.

Thank you for the idea, tried, but nothing changes.

Robin2:
Never mind Excel.

Post the Mega program and describe what you doing on the PC to collect the data and measure the time taken. And just provide the raw data - for 3 different baud rates there will just be 3 numbers (or maybe 9 if you repeat each test 3 times) so there is no need for spreadsheet.

...R

The program I am using for testing is on my first post.
The excel I attached has inside the RAW data obtained with arduino IDE, and the calculations I made for each test.

Thank you all.

peko86:
The program I am using for testing is on my first post.

That Arduino program has a whole lot of very slow code in it - floating points, modulus and Strings. If you want to test Serial speed just send a simple message such as "hello world".

Be aware, also that USB performs poorly for short messages as it works with 64 byte packets IIRC. If the message is less than 64 bytes it only gets sent after a timeout.

The excel I attached has inside the RAW data obtained with arduino IDE, and the calculations I made for each test.

I'm not going to open a spreadsheet file just to see 3 numbers - and if that means I'm lazy then so be it.

...R

Hi Robin2,

Robin2:
That Arduino program has a whole lot of very slow code in it - floating points, modulus and Strings. If you want to test Serial speed just send a simple message such as "hello world".

This is 100% true, and I did not tested....I will try later your suggestion. But I have no clear I can reach such difference of bps. In all ways, later I will try it.

Robin2:
I'm not going to open a spreadsheet file just to see 3 numbers - and if that means I'm lazy then so be it.

Sorry, but maybe I am confused. Which three numbers do you want to know?. RAW data are much more than only three numbers. Maybe are you asking regarding baudrates I got on the three tests??

Theorical 115200bps: 95366,66667bps
Theorical 230400bps:100182,1333bps
Theorical 1Mbps:111198,9333bps

peko86:
I thought using HC-05 or ESP-01, but I think I will have the same issue at the time I receive the data to the PC. If it is not capable to reach that baudrates wired, unwired and in the same ports I directly tested, some data will be lost.
I will take a look to the NodeMCU on more detail,

Both ESP-01 and NodeMCU use the ESP8266. If an ESP-01 is not up to the job, a NodeMCU will probably not be much help. I raised the matter of ESP's not because of the comms ability but because of the speed and memory - speed being the ability to do the job, not transmit the data, which is really just an afterthought. You may find the Mega you already have has sufficient of both, and there is no need to venture into wireless.

peko86:
Sorry, but maybe I am confused. Which three numbers do you want to know?.

Let's forget about 3 for a moment and just concentrate on 1

If you do a test at (say) 115,200 baud how are you measuring the throughput and what number do you get for the the throughput.

Please answer both questions.

...R

Thank you again for your support!

Nick_Pyner:
Both ESP-01 and NodeMCU use the ESP8266. If an ESP-01 is not up to the job, a NodeMCU will probably not be much help.

True, but I will buy a few NodeMCU, seems interesting for future projects, Thank you for the information

I don't know why, but the previous post was sent from my phone and was splitted, fortunatelly, I could recover the second part:

Robin2:
Let's forget about 3 for a moment and just concentrate on 1

If you do a test at (say) 115,200 baud how are you measuring the throughput and what number do you get for the the throughput.

Please answer both questions.

...R

It's not 100% precission method (I tried on other serial monitors as described by other ways with similar results), but the exposed method on the Excel sheet I made the following steps:
I monitored the output over serial monitor on Arduino IDE. I took three full seconds. I copied and pasted into Excel. I counted the number of rows and divided into the three seconds of sample and considered it as "data rate".
I took 10 rows from the measurement, and counted the number of caracters, I added "/r" and "/n" to each row and made the characters mean on each row.
Making this operation:
Data rate(samples/second)mean chacters/sample8bits/sample=X bits/second (bps)
If I made any mistake, let me know please. I am thinking a lot for possible solutions, for this purpose(as described for the university) I would like to use Arduino.
I am thinking too: I estimate my Arduino boards have between 3-8 years. I think would not be any reason but....Could It be the issue?

Thank you in advance.

And now I see again my message incomplete I put the throughputs on the previous message, but I should have some kind of issue from this phone and the forum and it doesnt run well at all:

peko86:
Theorical 115200bps: 95366,66667bps
Theorical 230400bps:100182,1333bps
Theorical 1Mbps:111198,9333bps

peko86:
I monitored the output over serial monitor on Arduino IDE. I took three full seconds. I copied and pasted into Excel. I counted the number of rows and divided into the three seconds of sample and considered it as "data rate".

I would not consider that approach at all reliable. There are too many aspects that could impact on the throughput.

You need to write a PC program that can receive the data and do the timing. I suggest you program the Arduino to send a specific amount of data and in the PC program note the time when the data starts coming and when it finishes coming.

I am convinced that the sloth is in the code in the Arduino program in your Original Post. An Arduino Leonardo sends data at full USB speed irrespective of what baud rate is specified and I have, in the past, verified that it does actually send at that speed.

...R

Robin2:
I would not consider that approach at all reliable. There are too many aspects that could impact on the throughput.

Do you really think that this estimation could have an error of 50-80% deppending on the baudrate? I am not sure. This is true and I am 100% sure that exists an error, maybe 10-15%.

Robin2:
You need to write a PC program that can receive the data and do the timing. I suggest you program the Arduino to send a specific amount of data and in the PC program note the time when the data starts coming and when it finishes coming.

Could I reach higher baudrates than a different Serial monitors I tried?: RealTerm, Putty, Arduino IDE's...
I think the reply is not, but really...I need to start the software too, could be the moment for begin that.

Robin2:
An Arduino Leonardo sends data at full USB speed irrespective of what baud rate is specified and I have, in the past, verified that it does actually send at that speed.

I have not a Leonardo, I have 2xMega 2560, 1xMega 1280, 1xUno and 2xNano...Maybe it's the time for buying one of them...

Thank you for your time and patience!

peko86:
I have not a Leonardo, I have 2xMega 2560, 1xMega 1280, 1xUno and 2xNano...Maybe it's the time for buying one of them...

I was not suggesting that a Leonardo would solve your problem. I was just trying to convey to you that much higher throughputs work. You should have no trouble getting an Uno or Mega to operate reliably at 500,000 baud.

If you are not seeing throughput that is consistent with 500,000 baud then the problem lies either in the program that is sending the data (which is what I suspect) or in the program that is receiving the data.

If you are not prepared to set up a proper test it will be difficult to help you - but that is your decision.

...R

Thank you a lot Robin2!

Robin2:
I was not suggesting that a Leonardo would solve your problem. I was just trying to convey to you that much higher throughputs work. You should have no trouble getting an Uno or Mega to operate reliably at 500,000 baud.

Yes, I understand...Only was a comment from my side-for completing my Arduino collection :smiley: . Sorry for the missunderstanding.

Robin2:
If you are not seeing throughput that is consistent with 500,000 baud then the problem lies either in the program that is sending the data (which is what I suspect) or in the program that is receiving the data.

If you are not prepared to set up a proper test it will be difficult to help you - but that is your decision.

Yes, you have all the reason. And I need to solve this issue.
I just tried an easier program, and I get the data in the same way (this time RealTerm). Now I have the expected results.
This is the program I just tried (impossible to be easier):

void setup() {
  Serial.begin(1000000);
}

void loop() {
Serial.println("0123456789");
}

The data was monitored on RealTerm, at 1000000bps, I obtain a data rate of around 198400 Characters/second, when previously in this same software with previous sketch I obtain around 18000. I don't really know how this terminal takes the measurements due if I multiply 198400*8=158400. So It's clear that it runs 10 times faster than previously, which is better, and the issue it's clear is in the Arduino sketch.

So now, I would like to improve the program I posted in the first message for obtaining a better data rate. I prefer starting with this (and not with a real sensor data, due it will send three virtual sinusoidal signals, with known parameters), and It would be easier to make a software which takes correct measurements for comparision.
Any suggestion? How can I make a continous data printing and processing (or obtaining the data in the future program) in backend mode? something as producer-consumer pattern? I will research of the capability of Arduino with producer-consumer pattern, I've never tried it on Arduino. Any recommendation regarding that?

peko86:
So now, I would like to improve the program I posted in the first message for obtaining a better data rate.

It's taken an awful long time to get here, but at least we have arrived :slight_smile:

Now you need to describe in English (not code) what you want the program to do. All programming starts with a requirement or specification. And the objective is not to do something quickly - it is just to do something. Only after we know what the something is can we think about performance.

...R

Here are the standard USB data transfer rates:

The Universal Serial Bus (USB) specification stipulates five data transfer rates:

USB 1.0/Low-Speed: 1.5 Megabits per second (Mbps)
USB 1.1/Full-Speed: 12 Mbps.
USB 2.0/Hi-Speed: 480 Mbps.
USB 3.0/SuperSpeed: 5 Gbps.
USB 3.1/SuperSpeed: 10 Gbps.

Which version of USB are you using to test with? The slowest?

Paul

Robin2:
It's taken an awful long time to get here, but at least we have arrived :slight_smile:

Now you need to describe in English (not code) what you want the program to do. All programming starts with a requirement or specification. And the objective is not to do something quickly - it is just to do something. Only after we know what the something is can we think about performance.

...R

Thank you Robin2,
True, I've never made a sketch with this baudrate requirements, but as you said, we arrived to the main cause. Maybe as described previously was a delay created due string creation?

Regarding the requirements, at this step: I would like to develop a program for simulating three sinusoidal signals with known amplitudes and frequencies, and giving it as serial output with this format: XxvalueYyvalueZzvalue. Example X15Y25Z10.
It's not an issue using the same Signal for X,Y and Z as the posted program before.
I would like to have this format for avoiding errors in the PC program. If you have any other suggestion, Will be welcome.

Paul_KD7HB:
Here are the standard USB data transfer rates:

The Universal Serial Bus (USB) specification stipulates five data transfer rates:

USB 1.0/Low-Speed: 1.5 Megabits per second (Mbps)
USB 1.1/Full-Speed: 12 Mbps.
USB 2.0/Hi-Speed: 480 Mbps.
USB 3.0/SuperSpeed: 5 Gbps.
USB 3.1/SuperSpeed: 10 Gbps.

Which version of USB are you using to test with? The slowest?

Paul

Hi Paul and Thank you for your reply,
I've tested on USB 2.0 and 3.0. Maybe one of the computers I've tried has one 1.1 port. I tried on three computers and in different ports with different configurations on all of them.
As we concluded, seems an Sketch "issue". But if you have any suggestion regarding the USB ports, Will be fine to improve the performance to the top.

Robin2:
It's taken an awful long time to get here, but at least we have arrived :slight_smile:

IKR?

This is exactly why those who ask for help should listen to the people who are trying to help. OP, if you had listened to my original advice several pages of replies ago, maybe the problem would be solved by now, lol. Please, reread my first two replies and create an honest to goodness, no "S"trings attached, test between Arduino and MATLAB. Remember efficiency is key!!!

Power_Broker:
IKR?

I don't understand, what It means?. Sorry for my English.

I will try without strings in an hour, only by serial monitor for today (it's quite late in Spain). And I Will post the results.

Thanks for your advices.

peko86:
I don't understand, what It means?. Sorry for my English.

You are excused. I believe it is American for "I know, right?" and not in common usage. PowerBroker is right, though, using "S"trings is a really bad idea, often ultimately fatal, and it may be that the only reason why your programme hasn't died already is because you have been saved by the Meg's extra memory.

Nick_Pyner:
You are excused. I believe it is American for "I know, right?" and not in common usage. PowerBroker is right, though, using "S"trings is a really bad idea, often ultimately fatal, and it may be that the only reason why your programme hasn't died already is because you have been saved by the Meg's extra memory.

Thanks for the American lesson.

Regarding the program I used last time: I removed String, delays...It increased the speed to around 1450Hz, but I need to increase it more. Maybe I need any multithreading process, such as producer-consumer, but I am not still sure If it's possible with arduino.
I attach my actual testing code:

//code modified for improvement from http://forum.arduino.cc/index.php?topic=8563.0


float wav1[3];//0 frequency, 1 unscaled amplitude, 2 is final amplitude
int average;
const int Pin = 9;
float time;
float percentage;
float templitude;
float offset = 2.5; // default value 2.5 volt as operating range voltage is 0~5V
float minOutputScale = 0.0;
float maxOutputScale = 5.0;
const int resolution = 5; //delay
const float pi = 3.14159;


void setup() {
  wav1[0] = 230; //frequency of the sine wave
  wav1[1] = 2.5; // 0 - 2.5 amplitude (Max amplitude + offset) value must not exceed the "maxOutputScale"
  Serial.begin(2000000);
}

void loop() {


  time = micros() % 1000000;
  percentage = time / 1000000;
  templitude = sin(((percentage) * wav1[0]) * 2 * pi);
  wav1[2] = (templitude * wav1[1]) + offset; //shift the origin of sinewave with offset.
  average = mapf(wav1[2], minOutputScale, maxOutputScale, 0, 255);



  Serial.print("X");
  Serial.print(average);
  Serial.print("Y");
  Serial.print(average);
  Serial.print("Z");
  Serial.println(average);
  //delayMicroseconds(resolution);

}
// function to map float number with integer scale - courtesy of other developers.
long mapf(float x, float in_min, float in_max, long out_min, long out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}