Skip to content

Instantly share code, notes, and snippets.

View smittytone's full-sized avatar
🕶️
In single-minded pursuit of the groove

Tony Smith smittytone

🕶️
In single-minded pursuit of the groove
View GitHub Profile
@smittytone
smittytone / i2c_example.agent.nut
Last active August 29, 2015 13:57
Sample code showing the use of I2C with the Electric Imp
// Print light reading trigger URL
server.log("Sensor Agent URL: " + http.agenturl());
// Define funtions
function requestHandler(request, response)
{
// Handle an incoming web request for a reading
@smittytone
smittytone / led_matrix_scroll.agent.nut
Last active August 29, 2015 13:57
Display a side-scrolling message sent over the Internet to an Imp connected to an LED matrix
// Log the URLs we need
server.log("Print message x: " + http.agenturl() + "?message=x&inv=1");
function requestHandler(request, response)
{
try
{
// check if the user sent 'print' as a query parameter
if ("inv" in request.query) device.send("ts.led.inverse", request.query.inv);
@smittytone
smittytone / one_wire_multi.device.nut
Last active August 29, 2015 14:00
Electric Imp UART implementation of 1-Wire for multiple devices
function one_wire_reset()
{
// Configure UART for 1-Wire RESET timing
ow.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS)
ow.write(0xF0)
ow.flush()
if (ow.read() == 0xF0)
{
// UART RX will read TX if there's no device connected
@smittytone
smittytone / one_wire_single.device.nut
Last active August 29, 2015 14:00
Electric Imp UART implementation of 1-Wire for single DS18B20 thermometer
function one_wire_reset()
{
// Configure UART for 1-Wire RESET timing
ow.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS)
ow.write(0xF0)
ow.flush()
if (ow.read() == 0xF0)
{
// UART RX will read TX if there's no device connected
@smittytone
smittytone / nokia_lcd.device.nut
Last active August 29, 2015 14:00
Electric Imp example code to drive a Nokia 3310/5110 84 x 48 mono LCD
// Nokia 5110 control code for the imp
// Adapted by Tony Smith from a variety of sources:
// http://playground.arduino.cc/Code/PCD8544
// http://www.microsyl.com/index.php/2010/03/24/nokia-lcd-library/
// Assign the control pins to global variables
PIN_RST <- hardware.pin9;
PIN_CE <- hardware.pin8;
PIN_DC <- hardware.pin7;
@smittytone
smittytone / spi.device.nut
Last active August 29, 2015 14:01
SPI on the Electric Imp using Analog Devices' ADXL345 accelerometer
// ADXL345 Register Values
const DEVICE_ID = 0x00; // Device ID register
const POWER_CTL = 0x2D; // Power Control register
const DATA_FORMAT = 0x31; // Data storage format register
const DATAX0 = 0x32; //X-Axis Data 0
const DATAX1 = 0x33; //X-Axis Data 1
const DATAY0 = 0x34; //Y-Axis Data 0
const DATAY1 = 0x35; //Y-Axis Data 1
const DATAZ0 = 0x36; //Z-Axis Data 0
@smittytone
smittytone / ssd1306.device.nut
Last active August 29, 2015 14:02
Electric Imp Squirrel class for the SSD1306 OLED controller
class SSD1306_OLED
{
// Squirrel Class for Solomon SSD1306 OLED controller chip
// [http://www.adafruit.com/datasheets/SSD1306.pdf]
// As used on the Adafruit SSD1306 I2C breakout board
// [http://www.adafruit.com/products/931]
// Bus: I2C
// Code by Tony Smith (@smittytone) June 2014
// Version 1.0.2
@smittytone
smittytone / bmp180.device.nut
Last active August 29, 2015 14:02
Electric Imp Squirrel class for Bosch BMP180 Temperature and Pressure Sensor
class BMP180_Sensor
{
// Squirrel Class for Bosch BMP180 Temperature and Pressure Sensor
// [http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf]
// As used on the Adafruit BMP180 breakout board
// [http://www.adafruit.com/products/1603]
// Bus: I2C
// Code by Tony Smith (@smittytone) June 2014
// Version 1.0
@smittytone
smittytone / zx81.device.nut
Created June 10, 2014 08:38
Sinclair ZX81 Character set stub for Squirrel
// Constants for the alphanumeric character set
static charset = [
[0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00], // Space - Ascii 32
[0x00,0x10,0x10,0x10,0x10,0x00,0x10,0x00], // !
[0x00,0x24,0x24,0x00,0x00,0x00,0x00,0x00], // ”
[0x00,0x24,0x7E,0x24,0x24,0x7E,0x24,0x00], // #
[0x00,0x08,0x3E,0x28,0x3E,0x0A,0x3E,0x08], // $
[0x00,0x62,0x64,0x08,0x10,0x26,0x46,0x00], // %
[0x00,0x10,0x28,0x10,0x2A,0x44,0x3A,0x00], // &
@smittytone
smittytone / onewire.device.nut
Last active August 29, 2015 14:02
Electric Imp Squirrel class for handling 1-Wire devices over a UART bus
// Squirrel Class for accessing 1-Wire devices, eg.
// Maxim Integrated DS18B20 temperature sensor
// [http://www.maximintegrated.com/datasheet/index.mvp/id/2812]
// via two-wire UART. The imp does not support 1-Wire natively
// Bus: UART
// Code by Tony Smith (@smittytone) June 2014
// Version 1.0