Skip to content

Instantly share code, notes, and snippets.

Mikael Levén mikaelleven

Block or report user

Report or block mikaelleven

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View athome.css
.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 Feb 24, 2017
Script to automagically enable SSH login through RSA key for the current user on a remote machine
View AllowSSH.sh
#!/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 Jul 7, 2017
NodeJS SPI Dump for MCP3008 (and Raspberry Pi)
View readme.md

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 Jul 23, 2019
NodeJS example using SPI communication to retrieve analog data through MCP3008 and Raspberry Pi
View spi_example.js
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 Dec 10, 2015
NodeJS loopback example for troubleshooting SPI communication on Raspberry Pi GPIO
View spi_loopback.js
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' : ' '));
};
You can’t perform that action at this time.