6 Jul 2020

Get Started with ESP8266/ESP32. Setup RTOS & NONOS, IDF SDKs


My setup IDF_PATH --> sudo nano ~/.zshrc

1. Toolchain Setup


ESP8266 toolchain for macOS is available for download from Espressif website:
https://dl.espressif.com/dl/xtensa-lx106-elf-macos-1.22.0-100-ge567ec7-5.2.0.tar.gz
Download this file, then extract it in ~/esp directory:

mkdir -p ~/esp 
cd ~/esp 
tar -xzf ~/Downloads/xtensa-lx106-elf-macos-1.22.0-100-ge567ec7-5.2.0.tar.gz

To use it, you will need to update your PATH environment variable in ~/.zshrc file. To make xtensa-lx106-elf available for all terminal sessions, add the following line to your ~/.zshrc file:

export PATH=$PATH:$HOME/esp/xtensa-lx106-elf/bin

sudo nano ~/.bash_profile
export PATH=$PATH:$HOME/esp/xtensa-lx106-elf/bin


ESP32 toolchain for macOS is available for download from Espressif website:
https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2020r1-macos.tar.gz
Download this file, then extract it in ~/esp directory:

mkdir -p ~/esp 
cd ~/esp 
tar -xzf ~/Downloads/xtensa-esp32-elf-gcc8_2_0-esp-2020r1-macos.tar.gz

To use it, you will need to update your PATH environment variable in ~/.zshrc  file. To make xtensa-esp32-elf available for all terminal sessions, add the following line to your ~/.zshrc  file:

export PATH=$HOME/esp/xtensa-esp32-elf/bin:$PATH

sudo nano ~/.bash_profile
export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin


2. Get SDK

~/esp directory to install the prebuilt toolchain, ESP8266_RTOS_SDK and sample applications.

cd ~/esp 
git clone --recursive https://github.com/espressif/ESP8266_RTOS_SDK.git

or

git clone --recursive https://github.com/espressif/ESP8266_NONOS_SDK.git

or

git clone --recursive https://github.com/espressif/esp-idf.git

https://docs.espressif.com/projects/esp-idf/en/v3.3.1/get-started/index.html#setup-path-to-esp-idf

3. Setup Path

The toolchain programs access ESP8266_RTOS_SDK using IDF_PATH environment variable.

Not all shells use .profile. If you have /bin/bash and .bash_profile exists then update this file instead. For zsh, update .zprofile. Other shells may use other profile files (consult the shell’s documentation).

macOS Catalina 10.15.5 uses .zprofile instead of .bash_profile

Open terminal

sudo nano .zshrc

add

export IDF_PATH="~/esp/esp-idf:$IDF_PATH"

or

export IDF_PATH="~/esp/ESP8266_RTOS_SDK:$IDF_PATH"


or

export IDF_PATH="~/esp/ESP8266_NONOS_SDK:$IDF_PATH"

^O (F3) write the current file to disk

Force the .bash_profile to execute. This loads the values immediately without having to reboot. In your Terminal window, run the following command.

source ~/.zshrc

test with

echo $IDF_PATH or printenv IDF_PATH

my .zshrc
export PATH=$PATH:$HOME/esp/xtensa-lx106-elf/bin
export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin
export IDF_PATH=~/esp/ESP8266_RTOS_SDK


sudo nano ~/.bash_profile then need add source ~/.bash_profile to .zshrc

sudo nano ~/.profile then always use source ~/.profile
sudo nano ~/.zprofile

4. Install the Required Python Packages

python -m pip install --user -r $IDF_PATH/requirements.txt

5. Start a Project

Copy get-started/hello_world to ~/esp directory:

cd ~/esp 
cp -r $IDF_PATH/examples/get-started/hello_world

6. Connect the board

look up the board 
ls /dev/tty.*

/dev/tty.usbserial-1420
/dev/tty.wchusbserial1420

7. Configure

cd ~/esp/hello_world 
make menuconfig

ERROR No such file or directory ...
source ~/.profile



Navigate to Serial flasher config > Default serial port
to configure the serial port with /dev/tty.wchusbserial1420

8. Build and Flash

make flash

This will compile the application and all the ESP8266_RTOS_SDK components, generate bootloader, partition table, and application binaries, and flash these binaries to your ESP8266 board.

====

make all

It will compile app based on the config.

When make all finishes, it will print a command line to use esptool.py to flash the chip. However you can also do this from make by running:

make flash

This will flash the entire project (app, bootloader and init data bin) to a new chip. The settings for serial port flashing can be configured with make menuconfig.

You don't need to run make all before running make flash, make flash will automatically rebuild anything which needs it.

8.1 Erasing Flash

The make flash target does not erase the entire flash contents. However, it is sometimes useful to set the device back to a totally erased state. 

To erase the entire flash, run:

make erase_flash

9. Serial Monitor

make monitor

=== Troubleshooting ===

The setting may be done manually, each time PC is restarted. Another option is to set up it permanently by defining IDF_PATH in the user profile.

For manually, the command:

export IDF_PATH=~/esp/ESP8266_RTOS_SDK

