Skip to content

Instantly share code, notes, and snippets.

View mikaelleven's full-sized avatar

Mikael Levén mikaelleven

View GitHub Profile
@mikaelleven
mikaelleven / athome.css
Last active April 12, 2017 12:06
athome
.btn-success2
{
display: inline-block;
height: 36px;
max-width: 100%;
overflow: hidden;
padding: 0 15px;
background-color: #c45e12;
border: none;
border-radius: 3px;
@mikaelleven
mikaelleven / AllowSSH.sh
Last active February 24, 2017 15:13
Script to automagically enable SSH login through RSA key for the current user on a remote machine
#!/bin/bash
###############################################################################
# ALLOW-SSH SCRIPT #
# Author: Mikael Levén #
###############################################################################
# What this script basically does: #
# 1. Reads your SSH key #
# 2. Logins in to the remote server #
# 3. Creates a new user using your current username #
@mikaelleven
mikaelleven / readme.md
Last active August 28, 2022 10:28
NodeJS SPI Dump for MCP3008 (and Raspberry Pi)

NodeJS SPI Dump for MCP3008

This is a simple script that reads all eight analog channels of an MCP3008 each second and outputs the result to the console.

I created this script to ease debugging of the MCP3008 ADC connected to my Raspberry Pi.

If you need to troubleshoot the SPI connection in itself you can check out my guide how to test SPI through the loopback "debug mode" https://mikaelleven.wordpress.com/2015/12/10/troubleshooting-spi-on-raspberry-pi-nodejs/.

Installation

@mikaelleven
mikaelleven / spi_example.js
Last active July 23, 2019 05:52
NodeJS example using SPI communication to retrieve analog data through MCP3008 and Raspberry Pi
var rpio = require('rpio');
rpio.spiBegin();
//rpio.spiChipSelect(0); /* Chip select: use CE0 (default) */
//rpio.spiSetCSPolarity(0, rpio.LOW) /* Commonly chip enable (CE) pins are active low, and this is the default. */
//rpio.spiSetClockDivider(256) /* MCP3008 max is ~1MHz, 256 == 0.98MHz */
//rpio.spiSetDataMode(0);
// Prepare TX buffer [trigger byte = 0x01] [channel 0 = 0x80 (128)] [placeholder = 0x01]
var sendBuffer = new Buffer([0x01, (8 + 0 << 4), 0x01]);
@mikaelleven
mikaelleven / spi_loopback.js
Created December 10, 2015 20:14
NodeJS loopback example for troubleshooting SPI communication on Raspberry Pi GPIO
var rpio = require('rpio');
var rxBuffer = rpio.spiTransfer(new Buffer('HELLOSPI'), 8);
for (var i = 0; i <= 7; i++) {
process.stdout.write(String.fromCharCode(rxBuffer[i]) + (i == 7 ? '\n' : ' '));
};