After Hours

with Monirul Pathan

Navigation Menu

LED Musical Greeting Card

LED Musical Greeting Card

Posted by on Oct 10, 2012 in Hacks | 1 comment

Looking for a super geeky card to make for that special someone? You could always buy a Hallmark card but let’s be honest, that’s just being lazy. In this post I’ll show you how I made my own for my partner’s 24th birthday.

Hit past the break to for a video of the card.

Read More

Stream music to your car with a USB powered Airport Express

Stream music to your car with a USB powered Airport Express

Posted by on Oct 6, 2012 in Hacks | 0 comments

The newer Airport Express’ are a quick 20 minute hack away from being able to be powered by anything giving out 3.3V or higher. So if you feel the need for a USB powered Airport Express in your car that you can Airplay music to, read on.

Why would you want to ever Airplay music to a car? Well not all cars have A2DP, which is a total car making scam. Maybe you’d like to play music from your laptop, or just plain hate auxillary cables all over the car. In any case, its quite easy to swap out the standard power supply form an AE with something more car friendly. Sure you could hook up the AE to an inverter, but apparently the alternator gives you a hiss on the sound quite often from poor grounding. Ok. Enough with the why. A simple “Because I can” would have been good enough.

Read on for instructions

Read More

ATTINY85 – Good things do come in small packages

ATTINY85 – Good things do come in small packages

Posted by on Sep 27, 2012 in Hacks, Reviews | 0 comments

The ATTINY85 is a gem of a microcontroller. Its the “Nifty Fifty” of chips: cheap, small and versatile. This 8pin package is not the most powerful thing on the block but for good enough for most hobbyists and there are a million and one tiny projects that this is fully capable of running. And at $1-$2 a pop, its really hard to beat. Its almost disposable if you order a bunch for all your random little projects. It does take a bit more setup than an Arduino to get it running, but there are lots of easy to follow tutorials on the internets for people to follow. If you have an Arduino sitting around, its quite easy to use it to program the chip as well.

Most of my hobbies don’t get along with my bank account so its nice to find the little things that can be so interesting. So pick up a few and whether you make something useful or just plain silly, rest assured, it’ll be fun!

Inspiration here: ATTINY85 on Hack-a-Day

Read More

[Review] Newark / element14 where have you been all my life…

[Review] Newark / element14 where have you been all my life…

Posted by on Sep 26, 2012 in Reviews | 2 comments

If you’ve never used Newark/element14 and find yourself disappointingly rummaging through your local electronic hobby parts store, read this review.

There’s great electronic component vendors out there. The local ones are all brilliantly expensive or have limited components in stock (Active Electronics and Sayal). I love Creatron Inc but they have relatively small selection and their website has even less and that’s me being generous. I’ve lately been ordering all my components from eBay vendors in China/HK and they have amazing prices and with free shipping its hard to beat. But 14-30 days wait time for deliveries to Toronto? I’m much too impatient, sorry. I’m lucky if I remember what I ordered 14 days later. So for huge supplies of assorted resistor, capacitor, etc. packs, eBay is great. I’ll need that stuff sooner or later anyway.

Now lets talk about Newark/element14.

  • Price: Its well priced. Not always as cheap as eBay but nowhere near retail.
  • Selection: MASSIVE. End of story. Hit search with an empty query and it finds 1,347,263 items. *drool*
  • Quality: Awesome. You get what you pay for on eBay and retailers often have rummaged through stuff thats been sitting on the shelves for a while.
  • Packaging: #winning! Here’s what impressed me the most. Take a look at the image below. Its stuff I’ve ordered off eBay vs Newark. There’s like 8 packs of Sorb-It (silica gel?)  and a “Cobalt Dichloride Free” (uhhh what?) chemical test strip thing in a sealed ESD bag, all packaged in a large cardboard box with appropriate packing materials inside. Overkill probably. I don’t even know what that chemical test strip is for and I’m pretty sure 8 packs of gel is way too much for 25 SMD LEDs but I love it! LOVE IT! Also the LEDs are in more ESD tape itself. The UPS guy could have thrown the box from a plane in the middle of a lightning storm and this would be fine.
  •  Shipping:  Any faster and I’d receive it before I even think about ordering it. I ordered over a dozen items yesterday morning and it was at my door this afternoon. And it came from the US. Things from the city itself takes longer sometimes. And this was their standard UPS shipping.
  • The only downside? At $12 for flat rate shipping to Canada, its quite expensive for regular small orders. My $20 bill almost doubled with the shipping and taxes. Its fine if you have to order a lot of things but I can’t keep ordering everything I fancy like I do on eBay.

