Working with Arduino

I started working on projects that use Arduino last year. The very first project was for a Heritage Gallery which showcases local education history and development since its establishment until present time. Following are my experience working on them.

Seamless projection shows using WatchOut and Arduino.

These 2 shows are similar in implementation with the only difference is on their number of projector used. The first one uses a single projector while the second uses 4. The video contents of the show are delivered using WatchOut, a software that output seamless projection out of multiple projectors. This software also controls the lighting in the projection room through it's DMX feature and in turn, the operation of the software is controlled using motion sensor and physical buttons. When motion sensor detects movement, lightings are turned on and the shows would transition to the introduction screen. It will stay until all visitors occupy the room. A gallery guide will then press one of the buttons to start the main part of the show. Another button which is designed to function as emergency will be used to stop the show. Near the ending of the show, a media player housed in an antique radio is triggered through a relay. All these things work in tandem to make the show appears harmonious.

To accomplish this, a number of things are put to work together: the storyline, animation and effect which make up most of the show, the DMX device that dims and brightens the lighting, the media player, the Arduino, Ethernet Shield and some related components. Arduino works as a proxy and manages the communication between these things. It receives input from motion sensor and buttons, transmits the corresponding message to WatchOut systems and through a relay, it triggers the playback of the media player. I was responsible for the implementation of the Arduino: wiring and programming. As this was my first time working with it, I had to learn basic electronics, soldering and stuff.

When everything was completed, we put them to test. At this time, an unknown error caused the show to jump to the start and end of timeline. The error manifested randomly, at one time, it caused a jump thorough the show and at other times, it didn't at all. I couldn't conclude anything from observing the continual occurrence of the error, it appeared purely random, without any pattern. In the end, this specific error took me almost 3 evenings to trace. As it turned out, the cables that that link the buttons to Arduino were to blame.

In the grand scheme of things, the cables were the least suspecting thing to me when I traced. I assumed they either work or didn't because they were just intermediary that carry the signal from the buttons and contain no moving parts. Earlier, I tested the cables using multimeter but found no defect. As the cables were quite long spanning from atop of the ceiling to outlets on the wall and was provided by an external vendor, I felt unenthusiastic to replace them if they worked fine. So hypothetically, I thought the cause of the error might lay elsewhere, perhaps in the wiring or in my code or even on the Arduino board.

The problem only became clear when I devised some test cases and started narrowing down the error. First I ran the WatchOut systems standalone and made sure they were operating as expected. Then I dismantled everything that was connected to Arduino and hooked them up step by step with a new set I built. The new set including some shorter cables just for testing were built because the previous debugging of old set didn't produce result. On each of these steps, I made the show run from start to end and log every message that was sent between Arduino and WatchOut to a text file using a serial logging utility called Gobetwino. The log enabled me to see what Arduino and the counterparts were doing and their states. After executing almost every test case, it became evident that the culprit was the cables. The new cables were running without hiccups for the first and subsequent times. And to replicate the error, I hooked back the old cables to Arduino. I showed this to the vendor and they replaced the cables next day. My boss's assumption was that from time to time, the cables somehow built up power and released it when reaching certain threshold.

Scrolling text using Matrix LED and Arduino.

The layout of this exhibit follows the model of a train map. It's installed vertically on the wall with 27 LED buttons fastened to it and covered by a thick glass. Each of these button corresponds to a message of the year during which an education policy is proposed or implemented. The message will be displayed on the Matrix LED when the button is pressed and stay scrolling until the message repeats for the second time.

This installation uses 27 buttons with LEDs so it requires 54 pins in total. Half of these pins are used for the press button input and another half for lighting up the LEDs on the button. To keep things simple, I used an Arduino Mega because of its larger quantity of pins. So that each pin can be mapped to either one button or it's LED. In fact, smaller Arduino boards can be used in conjunction with shift registers to produce more pins but this would make the whole thing more complex. For the wiring, I decided to use breadboard as is, instead of stripboard because hooking up 54 cables and resistors can be difficult and prone to short circuitry.

Luckily when the whole board was fully assembled, it looked neat. To make them easier to work with and also to prevent error, I put labels on each pair of them.

Override Joomla view logic class through plugin

