npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

arduino-nodejs

v1.0.0

Published

Module for arduino-nodejs communication

Downloads

1

Readme

Module for arduino-nodejs communication

const arduino_node = require("arduino-nodejs")

// Returns a promise
// Example of result: ["COM9", "COM3", "COM1"]
// The lower on the list, the bigger is the chance
// Of it being a arduino board
arduino_node.list()

// COM_port should be a port returned by list()
// Baud_rate should be one of the rates
// Here: https://arduino.stackexchange.com/questions/296/
// Baud rates higher than 115200 may not work on
// Devices using CH430G/CH430 or other non-standard
// USB to Serial converters

// Delay should be a number in milliseconds to wait
// After sending a message.
// With lower baud rates it may be neccesary to include
// A number bigger than 10
arduino_node.connect(COM_port, Baud_Rate, Delay?)

// Sends a object to the Arduino
await arduino_node.write(object)

// Reads a value. Should be in a interval
// As small as possible to get the 
// information fast
arduino_node.read()

// The arduino code should be like this:

#include <ArduinoJson.h>


void setup()
{
  Serial.begin(115200); // Should be the same baud rate as using in the nodejs file
}

void loop()
{
  if (Serial.available()) {
    DynamicJsonDocument doc(1024);
    deserializeJson(doc, Serial);

    if (doc["fingerprint"] == "X-Node-Fingerprint") {
      // Arduino detected the serial write and that it is from a nodejs script
      // Do something cool here

    }
  }
}

// Example of code that displays the views and likes of a youtube video:

// NodeJS 

await arduino_node.connect(list[0], 115200, 10)

const arduino_node = require("arduino-nodejs")
const gaxios = require("gaxios")
let video_id = "aKkVqmvs4NA"
let youtube_key = ""
let link = `https://www.googleapis.com/youtube/v3/videos?part=statistics&id=${id}&key=${youtube_key}`

function scrapeData(id) {
    return new Promise((resolve, reject) => {
        gaxios.request({ method: "GET", url: link})
            .then((data) => {
                resolve(data.data.items[0].statistics)
            })
            .catch((err) => {
                reject(err)
            })
    })
}

function printToScreen(){
    scrapeData(video_id)
    .then(async (data) => {
        await arduino_node.write({ type: "lcd_clear" })
        await arduino_node.write({ type: "setCursor", "pos1": 0, "pos2": 0 })
        await arduino_node.write({ type: "lcd_print", "text": `views: ${data.viewCount}` })
        await arduino_node.write({ type: "setCursor", "pos1": 0, "pos2": 1 })
        await arduino_node.write({ type: "lcd_print", "text": `likes: ${data.likeCount}` })
    })
}


arduino_node.list().then(async (list) => {
    arduino_node.connect(list[0], 115200, 10)

    printToScreen()
    setInterval(async () => {
        printToScreen()
    }, 8100);
}).catch((err) => {
    console.log(err)
})

// Arduino

#include <LiquidCrystal_I2C.h>
#include <ArduinoJson.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // This is using the I2C version, change this if you want the normal one

void setup()
{
  Serial.begin(115200);
  lcd.init();
  lcd.backlight();
}

void loop()
{
  if (Serial.available()) {
    DynamicJsonDocument doc(1024);
    deserializeJson(doc, Serial);

    if (doc["fingerprint"] == "X-Node-Fingerprint") {
      if (doc["type"] == "lcd_print") {
        lcd.print(doc["text"].as<String>());
      } else if (doc["type"] == "lcd_clear") {
        lcd.clear();
      } else if (doc["type"] == "setCursor") {
        lcd.setCursor(doc["pos1"].as<int>(), doc["pos2"].as<int>());
      }
    }
  }
}