Can you tell which is from element 14 and which is from HK?

Read More

Raspberry Pi + Temperature Sensors

Raspberry Pi + Temperature Sensors

Posted by on Sep 25, 2012 in Uncategorized | 8 comments

I have a Pi, and a couple of sensors to test with. Namely an LM-35, LM-335 (aka TMP36), DS18B20 and RHT03 (which is the same as the DHT22)

I2C – DS18B20

Occidentalis so far only has I2C support on GPIO pin #4 as far as I can tell, so that’s where the I2C based DS18B20 goes. Here is a bit of code to poll the chip every few seconds:

# This little example code checks and parses the temperature from
# a DS18B20 connected to GPIO 4 on the Raspberry Pi running Occidentalis
# By Monirul Pathan

# Connect a DS18B20 with VCC to 3V, ground to ground and Data
# to GPIO #4. Then connect a 4.7K resistor from Data to VCC.

# Rus on Occidentalis: http://learn.adafruit.com/adafruit-raspberry-pi-educational-linux-distro/occidentalis-v0-dot-1
# Thanks Adafruit for the awesome RPi distro =)

import glob
import time
import os
import datetime

#initialize the device
os.system("sudo modprobe w1-gpio")
os.system("sudo modprobe w1-therm")

print "DS18B20 - Raspberry Pi"
#find the device
devicedir = glob.glob("/sys/bus/w1/devices/28-*")
device = devicedir[0]+"/w1_slave"

while True:
#open up the file
f = open (device, 'r')
sensor = f.readlines()
f.close()

#parse results from the file
crc=sensor[0].split()[-1]
temp=float(sensor[1].split()[-1].strip('t='))
temp_C=(temp/1000.000)
temp_F = ( temp_C * 9.0 / 5.0 ) + 32
now = datetime.datetime.now()
dtime = datetime.time(now.hour, now.minute, now.second)

#output
if 'YES' in crc:
print dtime,":\t",temp_C,"*C\t",temp_F,"*F"
else:
print dtime,"\tCRC check failed."

#wait 5 seconds and repeat
time.sleep(5)

Wire it all up with a Cobbler, a breadboard, some wires, and the 4.7k resistor. Then put the above code into a whatever.py file and run “sudo python whatever.py” and voila, you’re getting temperature readings from the DS18B20 every 5 seconds.

Note: It often fails on my end (about 10% of the time) but that’s not terrible.

 

Analog – MCP3008 + LM35/LM335

The MCP3008 is an analog to digital converter that works beautifully with the Pi. This tutorial on using a potentiometer to control volume got me started. So I hooked up an LM35 and an LM335 (which I believe is the same as the TMP36) to the first 2 of 8 analog inputs on the chip.

The conversions were a bit trickier and I still don’t have it down to something I can fully trust but it gets me within 1*C of the room temperature.

#!/usr/bin/env python
import time
import os
import RPi.GPIO as GPIO
import glob
import datetime

#initialize the DS18B20
os.system("sudo modprobe w1-gpio")
os.system("sudo modprobe w1-therm")
#find the initialized device
devicedir = glob.glob("/sys/bus/w1/devices/28-*")
device = devicedir[0]+"/w1_slave"

#get values from the ds18b20
def getC () :
#open up the file
f = open (device, 'r')
sensor = f.readlines()
f.close()

#parse results from the file
crc=sensor[0].split()[-1]
temp=float(sensor[1].split()[-1].strip('t='))
temp_C=(temp/1000.00)

#output
if 'YES' in crc:
return temp_C
else:
return 999.99

 

GPIO.setmode(GPIO.BCM)
DEBUG = 1

# read SPI data from MCP3008 chip, 8 possible adc's (0 thru 7)
def readadc(adcnum, clockpin, mosipin, misopin, cspin):
if ((adcnum > 7) or (adcnum < 0)):
return -1
GPIO.output(cspin, True)

GPIO.output(clockpin, False) # start clock low
GPIO.output(cspin, False) # bring CS low

commandout = adcnum
commandout |= 0x18 # start bit + single-ended bit
commandout <<= 3 # we only need to send 5 bits here
for i in range(5):
if (commandout & 0x80):
GPIO.output(mosipin, True)
else:
GPIO.output(mosipin, False)
commandout <<= 1
GPIO.output(clockpin, True)
GPIO.output(clockpin, False)

adcout = 0
# read in one empty bit, one null bit and 10 ADC bits
for i in range(12):
GPIO.output(clockpin, True)
GPIO.output(clockpin, False)
adcout <<= 1
if (GPIO.input(misopin)):
adcout |= 0x1

GPIO.output(cspin, True)

adcout /= 2 # first bit is 'null' so drop it
return adcout

# change these as desired - they're the pins connected from the
# SPI port on the ADC to the Cobbler
SPICLK = 18
SPIMISO = 23
SPIMOSI = 24
SPICS = 25

# set up the SPI interface pins
GPIO.setup(SPIMOSI, GPIO.OUT)
GPIO.setup(SPIMISO, GPIO.IN)
GPIO.setup(SPICLK, GPIO.OUT)
GPIO.setup(SPICS, GPIO.OUT)
# temperature sensor connected channel 0 of mcp3008
lm35_adcnum = 1
lm335_adcnum = 0
while True:
# read the analog pin (temperature sensor LM35)
read_lm35 = readadc(lm35_adcnum, SPICLK, SPIMOSI, SPIMISO, SPICS)
time.sleep(0.5)
read_lm335 = readadc(lm335_adcnum, SPICLK, SPIMOSI, SPIMISO, SPICS)

# convert analog reading to millivolts = ADC * ( 3300 / 1024 )
lm35mv = read_lm35 * ( 3300.00 / 1024.00)
lm335mv = (read_lm335-760) * ( 3300.00 / 1024.00)
# 10 mv per degree

lm35_C = (((lm35mv) / 10.00)-1.50) #LM35
lm335_C = ((lm335mv/10.00)-1.00) #LM335
ds18_C= getC()

# convert celsius to fahrenheit
lm35_F = ( lm35_C * 9.00 / 5.00 ) + 32.00
lm335_F = ( lm335_C * 9.00 / 5.00 ) + 32.00
ds18_F = ( ds18_C * 9.00 / 5.00 ) + 32.00

# remove decimal point from millivolts
lm35mv = "%d" % lm35mv
lm335mv = "%d" % lm335mv

# show two decimal place for temprature and voltage readings
lm35_C = "%.2f" % lm35_C
lm335_C = "%.2f" % lm335_C
ds18_C = "%.2f" % ds18_C

lm35_F = "%.2f" % lm35_F
lm335_F = "%.2f" % lm335_F
ds18_F = "%.2f" % ds18_F

if DEBUG:
print "DS18B20 :\t ADC: NA \t MV: NA \t C:",ds18_C,"\t F:",ds18_F
print "LM-35 :\t ADC:",read_lm35,"\t MV:",lm35mv,"\t C:",lm35_C,"\t F:",lm35_F
print "LM335 :\t ADC:",read_lm335,"\t MV:",lm335mv,"\t C:",lm335_C,"\t F:",lm335_F

#os.system("cat /sys/bus/w1/devices/28-*/w1_slave")
#print "temp_F:\t\t", temp_F
print "\n\n"
# hang out and do nothing for 10 seconds, avoid flooding cosm
time.sleep(5)

Because the MCP3008 is talking to the Pi through SPI, it is a lot more reliable and I have yet to see a wacky reading (except that one time my cat stepped on the breadboard)

 

1-Wire (ish?) – DHT-22

There is some example code on the interwebs with the DHT22 but I have yet to get any readings out of it. Its a shame since it is one of the cooler components as it has a humidity sensor built in as well. I’m pretty sure this will get sorted out in a few weeks though.

Read More

Raspberry Pi Thermostat

Raspberry Pi Thermostat

Posted by on Sep 24, 2012 in Thermostat | 0 comments

The Raspberry Pi is probably the best thing to happen since the Arduino in terms of low cost systems that don’t requite an engineering degree to get started with. At $35 it is tremendously powerful and like the Arduino, has a great community working on a bazillion projects, almost all of which are open source.

Although the Pi was mainly intended to make programming and computing accessible to younger children all over the world (remember OLPC?), with its inclusion of its General Purpose Input/Output (GPIO) connectors, it makes for every hardware hackers’ wet dream. The little pins allow the RPi too be able to communicate digitally to all sorts of components: LEDs, sensors, relays, etc.

On the Pi’s initial release, GPIO support was kinda-sorta-there. Few months in and its as easy as Pi. (Hah see what I did there? =) ) The board runs Linux and there are several great distributions around, but for anyone experimenting with the GPIO, I would very highly recommend going with Adafruit’s Occidentalis. With a bit of python code that comes baked in, you’re ready to start plugging in all sorts of components in a matter of minutes.

Since my thermostat at home sucks, I’ve been playing around with making one out of a Pi. There are essentially 3 steps to this.

  1. Have the Pi detect the temperature. (Input)
  2. Know when to turn the fan, heater or ac ON or OFF (Logic)
  3. Turn on the right switches (Control)

Sounds simple enough. Time to get to work!

 

Read More