文件名称:
Arduino-Pascal-Magazine.pdf
开发工具:
文件大小: 4mb
下载次数: 0
上传时间: 2019-07-13
详细说明:Arduino-Pascal-Magazine.pdfMAXBOX STARTER 18 PAGE 1/8
START WITH ARDUINO PROGRAMMING V3. 1
Indy is different than other so called winsock
with RESErver do
components you may be familiar with. If youve
begin
工 E Active then ree;
worked with other components, the best approach
If not Active then
or you may be to forget how they work. Nearly
all other components use non-blocking
Bindings. Cleari
(asynchronous) calls and act asynchronously
bindings. Add;
bindings. items [0]. Port: AFORT;
They require you to respond to events, set up state
indings items [o]IP: = IPADDR
machines, and often perform wait loops
∥127.0.0.1;192.168.7.5
In fact there are 2 programming models used in
Active:- truei
TCP/IP applications. Non Blocking means that
oncommandGet.:= HttpseVe"gEt.
the application will not be blocked when the
Printe(' Listening Http on影s:影d.'
[Bindings [o. IP, Bindings[o]. Port])
application socket read/write data. This is
efficient, because your application don' t have to
wait for a connection Unfortunately, it is
complicated to develop
1 Use Case UML Editor maXbox
帝O仲即口◇x→品它口Q回分园机菌句
BrowserswitchLedMatrixBoxoverhttpandcom
Log Result
<>
*/Start COM Interface
Start Http server
Browser web form win form
Open Browser
Com interface
Atduino Board RGB LED
Arduino Terminal monitor
System Micro Controller Boundary
E:\maxboxlmaxbox3\examples\ 305 webserver_ arduino3ibz_rgb_ led uc stored
Figure 2: The Use Ca
So lets get back to our Http Create in line 123
Host names are human-readable names for
IP add
In line 131 and 132 you see port and ip address
An example host name is max kleiner. com, the
configuration of a Const, instead of Ip you can
www is just a convention and not necessary
also set a host name as a parameter
Every host name has an equivalent ip address
e.g.www.hower.org=207.65.96.71
72
+ Xbox
Issue Nr 6 2015 BLAISE PASCAL MAGAZINE
MAXBOX STARTER 18 PAGE 1/8
START WITH ARDUINO PROGRAMMING V3. 1
y maxbox Internet ar Arduino Weather Station LAWS
10990942015
H::日:5g器
76%
Temperature
Leiden
47
2日
目
日
>I Add Node
D Reduce Node
m Close App
题
pdate
GEO-Weather_Report: I'coord": f"": 4.49, "bt: 52.16), weather" Ef"id: 802, man": "Clouds"," descrption":"scattered douds, icon": "03d"
〔0ep(ohn1d:53mmR? scription""light rain","ico1儿 e'? stations,main'"temp1只
3: A few gadgets for Arduino
if uppercase(lccalcom ) uppercase('/LED')
The full target of the request
then
message is given by the URL
begin
cPort. Writestr('11)
property. Usually, this is a url that
writeln (Iocalcom+ ' LED on')
can be broken down into the
RespInfo. ContentText: getHTMLContentString('LEd is: oN)i
protocol (HITP), Host(server syster end
else
name(server application), path info
if uppercase(lccalcom ) uppercase('/DEL') then begin
(location on the host), and a query
Port. Writest=('A')i
writeln(localcom+ ' LED off)i
o far we have learned little
RespTrfo Concen=Text: getHTM"Ccntent String('LED is: OFF)
abouthttpandhostnames
end
Now it's time to run our program
at first with F9(if you havent done yet)and
learn something about GET and HTML
Http request messages contain many headers
The program(server)generates a standard
that describe information about the client, the
HTML output or other formats(depending on
target of the request, the way the request should
the MIme type) after downloading with GET
be handled, and any content sent with the request
or HEaD
Each header is identified by a name, such as
Host" followed by a string value. It then does a
request
So our command to shine on a led is../ LED and
ch off is,,/DEL(127.0.0,1:8000/LED)
You can also switch with F5 in a browser to
Those are get commands send with the browser
switch led on and off
or/R for Red or/G for green
webswitch: NOT webswitcri
The first line identifies the request as a get
if webswitch then
begin
A GET request message asks the Web server
cPort. Nritestr('1')/goes to Arduino
pplication to return the content
d with
the uri that follows the word get
getHIMLConcenestring('LED is
oN Switch’)
The following shows the magic behind in the
else
method HttpsErverGet(
egan
procedure IITTPServerGet(aThr: TIdPeer Thread;
reqinf: TidhTtprequEstinFo; respinf: TidhTiprespoNse-Nfo)I
One word concerning the thread: In the interna
cPort. Nritestr('A')i
architecture there are 2 threads categories
Resp-nfo. ContentText:
First is a listener thread that listens" and waits
getHTMLConcentString('LED is: OFF Switch')
for a connection So we don't have to worry aboutend
threads, the built in thread l'ldpeer thread will be
served by Indy through a parameter
Issue Nr 6 2015 BLAISE PASCAL MAGAZINE
faber
73
MAXBOX STARTER 18 PAGE 1/8
START WITH ARDUINO PROGRAMMING V3. 1
One of a practical way to learn much more began
about actually writing HTML is to get in
TichtTp. Create(N工L)
try
maXbax editor and load or open a web-file
memo2.lines.text=idhiip.Get2('http://127.0.0.1')
with the extension html. Or you copy the
for i:= 1 to 10 do
output and paste it in a new maxbox instance
memos. lines. add(IntTostr(i)+I:'+memo2 lines[il)
Then you click on the context menu and
finally
idhTTE. Free
change to hTML Syntax
In this mode the pc is a master and executes
the control algorithm while the arduino or delphi
Controller acts as an interface slave and follows
.Theobjecttidhttpisadynamically
commands coming from the pc or browser
allocated block of memory whose structure
through its rs232 port. Each RGB field in these
is determined by its class type. With the
records reflects a state of the sensors and
method Get1 you can download file
actuators of the LEd in those sense only actors as
LED light are in use
begin
A running Arduino(m485A)monitor server will
myURL S
http://www.softwareschule.ch/download/maxboxexampleszi
accept commands on input through a rs232 port
zipStream: TEileStream. Create('myexamples2 zip', fmCrea
idhttp:=tidhTtp.creAte(nil)
f (val=='1')
digitalNrite (ledPinll, HIGH);
idIITTP. Getl(myURL, zipStrean)
else if (val=='A')
digitalWrite(ledPinl, TOw)i
Of course a lot of lines to get a file from the web try
豆f(va1==12){
it shorter with the magic function wGetO
aigitalWrite(edPin2, HIGH);I
wget('http://www.softwareschule.ch/download/maxboxstarter17.pdf',
mytes tpdf. pdf')i
2ma]box Web Connect Arduino
la Firefox
Fils Edt View History Bookmarks Tools Holp
maxbox news
e61270.01:00
合vc图- nikas wirth zurich adresse
O Most Visted D Eisenbahn t TEE CLASSICS 0 modelbahn-portal, de.:bahnoNLINE ch: : D..0 Pascal Language Rcf. Inter Base IBAS Suche C xML Metadata Irkerc. Ab Zitatesarmmlung Ens.
elcome to RgB led Webbox3** Shine on you crazy diamond共兴兴
Check script 305 webserver_ arduino 3 to discover more
Search for a led to light event OnCommandGet and tag r/gb or switch ON OFFI
Example:19216848.1268000R
Switch led is on with led or off with del in url
Figur 4: The Browser controls
It downloads the entire file into memory if the
When the browser starts from script the server is data is compressed (Indy g does not support
ready for commands to pass chars to the serial
streamingdecompressionforhttpyet).Nextwe
communication. When a the server application
come closer to the main event of our web server in
finishes with our client request, it lights the LED line 40, it's the event on Command Get with the
and constructs a page of HTML code or other
corresponding event handler method
Mime content and passes the result back (via the httPservErgEto and one object of
seroerin TidHttpreSponSeiNfc)to the client Tidpeer Thread
for display
writeln (localcom+ ' LED on')
RespInfo Content Tex=: cetETMLContentString(' LEd is: oN);
Have you tried the program, it's also possible to You can use them as server as the way to serve
test the server without arduino or a browser
files of many kinds!
When you run this code from the script
102pashttpdownloadtxtyouwillseea
content(first 10 lines)of the site in HTML format
with the help of the method memo2lines add
74
+ Xbox
Issue Nr 6 2015 BLAISE PASCAL MAGAZINE
MAXBOX STARTER 18 PAGE 1/8
START WITH ARDUINO PROGRAMMING V3. 1
T) maXbox3 ScriptStudio 611_Arduino_COMOutputs2tt
tile Program Options yiew Debug Output Help
Load
Enumcomports(Comports);
Outputs
D463 //PrintF('COM Port Check of Arduino d COM
o_611_Arduino_COMOutputs2 Arduino 1.5.5-12
46
result:= true
File Edit Sketch Toois Help
bject)
465 except
回
PrintE('No CoM Ports,[1)i
result:= false
611 Arduino CoMDutputs2
TObjed
468
void setup() f
469 ComPorts. Free
DDFB=B00111111:
er: tob
// Set pins g to 13 as outputs
malin: ti
470 end
/ all outputs OFF
Serial begin(9E00)
b, c, d: byt
integer;
bject
473be1
void loop(
bject)
474 if Checkcomport then
/ put your main code here, to run repeatedly
bject);
InitcomportForm
inputstring =i
/ Clear inputstein:
C476 End
while (Serial available())(
char digit serial read(): / Read one byte tron srial outter
477
inputString +- digit.
// Add new character to the string
TObject)
78 ref
1(2):
479 Sketch uses 3,792 bytes (11%)of program storag
val -inputString toInt();// Convert inputstring into a number
maXbox2 C\maXbookimaxboxa3\ mX399)\m(39194 imaxbozz \examples 611 Arduino COMOut!
⊥r(va1!=-1)
1s
M T8
Serial. write(val)
/ read back to monitor
rt: cOM4 connected
Jmx3 executed:5/15/201510:51:21 PM Runtime:0:0:10.358
PORTB E val
/ Set Porth ren ster nits
PascalScrlpt maXbox3-Remobjects SynEdIt
Ver: 3.9.9.195(399). Work Dir: C: \maxbookmaxbox3\ maxbox3
StoreSettings at: C: maXbook maxbox3 nX3999 \ mX399194\ Taxbox Done ua cat
comform &port closed
Ver: 3.9.9. 195(399). Work Dir: C: \naXbook \maxbox3\ maxbox
Sketch uses 3, 792 bytes (-1 of progran storage space. Naximum is 32, 256 bytes
Global variables use 202 bytes [95] of dynan:c nemory, leaving 1,046 bytes for local
variables. MaxTum 9 2,048 bytes
5: maXuino Together Setting:
SERIAL LINE
Please read more about serial coding in Tutor 15!
int val 0
variable to store data from the serial port
The serial communications line is simply a way
int lecPin11 =11
for the Arduino to communicate with the outside /LED connected to digital pin 11 or the inbuilt 13!
world, in this case to and from the PC(via USB)
and the arduino ide's serial monitor or from
the uploaded code to 1/O Board back
pinMode (-edPin_l, OUTPLT
We just create and configure our COM settings
M/declare a LED's pin as output mode
erial, begin(960C i connect to serial port
(depends in which COM port a USB hub works)
procedure TForm1 FormcreateCom(Sender: TObject)i
egan
In the main loop we have an if statement". the
Port: TComPort Create(self)i
with cPort do begin
condition it is checking the value in (Serial read)
BaudRate:= br9600:
The Serial available command checks to see if any
Por=:= COMEORT;∥COM3
characters have been sent down the serial line. If
Parity Bits: s
any characters have been received then the
StopBi-s: shCnestopBit;
DataI=s: a
condition is met and the code within the if
⊥gat;
end;
statements" code block is now executed, you see if
then on and if 'a then OFF
The condition of checking is simply a char it's up
The arduino can be used to develop stand-alone
to you to code a protocol of your own
interactive objects or it can be connected to a
computer to retrieve or send data to the arduino
void lcop ()
val= Serial read(); read on the serial port
and then act on that data(e. g. send sensor data
if (val
out to the web or write data on a control LED)
f(va1==11)
Now we change to the arduino editor to explain
digitalWrite(ledPinl, hIGh)i
how he handles our commands(chars)
else if (val=='A')
Serialbegin tells arduino to start serial and the
digitalNrite(ledEinl, LOW)i
number within the parenthesis, in this case 9600
sets the baud rate(chars per second)that the
Serialprint (pata entered
serial line will communicate at
Issue Nr 6 2015 BLAISE PASCAL MAGAZINE
ta Xbox 75
MAXBOX STARTER 18 PAGE 1/8
START WITH ARDUINO PROGRAMMING V3. 1
and this is our way of sending data back from
If you're using a standard breadboard, you'll
the arduino to the pc. In this case the prin
need to use wires to reach the arduino run 3
command sends whatever is within the
wires (red, green and blue)to the pin sockets on
parenthesis to the PC, via the USB cable, where
the arduino. Run the other wire(black) to one of
we can read it in the monitor window or in
the gnd sockets on the arduino the colours
madOx
aren't essential but they will help you remember
what the wires are connected to and black is a
BREAD BOARD FLOW
convention for ground GND
at last but not least some words about
Once the connection to a client socket is
breadboards and electronics. a breadboard (or
completed, the server connection is
protoboard) is usually a construction base for
prototyping devices of electronics. The term
indistinguishable from a client connection Both
end points have the same capabilities and
breadboard is commonly used to refer to a
solder less breadboard (plug board)
receive the same types of events. Only the
listening connector is fundamentally different
With the breadboard you prepared above or
below, add three wires for power to RGB light and as it has only a single endpoint
Sockets provide an interface between your
one for ground gNd for your avr controller
network server or client application and a
Place 3 resistors and LED as shown. Make sure the networking software. You must provide an
longest leg of the led is to gnd connected to the
minus. The resistors dont have a direction, so it
interface between your application and clients
that use it
doesn't matter which way it goes in
Sockets let your network application
communicate with other systems over the
d network. Each socket can be viewed as an
endpoint in a network connection. It has an
address that specifies
垂
··
The system on which it is running
+·
The types of interfaces it understands
The port it is using for the connection
A full description of a socket connection
includes the addresses of the sockets on
both ends of the connection You can
describe the address of each socke
endpoint by supplying both the IP address
6: Breadboard Settings
or host and the port number
dmn与ht
m Dual Trace Osciloscope Ver 42.3
一时,时树时
U COM BAr
kunning
LED Control Arduino PIN
On Offset
山_4‖=
Gain
Dg liNt Eve
2
D006Ets
Gnd
7 cOM Settings
>l Disconnec
top Rainbow.
Figure 7: PwM signal measure in Oscilloscope
ConnectedandListeningonhttp192166143:8080
曲
76
+ Ybox Issue Nr 6 2015 BLAISE PASCAL MAGAZINE
MAXBOX STARTER 18 PAGE 8/8
START WITH ARDUINO PROGRAMMING V3. 1
In the next line we just start a browser to test our
Links of maXbox, Web of things, arduino
server in a so called frame work flow
and Indy
procedure letopenbrowseri
TS_ShellExecute Cmd =(se CndOpen, e CmdPrint, seCmdExplore)
lshelLapl.shellexecUte(Handle,PchaR(open),http://127.0.0.1:80/,Nil,nil,o);
SShellexecute('http:+ipaddr+':'+in-tostr(aport)+'/','',secmdopeN)
end i
Try to change the ip address in line 132 of
http://www.softwareschule.ch/download/
工P:=工 PADDR with a DHCP or dynDNS address,
webof 2013 pdf
so you can reach arduino from an android, but also
change settings
http://www.softwareschule.ch/
maxbox. htm
Somenotesatlastaboutfirewallsorproxy-servers.http://www.indyproject.org/
It depends on your network infrastructure to get a
Sockets/index. EN. aspx
file or not, maybe you cant download content
Socket-error#10060andatimeouterror.http://fritzing.orgrg/wiki/arduino
cause of security reasons and it stops with
http://en.wikipedia
Furthermore,italsodependsonthefirewallinusehttp://sourceforge.net/projects/maxbox
at both ends. If it's automatic and recognises data
http://sourceforge.net/projects/
that needs a response automatically it will work
delphiwebstart
It needs an administrator to open ports etc you're
http://www.blaisepascal.eu/index.php?
stuffed or configured
actie=/ subscribers/
Hope you did learn in this tutorial the theme of
UK Electronics Department
Arduino with a web server. The Arduino is an
amazing device and will enable you to make
http://www.blaisepascal.eu/subscribers/
anything from interactive works of art to robots. vogelaar elctronics info_ english.php
With a little enthusiasm to learn how to program
APPENDIX DELPHI CONTROLLER
the arduino and make it interact with other
components a well as a bit of imagination
Regulated
Activity LED
3.3Dc
you can build anything you want
Power supply
M324D40
The arduino can also be extended with the use
of Shields which circuit boards are containing
other devices(e.g. GPS receivers, LED Cubes,
7.37 MHz
Delphi CPU
LCD Displays, Sneakers, MIDI Synthesizers,
Ethernet connections, etc. that you can simply
40 pin yo extender
slot into the top of your Arduino to get extra
Function select
functionality
The arduino board is made of an atmel avr
microprocessor, a crystal or oscillator(basically a
http://www.blaisepascal.eu/index.php
?actie=/subscribers/UK Electronics Department
crude clock that sends time pulses to the micro-
controller to enable it to operate at the correct what
DELPHI SCHEMA
type of Arduino you have, you may also
Temperature sensor
have a USB connector to enable it to be
connected to a PC or Linux to upload or
10 segment LED Bar
retrieve data. The board exposes the
vE09206
micro-controllers I/O(Input/ Output
Delphi
pins to enable you to connect those pins
Controller
日日
to other circuits, buses or to sensors, etc
Feedbackpleaseto:maxgkleiner.com
Push button
2 Digit LED
User extension (opt. TCP/IP
Literature
Kleiner et al. patterns konkret, 2003
Rs232/Rs485
Software Support
Issue Nr 6 2015 BLAISE PASCAL MAGAZINE
faber
77
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.