5 Jul 2020

Add PATH to macOS Catalina 10.15.5

sudo nano ~/.bash_profile 

or (sudo nano ~/.profile)

(^ stands for the control key)
^O (F3) Write the current file to disk

add

export IM_STUDIO_PATH="$HOME/.imstudio/bin:$PATH"

The $PATH part is important as it appends the existing PATH to preserve it in the new value.

Force the .bash_profile to execute. This loads the values immediately without having to reboot. In your Terminal window, run the following command.

source ~/.bash_profile

That’s it! Now you know how to edit the PATH on your Mac OS X computer system. You can confirm the new path by opening a new Terminal and running:

echo $PATH


macOS Catalina 10.15.5

macOS Catalina uses .zprofile instead of .bash_profile

sudo nano .zprofile

add


export PATH=$PATH:/usr/local/scala/bin

==========

1. Enter nano .bash_profile (It will open the .bash_profile file in the nano editor)
2. After making changes to the file use ControlX (to "exit")
3. Then it asks for the changes to be made permanently and gives two options: Yes (or) No
4. Press Y and press Enter to save the file


14 Jun 2020

Entity Framework Core. Code-First Approach

Entity Framework Core. Code-First Approach

- FK defines relationships of tables
- Navigation Property defines the type of relations: One-To-One, One-To-Many, Many-To-Many
- If FK wasn't initialized, EF creates it automatically

How To Use?
1. Design a DB on the paper
2. Set FK (FK points from the main table to the dependent table)
3. Define Navigation property

// ==========================

public class Customer
{
        public int CustomerId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }

        // Navigation property (or Link)
        public List<Order> Orders { get; set; }
}

public class Order
{
        public int OrderId { get; set; }
        public string ProductName { get; set; }
        public string Description { get; set; }

        // Navigation property (or Link)
        public Customer Customer { get; set; }
}

31 May 2020

Override Bootstrap Styles (without !important)

<link href="bootstrap.min.css" rel="stylesheet">
<link href="custom.css" rel="stylesheet">

100 points for IDs 
10 points for classes and pseudo-classes 
1 point for tag selectors and pseudo-elements

<body id="bootstrap-overrides">

/* Example selector defined in Bootstrap */ 

.jumbotron h1
/* 10+1=11 priority scores */
line-height: 1; 
color: inherit; 

/* Your initial take at styling */ 
h1 {
/* 1 priority score, not enough to override Bootstrap jumbotron definition */ 
line-height: 1; 
color: inherit; 

/* New way of prioritization */ 
#bootstrap-overrides h1
/* 100+1=101 priority score, yay! */ 
line-height: 1; 
color: inherit; 
}

29 May 2020

React. Starting a New Project

New Project
Use either one of the below commands:

npx create-react-app my-app
npm init react-app my-app
yarn create react-app my-app


If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app to ensure that npx always uses the latest version.

npx create-react-app my-app
cd my-app
npm start


https://create-react-app.dev/docs/getting-started/

Bootstrap
npm install react-bootstrap bootstrap

Redux
npm install react-redux

9 May 2020

C++. Include file. File Path

If the directory is in another path, you'll have to qualify the pathname. remember that .. goes one directory up. so, let's say the cpp file is in directory "myproject/a/source.cpp" and event.h is in "myproject/b/event.h". Your include would look like this:

#include "../b/event.h"

14 Apr 2020

13 Apr 2020

Setup Serial Port VM VirtualBox

for macOS, Unix

Enable in Virtual Box

Ports -> 
Host Device:
/dev/tty.wchusbserial1420

Important! In the guest system install drivers for the device that will be used with the port.

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

26 Jan 2020

How to run Raspberrypi on QEMU emulator

Commands:
startx
sudo apt-get install raspberrypi-kernel-headers
sudo shutdown -h now
sudo apt install raspberrypi-ui-mods
sudo raspi-config
sudo apt-get update

SSH:
sudo raspi-config

Connect: 
(Install OpenSSH before)
ssh -p2222 -X pi@localhost
ssh pi@localhost -p 2222

IP:
hostname -I
10.0.2.15

qemu-img convert -f raw -O qcow2 2017-08-16-raspbian-stretch.img raspbian-stretch.qcow

Start:
-----
qemu-system-x86_64.exe -boot d -cdrom kolibri.iso -m 512
qemu-system-armw.exe -M versatilepb -cpu arm1176 -m 256 -hda 2019-09-26-raspbian-buster-lite.img -dtb versatile-pb.dtb -kernel kernel-qemu-4.19.50-buster -append 'root=/dev/sda2' -no-reboot
===
cd: <iso folder>
qemu-system-armw.exe -kernel ./kernel-qemu-4.4.34-jessie -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda raspbian-stretch-lite.qcow -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -net nic -nic user,hostfwd=tcp::2222-:22
===

- At the bottom of the screen. Type "pi" and hit enter.
- You will be prompted for a password, type "raspberry" and hit enter.
- If you wish to set a root password, type "sudo passwd root"
- From here you can continue to use the command line, but if you would prefer to use a window based desktop, type "startx"

Popular Posts