tinycodinglm / sys /sys-0021.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 19)
034ba67 verified
|
Raw History Blame Contribute Delete
1.57 kB
deepseek-harness trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

User

How do I control GPIO on Raspberry Pi?

Assistant
python
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

# LED blink
GPIO.setup(18, GPIO.OUT)
while True:
    GPIO.output(18, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(18, GPIO.LOW)
    time.sleep(1)

# Button input with interrupt
def button_callback(channel):
    print("Button pressed!")

GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(23, GPIO.FALLING, callback=button_callback, bouncetime=300)

# PWM (servo motor)
pwm = GPIO.PWM(18, 50)  # 50Hz
pwm.start(0)
pwm.ChangeDutyCycle(7.5)  # 90 degrees

# I2C with smbus
import smbus
bus = smbus.SMBus(1)
data = bus.read_byte_data(0x68, 0x75)  # Read WHO_AM_I from MPU6050

# SPI
import spidev
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 1000000
response = spi.xfer2([0x01, 0x00])

# Cleanup
GPIO.cleanup()