Sunday, February 17, 2013

Programming a LilyPad with a UARTsBee 3.1

The only reason you could possibly want to read this is if you have a UartSBee v3.1 and want to program an Arduino Lilypad with it.

I just got myself an Arduino Lilypad to experiment with some wearable electronics projects, and tried to program the Lilypad with the UartSBee v3.1 that I had lying around at home. If you're new to this, it's just a USB-Serial adapter with a Bee socket.

The Googles don't seem to know much about how to program a Lilypad with a UartSBee. Everyone seems to be using an FTDI breakout board for this. With a UartSBee v4, it's straightforward because you can just use a 6-pin FTDI cable. With the UartSBee v3.1, this is how you can use 5 wires with female connectors attached to the bent pins on the UartSBee and connect them to the bent pins on the LilyPad. Just use the following wiring scheme. Please note that the CTS pin on the LilyPad doesn't need to be connected.

Just wire it up like this, flip the voltage switch on the UartSBee to 5V, and your Arduino IDE should be able to upload your sketches to the Lilypad as you would expect.

Tuesday, January 15, 2013

Baby Monitor DIY (sorta)

When there's a new baby around, people seem to use the occasion as an outlet for their creativity. For example, our lovely neighbour hand-painted a beautiful lamb onto a wooden hanger for our baby. One of our friends knitted a sweater and a stuffed toy for her. My wife knitted a little cap and mittens. I tried to make a baby monitor.

What does it do?

Here's a screenshot of what it looks like.
In a nutshell, it lets me view a video feed of my baby's crib from anywhere. I can do it using a laptop from the living room, I can do it from my computer at work, and I can do it from my phone if I'm on the move. There are a few other handy features, like being able to tilt the camera, and viewing the temperature and humidity of the room. The nice thing about MJPEG is its almost universal support. It runs on Chrome and Firefox on my Ubuntu machines, as well as on Chrome on Android.

What does it not do?

It doesn't have a sensitive enough motion sensor to reliably tell if the baby is breathing (although the quality of the video is high enough that you can easily see that she is). It doesn't carry any audio (although that would be super-easy to hack on - I just didn't have a need for it).

What is it made with?

(It's a prototype and nothing more, so please don't cringe!)

This one is made with a PandaBoard ES-based ARM processor board. It's connected over (ugh) USB to a microcontroller that I use to read out the sensors and operate the servo motors. There's a standard Arduino UNO microcontroller there, a Passive Infrared (PIR) sensor, a DHT-11 Temperature/Humidity sensor, a Logitech webcam capable of 720p video, and a small servo to control camera tilt. The most expensive parts are the PandaBoard and the webcam (together ~300 CHF). Everything else together is under 50 CHF. You could just use whatever "small computer" you have lying around, so it doesn't need to be this expensive.

The second version that I'm working on is based on the Beaglebone. It'll cost a lot less to make, and I want to get rid of the ugliness of talking to the microcontroller through USB. I could have done this with the PandaBoard, but I didn't have the courage to solder headers to my PandaBoard.  Not a problem with the Beaglebone - it has headers mounted. I'm also going to make this version a lot smaller, and power it with a Li-Po battery. The only drawback of using a BeagleBone is that it doesn't come with built-in WiFi, which one can easily solve with a small dongle.

The software is quite simple. I used a patched version of the mjpeg-streamer tool, mod_python for the backend that the Javascript UI talks to, and a small python daemon that talks to the microcontroller, relaying commands back and forth, and logs timeseries data from the sensors. There's some C++ code on the microcontroller that reads and formats sensor data, and moves the servo motor. I've set up NAT+DynDNS on my router, which lets me use the service when I'm not at home. I use Apache's VirtualHost-level Basic Authentication support.

If you want to make something similar and have any questions for me, please let me know!

Saturday, December 03, 2011

Istanbul

Having spent two days in the south of Turkey, we headed for the historic city that was once the seat of the Eastern Roman Empire, and then the Ottoman Empire, Istanbul. We landed really late in the night and took a taxi to the Arden City Hotel, which was in the middle of the Sultanahmet area. Given that the hotel was about a hundred metres from Hagia Sophia, the Blue Mosque, the Topkapi Palace, and about a kilometre from the bazaar district, Ramya's choice of hotel was nothing short of a stroke of genius.

Given that Hagia Sophia was closed on Mondays, we went in to the Topkapi Palace. The palace was commissioned by Mehmet II after the fall of Constantinople in 1453 to the Ottoman Turks. The Byzantine palace was entirely in ruins, so an entirely new one was built in its place. The palace continued to be the residence of the Sultan till the mid 1800s.

A minaret on one of the structures in the palace.
Ramya at the outer entrance to the Palace.
The beautiful, long walkway to the inner entrance.
As we've seen with other Muslim cultures, the taboo on graven images means that artists have to look to other means of expression, such as  calligraphy. The Sultan's name is the prominent symbol on this plaque.

A large Byzantine cistern was discovered on the palace walkway in the course of some renovation work. It holds tens of thousands of liters in a huge underground chamber.
Another structure from the outside of the Topkapi Palace.

If you're a Hindi/Urdu speaker, the "Top" in "Topkapi" is what you think it means - a cannon! The palace itself is a huge complex of several different buildings, among which were libraries, administration buildings, harems, circumcision halls (!), Persian-style Diwan-e-khaas and Diwan-e-aam halls, the Sultan's bedchamber, the Queen Mother's complex, the royal kitchen, and the royal prayer halls.
The entrance gate where coronations would take place in the presence of an audience. The
little bronze container at the top would contain some water that would drip down. I haven't really understood the exact procedure, but it looked a bit like the arrangement above a Shivalingam in a Hindu temple.

A pattern of beautiful ceramics, broken only by a beautiful lady in the foreground.

The Sultan's bedchamber. I read somewhere that the concept of a canopy bed was a European invention to get around leaky castle ceilings. I wonder if the Turks had the same problem, or this is one of the European imports (like the baroque facades you'll see a bit further down).

This was a running theme throughout the palace complex - a small structure housing taps with running water. We were outside some sort of a training hall for statesmen,  which looked much like a modern day library with more comfortable seating. 

A lovely fountain in one of the palace gardens.


Couldn't resist cracking a "Not Found" joke on this one.

Built in the 1800s, and as baroque as can be.
Not sure I remember perfectly, but I think this lovely pattern of windows (with perfect Tetris gameplay shutters) are on the outside of the circumcision hall. I can imagine the princes developing a subliminal aversion to this place.
At least in terms of how the audio guide described it, this seemed to be analogous to the Persian Diwan-e-Aam , where the Sultan meets with the commoners.





After walking through the palace for a while, we found ourselves at the entrance to the harem. The word itself means "forbidden". Visually, the place was nowhere near as fascinating as the concept itself. The Sultan had a harem complex, where the Sultan's concubines, the Queen Mother, and the eunuchs that managed the complex lived. The concubines were specially trained to be . . . concubines, and they had different ranks, ranging from those who shared a bed with the Sultan, those that he called his favourites, those that he called a wife, and ultimately, the one person who would be the mother of the next in line to the throne. The eunuchs were custodians of the harem, and were really powerful; they had free access to the palace and the harem, and the "Lala" (custodian) could have an audience with the Sultan. I'm reading a detective novel called "The Janissary Tree" set in the 19th-century Ottoman Empire featuring a eunuch as the main protagonist. Exciting stuff so far.

This was right near the entrance to the harem. To the left were the rooms which the concubines shared.

To the left here were the rooms of the "black eunuchs", usually men from Ethiopia who were castrated by slavers and shipped over.

Courtyards in the harem.
Recursion in the Queen Mother's quarters. 
You could tell we were approaching the Queen Mother's quarters in the harem. The paintings got prettier, and the rooms got bigger.
After spending the morning in and around the Topkapi palace, we went down to the bazaars around the centre of the city, which are every bit as fascinating as the palace and the mosque. Several of these markets have been around from back in the day when Istanbul (or possibly Constantinople) was the junction for trade between the west and the east when cargo ships arrived from South Asia loaded with spices, gems, and other treasures which would eventually find their way to the markets of Europe.

Markets in Istanbul are quite different from European markets, and tend to resemble Indian bazaars a lot more. There usually are entire streets that cater to one kind of product. For example, we came across a stretch of a street that just sold towels and bath robes. A really long stretch that just sold spices. And a small stretch, just a few hundred meters long, that sold jewelry boxes, mannequins (just the hands and necks), and precision instruments like Vernier calipers and high-precision weighing scales. Upon asking, we were told that these were shops that catered to jewelers. 
A sheltered part of the bazaar.
More shops spring up nonchalantly against centuries-old walls.


A store that sold equipment for jewellery stores. Talk about a niche market.
While walking through the markets and shopping around, we came across this man selling Sahlep (a sweet milky drink with a couple of spices, served hot) to all the shopkeepers. We bought a glassful, and enjoyed it in the somewhat cool evening air. "This is what the Ottoman troops drank for energy back in the days of the empire", he said.
Another beautifully lit-up mosque.
Having spent the rest of the evening in bazaars, we slowly made our way back to our hotel in the Sultanahmet area and decided to call it a day. Early morning the next day, we decided to cross the Golden Horn and go over to Galata. In the middle ages, the area was home to some traders from the Italian city-states of Genoa and Venice. Today, it's one of the several districts comprising Istanbul. We took a tram over to the other side, and started walking up the slope to get to Taksim square. If you find the slope too much, you can also take a funicular.

