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.

1 Like

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/

2 Likes

I don’t think there is something for rbpi. I tried to write a library for handling GPIO pins on raspberry, but I noticed that there’s still no support for arm architecture.
I found this, but it doesn’t work, so the only available way to run crystal code on raspberry is to cross-compile the compiler for arm from another machine, then you can compile and work on rbpi.

that is not as hard as it sounds, but It’s true, it would be nice to have a more current .deb for arm.

Well, it depends. The last time I tried crystal was using LLVM 4.0 which was unable to cross-compile for ARM. I noticed that now crystal uses LLVM 8, so maybe it’s possbile to cross-compile the compiler itself.
Back then, the only thing that I couldn’t stand was the fact that I don’t want to debug the compiler fro writing my own project.

Hi…Get yourself a mutimeter to really check there is any action on an output pin. They can be had for a few dollars.
If your output is a slow, on and off kind of thing, you will see the meter reading zero or 3.3 volts respectively (approximately)
Even if you signal is changing rapidly you will get an idea that it at least there. The meter will read some intermediate voltage.
When I was a kid having this kind of problem with digital circuits my dad advised that I could just attach a crystal earphone to the pin and listen. If there is a change it “ticks”. If there are fast changes you hear a tone. Worked a treat.

assembling pcb