Removing all non-numeric characters from the serial monitor

Hello, I am using a memsic sensor for tilt to control motor speed and direction. When I use Serial.println to print the values coming from the sensor, I get numbers that would work fine, but they are always preceded by a letter or symbol. It seems to go in order where tilted all the way in one direction starts at letters then goes through the alphabet and then goes to symbols. It may have something to do with communicating to the motor controller, a Sabertooth 2x25 v2. Is there any way to remove any letter from the values but leaving the number and the -, for negative numbers? Thank you very much, this is for my senior project, and this is really the only thing I couldn't find stuff online for.

You will need to post your code for anyone to be able to help.

Sorry about that, heres the code

//use Sabertooth library
#include <SabertoothSimplified.h>

//name the sabertooth “ST”
SabertoothSimplified ST;

const int xPin = 2; //Pin 2 in the x-axis input

int sp;
int pulseX;
int accX;

void setup()
{
SabertoothTXPinSerial.begin(9600); //initialize serial communication
pinMode(xPin, INPUT); //pin 2 is input
}

void loop()
{

pulseX = pulseIn(xPin, HIGH); //read pulse width
accX = ((pulseX / 10) - 500) * 8; //convert to acceleration in milli-g’s

sp = (accX/2);
ST.motor(1,sp);
Serial.println(sp);
}

