1. Access the Serial REPL (more info below) and then reset the device. Device must be plugged into your computer!
screen /dev/cu.SLAB_USBtoUART 115200. To get back to Terminal, close the window and open Terminal again. You cannot use the exit() command as before since this is the MicroPython interpreter running on the board, not the Python interpreter running within Terminal itself.>>>, you're in a Python interpreter.2. "ampy" is a command line tool (much like pip) useful for accessing and manipulating the files on your HUZZAH. The storage on your device is organized with the same folder/directory structure as most computers, however it must be interacted with differently. ampy stands for Adafruit MicroPython tool.
pip install adafruit-ampysudo pip, pip2, or pip3 for this to wortk.ampy --help in Terminal or Command Prompt. A list of commands will show up.ampy --port (port) (command) (input) (occasional secondary input).ampy --port (port) (command) --help.cd (folder name)\(second folder name)\(etc). You can also return to the root folder (usually the C: drive) by running the command cd\.cd (folder name)/(second folder name)/(etc). You can also return to the root folder by running the command cd.3. Check for and perform any ampy updates by running the command pip install adafruit-ampy --upgrade.
4. Using Anaconda, open Spyder and create a script with the following code.
import networkimport ubinasciimac = ubinascii.hexlify(network.WLAN().config('mac'),':').decode()print(mac)5. Then, save it to a Python file on your computer titled "getMAC.py".
6. Use ampy to copy "getMAC.py" to your device under the name "main.py":
cd command as described in the "Using ampy" section above.ampy --port (port) put getMAC.py main.pyampy --port (port) put --help. 7. Open the Serial REPL and then reset your device (the HUZZAH has a RST button near the MicroUSB port). The MAC address should be displayed. Notice it is displayed above the >>> Python prompt because the code is performed automatically on startup before initializing the REPL.
8. Get permission to access Tufts_Wireless from your device by filing the MAC address with Tufts Network Registration (link).
9. Save the following code to a Python file on your computer and then copy it (using ampy) to your device under the name "boot.py". When doing so, make sure to use ampy --port (port) put boot.py.
# This file is executed on every boot (including wake-boot from deepsleep)#import esp#esp.osdebug(None)import gc#import webrepl#webrepl.start()gc.collect()import espesp.osdebug(None)def connect(): import network import time ssid = 'Tufts_Wireless' # insert your WiFi ssid here password = '' # insert your WiFi pass here # Create Station interface sta_if = network.WLAN(network.STA_IF) if not sta_if.isconnected(): print('Connecting to',ssid,'...') # Enable the interface sta_if.active(True) # Connect sta_if.connect(ssid, password) # Wait till connection is established while not sta_if.isconnected(): time.sleep_ms(300) print('Your device is now connected.') else: print('Already Connected.') print('Network Settings:', sta_if.ifconfig())connect()ampy -p (port) ls and then ampy -p (port) get boot.py. These commands will list the files on your device and then show the contents of the boot.py file, respectively.10. We can now make changes to the main.py file to do whatever we want with MicroPython.
import filenameAlternatively, you can use ampy to run files by using the command ampy -p (port) run (file on computer to be run on board). In general, MicroPython will wait to show outputs until the file has finished running, so if you have loops or need outputs shown immediately, use the "ampy run" command with the modifier --no_output or simply -n. More information on this is available in the command's individual help menu.
Advance to the next tutorial to learn how to connect with Thingworx using MicroPython!