Pages: [1]   Go Down
Author Topic: Arduino serial prints strange character in between figures  (Read 1290 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18720
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You post your code.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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);
}
}
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18720
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When compiled gives me:

Code:
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
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49033
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Pages: [1]   Go Up
Jump to: