Coder Social home page Coder Social logo

golemparts / blinkt Goto Github PK

View Code? Open in Web Editor NEW
21.0 2.0 7.0 194 KB

A Rust library for the Pimoroni Blinkt!, and any similar APA102 or SK9822 LED strips or boards, on a Raspberry Pi.

License: MIT License

Rust 100.00%
raspberry-pi raspberrypi rust rust-library blinkt blinkt-library apa102 sk9822

blinkt's Introduction

Blinkt

Build Status crates.io MIT licensed Minimum rustc version

Blinkt is a Rust library that provides an interface for the Pimoroni Blinkt!, and any similar APA102 or SK9822 LED strips or boards, on a Raspberry Pi. The library supports bitbanging mode on any GPIO pins, and hardware SPI mode on GPIO 10 (physical pin 19) for data, and GPIO 11 (physical pin 23) for clock.

For bitbanging mode, Blinkt gains access to the BCM283x GPIO peripheral either through /dev/gpiomem or /dev/mem. Hardware SPI mode is controlled through /dev/spidev0.0.

Both the original APA102 and the SK9822 clone are supported. The RGB LED/driver ICs are referred to as pixels throughout the code and documentation.

Backwards compatibility for minor revisions isn't guaranteed until the library reaches v1.0.0.

Blinkt is under development on the master branch of the repository on GitHub. If you're looking for the README.md or the examples directory for the latest release or any of the earlier releases, visit crates.io, download an archived release from the GitHub releases page, or clone and checkout the relevant release tag.

Documentation

Online documentation is available for the latest release, older releases, and the version currently in development.

Usage

Add a dependency for blinkt to your Cargo.toml using cargo add blinkt, or by adding the following line to your dependencies section.

[dependencies]
blinkt = "0.7.1"

Call Blinkt::new() to create a new Blinkt with the default settings. Alternative configuration options are available through Blinkt::with_settings() and Blinkt::with_spi().

use blinkt::Blinkt;

let mut blinkt = Blinkt::new()?;

Examples

The example below demonstrates swapping all pixels on a Blinkt! board between red, green and blue.

use std::error::Error;
use std::time::Duration;
use std::{mem, thread};

use blinkt::Blinkt;

fn main() -> Result<(), Box<dyn Error>> {
    let mut blinkt = Blinkt::new()?;
    let (red, green, blue) = (&mut 255, &mut 0, &mut 0);

    loop {
        blinkt.set_all_pixels(*red, *green, *blue);
        blinkt.show()?;

        thread::sleep(Duration::from_millis(250));

        mem::swap(red, green);
        mem::swap(red, blue);
    }
}

To control an LED strip consisting of 144 pixels, connected to the Raspberry Pi's hardware SPI pins (data on GPIO 10 (physical pin 19), and clock on GPIO 11 (physical pin 23)), at 16 MHz clock speed, replace the Blinkt::new() line in the above example with the following. You may have to tweak the maximum clock speed based on the number of pixels and the wire quality.

let mut blinkt = Blinkt::with_spi(16_000_000, 144)?;

Additional examples can be found in the examples directory.

Cross compilation

If you're not working directly on a Raspberry Pi, you'll have to cross-compile your code for the appropriate ARM architecture. Check out this guide for more information, or try the cross project for "zero setup" cross compilation.

Cargo

While additional steps may be necessary to cross-compile binaries on your platform, checking your code with cargo check only requires the installation of an appropriate target. Most Raspberry Pi models need the armv7-unknown-linux-gnueabihf target. For some models, like the Raspberry Pi Zero, a different target triple is required.

Install the relevant target using rustup.

rustup target install armv7-unknown-linux-gnueabihf

In the root directory of your project, create a .cargo subdirectory, and then save the following snippet to .cargo/config.

[build]
target = "armv7-unknown-linux-gnueabihf"

Visual Studio Code

The rust-analyzer extension for Visual Studio Code needs to be made aware of the target platform by setting the rust-analyzer.cargo.target configuration option. In the root directory of your project, create a .vscode subdirectory, and then save the following snippet to .vscode/settings.json.

{
    "rust-analyzer.cargo.target": "armv7-unknown-linux-gnueabihf"
}

Copyright and license

Copyright (c) 2016-2022 Rene van der Meer. Released under the MIT license.

blinkt's People

Contributors

ashhhleyyy avatar golemparts avatar hellow554 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

blinkt's Issues

Display issues under high CPU load

I am getting glitchy rendering (even when running the examples) when my pi's CPU is running high. It seems as though the python library had the same issue a while back and the fix and quite simple. Here is that PR: pimoroni/blinkt#62

Won't work on RPi3-B

I am having trouble getting this to work on the Raspberry Pi 3-B.

Any suggestions?

Brightness issues above 0.1

Thanks for the excellent crate.

0.6.0 is not available outside of the git repo even though the Github readme mentions it.

I'm not sure if any new features have been included since 0.5.0, I'm mainly after the updated rppal dependency to reduce compile time. :)

As an aside, is anything above 0.1 or so brightness supposed to be super bright? I've found that on the Pimoroni Fan Shim anything above 0.1 is ridiculously bright.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.