Getting Started with Maker Feather AIoT S3 using CircuitPython

Getting Started with Maker Feather AIoT S3 using CircuitPython

Setting up the board

The Maker Feather AIoT S3 comes with the pre-installed UF2 bootloader. Hence you will need to program it into CircuitPython software by dragging the correct .uf2 file into the drive.

1. Click here to download the Maker Feather AIoT S3 .uf2 file or search “Maker Feather AIoT S3” in circuitpython.org/downloads.

2. To upload the CircuitPython firmware into the Maker Featehr AIoT S3, you will need to enter the UF2 Bootloader mode. Press the reset button twice.

These indicate that we’re already in the UF2 bootloader mode:

  • RGB LED showing green color.
  • Status LED blinking slowly.
  • A drive detected as “MFAS3BOOT” in your "This PC".

 

Note: If you encounter any problems when you upload the .uf2 file or you cannot enter the UF2 bootloader mode, follow the instructions in the datasheet under 6.2 ROM Bootloader to reload the UF2 Bootloader in the board again and repeat Step 2.

3. Drag or copy and paste the Maker Feather AIoT S3 .uf2 file that you have downloaded previously to te drive named "MFAS3BOOT".

4. If you have successfully uploaded the CircuitPython firmware into your Maker Feather AIoT S3, you will be able to see a CIRCUITPY drive on your computer.

5. Before you start to code, make sure that the “CircuitPython (generic)” has been chosen as the interpreter (if applicable) in your coding software. And the required lib bundle can be found here.

 

We have prepared some simple example codes that you may start with:

  1. Example 1: Blink
  2. Example 2: Lighting Up The Neopixel RGB LED
  3. Example 3: Turn on the Music
  4. Example 4: Read Analog Sensor Value
  5. Example 5: Entering Sleep Mode on Maker Ports
  6. Example 6: Displaying Text on SSD1315 OLED module via I2C
  7. Example 7: NTP Clock

Example 1: Blink

1. Open your editor software (for example Thonny). Select the code.py file in your drive.
2. Copy and paste the following code to your editor.

#import necessary libraries
import board
import digitalio
import time

#initialize leds on D14, D21 and D47 pins
led1 = digitalio.DigitalInOut(board.D14)
led2 = digitalio.DigitalInOut(board.D21)
led3 = digitalio.DigitalInOut(board.D47)

#set the led pins as output
led1.direction = digitalio.Direction.OUTPUT
led2.direction = digitalio.Direction.OUTPUT
led3.direction = digitalio.Direction.OUTPUT

while True:
    #led1 is light up for 0.5s then turned off
    led1.value = True
    time.sleep(0.5)
    led1.value = False
    time.sleep(0.5)
    
    #led2 is light up for 0.5s then turned off
    led2.value = True
    time.sleep(0.5)
    led2.value = False
    time.sleep(0.5)
    
    #led3 is light up for 0.5s then turned off
    led3.value = True
    time.sleep(0.5)
    led3.value = False
    time.sleep(0.5)

3. Flash the codes to your Maker feather AIoT S3. And your CIRCUITPY drive should look like this (no lib file is used):

4. You may also try to flash this code to your Maker Feather AIoT S3 and observe what will happen to your Maker Feather AIoT S3.

#import necessary libraries
import board
import digitalio
import time

#define all of the led pins on the board in an array
led_pins = [board.D14, 
            board.D15,
            board.D16,
            board.D21,
            board.D47,
            board.D48,
            board.D38,
            board.D39,
            board.D40,
            board.D41,
            board.D42]

#set all of the led pins as output
led = []
for pin in led_pins:
    # Set pins as digital output
    digout = digitalio.DigitalInOut(pin)
    digout.direction = digitalio.Direction.OUTPUT
    led.append(digout)

while True:
    #Turn on LEDs one-by-one very quickly
    for i in range(len(led)):
        led[i].value = True
        time.sleep(0.15)

    # Turn off LEDs one-by-one very quickly
    for i in range(len(led)):
        led[i].value = False
        time.sleep(0.15)

 

Example 2: Lighting up the Neopixel RGB LED

1. Open your editor software (for example Thonny). Select the code.py file in your drive.
2. Copy and paste the following code to your editor.

#import necessary libraries
import board
import neopixel
import time

# Initialize Neopixel RGB LED on pin D46
pixels = neopixel.NeoPixel(board.NEOPIXEL, 46)
#Clear Neopixel RGB LED
pixels.fill(0)

#Set pixel brightness
pixels.brightness = 0.5

while True:
    #Light up Neopixel RGB LED with purple colour
  #the sequence of the colour code is (R,G,B) input range is from 0-255 (decimal)
    pixels.fill((200, 0, 200))
    time.sleep(0.5)
    pixels.fill(0)
    time.sleep(0.5)

3. Flash the codes to your Maker feather AIoT S3. And your CIRCUITPY drive should look like this:

    Library file(s) required:
    neopixel.mpy

If you don't have this file in your computer, download the lib bundle here and search for this file inside the "lib" folder.

You may also try to flash this code to your Maker Feather AIoT S3 and observe what will happen to your Maker Feather AIoT S3.

#Import necessary libraries
import board
import neopixel
import time

# Initialize Neopixel RGB LED on pin D46
pixel = neopixel.NeoPixel(board.NEOPIXEL, 46)
#Clear Neopixel RGB LED
pixel.fill(0)

#Set pixel brightness
pixel.brightness = 0.5

#Define each colour codes in RGB decimal format
RED = (255, 0, 0)
ORANGE = (255,180,0)
YELLOW = (80, 80, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
WHITE = (100, 100, 100)

#Group all the colours in an array
colour = [RED,ORANGE,YELLOW,GREEN,CYAN,BLUE,PURPLE,WHITE]

while True:
    #Light up the neopixel RGB LED and change the colour every 0.15s
    for i in range(len(colour)):
        pixel.fill(colour[i])
        time.sleep(0.5)

 

Example 3: Turn on the Music

1. Open your editor software (for example Thonny). Select the code.py file in your drive.
2. Copy and paste the following code to your editor.

#Import necessary libraries
import board
import digitalio
import simpleio
import time

#Define the Melody Note and Duration
MELODY_NOTE = [659, 659, 0, 659, 0, 523, 659, 0, 784]
MELODY_DURATION = [0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.2]

#Define pin connected to piezo buzzer
PIEZO_PIN = board.D12

#Initialize buttons
btn1 = digitalio.DigitalInOut(board.D3)
btn1.direction = digitalio.Direction.INPUT
btn1.pull = digitalio.Pull.UP

#Play melody during start up  
for i in range(len(MELODY_DURATION)):
    #The boad will not work with 0 frequency, so everytime the frequency is 0, it will rest for a duration of time
    if MELODY_NOTE[i] == 0:
        time.sleep(MELODY_DURATION[i])
    else:
        # Play melody tones
simpleio.tone(PIEZO_PIN, MELODY_NOTE[i], duration=MELODY_DURATION[i])

while True:
    # Check button (D3)
    if not btn1.value:  #Button is pressed

        # Play tones
        #Format(pin,frequency,duration)
        simpleio.tone(PIEZO_PIN, 262, duration=0.1)
        simpleio.tone(PIEZO_PIN, 659, duration=0.15)
        simpleio.tone(PIEZO_PIN, 784, duration=0.2)

3. Flash the codes to your Maker feather AIoT S3. And your CIRCUITPY drive should look like this:

    Library file(s) required:
    simpleio.mpy

If you don't have this file in your computer, download the lib bundle here and search for this file inside the "lib" folder.

Example 4: Read Analog Sensor Value

1. Open your editor software (for example Thonny). Select the code.py file in your drive.
2. Connect your sensor module to one of the maker ports using stemma QT to 4 female pins / grove cable.


3. Copy and paste the following code to your editor.

#Import necessary libraries
import board
import time
import analogio

#Define analog pin A3 used on the board
sensor = analogio.AnalogIn(board.A3)

while True:
    #Serial print the sensor value every 1 second
    print(str(sensor.value))
    time.sleep(1)

4. Flash the codes to your Maker feather AIoT S3. And your CIRCUITPY drive should look like this (no lib file is used):

Example 5: Enter Sleep Mode on Maker Ports

Note: GPIO LED, RGB LED, Piezo Buzzer and Maker Port (H) are powered by the Vperipheral. Make sure it’s enabled by turning on D11 before using them.

1. Open your editor software (for example Thonny). Select the code.py file in your drive.
2. Connect your sensor module to one of the horizontal maker ports using stemma QT to 4 female pins / grove cable.


3. Copy and paste the following code to your editor.

#Import necessary libraries
import board
import time
import analogio
import digitalio

#Define analog pin A3 used on the board
sensor = analogio.AnalogIn(board.A3)

#Define digital pin D11 used on the board as the switch
# D11 pin is used to turn on/off the Vperipheral, which powers the GPIO & RGB LEDs, piezo buzzer and Maker Ports (horizontal).
# You can check the status of D11 pin by observing the LED next to VP pin.

vp_switch = digitalio.DigitalInOut(board.D11)
vp_switch.direction = digitalio.Direction.OUTPUT

while True:
    #Turn on led switch on D11
    vp_switch.value = True
    #Serial print analog sensor value
    print(str(sensor.value))
    time.sleep(2)
    #Turn off led switch, then sleep for 10 seconds
    vp_switch.value = False
    time.sleep(10)

4. Flash the codes to your Maker feather AIoT S3. And your CIRCUITPY drive should look like this (no lib file is used):

Example 6: Displaying text on SSD1315 OLED module via I2C

1. Open your editor software (for example Thonny). Select the code.py file in your drive.
2. Connect your OLED module to the maker port marked "CL" and "CA" using stemma QT to 4 female pins / grove cable.


3. Copy and paste the following code to your editor.

#Import necessary libraries
import board
import busio
import adafruit_ssd1306

# Define the i2c GPIOs on D41 and D42
#format: (board.SCL, board.SCA)
i2c = busio.I2C(board.D41, board.D42)
# Define the OLED display using the above pins
#format: (width, length, i2c pins)
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)

while True:
    # Clear the OLED display
    oled.fill(0)                             
    # Write the data: ('text', x , y, pixel colour)
    # Pixel colour: 0 = false, 1 = true
    oled.text('Hello world!', 0, 0, 1)
    oled.text('Yeah!', 0, 25, 1)
    # Show the written data
    oled.show()  

4. Flash the codes to your Maker feather AIoT S3. And your CIRCUITPY drive should look like this:

    Library file(s) required:
    adafruit_framebuf.mpy, adafruit_ssd1306.mpy

    File(s) required:
    font5x8.bin

If you don't have this file in your computer, download the lib bundle here and search for this file inside the "lib" folder.

Example 7: NTP Clock

1. Open your editor software (for example Thonny). Select the code.py file in your drive.
2. Copy and paste the following code to your editor.


#Import necessary libraries
import time
import socketpool
import wifi
import adafruit_ntp
# Get wifi details and more from a secrets.py file
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise
#Connect to wifi
print("Connecting to WiFi")
wifi.radio.connect(secrets["ssid"], secrets["password"])
print("Connected!")
#Setting up the wifi conenction into the socketpool
pool = socketpool.SocketPool(wifi.radio)
#Defining ntp function with GMT +8 timezone
ntp = adafruit_ntp.NTP(pool, tz_offset=8)
while True:
    #Print ntp time (year, month, date, hour, min, second) every 1 second
    print(ntp.datetime)
    time.sleep(1)
)
        simpleio.tone(PIEZO_PIN, 784, duration=0.2)

3. Create another file and name it as secrets.py, then copy the following code to your editor:

#Change it to your wifi SSID and Password
secrets ={
    'ssid':'Your wifi SSID',
    'password':'Your wifi Password'}


4. Flash the codes to your Maker feather AIoT S3. And your CIRCUITPY drive should look like this:

    Library file(s) required:
    adafruit_ntp.mpy

If you don't have this file in your computer, download the lib bundle here and search for this file inside the "lib" folder.

Hardware Components


Related Posts

Getting Started with Maker Feather AIoT S3 (Arduino IDE)

Getting Started with Maker Feather AIoT S3 (Arduino IDE)

Getting started with Maker Feather AIoT S3 (Arduino IDE) with basic system. There are 7 complete example from totally basic until medium level...