Posts tagged ‘18F4455’

Communication with Pinguino via Bluetooth

I bought a BlueSMIRF Bluetooth module a few weeks ago, and this weekend I’ve finally had some time to put it in action 🙂

Connecting the BlueSMIRF module is really easy. The BlueSMIRF module has 6 pins: CTS-I, VCC, GND, TX-0, RX-1 and RTS-0. You have to connect CTS-I to RTS-0, connect VCC to the supply voltage and GND to ground. The TX-0 pin is connected to the RX pin of the microprocessor, while the RX-1 pin is connected to the TX pin of the microprocessor. On the PIC18F4455 these are pins 26 and 25 (pinguino pins 9 and 8). s

CTS-I  O----------------
VCC    O--5V           |
GND    O--0V (gnd)     |
TX-0   O-- to RX PIC   |
RX-1   O-- to TX PIC   |
RTS-0  O----------------

As explained in a previous post, I am using a Pinguino board, so the code should work on Arduino as well without needing too many modifications. This is the code I used for writing some text:

#define PIC18F4550
char incomingByte = 'K';	// for incoming serial data

void setup() {
  Serial.begin(115200);
}

void loop() {
	// send data only when you receive a C character
	if (Serial.available() > 0) {
		// read the incoming byte:
		incomingByte = Serial.read();
		if (incomingByte == 'C') {
			Serial.print("I received: ");
			Serial.print(incomingByte, DEC);
		}
	}
}
In the setup routine I connect to the serial port at 115200 bauds. The bluetooth module is just used as a regular serial cable, so no fancy tricks are necessary.
On my Ubuntu laptop, I had to do the following to get things running:
  • first connect your Bluetooth dongle to the BlueSMIRF (mine appeared as FireFLY-719A)
  • sudo hcitool scan #so we know the MAC address of the FireFLY
  • rfcomm connect 0 00:06:66:03:72:9A #substitute with your BlueSMIRF’s MAC address
  • sudo gtkterm -p /dev/rfcomm0 -s 115200 #start gtkterm to read/write to the serial port

Of course we don’t want to interact through gtkterm with our microcontroller. I wanted to employ Processing, but this gave some additional difficulties in my setup. In Processing, Serial.list() is used to list all available serial ports. The Bluetooth serial port /dev/rfcomm0 does not appear in the list though. A dirty hack to solve the issue is symlinking /dev/ttyS0 to /dev/rfcomm0:

sudo rm /dev/ttyS0
sudo ln -s /dev/rfcomm0 /dev/ttyS0

If anyone knows a better way to solve the issue, please mention so in the comments! This is the Processing code:

import processing.serial.*;

Serial myPort;                // Create object from Serial class

void setup()
{
  size(200, 200);
  myPort = new Serial(this, Serial.list()[0], 115200);  //the first port in the list is /dev/ttyS0 which we symlinked to /dev/rfcomm0
}

void draw()
{
  while (myPort.available() > 0) {                      //if something was received via serial port
    String inBuffer = myPort.readString();
    print(inBuffer);
  }
}

void keyPressed() {
  print(key);
  myPort.write(key);
}

void stop() {
  myPort.stop();
}

February 22, 2010 at 6:12 pm 3 comments

Scope with PIC microcontroller and Matlab

After many trials I recently succeeded in using the serial connection for communication between my PIC experimental board (based on a PIC18F4455) and my laptop. Turned out I was configuring my UART wrong, but now it works. I’m very happy about this because it is very useful for debugging my robot controller. I wrote a script in Matlab to read out the sensorvalues from the COM port and plot them in some sort of scope-window. The result looks pretty cool!

Matlab scope (from PIC ADC input)

Continue Reading June 23, 2008 at 3:30 pm 42 comments


Feeds

Articles to be written…

Twitter – kr3l

my del.icio.us

RSS Google Reader Shared Stuff

  • An error has occurred; the feed is probably down. Try again later.

RSS Listening to..

  • An error has occurred; the feed is probably down. Try again later.