Little fun with Aurdino compatible board

All my professional life had only been about software and I never really had any exposure to electronics. Arduino was in my radar but I thought I would just keep it in the box like I did with another large electronics kit I got more than a decade ago. But then, I saw the “$9 ARDUINO Compatible STARTER KIT” and so went and pledged. After a couple of months, the kit arrived but it was sitting in the shelf. Part of the reason is that I changed jobs and it’s been very busy. This crowd sourced project has been very well executed. So, as soon as the same owner started another project that supplements the first, I pledged for it and as part of that decision I thought I would at least give the board that’s already with me a try.

So I set up the Arduino IDE (which seems to still require Java 1.6 so had to down load that) and tried out a few samples. Coming from software background the difficult part for me is following the schematics for the hardware and debugging if something went wrong. Soon I wanted to write something of my own. So I modified the ButtonStateChange example and converted into what I call a Guessing Game. In the ButtonStateChange everytime the button is pressed 4*x times, it glows. Instead, I modified it to glow after every n times where n is between 2 and 4 inclusive. I am sure no adult would probably consider it as a game. However, my 4 yr old son and I had a lot of fun with it. We took turns and one of us would guess and the other would press it to see if it LED glowed as per the guess number of pushes or not. If it did, the one guessing would win.

Here is my little program if you want to make your “beginner tutorial” a bit more fun.

/*
* Guessing game
* Guess a number between 2 to 4. Press the button those many times.
* If the LED glows on the exact count, guessing person wins
* Otherwise, the person pressing the button wins.
* Circuit: same as http://arduino.cc/en/Tutorial/ButtonStateChange
*/

// this constant won’t change:
const int buttonPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to

// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
int rcount = random(1,5);
boolean pushed = false;

void setup() {
// initialize the button pin as an input
pinMode(buttonPin, INPUT);
// initialize the LED as an output
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
// initialize serial communication
Serial.begin(9600);
}

void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
pushed = false;
// if the button is pushed, increment the counter
if (buttonState == HIGH) {
buttonPushCounter++;
pushed = true;
}
}
else {
return;
}
lastButtonState = buttonState;
if(!pushed) return;
if (buttonPushCounter == rcount) {
buttonPushCounter = 0;
digitalWrite(ledPin, HIGH);
if(pushed)
rcount = random(2,5);
} else {
digitalWrite(ledPin, LOW);
}
}

WordPress seems to be messing up with the code formatting. But the code is very small for someone to read and understand it.

Posted in Uncategorized | Tagged | Leave a comment

Fix for iMac getting too hot

Recently I noticed that my iMac was getting too hot. This even after running an external fan next to it. It’s late 2009 model and more than 3 yrs old. It is likely that it’s clogged inside with dust. I tried my best to get rid of the dust along the various vents in the back. But it’s still getting hot. For example the Secondary Heat Sink has gone to a max of 96 degrees Centigrade! Yes, that’s a C and not F. The machine hasn’t shutdown or panic. I was :).

Researched online and tried a few options but nothing worked. It appears that the latest version of OS X, perhaps starting from Lion, the fans are not started up to a very high temperatures. Infact, the Intel Core i7 CPUs can apparently withstand up to 130 degrees C. Perhaps the iMacs that came in 2010 and later have something special that these later OS X versions were able to keep the fans low. That I don’t know. But I fixed my problem with a simple cron job that adjusts the fan temperature based on the Secondary Heat Sink temperature (I choose this sensor because this is the temperature that is reaching the max).

Below is the script and it uses two freely available software. One is smcFanControl. This allows adjusting the fan speed. The other is TemperatureMonitor that provides the temperature reading. Both these programs have GUI, but they also offer command line interface. So, the following shell script setup as a cron to run every 2 minutes adjusts the temperature and now I don’t even have to bother about turning on the external fan.


#!/bin/sh

smc=/Applications/smcFanControl_2_3/smcFanControl.app/Contents/Resources/smc

T=`/Applications/TemperatureMonitor.app/Contents/MacOS/tempmonitor -l -a | grep 'SMC SECONDARY HEATSINK' | sed -e 's/.*: \(..\) C/\1/'`

