Giter Club home page Giter Club logo

bcm2835's Introduction

Ruby Bindings for libbcm2835

The BCM2835 is the ARM11 core used in the Raspberry PI. It exposes several harware peripherals:

This library is a wrapper on top of libbcm2835 that provides a high level interface for accessing the ARM's hardware features from Ruby

View the Full Documentation on rubydoc.info

GPIO

General Purpose Input/Output

Using Inputs

pin = 17

# make pin an input
GPIO.input(pin)

# check if the input is HIGH i.e. true
puts "door is closed" if GPIO[pin]

Using Outputs

pin = 17

# make pin an output
GPIO.output(pin)

# blink
loop do
  GPIO[pin] = true
  sleep(1)
  GPIO[pin] = false
  sleep(1)
end

SPI

Serial Peripheral Interface

Reading from the SPI bus

SPI.begin do |spi| 
  puts spi.read       # returns 1 byte
  puts spi.read(1024) # returns an array of 1024 bytes 
end

Writing to the SPI bus

SPI.begin do |spi| 
  spi.write(0x22)           # write 1 byte
  spi.write("hello")        # write 5 bytes
  spi.write(0x22,0x45,0x71) # write several bytes at once 
end

I²C

Two Wire Interface

Not yet implemented

UART

Universal Asynchronous Receiver/Transmitter

You can use the Ruby Standard Library to read and write from the UART

Echo Example

File.open('/dev/ttyAMA0', 'a+') do |file|
  loop do 
    data = file.read
    file.puts(data)
  end
end

Installation

Add this line to your application's Gemfile:

gem 'bcm2835'

And then execute:

$ bundle

Or install it yourself as:

$ gem install bcm2835

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

bcm2835's People

Contributors

joshnuss avatar

Watchers

James Cloos avatar  avatar

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.