Delphi and Arduino

Arduino is a single-board microcontroller, intended to make electronic application of interactive objects or environments more accessible for everyone.

For people live in Indonesia where buying Arduino from overseas is expensive and requires months of delivery time, you can buy Arduino compatible boards from Vcc2Gnd.com, toko komponen elektronika yang menjual Arduino dengan harga murah. The price of Arduino Pro Mini in this store is incredibly cheap, less than US$7 [ cek harga jual Arduino Pro Mini ATmega328 16 MHz ].

I've found this piece of code for Delphi and Lazarus (free pascal), It suppose to control the level of brightness of a LED through the pin 7 of Arduino Board. Example comes with Arduino Sketch and Delphi/Lazarus Project. It uses freeware Synaser library to communicate directly to the serial port.

Penguin Cult Lab made a simple Arduino controller from Delphi, here the screen-shot:

This example uses 5 LEDs that will be controlled from the Delphi program via serial communication. Library used for serial communication is open source library the ComPort. Download zipped Delphi source code.

From Arduino, enter following code and save it as "delphi_leds.pde":

/*
 * Delphi LEDs Control
 * -----------------
 * Turns on and off 5 light emitting diodes(LED) connected to digital  
 * pins 2 thru 6. The LEDs will be controlled using check boxes on Delphi
 * that sends serial data to Arduino Board.
 *
 * IMPORTANT!!: Don't forget to download the Delphi PC Example that controls the leds connected to arduino board.
 *
 * Created April 02 2009
 * copyleft 2009 Roberto Ramirez <beta@thepenguincult.com>
 * Full Source code at http://www.thepenguincult.com/proyectos/arduino-delphi-control/
 * 
 */

int val = 0;       // variable to store the data from the serial port
int ledPin1 = 2;   // LED connected to digital pin 2
int ledPin2 = 3;   // LED connected to digital pin 3
int ledPin3 = 4;   // LED connected to digital pin 4
int ledPin4 = 5;   // LED connected to digital pin 5
int ledPin5 = 6;   // LED connected to digital pin 6

void setup() {

  pinMode(ledPin1,OUTPUT);    // declare the LED's pin as output
  pinMode(ledPin2,OUTPUT);    // declare the LED's pin as output
  pinMode(ledPin3,OUTPUT);    // declare the LED's pin as output
  pinMode(ledPin4,OUTPUT);    // declare the LED's pin as output
  pinMode(ledPin5,OUTPUT);    // declare the LED's pin as output


  
  Serial.begin(9600);        // connect to the serial port
}

void loop () {
  val = Serial.read();      // read the serial port

  
  if (val !=-1){

    if (val=='1'){
      digitalWrite(ledPin1,HIGH);
    }
    
    else if (val=='A'){
      digitalWrite(ledPin1,LOW);
      }
    
    if (val=='2'){
      digitalWrite(ledPin2,HIGH);
    }

    else if (val=='B'){
      digitalWrite(ledPin2,LOW);
      }

    if (val=='3'){
      digitalWrite(ledPin3,HIGH);
    }

    else if (val=='C'){
      digitalWrite(ledPin3,LOW);
      }

    if (val=='4'){
      digitalWrite(ledPin4,HIGH);
    }

    else if (val=='D'){
      digitalWrite(ledPin4,LOW);
      }

    if (val=='5'){
      digitalWrite(ledPin5,HIGH);
    }

    else if (val=='E'){
      digitalWrite(ledPin5,LOW);
      }
   
    //Serial.println();
  }
}

5 comments:

Fari said...

i'm sorry , why i can't open source code for delphi ? any link for download it ? thanks

Fari said...

i'm sorry , do you know, why i can't open source code for delphi ? any link for download it ? thanks

lotuspc said...

i'm sorry , do you know, why i can't open source code for delphi ? any link for download it ? thanks

GidSP said...

hey guys, use this instead:
https://web.archive.org/web/20160122214659/http://arduino.cl/descargas/

GidSP said...
This comment has been removed by the author.