I'm trying to do a very simple call and response sketch with processing and arduino. All I want to do is have processing initiate contact with arduino via serial, get a response from arduino, and then every time arduino ask for more data, have processing send another integer and print it out.
My Processing code is:
import processing.serial.*;
Serial myPort;
int inByte;
void setup() {
myPort = new Serial(this,Serial.list()[0], 9600);
establishContact();
}
void draw() {
//while(myPort.available() <= 0) {
inByte = myPort.read();
if(inByte == 'B') {
for (int i=0; i<=5; i++) {
myPort.write(i);
}
}
}
//}
void establishContact() {
myPort.write('A');
delay(300);
}
And the arduino code is:
#include <NewSoftSerial.h>
boolean firstContact = false;
char inByte;
void setup() {
Serial.begin(9600);
}
void loop() {
//while (Serial.available() > 0){
char inByte = Serial.read();
if(firstContact == false) {
if (inByte == 'A') {
//Serial.flush();
firstContact = true;
delay(300);
Serial.write('B');
}
}
else{
int inByte = Serial.read();
//char val = inByte;
Serial.println(inByte);
delay(500);
Serial.write('B');
}
//}
}
I have found Tom Igoe's example of Call and Response, but it seems to be going in the opposite direction I want. Tried playing with it to turn it around, but no luck. I'm sure it is a ver simple problem, but any help would be really great.
I have been really struggling with this problem for a few days now, and have read lots of threads and tutorials with interfacing with processing, but just can't get my sketch to work!?
I'm a bit of a noob, and it is probably something really easy I'm doing wrong, but an help would be appreciated so much.
I am trying to get processing to perform a yahoo search, and then send the result descriptions one at a time to arduino to be printed off. I then want the arduino to send back a "done" signal to processing to get the next description.
With my current code, the first description just keeps printing repeatedly!? Please help someone - getting very infuriated with it.
Processing Code:
import pyahoo.*;
import com.yahoo.search.WebSearchResults;
import processing.serial.*;
Serial port;
boolean done;
// Create a YahooSearch object. You have to pass in the API key given to you by Yahoo.
YahooSearch yahoo;
char [][]target;
void setup() {
size(200,200);
port = new Serial(this,Serial.list()[0], 9600);
// Make a search object, pass in your key
yahoo = new YahooSearch(this, "B5rzyEvV34EjE7c3OWj3BWOXBrP3f.b3HF9hLPGyB0r5CopLwlFLrvhdw8X1.wQnPE3mtihee94-");
}
void mousePressed() {
// Search for a String. By default you will get back 10 results.
// If you want more (or less), you can request a specific number by saying:
yahoo.search("peter thomas", 5);
}
void draw() {
noLoop();
}
// When the search is complete
void searchEvent(YahooSearch yahoo) {
// Get Titles and URLs
//String[] titles = yahoo.getTitles();
// Search results arrive as an array of Strings.
// You can also get the summaries with getSummaries().
//String[] urls = yahoo.getUrls();
String[] summaries = yahoo.getSummaries();
println(summaries);
int maxSummaryLength = 0;
for (int i=0; i<summaries.length; i++) {
if ( maxSummaryLength < summaries[i].length()) {
maxSummaryLength = summaries[i].length();
}
}
char[][] target = new char[summaries.length][maxSummaryLength];
I am a total beginner to processing, so please forgive me if this is a really question, but I can just not get it work!
I have a piece of processing code which performs a yahoo search, and saves the result descriptions in a string array. I want to send this information to arduino to then print it out from a receipt printer. As I believe, arduino can't handle strings, but uses char arrays instead, so I am trying to convert my string array into a two dimensional char array to then send to arduino.
Any help you could give me would be fantastic!
import pyahoo.*;
import com.yahoo.search.WebSearchResults;
import processing.serial.*;
Serial port;
// Create a YahooSearch object. You have to pass in the API key given to you by Yahoo.
YahooSearch yahoo;
char [][]target;
void setup() {
size(200,200);
port = new Serial(this,Serial.list()[1], 9600);
// Make a search object, pass in your key
yahoo = new YahooSearch(this, "B5rzyEvV34EjE7c3OWj3BWOXBrP3f.b3HF9hLPGyB0r5CopLwlFLrvhdw8X1.wQnPE3mtihee94-");
}
void mousePressed() {
// Search for a String. By default you will get back 10 results.
// If you want more (or less), you can request a specific number by saying: