Close

Getting to Blinky with Thonny MicroPython and the ESP32-C6

A project log for ESP32-C6 Exploration

Putting the ESP32-C6 Supermini though its paces. Is it worth using? How much does AI help me learn the chip quickly?

shanesnipeshane.snipe 03/02/2025 at 16:190 Comments

I have made the choice to start with Micropython because the burn and learn cycle is so much shorter than ESP-IDF or Arduino. I was concerned that the ESP32-C6 support would not be there yet in Micropython but it is looking good so far.

I started with wanting to blink the LED. The latest ChatGPT and GROK models allow you to attach a picture and they are pretty good an pulling information from it.  I have been attaching schematics and with good success and I save on the prompting I have to do. I wanted to try it with this round and attached the Pinout and asked for a blinking LED Micropython script.

I have been using Thonny for my Micropython. I connected the ESP32-C6 and under Tools->Options it recognized the USB port.. 


Clicking on the install link, I had the ESP32-C6 option. I picked the Espressif version and it installed.

I find Thonny a little cludgy to program. You may have to do some combination of pressing the stop program and the reset on the board. If a program is running it will not allow you to overwrite the main.py script. 

ChatGPT provided working code but did not recognize the right pin for the LED. It  suggested the builtin LED was on GPIO2 but it was on 15. 

 So I copied the LED code from ChaptGPT as follows:

from machine import Pin
import time

# Create a Pin object for the onboard LED (usually GPIO 2 for ESP32 boards)
led = Pin(15, Pin.OUT)

while True:
    led.value(1)  # Turn the LED on
    time.sleep(1)  # Wait for 1 second
    led.value(0)  # Turn the LED off
    time.sleep(1)  # Wait for 1 second

Saved it to MicroPython Device as main.py and pressed the play button. Blue light is blinking in less then 5 minutes.

I noticed there was another LED on the module with 4 pads and a 8 designator.

The pinout shows this LED to be a WS2812 (Neopixel) and I asked GROK to write me the code to run it. 

import machine
import neopixel
import time

# Define the pin for the WS2812 LED (GPIO8)
led_pin = machine.Pin(8)
# Define the number of NeoPixels (in this case, 1 for the onboard LED)
num_pixels = 1

# Create a NeoPixel object
np = neopixel.NeoPixel(led_pin, num_pixels)

# Function to set the LED to a specific color (RGB values, 0-255 each)
def set_color(red, green, blue):
    np[0] = (red, green, blue)  # Set the color for the first (and only) pixel
    np.write()  # Update the LED

# Function to cycle through colors (example animation)
def cycle_colors():
    while True:
        # Red
        set_color(255, 0, 0)
        print("Red")
        time.sleep(1)
        
        # Green
        set_color(0, 255, 0)
        print("Green")
        time.sleep(1)
        
        # Blue
        set_color(0, 0, 255)
        print("Blue")
        time.sleep(1)
        
        # White
        set_color(255, 255, 255)
        print("White")
        time.sleep(1)
        
        # Off (black)
        set_color(0, 0, 0)
        print("Off")
        time.sleep(1)

# Run the color cycle
cycle_colors()

30 seconds later I have updated the code in the main.py file on the ESP32-C6 and my board lights up like a Christmas tree. 

So, if the LLM knows what pin and what type of LED, this is all super smooth.

I unplugged in and connected it to a Voltaic power bank and it blinks away happily.

Note some power banks will shut down because the MCU does not drawing enough power.

The Voltaic will continue to work.

Discussions