All JoyPiNoteBetterLib modules with imports, methods, and examples.
- Button Matrix
- Buzzer
- Temperature & Humidity Sensor
- Joystick
- LCD Text Display
- Led Matrix
- Light Sensor
- NFC/RFID Reader
- Relay
- 7-Segment Display
- Servo Motor
- Sound Sensor
- Stepper Motor
- Tilt Sensor
- Touch Sensor
- Ultrasonic Sensor
- Vibrator
A 4x4 keypad with 16 buttons (0-15).
from JoyPiNoteBetterLib import ButtonMatrix
matrix = ButtonMatrix()| Method | Description | Returns |
|---|---|---|
getPressedKey() |
Returns the currently pressed button | int (0-15) or None |
getAdcValue() |
Reads the raw ADC value | int (0-1023) |
readChannel(channel) |
Reads raw ADC from specific channel | int (0-1023) |
matrix = ButtonMatrix()
while True:
key = matrix.getPressedKey()
if key is not None:
print(f"Button {key} was pressed")A small speaker that can produce beeping sounds.
from JoyPiNoteBetterLib import Buzzer, PwmBuzzer
# Simple buzzer (on/off only)
buzzer = Buzzer()
# PWM buzzer (with pitch control)
pwm_buzzer = PwmBuzzer()Simple Buzzer:
| Method | Description |
|---|---|
buzz(duration=1.0) |
Beeps for the specified time (in seconds) |
setBuzz(True/False) |
Turns the buzzer on or off |
stop() |
Turns the buzzer off |
PWM Buzzer:
| Method | Description |
|---|---|
setFrequency(frequency) |
Changes the pitch (in Hz) |
setDutyCycle(duty_cycle) |
Changes the volume (0-100) |
buzz(duty_cycle=50) |
Starts the tone |
stop() |
Stops the tone |
buzzer = Buzzer()
buzzer.buzz(0.5) # Beeps for 0.5 seconds
# Or with PWM for melodies
pwm = PwmBuzzer()
pwm.setFrequency(440) # Note A4
pwm.buzz(50)
time.sleep(1)
pwm.stop()A sensor that measures the current temperature and humidity.
from JoyPiNoteBetterLib import HumidityTemperatureSensor
sensor = HumidityTemperatureSensor()| Method | Description | Returns |
|---|---|---|
getTemperature() |
Current temperature | float (in °C) |
getHumidity() |
Current humidity | float (in %) |
sensor = HumidityTemperatureSensor()
temperature = sensor.getTemperature()
humidity = sensor.getHumidity()
print(f"Temperature: {temperature:.1f}°C")
print(f"Humidity: {humidity:.1f}%")A control stick that can be moved in all directions.
from JoyPiNoteBetterLib import Joystick, Direction
joystick = Joystick()| Method | Description | Returns |
|---|---|---|
getX() |
X-axis position (left/right) | int (0-1023, center ~512) |
getY() |
Y-axis position (up/down) | int (0-1023, center ~512) |
getXY() |
Both values as tuple | (x, y) |
getDirection(do8Directions, threshold) |
Direction as enum | Direction |
Direction.CENTER- CenterDirection.N- Up (North)Direction.S- Down (South)Direction.E- Right (East)Direction.W- Left (West)Direction.NE, SE, SW, NW- Diagonals (only withdo8Directions=True)
joystick = Joystick()
while True:
direction = joystick.getDirection()
if direction == Direction.N:
print("Moving up")
elif direction == Direction.S:
print("Moving down")
elif direction == Direction.E:
print("Moving right")
elif direction == Direction.W:
print("Moving left")A 16x2 character LCD display for showing text.
from JoyPiNoteBetterLib import LcdDisplay, ScrollingLinesLcd
lcd = LcdDisplay()
# For auto-scrolling multiple messages per line
scroller = ScrollingLinesLcd()
# Or with existing LCD instance
scroller = ScrollingLinesLcd(lcdDisplay=lcd)LcdDisplay:
| Method | Description |
|---|---|
clear() |
Clears the entire screen |
displayMessage(text, line=0) |
Shows text on a line |
setBacklight(True/False) |
Backlight on/off |
setDisplay(True/False) |
Display on/off |
setCursor(True/False) |
Show/hide cursor |
setBlink(True/False) |
Cursor blinking on/off |
setCursorPosition(col, row) |
Set cursor position |
setColumnAlign(True/False) |
Column alignment on/off |
setDirection(True/False) |
Text direction (RTL/LTR) |
showBigText(text, delay=0.3) |
Long text with auto-scroll |
showFileContent(filePath, delay=0.3) |
Display file content with scrolling |
ScrollingLinesLcd:
| Method | Description |
|---|---|
show(messages, line, delay=None) |
Set messages for a line and start scrolling |
start() |
Start the scrolling animation |
stop(True) |
Stop the scrolling animation |
lcd = LcdDisplay()
lcd.clear()
lcd.displayMessage("Hello", 0) # Line 1
lcd.displayMessage("World", 1) # Line 2
# Auto-scroll long text
lcd.showBigText("This is a very long text that scrolls automatically")
# Scrolling multiple messages per line
scroller = ScrollingLinesLcd(lcd)
scroller.show(["Message 1", "Message 2", "Message 3"], line=0, delay=1.0)
scroller.show(["Line 2 A", "Line 2 B"], line=1)
# Stop scrolling
time.sleep(5)
scroller.stop()An 8x8 matrix with 64 colored LEDs (NeoPixel).
Important
Requires sudo to run!
from JoyPiNoteBetterLib import LedMatrix
matrix = LedMatrix()| Method | Description |
|---|---|
clear() |
Turns off all LEDs |
setAll(color) |
Fills all LEDs with a color |
setPixel(position, color) |
Sets a single pixel (0-63) |
setBrightness(brightness) |
Change brightness (0-255) |
showChar(char, color, offsetX, background) |
Shows a character |
showText(text, color, background) |
Shows text (first char on 8x8) |
scrollText(text, color, delay, loops, background) |
Scroll text across display |
update() |
Apply changes to matrix |
Colors are specified as RGB tuples: (Red, Green, Blue) with values 0-255.
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
WHITE = (255, 255, 255)matrix = LedMatrix(brightness=20)
# Set individual pixels
matrix.setPixel(0, (255, 0, 0)) # Red pixel at position 0
matrix.update()
# Show single character
matrix.showChar("A", (0, 255, 0))
# Scroll text
matrix.scrollText("Hello", (0, 255, 0), delay=0.1)
# Scroll text with loops and background color
matrix.scrollText("Hi", (255, 0, 0), delay=0.1, loops=2, background=(0, 0, 50))
# Turn everything off
matrix.clear()A sensor that measures the ambient brightness (in Lux) via I2C.
from JoyPiNoteBetterLib import LightSensor
sensor = LightSensor()| Method | Description | Returns |
|---|---|---|
readLight() |
Measures current brightness | float (in Lux) |
convertToNumber(data) |
Converts raw sensor data to lux | float (in Lux) |
sensor = LightSensor()
brightness = sensor.readLight()
print(f"Brightness: {brightness:.1f} Lux")
if brightness < 50:
print("It's dark")
else:
print("It's bright")A reader for NFC tags and RFID cards.
from JoyPiNoteBetterLib import NfcReader
nfc = NfcReader()| Method | Description | Returns |
|---|---|---|
read() |
Reads data from a tag | (id, text) or (None, None) |
write(text) |
Writes data to a tag | (id, text) or (None, None) |
waitForTag() |
Waits until a tag is detected | (id, text) |
nfc = NfcReader()
print("Hold an NFC tag to the reader...")
id, text = nfc.waitForTag()
print(f"Tag ID: {id}")
print(f"Stored text: {text}")
# Write text to tag
nfc.write("Hello NFC")An electrical switch for turning devices on/off.
from JoyPiNoteBetterLib import Relay
relay = Relay()| Method | Description |
|---|---|
turnOn() |
Turns the relay on |
turnOff() |
Turns the relay off |
relay = Relay()
relay.turnOn() # Turn device on
time.sleep(5)
relay.turnOff() # Turn device offA 4-digit 7-segment display for numbers and simple characters.
from JoyPiNoteBetterLib import Seg7x4
display = Seg7x4()| Method | Description |
|---|---|
setFull(value, decimal=0) |
Shows number/text on display |
set(position, value) |
Sets a single digit (0-3) |
showColon() |
Shows the colon |
clear() |
Clears the display |
setBrightness(0.0-1.0) |
Set brightness |
setBlinkRate(0-3) |
Set blink rate |
update() |
Apply changes to display |
display = Seg7x4()
# Show number
display.setFull(1234)
display.update()
# Show time (e.g., 12:30)
display.setFull(1230)
display.showColon()
display.update()
# Decimal number
display.setFull(3.14, decimal=2)
display.update()
# Set individual digits
display.set(0, '1')
display.set(1, '2')
display.set(2, '3')
display.set(3, '4')
display.update()A motor that can rotate to a specific angle (0-180°).
from JoyPiNoteBetterLib import Servomotor
servo = Servomotor(90) # Starting position at 90°| Method | Description |
|---|---|
setDirection(angle, speed) |
Rotates to the specified angle |
getDirection() |
Returns current angle |
startDirection: Initial angle position (0-180 degrees, required)angle: Target angle (0-180 degrees)speed: Step size (0 = single step, higher values = faster transitions)
servo = Servomotor(90) # Starts at center position
servo.setDirection(0, 5) # Rotates to 0° (slowly)
servo.setDirection(180, 10) # Rotates to 180° (faster)
servo.setDirection(90, 0) # Back to center (single-step movement)A sensor that detects when a sound is made.
from JoyPiNoteBetterLib import SoundSensor
sensor = SoundSensor()| Method | Description | Returns |
|---|---|---|
isSoundDetected() |
Checks if a sound is detected | True/False |
sensor = SoundSensor()
while True:
if sensor.isSoundDetected():
print("Sound detected")
time.sleep(0.1)A motor that can rotate precisely in small steps.
from JoyPiNoteBetterLib import Stepmotor
motor = Stepmotor()| Method | Description |
|---|---|
setSpeed(1-100) |
Set speed |
turnSteps(steps) |
Rotate by X steps (negative = reverse) |
turnDegrees(degrees) |
Rotate by X degrees |
turnDistance(distance, radius) |
Rotate for a distance (with wheel) |
release() |
Release coils (free rotation, no heat) |
motor = Stepmotor()
motor.setSpeed(50) # Medium speed
motor.turnDegrees(90) # 90° clockwise
motor.turnDegrees(-90) # 90° counter-clockwise
motor.turnSteps(512) # 512 steps forward
motor.release() # Release motor coilsA sensor that detects if the board is tilted.
from JoyPiNoteBetterLib import TiltSensor
sensor = TiltSensor()| Method | Description | Returns |
|---|---|---|
isTilted() |
Checks if the board is tilted | True/False |
sensor = TiltSensor()
while True:
if sensor.isTilted():
print("The board is tilted")
else:
print("The board is level")
time.sleep(0.5)A sensor that detects touch.
from JoyPiNoteBetterLib import TouchSensor
sensor = TouchSensor()| Method | Description | Returns |
|---|---|---|
isTouched() |
Checks if the sensor is being touched | True/False |
waitForTouch(interval) |
Waits for a touch | - (blocks) |
sensor = TouchSensor()
print("Touch the sensor...")
sensor.waitForTouch()
print("Touch detected")
# Or in a loop
while True:
if sensor.isTouched():
print("Touched")
time.sleep(0.1)A sensor that measures distance to objects (like a parking sensor).
from JoyPiNoteBetterLib import UltrasonicSensor
sensor = UltrasonicSensor()| Method | Description | Returns |
|---|---|---|
getDistance(timeout) |
Measures the distance | float (in cm) or -1.0 on timeout |
sendTriggerPulse() |
Send a trigger pulse to sensor | - |
waitForEcho(timeout) |
Wait for echo signal | True/False |
sensor = UltrasonicSensor()
while True:
distance = sensor.getDistance()
if distance == -1:
print("No object detected")
elif distance < 10:
print(f"Warning! Object only {distance:.1f} cm away")
else:
print(f"Distance: {distance:.1f} cm")
time.sleep(0.5)A small motor that produces vibrations (like in a phone).
from JoyPiNoteBetterLib import Vibrator, PwmVibrator
# Simple vibrator (on/off only)
vibrator = Vibrator()
# PWM vibrator (with intensity control)
pwm_vibrator = PwmVibrator()Simple Vibrator:
| Method | Description |
|---|---|
vibrate(duration=1.0) |
Vibrates for X seconds |
setVibrate(True/False) |
Vibration on/off |
PWM Vibrator:
| Method | Description |
|---|---|
setIntensity(0-100) |
Set vibration intensity |
stop() |
Stop vibration |
# Simple vibration
vibrator = Vibrator()
vibrator.vibrate(0.5) # Vibrate for 0.5 seconds
# With variable intensity
pwm = PwmVibrator()
pwm.setIntensity(30) # Light vibration
time.sleep(1)
pwm.setIntensity(100) # Strong vibration
time.sleep(1)
pwm.stop()Modules automatically clean up when the program ends. If you have issues, you can also manually call del {object}.
try:
sensor = UltrasonicSensor()
distance = sensor.getDistance()
except Exception as e:
print(f"Error: {e}")Some modules (e.g., LedMatrix) require root privileges:
sudo python3 my_script.py