Below is a quick reference for ESPbased boards. If it is your first time working with this board it may be useful to get an overview of the microcontroller:. It also includes a troubleshooting subsection.
Tab-completion is useful to find out what methods an object has. The machine module:. The esp module:. The esp32 module:. Note that the temperature sensor in the ESP32 will typically read higher than ambient due to the IC getting warm while it runs.
This effect can be minimised by reading the temperature sensor immediately after waking up from sleep. The network module:. Use the time module:. The ESP32 port has four hardware timers. Use the machine. Timer class with a timer ID from 0 to 3 inclusive :. Pin class:. Available Pins are from the following ranges inclusive :, Note that many end-user boards use their own adhoc pin numbering marked e.
D0, D1, …. For mapping between board logical pins and physical chip pins consult your board documentation.
Pins 6, 7, 8, 11, 16, and 17 are used for connecting the embedded flash, and are not recommended for other uses. The pull value of some pins can be set to Pin.
PWM can be enabled on all output-enabled pins.This tutorial will guide you through setting up MicroPython, getting a prompt, using WebREPL, connecting to the network and communicating with the Internet, using the hardware peripherals, and controlling some external components.
The first thing you need is a board with an ESP32 chip. Names of pins will be given in this tutorial using the chip names eg GPIO2 and it should be straightforward to find which pin this corresponds to on your particular board. If your board has a USB connector on it then most likely it is powered through this when connected to your PC. Otherwise you will need to power it directly.
Please refer to the documentation for your board for further details. The first thing you need to do is download the most recent MicroPython firmware.
You can download it from the MicroPython downloads page. From here, you have 3 main choices:. If you are just starting with MicroPython, the best bet is to go for the Stable firmware builds. If you are an advanced, experienced MicroPython ESP32 user who would like to follow development closely and help with testing new features, there are daily builds. There are two main steps to do this: first you need to put your device in bootloader mode, and second you need to copy across the firmware.
The exact procedure for these steps is highly dependent on the particular board and you will need to refer to its documentation for details. For best results it is recommended to first erase the entire flash of your device before putting on new MicroPython firmware. Currently we only support esptool. Versions starting with 1. An older version at least 1. You may need to reduce the baudrate if you get errors when flashing eg down to by adding --baud into the command.
For some boards with a particular FlashROM configuration you may need to change the flash mode eg by adding -fm dio into the command. The baudrate is From here you can now follow the ESP tutorial, because these two Espressif chips are very similar when it comes to using MicroPython on them. If you experience problems during flashing or with running firmware immediately after it, here are troubleshooting recommendations:.
Be aware of and try to exclude hardware problems. The most reliable and convenient power source is a USB port. The flashing instructions above use flashing speed of baud, which is good compromise between speed and stability.
Try a more common baud rate instead in such cases.MicroPython Introduction. Thonny IDE Install. Flash Firmware esptool. MicroPython Programming. MicroPython Inputs Outputs. MicroPython Analog Inputs. MicroPython Interrupts. ESP32 Deep Sleep. ESP Deep Sleep. MicroPython Output Web Server. MicroPython Relay Web Server. MicroPython Relay Module.
MicroPython PIR. MicroPython BME MicroPython DS18B Weather Station Datalogger. MicroPython Access Point. MicroPython WiFiManager. Flash MicroPython Firmware. Learn MicroPython. MicroPython, a re-implementation of Python 3 programming language targeted for microcontrollers. It makes it easy and simple to program digital electronics.
Each tutorial includes circuit schematics, source code, images and videos. Share on facebook Facebook. Share on twitter Twitter. Share on linkedin LinkedIn.
This is one of the easiest ways to program your ESP boards! About Random Nerd Tutorials. Random Nerd Tutorials is an online resource with electronics projects, tutorials and reviews. Creating and posting new projects takes a lot of time.
At this moment, Random Nerd Tutorials has approximately free blog posts with complete tutorials using open source hardware and software that anyone can read, remix and apply to their own projects.This module provides an interface to a Bluetooth controller on a board.
A device may operate in multiple roles concurrently. This API is intended to match the low-level Bluetooth protocol and provide building-blocks for higher-level abstractions such as specific device types. This module is still under development and its classes, functions, methods and constants are subject to change. Get or set configuration values of the BLE interface. To get a value the parameter name should be quoted as a string, and just one parameter is queried at a time.
To set values use the keyword syntax, and one ore more parameter can be set at a time. Values can be:. This can be set at any time and changed multiple times. This buffer is global to the entire BLE driver and so handles incoming data for all events, including all characteristics. Increasing this allows better handling of bursty incoming data for example scan results and the ability to receive larger characteristic values. Registers a callback for events from the BLE stack.
The handler takes two arguments, event which will be one of the codes below and data which is an event-specific tuple of values.
Firmware for Generic ESP32 module
If your program needs to save one of these values to access after the IRQ handler has returned e. UUIDlike this:. And to print data from within the IRQ handler, print bytes addr will be needed. In order to save space in the firmware, these constants are not included on the ubluetooth module. Add the ones that you need from the list above to your program. Starts advertising at the specified interval in micro seconds.
This interval will be rounded down to the nearest us. To clear the advertising payload pass an empty bytesi. The default interval and window are 1. Disconnect the specified connection handle. This can either be a central that has connected to this device if acting as a peripheral or a peripheral that was previously connected to by this device if acting as a central.
A GATT server has a set of registered services. Each service may contain characteristics, which each have a value. Characteristics can also contain descriptors, which themselves have values. They can also be read from or written to by a remote client device. A device in either central or peripheral roles may function as a GATT server, however in most cases it will be more common for a peripheral device to act as the server.
Characteristics and descriptors have a default maximum size of 20 bytes. Anything written to them by a client will be truncated to this length.You also need an IDE to write and upload the code to your board. The BME sensor module reads barometric pressure, temperature and humidity.MicroPython #1 - Lets Get Started
Because pressure changes with altitude, you can also estimate altitude. This sensor communicates using I2C communication protocol, so the wiring is very simple. You can use the preceding links or go directly to MakerAdvisor. View raw code. Copy the BME library code into that file. The BME library code can be found here. After copying the code, save the file by pressing the Save button 2. Copy the library code to a new file.
The library was uploaded to your board. To make sure that it was uploaded successfully, in the Shell you can type:. It should return the files currently saved on your board. One of them should be the BME After uploading the library to your board, you can use the library functionalities in your code by importing the library.
It simply prints the temperature, humidity and pressure into the shell every 5 seconds. Set the I2C pins. Reading temperature, humidity and pressure is as simple as using the temperaturehumidity and pressure methods on the bme object. After uploading the code to your board, press the RST button to run the code. New BME sensor readings should be displayed every 5 seconds. Note: It is a good practice to include the boot. However, if you prefer, you can include all the code in the main.
This file imports the necessary libraries, defines the I2C pins to connect to the sensor and connects to your network.Below is a quick reference for ESPbased boards. If it is your first time working with this board it may be useful to get an overview of the microcontroller:.
It also includes a troubleshooting subsection. Tab-completion is useful to find out what methods an object has. The machine module:. The esp module:. The esp32 module:. Note that the temperature sensor in the ESP32 will typically read higher than ambient due to the IC getting warm while it runs. This effect can be minimised by reading the temperature sensor immediately after waking up from sleep.
The network module:. Use the time module:. Virtual RTOS-based timers are supported. Use the machine. Timer class with timer ID of Pin class:. Available Pins are from the following ranges inclusive :, Note that many end-user boards use their own adhoc pin numbering marked e. D0, D1, For mapping between board logical pins and physical chip pins consult your board documentation. PWM can be enabled on all output-enabled pins. The base frequency can range from 1Hz to 40MHz but there is a tradeoff; as the base frequency increases the duty resolution decreases.
See LED Control for more details. Note that, when using the default configuration, input voltages on the ADC pin must be between 0. Attenuation must be applied in order to increase this usable voltage range.MicroPython runs on a variety of systems and hardware platforms.
Here you can read the general documentation which applies to all systems, as well as specific information about the various platforms - also known as ports - that MicroPython runs on. Library Reference MicroPython libraries and modules. Language Reference information about MicroPython specific language features.
License MicroPython license information.
Quick reference for the pyboard pinout for the pyboard, snippets of useful code, and a tutorial. Module index quick access to all modules. Full index all functions, classes, constants. Glossary MicroPython terms explained.
Table of contents a list of all sections and subsections. MicroPython homepage the official MicroPython site. MicroPython forum community discussion for all things related to MicroPython. MicroPython 1. MicroPython documentation Welcome! This is the documentation for MicroPython v1. Versions and Downloads latest Versions v1. Module index quick access to all modules Full index all functions, classes, constants.
Glossary MicroPython terms explained Table of contents a list of all sections and subsections.