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();
  }
}

FastMM, a Fast Memory Manager

FastMM is a lightning fast replacement memory manager for Borland Delphi Win32 applications that scales well in multi-threaded applications, is not prone to memory fragmentation, and supports shared memory without the use of external .DLL files.

FastMM3 got a a few minor speed optimizations and a bug affecting DLLs was fixed in both: A DLL would erroneously check for memory leaks on shutdown, even when it was sharing the main application's memory manager.

FastMM4 is done and is currently being fine-tuned and tested internally. In the Fastcode memory manager challenge benchmarks it is currently 6.5% faster than FastMM3 while using less memory. FastMM4 combines all the features of FastMM2 and FastMM3 (and some nice new ones) and will obsolete both older versions when it is released. FastMM4 is faster, uses less memory, it catches attempts to free most invalid pointers, now it's supporting Delphi 5 and 6, DLLs automatically free leaked memory when unloading, supports 3GB user address space under Windows 32-bit (with /3GB switch), supports 4GB user address space under Windows 64-bit, enriched with Enhanced MM sharing options between application and DLLs (Refer to the "Usage" section inside the source file for details on how to enable this).

FastMM version 4.08 introduces a small .dpr project that allows you to build a replacement borlndmm.dll that you may use to replace the memory manager that the Delphi IDE uses. Delphi 7 loads about 10% faster and is noticeably more responsive if this replacement DLL is copied over the DLL in the \Bin folder. Unfortunately there appears to be a bug in Delphi 2005 that prevents this replacement DLL from working under Delphi 2005 (QC#14007), so for Delphi 2005 and newer versions you'll need to patch Delphi 2005 to accomodate memory manager replacement.

FastMM 4.10 adds a new "FullDebugMode" option. What this does are: Add a header and footer to all blocks to catch buffer overruns; Stores a call stack trace on allocate and free to allow you to investigate the cause of an error - only return addresses are displayed at this stage - the display of procedure name and line number detail (when debug info is available) may be implemented at a later stage; Zeroes out all freed memory, so using freed blocks should lead to errors being raised closer to the cause of the problem; Reports attempts to call virtual methods of freed objects (provided the blocks have not already been reused).

In "FullDebugMode" freed blocks are never combined with adjacent free blocks and are never returned to the operating system (so once a block of a certain size has been allocated, that block will exist for the duration of the process). They may be reused however. Factor in the extra processing required to do the stack traces and the memory used to store them and you will rightfully conclude that "FullDebugMode" is slow, uses a lot of memory and tends to fragment badly. It is intended for debugging only!

Errors can now also be logged to a text file through the "LogErrorsToFile" option.

From 4.13 onwards a new DLL is included in the package: FastMM_DebugInfo.dll. This DLL allows FastMM to display unit/line number debug information for stack traces in "FullDebugMode". This requires that debug information be available for the application and libraries. FastMM_DebugInfo.dll uses the JCL library, so either a map file, a .jdbg file or embedded JCL debug data must be available.

Read updates of FastMM through FastMM News Feed (will open in new window), or download FastMM from SourceForge.

DelphiFeeds.com Feeds

TBASSPlayer v.1.92, a Multimedia VCL

TBASSPlayer is a Delphi component, which helps you make stream players easily with the power of BASS Audio Library (bass.dll, basswma.dll, bassmidi.dll, and basscd.dll).
TBASSPlayer supports most functions of BASS audio library. Please read BASS.txt and related document if you want to know more about BASS audio library. You can get them at http://www.un4seen.com.

TBASSPlayer can play the file formats supported by BASS audio library such as
  • stream files (WAV, MP1, MP2, MP3, Ogg Vorbis, AIFF, WMA format)
  • music files (MOD, MO3, IT, XM, S3M, MTM, MOD, UMX format)
  • MIDI files (MID, MIDI, RMI, KAR format)
  • CD Audio tracks.
  • URL stream (files from the internet and Shout/Icecast)
TBASSPlayer supports "BASS add-ons" - plugin modules designed for BASS audio library which enables the playback of additional file formats. TBASSPlayer can play other file formats, which are none-BASS native, not supported by BASS add-ons, using Winamp input plug-ins. You can load upto 8 BASS add-ons and upto 8 Winamp input plug-ins simultaneously for various file format.

TBASSPlayer also supports followings:
  • Winamp visualization plug-ins (supports the latest plug-in such as Milkdrop 2.0e)
  • Winamp DSP plug-ins
  • Tag editor for WMA, MP3 and Ogg Vorbis file
  • 10 Band Equalizer
  • Sound effect (Flanger, Echo, Reverb)
So, you can enjoy the power of numerous Winamp plug-ins with that of BASS audio library.

Product License: Freeware (Source & EXE Demo are included)
File Status: Fully functional
Compatible with: D4 D5 D6 D7

Download TBASSPlayer192.zip from Torry.Net

Fastest Min/Max of Int Array Routine

Use this function to get the Max and Min value from series of data within integer array...
procedure MinMaxArray(const aArray:array of integer; out aMax,aMin:integer);
var
i,mi,ma:integer;
begin
ma := aArray[Low(aArray)];
mi := ma;
for i := Low(aArray) + 1 to High(aArray) do
begin
if (aArray[i] < mi) then mi:=aArray[i];
if (aArray[i] > ma) then ma:=aArray[i];
end;
aMax := ma;
aMin := mi;
end;

If you need more speed, a BASM version could be used as follow...

Useful Delphi Related Links

  • CodeGear
  • the home
  • CodeGear Community
  • CodeGear's developer portal
  • DelphiFeeds
  • all Delphi related blogs at one place
  • About Delphi
  • Your guide to everything you want to know about Delphi related topics
  • Atozed software
  • Home of Delphi's RAD web development tool IntraWeb
  • Torry Delphi pages
  • Award-winning and huge component collection and almost daily updates
  • Delphi Basics
  • learn all about Delphi
  • Delphi Pages
  • Interactive Delphi page with components, news, tips, info
  • Delphi Central
  • Articles and tutorials on Borland Delphi
  • Delphi StartKabel
  • Dutch Delphi portal site
  • DrBob
  • Latest Borland news, Delphi news, C++Builder news
  • Delphi Source
  • More interactive Delphi pages
  • Delphi3000
  • connecting people's Delphi knowledge
  • Hisoft2000
  • Script generator for Innosetup
  • BrotherSoft Downloads
  • Shareware and Freeware downloads and tested, rated and reviewed software submitted by software authors.
  • Euro Download
  • Shareware and Freeware downloads
  • SoftwareShield
  • Software Licensing and Copy Protection SDK for Windows application development

    Search with Google