Академический Документы
Профессиональный Документы
Культура Документы
Textbook Arduino Programming With Net and Sketch 1St Edition Agus Kurniawan Ebook All Chapter PDF
Textbook Arduino Programming With Net and Sketch 1St Edition Agus Kurniawan Ebook All Chapter PDF
NET and
Sketch 1st Edition Agus Kurniawan
Visit to download the full and correct content document:
https://textbookfull.com/product/arduino-programming-with-net-and-sketch-1st-edition
-agus-kurniawan/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...
https://textbookfull.com/product/arduino-programming-with-net-
and-sketch-1st-edition-agus-kurniawan-2/
https://textbookfull.com/product/raspbian-os-programming-with-
the-raspberry-pi-iot-projects-with-wolfram-mathematica-and-
scratch-1st-edition-agus-kurniawan/
https://textbookfull.com/product/beginning-arduino-nano-33-iot-
step-by-step-internet-of-things-projects-1st-edition-agus-
kurniawan/
https://textbookfull.com/product/iot-projects-with-nvidia-jetson-
nano-ai-enabled-internet-of-things-projects-for-beginners-agus-
kurniawan/
Modern Data Access with Entity Framework Core: Database
Programming Techniques for .NET, .NET Core, UWP, and
Xamarin with C# 1st Edition Holger Schwichtenberg
https://textbookfull.com/product/modern-data-access-with-entity-
framework-core-database-programming-techniques-for-net-net-core-
uwp-and-xamarin-with-c-1st-edition-holger-schwichtenberg/
https://textbookfull.com/product/modern-data-access-with-entity-
framework-core-database-programming-techniques-for-net-net-core-
uwp-and-xamarin-with-c-1st-edition-holger-schwichtenberg-2/
https://textbookfull.com/product/programming-arduino-next-steps-
going-further-with-sketches-2nd-edition-simon-monk/
https://textbookfull.com/product/arduino-measurement-projects-
for-beginners-arduino-programming-basics-and-get-started-guide-
simone-bales/
https://textbookfull.com/product/sql-server-database-programming-
with-visual-basic-net-concepts-designs-and-implementations-ying-
bai/
Arduino
Programming with
.NET and Sketch
Agus Kurniawan
Arduino Programming with .NET and Sketch
Agus Kurniawan
Depok
Indonesia
ISBN-13 (pbk): 978-1-4842-2658-2 ISBN-13 (electronic): 978-1-4842-2659-9
DOI 10.1007/978-1-4842-2659-9
Library of Congress Control Number: 2017936052
Copyright © 2017 by Agus Kurniawan
Any source code or other supplementary material referenced by the author in this book is
available to readers on GitHub via the book's product page, located at www.apress.com/
9781484226582. For more detailed information, please visit http://www.apress.com/
source-code.
Contents at a Glance
Introduction������������������������������������������������������������������������������������� xv
■
■Chapter 1: Introduction to Arduino Boards and Development�������� 1
■
■Chapter 2: Interfacing .NET and Arduino�������������������������������������� 21
■
■Chapter 3: Sensing and Actuating������������������������������������������������ 45
■
■Chapter 4: Windows Remote Arduino������������������������������������������� 69
■
■Chapter 5: Building Your Own IoT Using Arduino and .NET�������� 109
Index���������������������������������������������������������������������������������������������� 165
Contents
Introduction������������������������������������������������������������������������������������� xv
■
■Chapter 1: Introduction to Arduino Boards and Development�������� 1
Exploring Arduino Boards������������������������������������������������������������������������ 1
Arduino Boards for Beginners���������������������������������������������������������������������������������� 2
Arduino Boards for Advanced Users������������������������������������������������������������������������� 3
Arduino for Internet of Things����������������������������������������������������������������������������������� 4
Arduino-Compatible�������������������������������������������������������������������������������������������������� 7
Summary��������������������������������������������������������������������������������������������� 107
■
■Chapter 5: Building Your Own IoT Using Arduino and .NET�������� 109
Introduction to Internet of Things and Arduino������������������������������������ 109
Connecting Arduino to Internet Network��������������������������������������������� 110
Connecting to a Wired Network���������������������������������������������������������������������������� 110
Connecting to a WiFi Network������������������������������������������������������������������������������ 114
Summary��������������������������������������������������������������������������������������������� 163
Index���������������������������������������������������������������������������������������������� 165
Introduction
Arduino is a board development platform with which we can develop an embedded
application with several sensor and actuator devices. Arduino is an open source-based
hardware. There are many Arduino models that you can use to develop. This book is
designed for developers (especially for .NET developers) that want to build Arduino
programs for general and specific purposes.
Introduction to Arduino
Boards and Development
Arduino is one of the most famous development boards. You can attach sensor and
actuator devices easily into the board. This chapter will explore how to work with Arduino
development and prepare for a development machine. To work on this chapter, you
should have one of the Arduino board models for implementation.
This chapter covers the following topics:
• Exploring Arduino boards.
• Setting up development.
• Building your first project.
• Sketch programming.
• Arduino programming using Visual Studio.
The advantage of an Arduino board is it’s easy to use. You don’t need to solder
electronics components. An Arduino board is ready to use. You just attach sensor and
actuator devices into the board via jumper cables.
In this section, we explore various Arduino boards from Arduino LLC and Arduino
SRL. Each Arduino model has unique features. To optimize Arduino board usage, you
should know and understand what kind of Arduino model it is. I will introduce various
Arduino models based on complexity level and usage range.
Let’s start to explore Arduino boards.
2
Chapter 1 ■ Introduction to Arduino Boards and Development
3
Chapter 1 ■ Introduction to Arduino Boards and Development
Most Arduino boards don’t have a built-in debug chip, so if you want to debug our
program, you should add an additional debug tool. Fortunately, we can use the Arduino
ZERO board (https://www.arduino.cc/en/Main/ArduinoBoardZero) from Arduino LLC
and the Arduino M0 PRO board (http://www.arduino.org/products/boards/arduino-
m0-pro) from Arduino SRL, which are supported for debugging without additional tools.
These boards have Atmel’s Embedded Debugger (EDBG) to be used for debugging.
I suggest you to use these Arduino models if you have concerns about debugging without
additional tools. A form of Arduino Zero board is shown in Figure 1-4.
4
Chapter 1 ■ Introduction to Arduino Boards and Development
5
Chapter 1 ■ Introduction to Arduino Boards and Development
Most Arduino boards work with an RTOS environment. Arduino YUN combines
MCU and WiFi MCU, which runs OpenWrt Linux (called Linino OS). This board likes a
mini-computer with Linux OS. You can control Arduino MCU ATmega32u4 from Linux.
We also can access Linux API from the Arduino program. The Arduino YUN board
has built-in WiFi and Ethernet modules to solve your IoT cases. Figure 1-7 is a form of
Arduino YUN. You can review and buy this board on this site: http://www.arduino.org/
products/boards/arduino-yun.
If you’re looking for an Arduino with BLE connectivity capability, you can consider
using the Arduino/Genuino 101 board, which is shown in Figure 1-8. This board uses
Intel Curie as MCU, which has a built-in BLE module. You can control this board
through Bluetooth on your smartphone, such as Android and iPhone smartphones.
For further information about Arduino/Genuino 101, I recommend reading this website:
https://www.arduino.cc/en/Main/ArduinoBoard101.
6
Chapter 1 ■ Introduction to Arduino Boards and Development
Arduino-Compatible
In general, the original Arduino board price is expensive. If you have pricing issues on
your Arduino learning process, you could buy an Arduino-compatible board. As we know,
Arduino shares its design and scheme under an open source project. It means we can
build our own Arduino board without using the “Arduino” name for our board. Arduino-
compatible boards usually are manufactured by third-party companies. This section will
go through various Arduino-compatible boards in the market.
SparkFun RedBoard is a kind of Arduino-compatible board which is manufactured
by SparkFun. This board has a form like the Arduino UNO board and uses ATmega328
as MCU with installed Optiboot (UNO) Bootloader. For development, we can use
Arduino IDE to write a Sketch program and then flash the program to the board. If you
are interested in SparkFun RedBoard, you can buy it on https://www.sparkfun.com/
products/12757. You can see SparkFun RedBoard in Figure 1-9.
7
Chapter 1 ■ Introduction to Arduino Boards and Development
8
Chapter 1 ■ Introduction to Arduino Boards and Development
9
Chapter 1 ■ Introduction to Arduino Boards and Development
Now you can attach the Arduino board into your computer. If you have Arduino
boards based on ATTiny and ATMega MCUs such as Arduino UNO, you don’t need to
install a driver. Arduino software has installed it for you.
For instance, I attach my Arduino UNO on Windows 10; I obtained that my Arduino
UNO board is recognized as COM5, shown in Figure 1-13.
You also need Visual Studio to develop a .NET application, which accesses Arduino
boards. If you don’t have a Visual Studio license, you can download and install Visual
Studio Express edition on this URL: https://www.visualstudio.com/vs/visual-
studio-express/. For testing, I use Visual Studio 2015 with update 2. It is shown in
Figure 1-14.
10
Chapter 1 ■ Introduction to Arduino Boards and Development
We learn how to develop a .NET application to control our Arduino boards in the
next chapter. Make sure you have the Visual Studio tool. In the next section, we try to
build a simple Arduino program using Arduino software. We use a built-in LED on an
Arduino board.
11
Chapter 1 ■ Introduction to Arduino Boards and Development
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
12
Chapter 1 ■ Introduction to Arduino Boards and Development
You may see value 13 is replaced by LED_BUILTIN, which is shown in the following code:
void setup() {
// initialize digital pin 13 as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
Save this program. To compile the program, you can click the Verify icon. Before
uploading the program into an Arduino board, you should configure your IDE. Change
the Arduino board target by clicking menu Tools ➤ Board (Figure 1-16). Then, you also
need to set a serial port of the attached Arduino board by clicking menu Tools ➤ Port.
13
Chapter 1 ■ Introduction to Arduino Boards and Development
After it’s configured, you can compile and upload the program. Click the Upload
icon. You can see Verify and Upload icons in Figure 1-17.
If you succeed, you should see a built-in LED is blinking. For instance, Arduino UNO
has a built-in LED which is shown in Figure 1-18.
14
Chapter 1 ■ Introduction to Arduino Boards and Development
Sketch Programming
To develop an Arduino app, you should know Sketch programming. In general, Sketch
program uses C/C++ syntax. If you have experience in C/C++, you should be able to write
an Arduino program easily.
The thing that you should know is to understand a sketch programming model.
A sketch program uses two functions to run an Arduino program. The following is a
sketch program in general.
setup() {
// do something
}
loop(){
// do something
}
On setup() function, the sketch program will execute once. However, loop() function
is a function which is executed continually.
If you can build your own functions, then put them in either setup() function or
loop() function. For instance, I created foo() and perform() functions and executed them
on my Sketch program as follows.
perform() {
We also need to know some APIs in Sketch program. I recommend you read these
on the official website. You can read it on https://www.arduino.cc/en/Reference/
HomePage from Arduino LLC. Arduino SRL provides the reference website in http://www.
arduino.org/learning/reference.
15
Chapter 1 ■ Introduction to Arduino Boards and Development
Now you can bring your Sketch program into Visual Studio. You can write Sketch
program into Visual Studio. For instance, we can write Sketch program by selecting Blink
Led Example from Visual C++ ➤ Visual Micro.
After it’s selected, we can see a blinking Sketch program in Visual Studio editor
(see Figure 1-20). You should find xxx.ino file where xxx is a Sketch file.
16
Chapter 1 ■ Introduction to Arduino Boards and Development
Before you build and upload sketch, you should configure an Arduino board target.
You should see a list of Arduino board model. You can see it in Figure 1-21. Select your
Arduino board model from the list.
17
Chapter 1 ■ Introduction to Arduino Boards and Development
You also need to configure a serial port for Arduino. You can see its configuration on a
menu which is shown in Figure 1-22. Build and upload menus also can found on that toolbar.
Figure 1-22. Menu for selecting serial port, building, and uploading
Save your sketch. Then, try to build and upload the program. The program will run
on an Arduino board. Visual Studio debugger also runs. You can see it in Figure 1-23.
18
Chapter 1 ■ Introduction to Arduino Boards and Development
Summary
We have explored various Arduino models and tried to build a simple Arduino program
using Arduino software. We also built an Arduino program using Visual Studio and then
deployed it into an Arduino board.
You can now practice developing Arduino programs with sketch. In the next chapter,
we build an interface program to communicate between a .NET application and Arduino
boards.
19
CHAPTER 2
To access an external resource from Arduino I/O, we should deal with protocol
format. In general, Arduino boards have the following three communication models:
• serial communication
• SPI communication
• TWI/I2C communication
We use these communication models to communicate with a .NET application. Each
communication will be explained on the next section. Sketch will be used to describe how
these I/O communication work.
Let's explore!
22
Another random document with
no related content on Scribd:
Universale provata con monumenti [106], parlando degli scavi nello
stesso terreno, praticati nel 1689, e com’egli dice, alle radici del
monte Vesuvio, in lontananza di un miglio in circa del mare, recando,
a maggiore autorità una nota di Francesco Pinchetti, ch’ei chiama
architetto celebre in Napoli per la sua professione e molto più per il
museo sceltissimo ed antichità erudite da sè raccolte, fa chiaro che il
Pinchetti e altri con lui reputassero come le lapidi romane e le
osservazioni sue istituite sulla natura dei varj suoli scavati, fossero
fatte nel loco dove era la villa di Pompeo. Esso monsignor Bianchini
nondimeno non restò di soggiungere un proprio dubbio che, cioè, le
iscrizioni vedute dal Pinchetti, e da lui non ancora, potessero
spettare invece alla città di Pompei, e non ad una villa del magno
Pompeo e de’ di lui figliuoli; perciocchè la villa di quella famiglia e di
quel massimo capitano, da Loffredo si giudica non essere stata sotto
al Vesuvio, ma piuttosto verso Pozzuolo, non molto discosta dal lago
Averno.
La storia quindi degli scavi non parte che dal 1748, quando alcuni
agricoltori, avendo fatto delle fosse per piantagione d’alberi, si
imbatterono nelle mura di un edifizio e in una statua di bronzo.
Siffatta notizia portata a cognizione di Carlo III, regnante allora,
principe d’alti concepimenti, comunque despota per eccellenza [107],
— desti già la sua attenzione e l’interesse della scoperta da poco
tempo fatta di Ercolano, — come aveva fatto per gli scavi di questa
città, fece pur acquisto di tutto il terreno su cui quegli agricoltori
avevano lavorato e casualmente scoperta Pompei e posto mano ad
intraprendere escavazioni, gli venne dato di ottenerne i vagheggiati
risultamenti.
La sorte eguale con Pompei avuta dalla città di Ercolano nella
sciagura e il destino quasi identico e contemporaneo delle
escavazioni, reclamano che una breve parola io dica qui
dell’occasione fornita di una tale resurrezione intorno ad Ercolano.
La storia di questa città sorella e quella de’ suoi scavi completa
quella di Pompei: è quasi impossibile il tenerle onninamente divise:
l’una all’altra soccorre indubbiamente.
Neppur d’Ercolano sapevasi la precisa ubicazione. Emanuele di
Lorena, principe di Elbeuf, venuto, a capo dell’esercito imperiale
contro Filippo V, in Napoli nell’anno 1713, innamoratone del cielo e
del clima, e già sposo alla figliuola del principe di Salsa, prese ad
erigersi a Portici una villa; un contadino, levato dalla escavazione
d’un pozzo alcuni marmi, avendoglieli offerti, fu il primo indizio che lo
guidasse sulle traccie della sepolta città ed estesi subito gli scavi,
non corse guari che rinvenisse iscrizioni romane ed osche, un
tempio con ventiquattro colonne, ed altrettante statue in giro, una
statua d’Ercole ed una di Cleopatra. Eureka! fu gridato da lui e dai
dotti; Ercolano è risorta.
I primi capolavori di bronzo e di marmo ritornati alla luce, proprietà di
chi li aveva trovati, andarono ad arricchire musei stranieri; non così
per altro che i moltissimi rinvenuti di poi non valessero a costituire
tutta una preziosissima raccolta in Napoli di pitture, di vetri, di
medaglie, di utensili, di busti e principalmente delle due sole statue
equestri in marmo che l’antichità ci abbia trasmesso: quelle dei
Balbo, padre e figlio. E a mille si trovarono i papiri più greci che latini;
in questi come nelle arti più ricca Ercolano che non Pompei; onde ne
nacque l’idea della creazione d’un’academia la quale illustrasse i
monumenti dell’antico che si sarebbero rinvenuti negli scavi e che si
intitolò Ercolanese.
Il re Carlo III, fin dalla prima scoperta, ad impedire che le antiche
preziosità che si sarebbero diseppellite passassero all’estero, con
grave nocumento del paese, s’affrettava a ricomprare dal principe di
Elbeuf quella proprietà, e spingendo con sollecitudine i lavori di
escavazione, era egli che aveva ottenuta la certezza che fosse
quell’antica città d’Ercolano.
Ma quegli scavi tornavano difficili, anzi pericolosi. Su quella città non
era stato un lieve sepolcro di ceneri e di scorie soltanto, come in
Pompei, che il Vesuvio aveva posto, ma uno greve e di lava e di
lapilli infuocati; onde quel sepolcrale coperchio, dello spessore in più
luoghi perfino di venti metri, aveva cotanto persuaso di sua solidità,
da far credere che fosse tutta una vera roccia vulcanica e non lasciar
sospettare che mai si celasse al di sotto, che le sorvenute
generazioni vi avevano confidenti fabbricato su tutta una città ed un
villaggio, Portici e Resina e sulle sontuose ville di romani guerrieri,
eretto inconsapevolmente palagi eleganti di artisti di canto e d’altri
facoltosi. Intraprese le escavazioni, era stato mestieri, non come in
Pompei, far uso della marra, per liberare i sottoposti edificj, ma della
mina, nè si potè agire che colle maggiori cautele, perocchè a chi
scenda e penetri dentro gli scavi ercolanesi rechi sorpresa e
spavento l’udirvi sovra del capo il rumoreggiar de’ carri e degli
omnibus che animano la graziosa Portici ed anzi paresse necessità
di nuovamente interrare più luoghi frugati ad impedire il disastro di
rovine, privando le moli sovrastanti de’ loro antichi e naturali
sostegni. Laonde l’intera scoperta d’Ercolano e il ricupero di tutte le
preziosità che nasconde non sarà mai possibile sin quando non
vengano abbattute le belle case e villeggiature di Portici, nè io sarò
mai per dire che metta proprio conto di pur ciò desiderare.
Non a torto quindi il medesimo monarca s’era sollecitato a recare in
sua proprietà anche il terreno sotto cui tutto creder faceva
ascondersi Pompei, acciò non fosse frodato il paese di quanto vi si
sarebbe potuto trovare ed a commettere l’esecuzione su più
conveniente scala delle ricerche e degli scavi, resi essi più agevoli
dalla men dura materia che li copriva, perocchè quivi non si trattasse
che di rimuovere gli strati di ceneri commiste alle pomici, oltre quella
superficie che vi si era sopra distesa e che già avea servito alla
coltivazione.
A riguardo di queste due nobili città rivenute al giorno, potevasi dire
suggellato il vaticinio dal Venosino espresso nell’Epistola sesta del
libro I a Numicio:
e che se potemmo dare mentita nel passato a chi Italia aveva detto
nome geografico e nulla più, non era stato che per ciò solo che mai
non avevamo perduto lo scettro dell’Arti Belle.
Discorso dell’origine, del progresso e dello stato attuale delle
escavazioni, quantunque il perimetro della città non sia peranco
interamente sterrato; pure dai fatti esperimenti fu dato misurarne
l’estensione che si computa a circa quattro miglia, compresi i
sobborghi, ed è concesso di fornirne la topografia.
Pompei venne costruita su di una collina digradante al mare che in
passato la circondava da due lati e ne costituiva quasi una penisola.
Se si riguarda alla pietra su cui si fonda e che è di natura vulcanica,
anzi direbbesi antichissima lava, si avrebbe argomento a credere
che il terribile incendio del Vesuvio del 79 fosse stato ne’ tempi
caliginosi della storia preceduto da altri non minori cataclismi, pei
quali la lava o fosse fin qui fluita da quel formidabile serbatojo, o
avesse trovato altri aditi divisi dal cratere per uscire ad allagare la
circostante pianura; seppure questa collina stessa non fosse una
bocca vulcanica pari ad altre che si veggono attorno al Vesuvio.
Strabone portò l’egual congettura, constatando prima la sterilità della
vetta cinericcia del Vesuvio, poi le sue profonde caverne e le diverse
spaccature, e reputò doversi per avventura attribuire al suo fuoco e
alle sue ceneri la miracolosa fertilità, per la quale va la Campania
distinta.
Ma più specialmente catastrofi non di molto dissimili toccate a’ paesi
circostanti, sia per tremuoti come in quello memorabile da me riferito
del 63 di Cristo, sia per eruzioni ed anche a Pompei, lo attesterebbe
il nome stesso della città, se è vero quel che afferma la Dissertatio
Isagogica di C. Rosini, che essa venisse chiamata dapprima
Pompìa, e che ciò significhi fuoco spento [109]. Nella Via delle Tombe
inoltre vennero trovati in qualche luogo negli scavi, esistenti sotto le
costruzioni di romana origine, avanzi di altre precedenti opere
muratorie d’epoca assai remota e oggetti d’origine etrusca. Dalla
parte opposta a Napoli, da cui dista forse una quindicina di
chilometri, ho già detto che il seno che vi formava il mare ed entro
cui aveva la propria foce il Sarno, avesse costituito naturalmente un
porto capace di molte navi, anzi, secondo alcuni, perfino di una
intera flotta e che giovava ai bisogni non della sola Pompei, ma di
Acerra e di Nola, onde per i legni che scendevano o risalivano di
continuo codeste sponde, avesse ragione Strabone di designarlo
come un importante porto e di far della città un vero emporio, molto
più che, navigabile allora il Sarno, avesse preferenza sui porti di
Stabia e d’Ercolano, per il vantaggio che offriva del trasporto delle
merci che giungevano nell’interno del territorio.
Più in là del porto e verso Stabia — ed or direbbesi verso la via che
scorge a Castellamare, città che sorge appunto sulle rovine di
Stabia, fatte prima da Silla e compiute poi dal Vesuvio — erano le
Saline di Ercole, di cui si veggono oggi pur le vestigia nel luogo detto
Bottaro e la palude a cui fa cenno L. G. Moderato Columella, non
che il verso seguente che ne fa gradevole menzione: