diff --git a/README.md b/README.md index 1a61852..1a244cd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # MicroPython ESP8266/ESP32 ## Installation + You will want to make sure you are installing the latest version of [Micropython](hhttps://micropython.org/). Download the appropriate [.bin for your chip](https://micropython.org/download) and flash it to your board using the [esptool](https://github.com/espressif/esptool). You will most likely need the UART driver for this operation. In my case my board uses the [Silicon Labs CP210x driver](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers). ### Create a new virtualenv @@ -11,7 +12,9 @@ Virtualenv's separate third party packages from your system Python installation. python3 -m venv env source env/bin/activate ``` + Then pip install the requirements listed in the provided file. + ``` pip install -r requirements.txt ``` @@ -25,12 +28,14 @@ I am using a Mac and after installing the CP210x driver and plugging in the boar 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 +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 ``` @@ -42,6 +47,7 @@ esptool.py --chip esp32 --port /dev/cu.SLAB_USBtoUART --baud 115200 write_flash ``` ESP8266 + ``` esptool.py -p /dev/cu.SLAB_USBtoUART erase_flash ``` @@ -71,7 +77,7 @@ 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 @@ -79,7 +85,7 @@ There are two files that you should take note of `boot.py` and `main.py`. The `b An excellent source for additional "Standard Library" like code can be found at [Micropython-lib](https://github.com/micropython/micropython-lib). For shipping up code to you board I highly suggest using either the [Pycharm Pluggin](https://blog.jetbrains.com/pycharm/2018/01/micropython-plugin-for-pycharm/) or the [ampy](https://github.com/adafruit/ampy) modul -e tool from adafruit. +e tool from adafruit. ``` ampy --help @@ -87,7 +93,7 @@ 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. +See the basic directory within this project for more detailed usage of the ampy package. ## MQTT on Hassio @@ -100,8 +106,8 @@ Let's start assuming you are going to use the downloadable [MQTT broker](https:/ ```yaml #MQTT Setup mqtt: - broker: 0.0.0.0 - port: 1883 + 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. @@ -114,13 +120,13 @@ Once again you may be a little confused by the official documentation for settin #MQTT Light Sensor sensor office_light: - platform: mqtt - name: "Office Light" - unit_of_measurement: "No." + 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" + 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}}" + value_template: '{{value_json.payload}}' # Material design icons https://cdn.materialdesignicons.com/2.3.54/ icon: mdi:lightbulb-on-outline ``` @@ -141,4 +147,8 @@ Let's assume you haven't built the ESP8266 sensor. You can still test your servi - https://learn.adafruit.com/micropython-for-samd21 - https://learn.adafruit.com/micropython-hardware-i2c-devices - https://learn.adafruit.com/micropython-hardware-spi-devices -- https://learn.adafruit.com/building-and-running-micropython-on-the-esp8266/overview \ No newline at end of file +- https://learn.adafruit.com/building-and-running-micropython-on-the-esp8266/overview + +### Libs + +- https://github.com/jczic/MicroWebSrv diff --git a/etc/profile b/etc/profile new file mode 100644 index 0000000..9ab4cbb --- /dev/null +++ b/etc/profile @@ -0,0 +1,56 @@ +export AMPY_PORT=/dev/cu.SLAB_USBtoUART +export BAUD_RATE=115200 + +ARG=$1 + +if [ "$ARG" = '--kit' ] || [ "$ARG" = '-k' ]; then + echo "Using ESP-WOVER-kit_v4.1" +# export AMPY_PORT=/dev/cu.usbserial-143101 + export AMPY_PORT=/dev/cu.usbserial-14401 +fi + +function _set_kit_usbserial (){ + +} + + +function repl_connect (){ + echo "Connecting to $AMPY_PORT" + echo "Use Ctrl+a then k to kill the session" + sleep 2; + screen $AMPY_PORT $BAUD_RATE +} + +function upy (){ + _command=${1} + shift +# echo "command $_command params $@" + ampy -p $AMPY_PORT -b $BAUD_RATE ${_command} $@ +} + +# m0 maps to conng +alias mp="mpremote m0" + +function esp32-docs () { + echo "\nDocs: https://docs.micropython.org/en/latest/esp32/quickref.html\n" + open 'https://docs.micropython.org/en/latest/esp32/quickref.html' +} + +function upy-git () { + + echo '\n Upy Git: https://github.com/micropython/micropython\n' + open 'https://github.com/micropython/micropython' +} + +# Cool things you can do with mpremote +function mpremote_usage () { + echo "\n#### USAGE ####\n" + echo "\nDocs: https://docs.micropython.org/en/latest/reference/mpremote.html\n" + echo 'Ideas:' + echo "- The config file for mprempte is in ~/.config/mpremote/config.py" + echo '- You can user `mp mount . exec "import foo"` to mount a foo module from curdir and programmatically execute it.' + echo '- Rapidly iterate compiling C into .mpy files then mounting that file on your board! See: https://www.youtube.com/watch?v=EVJA01W9ArI' + echo "\n#### USAGE END ####\n" +} + + diff --git a/scripts/profile b/scripts/profile deleted file mode 100644 index cde2745..0000000 --- a/scripts/profile +++ /dev/null @@ -1,29 +0,0 @@ -export AMPY_PORT=/dev/cu.SLAB_USBtoUART -export BAUD_RATE=115200 - -ARG=$1 - -if [ "$ARG" = '--kit' ] || [ "$ARG" = '-k' ]; then - echo "Using ESP-WOVER-kit_v4.1" -# export AMPY_PORT=/dev/cu.usbserial-143101 - export AMPY_PORT=/dev/cu.usbserial-14401 -fi - -function _set_kit_usbserial (){ - -} - - -function repl_connect (){ - echo "Connecting to $AMPY_PORT" - echo "Use Ctrl+a then k to kill the session" - sleep 2; - screen $AMPY_PORT $BAUD_RATE -} - -function upy (){ - _command=${1} - shift -# echo "command $_command params $@" - ampy -p $AMPY_PORT -b $BAUD_RATE ${_command} $@ -} \ No newline at end of file diff --git a/tmp/test.json b/tmp/test.json new file mode 100644 index 0000000..1567cf9 --- /dev/null +++ b/tmp/test.json @@ -0,0 +1,4 @@ +{ + "neo_pin": 48, + "neo_number": 1 +} \ No newline at end of file