On previous post, I wrote about overriding AcyMailing’s archive view class with the purpose of adding a custom field. It was done through alteration of component core file since layout-override only applies to view-output files. Later, I found a more sensible way to override the view class through plugin. In its simplest term, the plugin is used to include the modified view-class thus the original view-class never gets declared. This is possible because when the system instantiates the view class, it uses class_exists to load the respective class. When a class gets declared, the subsequent declaration will simply be ignored.

The following code demonstrates this possiblity. The code gets executed during onAfterRoute event and it does so by including archive.view.html.php

On a side note, the plugin xml file now accepts install and sql tag but does’t seem to accept uninstall tag. During the plugin installation, the sql runs okay but not during uninstallation. Otherwise, this AcyMailing field extender could be packaged into an installable plugin and that the alteration of database, view-logic files inclusion and output override can be seamless and automatic through plugin installer.

Reference : http://community.joomla.org/blogs/community/521-did-you-know-overrides-are-not-just-for-html.html

Extend AcyMailing : add custom newsletter field

Recently, I worked on a Joomla based website where one of the requirements was to add a custom field and display it in front-end newsletter archive list, next to the default subject and date. This additional field contains multi-line short descriptions and would act as a summary to each newsletter. And there has to be an extra corresponding textarea in the back-end for the editing of this custom field during creation or updating of newsletters.

In back-end, by default, I see no option to just add the custom field, which means field addition to newsletter table isn’t supported out of the box. So one way to do is to alter the newsletter table and edit a few component files.

I posted the following steps in the hope that this might be of help to other users who are trying to achieve the same thing. Before that, please back-up database and Joomla files just in case.

  1. Add the custom field after ‘altbody’ to the newsletter table. Note that my table prefix is ‘jos’, if you have a different prefix, change it to whatever you’ve set during the installation.
  2. Add an editable textarea to the newsletter back-end form. Edit administrator/components/com_acymailing/views/newsletter/tmpl/form.php, add the following code after line 22:
  3. Alter newsletter archive’s view logic to include custom field query to the newsletter table. Edit components/com_acymailing/views/archive.view.html.php, replace line 98:

    with the following:
  4. Alter newsletter archive listing to show another table header and also the custom field. Multiple lines contained in this custom field would be outputted as unordered list. Edit components/com_acymailing/views/archive/tmpl/listing_newsletters.php, add the following code after line 33:

    and add after line 78 the following code:
  5. On step 4, we used JText::_( 'SUMMARY' ) to output its heading to table header. This entry is retrieved from the current active component’s language file. Since this is a new language entry, we need to add it to the language file. Edit language/en-GB/en-GB.com_acymailing.ini, add the following code after line 25:

Steps above are the minimum to get the custom field working. By now, the summary field should show up below the text version on the same form in the newsletter back-end. We can type summaries of the newsletter into that textarea and it will be saved into newsletter table. And once saved, it will be displayed on the archive list of the front-end as unordered list.

Last thing you might be concerned about is how the newer update of the component is going to affect the above alteration. We can technically put our altered view files under html folder of our current active template and leave the core view logic files untouched as these files will override those inside the component during execution of view logic. But this applies only to step 2 and 4 but not step 3 which contains the archive view logic. Because as of Joomla! 1.6, only component and module view output files can be overridden but not view logic files. So for now, we need to keep track of what has been changed and re-apply again on the next update.

A Meditative Experience

During year-end holiday two years ago, I experienced first hand a comprehensive meditation training in Klaten, Java. The training is held a few times in a year and draw many enthusiasts from different places. As there's a limit on the number of people per training, participants need to register themselves weeks or even months before the training starts to be invited. The limit is due to the need to host participants adequately in the small available space and to give them a more qualitative experience because normally there are only two teachers present for questions after each period of meditation.

As informed during the registration, the training requires participants to agree on a number of things. New participants will observe one set of rules and repeat participants will observe the same set with additional rules. It was a thorough training that span over the course of ten days. A few meditation techniques are introduced along the way, with each day getting more extensive than the previous. Code of disciplines, rules and timetable can be seen its course website : http://www.dhamma.org/en/code.shtml.

