Skip to content

Hardware Interface Examples

Serial Hardware Query Example

examples/hardware/serial_query.py
1
2
3
4
5
from pprint import pprint

from kevinbotlib.hardware.interfaces.serial import SerialIdentification

pprint(SerialIdentification.list_device_info())

Serial Raw Ping/Pong Example

Example

Image title

This example requires a serial device responding to pings to be connected.

You can make one using the Ping Pong Test Gadget

The test gadget can be flashed to most PlatformIO compatible devices.

examples/hardware/serial_raw_ping_pong.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import time

from kevinbotlib.hardware.interfaces.serial import RawSerialInterface

# ! remember to change these settings for your testing environment
gadget = RawSerialInterface(None, "/dev/ttyUSB0", 9600)
# gadget.open() # * not needed if a port is provided above ^

while True:
    gadget.write(b"ping\n")
    print("Sent ping, waiting for pong...")

    while True:
        line = gadget.readline().decode("utf-8").rstrip()
        if line == "pong":
            print("Got pong")
            break

    time.sleep(1)

  1. Arduino Nano image modified from an original image by MakeMagazinDE, licensed under CC BY-SA 4.0 (link).