Skip to content

Latest commit

 

History

History
81 lines (55 loc) · 2.79 KB

usingBlinka.md

File metadata and controls

81 lines (55 loc) · 2.79 KB

To set up a Raspberry Pi Pico microcontroller on Windows to use Blinka, one needs to install the necessary software and libraries to enable CircuitPython compatibility.

Here are the steps to get started:

Install Python:

Ensure you have Python 3.x installed on your Windows computer. You can download the latest version of Python from the official Python website. During installation, make sure to check the option to add Python to your system PATH.

Install Thonny IDE:

Thonny is a user-friendly integrated development environment (IDE) for Python and is a popular choice for programming the Raspberry Pi Pico. You can download Thonny from the official Thonny website.

Install Required Libraries:

Open a command prompt (cmd) and install the required libraries using pip, Python's package manager. Run the following commands:

bash

pip install hidapi
pip install adafruit-blinka

Set Environment variable:

You must do this every time before running circuitpython code, you can set it permanently in windows if you like, for now just type into the same cmd window you're using with Python

set BLINKA_U2IF=1

Verify Your Setup:

To verify that Blinka and CircuitPython are working correctly, you can run the following command

import hid
hid.enumerate()
'device' in dir(hid)

It list all the devices with the specific VID (Vendor ID) and PID (Product ID).

You can create Python scripts on your Windows computer using a text editor or IDE of your choice, such as Thonny. Save your Python code with a .py extension.

Run Your Code:

# Import necessary libraries
import time  # Provides time-related functions
import board  # Provides access to board-specific features
import analogio  # Allows reading analog input
import hid  # Provides access to Human Interface Device (HID) functionality

# Initialize the HID device
device = hid.device()
device.open(51966, 16389)  # Open a HID device with specific VID (Vendor ID) and PID (Product ID)

# Initialize the analog input from a knob
knob = analogio.AnalogIn(board.ADC0)  # Connect to the analog input pin ADC0
filename = "example.txt"  # Specify the name of the output file

# Function to convert raw ADC readings to voltage
def get_voltage(raw):
    return (raw * 3.3) / 65536

# Open the output file for writing in UTF-8 encoding
file = open(filename, "w", encoding="UTF-8")

# Read analog input, convert to voltage, and write to file 10 times with a delay
for i in range(10):
    raw = knob.value  # Read the raw ADC value from the knob
    volts = get_voltage(raw)  # Convert raw value to voltage
    result = "raw = {:5d} volts = {:5.2f} \n".format(raw, volts)  # Format the data as a string
    file.write(result)  # Write the formatted data to the file
    time.sleep(0.5)  # Pause for 0.5 seconds

# Close the file to save changes
file.close()