Pages: [1] 2   Go Down
Author Topic: Newbie programming code assistance  (Read 756 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all!  I am helping my daughter put together a science fair project (Galvanic Skin Response Tester) and I managed to get the arduino Uno working, but there is an example graph code that I need to program in order to get it to work and I have no idea how to enter it.  I have Cygwin downloaded, and I have the code, but since I don't know how to enter it we're kinda at a standstill.

My question is: Can I copy and paste the whole code?  Or do I need to enter everything manually?  Should I hit enter after every line?  If I can please get someone to provide ANY assistance, I'd be so grateful.  Thank you kindly.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 27363
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, you can copy & paste the whole code.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

Thank you so very much for the rapid reply! 

Ok, just tried it and each line is giving me a -bash and command not found error.  Any ideas, clues, or even lifelines?  smiley
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26509
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't imagine why you're getting bash errors.
You are using the IDE, aren't you?
If not, why not?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

More than likely it's because I have NO idea what I am doing and need some help or guidance from someone who can possibly talk me thru or walk me thru this.  I'm kinda stuck here.

This is the site we are using to build the model:  http://lifehacker.com/5902483/create-a-diy-polygraph-machine-with-tin-foil-and-an-arduino

And this is the code that is given.


Code:
/*
   Graph
  
  A simple example of communication from the Arduino board to the computer:
  the value of analog input 0 is sent out the serial port.  We call this "serial"
  communication because the connection appears to both the Arduino and the
  computer as a serial port, even though it may actually use
  a USB cable. Bytes are sent one after another (serially) from the Arduino
  to the computer.
  
  You can use the Arduino serial monitor to view the sent data, or it can
  be read by Processing, PD, Max/MSP, or any other program capable of reading
 data from a serial port.  The Processing code below graphs the data received
 so you can see the value of the analog input changing over time.
  
  The circuit:
  Any analog input sensor is attached to analog in pin 0.
  
 created 2006
  by David A. Mellis
  modified 9 Apr 2012
  by Tom Igoe and Scott Fitzgerald
  
  This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/Graph
  */
 
void setup() {
   // initialize the serial communication:
   Serial.begin(9600);
 }
 
void loop() {
   // send the value of analog input 0:
   Serial.println(analogRead(A0));
   // wait a bit for the analog-to-digital converter
  // to stabilize after the last reading:
   delay(2);
 }

Code:
/* 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
  // This example code is in the public domain.
  
  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++;
  }
  }
  }
  
  */

Code:
/* Max/MSP v5 patch for this example
  ----------begin_max5_patcher----------
 1591.3oc0YszbaaCD9r7uBL5RalQUAO3CvdyS5zVenWZxs5NcfHgjPCIfJIT
 RTxj+6AOHkoTDooroUs0AQPR73a+1cwtK3WtZxzEpOwqlB9YveAlL4KWMYh6
 Q1GLo99ISKXeJMmU451zTUQAWpmNy+NM+SZ2y+sR1l02JuU9t0hJvFlNcMPy
 dOuBv.U5Rgb0LPpRpYBooM3529latArTUVvzZdFPtsXAuDrrTU.f.sBffXxL
 vGE50lIHkUVJXq3fRtdaoDvjYfbgjujaFJSCzq4.tLaN.bi1tJefWpqbO0uz
 1IjIABoluxrJ1guxh2JfPO2B5zRNyBCLDFcqbwNvuv9fHCb8bvevyyEU2JKT
 YhkBSWPAfq2TZ6YhqmuMUo0feUn+rYpY4YtY+cFw3lUJdCMYAapZqzwUHX8S
 crjAd+SIOU6UBAwIygy.Q1+HAA1KH6EveWOFQlitUK92ehfal9kFhUxJ3tWc
 sgpxadigWExbt1o7Ps5dk3yttivyg20W0VcSmg1G90qtx92rAZbH4ez.ruy1
 nhmaDPidE07J+5n2sg6E6oKXxUSmc20o6E3SPRDbrkXnPGUYE.i5nCNB9TxQ
 jG.G0kCTZtH88f07Rt0ZMMWUw8VvbKVAaTk6GyoraPdZff7rQTejBN54lgyv
 HE0Ft7AvIvvgvIwO23jBdUkYOuSvIFSiNcjFhiSsUBwsUCh1AgfNSBAeNDBZ
 DIDqY.f8.YjfjV1HAn9XDTxyNFYatVTkKx3kcK9GraZpI5jv7GOx+Z37Xh82
 LSKHIDmDXaESoXRngIZQDKVkpxUkMCyXCQh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01xzl
 c3ZhUCtSHx3UZgjoEJYqNY+hYs5zZQVFW19L3JDYaTlMLqAAt1G2yXlnFg9a
 53L1FJVcv.cOX0dh7mCVGCLce7GFcQwDdH5Ta3nyAS0pQbHxegr+tGIZORgM
 RnMj5vGl1Fs16drnk7Tf1XOLgv1n0d2iEsCxR.eQsNOZ4FGF7whofgfI3kES
 1kCeOX5L2rifbdu0A9ae2X.V33B1Z+.Bj1FrP5iFrCYCG5EUWSG.hhunHJd.
 HJ5hhnng3h9HPj4lud02.1bxGw.
 -----------end_max5_patcher-----------
  
 */


However, if the problem is the processing program that I am using, please feel free to let me know.  Thank you again so very much!

Moderator edit: Code tags.
« Last Edit: November 15, 2012, 10:22:21 am by AWOL » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26509
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, slow down.
Have you downloaded the Processing IDE? (Processing.org)
Have you downloaded the Arduino IDE?  (Arduino.cc)

If not, do so now.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

Yes, I have downloaded both.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26509
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, so start the Processing IDE and paste the Processing code into it, and start the Arduino IDE and post the Arduino code into that.
It looks to me that the Processing code, for some obscure reason, is one big comment, so paste this instead:
Code:
// 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
  // This example code is in the public domain.
 
  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++;
  }
  }
  }
 
 
