Pages: [1]   Go Down
Author Topic: DFrobot bluetooth xbee and processing  (Read 186 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am having trouble getting processing to talk to arduino using the arduino library, the wireless shield , a dfrobot rover v2 and a DFrobot bluetooth bee.

I want to be able to make it so that the robot moves while a key is being held down. I can get it to respond using the serial terminal and typing commands. but when i try to get it to work in processing the link light on the bee lights up but when I press a key, nothing happens.

It works fine when I use a usb cable but not when I use the bee.

here is my code :
Code:
/*
arduino_output

Demonstrates the control of digital pins of an Arduino board running the
StandardFirmata firmware.  Clicking the squares toggles the corresponding
digital pin of the Arduino. 

To use:
* Using the Arduino software, upload the StandardFirmata example (located
  in Examples > Firmata > StandardFirmata) to your Arduino board.
* Run this sketch and look at the list of serial ports printed in the
  message area below. Note the index of the port corresponding to your
  Arduino board (the numbering starts at 0).  (Unless your Arduino board
  happens to be at index 0 in the list, the sketch probably won't work.
  Stop it and proceed with the instructions.)
* Modify the "arduino = new Arduino(...)" line below, changing the number
  in Arduino.list()[0] to the number corresponding to the serial port of
  your Arduino board.  Alternatively, you can replace Arduino.list()[0]
  with the name of the serial port, in double quotes, e.g. "COM5" on Windows
  or "/dev/tty.usbmodem621" on Mac.
* Run this sketch and click the squares to toggle the corresponding pin
  HIGH (5 volts) and LOW (0 volts).  (The leftmost square corresponds to pin
  13, as if the Arduino board were held with the logo upright.)
 
For more information, see: http://playground.arduino.cc/Interfacing/Processing
*/

import processing.serial.*;

import cc.arduino.*;

Arduino arduino;

color off = color(4, 79, 111);
color on = color(84, 145, 158);

int HIGH = Arduino.HIGH;
int LOW = Arduino.LOW;

int[] values = { Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW,
 Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW,
 Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW };

int rightMotor = 5;
int leftMotor = 6;

int rightDir = 7;
int leftDir = 8;

boolean[] keys = new boolean[255];

void setup() {
  size(470, 200);
 
  // Prints out the available serial ports.
  println(Arduino.list());
 
  // Modify this line, by changing the "0" to the index of the serial
  // port corresponding to your Arduino board (as it appears in the list
  // printed by the line above).
  arduino = new Arduino(this, "/dev/tty.usbmodemfa131", 9600);
 
 
  // Alternatively, use the name of the serial port corresponding to your
  // Arduino (in double-quotes), as in the following line.
  //arduino = new Arduino(this, "/dev/tty.Bluetooth_Bee_V2-DevB", 9600);
 
  // Set the Arduino digital pins as outputs.
  for (int i = 0; i <= 12; i++)
    arduino.pinMode(i, Arduino.OUTPUT);
}

void draw() {
 
   
 
  if (keys[87]) { // w, left Forwards
     
      arduino.digitalWrite(leftDir, HIGH);
      arduino.analogWrite(leftMotor, 10);
     
  } else if (keys[83]) { // s,  Left back
     
      arduino.digitalWrite(leftDir, LOW);
      arduino.analogWrite(leftMotor, 255);
     
  }
 
  if (keys[73]) { // i, right forwards
     
      arduino.digitalWrite(rightDir, HIGH);
      arduino.analogWrite(rightMotor, 70);
     
  } else if (keys[75]) { // k, right back
     
      arduino.digitalWrite(rightDir, LOW);
      arduino.analogWrite(rightMotor, 255);
  }
     
  if (!keyPressed) {
      stop();
  }
 
}
 
void keyPressed() {
    keys[keyCode] = true;
}

void keyReleased() {
    keys[keyCode] = false;
}


void stop(){
    for (int i = 1; i <= 13; i++){
        arduino.analogWrite(i, 0);
    }
}

I am using a MacBook Air running osx 10.9

Logged

Pages: [1]   Go Up
Jump to: