Configure ESP 32 - SnackChain/SnackPi GitHub Wiki

Install micropython in ESP-32

Download form here latest stable version and follow their instructions

You should modify the port /dev/ttyUSB0 to yours.

How to see the ESP-32 port?

If you have Arduino installed you can see your serial ports at Tools > Port

If you don't have Arduino, download it, you will need it in next steps:

Communicate with the ESP-32

There are different ways to communicate with the ESP-32 one of them is ampy, you can install it with pip

pip install adafruit-ampy

Note: if you don't have a python environment, you could install it with sudo pip3 install adafruit-ampy or sudo pip install adafruit-ampy but we strongly recommend to have a a python environment, you can see how to setup one here

Once ampy is installed, you could try your connection by writing this in your terminal:

ampy -p /dev/tty.usbserial-0001 -d 1 ls

If you have problems, you could try increasing delay time -d 1 to 2 seconds -d 2

Note: in order to don't have to write port and delay every time, you could save those parameters as environmental variables. You can do that in MacOS by tapping this in the terminal

export AMPY_PORT=/dev/tty.usbserial-0001

export AMPY_DELAY=1

Don't forget to change the port to your port

You can see all the ampy options with

ampy --help

Required libraries

We need some libraries to make it work, these is how we can install them:

  1. Open Arduino and select the ESP-32 serial port.
  2. Open the serial monitor (magnifying glass in top-right corner) and select Carriage return and 115200 baud
  3. Copy-paste the next lines by one by one in the text field and press return after each line.

import network

sta_if = network.WLAN(network.STA_IF)

sta_if.active(True)

sta_if.connect('**write here the name of your wifi network**', '**write here the password of your wifi network**')

import upip

upip.install('micropython-schedule')

upip.install('micropython-functools')

upip.install('urequests')

  1. Close the serial monitor, return to terminal and write

ampy rm lb/time.py

Upload files

Clone SnackPi in your computer (or just download it) and write the next lines one by one in the terminal

ampy put <replace with the path to SnackPi project>/project/constants.py

ampy put <replace with the path to SnackPi project>/project/handler

ampy put <replace with the path to SnackPi project>/project/main.py

ampy put <replace with the path to SnackPi project>/project/manager

ampy put <replace with the path to SnackPi project>/project/model

ampy put <replace with the path to SnackPi project>/project/provider

See it working

To see the logs while the ESP-32 is working, just open again the Arduino serial moinitor.

Note: every time you close and open the Arduino serial monitor will run main.py file