Wednesday, May 13, 2009

Twittering from the linux command line using curl

Recently I signed up for twitter and have found the need to "twit" from the command line. I found a quick tutorial on how to use curl to send twitter updates here: http://foxyurl.com/2CK

I've decided to extend it a little bit by adding some error checking. I called the script "twit". Here is the source code:


#!/bin/sh

user="someuser"
pass="somepass"
curl="/usr/bin/curl"

if [ ${#@} -gt 140 ]; then
echo "The update you are attempting to send is ${#@} characters long."
echo "Maximum update length is 140 characters. Twitter update was not sent!"
exit 1
fi

$curl --basic --user "$user:$pass" --data-ascii \
"status=`echo $@ | tr ' ' '+'`" \
"http://twitter.com/statuses/update.json" > /dev/null 2>&1

if [ $? -ne 0 ]; then
echo "Curl returned a non zero return code. Failed sending twitter update!"
exit 1
fi

exit 0



Nothing groundbreaking I know but it works as well enough.

I would probably make sure that you are the only one who can read this script as it has your password in plain text. To do this you can type: "chmod 700 twit".


Tuesday, November 4, 2008

Arduino LED MIDI Controller


It's been a while since I've made a post so I have decided that it was about time I did. This time I'll be talking about my Haunted House I made.

I started with the idea to take a Halloween decoration (small haunted house) and add some LEDs to it and make them blink. What I ended up with was a haunted house with 6 LEDs in it all controlled by MIDI. I used an Arduino to receive MIDI signals from my computer and turn on/off LED lights based on those signals.

Check out the video...




The "MIDI to Arduino Breakout Board" as I call it in the video I designed myself. I used various resources on MIDI around the web and came up with this schematic.




Digikey Part list:


2 x DIN5 - CP-2350-ND
2 x 6N138 - 516-1600-5-ND
1 x diode - 1N914B-ND
2 x 220 ohm resistor
1 x 270 ohm resistor


As you can see it isn't very complicated. The hardest part was finding in DIN5 part numbers at Digikey. The code on the other hand was a bit more complicated. The trick was to decode the MIDI signals without any real debugging tools. The RX/TX ports on the Arduino are being used by the MIDI ports. I had to use blinky LED lights to do the debugging. After fumbling around with it for a while I was able to get it working. The code should easily be expendable to allow for more LED lights. I chose to use the PWM pins on the Arduino so I could adjust the brightness of the LEDs.

I tried to comment the code the best I could. Download it here. Keep in mind that you must disconnect the MIDI breakout board before you program your Arduino or it wont work.


Side Node:

Unfortunately MIDI is meant for instruments and not lights so I wasn't able to really do what I wanted to do. As a future project I would like to implement MIDI show control to allow for more light specific functions. I still have to find a freeware program that supports MIDI show control. I'll keep you posted.

Monday, January 7, 2008

Ardunio and the SHT15

For my ongoing thermostat project I require some sort of temperature and humidity sensor. Because I'm fairly new to all this I decided to get a 2 in 1 sensor from Robotshop called the SHT15. I went with the SHT15 because it had both a temperature and humidity sensor and uses a "digital 2-wire" interface. When I first purchased it I didn't realize that "digital 2-wire" didn't mean I2C, but that's another story.

In order to get the sensor to communicate with the Arduino I needed to write some custom code that manipulates the data and clock lines by pulling them high and low at the correct times. I haven't had any experience doing this before so it was a learning experience for me.

Connecting the SHT15 to the Arduino is pretty simple. The data and sck lines each goto a digital input/output on the Arduino and the VCC goes to +5V. Pretty simple. Here is a picture of my breadboard.



As you can see I had to solder on some breadboard wires onto the SHT15 breakout board. It's been a while since I've soldered so it was good practice. NOTE: You can decouple the power supply pings (VCC, GND) with a 100nF capacitor.

Onto the code! As I said before I used the C source code from the website to help me with getting all the timing right. After a few short hours of some frustration I was able to get it working. One thing I didn't get working was outputting the actual temperature/humidity values in human readable form. The numbers that the SHT15 returns require you to plug them into a formula before they will make sense to us. The formulas can be found in the SHT15 datasheet. There are a few functions that I have yet to implement such as the heater but it shouldn't be too difficult.

Here is my source code (now on GitHub): serial_temp_humidity.pde

Enjoy! Feel free to ask me any questions. I'm out.

Thursday, December 27, 2007

First Ardunio Program

I have finally received my Arduino and have been able to write a few simple programs for it. For my thermostat program I am interested in being able to read several analog sensors (temperature and humidity). I also need to be able to poll specific sensor values from the computer using the serial interface so I can log their values in 5 minute intervals. I don't have all the electronic components yet to build my thermostat so I wanted to write up some test sketches. I based my sketches on a todbot blog entry that I found very useful.

I was originally going to use the C code that todbot wrote to test communication with the Arduino but I soon realized the limitations. What I ended up doing is using "screen" to open a terminal connection to the serial port so I could send and receive data to/from the Arduino. In the future I will have to write a daemon that will run on my linux box that will constantly poll the Arduino for data but thats another story. For now screen will work.

Download serial_tty.pde for the source code.


Using Screen


On my Mac all I had to type to communicate with my Arduino running the above sketch was:


screen /dev/cu.usbserial 9600

To "kill" your screen session you have to type: ctrl+a k


Hope you enjoy. I'm out.

Tuesday, December 18, 2007

Arduino shipped!

I love ordering things in the mail. It's the waiting I don't like. I ordered my Arduino along with a temperature/humidity sensor from Robotshop on Friday afternoon and they shipped it yesterday. Not a bad turn around time at all. According to the Canada Post website it is currently in Quebec somewhere. Now all I have to do is wait for it. I know it's a crazy time of year so we'll see how Canada Post is handling it.

Now all I have to do is find some time to goto Active Electronics and buy a prototyping board and a bunch of misc parts. I can't wait!

I should go do some work... I'm out.

Wednesday, December 12, 2007

Thermostat project (take 2)

Yes I am still on the thermostat kick. I just got my new humidifier installed today which is probably why I am still looking at my thermostat project. After some consideration I have decided that I'm going to scrap the whole gumstix idea. The reason I'm doing this is simply because I don't need that much computing power bolted to my wall. I've decided that the thermostat itself should be an Arduino using I2C to talk to a Temperature and Humidity sensor. Then I would have to design the circuit that would turn the furnace on and off. I have found some good documentation of how a regular thermostat works so it shouldn't be much of an issue getting that going. The Arduino would control the furnace and air conditioner, fan and humidifier. One added feature (the whole point of the project) would be to use the USB interface on the Arduino to connect to a LAMP server that would log all temperature and humidity levels and send commands to the Arduino. I just have to figure out how far the USB cable can actually be before I pursue this option any further. I may have to use some other communication methods.

I'm tired... out.

Monday, December 10, 2007

Thermostat project

It's that time of year again. Winter has hit full force here. I've been on an Arduino kick lately and came up with an idea for a project to battle the cold weather. A thermostat connected to your home network!! Why would you want to do that you ask? The answer is simple, I want to be able to control the temperature of my house from anywhere! If security is a concern then you could limit control to your local network (but that's another discussion).

Hardware:
First you would start with a gumstix connex 200xm along with a rs232 expansion board and an ethernet expansion board with a microSD interface for more storage. You could also go WiFi if you so desire. You will also need a temperature and humidity sensor with a serial interface.

Software:
The software system would be as simple as running a LAMP (Linux, Apache, Mysql, PHP) server. Of course I would have to develop some software to get the temperature readings from from the sensors and for controlling the furnace. The Mysql server would be used to log temperature/humidity levels and when the furnace and AC are firing. The Apache server would allow you to control the furnace remotely. You could also automate the temperature in your house. The possibilities are endless :)

The major problem would be to somehow control the furnace/AC. I have to figure out exactly how a furnace works yet before I can design that circuit. I might have to re-think the hardware required and add a robostix to the mix. We'll see.

In the end you would have a completely automated thermostat for your house! Perhaps you could also add X10 capabilities. Very cool.

Until next time. I'm out.

Twittering from the linux command line using curl

Recently I signed up for twitter and have found the need to "twit" from the command line. I found a quick tutorial on how to use ...