Arduino Delphi Serial Communication Ppt

Posted : admin On 09.08.2019
Arduino Delphi Serial Communication Ppt 6,4/10 1009 reviews
HOME - - - - - Delphi Tutorials TOC - - - - - -Other material for programmers
  1. Serial Communication Arduino To Pi
  2. Arduino Serial Communication Example
  3. Arduino Delphi Serial Communication Ppt Pdf

ARDUINO (Great Microprocessor) HOME

Jul 20, 2012  The gauge is one of the built-in sample components in Delphi. I wrote about this on my blog - it's in Hebrew, but even if you don't know Hebrew, you can still read the code snippets there: http.


Bookmark this on DeliciousRecommend to StumbleUpon

Delphi tutorial: serial comms, i.e. using the COM port
Bi-directional Communications
Hyperterminal derivative

This has good information, and a search button at the bottom of the page

Please don't dismiss it because it isn't full of graphics, scripts, cookies, etc!

This page is crude.. sorry.. Please don't judge my general postings based on this sub-standard example.

WARNING..

I am old fashioned. I disavow any responsibility for things you may elect to do. In particular, I disavow any responsibility for any consequences arising from connections you make between devices. You can't just plug 'anything' into your computer or anything else!. In particular, make sure that you aren't assuming that an RS-232 interface can be connected directly to, say, an Arduino or BASICstamp, or PIC or other microprocessor. There are notes on some of those issues on my serial ports page, for those of you who need them.

Enough 'lawyer feeding'.. let's turn to the Fun Stuff..

If you have already read my page 'dt4t' (the illustrations just a little way down the page will be familiar), you can jump ahead to material HERE that isn't duplicated THERE!

This is one in a series of tutorials which show you how to link two devices using serial comms. In the tutorials, the 'devices' are a Windows PC running programs written with Delphi and an Arduino.. neat little, inexpensive, fun, capable microprocessor. However: Either device could be replaced by another.. many of the issues discussed here are general, but I find that principles are best understood when backed up by examples of their application.

Click here if you want to know more about the sourceand format of these pages. It may be easier to read this if you re-size the window, so that it does not use the full width of your screen.

The Delphi sourcecode is available for download. The Arduino sourcecode is presented here in full, and you can copy it and paste it into your Arduino development environment for compilation and upload to your Arduino.

These pages are ROUGH and ILL-EDITED at this time. Explanations are sketchy. But the code DOES work. If this note is still here 15 September 2010, write and complain!

Two computers; one system

For many years, for a number of different reasons, I've wanted to hook a microprocessor to a 'big' computer, and have them talk to one another. These days (August 2010) I am using the wonderful Arduino for microprocessor projects, and a Windows XP computer for my 'main' work. The material below could be used with other devices. In particular, if your objective is to connect some serial device to a 'big' PC, you will find helpful material, I hope.

In the diagram below, if you assume that the 'some serial device' is a PC, you see two PCs attached to the Arduino. The one on the left is there for when you are setting up the Arduino to do whatever you want it to do with the other PC. It would normally unplugged, taken away after the system had been built.

The set up above is pretty general. Even without restricting what it implies, you can have two scenarios.

In order to explain the scenarios, I need to say what I mean by 'Master' and 'Slave' in the rest of this essay. A 'master' device is in charge. The 'slave' device will 'speak when spoken to'. It may get on with various things when it isn't commanded by the master to be doing other things, but it will not 'come up' on the serial channel, aka 'serial link' between master and slave unless the master has told it to. The master may 'speak' to the slave in an imperious manner, just issuing a command, and assuming the slave will execute it without any reply. If, for instance, there was an LED attached to the slave, the master might send a 'turn LED on' command'. Or, the master might 'say' 'Turn on the LED, and tell me that you've done it.' In the latter case, the master would have to be programmed to look for the slave's reply.

You can build systems like the above in which the 'Some Serial Device' is the master, and the Arduino is the slave, and you can build systems the other way around (Arduino as master, other serial device as slave.) In the work so far within this tutorial, an example of a Windows XP computer as master, with an Arduino as slave has been created. (The hard parts of doing the reverse are all solved, and part of the first solution.)

Serial Communication Arduino To Pi

It is all well and good thinking in general terms, but eventually it is necessary to get down to cases. For the work to be discussed, this is the set-up I was using..

