{"id":30555439,"url":"https://github.com/pezi/dart_periphery","last_synced_at":"2025-08-28T05:06:22.927Z","repository":{"id":42019753,"uuid":"336706648","full_name":"pezi/dart_periphery","owner":"pezi","description":"dart_periphery is a Dart port of the native c-periphery library","archived":false,"fork":false,"pushed_at":"2025-08-05T17:55:35.000Z","size":10879,"stargazers_count":47,"open_issues_count":7,"forks_count":12,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-19T13:20:35.509Z","etag":null,"topics":["flutter","raspberry-pi"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pezi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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},"funding":{"github":"pezi","buy_me_a_coffe":"wechselkrov"}},"created_at":"2021-02-07T05:14:50.000Z","updated_at":"2025-04-18T01:41:45.000Z","dependencies_parsed_at":"2024-04-03T09:25:35.803Z","dependency_job_id":"becf00c3-60a4-413e-ac32-1c8149c6dea1","html_url":"https://github.com/pezi/dart_periphery","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/pezi/dart_periphery","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pezi%2Fdart_periphery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pezi%2Fdart_periphery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pezi%2Fdart_periphery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pezi%2Fdart_periphery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pezi","download_url":"https://codeload.github.com/pezi/dart_periphery/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pezi%2Fdart_periphery/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272442806,"owners_count":24935845,"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","status":"online","status_checked_at":"2025-08-28T02:00:10.768Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["flutter","raspberry-pi"],"created_at":"2025-08-28T05:02:55.279Z","updated_at":"2025-08-28T05:06:22.917Z","avatar_url":"https://github.com/pezi.png","language":"Dart","funding_links":["https://github.com/sponsors/pezi","wechselkrov"],"categories":[],"sub_categories":[],"readme":"\n# dart_periphery\n\n![alt text](https://raw.githubusercontent.com/pezi/dart_periphery_img/main/header.jpg \"Title\")\n\n[![pub package](https://img.shields.io/badge/pub-v0.9.18-orange)](https://pub.dartlang.org/packages/dart_periphery)\n[![Pub Points](https://img.shields.io/pub/points/dart_periphery)](https://pub.dev/packages/dart_periphery/score)\n[![All Contributors](https://img.shields.io/github/contributors/pezi/dart_periphery)](https://github.com/pezi/dart_periphery/graphs/contributors)\n[![BSD License](https://img.shields.io/github/license/pezi/dart_periphery)](https://opensource.org/license/bsd-3-clause)\n\n## 📣 Important hints\n\nAdded RISC-V support, thanks to [Ali Tariq](https://github.com/alitariq4589) from [10xEngineers](https://10xEngineers.ai) for providing remote access to a Banana Pi BPI-F3 16GB on [Cloud-V](https://cloud-v.co), which enabled building the RISC-V variant of the c-periphery library.\n\nThe repository’s [Wiki](https://github.com/pezi/dart_periphery/wiki) is now enabled.\n\n## 📖 Introduction\n\n**dart_periphery** is a Dart port of the native [c-periphery library](https://github.com/vsergeev/c-periphery) (v2.4.3) \nfor Linux Peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO and Serial peripheral I/O). This package \nis designed for System on Chips (SoCs) such as Raspberry Pi, NanoPi, Banana Pi, and others.\n\n### What is c-periphery?\n\nAbstract from the project web site:\n\n\u003ec-periphery is a small C library for\n\u003e\n\u003e* GPIO,\n\u003e* LED,\n\u003e* PWM,\n\u003e* SPI,\n\u003e* I2C,\n\u003e* MMIO (Memory Mapped I/O)\n\u003e* Serial peripheral I/O\n\u003e\n\u003einterface access in userspace Linux. c-periphery simplifies and consolidates the native Linux APIs to these interfaces. c-periphery is useful in embedded Linux environments (including Raspberry Pi, BeagleBone, etc. platforms) for interfacing with external peripherals. c-periphery is re-entrant, has no dependencies outside the standard C library and Linux, compiles into a static library for easy integration with other projects, and is MIT licensed\n\n**dart_periphery** binds the c-periphery library with the help of the [dart:ffi](https://dart.dev/guides/libraries/c-interop) mechanism. \nNevertheless, **dart_periphery** tries to be close as possible to the original library. \nSee the following [documentation](https://github.com/vsergeev/c-periphery/tree/master/docs). Thanks to **Vanya Sergeev** for his great job!\n\n## 🤔 Why c-periphery?\n\nThe number of GPIO libraries/interfaces is shrinking:\n\n* The widely used wiringpi library is [deprecated](https://hackaday.com/2019/09/18/wiringpi-library-to-be-deprecated).\n* GPIO sysfs is [deprecated](https://www.raspberrypi.org/forums/viewtopic.php?t=274416).\n\n**dart_periphery**\n\n* [GPIO](#gpio) example / [API](https://pub.dev/documentation/dart_periphery/latest/dart_periphery/GPIO-class.html)\n* [I2C](#i2c) example / [API](https://pub.dev/documentation/dart_periphery/latest/dart_periphery/I2C-class.html)\n* [SPI](#spi) example / [API](https://pub.dev/documentation/dart_periphery/latest/dart_periphery/SPI-class.html)\n* [Serial](#serial) example / [API](https://pub.dev/documentation/dart_periphery/latest/dart_periphery/Serial-class.html)\n* [PWM](#pwm) example / [API](https://pub.dev/documentation/dart_periphery/latest/dart_periphery/PWM-class.html)\n* [Led](#led) (onboard leds) example / [API](https://pub.dev/documentation/dart_periphery/latest/dart_periphery/Led-class.html)\n* [MMIO](#mmio) (Memory Mapped I/O) example / [API](https://pub.dev/documentation/dart_periphery/latest/dart_periphery/MMIO-class.html)\n* [ADC](#adc) (Analog Digital Converter) example / [API-Grove](https://pub.dev/documentation/dart_periphery/latest/dart_periphery/GroveBaseHat-class.html), [API-NanoHatHub](https://pub.dev/documentation/dart_periphery/latest/dart_periphery/NanoHatHub-class.html), [PCF8591](https://github.com/pezi/dart_periphery/blob/main/example/i2c_pcf8591.dart)\n* DAC (Digital Analog Converter) example / [PCF8591](https://github.com/pezi/dart_periphery/blob/main/example/i2c_pcf8591.dart)\n\n\n## 🪧 Examples\n\n### GPIO\n\n![alt text](https://raw.githubusercontent.com/pezi/dart_periphery_img/main/pi.jpg \"Led demo\")\n\n``` dart\nimport 'package:dart_periphery/dart_periphery.dart';\nimport 'dart:io';\n\nvoid main() {\n  var config = GPIOconfig();\n  config.direction = GPIOdirection.gpioDirOut;\n  print('Native c-periphery Version :  ${getCperipheryVersion()}');\n  print('GPIO test');\n  var gpio = GPIO(18, GPIOdirection.gpioDirOut);\n  var gpio2 = GPIO(16, GPIOdirection.gpioDirOut);\n  var gpio3 = GPIO.advanced(5, config);\n\n  print('GPIO info: ' + gpio.getGPIOinfo());\n\n  print('GPIO native file handle: ${gpio.getGPIOfd()}');\n  print('GPIO chip name: ${gpio.getGPIOchipName()}');\n  print('GPIO chip label: ${gpio.getGPIOchipLabel()}');\n  print('GPIO chip name: ${gpio.getGPIOchipName()}');\n  print('GPIO chip label: ${gpio.getGPIOchipLabel()}');\n\n  for (var i = 0; i \u003c 10; ++i) {\n    gpio.write(true);\n    gpio2.write(true);\n    gpio3.write(true);\n    sleep(Duration(milliseconds: 200));\n    gpio.write(false);\n    gpio2.write(false);\n    gpio3.write(false);\n    sleep(Duration(milliseconds: 200));\n  }\n\n  gpio.dispose();\n  gpio2.dispose();\n  gpio3.dispose();\n}\n\n```\n\n### I2C\n\n![alt text](https://raw.githubusercontent.com/pezi/dart_periphery_img/main/bme280.jpg \"BME280 Sensor\")\n\n``` dart\nimport 'package:dart_periphery/dart_periphery.dart';\n\n/// https://wiki.seeedstudio.com/Grove-Barometer_Sensor-BME280/\n/// Grove - Temp\u0026Humi\u0026Barometer Sensor (BME280) is a breakout board for Bosch BMP280 high-precision,\n/// low-power combined humidity, pressure, and temperature sensor.\nvoid main() {\n  // Select the right I2C bus number /dev/i2c-?\n  // 1 for Raspbery Pi, 0 for NanoPi (Armbian), 2 Banana Pi (Armbian)\n  var i2c = I2C(1);\n  try {\n    print('I2C info:' + i2c.getI2Cinfo());\n    var bme280 = BME280(i2c);\n    var r = bme280.getValues();\n    print('Temperature [°] ${r.temperature.toStringAsFixed(1)}');\n    print('Humidity [%] ${r.humidity.toStringAsFixed(1)}');\n    print('Pressure [hPa] ${r.pressure.toStringAsFixed(1)}');\n  } finally {\n    i2c.dispose();\n  }\n}\n\n```\n\n___\n\n![alt text](https://raw.githubusercontent.com/pezi/dart_periphery_img/main/sht31.jpg \"SHT31 Sensor\")\n\n``` dart\nimport 'package:dart_periphery/dart_periphery.dart';\n\n/// Grove - Temp\u0026Humi Sensor(SHT31) is a highly reliable, accurate,\n/// quick response and integrated temperature \u0026 humidity sensor.\nvoid main() {\n  // Select the right I2C bus number /dev/i2c-?\n  // 1 for Raspbery Pi, 0 for NanoPi (Armbian), 2 Banana Pi (Armbian)\n  var i2c = I2C(1);\n  try {\n    var sht31 = SHT31(i2c);\n    print(sht31.getStatus());\n    print('Serial number ${sht31.getSerialNumber()}');\n    print('Sensor heater active: ${sht31.isHeaterOn()}');\n    var r = sht31.getValues();\n    print('SHT31 [t°] ${r.temperature.toStringAsFixed(2)}');\n    print('SHT31 [%°] ${r.humidity.toStringAsFixed(2)}');\n  } finally {\n    i2c.dispose();\n  }\n}\n```\n\n### SPI\n\n![alt text](https://raw.githubusercontent.com/pezi/dart_periphery_img/main/bme280_spi.jpg \"BME280 SPI Sensor\")\n\n``` dart\nimport 'package:dart_periphery/dart_periphery.dart';\n\nvoid main() {\n  var spi = SPI(0, 0, SPImode.mode0, 1000000);\n  try {\n    print('SPI info:' + spi.getSPIinfo());\n    var bme280 = BME280.spi(spi);\n    var r = bme280.getValues();\n    print('Temperature [°] ${r.temperature.toStringAsFixed(1)}');\n    print('Humidity [%] ${r.humidity.toStringAsFixed(1)}');\n    print('Pressure [hPa] ${r.pressure.toStringAsFixed(1)}');\n  } finally {\n    spi.dispose();\n  }\n}\n````\n\n### Serial\n\n![alt text](https://raw.githubusercontent.com/pezi/dart_periphery_img/main/cozir.jpg \"CozIR Sensor\")\n\n``` dart\nimport 'package:dart_periphery/dart_periphery.dart';\nimport 'dart:io';\n\n///\n/// [COZIR CO2 Sensor](https://co2meters.com/Documentation/Manuals/Manual_GC_0024_0025_0026_Revised8.pdf)\n///\nvoid main() {\n  print('Serial test - COZIR CO2 Sensor');\n  var s = Serial('/dev/serial0', Baudrate.b9600);\n  try {\n    print('Serial interface info: ' + s.getSerialInfo());\n\n    // Return firmware version and sensor serial number - two lines\n    s.writeString('Y\\r\\n');\n    var event = s.read(256, 1000);\n    print(event.toString());\n\n    // Request temperature, humidity and CO2 level.\n    s.writeString('M 4164\\r\\n');\n    // Select polling mode\n    s.writeString('K 2\\r\\n');\n    // print any response\n    event = s.read(256, 1000);\n    print('Response ${event.toString()}');\n    sleep(Duration(seconds: 1));\n    for (var i = 0; i \u003c 5; ++i) {\n      s.writeString('Q\\r\\n');\n      event = s.read(256, 1000);\n      print(event.toString());\n      sleep(Duration(seconds: 5));\n    }\n  } finally {\n    s.dispose();\n  }\n}\n```\n\n### Led\n\n![alt text](https://raw.githubusercontent.com/pezi/dart_periphery_img/main/led.jpg \"Power led\")\n\n``` dart\nimport 'package:dart_periphery/dart_periphery.dart';\nimport 'dart:io';\n\nvoid main() {\n  /// Nano Pi power led - see 'ls /sys/class/leds/'\n  var led = Led('nanopi:red:pwr');\n  try {\n    print('Led handle: ${led.getLedInfo()}');\n    print('Led name: ${led.getLedName()}');\n    print('Led brightness: ${led.getBrightness()}');\n    print('Led maximum brightness: ${led.getMaxBrightness()}');\n    var inverse = !led.read();\n    print('Original led status: ${(!inverse)}');\n    print('Toggle led');\n    led.write(inverse);\n    sleep(Duration(seconds: 5));\n    inverse = !inverse;\n    print('Toggle led');\n    led.write(inverse);\n    sleep(Duration(seconds: 5));\n    print('Toggle led');\n    inverse = !inverse;\n    led.write(inverse);\n    sleep(Duration(seconds: 5));\n    print('Toggle led');\n    led.write(!inverse);\n  } finally {\n    led.dispose();\n  }\n}\n\n```\n\n### PWM\n\nEnsure that PWM is correctly enabled. e.g. see the following [documentation](https://github.com/dotnet/iot/blob/main/Documentation/raspi-pwm.md) for the Raspberry Pi.\n\n``` dart\nimport 'package:dart_periphery/dart_periphery.dart';\nimport 'dart:io';\n\nvoid main() {\n  var pwm = PWM(0, 0);\n  try {\n    print(pwm.getPWMinfo());\n    pwm.setPeriodNs(10000000);\n    pwm.setDutyCycleNs(8000000);\n    print(pwm.getPeriodNs());\n    pwm.enable();\n    print(\"Wait 20 seconds\");\n    sleep(Duration(seconds: 20));\n    pwm.disable();\n  } finally {\n    pwm.dispose();\n  }\n}\n```\n\n### MMIO\n\n**Memory Mapped I/O**: Turns on a led at pin 18 on a Raspberry Pi using MMIO. This direct register \naccess example is derived from [elinux.org](https://elinux.org/RPi_GPIO_Code_Samples#Direct_register_access).\n\n``` dart\nimport 'package:dart_periphery/dart_periphery.dart';\nimport 'dart:io';\n\nconst int bcm2708PeriBase = 0x3F000000; // Raspberry Pi 3\nconst int gpioBase = bcm2708PeriBase + 0x200000;\nconst int blockSize = 4 * 1024;\n\nclass MemMappedGPIO {\n  MMIO mmio;\n  MemMappedGPIO(this.mmio);\n\n  // #define INP_GPIO(g) *(gpio+((g)/10)) \u0026= ~(7\u003c\u003c(((g)%10)*3))\n  void setPinInput(final int pin) {\n    var offset = (pin ~/ 10) * 4;\n    var value = mmio[offset];\n    value \u0026= (~(7 \u003c\u003c (((pin) % 10) * 3)));\n    mmio[offset] = value;\n  }\n\n  // #define OUT_GPIO(g) *(gpio+((g)/10)) |=  (1\u003c\u003c(((g)%10)*3))\n  void setPinOutput(final int pin) {\n    setPinInput(pin);\n    var offset = (pin ~/ 10) * 4;\n    var value = mmio[offset];\n    value |= (1 \u003c\u003c (((pin) % 10) * 3));\n    mmio[offset] = value;\n  }\n\n  // #define GPIO_SET *(gpio+7) - sets   bits which are 1 ignores bits which are 0\n  void setPinHigh(int pin) {\n    mmio[7 * 4] = 1 \u003c\u003c pin;\n  }\n\n  // #define GPIO_CLR *(gpio+10) - clears bits which are 1 ignores bits which are 0\n  void setPinLow(int pin) {\n    mmio[10 * 4] = 1 \u003c\u003c pin;\n  }\n\n  // #define GET_GPIO(g) (*(gpio+13)\u0026(1\u003c\u003cg)) - 0 if LOW, (1\u003c\u003cg) if HIGH\n  int getPin(int pin) {\n    return mmio[13 * 4] \u0026 (1 \u003c\u003c pin);\n  }\n}\n\nvoid main() {\n  // Needs root rights and the gpioBase must be correct!\n  // var mmio = MMIO(gpioBase, blockSize);\n  var mmio = MMIO.advanced(0, blockSize, '/dev/gpiomem');\n  var gpio = MemMappedGPIO(mmio);\n  try {\n    print(mmio.getMMIOinfo());\n    var pin = 18;\n    print('Led (pin=18) on');\n    gpio.setPinOutput(pin);\n    gpio.setPinHigh(pin);\n    sleep(Duration(seconds: 10));\n    gpio.setPinLow(pin);\n    print('Led (pin=18) off');\n  } finally {\n    mmio.dispose();\n  }\n}\n```\n\n### ADC\n\n![alt text](https://raw.githubusercontent.com/pezi/dart_periphery_img/main/hat_adc_demo.jpg \"Extension hat - ADC\") \n\nExtension hats, such as the [Grove Base Hat RaspberryPi Zero](https://wiki.seeedstudio.com/Grove_Base_Hat_for_Raspberry_Pi_Zero), add additional functionality like ADC (Analog-to-Digital Converter) support. See also complete [example](https://github.com/pezi/dart_periphery/blob/main/example/extension_hats/hat_light_sensor_led.dart) with support for FriendlyElec [NanoHat Hub](https://wiki.friendlyelec.com/wiki/index.php/BakeBit_-_NanoHat_Hub)\nand [Grove Base Hat RaspberryPi](https://www.seeedstudio.com/Grove-Base-Hat-for-Raspberry-Pi.html). \n\nIn this demo, the LED turns on when the value of the light sensor falls below a certain threshold.\n\n``` dart\nimport 'package:dart_periphery/dart_periphery.dart';\nimport 'dart:io';\n\nconst wait = 150;\nconst threshold = 100;\n\n/// https://wiki.seeedstudio.com/Grove-Light_Sensor/ \n/// https://www.seeedstudio.com/Grove-Base-Hat-for-Raspberry-Pi.html\n/// https://wiki.seeedstudio.com/Grove_Base_Hat_for_Raspberry_Pi_Zero\nvoid main() {\n  const analogPin = 0;\n  const ledPin = 16;\n\n  var hat = GroveBaseHat();\n  print(hat.getFirmware());\n  print(hat.getName());\n  print(\"Analog pin: $analogPin\");\n  print(\"Led pin: $ledPin\");\n\n  var led = GPIO(ledPin, GPIOdirection.gpioDirOut);\n  led.write(false);\n\n  bool ledStatus = false;\n\n  while (true) {\n    var value = hat.readADCraw(analogPin);\n    if (value \u003c threshold) {\n      if (!ledStatus) {\n        ledStatus = true;\n        led.write(true);\n      }\n    } else {\n      if (ledStatus) {\n        ledStatus = false;\n        led.write(false);\n      }\n    }\n    sleep(Duration(milliseconds: wait));\n  }\n}\n```\n\n## 🏗 Install Dart on Raspbian and Armbian\n\n1.) Navigate to the home directory:\n\n``` bash\ncd ~\n```\n\n2.) Download the last stable Dart SDK from [archive](https://dart.dev/tools/sdk/archive) for your CPU architecture/OS and unzip it.\n\n### arm\n\n``` bash\nwget https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.0/sdk/dartsdk-linux-arm-release.zip\nunzip dartsdk-linux-arm-release.zip\n```\n\n### arm64\n\n``` bash\nwget https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.0/sdk/dartsdk-linux-arm64-release.zip\nunzip dartsdk-linux-arm64-release.zip\n```\n\n### IA32\n\n``` bash\nwget https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.0/sdk/dartsdk-linux-ia32-release.zip\nunzip dartsdk-linux-ia32-release.zip\n```\n\n### X64\n\n``` bash\nwget https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.0/sdk/dartsdk-linux-x64-release.zip\nunzip dartsdk-linux-x64-release.zip\n```\n\n### RISC-V (RV64GC)\n\n``` bash\nwget https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.0/sdk/dartsdk-linux-riscv64-release.zip\nunzip dartsdk-linux-riscv64-release.zip\n```\n\n3.) Move and grant the appropriate permissions to the SDK:\n\n``` bash\nsudo mv dart-sdk /opt/\nsudo chmod -R +rx /opt/dart-sdk\n```\n\n4.) Add Dart SDK to the path by editing `~/.profile` and then apply the changes:\n\n``` bash\nnano ~/.profile\n```\n\nfollowing command\n\n``` bash\nexport PATH=$PATH:/opt/dart-sdk/bin\n```\n\nat the end of the file and call\n\n``` bash\nsource ~/.profile\n```\n\nafter editing to apply the changes.\n\nTest the installation\n\n``` bash\ndart --version\nDart SDK version: 3.7.0 (stable) (Wed Feb 5 04:53:58 2025 -0800) on \"linux_riscv64\"\n```\n\n## 📚 Native libraries\n\n**dart_periphery** includes prebuilt native c-periphery libraries for\n\n* [Abi.linuxArm](https://api.flutter.dev/flutter/dart-ffi/Abi/linuxArm-constant.html) - [libperiphery_arm.so](https://github.com/pezi/dart_periphery/raw/main/lib/src/native/libperiphery_arm.so)\n* [Abi.linuxArm64](https://api.flutter.dev/flutter/dart-ffi/Abi/linuxArm64-constant.html) - [libperiphery_arm64.so](https://github.com/pezi/dart_periphery/raw/main/lib/src/native/libperiphery_arm64.so)\n* [Abi.linuxIA32](https://api.flutter.dev/flutter/dart-ffi/Abi/linuxIA32-constant.html) - [libperiphery_ia32.so](https://github.com/pezi/dart_periphery/raw/main/lib/src/native/libperiphery_ia32.so)\n* [Abi.linuxX64](https://api.flutter.dev/flutter/dart-ffi/Abi/linuxX64-constant.html) - [libperiphery_x64.so](https://github.com/pezi/dart_periphery/raw/main/lib/src/native/libperiphery_x64.so)\n* [Abi.linuxRiscv64](https://api.flutter.dev/flutter/dart-ffi/Abi/linuxRiscv64-constant.html)  - [libperiphery_riscv64.so](https://github.com/pezi/dart_periphery/raw/main/lib/src/native/libperiphery_riscv64.so)\n\n**Important hint:** **dart_periphery** includes an automatic mechanism to load the correct library. \n\n\nThe additional methods described here can be used to override this default mechanism if needed.\nBut be aware, any of these methods to disable or change the behaviour the auto detection must be \ncalled before any **dart_periphery** interface is used!\n\n``` dart\n/// Sets the tmp directory for the extraction of the libperiphery.so file.\nvoid setTempDirectory(String tmpDir)\n\n/// Allows to load an existing libperiphery.so file from tmp directory. \nvoid reuseTmpFileLibrary(bool reuse)\n```\n\n``` dart\n/// loads the shared library \n/// export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH\nuseSharedLibrary(); \n```\nIf this method is called, **dart_periphery** loads the shared library. For this case c-periphery \nmust be installed as a shared library. See the [section Shared Library](https://github.com/vsergeev/c-periphery#shared-library) for details.\n\nTo load a custom library call following method\n\n``` dart\nvoid setCustomLibrary(String absolutePath)\n```\nThis method can also be helpful for a currently not supported platform.\n\nIf you want to load the library from the current directory call\n\n``` dart\nvoid useLocalLibrary()\n```\nThe appropriate library can be found [here](https://github.com/pezi/dart_periphery/blob/main/lib/src/native) .\n\n## ⏱️ Dart isolates \n\nStarting from version *0.9.7*, the default library handling mechanism creates a temporary library \nfile, named in the format e.g. `pid_1456_libperiphery_arm.so`. The unique process ID for each isolate \nprevents repeated creation of the temporary library, avoiding crashes caused by overwriting an \nactively used library.\n\nLibrary setup override methods, such as: \n\n```\nvoid useSharedLibrary();\nvoid setCustomLibrary(String absolutePath);\n```\n\nmust be called separately within each isolate. This is necessary because each isolate initializes \n**dart_periphery** independently.\n\n## 🍓 flutter-pi\n\n**dart_periphery** works with flutter-pi, a light-weight [Flutter Engine Embedder](https://github.com/ardera/flutter-pi) for  Raspberry Pi.\n\n### flutter-pi specific methods\n\n``` dart\n// Loads the library from the flutter-pi asset directory.\nvoid loadLibFromFlutterAssetDir(bool load) \n```\n\nloads the appropriate library from the flutter asset directory. This overwrites the library \nself-extraction mechanism.\n\n* ARMv7 library: [libperiphery_arm.so](https://github.com/pezi/dart_periphery/raw/main/lib/src/native/libperiphery_arm.so) for Raspberry Pi OS 32-bit\n* ARMv8 [libperiphery_arm64.so](https://github.com/pezi/dart_periphery/raw/main/lib/src/native/libperiphery_arm64.so) for Raspberry Pi OS 64-bit\n\n\nThese methods must be called before any **dart_periphery** interface is used! See last \nsection, [native libraries](https://pub.dev/packages/dart_periphery#native-libraries) for details.\n\n\n``` dart\nList\u003cString\u003e getFlutterPiArgs();\n```\n\nreturns the command line parameter list of the `flutter-pi` command. The last parameter contains \nthe asset directory.\n\n## 🔬 Tested SoC hardware\n\n* [Raspberry Pi 3 Model B](https://www.raspberrypi.org/products/raspberry-pi-3-model-b-plus/), OS: [Raspberry Pi OS](https://www.raspberrypi.com/software/)\n* [Raspberry Pi Zero 2 W](https://www.raspberrypi.com/products/raspberry-pi-zero-2-w/), OS: [Raspberry Pi OS](https://www.raspberrypi.com/software/)\n* [NanoPi](https://wiki.friendlyelec.com/wiki/index.php/NanoPi_NEO) with a Allwinner H3, Quad-core 32-bit CPU, OS: [Armbian](https://www.armbian.com/nanopi-neo-core-2-lts/)\n* [NanoPi M1](https://wiki.friendlyelec.com/wiki/index.php/NanoPi_M1) with a Allwinner H3, Quad-core 32-bit CPU: OS [Armbian](https://www.armbian.com/nanopi-m1/)\n* [NanoPi Neo2](https://wiki.friendlyelec.com/wiki/index.php/NanoPi_NEO2) with a Allwinner H5, Quad-core 64-bit CPU, OS: [Armbian](https://www.armbian.com/nanopi-neo-2/)\n* [Banana Pi BPI-M1](https://en.wikipedia.org/wiki/Banana_Pi#Banana_Pi_BPI-M1) with a Allwinner A20 Dual-core, OS: [Armbian](https://www.armbian.com/bananapi/)\n* [Banana Pi BPI-F3 16GB](https://wiki.banana-pi.org/Banana_Pi_BPI-F3) with a [SpacemiT K1 8 core RISC-V](https://docs.banana-pi.org/en/BPI-F3/SpacemiT_K1), OS: [Armbian Dev](https://www.armbian.com/bananapi-f3), [Wiki](https://github.com/pezi/dart_periphery/wiki/BPI_F3) article\n\n\n## 🖥 Supported devices (sensors, actuators, extensions hats and displays)\n\n* [SGP30](https://github.com/pezi/dart_periphery/blob/main/example/i2c_sgp30.dart): tVOC and eCO2 Gas Sensor\n* [BME280](https://github.com/pezi/dart_periphery/blob/main/example/i2c_bme280.dart): Temperature, humidity and pressure sensor.\n* [BME680](https://github.com/pezi/dart_periphery/blob/main/example/i2c_bme680.dart): Temperature, humidity pressure and gas (Indoor Airy Quality) sensor.\n* [SHT31](https://github.com/pezi/dart_periphery/blob/main/example/i2c_sht31.dart): Temperature and humidity sensor. \n* [SHT4x](https://github.com/pezi/dart_periphery/blob/main/example/i2c_sht4x.dart): Temperature and humidity sensor. \n* [AHT10/AHT20](https://github.com/pezi/dart_periphery/blob/main/example/i2c_ahtx0.dart)  Temperature and humidity sensor\n* [CozIR](https://github.com/pezi/dart_periphery/blob/main/example/serial_cozir.dart): CO₂, temperature and humidity sensor.\n* [Grove Gesture](https://github.com/pezi/dart_periphery/blob/main/example/i2c_gesture_sensor.dart): can recognize 9 basic gestures.\n* [MPU-6050 Six-Axis](https://github.com/pezi/dart_periphery/blob/main/example/i2c_mpu6050.dart): (Gyro + Accelerometer) sensor.\n* [MCP9808](https://github.com/pezi/dart_periphery/blob/main/example/i2c_mcp9808.dart): high accuracy temperature sensor.\n* [MLX90615](https://github.com/pezi/dart_periphery/blob/main/example/i2c_mlx90615.dart): digital infrared non-contact temperature sensor.\n* [PCF8591](https://github.com/pezi/dart_periphery/blob/main/example/i2c_pcf8591.dart): ADC+DAC combo \n* [SDC30](https://github.com/pezi/dart_periphery/blob/main/example/i2c_sdc30.dart): CO₂, temperature and humidity sensor.\n* [SI1145](https://github.com/pezi/dart_periphery/blob/main/example/i2c_si1145.dart) sunlight sensor: visible \u0026 IR light, UV index\n* [TSL2591](https://github.com/pezi/dart_periphery/blob/main/example/i2c_tsl2591.dart) light sensor\n* [DS1307/DS3231](https://github.com/pezi/dart_periphery/blob/main/example/i2c_ds1307.dart) real time clock support\n* [VL53L0X](https://github.com/pezi/dart_periphery/blob/main/example/i2c_vl53l0x.dart) Time-of-Flight sensor \n* [AT24C128](https://github.com/pezi/dart_periphery/blob/main/example/i2c_at24c128.dart) 256 KB EEPROM\n* Analog [Light sensor](https://github.com/pezi/dart_periphery/blob/main/example/extension_hats/hat_light_sensor_led.dart)\n* [Button](https://github.com/pezi/dart_periphery/blob/main/example/extension_hats/hat_button.dart)\n* [Magnetic switch sensor](https://github.com/pezi/dart_periphery/blob/main/example/extension_hats/hat_magnetic_switch.dart)\n* [Magnetic hall sensor](https://github.com/pezi/dart_periphery/blob/main/example/extension_hats/hat_magnetic_hall.dart)\n* [Vibration sensor](https://github.com/pezi/dart_periphery/blob/main/example/extension_hats/hat_vibration.dart)\n* [PIR motion sensor ](https://github.com/pezi/dart_periphery/blob/main/example/extension_hats/hat_pir_motion.dart)\n* [SSD1306](https://github.com/pezi/dart_periphery/blob/main/example/i2c_ssd1306.dart) 128x64 pixel OLED\n* [SSD1306](https://github.com/pezi/dart_periphery/blob/main/example/i2c_ssd1306) 128x64 pixel OLED with Java bridge for image generation\n* FriendlyElec [NanoHat Hub](https://wiki.friendlyelec.com/wiki/index.php/BakeBit_-_NanoHat_Hub)\n* [Grove Base Hat RaspberryPi](https://www.seeedstudio.com/Grove-Base-Hat-for-Raspberry-Pi.html)\n* [Grove Base Hat RaspberryPi Zero](https://wiki.seeedstudio.com/Grove_Base_Hat_for_Raspberry_Pi_Zero)\n* [PN532](https://github.com/pezi/dart_periphery/pull/6) NFC Reader Module, Thanks to [UliPrantz](https://github.com/UliPrantz)!\n\n\n## 🌡 flutter_pi_sensor_tester\n\n![alt text](https://raw.githubusercontent.com/pezi/dart_periphery_img/main/flutter_sensor_tester.gif \"Flutter Sensor Tester\")\n\nThis [subproject](https://github.com/pezi/flutter_pi_sensor_tester) bases on \n[flutter-pi](https://github.com/ardera/flutter-pi) and implements a simple\nDart isolate/stream architecture designed to transfer sensor data from an isolate to the Flutter UI:\n\n**Isolate interface**: This consists of the steps `InitTask`, `MainTask`, and `ExitTask`, along with a \nlimited back channel for controlling the Dart isolate. This setup is typically used for sensor \nmeasurements:\n* `InitTask`: Initializes the sensor.\n* `MainTask`: Collects sensor data and passes it to a stream.\n* `ExitTask`: Disposes of the sensor.\n\n**Listening Mode**: Supports user-defined handling for isolate events. \nThis variant remains on standby for data; once data is processed, the result is passed to the stream \nand subsequently to the Flutter UI. This model is used for actuator control, such as operating a LED.\n\n**Support for Multiple Streams**: Enables handling of multiple data streams simultaneously.\n\nThis project is currently still beta and development is ongoing.\n\n## 💧 flutter_sensor_tester \n\nThis project builds upon the `flutter_pi_sensor_tester` by introducing a client/server architecture, enhancing its functionality for distributed applications.\n\n![alt text](https://raw.githubusercontent.com/pezi/dart_periphery_img/main/client_server.png \"Client Server\")\n\nCurrently in its alpha stage, the project is scheduled for release in March 2025.\n\n## 📋 Test matrix\n\n[Test suite](https://github.com/pezi/dart_periphery/tree/main/test)\n\n| Architecture  |   GPIO    | GPIO\u003csub\u003esysfs\u003c/sub\u003e |   I2C   |   SPI   | Serial  |  MMIO   |   PWM   |     LED |\n|---------------|:---------:|:--------------------:|:-------:|:-------:|:-------:|:-------:|:-------:|--------:|\n| **ARM** ²     |  \u0026#9989;  |       \u0026#9989;        | \u0026#9989; | \u0026#9989; | \u0026#9989; | \u0026#9989; | \u0026#9989; | \u0026#9989; |\n| **AARCH64** ³ | \u0026#10060;⁴ |       \u0026#9989;        | \u0026#9989; | \u0026#9989; | \u0026#9989; | \u0026#9989; | \u0026#9989; | \u0026#9989; |\n| **X86** ⁵     |  \u0026#9744;  |       \u0026#9744;        | \u0026#9744; | \u0026#9744; | \u0026#9744; | \u0026#9744; | \u0026#9744; | \u0026#9744; |\n| **X86_64** ⁵  |  \u0026#9744;  |       \u0026#9744;        | \u0026#9744; | \u0026#9744; | \u0026#9744; | \u0026#9744; | \u0026#9744; | \u0026#9744; |\n| **RISC V** ⁶  |  \u0026#9744;  |       \u0026#9744;        | \u0026#9989; | \u0026#9744; | \u0026#9744; | \u0026#9744; | \u0026#9744; | \u0026#9744; |\n\n\u0026#9744; missing test | \u0026#9989; test passed | \u0026#10060; test failed\n\n² [Raspberry Pi 3 Model B](https://www.raspberrypi.org/products/raspberry-pi-3-model-b-plus/)\n\n³ Raspberry Pi OS (64-bit), [NanoPi Neo2](https://wiki.friendlyelec.com/wiki/index.php/NanoPi_NEO2) with a Allwinner H5, Quad-core 64-bit CPU\n\n⁴ Fails for NanoPi, NanoPi Neo2 and Banana Pi on Armbian- same behavior like the original \nc-periphery [test program](https://github.com/vsergeev/c-periphery/blob/master/tests/test_gpio.c). This is a point of deeper investigations\n\n⁵ no X86/X86_64 SoC for testing available\n\n⁶ Banana Pi BPI-F3, only limited tests\n\n\n## 🙏 Help wanted\n\n* Testing **dart_periphery** on different [SoC platforms](https://www.armbian.com/download/)\n* Documentation review - I am not a native speaker.\n* Code review - this is my first public Dart project. I am a Java developer and probably I tend \nto solve problems rather in the Java than in the Dart way.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpezi%2Fdart_periphery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpezi%2Fdart_periphery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpezi%2Fdart_periphery/lists"}