{"id":15538808,"url":"https://github.com/Seeed-Studio/Seeed_Python_RPi","last_synced_at":"2025-05-08T08:31:42.885Z","repository":{"id":57465302,"uuid":"359735279","full_name":"Seeed-Studio/Seeed_Python_RPi","owner":"Seeed-Studio","description":"This is a Python library that facilitates the utilization of onboard hardware in Seeed's RPI series products.","archived":false,"fork":false,"pushed_at":"2025-01-08T08:31:26.000Z","size":17257,"stargazers_count":28,"open_issues_count":0,"forks_count":7,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-17T19:33:57.954Z","etag":null,"topics":["python","raspberrypi","reterminal","seeedstudio"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Seeed-Studio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-20T08:09:36.000Z","updated_at":"2025-01-13T06:24:06.000Z","dependencies_parsed_at":"2024-11-25T17:08:39.102Z","dependency_job_id":null,"html_url":"https://github.com/Seeed-Studio/Seeed_Python_RPi","commit_stats":{"total_commits":37,"total_committers":8,"mean_commits":4.625,"dds":0.7027027027027026,"last_synced_commit":"66a6132788fcfd1b249a1786d595ba903d412626"},"previous_names":["seeed-studio/seeed_python_rpi","seeed-studio/seeed_python_reterminal"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Seeed-Studio%2FSeeed_Python_RPi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Seeed-Studio%2FSeeed_Python_RPi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Seeed-Studio%2FSeeed_Python_RPi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Seeed-Studio%2FSeeed_Python_RPi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Seeed-Studio","download_url":"https://codeload.github.com/Seeed-Studio/Seeed_Python_RPi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253029043,"owners_count":21843011,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","raspberrypi","reterminal","seeedstudio"],"created_at":"2024-10-02T12:06:23.459Z","updated_at":"2025-05-08T08:31:42.868Z","avatar_url":"https://github.com/Seeed-Studio.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python library for Seeed RPi board\n\nThis is a Python library specifically designed for Seeed's RPi boards, enabling you to utilize the onboard hardware features.  Currently, the accelerometer, user LEDs, user buttons, and buzzer can be accessed and controlled using this library on Seeed's RPi boards.  Additionally, if your board supports features like a fan, RS232, RS485, or CAN, this library provides the necessary interfaces to interact with them as well.\n\n## Installation\n\n### From PyPI\n\n- To install the latest release from PyPI\n```\nsudo pip3 install seeed-python-rpi\n```\n\n### From Source\n\n- To install from source, clone this repository\n```\ngit clone https://github.com/Seeed-Studio/Seeed_Python_RPi\n```\n\n- Install the library \n\n```\ncd Seeed_Python_rpi\nsudo pip3 install .\n```\n\n## Usage\n\n### User LEDs Test\n\n```python\nimport seeed_python_rpi.core as rt\nimport time\n\nprint(\"STA ON, USR OFF\")\nrt.sta_led = True\nrt.usr_led = False\ntime.sleep(1)\n\nprint(\"STA OFF, USR ON\")\nrt.sta_led = False\nrt.usr_led = True\ntime.sleep(1)\n\nprint(\"STA RED, USR OFF\")\nrt.sta_led_green = False\nrt.sta_led_red = True\nrt.usr_led = False\ntime.sleep(1)\n\nprint(\"STA OFF, USR OFF\")\nrt.sta_led = False\nrt.usr_led = False\n```\n\n### Buzzer Test\n\n```python\nimport seeed_python_rpi.core as rt\nimport time\n\nprint(\"BUZZER ON\")\nrt.buzzer = True\ntime.sleep(1)\n\nprint(\"BUZZER OFF\")\nrt.buzzer = False\n```\n\n### User Buttons Test\n\n```python\nimport seeed_python_rpi.core as rt\nimport seeed_python_rpi.button as rt_btn\n\n\ndevice = rt.get_button_device()\nwhile True:\n    for event in device.read_loop():\n        buttonEvent = rt_btn.ButtonEvent(event)\n        if buttonEvent.name != None:\n            print(f\"name={str(buttonEvent.name)} value={buttonEvent.value}\")\n```\n\n### Accelerometer Test\n\n```python\nimport seeed_python_rpi.core as rt\nimport seeed_python_rpi.acceleration as rt_accel\n\n\ndevice = rt.get_acceleration_device()\nwhile True:\n    for event in device.read_loop():\n        accelEvent = rt_accel.AccelerationEvent(event)\n        if accelEvent.name != None:\n            print(f\"name={str(accelEvent.name)} value={accelEvent.value}\")\n```\n\n### Accelerometer and Buttons Test\n\n```python\nimport asyncio\nimport seeed_python_rpi.core as rt\nimport seeed_python_rpi.acceleration as rt_accel\nimport seeed_python_rpi.button as rt_btn\n\n\nasync def accel_coroutine(device):\n    async for event in device.async_read_loop():\n        accelEvent = rt_accel.AccelerationEvent(event)\n        if accelEvent.name != None:\n            print(f\"accel name={str(accelEvent.name)} value={accelEvent.value}\")\n\n\nasync def btn_coroutine(device):\n    async for event in device.async_read_loop():\n        buttonEvent = rt_btn.ButtonEvent(event)\n        if buttonEvent.name != None:\n            print(f\"name={str(buttonEvent.name)} value={buttonEvent.value}\")\n\n\naccel_device = rt.get_acceleration_device()\nbtn_device = rt.get_button_device()\n\nasyncio.ensure_future(accel_coroutine(accel_device))\nasyncio.ensure_future(btn_coroutine(btn_device))\n\nloop = asyncio.get_event_loop()\nloop.run_forever()\n```\n\n### Illuminance Sensor Test\n```python\nimport time\nimport seeed_python_rpi.core as rt\n\nwhile True:\n    print(rt.illuminance)\n    time.sleep(0.2)\n```\n\n**The Following Test Should Work With Reterminal Bridge**\n\n### fan Test\n\n```python\nimport seeed_python_rpi.core as rt\nimport time\n\nprint(\"FAN ON\")\nrt.fan = True\ntime.sleep(1)\n\nprint(\"FAN OFF\")\nrt.fan = False\n```\n\n### RS232 Test\n\n```python\nimport sys\nimport serial\nimport time\nimport seeed_python_rpi.core as rt\n\nparam1 = sys.argv[1]\n\n# enable the rs232 for test\nrt.rs232_or_rs485 = \"RS232\"\n\n# init the serial\nser = serial.Serial(\n    port='/dev/ttyS0',\n    baudrate = 9600,\n    parity=serial.PARITY_NONE,\n    stopbits=serial.STOPBITS_ONE,\n    bytesize=serial.EIGHTBITS,\n    timeout=1\n)\n\nif param1 == \"send\":\n    counter=0\n    try:\n        print(\"rs232 starts now!\\n\")\n        ser.write(\"rs232 starts now!\\n\".encode())\n        while 1:\n                ser.write((\"Write counter:{}\\n\".format(counter)).encode())\n                time.sleep(1)\n                counter += 1\n    except KeyboardInterrupt:\n        exit()\nelif param1 == \"receive\":\n    try:\n        print(\"Start receiving data now!\\n\")\n        while 1:\n            x=ser.readline()\n            if x != b'':\n                print(x)\n    except KeyboardInterrupt:\n        exit()\nelse:\n    print('param input error,try again with send or receive')\n```\n**Note:**:When we use the test script of RS232/RS485/CAN.We need to pass a parameter to them.\n\nTake the RS232 for example:\n```\npython3 test_rs232.py send # test the send(TX) function of RS232\npython3 test_rs232.py receive # test the receive(RX) function of RS232\n```\n\n### RS485 Test\n\n```python\nimport sys\nimport serial\nimport time\nimport seeed_python_rpi.core as rt\n\nparam1 = sys.argv[1]\n\n# enable the rs485 for test\nrt.rs232_or_rs485 = \"RS485\"\n\n# init the serial\nser = serial.Serial(\n    port='/dev/ttyS0',\n    baudrate = 9600,\n    parity=serial.PARITY_NONE,\n    stopbits=serial.STOPBITS_ONE,\n    bytesize=serial.EIGHTBITS,\n    timeout=1\n)\n\nif param1 == \"send\":\n    counter=0\n    # enable the rs485 for tx\n    rt.rs485_tx_rx_stat = \"TX\"\n    try:\n        print(\"rs485 starts now!\\n\")\n        ser.write(\"rs485 starts now!\\n\".encode())\n        while 1:\n                ser.write((\"Write counter:{}\\n\".format(counter)).encode())\n                time.sleep(1)\n                counter += 1\n    except KeyboardInterrupt:\n        exit()\nelif param1 == \"receive\":\n    # enable the rs485 for rx\n    rt.rs485_tx_rx_stat = \"RX\"\n    try:\n        print(\"Start receiving data now!\\n\")\n        while 1:\n            x=ser.readline()\n            if x != b'':\n                print(x)\n    except KeyboardInterrupt:\n        exit()\nelse:\n    print('param input error,try again with send or receive')\n```\n\n### CAN Test\n\n```python\n# NOTICE: please make sure you have pip3 install python-can\n#         before you use this test script\n# import the library\nimport can\nimport sys\nimport time\n\nparam1 = sys.argv[1]\n\n# create a bus instance\n# many other interfaces are supported as well (see documentation)\nbus = can.Bus(interface='socketcan',\n              channel='can0',\n              receive_own_messages=True)\n\nif param1 == \"send\":\n    # send a message\n    counter=0\n    print(\"can send starts now!\\n\")\n    try:\n        while True:\n            message = can.Message(arbitration_id=123, is_extended_id=True,\n                      data=[0x11, 0x22, counter])\n            bus.send(message, timeout=0.2)\n            time.sleep(1)\n            counter += 1\n    except KeyboardInterrupt:\n        exit()\n\nelif param1 == \"receive\":\n    # iterate over received messages\n    try:\n        for msg in bus:\n            print(f\"{msg.arbitration_id:X}: {msg.data}\")\n    except KeyboardInterrupt:\n        exit()\nelse:\n    print('param input error,try again with send or receive')\n```\n**Note:** Please make sure your CAN interface is working before run this script.\nIf not. You will get the error log with \"Network is down\". And you can \nenable the can with \"sudo ip link set can0 up type can bitrate 500000\".\n\n## API Reference\n\n- **usr_led**: Turn on/off green USR LED\n\n```python\nrt.usr_led = True #Turn on green USR LED\nrt.usr_led = False #Turn off green USR LED\n```\n\n- **sta_led_red**: Turn on/off red STA LED\n\n```python\nrt.sta_led_red = True #Turn on red STA LED\nrt.sta_led_red = False #Turn off red STA LED\n```\n\n- **sta_led_green**: Turn on/off green STA LED\n\n```python\nrt.sta_led_green = True #Turn on green STA LED\nrt.sta_led_green = False #Turn off green STA LED\n```\n\n**Note:** If red STA LED is on during this time, the green STA LED will turn on over the red STA LED\n\n- **sta_led**: Turn on/off green STA LED\n\n```python\nrt.sta_led = True #Turn on green STA LED\nrt.sta_led = False #Turn off green STA LED\n```\n\n**Note:** If red STA LED is on during this time, the green STA LED will turn on and the red STA LED will turn off\n\n- **buzzer** : Turn on/off buzzer\n\n```python\nrt.buzzer = True #Turn on buzzer\nrt.buzzer = False #Turn off buzzer\n```\n\n- **get_button_device()**: Obtain information about the buttons including all the events supported by them\n\n```python\ndevice = rt.get_button_device()\n```\n\n- **ButtonEvent()**: Calls the ButtonEvent() and returns the EVENT\n\n```python\nbuttonEvent = rt_btn.ButtonEvent(event)\n```\n\n- **get_acceleration_device()**: Obtain information about the accelerometer including all the events supported by it \n\n```python\ndevice = rt.get_acceleration_device()\n```\n\n- **AccelerationEvent()**: Calls the AccelerationEvent() and returns the EVENT\n\n```python\naccelEvent = rt_accel.AccelerationEvent(event)\n```\n\n- **Illuminance** :Obtain the current value from the illuminance sensor\n```python\nilluminance = rt.illuminance\n```\n\n- **fan**: Turn on/off fan\n\n```python\nrt.fan = True # Turn on fan\nrt.fan = False # Turn off fan\n```\n\n- **rs232_or_rs485**: Open the RS232 or RS485\n\n```python\nrt.rs232_or_rs485 = \"RS232\" # open the RS232\nrt.rs232_or_rs485 = \"RS485\" # open the RS485\n```\n\n- **rs485_tx_rx_stat**: Switch the function between send(TX) and receive(Rx) of RS485\n\n```python\nrt.rs485_tx_rx_stat = \"TX\" # enable the send(TX) of RS485\nrt.rs485_tx_rx_stat = \"RX\" # enable the receive(RX) of RS485\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSeeed-Studio%2FSeeed_Python_RPi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSeeed-Studio%2FSeeed_Python_RPi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSeeed-Studio%2FSeeed_Python_RPi/lists"}