if test $T -ge 90;
then
# set Fan 2 to forced mode
$smc -k "FS! " -w 0004
$smc -k F2Tg -w 1F40
#echo "setting fan to 2000 RPM"
elif test $T -ge 80;
then
# set Fan 2 to forced mode
$smc -k "FS! " -w 0004
$smc -k F2Tg -w 1770
#echo "setting fan to 1500 RPM"
elif test $T -ge 70;
then
# set Fan 2 to forced mode
$smc -k "FS! " -w 0004
$smc -k F2Tg -w 12C0
#echo "setting fan to 1200 RPM"
else
# set Fan 2 to forced mode
$smc -k "FS! " -w 0000
#echo "setting fan to auto"
fi

I just experimented and setup 3 different fan speeds for 3 different temperature ranges. I am not sure if this is the most optimal. Once you play around with this, you get the idea and you can adjust as per your needs.

Update: I upgraded to OS X 10.9 (Maverics) and it seems the OS is doing it’s job of turning the fan on. So, I disabled my cron job. If I see the system heating up again and the fan not working, I will turn it on. Also, based on how the OS is turning the fan on, may be I need to adjust the above values which seem to be on low for the span feed.

Posted in Uncategorized | Tagged | Leave a comment

Where to buy LEGO sets that are not retired

Recently I was looking at a few LEGO sets for my son (and me :)) and did a bit of research on LEGO. I used to think LEGO was either their robotic edition (Mindstorms) or those simple rectangular blocks which you use to make various shapes. Only recently did I come to know about their various themes the favorite of mine being the LEGO Technic. Me being an engineer, it probably may be understandable. I chanced upon LEGO Technic when I was researching 3D Printers. A few creative minds have created interesting 3d machines (one is like a lathe, another which can build a house by picking bricks, another one is a paper folder, yet another one that can knit a piece of cloth!)

One of the things I soon learned is that some LEGO sets end up being classics that should be owned by the LEGO fans. However, LEGO retires a set after a couple of years (or may be months, don’t know the exact duration). So suddenly there is no supply and even a small demand makes the price of these sets to sky rocket.

One such set I am interested in is LEGO 8043 which has a lot of power functions (you can use a remote control and control the various features). While scouting Amazon and eBay I noticed that even the sets that are currently available are also being sold on these websites by 3rd parties. This is the part that I don’t get and hence just thought of writing this down.

LEGO offers something called VIP program which is free. It allows accumulating points where when you spend $100 on their website, you get $5 worth of points that you can redeem in the future (subject to time limit of 2 yrs or so). That should make it no brainer for any serious LEGO buyers to go to lego.com and buy online. For example, they came up with a new LEGO 42009 Mobile Crane MK II which retails on lego.com for $219.99. With VIP program you are essentially getting $11 back and with free shipping because lego.com gives free shipping for orders over $75. On top of that, LEGO also seems to be giving away small sets each month with your online order (probably for orders over a certain value).

So you would think this is no brainer for people to buy it directly from LEGO. However, I see people buying them on eBay and Amazon for $250 and more. Highest paid on eBay as of today seems to be $289. This is probably due to the fact that searching for “LEGO 42009” on Google doesn’t take you to the LEGO’s shopping page. It instead takes you to their blog covering the same product. It’s possible people may not know about LEGO 42009 and hence may not be searching using this keyword. Even then, it seems that the lack of awareness that it’s possible to buy the product directly on LEGO’s website is helping a few to pocket some extra bucks and others to lose some.

One interesting observation is, there are some sales on eBay below the price that LEGO sells. The cheapest was gone for $160. I have no idea how it’s possible to sell it for so less including free shipping.

All this makes it a strangeCommerce :).

Posted in Uncategorized | Tagged | Leave a comment

Securing mjpg streamer

I mentioned that I turned my raspi with the camera module into a video streamer (actually image streamer). I did this by using a very nice software called mjpg_streamer. Once I got that working and with NAT on my router I could see the image streaming from any machine on the Internet which includes my phone. As per a friend’s advice I wanted to make it secure. It doesn’t seem like mjpg_streamer has an option to support https. After a little search I found a nice utility called stunnel. What it can do is turn any unsecured network service into a secured service. Essentially at the simplest level you can say any network request on port A should map to another service on port B. So, I enabled mjpg_streamer on one port and stunnel routing via another port and finally the port forwarding on my router points to the port that stunnel accepts on.

