You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Drew Bednar f8ef12064b removing ampy notes 2 years ago
CANBus new usb uart examples 2 years ago
basics removing ampy notes 2 years ago
bluetooth new usb uart examples 2 years ago
circuitpy More code 4 years ago
esp_wrover_kit_v4_1/sdcard adding an SDCard Example for the ESP-Wrover-kit 4 years ago
etc saving changes 2 years ago
interrupts Adding interrupt example 4 years ago
ir_encoder savin some code 3 years ago
kitchen_sink Here are some updates 4 years ago
light_sensor Here are some updates 4 years ago
motors some bluetooth and odrive updates 3 years ago
neo_pixel_DHT Adding DHT and OLED projects 4 years ago
ssd1306_oled Here are some updates 4 years ago
threading Adding interrupt example 4 years ago
tmp saving changes 2 years ago
uart new usb uart examples 2 years ago
webserver Adding interrupt example 4 years ago
.gitignore Here are some updates 4 years ago
README.md saving changes 2 years ago
requirements.in Added basics folder with instructions on how to use the micropython tool chains 5 years ago
requirements.txt Added basics folder with instructions on how to use the micropython tool chains 5 years ago

README.md

MicroPython ESP8266/ESP32

Installation

You will want to make sure you are installing the latest version of Micropython. Download the appropriate .bin for your chip and flash it to your board using the esptool. You will most likely need the UART driver for this operation. In my case my board uses the Silicon Labs CP210x driver.

Create a new virtualenv

Virtualenv's separate third party packages from your system Python installation. It is a good practice to install 3rd party packages into a separate virtualenv to avoid dependency conflicts.

python3 -m venv env
source env/bin/activate

Then pip install the requirements listed in the provided file.

pip install -r requirements.txt

Finding your board

I am using a Mac and after installing the CP210x driver and plugging in the board I have a new Silicon Labs device:

(env) drewbednar@MacBook-Pro micropython % ls -la /dev/*.SLAB*
crw-rw-rw-  1 root  wheel   18,   5 Feb  2 11:03 /dev/cu.SLAB_USBtoUART
crw-rw-rw-  1 root  wheel   18,   4 Feb  2 11:03 /dev/tty.SLAB_USBtoUART

The file type position lists this as a 'c' or character device. The cu.SLAB_USBtoUART and tty.SLAB_USBtoUART are the same device, but tty is supposed to be used for devices calling into Unix/Linux where cu is a "Call-Up" device meant for calling other devices (e.g. modems). Since we are calling from the Mac to the dev board we will be using the /dev/cu.SLAB_USBtoUART character file for connecting to the board.

Flashing your board

ESP32

esptool.py --chip esp32 -p /dev/cu.SLAB_USBtoUART erase_flash
esptool.py --chip esp32 --port /dev/cu.SLAB_USBtoUART --baud 115200 write_flash -z 0x1000 esp32spiram-idf3-20200902-v1.13.bin

ESP8266

esptool.py -p /dev/cu.SLAB_USBtoUART erase_flash

Then you will need to write the flash to your board. Be sure to connect with an appropriate baud rate. These boards can do 115200.

esptool.py --port /dev/cu.SLAB_USBtoUART --baud 115200 write_flash --flash_size=detect 0 esp8266-20170108-v1.8.7.bin

Connecting to your board

If you are using a mac just leverage the screen program:

screen /dev/cu.SLAB_USBtoUART 115200

This should connect you to the boards REPL

Connecting to the network

PLACEHOLDER

Code files

Micropython provides a "Virtual" filesystem for you code and collateral (config files etc.).

There are two files that you should take note of boot.py and main.py. The boot.py file will be executed immediately as the interpreter is brought online. It is here that we can place code to connect to a network for example. The main.py file should contain the entry point for your Micropython code. This will typically follow the same "Initialize" and enter "While Loop" pattern of code that you see if Arduinos

Extras

An excellent source for additional "Standard Library" like code can be found at Micropython-lib.

For shipping up code to you board I highly suggest using either the Pycharm Pluggin or the ampy modul e tool from adafruit.

ampy --help

ampy -p /dev/cu.SLAB_USBtoUART -b 115200 ls

See the basic directory within this project for more detailed usage of the ampy package.

MQTT on Hassio

Assuming you have Hassio installed (on a raspberry Pi3 for example). You will find the official MQTT broker documentation lacking in that small amount of detail that will get you up and running. This section is supposed to help take you that final mile.

The MQTT Broker

Let's start assuming you are going to use the downloadable MQTT broker from the add-on store. You will also want to have the configurator package installed too. Open up the configurator web-gui and find your /config/configuration.yaml file and addc the following entry at the bottom of the file:

#MQTT Setup
mqtt:
  broker: 0.0.0.0
  port: 1883

This will ensure that your broker properly configured. Now just make sure that you set the Start on boot to True in the addon details and restart your home-assistant.

An MQTT Sensor

Once again you may be a little confused by the official documentation for setting up an MQTT sensor. Assuming you are using the sample photoresitor light sensor that is included in this repo. Go back to your /config/configuration.yaml and this entry:

#MQTT Light Sensor
sensor office_light:
  - platform: mqtt
    name: 'Office Light'
    unit_of_measurement: 'No.'
    # Note your esp8266 will have a different MAC id. You can find the sensor's full topic path in the logs of the MQTT add-on
    state_topic: 'light/esp8266_aa00f800'
    # Our json is a simple single value extracted with this jinja2 template
    # More templating info can be found here https://www.home-assistant.io/docs/configuration/templating/#processing-incoming-data
    value_template: '{{value_json.payload}}'
    # Material design icons https://cdn.materialdesignicons.com/2.3.54/
    icon: mdi:lightbulb-on-outline

This should create an MQTT sensor that you will find on your Overview homepage after you restart the Hassio server.

Testing your new topic

Let's assume you haven't built the ESP8266 sensor. You can still test your service through the Hassio Developer tools at http://hassio:8123/dev-service. Select mqtt.publish and just craft a simple payload. Once you call the service you should see the result in the Sensor's component on your Overview

Appendix

Libs