The Crystal Programming Language Forum

Raspberry pi GPIO in Crystal

Good day, dear Crystal-lang community!
I am new to programming but 2 months ago I was inspired by Ruby and 1 month ago the same was when I founded Crystal => it is great!

Could somebody tell me, is it possible to create Raspberry Pi GPIO library with Crystal? Which knowledge should I have to do it? How many time it can take (approximately)?

I think Crystal-lang is very good for IoT and sensors because it is fast and slick.

You don’t need to create a raspberry PI GPIO library, you can just use wiringpi (libwiringpi) and call its functions from crystal.

  @[Link("wiringPi")]
  lib LibWiringPi
    fun Setup = wiringPiSetupSys : LibC::Int
    fun DigiWrite = digitalWrite(pin : LibC::Int, value : LibC::Int) : Void
    fun PinMode = pinMode(pin : LibC::Int, mode : LibC::Int) : Void
  end

    LibWiringPi.Setup()
    LibWiringPi.PinMode(output_pin,1)
    LibWiringPi.DigiWrite(output_pin, 1)
    sleep(1)
    LibWiringPi.DigiWrite(output_pin, 0)

Inputs are similar, just have a look at the documentation of wiringpi at http://wiringpi.com/

1 Like