You should edit your post and place the code between code tags (the # character in the toolbar)

Does the code compile okay as

 SabertoothTXPinSerial.begin(9600);  //initialize serial communication

looks a bit iffy. Apart from that I can see no reason your code would print spurious characters.
Maybe also post a capture of the serial output (in code tags) will help.

Can you show an example of the output?

Hmm... since there is no delay() in your loop, and your baud rate is 9600... you're going to overload your serial buffer. I suspect your problem is due to trying to push too much data through the serial port. Add a delay(1000); statement before tend of your loop and see if that solves the problem.

Sounds a bit suss. "all through the alphabet and then some symbols" might sound a bit like your compiler is not doing what you asked it to and is serialprinting (char)sp instead of the integer sp. Does it look like the ascii symbol set?. If so, it is 50/50 whether your local pc mungs the compile at the Serial.println(sp), or further up. Just in case the latter, what happens if you change

sp = (accX/2);

to

sp = (int)(accX/2);

???

or what happens if you change to Serial.println(sp,HEX); and Serial.println(sp,DEC); //this is meant to be the default for printing of numbers

Also, what PC (brand, cpu, number of cores, clockrate, 32b or 64b) and operating system and arduino ide version number are you working from?

Here’s the normal output

c70.0000000000
d73.0000000000
d72.0000000000
d72.0000000000
e75.0000000000
f76.0000000000
d72.0000000000
f76.0000000000
f77.0000000000
f76.0000000000
f77.0000000000
f76.0000000000
f76.0000000000
g79.0000000000
f77.0000000000
f77.0000000000
g78.0000000000
g79.0000000000
g78.0000000000
g79.0000000000
g79.0000000000
h80.0000000000
h80.0000000000
i82.0000000000
i82.0000000000
i83.0000000000
i82.0000000000
i83.0000000000
i82.0000000000
k87.0000000000
j84.0000000000
i82.0000000000
k86.0000000000
k87.0000000000
j85.0000000000
k87.0000000000
i83.0000000000
k87.0000000000
j84.0000000000
k87.0000000000
k87.0000000000
k87.0000000000
j84.0000000000
k87.0000000000
j84.0000000000
n92.0000000000
n92.0000000000
q98.0000000000
q99.0000000000
q98.0000000000
m90.0000000000
l88.0000000000
j85.0000000000
n92.0000000000
n92.0000000000
n92.0000000000
k87.0000000000
m90.0000000000
l89.0000000000
m91.0000000000
n92.0000000000
n92.0000000000
m91.0000000000
m90.0000000000
l88.0000000000
m90.0000000000
m90.0000000000
n92.0000000000
m91.0000000000
l89.0000000000
n92.0000000000
n93.0000000000
n92.0000000000
m90.0000000000
m90.0000000000
n92.0000000000
n92.0000000000
n92.0000000000
o94.0000000000
m90.0000000000
n92.0000000000
o94.0000000000
n92.0000000000
o94.0000000000
m91.0000000000
n92.0000000000
o95.0000000000
n92.0000000000
o94.0000000000
n92.0000000000
m91.0000000000
m90.0000000000
o94.0000000000
n92.0000000000
l89.0000000000
k87.0000000000
m90.0000000000
l89.0000000000
m91.0000000000
m90.0000000000
n92.0000000000
m90.0000000000
l88.0000000000
k87.0000000000
l89.0000000000
k86.0000000000
l88.0000000000
k87.0000000000
m90.0000000000
m90.0000000000
m90.0000000000
k86.0000000000
m90.0000000000
m90.0000000000
k86.0000000000
l89.0000000000
k87.0000000000
j84.0000000000
k87.0000000000
j84.0000000000
j84.0000000000
j84.0000000000
i82.0000000000
i82.0000000000
g79.0000000000
g79.0000000000
g78.0000000000
f76.0000000000
e75.0000000000
e75.0000000000
e75.0000000000
f76.0000000000
e74.0000000000
e74.0000000000
d72.0000000000
d72.0000000000
d72.0000000000
d72.0000000000
b68.0000000000
b68.0000000000
c70.0000000000
c70.0000000000
b69.0000000000
b69.0000000000
a66.0000000000
a66.0000000000
_62.0000000000
`65.0000000000
`65.0000000000
`65.0000000000
`65.0000000000
`64.0000000000
]59.0000000000
]58.0000000000
]58.0000000000
\57.0000000000
\57.0000000000
\56.0000000000
\57.0000000000
\56.0000000000
Z53.0000000000
Z53.0000000000
Z52.0000000000
Z52.0000000000
Y50.0000000000
Y50.0000000000
X48.0000000000
Y50.0000000000
Y51.0000000000
Y50.0000000000
Y50.0000000000
X49.0000000000
Y50.0000000000
Y50.0000000000
X49.0000000000
X48.0000000000
X48.0000000000
W46.0000000000
V45.0000000000
W46.0000000000
W47.0000000000
V45.0000000000
V44.0000000000
U43.0000000000
U43.0000000000
U43.0000000000
V44.0000000000
T41.0000000000
U42.0000000000
T40.0000000000
U42.0000000000
U42.0000000000
T40.0000000000
S39.0000000000
S39.0000000000
T40.0000000000
T40.0000000000
U42.0000000000
S39.0000000000
S39.0000000000
S38.0000000000
R37.0000000000
R37.0000000000
S38.0000000000
S38.0000000000
S38.0000000000
R37.0000000000
R36.0000000000
S38.0000000000
T40.0000000000
S38.0000000000
R37.0000000000
R37.0000000000
R36.0000000000
R37.0000000000
P33.0000000000
Q34.0000000000
P33.0000000000
Q34.0000000000
P33.0000000000
O30.0000000000
O30.0000000000
P32.0000000000
O30.0000000000
N29.0000000000
N28.0000000000
O30.0000000000
N28.0000000000
M26.0000000000
M27.0000000000
M27.0000000000
N28.0000000000
M27.0000000000
L24.0000000000
M26.0000000000
L25.0000000000
L24.0000000000
L24.0000000000
K23.0000000000
L24.0000000000
K23.0000000000
K23.0000000000
K22.0000000000
J20.0000000000
J20.0000000000
J20.0000000000
J20.0000000000
K22.0000000000
K22.0000000000
I19.0000000000
J20.0000000000
J20.0000000000
K22.0000000000
K22.0000000000
J21.0000000000
K23.0000000000
J20.0000000000
J21.0000000000
I18.0000000000
I18.0000000000
J20.0000000000
H16.0000000000
H16.0000000000
H16.0000000000
H16.0000000000
H16.0000000000
G14.0000000000
F13.0000000000
F12.0000000000
F12.0000000000
E10.0000000000
D8.0000000000
D9.0000000000
F13.0000000000
F12.0000000000
E10.0000000000
E10.0000000000
E10.0000000000
E10.0000000000
D8.0000000000
F12.0000000000
D8.0000000000
E10.0000000000
C6.0000000000
A3.0000000000
A3.0000000000
A2.0000000000
B5.0000000000
@0.0000000000
@0.0000000000
@1.0000000000
?-1.0000000000
?-1.0000000000
?-1.0000000000
?-1.0000000000
>-3.0000000000
@0.0000000000
<-6.0000000000
<-6.0000000000
=-5.0000000000
<-6.0000000000
;-8.0000000000
:-10.0000000000
;-8.0000000000
<-6.0000000000
:-11.0000000000
:-11.0000000000
8-14.0000000000
9-13.0000000000
9-12.0000000000
9-12.0000000000
9-12.0000000000
:-11.0000000000
;-8.0000000000
9-13.0000000000
9-12.0000000000
9-13.0000000000
9-12.0000000000
:-10.0000000000
:-11.0000000000
:-10.0000000000
:-11.0000000000
:-11.0000000000
:-10.0000000000
:-10.0000000000
9-12.0000000000
9-13.0000000000
9-13.0000000000
9-13.0000000000
9-12.0000000000
9-13.0000000000
8-15.0000000000
8-14.0000000000
8-15.0000000000
8-14.0000000000
8-14.0000000000
7-16.0000000000
6-18.0000000000
5-20.0000000000
6-18.0000000000
6-18.0000000000
7-16.0000000000
6-18.0000000000
6-18.0000000000
5-21.0000000000
4-22.0000000000
4-22.0000000000
4-22.0000000000
6-18.0000000000
6-18.0000000000
4-23.0000000000
4-23.0000000000
4-23.0000000000
3-25.0000000000
5-21.0000000000
4-22.0000000000
3-25.0000000000
3-24.0000000000
4-23.0000000000
5-21.0000000000
5-21.0000000000
5-21.0000000000
4-23.0000000000
3-24.0000000000
4-23.0000000000
5-21.0000000000
5-21.0000000000
5-20.0000000000
3-25.0000000000
2-26.0000000000
1-28.0000000000
1-28.0000000000
0-31.0000000000
/-32.0000000000
0-31.0000000000
.-34.0000000000
.-35.0000000000
--36.0000000000
.-35.0000000000
/-33.0000000000

around -65 it starts to pick up symbols, but theres also numbers and stuff.

sp = (int)(acc/2) gave me more symbols before the numbers

\56.00
a67.00
d72.00
i82.00
m90.00
s102.00
r101.00
q99.00
q99.00
q99.00
m90.00
\57.00
?-1.00
#-56.00
-80.00
-95.00

heres Serial.println(sp, DEC)

g78.0000000000
n92.0000000000
r101.0000000000
u106.0000000000
m91.0000000000
_62.0000000000
b69.0000000000
Z52.0000000000
T40.0000000000
P32.0000000000
I18.0000000000
B4.0000000000
=-5.0000000000
7-17.0000000000
.-34.0000000000
$-54.0000000000

Adding a delay(1000) didn’t do anything different

My computer is a mid-2010 Macbook, everything is standard except upgraded RAM to 4gb

Since the Sabertooth is connected to the Tx pin, you are seeing all the motor commands in the serial monitor. Likewise the sabertooth is seeing all the println output. Can you move the Sabertooth to another pin?

Thank you everyone for the help, I actually just removed all the serial stuff and that somehow fixed the problem. Weird but its all good now.