[AN] Anup Narkhede

Programmer, Hobbyist, Jack of many trades, Master of some

Ultrasonic Range Finder

| Comments

SRF05 is an ultrasonic ranger module for arduino. Using the previously posted GLCD setup, I have built a simple range finder.


Trigger and echo pins of sensor module are connected to I/O pins 12 and 13 respectively.



#include <glcd.h>
#include <fonts/allFonts.h>

int trigger = 12;
int echo    = 13;

void setup()
 pinMode(trigger, OUTPUT);
 pinMode(echo, INPUT); 

void loop(){
  int distance  = calculateDistance();

int calculateDistance(){
  digitalWrite(trigger, LOW);
  digitalWrite(trigger, HIGH);
  digitalWrite(trigger, LOW);
  return (pulseIn(echo, HIGH)/58);

void displayOutput(int distance){
  GLCD.print("Distance: ");


| Comments

I was looking for a way to send interrupts from Arduino to my macbook, without performing polling on a port. Here is a simple attempt to make it work. em-serialport is eventmachine compatible asynchronous library based on ruby-serialport.

The operation is simple. Whenever data is is available over serial port, on_data callback gets invoked. Similarly send_data writes the data on serial port.


gem install em-serialport


If you are on Mac, you need to set up a virtual USB serial port by installing a driver from http://www.ftdichip.com/Drivers/VCP.htm. Identify your serial port device. For ex: /dev/tty.usbserial-xxxxxxxx

EM.run do
  serial = EventMachine.open_serial('/dev/tty.usbserial-xxxxxxxx', 9600, 8, 1, 0)
  serial.send_data "foo"

  serial.on_data do |data|
    # you got data. Eat it.

Serial Monitor

The gem comes with a simple command line Serial Monitor. Launch it as:

bundle exec serial-monitor /dev/tty.usbserial-xxxxxxxx

Here is a working example, tested with an https://github.com/railsbob/arduino-examples/tree/master/echo_server. It simply reads and writes data to serial port from command line.

Serial monitor initialized. Enter data followed by a newline character.
Ctrl-C to stop
received: hello
A very long sentence
received: A v
received: ery long
received:  sentence

Interface LCD TM12864L With Arduino

| Comments

I bought TM12864L LCD display off ebay, however it came without any datasheet or documentation. After looking for help in forums, I was finally able to make it work. Here is a guide to interface TM12864L LCD display with Arduino Mega (1280).


GLCD Library

Once the module is wired in, you need to set up GLCD library in Arduino SDK. Follow these steps for OSX:

  • Assuming that your SDK is configured at ~/Documents/Arduino, create a folder ‘libraries’ inside Arduino folder.
  • Unzip GLCD library & move it to ~/Documents/Arduino/libraries/glcd
  • Start Arduino SDK and you should see ‘glcd’ under Sketch > Import Library > Contributed menu.

Running Examples

GLCD library comes with extensive code samples. If you have configured the library correctly, you should be able to see and compile demo examples from: File > Examples > glcd menu.