Go Down

Topic: how to interpret the serial data (Read 9789 times) previous topic - next topic


The problem looks to be that you're never printing the value of "inData" when it has some dta a in it.
Move the final "print" inside the "started && ended" condition, but before you reset the string.


Mar 14, 2013, 05:35 pm Last Edit: Mar 14, 2013, 05:37 pm by AWOL Reason: 1
The problem?
You didn't open the serial monitor, you didn't select the correct line speed, you didn't compile the code, you didn't upload the code, you didn't hit "send"...
It works, perfectly.


im sory....it works it print but the problem is it auto scroll...


You'll have to explain what that means, and why you perceive it to be a problem.


THANK YOU very much...is it functional of what i want to do as what i said in my first post?


is it functional if the computer will send two type of  data for example <jvvmv>{fff},is it posible to use two start and end maker...


is it posible to use two start and end maker...

Yes, but...

<jvvmv,fff> is easier to deal with. Save all the data, then use strtok() to parse into jvvmv and fff.

With two start and end markers, you need two arrays, and you need to keep track of which array to store a character in. Does f go in the first buffer or the second buffer?


what i need to do?
you need to start thinking for longer than 20 minutes at a time, and working through some of the examples in the IDE.
I believe I've said this before, but it's worth repeating.

(Hint: you haven't written anything called "sendCommand" yet.)



This example may help you grasp the basics.

Code for Arduino:

Code: [Select]
void setup() {

void loop() {

Code for Processing:
Code: [Select]
import processing.serial.*;

Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph

void setup () {
// set the window size:
size(400, 300);       

// List all the available serial ports
// I know that the first port in the serial list on my mac
// is always my  Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
// set inital background:
void draw () {
// everything happens in the serialEvent()

void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');

if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0, height);

// draw the line:
line(xPos, height, xPos, height - inByte);

// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
else {
// increment the horizontal position:

Go Up