Go Down

Topic: Re: Arduino Mega Kit source example (Program Cod) (Read 1 time) previous topic - next topic

Dimitar Wodenicharov

hello,i`ve just buyed Arduino Mega Kit,but i`ve never worked with it and i want to ask if someone could give me an example program to visualize some data on PC through USB interface...it doesn`t matter what data would be power,current or voltage

thank you !!!

Yot

Hi  Dimitar.

If you start the arduino IDE, open file->examples->communication->Graph and read the text in that sketch. The sketch also gives code for processing (http://processing.org/) and Max/MSP as programs for on your computer.

Jeroen

Dimitar Wodenicharov

Thank you for the previous info. I saw the materials witch you point me but because I'm a beginner I couldn't handle myself.If this doesn't bother you could you give me the program ( code) and its algorithm with witch to visualize the value of Power.

Yot

I (we) will help you with problems as they arise but i will not write your code.

Quote
...witch to visualize the value of Power.

Power of what? Can you explain what it is that you want to accomplish?

Jeroen

Dimitar Wodenicharov

i want to visualize on my pc connected to the  board with usb interface voltage from some analog input

Yot

Ok. If you try what i explained in reply 1 what is the first problem you have?

Jeroen

Dimitar Wodenicharov

i can`t find the source code(program) to visualize voltage

Yot

It's between
Quote
/* Processing code for this example
and
Quote
xPos++;
}
}
}

*/
In the arduino sketch i pointed you to.

You should copy/paste that to the processing program on the pc and remove what is highlighted below.
Quote
[glow]/* Processing code for this example[/glow]
..
..
..
..
// increment the horizontal position:
xPos++;
}
}
}

[glow]*/[/glow]


Probably a better advice would be to experiment with some (all) of the examples (like digital->blink) before you do a 'full project' to learn some programming/syntax.  While it seems that that doesn't help you with your goal it is actually vitally important.

Jeroen

Dimitar Wodenicharov

is this the program(cod) I need to visiolize the voltage

/* Processing code for this example

// Graphing sketch


// This program takes ASCII-encoded strings
// from the serial port at 9600 baud and graphs them. It expects values in the
// range 0 to 1023, followed by a newline, or newline and carriage return

// Created 20 Apr 2005
// Updated 18 Jan 2008
// by Tom Igoe

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
println(Serial.list());
// 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:
myPort.bufferUntil('\n');
// set inital background:
background(0);
}
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:
stroke(127,34,255);
line(xPos, height, xPos, height - inByte);

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

*/

Yot

#9
Dec 18, 2009, 12:34 pm Last Edit: Dec 18, 2009, 12:37 pm by Yot Reason: 1
Yep. That's the code to paste in processing on your pc. Remember to remove the lines that are highlighted in reply 7.

Jeroen

edit: If you post code please use the #-button.

Dimitar Wodenicharov

is this the program(cod) ?


// Graphing sketch


// This program takes ASCII-encoded strings
// from the serial port at 9600 baud and graphs them. It expects values in the
// range 0 to 1023, followed by a newline, or newline and carriage return

// Created 20 Apr 2005
// Updated 18 Jan 2008
// by Tom Igoe

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
println(Serial.list());
// 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:
myPort.bufferUntil('\n');
// set inital background:
background(0);
}
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:
stroke(127,34,255);
line(xPos, height, xPos, height - inByte);

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

Yot

Have you tried? What did it do?
You actually have to do something yourself.

Jeroen


Dimitar Wodenicharov

I haven't got any knowledge of this program but I've been assign a task to visualize the voltage. Can I use a ready code from somewhere, coz I can't write it by myself.

Yot

If you spend a couple of hours reading the examples in the arduino IDE and processing IDE you will have the knowledge to do what you want by copy/pasting.  

If you don't want to do that then the simplest way of 'visualize the voltage' will probably a multimeter.



Jeroen

Go Up