Skip to content

pierreportal/KnobGPIO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KnobGPIO

Plugin for the ChucK programming language.

Prerequisite

MCP3008

The MCP3008 is a 10-bit Analog-to-Digital Converter (ADC) chip that allows microcontrollers (like the Raspberry Pi) to read analog signals. The Raspberry Pi does not have built-in analog input pins, so if you're using an analog sensor (like a potentiometer, temperature sensor, or light sensor), you need an external ADC like the MCP3008 to convert the analog signal into a digital value that the Pi can process.

MCP3008 Pin Connect to Raspberry Pi Pin
VDD (16) 3.3V (Pin 1)
VREF (15) 3.3V (Pin 1)
AGND (14) GND (Pin 6)
CLK (13) GPIO11 (SPI CLK, Pin 23)
DOUT (12) GPIO9 (SPI MISO, Pin 21)
DIN (11) GPIO10 (SPI MOSI, Pin 19)
CS (10) GPIO8 (SPI CE0, Pin 24)
DGND (9) GND (Pin 6)
CH0 - CH7 Connect to potentiometer middle pin or other analog sensor
       _______
CH0 --|1  ° 16|-- VDD     -> 3.3v
CH1 --|2    15|-- VREF    -> 3.3v
CH2 --|3    14|-- AGND    -> gnd
CH3 --|4    13|-- CLK     -> GPIO11 (SPI CLK, Pin 23)
CH4 --|5    12|-- DOUT    -> GPIO9 (SPI MISO, Pin 21)
CH5 --|6    11|-- DIN     -> GPIO10 (SPI MISO, Pin 19)
CH6 --|7    10|-- CS/SHDN -> GPIO8 (SPI CE0, Pin 24)
CH7 --|8_____9|-- DGND    -> gnd

Install

On linux

git clone https://github.com/pierreportal/KnobGPIO.git

cd KnobGPIO
make linux
sudo make install

Usage

Basic Usage

KnobGPIO knob;

while (true)
{
    <<< knob.last() >>>;
}

Advanced Usage

KnobGPIO knob;

// Set ADC channel (0-7, automatically clamped if out of range)
knob.setChannel(0);

// Optional: Adjust update rate for performance tuning
// Default is 441 frames (~100Hz at 44.1kHz sample rate)
// Lower values = more responsive, higher CPU usage
// Higher values = less CPU usage, slower response
knob.setUpdateRate(220);  // ~200Hz update rate

while (true)
{
    <<< knob.last() >>>;
}

Features

  • Channel Validation: Channels are automatically clamped to valid range (0-7)
  • Error Handling: Graceful fallback if GPIO/SPI initialization fails
  • Performance Optimization: ADC reads are throttled to reduce CPU usage while maintaining responsiveness
  • Robust Operation: Continues outputting last valid value if ADC read errors occur

About

KnobGPIO is a custom Chugin (ChucK plugin) written in C++ that enables direct access to the Raspberry Pi’s GPIO pins from within ChucK. It allows ChucK programs to interface with physical hardware like knobs, buttons, and sensors, making it ideal for real-time, interactive audio systems running on the Pi.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors