7 Feb 2020

How to set Python3 as a default python version on macOS?

Look where Python is installed.
ls -l /usr/local/bin/python*

Change the default python symlink to the version you want to use from above.
Note that, we only need to choose the one that ends with python3.*. Please avoid using the ones' that end with config or python3.*m or python3.*m-config.

ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python

Close the current terminal session or keep it that way and instead open a new terminal window.

Run this:
python --version

MicroPython on the ESP8266 (macOS) Part 2


Rshell (Alternative to Ampy)

----------------------------------

Remote MicroPython shell. This is a simple shell which runs on the host and uses MicroPython's raw-REPL to send python snippets to the pyboard in order to get filesystem information, and to copy files to and from MicroPython's filesystem.

Install
sudo pip3 install rshell

Enter:
rshell

Term output:
Welcome to rshell. Use Control-D (or the exit command) to exit rshell.
No MicroPython boards connected - use the connect command to add one

connect serial /dev/tty.wchusbserial1420 115200
(connect serial [port] [baud])

Term output:
Connecting to /dev/tty.wchusbserial1420 (buffer-size 512)...
Trying to connect to REPL connected

etc...

Use Rshell:

----------------------------------

List files on the board
ls /pyboard/

Entering REPL
repl (Use Control-X to exit.)

Get help 
help()

https://github.com/dhylands/rshell
https://github.com/wendlers/mpfshell

Upload *.py files

----------------------------------

Copy a file from local directory to esp8266 board
cp main.py /pyboard/

Copy a file from the board to desktop
cp /pyboard/main.py desktop

Run in the REPL
import main

Reset

----------------------------------

There are soft resets and hard resets. A soft reset simply clears the state of the MicroPython virtual machine but leaves hardware peripherals unaffected. To do a soft reset, simply press Ctrl + D on the REPL, or within a script do:

import sys 
sys.exit()

A hard reset is the same as performing a power cycle to the board. In order to hard reset the WiPy, press the switch on the board or:

import machine 
machine.reset()

4 Feb 2020

Getting started with MicroPython on the ESP8266 (macOS) Part 1

Micropython-logo

Esptool Installation

----------------------------------

Install Pip (or use easy_install). Pip is a packet manager for Python.
sudo pip install --upgrade pip
sudo pip install esptool (pip uninstall esptool) 

Alternatively, we can use easy_install. This is a python module bundled with setuptools that lets us automatically download, build, install, and manage Python packages.

sudo easy_install pip
sudo easy_install esptool

Add path (if necessary)
sudo nano /etc/paths

Path to script /usr/local/bin/esptool.py or check via uninstalling command. If you run pip show -f esptool then it should list all of the files installed by the esptool package.

Esptool Commands:
esptool.py -h to see a summary of all available commands and command-line options.
esptool.py version


MicroPython Firmware Installation

----------------------------------

--> Erase flash ESP8266
esptool.py --port /dev/tty.wchusbserial1420 erase_flash

--> Burn MicroPython on chip
1. Navigate to the folder with firmware
2. Run:
esptool.py --port /dev/tty.wchusbserial1420 --baud 460800 write_flash --flash_size=detect 0 esp8266-20191220-v1.12.bin

Term output:
esptool.py v2.8
Serial port /dev/tty.wchusbserial1420
Connecting........_
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz


and etc...
more details

--> Test Connection
Connect the ESP82266 board into usb port and find connected devices
ls /dev/tty.*
ls /dev/cu.*

Term output:
/dev/tty.wchusbserial1420

Access to the REPL (read-eval-print loop) which is always available on the UART0 serial peripheral, which is connected to the pins GPIO1 for TX and GPIO3 for RX.

screen /dev/cu.wchusbserial1420 115200

>>> print("Hi")
Hi
(it is already running on the ESP8266 board)

To exit from 'screen' type 'Ctl-a, k'; and then answer 'y' to exit

Example:
>>> import machine 
>>> pin = machine.Pin(2, machine.Pin.OUT)
>>> pin.on() 
>>> pin.off()


Uploading *.py files into the ES8266 board

----------------------------------

To upload files, we can use WebREPL or ampy tools. To use WebREPL connect your computer to the ESP8266’s access point (MicroPython-xxxxxx) and open client https://micropython.org/webrepl/.

more details

Enable WebREPL
>>> import webrepl_setup

Ampy is made to talk to a CircuitPython MicroPython board over its serial connection. You will need your board connected and any drivers to access it serial port installed.

more details

Install Ampy
sudo pip3 install ampy or
sudo pip install adafruit-ampy or 
pip3 install --upgrade git+https://github.com/adafruit/ampy

or install from sources (Update python version to Python 3.x)


git clone https://github.com/adafruit/ampy.git
sudo python3 setup.py install


--> Upload
ampy --port /dev/tty.wchusbserial1420 --baud 115200 put main.py

For convenience, you can set an AMPY_PORT environment variable which will be used if the port parameter is not specified. For example export on Linux or OSX:

export AMPY_PORT=/dev/tty.wchusbserial1420
ampy ls


and now just it

ampy put main.py 

--> Show files (ESP266 flash)
ampy --port /dev/tty.wchusbserial1420 --baud 115200 ls

Ampy Commands

----------------------------------

get retrieve a file from the board.
ls list contents of a directory on the board. 
put put a file on the board. 
rm remove a file from the board. 
run run a script and print its output.

ampy --port /serial/port ls
ampy --port /serial/port put test.py /foo/bar.py
ampy --port /serial/port get boot.py
ampy --port /serial/port mkdir foo
ampy --port /serial/port rm test.py
ampy --port /serial/port rm /foo/bar

---------------

git clone https://github.com/pyserial/pyserial
sudo python setup.py install

UART Terminal on macOS

Find connected devices
ls /dev/tty.*
ls /dev/cu.*

or ls /dev/ to show all drivers

Open screen
screen /dev/cu.wchusbserial1420 9600

To exit from 'screen' type 'Ctl-a, k'; and then answer 'y' to exit.

How to flash Robotdyn ESP8266-PRO board

Connections (Robotdyn ESP8266-PRO):

EN --- <10k> --- 3.3V
GPIO2 --- <10k> --- 3.3V (use optional)
GPIO0 --- <10k> --- 3.3V --- Flash Button --- GND
GPIO15 --- <10k> --- GND

for other boards add
RST --- <10k> --- 3.3V --- Reset Button --- GND

How to flash Robotdyn ESP8266-PRO board

1 Feb 2020

Terminal (macOS)

Type chmod u+rwx "filename" to grant read, write and execute permissions.

List all disks with their identifiers, even if unmounted
diskutil list

Change disk
ls /volumes

Popular Posts