Skip to main content
Arduino

Return to Question

Fixed syntax highlighting, added tag.
Source Link
VE7JRO
  • 2.5k
  • 19
  • 27
  • 29

I am using Arduino Uno Rev 3, and according to this link we can achieve 2000000 baud rate.

This problem can be easily repeated by the following code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 Serial.println(val);
}
void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 Serial.println(val);
}

I am using the serial-USB cable. To read the data, I used Python pyserial (< 20 lines of code including empty lines and import lines):

import serial
import matplotlib.pyplot as plt
LEN = 10000
data = []
ser = serial.Serial('COM3', baudrate=2000000)
for i in range(LEN):
 try:
 data.append(int(ser.readline()))
 except:
 pass
ser.close()
# %% Plot data
plt.figure(figsize=(6, 4))
plt.plot(data)
plt.savefig('data.png')
import serial
import matplotlib.pyplot as plt
LEN = 10000
data = []
ser = serial.Serial('COM3', baudrate=2000000)
for i in range(LEN):
 try:
 data.append(int(ser.readline()))
 except:
 pass
ser.close()
# %% Plot data
plt.figure(figsize=(6, 4))
plt.plot(data)
plt.savefig('data.png')

Here is what I got:

Plot of data

Edit below

Chris mentioned a good point that it might be the high baud rate of 2,000,000 causing the instability. I did think about that when I first ran into this, but then I did a little trick: adding a sinusoid into the constant. If I do that, the weird spiking goes away! I think it indicate that this is not a high baud rate issue... Is it?

Code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 val += int(512 * (sin(float(millis()) * 0.01) + 1)) * 0.1;
 Serial.println(val);
}
void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 val += int(512 * (sin(float(millis()) * 0.01) + 1)) * 0.1;
 Serial.println(val);
}

Output:

Output

I am using Arduino Uno Rev 3, and according to this link we can achieve 2000000 baud rate.

This problem can be easily repeated by the following code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 Serial.println(val);
}

I am using the serial-USB cable. To read the data, I used Python pyserial (< 20 lines of code including empty lines and import lines):

import serial
import matplotlib.pyplot as plt
LEN = 10000
data = []
ser = serial.Serial('COM3', baudrate=2000000)
for i in range(LEN):
 try:
 data.append(int(ser.readline()))
 except:
 pass
ser.close()
# %% Plot data
plt.figure(figsize=(6, 4))
plt.plot(data)
plt.savefig('data.png')

Here is what I got:

Plot of data

Edit below

Chris mentioned a good point that it might be the high baud rate of 2,000,000 causing the instability. I did think about that when I first ran into this, but then I did a little trick: adding a sinusoid into the constant. If I do that, the weird spiking goes away! I think it indicate that this is not a high baud rate issue... Is it?

Code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 val += int(512 * (sin(float(millis()) * 0.01) + 1)) * 0.1;
 Serial.println(val);
}

Output:

Output

I am using Arduino Uno Rev 3, and according to this link we can achieve 2000000 baud rate.

This problem can be easily repeated by the following code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 Serial.println(val);
}

I am using the serial-USB cable. To read the data, I used Python pyserial (< 20 lines of code including empty lines and import lines):

import serial
import matplotlib.pyplot as plt
LEN = 10000
data = []
ser = serial.Serial('COM3', baudrate=2000000)
for i in range(LEN):
 try:
 data.append(int(ser.readline()))
 except:
 pass
ser.close()
# %% Plot data
plt.figure(figsize=(6, 4))
plt.plot(data)
plt.savefig('data.png')

Here is what I got:

Plot of data

Edit below

Chris mentioned a good point that it might be the high baud rate of 2,000,000 causing the instability. I did think about that when I first ran into this, but then I did a little trick: adding a sinusoid into the constant. If I do that, the weird spiking goes away! I think it indicate that this is not a high baud rate issue... Is it?

Code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 val += int(512 * (sin(float(millis()) * 0.01) + 1)) * 0.1;
 Serial.println(val);
}

Output:

Output

replaced http://arduino.stackexchange.com/ with https://arduino.stackexchange.com/
Source Link

I am using Arduino Uno Rev 3, and according to this link this link we can achieve 2000000 baud rate.

This problem can be easily repeated by the following code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 Serial.println(val);
}

I am using the serial-USB cable. To read the data, I used Python pyserial (< 20 lines of code including empty lines and import lines):

import serial
import matplotlib.pyplot as plt
LEN = 10000
data = []
ser = serial.Serial('COM3', baudrate=2000000)
for i in range(LEN):
 try:
 data.append(int(ser.readline()))
 except:
 pass
ser.close()
# %% Plot data
plt.figure(figsize=(6, 4))
plt.plot(data)
plt.savefig('data.png')

Here is what I got:

Plot of data

Edit below

Chris mentioned a good point that it might be the high baud rate of 2,000,000 causing the instability. I did think about that when I first ran into this, but then I did a little trick: adding a sinusoid into the constant. If I do that, the weird spiking goes away! I think it indicate that this is not a high baud rate issue... Is it?

Code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 val += int(512 * (sin(float(millis()) * 0.01) + 1)) * 0.1;
 Serial.println(val);
}

Output:

Output

I am using Arduino Uno Rev 3, and according to this link we can achieve 2000000 baud rate.

This problem can be easily repeated by the following code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 Serial.println(val);
}

I am using the serial-USB cable. To read the data, I used Python pyserial (< 20 lines of code including empty lines and import lines):

