Skip to content

Binney/electronics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Electronics Tips

Here are some useful links and basic code snippets!

Links

Interactive Pi Pico Pinout

CircuitPython uf2 download

Adafruit CircuitPython library bundle (you shouldn't need this if you're using the VS Code extension)

VS Code

CircuitPython v2 VS Code extension

Keyboard, mouse and gamepad

My etch a sketch mouse tutorial

Adafruit HID tutorial

Adafruit HID docs and examples using mouse, keyboard and gamepad

Custom HID descriptors (more complex)

Cool stuff to do with Velostat (electronic circuits made of fabric)

Where to buy

There are plenty of good online stores for electronics equipment but the 3 I like most are

The Pi Hut - very thorough collection and good documentation on most listings

Pimoroni - more suited to kits and fun variants on the basics (e.g. they do a pi pico but it's huge)

CPC Farnell - good if you're doing a bulk order and you know exactly what you want, will be a bit cheaper than Pi Hut or Pimoroni - but worse UX and I've definitely ordered the wrong thing before because the description wasn't as clear

Hardware Hacking Evening slides

They're here!

Pico setup

  1. Download UF2 for the correct board (28th July: we are using Pi Pico, not W, not 2)
  2. Plug Pico into your computer with a decent USB Micro cable.
  3. Copy UF2 to root of device.
  4. Open VS Code with extension installed.
  5. CircuitPython: Select Serial Port -> click whatever it says
  6. CircuitPython: Choose CircuitPython Board -> Raspberry Pi:Pico
  7. CircuitPython: Open Serial Monitor
  8. Install dependencies: CircuitPython: Show Available Libraries
  9. Write code
  10. Hack
  11. Have fun!

Sample code

Blinky

import board
import digitalio
from time import sleep

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = True
    sleep(1)
    led.value = False
    sleep(1)

Pressy Buttony

import time
import board
from digitalio import DigitalInOut, Direction, Pull

led = DigitalInOut(board.LED)
led.direction = Direction.OUTPUT

switch = DigitalInOut(board.GP15)
switch.direction = Direction.INPUT
switch.pull = Pull.UP

while True:
    if switch.value:
        led.value = False
    else:
        led.value = True
    time.sleep(0.01)

Debouncing

import board
import digitalio
from adafruit_debouncer import Debouncer

pin = digitalio.DigitalInOut(board.GP15)
pin.direction = digitalio.Direction.INPUT
pin.pull = digitalio.Pull.UP
switch = Debouncer(pin)

while True:
	switch.update()
	if switch.fell:
		print('Just pressed')
	if switch.rose:
		print('Just released')

Basic keyboard

import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from time import sleep

keyboard = Keyboard(usb_hid.devices)

while True:
    keyboard.send(Keycode.CAPS_LOCK)
    sleep(1)

Separate press and release keyboard

import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from time import sleep

keyboard = Keyboard(usb_hid.devices)

while True:
    keyboard.press(Keycode.CAPS_LOCK)
    sleep(0.5)
    keyboard.release(Keycode.CAPS_LOCK)
    sleep(1)

About

Doodles and fragments

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •