MicroPython on ESP32S3 or STM32F405 Pyboard - Getting started for Final Year Projects

Working on your final-year projects. Here are some guides or notes of Micropython programming that might be quite useful for the development for the FYPs (Final-Year Projects).


Xiao ESP32S3 Sense Pinouts (click the picture to enlarge it)


Xiao ESP32S3 Sense Front Diagram

1) Xiao ESP32S3 Sense


eBook pdf free downloads: XIAO: Big Power, Small Board : Mastering Arduino and TinyML, by  : https://mjrovai.github.io/XIAO_Big_Power_Small_Board-ebook/  Xiao Big Power PDF version Download



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


2) ESP32S3 无名科技 No Logo

Link: https://www.nologo.tech/product/esp32/esp32s3/esp32s3supermini/esp32S3SuperMini.html

Path: F:\Papers\PolyU-ama\projs\uPython-NoLogo_esp32s3\ESP32-S3-SuperMini+PICO+HXB-info\

Help commands - how to use help in MicroPython?

Type help() in Thonny IDE

>>> help()

Welcome to MicroPython on the ESP32!

For generic online docs please visit http://docs.micropython.org/

For access to the hardware use the 'machine' module:

import machine

pin12 = machine.Pin(12, machine.Pin.OUT)

pin12.value(1)

pin13 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP)

print(pin13.value())

i2c = machine.I2C(scl=machine.Pin(21), sda=machine.Pin(22))

i2c.scan()

i2c.writeto(addr, b'1234')

i2c.readfrom(addr, 4)


Basic WiFi configuration:

import network

sta_if = network.WLAN(network.STA_IF); sta_if.active(True)

sta_if.scan()                             # Scan for available access points

sta_if.connect("<AP_name>", "<password>") # Connect to an AP

sta_if.isconnected()                      # Check for successful connection


Control commands:

  CTRL-A        -- on a blank line, enter raw REPL mode

  CTRL-B        -- on a blank line, enter normal REPL mode

  CTRL-C        -- interrupt a running program

  CTRL-D        -- on a blank line, do a soft reset of the board

  CTRL-E        -- on a blank line, enter paste mode


For further help on a specific object, type help(obj)

For a list of available modules, type help('modules')

>>> help(help)

object <function> is of type function

  • Type the command: help('modules') to display the available modules of your firmware's MicroPython. See the pictures below.


(Click the picture to enlarge it)

If you want to know more on how to use the hardware 'machine' in the MicroPython environment, you can try to input as follows:

  • First, you need to import the module 'machine' or 'umachine': import machine
  • Then, you can ask the help on the module of machine. The help command will recognise the 'machine' is of type module.
     
         

  • As shown above, you can find a lot of functions under the module 'machine' or 'umachine'.
  • But you might probably want to learn more on how to use the functions, e.g. PWM.
  • By typing help(PWM), you can learn how to use the PWM function. Remember that you need to import the PWM function first.
     



  • After importing: from machine import Pin
  •     help(Pin) can give more info.
  •     d08.PULL_DOWN is to pull down the pin with weak power to ground, upon reset.





===== PWM (Pulse Width Modulation) =====
As an example, there are functions, e.g. PWM.init()

     

References 


===== ----- ***** Thonny Shell Commands ***** ----- =====

Ref: https://techexplorations.com/guides/esp32/micropython-with-the-esp32/13-micropython-shell/

>>> import uos
>>> uos.listdir()
>>> execfile("hello_world.py")


===== ===== Pins and GPIO ===== =====
  • You can also check how to use the 'Pin' function, by typing help(machine.Pin) or help(Pin) after importing machine.
     



===== Motor Driver uPython Test Program =====
from machine import Pin
import time
p14 = Pin(14, Pin.OUT)  # keep alive, 
p14.on()     # Turn on power mosfet: PBAT_SW = PBAT
# p14.off()
p7 = Pin(7, Pin.OUT)   # GPIO7 = motor enable mot_en
for i in range(3):
   p7.on()     # mot_en = 1, LED motor On
   time.sleep_ms(500)
   p7.off()
   time.sleep_ms(500)
   print("Blink ", i+1)

p7.on()

from machine import Pin, PWM

# p15 = Pin(15, Pin.OUT)
# p15.on()
p18 = Pin(18, Pin.OUT)      # Gpio18 = p18 = motor1_c1
p18.off()
p17 = PWM(Pin(17), duty=355)  # Gpio17 = p17 = motor1_c2, duty 0 ~ 1024
p17.freq(1)  # 5 Hz
p18 = Pin(18, Pin.OUT)
p18.off()
time.sleep_ms(5000)

p17.deinit()   # stop motor

   
From above, we can know that led.value() is a function. We can try to type:  led.value()

   





 


===== ADC uPython Test Program (Read DC Voltages) =====
from machine import ADC, Pin
import time

adc9 = ADC(Pin(9))
adc9.read()
adc9.atten(ADC.ATTN_11DB)
    # 设置 11dB 衰减输入 (测量电压大致从 0.0v - 3.6v)
adc9.width(ADC.WIDTH_12BIT)
adc10 = ADC(Pin(10))
adc10.atten(ADC.ATTN_11DB)
adc10.width(ADC.WIDTH_12BIT)
adc10.read()
adc11 = ADC(Pin(11))
adc11.atten(ADC.ATTN_11DB)
adc11.width(ADC.WIDTH_12BIT)
adc11.read()
time.sleep_ms(1000)
adc9.read()
adc10.read()
adc11.read()
time.sleep_ms(1000)
adc9.read()
adc10.read()
adc11.read()







Comments

Popular posts from this blog

New small Xiao MG24 Sense board - can it run microPython?