Quantcast
Channel: Android Mode - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 941

android serial usb arduino hiccups?

$
0
0

Hello everyone, i've been working with processing and the android mode for a few days now, and i decided to do this little sensors report when i plug in my android phone to my arduino. i set up the manifest with the vendor IDs and everything and it all works fine but...

even though the arduino Tx lights up continuously (sends data all the time) the processing software looks like it's getting data for a couple of seconds, then looks completely idle for 10 seconds, then takes data again, then no comminucation again... i know the app is not freezing because i'm doing a sliding graph, which happily slides along. any idea what could be causing this hiccup? a buffer overrun?

to be honest i'm trying to make something like a semi-fast DMM, and right now the arduino sends 2 values every 100ms, @38400 baud. is this too fast for the app to handle?

forgive me for the following, but i can't find a code format button...? :D

this is the arduino code:

` void setup() { Serial.begin(38400); pinMode(A0,INPUT); pinMode(A1,INPUT); }

void loop() { Serial.print(analogRead(A0)); Serial.print(";"); Serial.println(analogRead(A1)); delay(150); }`

and the android side:

`import io.inventit.processing.android.serial.*; //ANDROID

//SERIAL PORT Serial myPort; //thermostat serial port String inString=""; //input string from serial port

//FONTS PFont dateFont; //date font

//REALTIME DATA float v1 = 0.0; //voltage1 float v2 = 0.0; //voltage2

//COLORS color activeText = color(182, 230, 244); color inactiveText = color(60, 60, 60);

//BUTTONS transButton resetBtn = new transButton( width/2, height-50, 200, 50, "Reset");

void setup() { fullScreen(); orientation(LANDSCAPE); frameRate(200);

//init fonts dateFont = createFont("WalkwayBold.ttf", 60);

//init USB serial port myPort = new Serial(this, Serial.list(this)[0], 38400); //ANDROID myPort.bufferUntil(10); }

//===========INCOMING DATA FROM THERMOSTAT============= void serialEvent(Serial myPort) { try { inString = myPort.readString(); String[] list = split(inString, ';'); v1 = float(list[0])/1024.0; v2 = float(list[1])/1024.0; } catch(RuntimeException e) { e.printStackTrace(); } }

//===============MAIN LOOP=================== void draw() { //timeNow = millis(); drawMainScreen(); }

//===============DRAWING LOOP=================== void drawMainScreen() { background(36,93,142);

//voltage 1 fill(255); textFont(dateFont); textAlign(LEFT, CENTER); text("v1: " + v1 + "V", 50, 20);

//voltage 2 fill(255); textFont(dateFont); textAlign(LEFT, CENTER); text("v2: " + v2 + "V", 50, 80);

//raw serial input fill(255); textFont(dateFont); textAlign(CENTER, TOP); text("raw: " + inString, 700, 20); `


Viewing all articles
Browse latest Browse all 941