The Wulfden module is a neat, inexpensive solution to the problems arising from the fact that the PC uses RS-232 serial comms and the Arduino is a TLL device. I'll try to expand on that later. (See my serial port page, for a badly written 'answer', in the meantime.('Hardware' section, near top.)) N.B.: The 'Rx'/'Tx' markings on the device, and on the diagram above cause people no end of confusion. They stand for 'transmit' and 'receive'.. but relative to which device??? There's a signal FROM the PC TO the Arduino that is marked 'Tx' above. and we are transmitting from the PC to the Arduino.. but the Arduino might well call that line 'Rx', as it is the line the Arduino is receiving on. Not rocket science, but easy to get turned around. Follow the diagram: Connect the signal marked 'Tx' on the PA4B to digital pin '3' of the Arduino, the signal marked 'Rx' on the PA4B to digital pin '4' of the Arduino, enter the Arduino programs given below, and all will be well.

I suppose this is the place to say something about the connection from the PC running the Arduino Development Environment to the Arduino. It goes to digital pins 0 and 1. I'm not doing anything 'clever' here.. that's just the normal connection, over which you send programs ('sketches') to the Arduino from the PC where they are compiled.

Apologies for that little diversion. The problems this tutorial sets about solving are rife with 'little details', all of which have to be Got Right.

Start at beginning? Jump to last chapter?

If you work your way though what is on this page, and it isn't easy at the moment, as it is a work in progress, you will have a better understanding of various things which are going on. Alternatively, especially if you have some Arduino and general serial comms experience, and (in any case) until this page has had more editing, you might want to jump ahead to a tutorial where a fancy 2 computer 'master' / 'slave' system is explained. That link jumps you past material at the start of the page, material similar to what you've already read here.

Of episodes 15 Production Producer(s) John Archer Editor(s) Timo Langer Running time 915 minutes Production company(s) Hopscotch Films Release Original network External links Website The Story of Film: An Odyssey is a documentary film about the, presented on television in 15 one-hour chapters with a total length of over 900 minutes. It was directed and narrated by, a film critic from, based on his 2004 book The Story of Film. The series was broadcast in September 2011 on, the digital television service of UK broadcaster. Nest in the wind second edition sparknotes romeo and juliet. It was broadcast in the United States on beginning in September 2013. The Story of Film was also featured in its entirety at the, and it was exhibited at the in New York City in February 2012.

Some day I will re-write all of this, and give you tutorials of my usual style.. nice, progressive, help you understand what's happening bit by bit tutorials.

I don't have time to write it like that now. The work of developing the code is well along. The code needs rough edges 'sanded', but it WORKS. So for now, in the rest of this page, I'll just 'dump' in your laps, the stages I followed to arrive on the brink of creating the 'final' (for now!) stage.

If you jump ahead to the tutorial where a fancy 2 computer 'master' / 'slave' system is explained, you will find the full source code there. The source code for the stages of development leading to the 'fancy' answer are also available, and listed below. (DD81, DD82, and supporting Arduino programs.)

Many, many of the underlying concepts upon which this system is built.. especially the part in the Windows PC.. were discussed, explained, etc, earlier in the series of tutorials which led to this one. In particular the one about DD80 is worth a visit if you are puzzled about things.

There are a lot of rems in the Delphi code to help you understand what is going on. You don't, by the way, have to do this with Delphi or with a Windows computer as the master. If you know how to connect something else to a serial stream, and can send things to the Arduino over a 'Tx to other device' line, and read bytes received over a 'Rx from other device' line, you can use the Arduino code I've presented here with the software and serial device of your choosing.


The rest of this is 'scraps'.. well written code, but badly written explanation.. of a stepwise progress to the 'finished product' given above.


Road To Solution

To come.. work in progress!

Other Delphi Sourcecode

I will try to explain more fully what DD81 and 82 are.. later.

You can download the free sourcecode for DD81. The zip file also includes a compiled copy of the application. The compiled version is hard coded to operate on COM1 at 9600, with no handshake.

You can download the free sourcecode for DD82. The zip file also includes a compiled copy of the application. The compiled version is hard coded to operate on COM1 at 9600, with no handshake.

At the moment (03 Aug 2010, 13:17UK) the other 4 Arduino programs related to DD81-83, and leading up to 'SerialArdAsSleave2' are presented in the next block. Sorry! Will sort out when and as I can. By the way, my program and file naming works like this..

  • Whatsit
  • Whatsit2
  • Whatsit3
  • Thingie
  • Thingie2
  • Thingie3
  • Thingie4

I try to avoid series like 'Whatsit', 'Whatsit2', 'Whatsit3'.. But when I fall to human frailty, I have no 'Whatsit1' in the series. The 'Whatsit(no number)' is 'Whatsit1', and 'Whatsit2' is the second in the series.

Have you looked at my Windows freeware and shareware, mentioned to friends with kids, schools, and also non-kid learners, and even non-learners? You do that for me (for free) while I write this page for you, for free?!


Arduino Code for Bi-directional Serial Comms