The configuration file to make this happen with stunnel is very simple.

cert = /etc/stunnel/stunnel.pem
key = /etc/stunnel/stunnel.pem
sslVersion = all
debug = 7

[https]
client = no
accept = 1234
connect = 127.0.0.1:5678

Here, 1234 is the external port to which the router should forward the incoming request. And 5678 is the port that mjpg_streamer should be streaming. Note that “client = no” ensures the call to mjpg_streamer is done using http. Otherwise, it will try to use https and you would end up with an error like “GnuTLS: A TLS packet with unexpected length was received.”

Posted in Uncategorized | Tagged | Leave a comment

Few more projects with my Raspberry Pi

I tried out a few more projects with my Raspi. First was to convert Raspi to a portable bluetooth speakers. I used the steps in this article. Initially I had a problem with PulseAudio where only playing the music as root worked but that some how got fixed when I tried various suggestions on the web. I could play the music from iMac but it used to have stability problems. Not sure if it was because I also did ssh from iMac and there is a second connection. Or may be powering the USB for Wifi and the Bluetooth for music was simply too much. I wanted to try it on iphone but iphone didn’t recognize the bluetooth device.

I also gave the Shairport a try to do the AirPlay. That worked very well and could stream music from iMac and iPhone. However when I used AirAudio and tried from an Android phone, it didn’t work.

Then the third project was done yesterday when I got the camera module. The camera module is just 3 grams and so tiny and really awesome. I wanted to two things with the camera module and did one of them successfully so far. I wanted to be able to stream the video as a webcam so that I can use it as a home security system if I wanted to. Second purpose I have in mind is to use it as a stop motion video catpure system. I can certainly use raspistill and get this done. May be will post it later on how that went.

BTW, I wanted to check out the GPIO (this is brand new to me and not coming from an Electronics/Electrical engineering background, the whole concept of microcontrollers and how those tiny things can do amazing things with very little overhead and hence power is new to me) but didn’t get the time and motivation to spend on a few connecting wires. But I came to know that the led on the camera has an option to disable via a boot config option but it can also be turned on and off programatically later on. So using RPi.GPIO I managed to make the led blink a few times and that’s a good start for a GPIO programming without any wires, breadboard and other stuff needed with kits. Of course, I do want to check out Arduino as time permits.

Posted in Uncategorized | Tagged | Leave a comment

Preserving the past

There is this concern that a lot of digital media will become inaccessible due to changes to storage formats (floppy, cd, dvd, bluray …), protocols (com, usb, bluetooth), operating systems (windows 95, 2000, Windows XP, Windows Vista, Windows 7, Windows 8), (serial port vs USB vs Firewire) hardware and so on. I recently had to deal with this in a very interesting way. I bought LEGO Mindstorms Invention System 1.0 about 14 yrs back. I may have played with it for a couple of weeks at best and then just kept it aside. Now that my 4 yr son is showing interest in various toys and LEGOs, I opened up my old box and wanted to make sure everything works fine. I have the entire set with all the parts and the software it came with (only issue is the rubber cover of the connector wires which are degrading). The software was meant to run on Windows 98. I have a iMac with a Windows 7 running in a VM. However, the IR tower I have is based on a serial port and there is no serial port on my iMac. First thing I did was ordered a Serial (9 pin) to USB adapter. It came today and I was all set to start the program. The RIS software runs initially in a guided mode (which apparently can be disabled by clicking Control-About (About is a button on the software) which I came to be aware only at the end of going through a painful training mode). One of the steps in the training mode which I couldn’t go past was to download the firmware. The adapter seemed to work fine because I could see the IR receiver to light up and also could see the brick counting from 1 to 20 and repeat. It was supposed to count up to 1600 but that never happened. That’s when I wasn’t sure what was wrong. Wasn’t sure if the adapter had a problem, if the program running in a VM was a problem, running within Windows 7 was a problem.

