# coding problems not sure about whats wrong

**URL:** <https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866>\
**Category:** Programming\
**Created:** [September 21, 2014, 2:17am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866 "2014-09-21T02:17:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 21, 2014, 2:17am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/1 "2014-09-21T02:17:39Z")

</div>

this is my first post and i think i am just asking a stupid question but i don't know for sure. I am following this code below from my book and I understand that it is supposed to run on the computer;but how do I make it do that.

import processing.serial.\*;  
String feed = "hppt://blog.makezine.com/index.xml";  
int intirval = 10;  
int lastTime;  
int love = 0;  
int peace = 0;  
int arduino = 0;  
int light = 0;  
Serial port;  
color c;  
String cs;  
String buffer = "";  
PFont font;  
void setup() {  
size(640, 480);  
frameRate(10);  
font = loadFont("HelveticaNueue-Bold-32.vlw");  
fill(255);  
textFont(font, 32)  
String arduinoPort = Serial.list()[3];  
port = new Serial(this, arduinoPort, 9600);  
lastTime = 0;  
fetchData();  
}  
void draw() {  
backround( c );  
int n = (interval - ((milis() - lastTime) / 1000));  
c = color(peace, love, arduino);  
cs = "#" + hex(c, 6);  
text("Arduino Networked Lamp", 10, 40);  
text("Reading feed", 10, 100);  
text(feed, 10, 140);  
text("Next update in " + n + " seconds", 10, 450);  
text("peace" , 10, 200);  
text("" + peace, 130, 200);  
rect(200, 172, peace, 28);  
text("love", 10, 200);  
text("" + love, 130 240);  
rect(200, 212, love, 28);  
text("arduino ", 10, 280);  
text("" + arduino, 130, 280);  
rect(200, 252, arduino, 28);  
text("sending", 10, 340);  
text(cs, 200, 340);  
text("light level", 10, 380);  
rect(200, 352, light / 10.23, 28);  
if (n \<= 0) {  
fetchData();  
lastTime = millis();  
}  
port.write(cs);  
if (port.avaliable() \> 0) {  
int inByte = port.read();  
if (inByte != 10) {  
buffer = buffer + char(inByte);  
}  
else {  
if (buffer.length() \> 1) {  
buffer = buffer.substring(0, buffer.length() - 1);  
light = int(buffer);  
buffer = "";  
port.clear();  
}  
}  
}  
void fetchData() {  
String data;  
String chunk:  
love = 0  
peace = 0;  
arduino = 0:  
try {  
URL url = new Url(feed);  
URLConnection conn = url.openConnection();  
conn.connect();  
BufferedReader in = new  
BufferedReader(new InputStreamReader(conn.getInputStream()));  
while ((data = in, readLine()) != null) {  
StringTokenizer st =  
new StringTokenizer(data, ""\<\>,.()[] ");  
while (st.hasMoreTokens()) {  
chunk = st.nextToken().toLowerCase() ;  
if (chunk.indexOf("love") \>= 0 )  
love++;  
if (ckunk.indexOf("peace") \>= 0)  
peace++;  
if (chunk.indexOf("arduino") \>= 0)  
arduino++;  
}  
}  
if (peace \> 64) peace = 64;  
if (love \> 64) love = 64;  
if (arduino \> 64) arduino = 64;  
peace = peace \* 4;  
love = love \* 4;  
arduino = arduino \* 4;  
}  
catch (Exeption ex) {  
ex.printStackTrace();  
System.out, println("ERROR: " + ex.getMessage());  
}  
}

---

<div class="post-metadata">

**Author:** ![Piethon](https://avatars.discourse-cdn.com/v4/letter/p/94ad74/32.png) [@Piethon](https://forum.arduino.cc/u/Piethon)\
**Post date:** [September 21, 2014, 4:02am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/2 "2014-09-21T04:02:34Z")

</div>

Please make sure you post any code within the code tags, so it's easier to read. just put [_code][_/code] around it (without the \* though)

Also, it looks like you're looking to run this code with Processing. I would suggest first looking at the [Arduino with Processing](http://playground.arduino.cc/interfacing/processing) tutorial.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 21, 2014, 2:30pm UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/3 "2014-09-21T14:30:30Z")

</div>

thanks 🙂

---

<div class="post-metadata">

**Author:** ![Piethon](https://avatars.discourse-cdn.com/v4/letter/p/94ad74/32.png) [@Piethon](https://forum.arduino.cc/u/Piethon)\
**Post date:** [September 21, 2014, 5:07pm UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/4 "2014-09-21T17:07:08Z")

</div>

> captianillogical:  
> thanks 🙂

Also, just a quick note, it looks like you have a typo:

```arduino
String feed = "hppt://blog.makezine.com/index.xml";

```

Shouldn't that be 'http'? 😛

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 21, 2014, 7:12pm UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/5 "2014-09-21T19:12:05Z")

</div>

> Shouldn't that be 'http'?

There are two typos. char \* is seriously misspelled, too.

---

<div class="post-metadata">

**Author:** ![Henry\_Best](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/henry_best/32/1013044_2.png) [@Henry\_Best](https://forum.arduino.cc/u/Henry_Best)\
**Post date:** [September 22, 2014, 3:02am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/6 "2014-09-22T03:02:13Z")

</div>

There's also a 'ckunk' where I think he means 'chunk'.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 6, 2014, 10:49pm UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/7 "2014-10-06T22:49:25Z")

</div>

i am having a problem with the command `void fetchData(){ `in processing i am in java mode of processing what is the problem also this is the same code from earlier

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 7, 2014, 12:52am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/8 "2014-10-07T00:52:56Z")

</div>

```cpp
import processing.serial.*;
String feed = "hppt://blog.makezine.com/index.xml";
int intirval = 10;
int lastTime;
int love  = 0;
int peace  = 0;
int arduino  = 0;
int light = 0;
Serial port;
color c;
String cs;
String buffer = "";
PFont font;
void setup(){
  size(640,480);
  frameRate(10);
  font = loadFont("HelveticaNueue-Bold-32.vlw");
  fill(255);
  textFont(font, 32);
  String arduinoPort = Serial.list()[0];
  port = new Serial(this, arduinoPort, 9600);
  lastTime = 0;
   fetchData();
}
void draw(){
  backround( c );
  int n = (interval - ((milis()-lastTime)/1000));
  c = color(peace, love, arduino);
  cs = "#" + hex(c,6);
  text("Arduino Networked Lamp", 10, 40);
  text("Reading feed", 10, 100);
  text(feed, 10, 140);
  text("Next update in "+ n + " seconds",10,450);
  text("peace" ,10,200);
  text("" + peace, 130, 200);
  rect(200,172, peace, 28);
  text("love",10,200);
  text(""+ love, 130, 240);
  rect(200,212, love, 28);
  text("arduino ",10,280);
  text("" + arduino, 130, 280);
  rect(200,252, arduino, 28);
  text("sending", 10, 340);
  text(cs, 200,340);
  text("light level", 10, 380);
  rect(200, 352,light/10.23,28);
  if (n <= 0){
    fetchData();
    lastTime = millis();
  }
  port.write(cs);
  if (port.avaliable() > 0) {
    int inByte = port.read();
    if (inByte != 10) {
      buffer = buffer + char(inByte);
    }
    else{
      if (buffer.length() > 1) {
        buffer = buffer.substring(0,buffer.length() -1);
        light = int(buffer);
        buffer = "";
        port.clear();
      }
    }
  }
   fetchData
    String data;
    String chunk;
    love  =0;
    peace =0;
    arduino =0;
    try{
      URL url = new Url(feed);
      URLConnection conn = url.openConnection();
      conn.connect();
      BufferedReader in = new
      BufferedReader(new InputStreamReader(conn.getInputStream()));
      while ((data = in.readLine()) != null){
        StringTokenizer st =
        new StringTokenizer(data,"\"<>,.()[] ");
        while (st.hasMoreTokens()){
          chunk= st.nextToken().toLowerCase();
          if (chunk.indexOf("love") >= 0 )
            love++;
          if (chunk.indexOf("peace") >= 0)
          peace++;
          if (chunk.indexOf("arduino") >= 0)
          arduino++;
        }
      }
      if (peace > 64)  peace = 64;
      if (love > 64)  love = 64;
      if (arduino > 64) arduino = 64;
      peace = peace * 4;
      love = love * 4;
      arduino = arduino * 4;
    }
    catch (Exeption ex) {
      ex.printStackTrace();
      System.out.println("ERROR: "+ex.getMessage());
    }
  }

```

im doing this sketch from my book and i am having a lot of problems.I understand that it is Processing code and every time i try to run processing with the arduino plugin it just crashes! Also can i run this program without the plugin. in conclusion i am unsure about pretty much everything. plaese help

---

<div class="post-metadata">

**Author:** ![partsofme](https://avatars.discourse-cdn.com/v4/letter/p/c4cdca/32.png) [@partsofme](https://forum.arduino.cc/u/partsofme)\
**Post date:** [October 7, 2014, 1:18am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/9 "2014-10-07T01:18:39Z")

</div>

hppt://blog.makezine.com/index.xml should use http instead of hppt... try that?

---

<div class="post-metadata">

**Author:** ![michinyon](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@michinyon](https://forum.arduino.cc/u/michinyon)\
**Post date:** [October 7, 2014, 1:20am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/10 "2014-10-07T01:20:09Z")

</div>

this is a processing problem, not an arduino problem.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 7, 2014, 11:29am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/11 "2014-10-07T11:29:27Z")

</div>

```cpp
  String arduinoPort = Serial.list()[0];

```

If Serial.list() returns NULL, because there are no com ports that the Arduino could be listening to, referencing the first item in the non-existent list WILL cause a crash.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 7, 2014, 11:47am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/12 "2014-10-07T11:47:01Z")

</div>

> i am having a problem with the command

Bummer, dude!

Now, if you defined what the problem was, maybe we could offer some suggestions.

> i am in java mode of processing

What the heck does this mean?

> what is the problem also this is the same code from earlier

Complete lack of punctuation.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 8, 2014, 12:36am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/13 "2014-10-08T00:36:59Z")

</div>

`unexpected token void` was command my problem  
ignore my punctuation and and at the top right it says mode manager and i cant get rid of java mode without another mode such as python

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 8, 2014, 12:42am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/14 "2014-10-08T00:42:44Z")

</div>

> michinyon:  
> this is a processing problem, not an arduino problem.-michinyon

everyone on processing says this is an arduino problem

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 8, 2014, 12:45am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/15 "2014-10-08T00:45:44Z")

</div>

> was command my problem

Could be that because of your piss-poor indenting, you are trying to define the fetchData() function inside the draw() function.

> at the top right it says mode manager

At the top, right of what?

Idontunderstandwhyyouthinkpunctuationandpropercapitalizationdoesn'tmatter.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 8, 2014, 12:53am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/16 "2014-10-08T00:53:15Z")

</div>

> everyone on processing says this is an arduino problem

> and every time i try to run processing with the arduino plugin it just crashes!

Unplug the Arduino. Run Processing. Does it crash? If so, it can't possibly be an Arduino problem.

You should print the list returned by Serial.list(), with delimiters before and after the list, so the list is quite clear. If the list is empty, you have one problem. If it's not, you have another problem. Which one are we trying to help you solve?

---

<div class="post-metadata">

**Author:** ![nickgammon](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nickgammon](https://forum.arduino.cc/u/nickgammon)\
**Post date:** [October 8, 2014, 1:50am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/19 "2014-10-08T01:50:49Z")

</div>

Isn't there a Processing forum?

---

<div class="post-metadata">

**Author:** ![nickgammon](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nickgammon](https://forum.arduino.cc/u/nickgammon)\
**Post date:** [October 8, 2014, 1:54am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/20 "2014-10-08T01:54:14Z")

</div>

Please **do not cross-post**. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

- Moderator

---

<div class="post-metadata">

**Author:** ![nickgammon](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nickgammon](https://forum.arduino.cc/u/nickgammon)\
**Post date:** [October 8, 2014, 2:00am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/21 "2014-10-08T02:00:50Z")

</div>

Here is the same question on the Processing forum:

[http://forum.processing.org/two/discussion/7485/how-to-get-arduino-to-work-with-processing](http://forum.processing.org/two/discussion/7485/how-to-get-arduino-to-work-with-processing)

> quark:  
> I have moved this to the Arduino forum
> 
> In line 2 should it not be http rather than hppt

> captianillogical:  
> everyone on processing says this is an arduino problem

Everyone? One person moved your post to the **Arduino section** of the Processing forum. They did not tell you to go to the Arduino forum.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 8, 2014, 7:07am UTC](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866/23 "2014-10-08T07:07:36Z")

</div>

> PaulS:
> 
> > Shouldn't that be 'http'?
> 
> There are two typos. char \* is seriously misspelled, too.

😃

[Next page](https://forum.arduino.cc/t/coding-problems-not-sure-about-whats-wrong/258866.md?page=2)
