---
# System prepended metadata

title: 'Part 2: Terms & Project Structure'
tags: [PyCom, ESP32, TA Stuff ESP32, Heltec]

---

# Part 2: Terms & Project Structure
###### tags: `TA Stuff ESP32` `PyCom` `Heltec` `ESP32`

In this tutorial, you will read about some terms used in IoT then we will walk you through the project structure in MicroPython which will make you ready for the next tutorial; using sensors. This tutorial is helpful for both Heltec and PyCom board owners.  
 
We will:
+ read about the difference between sensors and actuators
+ read about the different types of sensor communication
+ read about the MicroPython project structure

**If you want to learn more about the basics of electricity and circuits** before heading onwards to connecting sensors, check out [this awesome course on Khan Academy](https://www.khanacademy.org/science/physics/circuits-topic).  

As always, we'll continuously update this walkthrough. **Is there anything missing or unclear, or have you experienced some issue? Please add a comment.** You do this by highlighting the text and then you can write a comment on the highlighted part. You need to log in/create an account on hackMD first.  

## Sensors & Actuators

### Sensors
Sensors are physical devices used for converting physical and natural quantities into electrical signals. There are different varieties of sensors like; Temperature, Pressure, Motion, Level (Water & Liquids), Image, Proximity, Water Quality, Chemical, Gas, Smoke, Infrared (IR), Acceleration, Gyroscopic, Humidity, Optical, and many more. These sensors have two broad categories; those which create continuous sine form output called **Analog Sensors** and those that produce discrete digital output **0s and 1s** are called **Digital Sensors**. 

### Actuators
Actuators are physical devices converting electrical signals into physical actions. They are changing the state of a device by using different forces like; Pneumatic, Hydraulic, Electric, Thermal, Magnetic and more.  

## Sensors Communication Protocols 
These are more advanced concepts and we do not expect you to learn them, but if you have got sensors or building a project that needs to use a sensor it would help you to understand it better. We just give a very brief overview and you can study them further by clicking on the links provided.  

### SPI
SPI (**Serial Peripheral Interface**) is a common communication protocol used by many different devices, like; SD card reader modules, RFID card reader modules, and OLED screens. It is a Master/Slave communication meaning there is a Master who selects which slave could use the data line at the moment. It uses four pins for communication, and you can read more about how it works [**here**](https://www.circuitbasics.com/basics-of-the-spi-communication-protocol) and for the MicroPython interaction, you can read [**PyCom**](https://docs.pycom.io/firmwareapi/pycom/machine/spi/).  
![](https://i.imgur.com/tcJYnfM.png)  

### UART
UART stands for **Universal Asynchronous Receiver/Transmitter** and is one of the most used device-to-device communication. It’s not a communication protocol like SPI and I2C, but a physical circuit in a microcontroller, or a stand-alone IC. A UART’s main purpose is to transmit and receive serial data. You can read more about how it works [**here**](https://www.circuitbasics.com/basics-uart-communication/) and how to use it in MicroPython you can read [**PyCom**](https://docs.pycom.io/firmwareapi/pycom/machine/uart/).  
![](https://i.imgur.com/XdX3DbL.png)  

### I2C
I2C stands for **Inter-Integrated Circuit** and is a multi-master multi-slave communication protocol. You can connect multiple slaves to a single master (like SPI) and you can have multiple masters controlling single, or multiple slaves. This is useful when you want to have more than one microcontroller logging data to a single memory card or displaying text to a single LCD. You can read more about how it works [**here**](https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol) and on how to use it in MicroPython you can read [**PyCom**](https://docs.pycom.io/firmwareapi/pycom/machine/i2c/).  
![](https://www.kernel.org/doc/Documentation/i2c/i2c.svg)  

 ### 1-Wire  
1-Wire is a device communications bus system designed by Dallas Semiconductor Corp. that provides low-speed (16.3 kbit/s) data, signaling, and power over a single conductor. 1-Wire is similar in concept to I²C, but with lower data rates and longer range. It is typically used to communicate with small inexpensive devices such as digital thermometers and weather instruments. You can read more about it [**here**](https://en.wikipedia.org/wiki/1-Wire) and for using it read MicroPython [**PyCom**](https://docs.pycom.io/tutorials/hardware/owd/) documentation.  
![](https://i.imgur.com/xCHzEKR.gif)  

<br><br>
   
## Project Structure  
This section describes the file structure in MicroPython projects.
### Projects File Hierarchy 
When creating a new project there is a standard structure to follow: 
```
Your_project_name
|-lib
| |-library.py
|-boot.py
|-main.py
``` 
Note that `boot.py` and `main.py` are outside of the `lib` folder while `library.py` is inside the `lib`. All of them are, however, inside the project folder `Your_project_name`.  

In the respective IDEs, Atom and Thonny, the same structure will look like this:
Atom project        | Thonny project
:-------------------------:|:-------------------------:
![](https://i.imgur.com/ple2Y11.png)    | ![](https://i.imgur.com/A7kWjDA.jpg)

* The `lib` folder will hold libraries, that is, code files you may have use of in your project. This could for example be sensor libraries; already written code that makes it easy for you to make sense of the sensor's output data. You will read more about how you import libraries and use them in the next tutorial.
* The `boot.py` file is the first script that runs in the device when it is powered on. It could be used for setting up a  WiFi connection and thus declutter the main file where this code otherwise would be placed. Most often you don't have to worry about this file.
* The `main.py` file is where you tell the device what to do. It will run directly after the boot file. This is the place for your main code and where you may use files in the lib folder.

### Creating a new project
You may create a new project and this file structure by doing the following: 
* First you will open a new folder by clicking `File > Open Folder`. This will lead you to your file explorer, now create a new folder, and name your project. Select this folder and open it. 
* Now, for **Atom** inside the project manager area, right-click on your mouse or mousepad and select a file or folder to name and create them. It is also possible to create files from `File > New File` in both **Atom** and **Thonny**, just remember to save them in the right folder. 

Atom project        | Thonny project
:-------------------------:|:-------------------------:
![](https://i.imgur.com/IbstUjS.png) | ![](https://i.imgur.com/1TLdqiE.jpg)

:::success
Now you know some theories about sensors and the terms used in IoT sensors. You also know how projects are structured in MicroPython and are ready to move to the next tutorial to learn about your development board and how to connect sensors to it for collecting some data.
:::
