Bluetooth serial communication with Mac, JY-MCU Bluetooth and Arduino

After a long while without posting I finally got some time to work in a project which I will later post here (A bluetooth controlled car), but first I had to test the bluetooth module and I’ll use arduino for it, let’s get start with it.

first upload the following test code to your arduino.-

char val; // variable to receive data from the serial port
int ledpin = 8; // LED connected to pin 48 (on-board LED)

void setup() {

  pinMode(ledpin, OUTPUT);  // pin 48 (on-board LED) as OUTPUT
  Serial.begin(9600);       // start serial communication at 9600bps
}

void loop() {

  if( Serial.available() )       // if data is available to read
  {
    val = Serial.read();         // read it and store it in 'val'
  }
  if( val == 'H' )               // if 'H' was received
  {
    digitalWrite(ledpin, HIGH);  // turn ON the LED
  } else { 
    digitalWrite(ledpin, LOW);   // otherwise turn it OFF
  }
  delay(100);                    // wait 100ms for next reading
} 

Now power up your bluetooth module with 3.3V works just fine, ground it first and then connect to 3.3V, once that’s ready connect the Tx (transmitter) of the module to the Rx (Receiver) of the arduino and the Rx of the module to the Tx of arduino and attach an LED to port 8 of your arduino with and 220Ω resistor. (More details on wiring.- http://robotosh.blogspot.mx/2012/07/arduino-jy-mcu-bluetooth.html)

Once you got that working let’s configure our mac’s.-

1.- Go to system preferences and click on the bluetooth symbol.

Image

now you should see something like this.-

Image

click on the plus sign to add a device and you should see something like this.-

Image

click on your device in my case that’s the only bluetooth device available, odds are you’ll see something like this.-

Image

don’t worry just click Passcode Options and select use a specific passcode in my case the passcode is 1234 so I just change it and clicked ok.

Image

Now you should see something like this.-

Image

great it’s almost done let’s get back to the system preferences menu and select the bluetooth option again, select our device, click the gear icon and select “Edit Serial Ports…” like the following image.-

Image

let’s keep things simple for the test so configure as following (with the name you wish).-

Image

look at the path it generate and now let’s open terminal and write.-

ls /dev/tty.*

A list of all of the devices will be displayed you should be able to see the same path we saw at the config window. Write at the terminal the following.-

screen /dev/tty.(here goes the device you want to acces)

in my case is

screen /dev/tty.HC

an empty window appears now type H and the LED we attached to port 8 of arduino now turns on type another character and it should turn off.

That’s all for today I’ll be posting as I advance in the project. Best Regards.

Advertisements
Posted in Technology | 7 Comments

Kinect on OS X 10.8 and Processing

I was working so happily with kinect and my previous OS 10.6 , but then I had to move on to 10.8 and by the time I tried to work with processing and the SimpleOpenNI library, I got the following message.-

SimpleOpenNI Version 0.27
SimpleOpenNI Error: ContextWrapper::checkLicenses, there is no valid license, please check your installation !

Can't open the depthMap, maybe the camera is not connected!

And with my own code.-

Display 0 does not exist, using the default display instead.
SimpleOpenNI Version 0.27
SimpleOpenNI Error: ContextWrapper::checkLicenses, there is no valid license, please check your installation !

Exception in thread "Animation Thread" java.lang.NullPointerException
	at SimpleOpenNI.SimpleOpenNI.updateDepthImage(SimpleOpenNI.java:838)
	at SimpleOpenNI.SimpleOpenNI.depthImage(SimpleOpenNI.java:426)
	at distance.draw(distance.java:50)
	at processing.core.PApplet.handleDraw(PApplet.java:1631)
	at processing.core.PApplet.run(PApplet.java:1530)
	at java.lang.Thread.run(Thread.java:680)

with processing 2.0b3.-
SimpleOpenNI Version 0.27
SimpleOpenNI Error: ContextWrapper::checkLicenses, there is no valid license, please check your installation !

Exception in thread "Animation Thread" java.lang.NullPointerException
	at SimpleOpenNI.SimpleOpenNI.updateDepthImage(SimpleOpenNI.java:838)
	at SimpleOpenNI.SimpleOpenNI.depthImage(SimpleOpenNI.java:426)
	at distance.draw(distance.java:51)
	at processing.core.PApplet.handleDraw(PApplet.java:2128)
	at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:190)
	at processing.core.PApplet.run(PApplet.java:2006)
	at java.lang.Thread.run(Thread.java:680)

After all the frustration I finally get it to work, but it was sort of difficult to find all of the information, and most of the posts have been left aside, that’s the main reason of this post, to  make your life easier by skipping all of the search.

Enough of this rambling speech, first of all you’ll need to have the following apps installed.-

XCode

With the Command line tools installed, in order to do so you’ll need to go to XCode> Open Developer Tool> More Developer Tools

Imagen

Once there sign in with your apple ID

Imagen

download and install the .dmg

XQuartz 2.7.2

MacPorts a guide of MacPorts https://trac.macports.org/wiki/UsingMacPortsQuickStart

CMake In case a window appear telling you that you can’t infall it, go to Preferences> Security and Privacy > General and change Allow downloaded apps for every site.

Libtool

Now Open Terminal (Applications> Utilities> Terminal) and run the following command:

sudo port install libtool

Press return, and then, enter the admnistrador password and press return.

When the installation is done, restart your Mac. sudo refers to super user do, it gives you privileges of administrator, port is used in conjunction with MacPorts and install it’s the command line to install the libtool.

Libusb

Now Open terminal and run (exactly) the following command:

sudo port install libusb +universal
Press return, and then, enter the admnistrador password and press return.
When the installation is done, restart your Mac again.

Now type in your terminal.-

port installed

And you should see something like this.-
The following ports are currently installed:
libtool @2.4.2_3 (active)
libusb @1.0.9_0+universal (active)

OpenNi

You should create a folder named kinect wherever you want to , and by so make it as organized as possible. ( Trust me it would be a mess).

go to http://www.openni.org/openni-sdk/openni-sdk-history-2/

and download “OpenNI SDK v1.5.4.0” for MacOSX

move the file you have just downloaded to your kinect folder and uncompressed it. Now in the terminal change directory to your kinect folder, use cd (change directory) and ls (list) to move among the folders, if you need to back one folder back use cd ../

Change directory to the folder of OpenNI “OpenNI-Bin-MacOSX-Dev-v1.5.4.0”
Run the command
sudo ./install.sh

with “./” you can execute files (for those who are new with terminal).

SensorKinect

Now go to https://github.com/avin2/SensorKinect and download the files (click on the button with the cloud that says zip) extract it in your kinect folder.

Go to the “bin” folder. Extract the file “SensorKinect093-Bin-MacOSX-v5.1.2.1.tar.bz2” in the same bin folder.
In Terminal, go to the bin folder (with cd) and run the command:
sudo ./install.sh

PrimeSenseNite

Go back to http://www.openni.org/openni-sdk/openni-sdk-history-2/

and download “NiTE v1.5.2.21” for MacOSX. Extract the contents of the folder “kinect.”
Open Terminal, go to the directory “NITE-Bin-MacOSX-Dev-v1.5.2.21”
Run the command:
sudo ./install.sh

To test the demos, copy all *. xml files that are in “NITE-Bin-Dev-MacOSX-v1.5.2.21/Data” to “SensorKinect/Data”
Imagen

Imagen
Plug the Kinect on the Mac to check if the demos work.

Test the demos

Open Terminal,
Go to the directory “NITE-Bin-Dev-MacOSX-v1.5.2.21/Samples/Bin/x64-Release”
open the example “PointViewer” with the command:
./Sample-PointViewer
Shake hands, OpenNI  will track your hand.

Processing

Download Processing for your platform and install it

Now go to http://code.google.com/p/simple-openni/downloads/list

And download     SimpleOpenNI-0.27.zip  

Copy the ‘SimpleOpenNI.zip’ into this folder:

/Users/’yourusername’/Documents/Processing/libraries

If you don’t have this folder then create it.

And now you could go to File>Examples>Contributed Libraries>SimpleOpenNI and play around with the examples to run them just press play .

Captura de pantalla 2013-01-18 a la(s) 19.06.41

Captura de pantalla 2013-01-18 a la(s) 19.07.27

I hope you’ll find it useful.

Some links.-

http://creativec0d1ng.blogspot.mx/2012/08/installing-openni-on-osx-lionmountain.html

http://lara.unb.br/wiki/index.php/Kinect_MacOS

http://www.miguelespada.es/?p=579

Aside | Posted on by | Tagged , , | 36 Comments