We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › proHTML with serial communication
Page Index Toggle Pages: 1
proHTML with serial communication (Read 817 times)
proHTML with serial communication
Jan 22nd, 2008, 4:11am
 
Hello there,

I like using the data from a weather website. I got the number from the website by using proHTML library, and I tried to send this number to Arduino board via serial communication. This is my code to send a number to Arduino to control the motor.

import prohtml.*;
import processing.serial.*;

HtmlList htmlList;
Serial myPort;

void setup(){
 size(100,100);
 myPort = new Serial(this, Serial.list()[2], 9600);
}

void draw() {

 htmlList = new HtmlList("http://www.qwikcast.com/cgi-bin/forecast.cgi?zip=Kaohsiung,TW");
   
 println(htmlList.pageList.get(512));
 myPort.write(htmlList.pageList.get(512));
delay(1000);
}
 
And then I got a error message like this:

C:/DOCUME~1/JaeMin/LOCALS~1/Temp/build6856.tmp/Temporary_7990_5751.java:17:5:17:
44: Semantic Error: No applicable overload for a method with signature "write(java.lang.Object)" was found in type "processing.serial.Serial". Perhaps you wanted the overloaded version "void write(java.lang.String $1);" instead?

I read a reference of "write" function in serial. But I could not find any clue for this work. Is there a way to send the data for proHTML? or I would like to hear any comment to send data in proHTML.

Thanks in advance,

Jaemin


Re: proHTML with serial communication
Reply #1 - Jan 22nd, 2008, 2:43pm
 
hi, i have no experience with proHTML... but the error with stating "write(java.lang.Object)" indicates that pageList().get(#) probably doesn't return a String, but a generic Object. Can you try to cast it to a string? I don't know what that method really returns though... but string would make sense:

myPort.write((String) htmlList.pageList.get(512));  
Re: proHTML with serial communication
Reply #2 - Jan 24th, 2008, 11:52pm
 
Dear Extrapixel,

Thank you for your reply to my question. I tried to use string which you recommend in my code, and I got a error message like that:

java.lang.ClassCastException: prohtml.TextElement cannot be cast to java.lang.String

So, I am starting to study about the string instead of using proHTML to get a humidity data from a weather website.

Thanks again,

Jaemin
Re: proHTML with serial communication
Reply #3 - Jan 25th, 2008, 12:14am
 
ok, sorry I wrongly assumed HTMLlist was a list of Strings. I checked the proHTML source and there is a toString() method in the TextElement class. It returns the content of the element as a String.

So... i guess this should work:
myPort.write(htmlList.pageList.get(512).toString());
Re: proHTML with serial communication
Reply #4 - Jan 25th, 2008, 3:16am
 
Dear Extrapixel,

Thank you for your update. I used myPort.write(htmlList.pageList.get(512).toString()); on my code. I got a number of the humidity like 78, and I did not have an error message in the Processing. However, my Arduino did not response from the number. So, I tested using myPort.write(78) in my Processing code, and then Arduino turned a motor.

This is my Arduino code:

#include <Stepper.h>
int val;

#define motorSteps 20    

#define motorPin1 8
#define motorPin2 9
#define motorPin3 10
#define motorPin4 11
#define ledPin 13

Stepper myStepper(motorSteps, motorPin1, motorPin2, motorPin3, motorPin4);

void setup() {
 myStepper.setSpeed(180);
 Serial.begin(9600);
 pinMode(ledPin, OUTPUT);
}

void loop() {
  if (Serial.available()) {
   val = Serial.read();
  }
 if (val == 78) {
  digitalWrite(ledPin, HIGH);
  myStepper.step(10);
 } else {
  digitalWrite(ledPin, LOW);
  myStepper.step(-10);
 }
}

I am wondering that does a toString()method in the proHTML only work for a text? or is it possible to make htmlList element() to the number which works for Arduino?

Thanks in advance,

Jaemin  


Re: proHTML with serial communication
Reply #5 - Jan 25th, 2008, 3:24am
 
ok, you're sending data of the type String now, but your arduino-code is looking for integers. You'll need to turn that string from toString() into an int before sending it to the arduino. check this out: http://processing.org/reference/int_.html
Re: proHTML with serial communication
Reply #6 - Feb 9th, 2008, 5:11am
 
Dear Extrapixel,

Finally, I got a serial communication with the whether website. My motor has a good response from the data, which is chaged from toString() to integer. I really appreciate your advise and concern to me.

Thanks again,

Jaemin
Page Index Toggle Pages: 1