Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[MKC-1061]MicroPython 101 revision #1203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
jacobhylen merged 7 commits into main from jacobhylen/number-micropython101chapters
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
featured: micropython-101
title: 'Introduction to Arduino'
title: '1. Introduction to Arduino'
description: 'Learn about the Arduino platform'
author: 'Karl Söderby'
hero_image: "./hero-banner.png"
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ author: 'Karl Söderby'
hero_image: "./hero-banner.png"
micropython_type: "101"
featured: micropython-101
title: 'Introduction to MicroPython'
title: '2. Introduction to MicroPython'
description: 'Learn about the Arduino platform'
---

Expand Down Expand Up @@ -146,39 +146,67 @@ For example, to use a module for a specific sensor, we need to install it **exte

### Install External Modules

To install an external module, we are going to use something called `mip`. With `mip`, we can install a module on the board directly, by connecting to Wi-Fi and downloading the module directly to the board. So how do we do this?
To install an external module, we are going to use a package manager called `mip`. With `mip`, we can install a module on the board by connecting to Wi-Fi® and downloading the module directly to the board. Installing external modules is done in two steps:

Below is a script that first connects to Wi-Fi®, and then downloads a specific module. In this case, we will provide a URL to a file stored on GitHub (the raw file). In this case, we will install the `lis3dh` module, which will be used later on in this course.
1. Establish a Wi-Fi connection.

Please note that you need to add your own Wi-Fi® network and password in the `WIFI_NETWORK` and `WIFI_PASSWORD` fields.
2. Download the module from a specific URL using `mip`.

To connect to your local Wi-Fi you can upload the following script to `boot.py` file. We choose `boot.py` because we want to make sure our board connects to the internet as soon as it boots up.

**Connect to Wi-Fi**

![Wi-Fi script inside boot.py](./assets/boot.png)

***Please note that you need to add your own Wi-Fi network and password in the `WIFI_NETWORK` and `WIFI_PASSWORD` fields.***

```python
"""
This script first connects to Wi-Fi,
then installs the module specified
in the URL variable.
This script connects to Wi-Fi
"""

import network
import mip

WIFI_NETWORK='YOUR_NETWORK_NAME'
WIFI_PASSWORD='YOUR_NETWORK_PASSWORD'

# add the URL of the module you want to install
URL = "https://raw.githubusercontent.com/tinypico/tinypico-micropython/master/lis3dh%20library/lis3dh.py"

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_NETWORK, WIFI_PASSWORD)

print()
print("Connected to ",WIFI_NETWORK)
```
Press run and you should see `Connected to <your Wi-Fi>` being printed inside the REPL.

![Successful connection](./assets/wifiConnected.png)

**Install external modules**

Next, you need to run a script that installs the external module from a specific URL. Upload the following script to `main.py`.

mip.install(URL)
![Module installation script inside main.py](./assets/main.png)

```python
'''
This script installs external modules using mip
'''

import mip
mip.install("https://raw.githubusercontent.com/tinypico/tinypico-micropython/master/lis3dh%20library/lis3dh.py")
```

Once you run the script successfully, you will have installed the module on your board.
Press run and you should see the following inside the REPL:

![Successful download](./assets/download.png)

In this case, we will provide a URL to a file stored on GitHub (the raw file). The script installs the `lis3dh` module, which will be used later on in this course.

You can verify that the module was installed correctly by pressing `Files` and checking inside the `lib` folder. You should see a file called `lis3dh.py` inside.

![Installed module](./assets/libFolderIn.png)

When asked later in the course to install external modules simply paste the provided script into `main.py` and press run.

### Removing Modules

Expand Down Expand Up @@ -215,9 +243,9 @@ OSError: -202

Some things to check are:
- Did you enter your network credentials properly?
- Did you already connect to Wi-Fi®?
- Did you already connect to Wi-Fi?

If the error persist, you can try to "soft-reset" the board, by clicking the **"Reset"** button, and run the script again.
If the error persists, you can try to "soft-reset" the board, by clicking the **"Reset"** button, and run the script again.

![](assets/reset.png)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]
View file Open in desktop
Binary file not shown.
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ author: 'Jacob Hylen'
hero_image: "./hero-banner.png"
micropython_type: "101"
featured: micropython-101
title: 'MicroPython Installation Guide'
title: '3. MicroPython Installation Guide'
description: 'Learn how to install a code editor needed to program your board with MicroPython.'
---

