---
# System prepended metadata

title: '**Tutorial on how to measure the room temperature, how to transmit temperature data and Switch code to Pybytes and how to connect an antenna to Helium**'

---

# **Tutorial on how to measure the room temperature, how to transmit temperature data and Switch code to Pybytes and how to connect an antenna to Helium**
- [x] *Adriana Ulici, student LNU: au222fd* 
- [x] *July 2021*
- [x] *Short project overview:* The tutorial contains three themes. The first one is about how to connect a sensor to the computer via Pycom, to get the temperature. 🌡️ The second one is about how to connect a Switch sensor. The data collected with the temperature and Switch sensor is transmitted to Pybytes, also getting the device location. The third theme is how to connect an antenna to Helium, searching for the closest network. 
- [x] *How much time it might take to do:* You must have the codes for the temperature and the Switch. Once you have the Visual Studio Code installed and you are registered in Pybytes and the Helium Console, it would take approximately 2+1 hours to run the code for the temperature and the Switch. 

![](https://i.imgur.com/4KVVtnx.jpg)


| Visual Studio Code | Pybytes | Helium |
| -------- | -------- | -------- |
| File main.py or boot.py    | Temperature / Switch     | Antena    |


### Objective
- [x] (Why I chose the project) I chose this project for two principal reasons: The first reason is that I consider it is adequate to my level, as a total beginner in Computer Science. The second reason is that I considered it would be interesting to follow the work I did in the workshops during the course, showing the challenges, what I succeeded to do with the help of the TAs, and the issues I found and fixed (I don't want to use the word "problem", lol 😎). 
- Before starting the course, I had in mind some more interesting projects I could make:
    - Tracking a car / a phone / elderly people.
    - Connecting and controlling devices like a Smart TV or a Healthkeep to the computer.
    - Measuring the humidity of the room.
    - Getting a notification when the email has arrived.
    - Placing a wireless doorbell on the outside doorway, to ring in a room.
    - Setting up a home alarm.
    - Placing a surveillance camera at home.
    - Setting up a video intercom on the exterior door.
- I guess I had too ambitious dreams. For now, I am missing more material, time, knowledge and information from the manufacturer (developer) about the Healthkeep application. In the next courses, some of these ideas will be done, I hope.  
- [x] (What purpose does it serve?) I consider this tutorial could be a friendly guide for someone that initiates in this fascinating world of IoT. It could also be useful to avoid the issues I overcame, in order to gain time and avoid burning sensors or the breadboard.
- [x] (What insights it will give?) I included some basic information about how to install the Pycom device, the Visual Studio Code, about how to connect to Pybytes and Helium. My Tutorial contains information about how to connect the sensors to the Lopy4, how to connect the antenna. I used pictures and drawings to make it more obvious.


### Material received from Electrokit - Pack IoT
[Pack IoT Electrokit ](https://www.electrokit.com/produkt/lnu-1dt305-tillampad-iot-lopy4-and-sensors-bundle/)
Pack price 101,54€. I didn't use all the material from this pack in doing the tutorial and the workshops.

#### Pycom device Lopy4 (+ pictures)
| Device| Pycom | Lopy4 |
| -------- | -------- | -------- |
| Expansion board| Development board | Breadboard 
| Sensors + tilt switch    | Antena + wire    | Cable USB 

## Computer setup 
- [x] Editor used:
**Editor used: Visual Estudio Code**
1. Data transmitted to Pybytes via WiFi: temperature sensor and tilt Switch sensor
1. I got the location device.
1. I made a chart temperature.
1. I connected an antenna to Helium via WiFi.

- [x] Me during Workshops, lol. :smiley::sunglasses::nerd_face:
![](https://i.imgur.com/TSbS1dD.jpg)
.
![](https://i.imgur.com/TydY4wc.jpg)


## Presenting the data
#### Explaining Pybytes:
- [x] Why did I choose it? Pybytes is an important IoT platform that grants full control of the Pycom devices. The python application sends data every 5 seconds to Pybytes; it offers good data visualization. 
- [x] Being a cloud-based device management platform available for all Pycom development boards and modules, it works from a computer, smartphone or desktop.
- [x] It is a free platform. 
- [X] I used the Wifi wireless protocols to connect myself to Pybytes.
- [x] Alternatives: Some alternatives to Pybytes are: TIG-stack, Ubidots, Datacake, AWS, Google Cloud, etc. 
- [x] Functionality: Pybytes is an IoT platform designed to let users manage their connected devices. Features widget-based dashboards, mapping and much more. It permits getting device locations, Firmaware updates, etc.

### Transmitting the data / connectivity 
## Connecting temperature sensor to Pybytes
### Materials used:
* Pycom device (Lopy4) Expansion Board
* Temperature sensor
* Wires
* Usb cable 
* HP EliteBook laptop

#### Operating system: Windows
#### Visual Studio Code installation
[Link to setup](https://code.visualstudio.com/docs/setup/setup-overview/)

***Pybytes***
#### Working with Pybytes
[Link to Pybytes](https://docs.pycom.io/pybytes/gettingstarted/)
* Create an account in Pybytes:
* Add a device: select the device Lopy4
* Select the network: in my case, I set Wifi credentials (fill the entire name of the red Wifi)
* Execute the pycom_firmware_updater_1.16.5. Firmware Updater Tool must be executed, cf. link to Pymakr Plugin  
Note: Select the checked boxes in the picture! 

#### Pymakr Plugin installation 
[Link to Pymakr Plugin](https://docs.pycom.io/gettingstarted/software/vscode/)
![](https://i.imgur.com/FtWHKSn.jpg)
![](https://i.imgur.com/ACIvRIF.jpg)

* The installation process askes for a Pybytes activation token. I generated a token from Pybytes and pasted it into the Firmware Updater tool.
* I reset the Pycom device using the reset button; this rebooted the device and activated the Pybytes connection automatically. The "Last Connection" status in Pybytes changed from "Never" to "Seconds ago".

* In "Dashboard" update location - I got the device location.
***Device location***
![](https://i.imgur.com/U0r3X4v.png)
![](https://i.imgur.com/d30M2RX.png)

* In "Signals", I defined a new signal called "Temperature", value 1 and gave the name and the value in "grades Celsius"

***Temperature in Pybytes***
![](https://i.imgur.com/RnJJeAm.png)

* In "Create a new display", I got a chart that can be personalized.  
![](https://i.imgur.com/a0syNQk.png)
![](https://i.imgur.com/gj5Ozye.png)

- [x] Steps to connect the Pycom device to Pybytes with the temperature sensor
- 1: Connect Lopy4 to blackboard 
- 2: Connect the USB cable to Pycom device
- 3: Insert cables 
    - to Pycom device:
        - blue: to GND
        - red: to 3V3
        - white: to P16
    - to Expansion board 
        - blue: to -1
        - red: to +1
        - white: to B4
        - blue (only to the expansion board): -3 and a5
        - red (only to the expansion board): +4 and B3
    - to Expansion board
        - Temperature sensor: d3, d4, d5

###### Note: I almost burned the temperature sensor for placing it with the round part towards the wires. I touched it, and it was hot. :sunglasses:
------
> Observation: Connect the positive voltage leg to 3V3, the ground leg to GND and the output leg to any pin with ADC capabilities (in this case, P16).
> ⚠️Important⚠️ Some sensors have a flat and a curved face. For example the TMP36 sensor mentioned above. Make sure to connect them in the same way as the pictures since you otherwise they might burn out.
> [From Tutorial 2: Project & Sensor Setup](https://hackmd.io/@lnu-iot/BJnuGmJh_)
> 
------------------
- 4. Connect to laptop
- 5. The device blinks in 3 different colours: blue, yellow and orange.


***Temperature sensor***
![](https://i.imgur.com/heAcyJp.jpg)
.
![](https://i.imgur.com/lGdVKZx.jpg)
.
![](https://i.imgur.com/gxo11ub.jpg)

![](https://i.imgur.com/SOf435c.jpg)
![](https://i.imgur.com/rOvB80N.jpg)


***VS Code***
***Steps: ***
* Create a file named "boot.py" or "main.py".
* Write the code, cf. "link code".
* Save!
* Upload.
* Run.


- [x] ***Code used for temperature:***`from (TA) David M.` 
File created in VS Code: "main.py"
```
import machine
import time

adc = machine.ADC()
apin = adc.channel(pin='P16')

while True:
  millivolts = apin.voltage()
  celsius = (millivolts - 500.0) / 10.0

  print(celsius)

  pybytes.send_signal(1, celsius)

  time.sleep(2)
```


* I put one hand on the back of the Lopy to increment the temperature. I saw the temperature changing in VS Code.


- [x] Steps to connect Pycom to Pybytes with the Switch sensor. Lopy4 is connected to the blackboard and the USB cable is already connected to the Pycom device
- Insert cables 
    - to Pycom device:
        - white: to P15 (3rd right)
        - red: to 3/3 (3rd left)
    - to Expansion board:
        - white: to 1i
        - red: to 1a
        - tilt switch (only in the expansion board): "golden" side HS: 1b, "silver" side RoH: 1h
    
- [x] ***Code used for Switch:***`from (TA) Erik B.` 
I created a file named "boot2.py" in VS Code 
```
from machine import Pin
import time

tilt = Pin('P15', mode=Pin.IN, pull=Pin.PULL_DOWN)
# Read value by running tilt()
while True:
    value = tilt()
    print(value)
    time.sleep_ms(300)
```
---


***Switch sensor***
![](https://i.imgur.com/Q678WtA.jpg)

![](https://i.imgur.com/18w1cvC.jpg)
![](https://i.imgur.com/kAqOuR3.jpg)
![](https://i.imgur.com/AYf34el.jpg)

***Switch in Pybytes***
![](https://i.imgur.com/FZ7u1N7.jpg)
![](https://i.imgur.com/LTyYoqD.jpg)
![](https://i.imgur.com/rvoOdIQ.jpg)


* I moved the Pycom device to get 1 and 0 values from Lopy.


***Issues that I needed help to solve in VS Code:***
* Once, it didn't run because the Pymakr Console was not open. (Picture of the Pymakr Console)
* I didn't know that I shouldn't select anything in the code, otherwise it wouldn't work.
* I didn't know that I must save the code right after writing it to can run.

Issues in connecting the temperature sensor to Pybytes after connecting  the Switch sensor, in order to transmit data from VS Code. 
I had to delete (with the help of `(TA) David M.` and also the ideas of `(TA) Erik Karlsson` the initial data and update the Pymark Plugin and create a new device in Pybytes. 

---


***Helium***

* In Helium, I connected myself to a red closer to my location.
[Searching for Helium coverage](https://explorer.helium.com/coverage#2.9/57.36/31.54)
![](https://i.imgur.com/JzEQMo7.jpg)

[Searching in the zone](https://explorer.helium.com/hotspots/1128QY4vbLKZBmvZ58EVQLapY6FV5FApSf7gZxxBNczbifLw5ziZ)
![](https://i.imgur.com/QJRHSHL.jpg)

![](https://i.imgur.com/WgHi1RT.jpg)

![](https://i.imgur.com/o8DLrTL.jpg)
![](https://i.imgur.com/sgqZviw.jpg)

***Connecting the antenna:***
![](https://i.imgur.com/g799TgL.jpg)

![](https://i.imgur.com/gnCsdBk.jpg)

![](https://i.imgur.com/QQsJZmo.jpg)

***Code used for Helium in VS Code:***`from (TA) Erik B.` 
- [x] [Code Helium Repository](https://github.com/AdrianaUl/Helium-code/edit/main/README.md/)
Specific important parts of code for the antena:
```
app_eui = ubinascii.unhexlify('6081F940969DC04C')
app_key = ubinascii.unhexlify('32AE69E229CD1BE25EF78CA017BCAC2B')

```
***Getting data in Helium:***
![](https://i.imgur.com/xV0LVvY.jpg)
![](https://i.imgur.com/DHIj8bR.jpg)
![](https://i.imgur.com/ADiw9rG.jpg)
![](https://i.imgur.com/Wu9DkDL.jpg)


### Finalizing the design and writing conclusion
- [x] I included pictures from some workshops, to make my tutorial more personal, and to show and remember how challenging this course was. I also want to manifest that it was very instructive, practical and funny. I was well surprised at how much help I received from the TAs, in a good environment. The hours of the workshops were passing very fast. My mind was totally absorbed by the activities and trying to get things done. 
- [x] I am grateful to all the TAs that helped me during the workshops.((TA) Erik Karlsson, (TA) Erik B., (TA) David M., (TA) Mohammad Qasem). 
- [x] I'm grateful to Fredrik for the way of teaching and organizing this course.

------------------

