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 › Processing and ArduinoBT
Page Index Toggle Pages: 1
Processing and ArduinoBT (Read 2700 times)
Processing and ArduinoBT
Sep 2nd, 2008, 7:57am
 
Hello I am having some issues getting an ArduinoBT working with Processing. here is the output I am getting.

Code:

2008-09-02 01:52:33.341 java[33923:c1b] Can't open input server /Library/InputManagers/Smart Crash Reports.bundle

Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
[0] "/dev/tty.Bluetooth-PDA-Sync"
[1] "/dev/cu.Bluetooth-PDA-Sync"
[2] "/dev/tty.LGTG800-SerialPort-1"
[3] "/dev/cu.LGTG800-SerialPort-1"
[4] "/dev/tty.BrownBandit-Bluetooth-P-1"
[5] "/dev/cu.BrownBandit-Bluetooth-P-1"
[6] "/dev/tty.Bluetooth-Modem"
[7] "/dev/cu.Bluetooth-Modem"
[8] "/dev/tty.LGTG800-Dial-upnetworki-2"
[9] "/dev/cu.LGTG800-Dial-upnetworki-2"
[10] "/dev/tty.ARDUINOBT-BluetoothSeri-1"
[11] "/dev/cu.ARDUINOBT-BluetoothSeri-1"
JSyn using native library JSynV144
Experimental: JNI_OnLoad called.
CSyn 14.4 (C) 1997-2007 Phil Burk, Mobileer Inc built on Dec 23 2007 at 15:33:13
JSyn for OS X, Built on Dec 23 2007.
Input Device #7: Unknown USB Audio Device has 1 channels
Input Device #3: Built-in Line Output has 2 channels

gnu.io.PortInUseException: Unknown Application

at gnu.io.CommPortIdentifier.open(CommPortIdentifier.java:354)

at processing.serial.Serial.<init>(Serial.java:136)

at processing.serial.Serial.<init>(Serial.java:102)

at interface_1.setup(interface_1.java:54)

at processing.core.PApplet.handleDraw(PApplet.java:1377)

at processing.core.PApplet.run(PApplet.java:1305)

at java.lang.Thread.run(Thread.java:613)
Exception in thread "Animation Thread" java.lang.RuntimeException: Error inside Serial.<init>()

at processing.serial.Serial.errorMessage(Serial.java:588)

at processing.serial.Serial.<init>(Serial.java:148)

at processing.serial.Serial.<init>(Serial.java:102)

at interface_1.setup(interface_1.java:54)

at processing.core.PApplet.handleDraw(PApplet.java:1377)

at processing.core.PApplet.run(PApplet.java:1305)

at java.lang.Thread.run(Thread.java:613)


any suggestions how I can fix this?

I have tried using the Arduino Serial Proxy.

Code:

/*
###################################################################################
Audio visual interface - for nuit blance
sketch and hardware (c)2008 August 20 Brian Durocher
___________________________________________________________________________________
uses Arduino Library from
http://www.arduino.cc/playground/uploads/Interfacing/processing-arduino2.zip

Serial

Sound libray - Sonia
Requires JSyn Library Win / Mac / Linux

###################################################################################
for interactive project with Emmanuelle Raynault (Paris), Duncan MacDonald (Canada),
and myself Brian Durocher (Canada)

for questions or concerns please contact Brian Durocher at brian.durocher@gmail.com



###################################################################################
*/

import pitaru.sonia_v2_9.*;
import processing.serial.*;
import cc.arduino.*;


Sample mySample;

String portname0="/dev/tty.ARDUINOBT-BluetoothSeri-1";
String portname1="";
String portname2="";
Serial port0; // Create object from Serial class
Serial port1;
Serial port2;
//perhaps create an abstract datatype such as a struct for this.
//must also conform to the BT-Arduino's Protocol.
int val0; // Data received from the serial port
int val1;
int val2;

void setup()
{
println(Arduino.list());
size(512, 200);
Sonia.start(this); // Start Sonia engine.
// create a new sample object.
mySample = new Sample("sine.aiff");


// Open the port that the board is connected to and use the same speed (9600 bps)
port0 = new Serial(this, portname0, 115200); //115200 baud for Arduino Bluetooth board.
port1 = new Serial(this, portname1, 115200);
port2 = new Serial(this, portname2, 115200);
}

void setRate(){
// set the speed (sampling rate) of the sample.
// Values:
// 0 -> very low pitch (slow playback).
// 88200 -> very high pitch (fast playback).
//float rate = (height - mouseY)*88200/(height);
float rate = 44000;
mySample.setRate(rate);
}


void draw(){

//val0 = port0.read(); // read port and store it in val

//println(val0);


//play audio if values are withing range
background(0);

//background(0);
stroke(0);
rectMode(CENTER);
fill(204, 0, 0);
rect(100, 20, 5, 5);
rectMode(CENTER);
fill(204, 0, 0);
rect(120, 20, 5, 5);
rectMode(CENTER);
fill(204, 0, 0);
rect(140, 20, 5, 5);
}//end of draw


void keyPressed() {
if (key == 'a'){
mySample.repeat();
}
else if(key == 's'){
mySample.stop();
}
}

public void serialEvent(Serial which) {
if (which == port0) {
delay(10);
val0 = port0.read(); // read port and store it in val
delay(100);
val1 = port0.read();
delay(100);
val2 = port0.read();
delay(100);
println(val0);
println(val1);
println(val2);
}
else if (which == port1) {
// do something else to read from port1
}
else if (which == port2){
//do something else to read from port2
}
}