Ramya in front of one of the mosques on the "Galata side".

Istanbul's seemingly omnipresent, very well-fed stray dogs enjoying
a bit of sun on a somewhat nippy morning. 
The "Monument of the Republic" (1928) at Taksim Square.
 Taksim Square seemed like a very upmarket area with a lot of trendy office buildings, lots of coffee shops, and smartly dressed people walking about in a hurry. Leading off from Taksim square is Istiklal Avenue, a really long street lined with shops, restaurants, and all sorts of interesting buildings.
"A History of Cyprus" is an interesting title to find in a bookshop
in a country that doesn't entirely recognize Cyprus as a nation.

The Church St. Anthony of Padua, built by the Italian residents of Istanbul in the 18th century.

A shop full of guitars on a street full of shops full of guitars near the Galata tower.
The Galata tower, built by the Genoese inhabitants of Galata in the 14th century.
 Having made our way from Taksim square through Istiklal Avenue all the way back to the waterfront, we were feeling a bit peckish. And we treated ourselves to a fish grill right next to the fish market right next to the water near Galata Bridge. I'm pretty sure that the grilled fish that ended up in our sandwiches were swimming in the sea no more than an hour ago. We settled down on the bridge to eat our snack, watching people have a go with their fishing rods towards noon. Incidentally, the underside of Galata Bridge has a huge assortment of shops stocking walkie-talkies, phones, exotic watches and clocks, and handguns(!?). Folks from Mumbai will find it very similar to some parts of CST and Lamington Road.
Fish grilled sandwich, while-you-wait (for about 30 seconds).

Ta-dah! A freshly grilled fish with onions and veggies in a
freshly baked piece of bread, 5 Turkish Lira. YUM!
One of the biggest attractions in Istanbul, at least for me, was the Theodosian walls. These walls, first built in the 6th century, kept invaders out of Byzantine Constantinople for about a thousand years. The first time that the city walls fell was when Constantinople fell to the Ottoman Turks in 1453. One could say that these walls were the state-of-the-art in the keep-invaders-out business for about ten centuries, which makes them a heck of an engineering marvel. So after devouring our snack, we took a tram over to the western part of the city, where the old city ended.

Getting off at the "Topkapi" tram stop (do not confuse this with the "Topkapi Palace" stop at the other side of the city!), we came to the surface and saw the same sight that must have crushed the hearts of many an invading army - the double-layered walls of Constantinople. The two-meter thick outer walls in front of the 12-meter high inner walls, or what's left of them, are still an imposing sight. I can imagine that before the use of gunpowder warfare in this part of the world, they must have been virtually impenetrable. For more insight into how the Ottomans attacked the wall in the battle of 1453,read Roger Crowley's gripping book, "Constantinople: The Last Great Siege".

The Theodosian walls from about 200m away.

Alternate layers of brick helped hold together
the mortar better, offering better earthquake-proofing.

Ramya on the inner wall.
Having spent an hour near the walls and just trying to imagine what we would have done if were were heading an attack on Constantinople, we started making our way back to Sultanahmet, to visit Hagia Sophia, the iconic mosque/church.

It's hard to tell if Hagia Sophia is more fascinating from the inside or the outside.
The church/mosque has a fascinating history. Initially it started out as a Byzantine church, but was then converted to a mosque by Sultan Mehmet II, the conqueror. When the Turkish Republic was formed, a decision was made to make it a place of worship for both faiths. What we found particularly interesting was how they reconciled the Muslim taboo against graven images and the Christian practice of lavishing their churches with beautiful imagery, mostly of characters from the Bible.

Pop-quiz: What are the photographers here taking pictures of in
a 1500-year-old, twice-rebuilt mosque+church? A cat.

Big enough to park and turn a 747 in.

A view from the first floor balcony.

Gilded paintings of Jesus, St. John the Baptist, and one other person
on the walls at Hagia Sophia.
Having sufficiently recovered from the dazzling experience of visiting Hagia Sophia, we walked around town a bit and found tucked away in an inconspicuous, decidedly un-touristy street, a small shop that called itself an "Art Cafe". True to its name, the owner stocked lots of paintings, rugs, and painted fabrics in the shop in addition to selling  coffee and shisha. The place had amazing local charm. Ramya and I spent a good deal of time there, enjoying the warm tea, watching the locals come in and play chess, and just looking around. It was a terrific place to relax and unwind, and a very memorable part of an amazing 5 days in Turkey.

The Art Cafe towards the southern part of Sultanahmet and its
very friendly and courteous proprietor.

The Hippodrome, an Byzantine arena for racing horses.
Home to two very fine Egyptian obelisks.
Our room at the Arden City Hotel, just before we left it.