After the training ended, I came back but didn't manage to keep the same training regularly. I forget the extensive part of the training. Still I think it's worth my effort and time because I was able to go through something that interest me and completed it. I remember on the last day of the meditation, the teacher advised us to keep the practice going and try to make it part of our life. The practise doesn't have to be as extensive but setting aside two hours each day and keeping it consistent would suffice. He added that the more we practice each day, the better we become.

Since a few months ago up until today, I began doing a relatively short breathing meditation again. As the name implies, it's the action of focussing attention on one's own breath. I do it a few times daily with each one typically takes more or less than half an hour. I have so far been able to keep the practice going in a consistent manner. Below is my experience and observation.

I would start the meditation by sitting on a cushion with my back straight and eyes closed. In a relaxed posture and I would signal different parts of my body to rest. Then I would take a few deep breaths. Starting out, there might be stiffness around the chest, taking deep breath will weaken the stiffness and gradually they will disappear. After a while, my whole body would feel relax, I would draw my attention to the tip of the nose and focus solely on the in-out of my breath and try to sustain the attention for as long as I could with my focus fixed on the nostril. This process lasts for a while until my mind helplessly gets distracted and busy, evidenced by the arising of stream of thoughts. This will often the case cause my attention to weaken if I am not mindful. The attention might even descend into any arising thought and wander along for a while until awareness manifest itself again. Soon I would try to pull the focus back on the nostril.

The lost and found cycle of our attention would go on and on which I believe will improve over time the more we practice. I noticed a small but significant improvement over the course of a few months even though my attention still wander and lost very often during the practice. I feel that the longer I could sustain and focus my attention on breathing, the subtler the surrounding noises become. This feeling is like cotton being put into ears which made the noise considerably weaker. Also when breath becomes much more subtler, the ins, the outs and the pauses as they change can still be felt. Until this point, my mind somehow doesn't follow the arising and passing thoughts any longer. It observes them instead without being pulled into it, like a retired man sitting peacefully in his home garden observing vehicles moving past on a busy street.

During meditation, I could feel how unrestrained my mind is. With eyes closed and focus turn inward, thoughts could still arise from any past or recent encounter made with the people around me. Stored inside memory, everything I saw or heard or experienced could surface. Memory of these encounters bring along all kind of feelings and emotions — bliss, sorrow, jealousy, indignity, anger, guilt and all the kind that we could describe and label. But by simply staying put and observe without being attached to them, I feel calm and peaceful.

Sitting alone in solitude made me capable of scrutinizing my own thoughts, sometimes way before the occurrences manifested into thought. The capacity to intercept and inspect them may still be infancy but it's there and needs to be constantly sharpened. I also acquired a new idea about "perception" and it was enforced when I attended a short talk last week. The speaker described that things we generally see has gone through a lot of distortions, in a subjective way, which include our mishmash of emotions, past experiences, both pleasant and unpleasant.

Alas, I do hope that I could keep the practice going for as long as I could.

Stillness

Img_1263

I strolled along the elevated pathway surrounding the reservoir yesterday. The elevated pathway acts as boundary to the surrounding area which is on a lower altitude. In one corner of the reservoir, there remains a huge water outlet which lead to a nearby river. Extra water would be released to the river when the level gets high during rainy season as to prevent them from flooding surrounding land and road. The river in turn, leads to the sea.

One early morning, the atmosphere was serene at the reservoir and the wind breezy. I can see the effect wind-sheer has made upon the water surface. Seen from distance, they felt alive. But into the second half hour, the wind went silent. As can be seen from the photo, the water and trees were in complete stillness. The sky and dark trees due to faint light, were reflected on the still water. Behind these dark trees, layers of hills appear fainter and fainter the farther they are situated.

This particular scene reminded me of Michael's work where they showcase the deep silent of nature. Being able in a place where things are in tranquility and experiencing it is both rewarding and fulfilling.

Clouds In The Sky

Happiness is like a cloud, if you stare at it long enough, it evaporates. - Sarah McLachlan

Cloud as object of photography can sometimes bring emotion to whoever takes them. They are formed by billions of tiny water vapor yet almost weightless, drifting to wherever the wind takes them. Motion of the drifting clouds in the vast sky give me a sense of broadness and ever-changing. On a fine day when nature paints the sky blue and the cloud white, they together provide a sense of cheerful and warmth. At times when it's about to rain, dark clouds form and they give me gloomy feeling.

