If your ruby serial port doesn't read what' you're sending...
Some days ago I got my Novation launchpad an immediately started hacking with some Ruby and Arduino flavor. I wanted to port ccb23 Raindrops Project to launchpad.
For that, I needed Serial communication within ruby. Thanks to ruby-serialport first steps went quite well. I could write OR read from and to Arduino easily. But for some reasons, writing AND reading using the same instance didn’t work out.
I used a simple ‘send-input-back’ sketch on the Arduino side. So every byte I’m sending is returned back. I checked with the Arduino IDE Serialmonitor and a simple Processing script - everything worked alright. But using ruby it was different. Writing to serial port worked okay, but reading from it was just random. Sometimes I read the response, sometime I didn’t - really, really weird. Some headaches and a lot of time testing I finally found the solution: just open two instances of the serial port. One for sending, one for reading - and, surprise, surprise - it works perfect! Who would have guessed that!? Strange..
[ruby]
// To be completed
require ‘serialport’
port_write = Serialport.new()
port_read = Serialport.new()
[/ruby]
Ok, continuing hacking, more soon…
How to sync my mp3 Songs rating in iTunes across multiple Libraries
By now, I havn’t find any good solution to share my mp3 across multiple systems and disks. I’ve some on my local machine, some at work and some on my external harddisk to archive. Luckily, when copying my tracks to another library duplicates are ignored. But what annoys me most is that my ratings don’t get copied, as iTunes doesn’t store it within the file. Some while ago I found a solution by storing the number of stars into the ‘Grouping’ Field, so I can recover the rating afterwards. Now, I came up with this little applescript do automate the write and recover process. Just run this script, copy you mp3 to the other library, run the script again, and voilá, you ratings are back - nice!
[shell]
(* small apple script to save rating into grouping field and
vice versa. Perfect to persitent store your rating witin the file
*)
tell application “iTunes”
repeat with stars from 1 to 5
set rating_value to stars * 20
set group_name to “” & stars & “ Stars”
set sel to (every track whose rating is rating_value and grouping is “”)
repeat with aTrack in sel
tell aTrack
set grouping to group_name
end tell
end repeat
set sel to (every track whose rating is 0 and grouping is group_name)
repeat with aTrack in sel
tell aTrack
set rating to rating_value
end tell
end repeat
end repeat
end tell
[/shell]
Btw. for each Star rating I do have a smart playlist which allows me to find those quickly.
Ruby: a nice way to get name of current method you're in:
This is a nice extension to get the name of the method you’re currently in (Ruby < 1.9)
[ruby]
module Kernel
private
def this_method
caller[0] =~ /`([^’]*)’/ and $1
end
end
[/ruby]
for Ruby >= 1.9 you can uses this:
[ruby]
module Kernel
private
def this_method
method
end
end
[/ruby]
[see Stack Over Flow as well]
Lot's of Ruby and Rails Tricks
Quick, short post I always had in the queue:
Check this out, here some lists of good techniques to get started and to impove your Ruby and Rails code:
http://nettuts.com/articles/web-roundups/10-awesome-ruby-on-rails-techniques-to-get-you-started/
http://www.rubyinside.com/19-rails-tricks-most-rails-coders-dont-know-131.html
http://www.rubyinside.com/21-ruby-tricks-902.html
[Awsm picture taken from DesignShark]
Orangutan Robot Controller
Ui, I just stumbled over the Orangutan Robot Controller. Funny, as it’s name is similar to this blogs name ;-)
http://www.pololu.com/catalog/product/225 - to bad is has discontinued
Programming Interactivity: A Designer's Guide to Processing, Arduino, and openFrameworks
I just stumbled upon this interesting sounding book by Joshua Noble:
Programming Interactivity: A Designer’s Guide to Processing, Arduino, and openFrameworks.
A few of the topics covered: Basic C, Processing, openFrameworks, Gesture and touch recognition, Motors and Servos, LEDs and LCDs, LilyPad and many more! - Wow, that’s sounds promising - wanna have!
mtXcontrol wins the Seeedstudio Rainbowduino Carnival
Yay - the voting for the Seeedstudio Rainbowduino Carnival Competition is over. And, guess what, my project mtXcontrol made the run - I won the first price! Yipheee.. that’s 12x Rainbowduinos + 100$ Shopping voucher which I’ll invest in buying Xbee Stuff.. Can’t wait to get my hands on! Stay tuned…
Thanks to everybody voting for my project!
Btw. I just released the latest version 1.02 with some bugfixes and new features in the API…
Rainbowduino Carnival Competition Voting has started
As mentioned in earlier post, I submitted the first public version of mtXcontrol to the Rainbowduino Carnival Competition by Seeedstudio. Now it’s time to vote for the best projects:
I know, the decision will be quite hard, as a lot of other cool projects were submitted as well. Like this cool Daft Punk Helmet or this nice lipsync speaking Robot…
Please check out the Raindrop Rainbowduino Game by my friend ccb23 as well. It’s a Rainbowduino connected via I2C to an Arduino with an Accelerometer. With that you can move the red dot on the Matrix and avoid hitting the falling blue raindrops. nice!
As contribution for Seeedstudio Carnival I’m proud to release the version 1.0 of mtXcontrol today. It’s feature list extended quite a lot, beside new frame editing features like Frame moving and Copy & Paste, it now comes with Letter / Number placer to easily draw characters. Additional the frame preview bar makes it easily to navigate between the frames. As of this, it was time to get an proper UI with lot’s of buttons for those who couldn’t remember all those keyboard shortcuts (like me ;-))
So check out this Demo:
Check out it’s new project page with details, video and sources to download:
http://www.rngtng.com/mtXcontrol
Understanding the Rainbowduino Controller by Seeedstudio
As you may know, I’ve orderd a Rainbowduino from Seeedstudio. They delivered quite fast and I’m very happy of the price/quality/functionality ratio. In my opinion, the Rainbowduino is the cheapest ready-to-go 8x8 RGB LED Controller Set at the moment - for just 43.4$ ( 19.90$ Board + 23.50$ Matrix) you are set for taking of!
My first tests went quite well. The Rainbowduino comes with a ready to use the program/sketch which allows you basic controls via I2C bus easily, like writing letters & lines in different color and light strength. But soon I hit the limits when it came so single control each LED to my will. So no doubt, I had to dig deeper in understanding how to control the Rainbowduino. Here a short summery of my results:
To understand how the Rainbowduino works, I kind of reverseengineered the sketch by seeedstudio which came with the controller. As usual for driving those Matrixes, PWM is used as basic concept. This means the frame image is created row by row by high frequency, so human eye puts it all together to one single image.
To simplify this process I created the Rainbowduino.h Library, which comes with some nice methods to set frames and draw those to the Rainbowduino. It’s part of the mtXcontrol firmware an can be downloaded from github
How it works:
To tell rainbowduino which row to draw the method ‘open_row’ is called. As each row is represented by a one output PIN, this method sets the according PIN to high, all others to low. Unfortunately the row pins are not all on one port: rows 1-3 are on PORTB Bit 1-3, rows 4-8 are on PORTD Bit 4-8. This makes the method kind of bit ugly ;-)
After the row is selected, its time to set the pixels. One pixel consists of 3 LEDs: red, green & blue. Each LED has to be separately to high or low to mix the final color (e.g. red + green is yellow). First all blue values of a row are set, then red and finally green. This happens in serial on PORTC. First bit is the value input, second bit is clock, bit 3 the write mode bit and bit 4 to display the shifted value. Call the method ‘draw_row’ to display a row. First parameter is the row number (0-7), second the intensity (1-16) and then the red, blue & green values for the row. e.g passing the color values 1,0,0 would light the first pixel red and all other off, where as 255, 255, 255 would light up all LED and all colors, to the full row would be white.
To store the row values the Library comes with a frame buffer for 10 frames. (That the amount of frames we can store to EEPROM without compression as well). You can pre fill the buffer and set the frame number to display. By calling draw() the frame of the current _frame number is drawn.
It makes sense to call this function by a timer interrupt to not disturb your actual program progress and to ensure it’s call in regular frequency to avoid different display colors.
To set up the timer, include this in your code:
[c]
Rainbowduino rainbow = Rainbowduino(10); //max 10 Frames
void setup_timer() {
TCCR2A = 0;
TCCR2B = 1<<cs22></cs22> TIMSK2 = 1<<toie2></toie2> TCNT2 = 0;
sei();
}
ISR(TIMER2_OVF_vect) {
rainbow.draw();
}
[/c]
Now, just fill you frames with
[c]
rainbow.set_frame(0, *data);
[/c]
and your’re ready to go. Have fun!
First tests of the library with earlier version of mtXcontrol, an Editor to create images on the Matrix easily:
http://www.youtube.com/watch?v=MVj1YPzREKI
Stay tuned for more examples soon…
Nabaztag:tag arrived - meet Nabaccia!
Yay, my new toy has arrived: It’s a Nabaztag. Short story: I first met the rabbit in 2007 at re:publica conference @ Berlin, and always want to have one since then. Nabaztag is a rabbit connected to the Internet with moving ears, 4x color LEDs, a RFID reader, a button and Sound In & Output. It’s hard to understand why one wants to have such rabbit, but the idea to connect things with the internet sounds very interesting to me. But just for playing around, it was to expensive … till now!
Sadly (well, luckily for me) Violet, the producer of Nabaztag, is on it’s way to bankruptcy. As of this MyRobotcenter started selling them half price - nice! I couldn’t anymore resists buying and got the rabbit+mirror+zstamps for a good price - that’s all right!
According to violet, each thing needs a name, so mine is called Nabaccia , listens to emails via nabaccia - things.violet.net and, of course, twitters here as well. So, now it’s time to hack the rabbit. I saw a couple of interesting project out there, let’s get it on! More on this soon!
I know it’s totally wired and hard to understand why, just don’t ask ;-)
Image by Liron - thx!
Rails flag_shih_tzu Plugin with named_scope
When it comes to store a load of boolean data into your model you easily end up with lots of columns which blow up your table unnecessarily. The developers at Xing solved this problem with a nifty Rails Plugin called flag_shih_tzu. The trick is to store all boolean values combined as a bit vector, which allows you to put up to 32 values (4Byte) within a single Integer column. Automatic generated access methods allows you to deal with you model as your are used to. Wanna see an example? (Taken from plugin docs)
[ruby]
class Spaceship < ActiveRecord::Base
include FlagShihTzu
has_flags 1 => :warpdrive,
2 => :shields
end
enterprise = Spaceship.new
enterprise.warpdrive = true
enterprise.shields = false
enterprise.save
enterprise.warpdrive? #=> true
enterprise.shields? # => false
[/ruby]
Nice, isn’t it?
Unfortunately named scopes where missing for selecting models easily. So another github fork, another fix, and here were are. Now this works as well:
[ruby]
Spaceship.flagged(:warpdrive).not_flagged(:shields).all
[/ruby]
Check it out here: http://github.com/rngtng/flag_shih_tzu/tree/master
Update: replaced ‘routes’ with ‘scopes’ - I’m getting confused with that all the time, how come!? ;-)
Quake like Terminal on Mac OS X: Visor Plugin
Sure you do remember Quake. And sure you di remember how cool the console faded / slided in from the top? Image this would be available for your Mac OS X Console/Terminal. Well now (actually since ages, but I just forgot to mention ;-) it is. As small SIMBL plugin called Visor Plugin allows to to bring up the Terminal via a hotkey in anytime. I really love it and can’t without it anymore.
Check it out here: http://visor.binaryage.com/
As you know I’m quite fond of working with Active Scaffold (AS) for data administration proposes. Quite recently we moved over to the RoR paperclip attachment plugin for file upload handling. I was even more happy to see a Active Scaffold bridge which integrates paperclip smoothly into AS as well. It’s created by and hosted here on github.
Unfortunately it didn’t provide the possibility to delete or update an image once it’s assigned to an object. Well no problem, another fork of mine, some coding and now it possible. I basically reused to code of the as_file_column_bridge. Check it out here:
http://github.com/rngtng/as_paperclip_bridge/tree/master
Update: changes got merged into trunk, check it out:
http://github.com/mnaglik/as_paperclip_bridge/
Stealth Project on a Nova 10x10x10 LED Cube
Hey guys, look at this: I just found this awesome project by Squidsoup. They put up a 10x10x10 LED Cube “NOVA 3D LED” (yes, 3 dimensions, yes that’s 1000 single controlled LEDs) and created cool stuff like webcam projection or a the “Stealth Project” , a game similar to Battleships. Just get it’s great sounds and projections:
More on this here: http://www.squidsoup.org/stealth/
[via nejo0017.wordpress.com]