« Last Edit: November 15, 2012, 10:25:24 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

Thank you again, so very much, for all your assistance.

I copied everything (was that the right thing to do?) and pasted it into the program.  Here is what I am getting (and this is just from the last few lines of the code):

chasenmayra@chasenmayra-PC /home/chasenmayra
$   // increment the horizontal position:
-bash: //: is a directory

chasenmayra@chasenmayra-PC /home/chasenmayra
$   xPos++;
-bash: xPos++: command not found

chasenmayra@chasenmayra-PC /home/chasenmayra
$   }
-bash: syntax error near unexpected token `}'

chasenmayra@chasenmayra-PC /home/chasenmayra
$   }
-bash: syntax error near unexpected token `}'

chasenmayra@chasenmayra-PC /home/chasenmayra
$   }
-bash: syntax error near unexpected token `}'
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 107
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Unfortunately, the link from the lifehacker post isn't working for me.  It is not at all clear to me why you downloaded and installed cygwin, and what bash has to do with this application.  The Arduino code goes into the Arduino IDE, and the Processing code goes into the Processing IDE.  I have no idea what the Max/MSP v5 patch (the last block of stuff you posted) does at all.  I don't see any reason to be using Cygwin at all.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 642
Posts: 50365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I copied everything (was that the right thing to do?) and pasted it into the program.
Into what program? It appears that there are three parts to the project. It helps if you say what part you are working on.
Logged

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

Thank you everyone, so much, for your patience.

Perhaps it will help if I just tell you what I have done from the beginning, because I may be missing some steps and wouldn't know it if I did.

http://mad-science.wonderhowto.com/how-to/diy-polygraph-machine-detect-lies-with-tin-foil-wire-and-arduino-0134599/

That is the actual site that gives all instructions for creating this.

We created the sensors and did all the wiring for the Arduino and the breadboard.

Step 3 is where I got lost.  I downloaded the processing application from the site, and ended up with cygwin from there.
I then connected the Arduino to my laptop using a USB cord.  The Arduino lit up (steady green and blinking orange), but the computer would not install it.  Anyway, we got that taken care of and the driver installed.  Now, the rest is where I am extremely lost.  And since I don't understand the programming language, that is also making it a bit difficult to continue.  smiley  Please let me know if I can provide additional information.  Thank you again.
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 107
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm thinking you may have downloaded the wrong file for Processing.  Was it this one?
http://processing.googlecode.com/files/processing-1.5.1-windows.zip

I don't believe cygwin is at all required to use Processing.
Logged

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

No, that was not it at all, but I downloaded the one from the link you just provided and it is running!!!!  THANK YOU!
Ok, now is there something else I need to be looking for and downloading in order to run the Arduino then?
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 107
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino IDE is found here:
http://arduino.googlecode.com/files/arduino-1.0.2-windows.zip
Logged

Pages: [1] 2   Go Up
Jump to: