Skip to content

Instantly share code, notes, and snippets.

@hgdeoro
hgdeoro / libvirt_xml_bus_device.xml
Created July 1, 2011 16:21
USB+KVM using bus+device
<hostdev mode='subsystem' type='usb' managed='no'>
<source>
<address bus='2' device='4'/>
</source>
</hostdev>
@hgdeoro
hgdeoro / free_memory_example.py
Created June 8, 2011 04:08
Ejemplo: imprimir memoria libre
from arduino_proxy.proxy import ArduinoProxy
proxy = ArduinoProxy('/dev/ttyACM0')
print "Memoria libre:", proxy.getFreeMemory()
@hgdeoro
hgdeoro / get_free_memory_method.py
Created June 8, 2011 02:12
Ejemplo: ArduinoProxy.getFreeMemory()
class ArduinoProxy(object):
(...)
def getFreeMemory(self):
val = self.send_cmd("_gFM")
return val
getFreeMemory.arduino_function_name = '_gFM'
getFreeMemory.arduino_code = """
@hgdeoro
hgdeoro / free_memory.js
Created June 5, 2011 14:43
Show memory usage of Arduino using PyArduinoProxy and JS Prototypes
var ram = proxy.globalData()['arduino_type_struct']['ram_size_bytes'];
var free = proxy.getFreeMemory();
var pc = Math.floor((free/ram)*100);
logMessage("Free ram: " + free + " bytes of " + ram + " bytes (" + pc + "% free).");
@hgdeoro
hgdeoro / read-temperature-with-lm335.js
Created June 3, 2011 04:38
Javascript to read temperature with LM335, using PyArduinoProxy
/***********************************************************************
* First example. Testing how to use LM335 to read temperature,
* using PyArduinoProxy.
***********************************************************************/
var value = proxy.analogRead(0);
logMessage("analogRead(): " + value);
var volt = (5.0/1024.0) * value;
logMessage("volt: +" + volt +"V");
@hgdeoro
hgdeoro / pyarduinoproxy-example.js
Created June 1, 2011 03:07
Examples used on video of web interface (PyArduinoProxy)
/*
* FIRST EXAMPLE
*/
var i;
for(i=2; i<=5; i++) {
proxy.pinMode(i, OUTPUT);
}
var j;
@hgdeoro
hgdeoro / shift-reg.py
Created May 17, 2011 04:57
Test 74HC164 shift register with Py-Arduino-Proxy
# Test 74HC164 shift register
import time
from arduino_proxy import ArduinoProxy
def blink():
print "blink()"
proxy.shiftOut(10, 11, ArduinoProxy.LSBFIRST, 0)
time.sleep(0.5)
proxy.shiftOut(10, 11, ArduinoProxy.LSBFIRST, 255)
time.sleep(0.5)
@hgdeoro
hgdeoro / wait_push_button_to_start.pde
Created April 15, 2011 21:20
Press a button to start
#define PIN_ONBOARD_LED 13 // DIGITAL
#define PIN_START_BUTTON 12 // DIGITAL
void setup() {
// Pin 13 has an LED connected on most Arduino boards.
pinMode(PIN_ONBOARD_LED, OUTPUT);
pinMode(PIN_START_BUTTON, INPUT);
wait_start();
@hgdeoro
hgdeoro / FakeReadOnlyBinaryFile.py
Created March 29, 2011 21:15
File-like object for reading random data (usefull for testing)
import random
def rnd_byte():
return chr(random.randint(0, 255))
class FakeReadOnlyBinaryFile:
"""
File-like object for reading random data. The ammount of data to generate
is specified when the object is created.
@hgdeoro
hgdeoro / unittest_snippet.py
Created March 17, 2011 14:38
Using private function with unittest.assertRaises()
class SomeTest(unittest.TestCase):
.
.
.
def test_queue(self):
.