void stop()
{
// always close Sonia audio classes when you are done with them
// dealocates memory space
Sonia.stop();
super.stop();
}
Re: Processing and ArduinoBT
Reply #1 - Sep 3rd, 2008, 5:58am
 
Corrected the issue using this link

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Electronics;action=display;num=1212032726

Load the ArduinoBT with the firmata firmware .pde file. I used simple_analog.pde for this test. Works Great.

Pins 0, 1, 2 have TEMT6000 ambient light sensors attached to them.

Code:

/*
###################################################################################
Audio visual interface - for nuit blance
sketch and hardware (c)2008 August 20 Brian Durocher
___________________________________________________________________________________
uses Arduino Library from
http://www.arduino.cc/playground/uploads/Interfacing/processing-arduino2.zip

Serial

Sound libray - Sonia
Requires JSyn Library Win / Mac / Linux

###################################################################################
for interactive project with Emmanuelle Raynault (Paris), Duncan MacDonald (Canada),
and myself Brian Durocher (Canada)

for questions or concerns please contact Brian Durocher at brian.durocher@gmail.com

ArduinoBT Must Be Reset just before program execution for this to work.
Board is loaded with Firmata firmware


###################################################################################
*/

import pitaru.sonia_v2_9.*;
import processing.serial.*;
import cc.arduino.*;


Sample mySample;

int analogPin0 = 0;
int analogPin1 = 1;
int analogPin2 = 2;

int analogValue0 = 0;
int analogValue1 = 0;
int analogValue2 = 0;
Arduino arduino;

void setup()
{
println(Arduino.list());
size(512, 200);
Sonia.start(this); // Start Sonia engine.
// create a new sample object.
mySample = new Sample("sine.aiff");

arduino = new Arduino(this, Arduino.list()[10], 57600); //open up arduino for use with processing

}


void draw(){


analogValue0 = arduino.analogRead(analogPin0);
int inByte0 = int(map(analogValue0,0,1023,0,255)); // mapping the analogSensor values (0-1023) to values between 0-255
println(analogValue0);
analogValue1 = arduino.analogRead(analogPin1);
int inByte1 = int(map(analogValue1,0,1023,0,255)); // mapping the analogSensor values (0-1023) to values between 0-255
println(analogValue1);
analogValue2 = arduino.analogRead(analogPin2);
int inByte2 = int(map(analogValue2,0,1023,0,255)); // mapping the analogSensor values (0-1023) to values between 0-255
println(analogValue2);


//play audio if values are withing range
background(0);

//background(0);
stroke(0);
rectMode(CENTER);
fill(inByte0, 0, 0);
rect(100, 20, 5, 5);
rectMode(CENTER);
fill(inByte1, 0, 0);
rect(120, 20, 5, 5);
rectMode(CENTER);
fill(inByte2, 0, 0);
rect(140, 20, 5, 5);
}//end of draw


void keyPressed() {
if (key == 'a'){
mySample.repeat();
}
else if(key == 's'){
mySample.stop();
}
}


void setRate(){
// set the speed (sampling rate) of the sample.
// Values:
// 0 -> very low pitch (slow playback).
// 88200 -> very high pitch (fast playback).
//float rate = (height - mouseY)*88200/(height);
float rate = 44000;
mySample.setRate(rate);
}



void stop()
{
// always close Sonia audio classes when you are done with them
// dealocates memory space
Sonia.stop();
super.stop();
}


Firmata Firmware

Code:

/* Copyright (C) 2008 Free Software Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* See file LICENSE.txt for further informations on licensing terms.
*/

/* Supports as many analog inputs and analog PWM outputs as possible.
*
* Written by Hans-Christoph Steiner <hans@eds.org>
*/
#include <Firmata.h>

byte analogPin;

void analogWriteCallback(byte pin, int value)
{
pinMode(pin,OUTPUT);
analogWrite(pin, value);
}

void setup()
{
Firmata.setFirmwareVersion(0, 1);
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
Firmata.begin();
}

void loop()
{
while(Firmata.available()) {
Firmata.processInput();
}
for(analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) {
Firmata.sendAnalog(analogPin, analogRead(analogPin));
}
}



Works. Now to get the standard firmata firmware a test.
Re: Processing and ArduinoBT
Reply #2 - May 30th, 2009, 3:52am
 
Hi,
I am trying to hook up a couple of buttons to Arduino BT just in order to switch diferente functions in Processing. My initial code works perfectly with an Arduino USB. But when I switch over to the Arduino BT, it only works with the furst button I clic. The other button won't react...or send a signal. I made the necessary changes in Processing code for the Serial Port, etc... That isnt an issue I think. Would the Firmata code help here?
Re: Processing and ArduinoBT
Reply #3 - Dec 26th, 2009, 2:40am
 
heduino wrote on May 30th, 2009, 3:52am:
Hi,
I am trying to hook up a couple of buttons to Arduino BT just in order to switch diferente functions in Processing. My initial code works perfectly with an Arduino USB. But when I switch over to the Arduino BT, it only works with the furst button I clic. The other button won't react...or send a signal. I made the necessary changes in Processing code for the Serial Port, etc... That isnt an issue I think. Would the Firmata code help here


Hello heduino,

I have been working with Firmata + processing alot. I only worked with analog input (like a potmeter).

Now I want to send button info (High Low) to a processing sketch. Could you post or mail me an example of your code I cant seem to find it out myself. And what you write about seems to be everything I need for my new project.

I will be thankfull  Smiley

Page Index Toggle Pages: 1