This set of cloud photos were taken using camera phone, which is handy for this kind of quick snap. As clouds evaporate fast, one moment they are fluffy and huge, the next they disappear altogether, leaving only vast blueish sky. All pictures in this set are portrait oriented and I experimented with this orientation to somehow get a different feeling out of them instead of a normal landscape mode.

Lake Toba

This is a short clip that I took when I was at Lake Toba a few months ago. During the visit, I stayed in Carolina Cottage, a clean and affordable lodge in Tuk Tuk. This cottage features beautiful view, overseeing the lake and surrounding hills. It has around 20-something number of rooms, shore or lake front. I took a lake front room which has double beds and a modest bathroom without heater. It's situated at the utmost right of the cottage.

There's a restaurant in the center of the cottage serving Western and Indonesian food. And they have this kind of unique payment that you just order the food during your stay and they'll only bill when you are checking-out, which is convenient for longer staying travellers. Just recently I heard they begin accepting credit cards.

To the left of the restaurant, there are some other rooms near the shore with a few long chairs and a jumping board and a hut by the side of the lake. A few trees surround the hut and a small fish pond just right beside, making it shady. A totem pole stands in front of the pond. I am not sure what it is but it must mean something for the Batak.

The clip was taken in the corner of the shore. It was a windy afternoon and the sun can hardly be seen. A boat has just made crossing from the opposite island to fetch and aboard travelers before heading back again.

I stayed two nights in this cottage. The first day, as I arrived late in the afternoon I immersed myself around the lake until dark. Early morning the next day, I rented a motorbike and toured around the coastline of Samosir which is some fifty kilometers long. I made a few stops along the way, first to the Museum of Batak. It was almost noon when I reached the museum and I was the only visitor. Inside the museum you can see ancient tools, weapons and boat used by the Batak. Nearby, there are granaries, tombs and a dancing ground which has a two meters high totem pole in the center.

I proceeded to Pangururan after museum and it took almost half of the journey before I got there. A few hot springs can be seen up until I travelled out of Samosir Island, not far from Pangururan. I was travelling alone in this trip so I didn't visit any hot spring as most of them were empty. I took a last view of the surrounding before I headed back to the cottage.

You can see more of my Lake Toba pictures on Flickr.

Minimalism

I stumbled across the works of Michael Kenna, a professional photographer whose works center around nature. As can be seen from his online gallery - lake, forest and trees are some of his favorite objects. He, amongst the photographers that I paid attention to, has a singular minimalist style (if I may label so for his style of photography).

His color of choice is modest, mostly using black and white. And it can be seen consistently across all of his work. Simple yet sophisticated. They evoke a calm and peaceful response and leave very much the rest to our own, the viewer's imagination. When being asked in an interview by The Light magazine on why he loves doing black and white photography, his replied:

I believe black and white is immediately more mysterious because we see in color all the time. It is also more subjective. I think it is quieter and more calm than color.

Personally, I think minimalism in general deal with something that is functional yet with less clutter. But there can be times when we can't resist introducing something extra into them. It then become a distraction. Michael's work provides us a perspective to keep our work simple and quiet.

West Lake

I spent 2 weeks in China a few months ago and had a chance to visit Hangzhou, a renowned city famous for its beautiful natural scenery. One of the popular places is West Lake (西湖), a name that I've heard many times both in historical dramas and music performances.

Being part of a tour group and a conversational mandarin speaker myself although not a very good one, I was able to understand most of what the tour guide was saying. Along the journey, he spoke a number of proverbs and one that stick to my head is the following:

生在苏州, 活在杭州, 吃在广州, 死在柳州

Which roughly translates to "Be born in Suzhou, live in Hangzhou, eat in Guangzhou and die in Liuzhou". The meaning behind the proverb is that for the most of ancient times, Suzhou has been renowned for its educated scholars, Guangzhou for its food delicacies, Liuzhou for its wooden coffins used for the resting of the dead. And Hangzhou had been a prosper and livable city with scenic landscapes.

The galery above contains some pictures that I took around the lake. I especially like the first one where the willow leaves hang from above against the background of hills and calm water. It feels peaceful.