TS Deno Interface to help communicate with the raspberry pi's GPIO pins

Overview

Raspberry pi GPIO helpers made for Deno

An interface for interacting and reading from the raspberry pi GPIO pins using sysfs.

Why?

Just for shits and giggles. Also why not? LOL!

Examples

Turning on an LED:

/*
- set pin direction to out. will queue up an instruction to auto-export the pin
- also sets the pin value to high. RPis do not have analogue: 1 for HIGH 0 for LOW
*/
import { executeInstructions, Pin, PinDirection, sleep } from "./mod.ts";

// full bash-level execution.
const led = new Pin(24, PinDirection.OUT, 1);
sleep(5);
led.setValue(0);
led.unexport();
executeInstructions(); // executes the above instructions.

it is highly recommended you unexport the pin after you are done using it.

It is also possible to take a more hybrid approach in which you come back to javascript:

// alternative hybrid (transfer from bash to JS and vice-versa)
// note that this approach is a bit slower and can cause timing issues with some 'dumb' sensors that require precise instruction sequences.
const led = new Pin(24, PinDirection.OUT, 1);
// the Pin constructor queues up some export instructions.. we are executing these here
executeInstructions(); // calls sysfs. returns a promise.

// standard JS timeout..
setTimeout(() => {
  led.setValue(0);
  led.unexport();
  executeInstructions();
}, 4000);

Listening for button press

import { executeInstructions, Pin, PinDirection } from "./mod.ts";

const button = new Pin(24, PinDirection.IN);
// the Pin constructor queues up some export instructions.. execute here.
await executeInstructions();
console.log("Waiting for button press");

while (true) {
  if (button.readValue() == 1) {
    console.log("button pressed");
    button.unexport();
    executeInstructions();
    break;
  }
}

Waiting for a pin to be a specific value

The following will issue an instruction to wait until the provided pin is set to HIGH (1) before continuing executing other commands:

const button = new Pin(24, PinDirection.IN);
button.waitForValue(); // wait (and thus blocking) occurs here
button.unexport();
await executeInstructions(); // this is where the main loop gets blocked in JavaScript.

Note that this blocking will happen in the sub-process created by Deno and will not block the JavaScript loop unless we use async await. it is also important to note that the blocking happens at the point of execution (i.e., when 'await executeInstructions();' is called)

Limitations

  1. JavaScript it not very 'precise'. i.e. no microsecond delay support for interacting with hardware that requires this (e.g. DHT11). To circumvent this, a method named pipeValue can be used to add read instructions in the instruction queue which will be executed along other instructions (including sleep instructions) in a shell.

Deno on the pi?

YES!!!! This will explain it all

You might also like...

Deno bindings for yoga, using Deno FFI.

deno_yoga Deno bindings for yoga, using Deno FFI. Usage flags: --allow-ffi: Requires ffi access to "yogacore.dll", "libyogacore.so", "libyogacore.dyli

Feb 11, 2022

🛣️ A tiny and fast http request router designed for use with deno and deno deploy

Rutt Rutt is a tiny http router designed for use with deno and deno deploy. It is written in about 200 lines of code and is pretty fast, using an exte

Dec 10, 2022

A small, but powerful HTTP library for Deno & Deno Deploy, built for convenience and simplicity

A small, but powerful HTTP library for Deno & Deno Deploy, built for convenience and simplicity

Wren Wren is a small, but powerful HTTP library for Deno & Deno Deploy, built for convenience and simplicity. convenient aliases for HTTP responses au

Dec 12, 2022

deno-ja (Deno Japanese community) showcase

Showcase Deno本家よりも気軽に作ったものを公開できるようなShowcaseです。 スクリーンショットの撮影方法 短めのidを決めていただいて、下記のようにスクリプトを実行してください。 deno task screenshot [url] [id] ※エラーが出る場合は、下記を実行してみ

Oct 28, 2022

A command-line tool to manage Deno scripts installed via deno install

🏞️ nublar nublar is a command-line tool to manage your scripts installed via deno install. 🛳️ Installation deno install --allow-read --allow-write -

Dec 26, 2022

CloudCrafter CLI is a command-line interface tool that provides templates for common cloud resources to help you get started quickly.

CloudCrafter CLI CloudCrafter CLI is a command-line interface tool that provides templates for common cloud resources to help you get started quickly.

May 5, 2023

Creates Photoshop-like guides and rulers interface on a web page

Creates Photoshop-like guides and rulers interface on a web page

RulersGuides.js This Javascript package creates Photoshop-like guides and rulers interface on a web page. DEMO Main window: Menu: Guides are created b

Nov 27, 2022

The all-in-one interface for Chrome

The all-in-one interface for Chrome

Omni The most powerful interface for Chrome 🔥 With Omni you can use Chrome like a pro. Manage tabs, bookmarks, your browser history, perform all sort

Dec 31, 2022
Releases(1.4.0)
Owner
Duart Snel
self-taught software/hardware engineer from Curaçao, started when i was 12. Currently doing full-stack "stuff" www.linkedin.com/in/duart-snel-2465a5160
Duart Snel
This is an app that will service the ASD community to help them communicate what they want. The individual can be either verbal or non-verbal.

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

MailingDelgadoMedina 3 Jun 28, 2022
TzKTApi is a Node.js module to communicate with a tzkt API.

TzKTAPI TzKTApi is a Node.js module to communicate with a tzkt API. Heavily inspired by the dipdup-sdk. It uses the openapi-typescript-codegen to gene

Asbjorn Enge 10 Mar 10, 2022
Opinionated collection of TypeScript definitions and utilities for Deno and Deno Deploy. With complete types for Deno/NPM/TS config files, constructed from official JSON schemas.

Schemas Note: You can also import any type from the default module, ./mod.ts deno.json import { type DenoJson } from "https://deno.land/x/[email protected]

deno911 2 Oct 12, 2022
e-ONG, an authorial project, whose objective is to help ONGs to find people who need help or would like to help them

This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: npm start Runs the app in the developmen

Lucas Lima 2 Nov 11, 2022
A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch screens with a resolution of 1024x600 connected to a Raspberry Pi.

EDStatusPanel A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch scr

marcus-s 24 Oct 4, 2022
An open-source boat display cockpit for navigation, speed, heading, and tide tables running on Raspberry Pi and accessible as a webapp through any smartphone.

An open-source boat display cockpit for navigation, speed, heading, and tide tables running on Raspberry Pi and accessible as a webapp through any smartphone

Andy 44 Dec 30, 2022
The Raspberry Pi + OpenScan Pi Shield can be used to control two independent stepper motors and a variety of different cameras

OpenScan2 Overview: The Raspberry Pi + OpenScan Pi Shield can be used to control two independent stepper motors and a variety of different cameras (Pi

Thomas 149 Jan 3, 2023
An implementation of the ECMA-419 spec on the Raspberry Pi

raspi-419 An implementation of the ECMA-419 spec on the Raspberry Pi Licsense MIT License Copyright (c) Bryan Hughes Permission is hereby granted, fre

Bryan Hughes 4 Jun 9, 2022
This is a simple boilerplate for a Deno website, deployed with Deno Deploy.

Simple Deno Website Boilerplate This is a simple website boilerplate built using Deno and deployed using Deno Deploy. Demo at simple-deno-website-boil

Bruno Bernardino 15 Dec 3, 2022
TypeSafe MongoDB Atlas Data API SDK for Deno & Deno Deploy

Atlas SDK atlas_sdk is a TypeSafe MongoDB Atlas Data API SDK for Deno & Deno Deploy Links Docs Import Replace LATEST_VERSION with current latest versi

Erfan Safari 20 Dec 26, 2022