-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Internet of Things from Scratch
By :

In this section, we will walk you through setting up the foundational development environment for the book. There may be additional configurations that will need to be done for specific chapters, but the setup here will be enough for you to make those additional ones with ease. The two main components that need to be set up here are the Arduino IDE for uploading code to your ESP32 microcontroller and your GitHub environment for source control. Note that ESP-32 is not part of the Arduino family hardware; we are simply using it as it is an editor that supports the development of ESP-32. We will also set up your AWS environment, but we will explore that in Chapter 7, Working with Cloud Computing to Power IoT Solutions where working with your workloads on AWS will be discussed further.
Your Arduino IDE environment is where you will be working with your code and uploading that code onto your ESP32. Note that you are not limited to only using the Arduino IDE environment for doing this, so if you are familiar with other environments, feel free to use them. For the purposes of this book, we will be working with this IDE.
The Arduino integrated development environment (IDE) is a powerful, user-friendly software platform designed for programming and interacting with Arduino microcontroller boards. The IDE makes it easy for beginners to get started with microcontroller programming while also offering advanced features for experienced developers. In this section, we will guide you through the process of setting it up on your computer, enabling you to bring projects described in this book and beyond to life:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
. Click OK.esp32
into the search bar. Click Install on the latest ESP32 version that pops up:Figure 1.4 – Accessing Boards Manager on the Arduino IDE
void setup() { // put your setup code here, to run once: } void loop() { // put your main code here, to run repeatedly: }
To see whether your IDE is working correctly, click on Verify, which is the button in the top-left corner of the screen.
Check your IDE’s terminal to see whether the code has been uploaded successfully.
With this, your Arduino IDE should be set up and ready to be used. We can now proceed to try it out with our inaugural Hello World exercise.
To test the functionality of the ESP32 and to give you a taste of working with your new development kit, we are going to create the equivalent of a Hello World exercise—a practical exercise to light up a red LED bulb.
For this, you will need the following components:
As you go along, you can refer to the upcoming assembly diagram to see the placement of the components on the board and get an overall idea of what we are trying to create to follow the instructions more easily.
Now, we will proceed to set up the hardware accordingly. The following figure shows the breadboard diagram that can be used as a reference while you follow the instructions to wire up the board, breadboard, LED, and resistor:
Figure 1.5 – Breadboard diagram for connecting the LED
Now we have successfully set up the hardware that is needed for this practical exercise. We can now move on to producing the necessary code on our Arduino IDE.
Now, we will upload the code for running the LED experiment to the ESP32. Use the following code for this purpose:
const byte led_gpio = 32; void setup() { pinMode(led_gpio, OUTPUT); } void loop() { digitalWrite(led_gpio, HIGH); delay(1000); digitalWrite(led_gpio, LOW); delay(1000); }
In the setup
section of the code, the digital pin led_gpio
is initialized as an output. Within the loop
section of the code, we are simply alternating between turning the light on and off (as indicated by the high and low). Each wait 1,000 milliseconds—equivalent to one second—before switching to the next state, as seen with the delay
statement.
And with that, you’ve just created your first IoT program on the ESP32!
GitHub is a code repository platform that is used for version control and collaboration on your code. With it, developers can track changes to code and collaborate on a project, while also setting extra restrictions for changes as part of best practices such as letting developers review each other’s code and merge changes from anywhere. We will be using GitHub throughout this book for you to both use the platform to pull the code that we use throughout our chapters and put in your code.
To start, we will create our GitHub account to use to set up our repository:
You now have a GitHub account, which is the first step for setting up our version control environment and for making optimum use of the resources of this book that are ready for you to pull onto your local environment.
When you pull code or create local repositories to push up to GitHub, it is much easier if you use the command-line interface (CLI). The following are the steps that you need to take to install the CLI on your laptop:
2.21.1
, but this may change, so navigate accordingly) and download the file that ends with windows_amd64.msi
.Path
variable within the user variables for your account. Click New and add the path of the folder that contains your GitHub installation.git –version
. If the output returns the version, that confirms that Git is already installed.$ git config –global user.name "{firstname} {lastname}"
$ git config –global user.email "{youremail}"
$ ssh-keygen -t ed25519 -C "{youremailhere}
id_ed25519
file that is generated in a text editor of your choice and copy the contents of the file.Access
section, click on the SSH and GPG keys.Title
field, add a label that describes the purpose of your key, such as an identifying name for the device you are linking it with. Select the type of key, which in this case is Authentication Key. Paste the key that you have copied into the Key field and click the SSH key.Figure 1.6 – GitHub page to add a new SSH key
You should now have authorized your device to modify repositories on GitHub, so we will now be able to push code from our local development environment onto the GitHub repositories.
If your CLI is configured properly, you should be able to pull the code from the repository straight to your local development environment:
$ git clone {SSHLine}
Your GitHub repository is where you will be storing, committing, and pushing your code. You will need to create one via GitHub to then push and pull to and from your local development environment:
You should now be able to push to the repository as part of the next section.
These four steps are a crucial part of any GitHub experience, as you want to store the code and continually update the repository based on the changes you have done to collaborate with others or simply just to track the changes that you have made as part of the version control process.
To understand how these four steps work for your projects, let’s go through them:
.git
folder should be initialized in your folder:$ git init
$ git add .
$ git commit -m "{Your commit message here}"
$ git remote add origin {remoteURL}
$ git remote -v
$ git push origin main
Note that if the folder is already initialized as a local repository and the remote URL is already set, we will only have to repeat steps 2, 3, and 6 for every consecutive push.
Now that we have the skills for GitHub, let’s use it to push your newly created Hello World LED project’s code into GitHub:
git init
to initialize the folder as a repository:$ git init
$ git add .
$ git commit -m "Created Hello World LED IoT Project"
git remote add origin https://github.com/renaldig/firstledproject.git
$ git push origin main
And with that, you have your first repository good to go! Try to practice making a few changes to your code and repeating the process. See whether you can answer the following questions:
With this, you should now be able to use the Arduino IDE, try out a practical exercise that demonstrates the capabilities of Arduino at a high level, and create and use GitHub in your local environment for version control. In the next section, we will explore how we can choose between IoT hardware, considering the unique set of requirements that projects need.
Change the font size
Change margin width
Change background colour