Sorry.. the best I can do for now is to 'dump' the code for several Arduino programs here. They interface with DD18, DD82 or DD83. I will one day come back to this page and sort things out, but for now you at least have the working code to draw on. In particular, look at the inline rems.

NEW PROGRAM

NEW PROGRAM

NEW PROGRAM


This isn't the place to explain the general principles of serial ports to you. I have a separate page with more general serial port information. (At 2 Apr 10, that page has a number of topics which need further development, but it already has some useful things for you.. among them information on RS-232 to TTL level shifting, and how to use an inexpensive USB device to provide your PC with a virtual serial port which works fine with the software developed in this tutorial. If you look a little farther, I think you will find that there are 'serial port proxies', which allow you to have 'a serial port'.. on a computer that you are only 'connected' to across a LAN, or even across the internet! Serial ports are NOT 'easy', but they have been earning their keep for many, many years. Master them, and you have access to all sorts of things.)

If you've never done anything with serial ports, it may pay you to go to another one I wrote. That covers setting up a serial connection from a PC to some external device, but a connection that merely sends data. Even more basic that the objectives of the tutorial you are currently reading.. but all of the things that you learn to do there are incorporated in what we will do here. You can make your headache less painful by attacking the job in two halves. But even if you don't take my advice, the page you are reading should be all you need to get started with bi-directional serial comms.

Writing the program..

Apologies to those of you who read the tutorial for the program before this one. (This one: DD81. The one before: DD80.) Much of the material below is just a re-cap of things already said in the discussion of DD80.

Start creating the application. I encourage the following general working practices: Choose a robust name for it, and create a folder, probably within something named something like 'Delphi prj-tkb', if your initials are 'tkb'. To follow along with what is to come, you can put the application's folder anywhere you like, but call it DD81. (For Eighty-First Delphi Demo).

Fire up your Delphi.. I'm using Delphi 7 under Windows XP, but what is here should work in earlier Delphis, too. Put a button on the form, don't bother to change even its name yet. Name the form they are on DD81f1. Give it a good caption. The caption determines what will be in the window's title bar when you run it. Save the unit as DD81u1.pas (in a DD81 folder), and save the project as DD80.dpr. (The system will create the essential DD81u1.dfm, and a bunch of other things that aren't essential to backing up your work.)

(I'll try to write the rest of this for you later, but it won't be soon. For now, just load the finished sourcecode from the download!

Site MapWhat's NewSearchThis search merely looks for the words you enter. It won't answer 'Where can I download InpOut32?'Arduino

Click here if you're feeling kind! (Promotes my site via 'Top100Borland')

If you visit 1&1's site from here, it helps me. They host my website, and I wouldn't put this link up for them if I wasn't happy with their service. They offer things for the beginner and the corporation.

Ad from page's editor: Yes. I do enjoy compiling these things for you. I hope they are helpful. However.. this doesn't pay my bills!!! Sheepdog Software (tm) is supposed to help do that, so if you found this stuff useful, (and you run a Windows or MS-DOS PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!
Click here to visit editor's freeware, shareware page.
Link to Tutorials main pageHow to email or write this page's editor, Tom Boyd

Page tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org


If this page causes a script to run, why? Because of things like Google panels, and the code for the search button. Why do I mention scripts? Be sure you know all you need to about spyware.

.... P a g e . . . E n d s ...

Introduction

In order to make two devices communicate, whether they are desktop computers, microcontrollers, or any other form of computer, you need a method of communication and an agreed-upon language. Serial communication is one of the most common forms of communication between computers. These notes explain the basics of getting two computers talking to each other using Asynchronous Serial communication.

To get the most out of these notes, you should know what a microcontroller is and have an understanding of the basics of microcontroller programming. You should have some understanding of programming a personal computer as well, ideally in a language that can access the serial ports of the computer, like the Processing programming environment, node.js programming environment, Python, or Java.

Arduino Serial Communication Example

Serial Communication Agreements

Communicating serially involves sending a series of digital pulses back and forth between devices at a mutually agreed-upon rate. The sender sends pulses representing the data to be sent at the agreed-upon data rate, and the receiver listens for pulses at that same rate. This is what’s known as asynchronous serial communication. There isn’t a common clock in asynchronous serial communication; instead, both devices keep time independently, and either send or listen for new bits of data at an agreed-upon rate.

In order to communicate, the two devices need to agree on a few things:

  • the rate at which data is sent and read
  • the voltage levels representing a 1 or a 0 bit
  • the meaning of those voltage levels; is a high voltage 1 and a low voltage 0, or is the signal inverted so that a low voltage is a 1 and high voltage is 0?

Arduino Delphi Serial Communication Ppt Pdf

For example, let’s say two devices are to exchange data at a rate of 9600 bits per second. First, you would make sure there’s an agreed upon high and low voltage supplying each device, then you’d make three connections between the two devices:

  • a common ground connection, so both devices have a common reference by which to measure voltage;
  • one wire for the sender to send data to the receiver on (transmit line for the sender);
  • one wire for the receiver to send date to the sender on (receive line for the sender).

Since the data rate is 9600 bits per second (sometimes called 9600 baud), the receiver will read the voltage on its receive wire every 1/9600th of a second. It will interpret that voltage reading as a new bit of data. If the voltage is high (typically +5V or +3.3V in the case of most microcontrollers), it will interpret that bit of data as a 1. If it is low (typically 0V), it will interpret that bit of data as a 0. By interpreting the bits of data over time, the receiver can get a detailed message from the sender. at 9600 baud, for example, 1200 bytes of data can be exchanged in one second.

What Do the Serial Voltage Changes Mean?

Let’s look at a byte of data being exchanged. Imagine you want to send the number 90 from one device to another. First, you have to convert the number from the decimal representation 90 to a binary representation. In binary, 90 is 01011010. So your sending device will pulse its transmit line as shown in Figure 1:

As you might guess from this diagram, both devices also have to agree on the order of the bits. Usually the sender sends the highest bit (or most significant bit) first in time, and the lowest (or least significant bit) last in time. As long as you have an agreed upon voltage, data rate, order of interpretation of bits, and agreement on what the voltage levels mean, you can exchange any data you want serially.

For the data transmission above, a high voltage indicates a bit value of 1, and a low voltage indicates a voltage of 0. This is known as true logic. Some serial protocols use inverted logic, meaning that a high voltage indicates a logic 0, and a low voltage indicates a logic 1. It’s important to know whether your protocol is true or inverted. For example, RS-232, which was the standard serial protocol for most personal computers before USB came along, uses inverted logic.

UART? USB? CDC?

The asynchronous serial communication you’ll be using here is sometimes referred to as TTL serial, and it’s not an inverted serial protocol. In TTL serial communications, high voltage means logic 1, and low voltage means logic 0. Most processors on the market today are equipped with one or more Universal Asynchronous Receiver-Transmitters, or UARTs, for communicating this way.

Most personal computers do not have an asynchronous serial port anymore. Instead, they have USB ports. USB stands for Universal Serial Bus, and it’s a slightly different serial protocol that allows multiple devices to communicate over the same wires. This configuration is known as a bus configuration. USB is a complex protocol that can support many different classes of devices, from human interface devices (HID) like mice and keyboards to mass storage devices to cameras, and more. Because so many devices still use asynchronous serial communication, USB includes a Communications Device Class (CDC) that supports asynchronous serial communication. Devices that include a USB-to-serial converter will show up as serial ports to your computer when you plug them in. Many microcontroller boards, including the Arduino boards, include a USB-to-serial converter to communicate with your computer in this way. When you plug them in, any program that can read serial ports will list the connected Arduino in the list of serial ports.

Serial Buffers and Control of the Port

Once you’ve got the computer and the microcontroller connected, you’ll need to write a program to address the serial ports. The process is slightly different on the different microcontrollers, but there are some elements common to all of them.

All processors that have a UART (this includes personal computers and microcontrollers, and most embedded boards like the Beaglebone Black and Raspberry Pi as well) have an area in memory where they store incoming data from the serial ports called a serial buffer. Because of this, they can do other tasks while waiting for data to come in, and act on the data from the buffer after it comes in.

Serial ports can only be controlled by one program at a time. For microcontrollers that aren’t running an operating system, this is simple; whatever program is running on the controller gets the serial port. On computers with an operating system, you might have multiple programs running, but only one can control a given serial port at any one time. For example, if you have a laptop connected serially to an Arduino, and the Arduino IDE’s Serial Monitor is open, then no other program can read from that serial port. You’d need to close the serial monitor to open the port from Processing or any other application. Related video: Only one program can control the port

Once you’ve got the serial port open, any bytes sent by the connected device will be available to your program in the order that they were sent. As you read each byte, the byte is removed from the serial buffer. This is why serial buffers are also called First-In, First-Out or FIFO buffers.

See the Arduino serial lab, the Serial Input to the P5.js IDE lab or the Serial Communication with Node.js lab for more on sending serial from Arduino to another computer.

When two devices are communicating serially, they can’t read each other’s program logic. They can only read what the other device has said. Because of this, you need to make sure that the programs on both sides are using the same communications protocol. This is the highest level of agreement in serial communications: both sides need to agree on what the bytes being sent mean, and in what order they are being sent. For more on this, see the serial data interpretation notes.