import serial
import matplotlib.pyplot as plt
LEN = 10000
data = []
ser = serial.Serial('COM3', baudrate=2000000)
for i in range(LEN):
 try:
 data.append(int(ser.readline()))
 except:
 pass
ser.close()
# %% Plot data
plt.figure(figsize=(6, 4))
plt.plot(data)
plt.savefig('data.png')

Here is what I got:

Plot of data

Edit below

Chris mentioned a good point that it might be the high baud rate of 2,000,000 causing the instability. I did think about that when I first ran into this, but then I did a little trick: adding a sinusoid into the constant. If I do that, the weird spiking goes away! I think it indicate that this is not a high baud rate issue... Is it?

Code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 val += int(512 * (sin(float(millis()) * 0.01) + 1)) * 0.1;
 Serial.println(val);
}

Output:

Output

I am using Arduino Uno Rev 3, and according to this link we can achieve 2000000 baud rate.

This problem can be easily repeated by the following code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 Serial.println(val);
}

I am using the serial-USB cable. To read the data, I used Python pyserial (< 20 lines of code including empty lines and import lines):

import serial
import matplotlib.pyplot as plt
LEN = 10000
data = []
ser = serial.Serial('COM3', baudrate=2000000)
for i in range(LEN):
 try:
 data.append(int(ser.readline()))
 except:
 pass
ser.close()
# %% Plot data
plt.figure(figsize=(6, 4))
plt.plot(data)
plt.savefig('data.png')

Here is what I got:

Plot of data

Edit below

Chris mentioned a good point that it might be the high baud rate of 2,000,000 causing the instability. I did think about that when I first ran into this, but then I did a little trick: adding a sinusoid into the constant. If I do that, the weird spiking goes away! I think it indicate that this is not a high baud rate issue... Is it?

Code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 val += int(512 * (sin(float(millis()) * 0.01) + 1)) * 0.1;
 Serial.println(val);
}

Output:

Output

deleted 41 characters in body
Source Link

I am using Arduino Uno Rev 3, and according to this link we can achieve 2000000 baud rate.

This problem can be easily repeated by the following code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 Serial.println(val);
}

I am using the serial-USB cable. To read the data, I used Python pyserial (< 20 lines of code including empty lines and import lines):

import serial
import matplotlib.pyplot as plt
LEN = 10000
data = []
ser = serial.Serial('COM3', baudrate=2000000)
for i in range(LEN):
 try:
 data.append(int(ser.readline()))
 except:
 pass
ser.close()
# %% Plot data
plt.figure(figsize=(6, 4))
plt.plot(data)
plt.savefig('data.png')

Here is what I got:

Plot of data

Edit below

Chris mentioned a good point that it might be the high baud rate of 2,000,000 causing the instability. I did think about that when I first ran into this, but then I did a little trick: adding a sinusoid into the constant. If I do that, the weird spiking goes away! I think it indicate that this is not a high baud rate issue... Is it?

Code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 val += int(512 * (sin(float(millis()) * 0.01) + 1)) * 0.011;
 Serial.println(val);
}

Output:

(Place holder Not by Arduino right now, will update in 12 hours - but I do think it'll fix it)Output

I am using Arduino Uno Rev 3, and according to this link we can achieve 2000000 baud rate.

This problem can be easily repeated by the following code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 Serial.println(val);
}

I am using the serial-USB cable. To read the data, I used Python pyserial (< 20 lines of code including empty lines and import lines):

import serial
import matplotlib.pyplot as plt
LEN = 10000
data = []
ser = serial.Serial('COM3', baudrate=2000000)
for i in range(LEN):
 try:
 data.append(int(ser.readline()))
 except:
 pass
ser.close()
# %% Plot data
plt.figure(figsize=(6, 4))
plt.plot(data)
plt.savefig('data.png')

Here is what I got:

Plot of data

Edit below

Chris mentioned a good point that it might be the high baud rate of 2,000,000 causing the instability. I did think about that when I first ran into this, but then I did a little trick: adding a sinusoid into the constant. If I do that, the weird spiking goes away! I think it indicate that this is not a high baud rate issue... Is it?

Code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 val += int(512 * (sin(float(millis()) * 0.01) + 1)) * 0.01
 Serial.println(val);
}

Output:

(Place holder Not by Arduino right now, will update in 12 hours - but I do think it'll fix it)

I am using Arduino Uno Rev 3, and according to this link we can achieve 2000000 baud rate.

This problem can be easily repeated by the following code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 Serial.println(val);
}

I am using the serial-USB cable. To read the data, I used Python pyserial (< 20 lines of code including empty lines and import lines):

import serial
import matplotlib.pyplot as plt
LEN = 10000
data = []
ser = serial.Serial('COM3', baudrate=2000000)
for i in range(LEN):
 try:
 data.append(int(ser.readline()))
 except:
 pass
ser.close()
# %% Plot data
plt.figure(figsize=(6, 4))
plt.plot(data)
plt.savefig('data.png')

Here is what I got:

Plot of data

Edit below

Chris mentioned a good point that it might be the high baud rate of 2,000,000 causing the instability. I did think about that when I first ran into this, but then I did a little trick: adding a sinusoid into the constant. If I do that, the weird spiking goes away! I think it indicate that this is not a high baud rate issue... Is it?

Code:

void setup() {
 Serial.begin(2000000);
}
void loop() {
 int val = 234;
 val += int(512 * (sin(float(millis()) * 0.01) + 1)) * 0.1;
 Serial.println(val);
}

Output:

Output

added 695 characters in body
Source Link
Loading
Source Link
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /