Writing Serial Data (via Bluetooth)

Okay I'm stumped. I'm trying to control an I-racer car (https://www.sparkfun.com/products/11162) over bluetooth via Processing. So I thought the best starting point would be to make sure I can send bluetooth commands from my mac, so I paired the car with my mac, used z-term (http://www.dalverson.com/zterm/) to connect to the bluetooth "port", and send the hex codes that control the car. It worked. Then I thought I should be able to do the same thing with the Serial library in Processing. And kind of I can, but only once. If I unpair the car, then repair it in system prefs, and start my Processing app it can send exactly 1 command to the car, and it works. But then it won't send anything else. I quit the application (I've tried it with and without closing the serial port), start it again and I cannot send commands again. Unless I start z-term or unpair the device I can never send commands again (Z-term can always send unlimited amounts of commands).

Not sure where to go from here. Here's a stripped-down version of my code: import processing.serial.*;

Serial s;

void setup() {
  println(Serial.list()); 
  s=new Serial(this, Serial.list()[5], 38400);
  println("OPENING PORT");
}

void draw() {
}

void keyPressed() {
  if (key=='a') {
    println("sending 0x6f");
    s.write(0x6f);
  }

  if (key=='b') {
    println("sending 0x2f");
    s.write(0x6f);
   }

   if (key=='q') {
    s.clear();
    s.stop();

    println("CLOSING PORT");
   }  
}

Only works once. Thoughts? Thanks!

Tagged:

Answers

  • By the way, on OS X 10.9

  • edited October 2014

    Did you get this working? If not might i suggest that check key i think should be inside the draw function as this is the function that get automatically looped. If this does resolve your issue can you let me know.

Sign In or Register to comment.