Go Down

Topic: Arduino serial prints strange character in between figures (Read 1 time) previous topic - next topic

doughng

I want to use an accelerometer with arduino and Unity3d. I printed the serial port values to csv and noticed that its including some strange characters in the stream;
 
Quote
10 10   7
          40   37   15
          MNb??b??j   
         48   24   17


What can I do to correct this?

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

doughng

Code: [Select]
SerialPort stream = new SerialPort("COM8", 9600);  //Set the port (com8) and the baud rate (9600, is standard on most devices)


void Start ()
{
stream.Open(); //Open the Serial Stream
}


void Update ()

{
string value = stream.ReadLine();   
var values = value.Split(',');    //Split incoming stream values on comma into arrays

string path = @"c:\data\accelerometer.CSV";

if(!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
while (value
sw.WriteLine(value);
}
}

using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine(value);
}
}

Nick Gammon

When compiled gives me:

Code: [Select]
sketch_aug23d:15: error: stray '@' in program
sketch_aug23d:0: error: 'SerialPort' does not name a type
sketch_aug23d.cpp: In function 'void Start()':
sketch_aug23d:5: error: 'stream' was not declared in this scope
sketch_aug23d.cpp: In function 'void Update()':
sketch_aug23d:12: error: 'string' was not declared in this scope
sketch_aug23d:12: error: expected `;' before 'value'
sketch_aug23d:13: error: 'var' was not declared in this scope
sketch_aug23d:13: error: expected `;' before 'values'
sketch_aug23d:15: error: expected `;' before 'path'
sketch_aug23d:17: error: 'File' was not declared in this scope
sketch_aug23d:17: error: 'path' was not declared in this scope
sketch_aug23d:19: error: expected nested-name-specifier before '(' token
sketch_aug23d:19: error: expected unqualified-id before '(' token
sketch_aug23d:19: error: expected `;' before '(' token
sketch_aug23d:19: error: 'StreamWriter' was not declared in this scope
sketch_aug23d:19: error: expected `)' before 'sw'
sketch_aug23d:24: error: expected `;' before '}' token
sketch_aug23d:26: error: expected nested-name-specifier before '(' token
sketch_aug23d:26: error: expected unqualified-id before '(' token
sketch_aug23d:26: error: expected `;' before '(' token
sketch_aug23d:26: error: 'StreamWriter' was not declared in this scope
sketch_aug23d:26: error: expected `)' before 'sw'
sketch_aug23d:30: error: expected `;' before '}' token
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

doughng

Oh no, thats the c# code on my Unity3d to read the port and write the values in a csv.

doughng

Is it possible that its doing that because Serial.flush() is missing?

PaulS

Quote
Is it possible that its doing that because Serial.flush() is missing?

Is it possible that your LCD is showing strange characters because you do not throw away random amounts of unread serial data? Not likely.

It is more likely because you are using println() to send data to the LCD, instead of print().

Why can't you post your Arduino code?

Go Up