Expand Down Expand Up @@ -33,15 +33,7 @@ First, [download the app here](https://labs.arduino.cc/en/labs/micropython). It

If you're on macOS, move the application to your **Applications** folder.

**2. Put the Board in Bootloader Mode**

Before we can install MicroPython, we need to place our board in a "bootloader" mode as we call it. This will make it possible to send a new firmware to it.

Connect your board to your computer, and connect B1 to GND with a jumper wire, tweezers, or something else metallic you have handy. Once you see a green light on the board, press the reset button on the board. If you remove the connection between B1 and GND, you should see a dim purple light if this step was successful. If not, then try again.

![Bootloader Mode](./assets/bootloader.png)

**3. Download the Firmware Installer**
**2. Download the Firmware Installer**

The **Firmware Installer** program will help install MicroPython on your board.

Expand All @@ -51,21 +43,21 @@ First [download the app here](), and extract the files to a folder on your compu

If you're on macOS, move the application to your **Applications** folder.

**4. Flash Firmware**
**3. Flash Firmware**

Now open the Firmware Installer tool, select the Arduino Nano ESP32, and press **"Install MicroPython"**. Wait for the installer to do its magic and after some seconds, we are ready to go!

![Installer with Board Selected](./assets/installer.png)

If the installer doesn't find the MicroPython firmware automatically, you can download it manually from [here](./assets/nanoesp32_micropython.bin)

**5. Connect your Code Editor and Board**
**4. Connect your Code Editor and Board**

In the Arduino Lab for MicroPython app, press **connect** in the top left corner and choose the serial port that comes up. This is your Nano ESP32.

![Connect to your Board](./assets/connect.png)

**6. Verify**
**5. Verify**

Now, to verify things are working as they should, copy the script script below into your `main.py` file, and run it by clicking the **"Run"** button.

Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
author: 'Karl Söderby'
hero_image: "./hero-banner.png"
featured: micropython-101
title: 'Python Crash Course'
title: '4. Python Crash Course'
description: 'Learn some Python fundamentals that will help you create MicroPython scripts.'
---

Expand Down
8 changes: 7 additions & 1 deletion content/micropython-course/course/04.digital/03.digital.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ author: 'Karl Söderby'
hero_image: "./hero-banner.png"
micropython_type: "101"
featured: micropython-101
title: 'Digital I/O'
title: '5. Digital I/O'
description: 'Learn how to read & write digital signals.'
---

Expand Down Expand Up @@ -32,6 +32,12 @@ In this exercise, we will read a button, which we will need to connect to our Na

![Button Circuit.](assets/circuitButton.png)

When placing the Nano ESP32 onto the Nano Screw Terminal Adapter, pay attention to the drawing on the adapter, and line up your board with it, so that the boards USB-C® port lines up with the drawing.

Screw terminals are a great way of connecting components quickly and sturdily. Grab yourself a screwdriver of an appropriate size, then feed the wire that you want to connect to a pin through the hole on the side of the adapters screw terminal, and screw down the corresponding screw to tighten its grip on the wire.

Once the cable is stuck in there, you've made a solid connection!

Open the code editor, and copy paste the following script to the `main.py` file, then click on the **"Run"** button to run it.

```python
Expand Down
2 changes: 1 addition & 1 deletion content/micropython-course/course/05.analog/04.analog.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ author: 'Karl Söderby'
hero_image: "./hero-banner.png"
micropython_type: "101"
featured: micropython-101
title: 'Analog I/O & PWM Signals'
title: '6. Analog I/O & PWM Signals'
description: 'Learn how to read analog signals and how to generate PWM signals.'
---

Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ author: 'Karl Söderby'
hero_image: "./hero-banner.png"
micropython_type: "101"
featured: micropython-101
title: 'Serial Protocols'
title: '7. Serial Protocols'
description: 'Learn how to use the I2C, SPI and UART serial protocols.'
---

Expand Down
Binary file modified content/micropython-course/course/06.serial/assets/spi.png
View file Open in desktop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is certainly challenging to be pedagogical and accurate at the same time. Thanks for improving the SPI diagram.
I would have loved to see this when I was learning about SPI myself 😍

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ author: 'Karl Söderby'
hero_image: "./hero-banner.png"
micropython_type: "101"
featured: micropython-101
title: 'Internet of Things with MicroPython'
title: '8. Internet of Things with MicroPython'
description: 'Learn how to connect to Wi-Fi® networks, how to make a HTTP request to a REST API.'
---

Expand Down
5 changes: 4 additions & 1 deletion content/micropython-course/course/08.examples/examples.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ author: 'Hannes Siebeneicher'
hero_image: "./hero-banner.png"
micropython_type: "101"
featured: micropython-101
title: 'Component Examples'
title: '9. Component Examples'
description: 'Ready to use code & circuit examples for popular components such as Neopixel, DHT11 & Servo motor.'
---

Expand Down Expand Up @@ -287,6 +287,7 @@ This example demonstrates how to use an [OLED](https://store.arduino.cc/products
This module is not part of the MicroPython installation, and needs to be installed via the following command:

```python
import mip
mip.install("https://raw.githubusercontent.com/micropython/micropython-lib/master/micropython/drivers/display/ssd1306/ssd1306.py")
```

Expand Down Expand Up @@ -386,6 +387,7 @@ This example shows how to use a [Grove Accelerometer](https://store.arduino.cc/p
This module is not part of the MicroPython installation, and needs to be installed via the following command:

```python
import mip
mip.install("https://raw.githubusercontent.com/tinypico/tinypico-micropython/master/lis3dh%20library/lis3dh.py")
```

Expand Down Expand Up @@ -502,6 +504,7 @@ This example shows how to use a [Grove 4-digit display](https://store.arduino.cc
This module is not part of the MicroPython installation, and needs to be installed via the following command:

```python
import mip
mip.install("https://raw.githubusercontent.com/mcauser/micropython-tm1637/master/tm1637.py")
```

Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ featured: micropython-101-projects
title: 'Alarm Clock'
description: 'Build your own alarm clock using a 4-digit-display and a buzzer to get you out of bed.'
---

***Please complete the basic installation-chapters before starting a project.***

This project will use the `ntptime` module to keep track of the time and display it on a 4-digit-display. An alarm can then be set in the code, which will turn on the buzzer at a specified time. To keep track of time accurately the board will also connect to a Wi-Fi® network.

Expand All @@ -29,6 +29,14 @@ Assemble the components according to the circuit diagram below:

Read the comments in the code and change the variables as necessary then upload it to your board.

In order to use the 4-digit-display you will need to install the following module:

```python
mip.install("https://raw.githubusercontent.com/mcauser/micropython-tm1637/master/tm1637.py")
```

***If you are unsure how to install external modules you can read up on it [here](https://docs.arduino.cc/micropython-course/course/introduction-python#external-modules)***

```python
from machine import Pin, PWM, RTC
import time
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ featured: micropython-101-projects
title: 'Scene Changer'
description: 'Learn how to change the scene on an OLED screen with the press of a button'
---
***Please complete the basic installation-chapters before starting a project.***

This project will show you how to interact with a screen using a button. The script will follow a sequence when the button is pressed and change what is displayed. It will call different functions depending on the current function that is displayed.

Expand All @@ -28,6 +29,14 @@ Assemble the components according to the circuit diagram below:

Read the comments in the code and change the variables as necessary then upload it to your board.

In order to use the OLED screen you will need to install the following module:

```python
mip.install("https://raw.githubusercontent.com/micropython/micropython-lib/master/micropython/drivers/display/ssd1306/ssd1306.py")
```

***If you are unsure how to install external modules you can read up on it [here](https://docs.arduino.cc/micropython-course/course/introduction-python#external-modules)***

```python
from machine import SoftI2C, Pin
from Button import Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ featured: micropython-101-projects
title: 'Temperature Display'
description: 'Use a temperature sensor together with a NeoPixel stick, giving you visual feedback on the current temperature.'
---
***Please complete the basic installation-chapters before starting a project.***

This project will take the temperature reading from a DHT11 sensor and change the color of the LEDs on the NeoPixel accordingly.

Expand Down

AltStyle によって変換されたページ (->オリジナル) /