After a bit of search, I came to know about two things. One is, there is an excellent open source software called BricxCC which is an alternative to RIS and the second info is a website where I could download Mindstorms 2.5 SDK. These two helped me overcome the hurdles and complete the training. What has to be done is to start the BricxCC and it has Download Firmware within Tools. What it does is, it asks for the firmware file and uploads it to the brick. If you have the original RIS 1.0 you would have an older firmware (firm0309.lgo) but the Mindstorms 2.5 SDK provides the later firmware. BricxCC didn’t have any problem uploading the firmware while the original RIS system couldn’t do it.

Anyway, just thought I will pen this down for my own future reference (since the firmware needs to be uploaded every time the batteries are changed on the brick) and also to contribute back to the open knowledge. Have fun with your old LEGO toys. Or may be just wait for the upcoming LEGO EV3 and not worry about all these incompatibility issues.

Posted in Uncategorized | Tagged , , | Leave a comment

Powering Raspberry Pi from iMac

I just tried powering my Raspberry Pi by connecting it to the USB port on my iMac and it worked just fine. My Pi setup is that it only has a USB wifi dongle and nothing else and runs in headless mode. Model B requires 5V at up to 700 mA. USB 2 on my iMac actually provides 5V at 500 mA. However, Apple has a note that it’s possible to power devices with higher current requirements, see this note. So I decided to give it a try and it worked. However, I didn’t see the RPi in the system information under USB on the iMac. Perhaps the USB is just acting as a power supplier, it doesn’t list it.

While it is good to know that the Raspberry Pi can be powered from an iMac, I am not going to really do this often. I will have it powered from a power outlet.

Posted in Uncategorized | Tagged | Leave a comment

My first Raspberry Pi and what I got it for

I switched from Linux to Mac a few years back (this is not an article debating which one is better or anything like that, so don’t bother). I have some content on the linux machine that I would prefer to have it (but if I don’t have it immediately or worst case never, it’s not the end of the world). As time passed, I transferred some files but there are still a lot left. In the meanwhile my Linux box kind of died on me. One fine day it heated up and stopped booting. Then I bought a new fan and also a heatsink. This made the machine to boot up but in a few minutes it would enter into dangerously hot zone.

I bought Iomega’s iConnect to make my hard drives available on the network. Think of this as a poor-man’s NAS solution or non-technical user’s simple solution to sharing harddisks. I thought I could remove the hard-drive from the old Linux machine and make it shareable using iConnect. Unfortunately, there was one small problem. This machine was so old that I formatted it using reiserfs when that filesystem was very active and one of the best solutions. Given that people are moving/moved away from this filesystem I guess Iomega didn’t bother to include it in the firmare of iconnect. Mind you, iConnect actually uses Linux underneath. But given it’s a closed platform, I didn’t really fiddle around with it.

As a result of all that I had a spare external harddrive enclosure and a rusting linux box with a harddrive inside. Fast forward 3 yrs. Last year I heard about Raspberry Pi but didn’t really pay much attention. Then I came across some cool projects on Kickstarter using Raspberry Pi and that’s when I thought why not get a Raspberry Pi and liberate my old linux hard drive with Reiserfs.

I paid a total of $96.51 and got 6 components to put together a Raspberry Pi. I bought the following

1) Raspberry Pi, Model B ($43.30)
2) Raspberry Pi Case ($13.48). This is definitely expensive, once I get my 3D printer I will try to design something of my own and have fun. It’s expensive because, compare that to a soap box some of which sell for less than a buck and use similar amount of plastic.
3) Edimax EW-7811Un 150 Mbps Wireless 11n Nano Size USB Adapter ($10.87). I wanted to be able to put the RPi where ever I wanted in the home.
4) Motorola USB Wall Charger with Micro USB Data Cable ($6.14)
5) Transcend 16GB Class 10 SDHC Flash Memory Card ($14.05). I could have gone for a lower class and lower memory, but I think this is worth the investment.
6) Kootek Aluminum Heatsink set for Raspberry Pi ($5.99). They are smaller than they appear on the website. Injection molding and the cost of the material should get them < $2 in bulk, so they are relatively expensive but perhaps "Prime eligible" on Amazon makes them a bit more expensive. Also, at the moment I am not going to overclock. So not sure if these are really needed. So all of this put together it cost $93.83 and along with tax it came to $96.51. What's interesting is all 6 the parts are from 5 different suppliers with Amazon providing the charger and the sd card while the rest from 3rd party sellers. But since they are all prime eligible, they got shipped in 2 days, all in one shipment! I was expecting to get a large box delivered and when I went home I found a small packet like the one Amazon uses to ship books. Yes, the form factor is really that small with Raspberry Pi and that's pretty cool. Installing Raspberry Pi on a Mac in headless mode made it a bit difficult initially but it all worked out. My plan of being able to make my aging linux hard drive to work succeeded thanks to the Raspberry Pi.

Posted in Uncategorized | Tagged | Leave a comment

My first 3D printer, yet to come and hopefully it will

I recently pledged on Kickstarter to for a 3d printer. Yes, the The Buccaneer. Hopefully there are no risks and everything goes well and it would arrive Feb 2014. Long wait, but may be worth it.

I have been prepping myself for using this 3d printer by learning 3d modeling. I came to know about Autodesk’s Inventor Fusion from a colleague. I tried it and felt it to be a bit complex. However, Autodesk also has 123D Design. Think of this as a lite version of the Inventory Fusion. Awesome product. It has a bunch of tutorials on Youtube. Watching about 12 videos, one would become quite familiar with using this simple tool. The tool is simple, but the designs that can be made have no limitation, they can be quite complex. I use this on my iMac and the only drawback it has is that it crashes sometimes. So, it’s very important to keep saving your work periodically.

The other day I was trying to design a disk with a face. For the mouth, I added a torus and tried to combine the disk and the torus using the “Subtract” operation. Then it gave me an error “Combine failed. Bodies are not intersecting”. I scratched my head quite a bit on this because I know for sure both the disk and the torus were indeed intersecting. I just gave up and instead drew a simple with spline, extruded it and then subtracted it and moved on.

Anyway, as I am all exited about the new 3d printer that would be coming next year (Yeah, it’s a painfully long wait, but Kickstarter backers have to get used to this type of wait as compared to ordering with Amazon Prime and getting it the next day or the day after!) I was thinking what all should I print. I visited the Thingiverse and have a couple of them in mind. But I also wanted to design something of my own. My son’s name happened to have 6 letters and the cube has 6 faces. So, I thought I will create a hollow cube and subtract the letters of the name one from each face of the cube. When I started doing this with “A” I again got the above mentioned error. Then I realized what’s going on. Thing is, subtracting “A” or the torus from a sheet creates two separate parts. So the “Bodies are not intersecting” is related to the final shape after subtracting. It appears, and probably makes sense, that after subtraction there should still be a single connected body. Otherwise think how the two disconnected bodies will stay put together? Mystery solved.

But I still need to proceed with my idea of creating a cube with letters on the faces. What I ended up doing was, to first take “A” and another thin block and subtract that block from the letter right at the middle on the horizontal line of “A”. This makes the middle triangle now to be connected to the rest of the body when subtracted.

It’s possible to get away like this for all the alphabet. In fact, the list of alphabet that will have problem are A, B, D, O, P, Q and R. Just 7 letters. Rest all don’t have the above mentioned problem. Perhaps we need a new font just for 3d Printing.

Update: I finally ended up canceling my pledge for The Buccaneer and go with The Bukito. Will know in a few months if that was a wise decision.

Posted in Uncategorized | Tagged | Leave a comment

in-Vitro Meat: An invention that can spare killing animals

I am a vegetarian by choice but still this news, Engineering the $325,000 burger attracted my attention. Apparently, they are trying to grow beef tissue in a lab. If this is successful, economical and no health issues for those who eat it, it can become the next phase of domestication. Meat farmers! Assuming this is the future, I like this idea because it would spare the lives of many animals. Better yet, there is no need to grow so many animals and birds in bad conditions.

 

Posted in Uncategorized | Tagged | Leave a comment