MicroPython IoT MicroController-Installation Guide and Basics

Live Price Tracker Display Price Ticker on TFT LCD Shield Python-to-Arduino:


For Instructions Watch The Video Here:


 
import serial
import time
import requests
symbol='BTCUSD'
headers={
    'User-Agent': 'Python',
    'Accept': 'application/json'
    }
ser=serial.Serial('COM4',9600)
time.sleep(2)
while True:
    data=requests.get(f'https://api.india.delta.exchange/v2/tickers/{symbol}',headers=headers)
    mark_price=round(float(data.json().get('result')['mark_price']),2)
    print(mark_price)
    ser.write((f'{symbol}:{mark_price}\n').encode('utf-8'))
    time.sleep(30)

Python-to-Arduino TFT Live Signal Text Display:


For Instructions Watch The Video Here:


Upload this Code to TFT LCD Shield Arduino:

 
// All the mcufriend.com UNO shields have the same pinout.
// Control pins A0-A4. Data D2-D9. microSD D10-D13.

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

#include 
#include "Adafruit_GFX.h"
#include 
MCUFRIEND_kbv tft;

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

void setup(void) {
    Serial.begin(9600);
    uint16_t ID = tft.readID();
    if (ID == 0xD3D3) ID = 0x9481;
    tft.begin(ID);

    tft.setRotation(0);
    tft.fillScreen(BLACK);
    tft.setTextColor(WHITE, BLACK);
    tft.setTextSize(2);
    tft.setCursor(0, 0);
    tft.println("Waiting for Python...");
}

void loop(void) {
    if (Serial.available()) {
        String msg = Serial.readStringUntil('\n');
        msg.trim();

        tft.fillScreen(BLACK);
        tft.setCursor(0, 0);
        tft.setTextColor(WHITE, BLACK);
        tft.setTextSize(2);
        tft.println(msg);

        Serial.println("OK: " + msg);
    }
}

Run the Python Code in IDE/IDLE:


import serial
import time

ser=serial.Serial('COM4',9600)
time.sleep(2)

ser.write(b'Hello World\n')



Fetch Tickers Data in MicroPython ESP32 IoT Device to Automate Trades:


For Instructions Watch The Video Here:


 
from machine import Pin
import network
import json
import urequests
led=Pin(2, Pin.OUT)
wlan=network.WLAN(network.STA_IF)
wlan.active(True)
# Read credentials from ss.txt
w = open('delta.txt', 'r').read().strip()
wc = json.loads(w)
wn = wc['in']
wp = wc['key']
print("Connecting to Wi-Fi:", wn)
wlan.connect(wn,wp)
# wlan.ifconfig()[1:3]
# urequests.get('https://api.ipify.org').text
symbol='BTCUSD'
headers={
    'User-Agent': 'MicroPython',
    'Accept': 'application/json'
    }
data=urequests.get(f'https://api.india.delta.exchange/v2/tickers/{symbol}',headers=headers)
print(data.json())

Static IP MicroPython ESP32 IoT Device to Automate Trades:


For Instructions Watch The Video Here:


 
from machine import Pin
import network
import json
import urequests
led=Pin(2, Pin.OUT)
wlan=network.WLAN(network.STA_IF)
wlan.active(True)
# Read credentials from ss.txt
w = open('delta.txt', 'r').read().strip()
wc = json.loads(w)
wn = wc['in']
wp = wc['key']
print("Connecting to Wi-Fi:", wn)
wlan.connect(wn,wp)
print(wlan.ifconfig()[1:3])
print(urequests.get('https://api.ipify.org').text)

Connect MicroPython ESP32 IoT Device to WIFI:


For Instructions Watch The Video Here:


 
from machine import Pin
import network
import json
led=Pin(2, Pin.OUT)
wlan=network.WLAN(network.STA_IF)
wlan.active(True)
# Read credentials from ss.txt
w = open('ss.txt', 'r').read().strip()
wc = json.loads(w)
wn = wc['in']
wp = wc['key']
print("Connecting to Wi-Fi:", wn)
wlan.connect(wn,wp)
print(wlan.ifconfig()[2])

Get your ESP32 MicroController Board From YouTube Store Follow the Link : https://www.youtube.com/@ProfitAddaWeb/store


Get your USB Cable From YouTube Store Follow the Link :

Get your ESP32 MicroController Board From YouTube Store Follow the Link : https://www.youtube.com/@ProfitAddaWeb/store


In CMD Install esptool through PIP such as: pip install esptool


Erase Flash: c:\Python36\Lib\site-packages>esptool.py --port COM6 erase_flash


Install ESP32 Firmware from here : https://micropython.org/download/all


Write Flash: c:\Python36\Lib\site-packages>esptool.py --port COM6 write_flash 0x1000 C:\Users\PCNAME\Desktop/arduino/write_flash/esp32-20180511-v1.9.4.bin


Open your Putty Put as COM6(Your PORT) in Serial Line Box and in Speed 115200 then go for Connection type and Select as Serial and then go and Select Open. A Command Line Python will Be opened do type the programme or select the programme from import and run them.


In CMD Install ampy through PIP such as: pip install adafruit-ampy


Put Code in ESP32 development board through ampy as such : ampy --port COM6 put blinky.py



>>> from machine import Pin
>>> led=Pin(2,Pin.OUT)
>>> led.value(1)
>>> led.value(0)
>>>