My Blog

A secured gateway to home-brewed HA

posted Aug 8, 2017, 3:41 PM by Pratik Panchal   [ updated Aug 8, 2017, 3:52 PM ]

Welcome to the latest article of bowl-of-IOT. Exciting developments since last time. 

IOT is still in early stages. And the ONE thing that I despise is the security. There are no industry standards that promises the security of that home-brewed smart device connected to the world, sitting in your living room. 

Although there are workarounds. And I'm sure, we'll have a good solution soon. 

But meanwhile, here is the Particle Photon - tadaaaa! 

The Web API calls to this board is secured and based on the 32 bit keys unique to your account. And your account is protected. Pretty secured for my needs.
On the other side of the router, when I look at my internal 192.168.x.x network; things are pretty unsecured. 

That's where the arduino-like code for particle photon comes into play. The ease with which the Particle board can talk with the internal devices is totally worth the workaround:

    // Make request to ESP board
    sprintf(publishString,"IP: %d.%d.%d.%d",ESP_SERVER_IP[0],ESP_SERVER_IP[1],ESP_SERVER_IP[2],ESP_SERVER_IP[3]);
    Particle.publish("Attempting connection to server",publishString); //+ESP_SERVER_IP[1]+"."+ESP_SERVER_IP[2]+"."+ESP_SERVER_IP[3]));
    while (!client.connect(ESP_SERVER_IP, ESP_SERVER_TCP_PORT) && (connectRetries++ <= MAX_CONNECT_RETRIES)) {

And Voila!!
Suddenly I can make secured web based calls to control my internal unsecured ESP boards. Not only that, devices like Google Home and Amazon Alexa can now control bunch of my internal devices via IFTTT (another service I'm in love with). 

A block diagram of how everything is put together:
Block diagram - secured gateway to my HA

The little ESP end-node running the home-brewed unsecured web server to control the GPIOs.
Note the wires - they are going to the actual solid state relays (again home-made :) )
The ESP end-node

And the shiny new Google Home to control one, and all!

Ghost capacitance on data bus can haunt your project

posted Dec 11, 2012, 12:10 PM by Pratik Panchal   [ updated Apr 1, 2013, 7:47 PM ]

11th December, 2012, @desk.

So, lately, I've been working on developing the I2C message protocol to create a feeling of 'brotherhood' among the sailors on the ship - Uhh, I mean, chips on the board. And to plunge myself directly onto it, I got a ready-made board with a 32 bit PIC and an EEPROM from Atmel. I did not waste time on going over the hardware schematics (no reason, right), and initiated the development process straight away.

As a habit, I developed a minimal amount of framework - a skeleton, perfectly in line with the message protocol and the hardware datasheet - just to verify, that I was seeing, what I was imagining. But to the disappointment, I saw something weird going on the bus:

This was just terrible. There weren't sufficient clock pulses (9, to be precise) on SCL, the data wasn't authentic on SDA, the frequency had an error of 17%, and the duty cycle was not 50%. And the worst part - this wasn't consistent. The pictures were changing with each run.

Now, before plunging into my own development, I had tried the firmware from Microchip - and that was working perfectly okay at 8Mhz frequency. Although, I was trying to develop with PLL on, at 80 MHz, it didn't seem to be a problem - since the datasheet mentioned the usage of frequencies above 40Mhz, which was not possible, without using PLL.

So, the problem seemed like the PLL - with it being ON, things were messed up; and without it; at raw crystal speed of 8Mhz, things were good - life was pretty.

With this I spent full 2 weeks, trying to figure out the workaround - contacted Microchip guys, asked for simple sequencing code, did lot of signal analyzing stuff - and the presence of random spikes, on SCL lines, every now and then was just annoying and painful.

Nonetheless, at the end of the week, I realized, I had spent way too much of time on this - I decided to pull myself out, and look at the picture from the distance. I thought of isolating the big guy PIC from the bus and see what's going on, on the pins - just to eliminate the possible causes of interference from other devices on the bus - pull-ups and the EEPROM. Since the board was multi-layered, and traces hidden below a laminate layer, the only option I was left was to was to physically force-out and lift the pins off the board. SMD components could strains your eyes, especially when the pins you want to force out are in middle of the array of 25 other pins. But, fortunately, a microscope came in handy and this point and the operation was successful. I then re-soldered two thin wires at the pulled-up pins, and fetched them to a safer distance. I connected two external pull-ups on these lines and hooked them to the logic analyzer.

The result was astonishing. The protocol was perfect!! The devil was hiding somewhere on that bus on the board! The first thing that came to my mind was to see the capacitance between the lines, and it was of a fatal value of more than 100 microFarads!! I didn't knew what was causing that high capacitance (poor board layout? foreign particle somewhere in between the tracks? who knows?), but I immediately isolated the whole bus from the board. The protocol seemed to be flowing perfectly now.

But, the thing that bothered me was, that, how the heck did the protocol able to maintain sanity with 8Mhz clock and PLL on?; you see, the output on the I2C bus clock line remains 100kHz irrespective of its source input. Somehow, in this situation, it seemed apparent that, the switching on PLL caused some kind of signal degeneration, which in-turn reacted adversely with the bus capacitance to produce those bus lags and waveform deterioration. I tried to see the difference between the waveforms under both scenarios; but couldn't catch anything big. 

I hope it doesn't remain a mystery unsolved.

Science in a Musical Way

posted Apr 10, 2012, 8:28 PM by Pratik Panchal   [ updated Apr 10, 2012, 8:48 PM ]

10th April, @Desk.

The other day, I was going through my favorite Carl Sagan and Richard Feynman talks over the youtube and suddenly came across a musical jingle where Carl Sagan, Richard Feynman, Dr. Kaku, and other notables were seen "singing" out the science (  !!!  ). Well, I never knew before this, but there exists a musical project initiated by John Boswell, which aims to delivers the scientific tit-bits over a series of musical videos. 

The voices of the characters are modulated and toned, but they are their own words spoken over various shows aired till date. The website hosts all the videos made till date and offers free download. Most of them are asynchronous (non-rhythmic), with repetitive phrases but its fun watching them. My favorite ones are 'the quantum world' and 'the world of Dinosaurs' (remember Dr. Alice and Dallas Campbell?). Also, some of the phrases like 'the universe is made of 12 particles of matter, 4 forces of nature' (by Dr. Cox over TED talks in 'the quantum world') and 'the more we find, the more complete our understanding' (by Dr. Alice in 'the world of Dinosaurs') are quite 'catchy' and stayed on my mouth over the day.

Well, what is a better way to start the day than, letting Dr. Cox, Dr. Kaku, and Dr. Feynman sing you the Quantum Physics!!

Thank you SymphonyOfScience..!

web counter

Utterly Awe-inspiring Bio-mechanism behind the Blink of an Eye

posted Apr 10, 2012, 7:14 PM by Pratik Panchal   [ updated Apr 10, 2012, 11:29 PM ]

9th April, 2012, @lab, Phillips Hall.

The other day, over some project work, Skye N. came over and bumped me with a question: "Why don't we feel our eye-blink?". 

"What do you mean by why don't we feel it? Obviously we feel it, see <blink> <blink> <blink>", said I with utter naivety. 

"No, that is what you feel when you blink your eyes consciously. What I mean is, why don't we feel it when we are not paying attention to that process, which happens continuously with such 'high' frequency?"

"Well, maybe we are not paying attention to it. Maybe, the brain is occupied with other activities and so doesn't notice this reflex."

"So, you mean to tell that if we 'blink' (switch-on - switch-off) the lights of the room for the duration of time it takes for the eye to blink, the brain wouldn't notice it?"

"I guess so - Well, lets try it."

So, over next hour, I spent finding out the duration of the eye-blink. I kept a light sensor near to my eye, which sensed the reflected light from my eye. I expected that when the eye-lid would close, the photo-sensor output might go low since its not getting as much reflected light as it got from shiny surface of my eye-ball. But to vain, it did pick up reflections from my eye-lid and didn't operate as I intended. So, I took a black marker and painted the eye-lid with it. Problem solved. No more reflections from eye-lid.

The oscilloscope said that the duration was about 310 milli seconds at about very 15 seconds. Well, I could have got this values through Google, but its interesting to get your "own" readings sometime.

So, the next step was writing a small code and deploying on a PIC18F4420 which would shut down all the lights of my room every 15 seconds for duration of 310 ms, and well that was pretty simple.

Well, this frequent 'blinking' became extremely annoying and frustrating. I couldn't comprehend why the same equivalent action wasn't so disturbing. The natural eye-blink goes almost unnoticed untill you do it consciously.

The awesomeness behind:
It turns out that when the eye blinks, the part of the brain which receives the visual signals from eye-balls and processes them, also shuts down for those 310 milli seconds of duration. Thus, the brain doesn't see a black dark patch for that duration, instead, it just 'skips' those 310 ms, unless and untill you consciously blink your eye which keeps that part of brain active and enables you to see that black dark patch for the duration of eye blink. A more biologically technical description can be found here:

This is something like an 'interrupt' routine of a processor; the processor will execute the task only when it receives the 'interrupt' signal to do so; else it simply doesn't acknowledges it. Well, in this case it is done to free up the processing space.

Isn't this simply awe-inspiring mechanism? Its such an elegant design! Such simple yet absolutely smart bio-mechanism deserves a moment of attention. It naturally leads us to think the complex behavior of the evolutionary path that we have been from. What a wonder, these carbon and hydrogen atoms can do when they are left for 13.7 billion years (the life of the universe)!!

P.S.: Please don't paint your eye-lid with a marker; It takes two days to get off  :)

web counter


On "Fairness" of outcome of Flip of a Fair Coin.

posted Apr 6, 2012, 11:16 PM by Pratik Panchal   [ updated Apr 9, 2012, 11:05 PM ]

7th April, 2012, @stacks, Uris.

The arenas in which probabilities work 'too much' is something which I find difficult to comprehend. Say for example, the flip of a fair coin.

We say that the probability of an outcome - heads or tails - in case of a flip of a fair coin is 0.5. Well, isn't on larger scale, it is possible to know the outcome with certainty by referring to the kinetics of bodies? Taking this example of coin, isn't the outcome a function of following actions (variables):

1. The mass of the coin.
2. The state of coin just before flipping (which side is up and which side is down, and at what angles).
3. The vector force (which enables the coin to attain a height) given to it to move upwards.
4. The angular torque (which gives the coin its rotational speed) provided.
5. The air resistance that the coin is traversing through.
6. The gravitational field in which it is moving.
7. The instant at which it is caught.

Well, all these are real valued variables and if we precisely are aware of them and fit them into a beautiful equation describing the motion of the coin, we can say with certainty that if the coin is caught at a particular time instant t, the "heads" will be up.

Well, so, I asked Skye Nebulae,  a dear friend of mine, what do we mean by probability in such a case. What set of actions will make the outcome probable. Well the obvious reasoning was that "we don't know" with what (above mentioned) variables will we be flipping the coin and that is what will make the outcome probable. But, that is what my exact point of conveyance is: Isn't a "set of probable outcomes" is a set of all solutions which will be achieved on varying the input variables (the above mentioned points) from extremes? Isn't it that we are grouping the "likely" solutions and surrendering to the probabilities because of the ignorance involved in the process of determining the state; I mean the process of capturing variable values and constructing motion equations.

Consider another example of throwing a pack of cards up in air. The position of each of the card, well, is function of initial ordering of the cards, throw-related variables, effect of air resistance, effects of inter-collisions, topology of landing surface and some others.

Well, it seems doable and can be extended to systems comprising of larger variables with apparent increasing complexities.

But, well, we also have giant beautiful foundations like Quantum Mechanics which largely is based on deterministic probabilities - and I'm in no position to write a further word on that. :-|

web counter

Interfacing 128X64 pixel graphics LCD with 8 bit PIC

posted Mar 29, 2012, 9:15 PM by Pratik Panchal   [ updated Mar 29, 2012, 9:50 PM ]

March 2012, Microcontroller Design Lab

Well, I wanted to integrate a touch screen in a project and nothing was quicker to start with, than a resistive touchscreen overlay on a 128x64 graphics LCD - that is what I thought - Actually, it was a pain.

Before this, I had only worked with the conventional JHD402A controller based 16x2 line LCD modules - and those were pretty easy to work with; mainly because of the ease of sending desired data to be displayed. Moreover, the datasheet also provides comprehensive interfacing algorithms with the help of which, you can start straight forward.

But, a graphics LCD (GLCD) doesn't have inbuilt ASCII converter/generator; rather you can control state of a single pixel and hence its not easy to send data to it (well, that is the reason to use GLCD, if you just want to display characters, interface a 16x2 or a 16x4 LCD!!). I bought NT7108C controller based GLCD (which is quite similar to KS0108B module). Even though being a more complicated device than a 16x2 LCD, the datasheet that manufacturer provided along with the module was really crappy and technically insufficient - and I realized this after getting one (bad luck, eh!). The first time, when I referred the datasheet, I couldn't even understand the architecture properly. When I developed the code referring the timing diagram given, the GLCD just didn't respond. After a while, it started giving junk. Well, finally, it after lot of code optimization, I was finally able to get through and print the favorite phrase - Hello World!.

I would like to document all my efforts here on my webpage for (1) my own ready reference, and (2) for the reader who would like to save time experimenting with and adjusting the timing cycles. Continue reading in 'My Wired World'

Enhanced Matrix Keyboard - An Idea of Pin Optimization - An Experiment

posted Jul 17, 2011, 6:42 AM by Pratik Panchal   [ updated Jul 19, 2011, 12:54 PM ]

17th July, 2011, @Desk, Ankleshwar.

There are several ways to interface keys with a microcontroller to create a HMI. The matrix layout is known to be one of the most port-pin-optimized solutions for interfacing keys to a microcontroller. The maximum number of keys that can be connected through matrix layout is given by the expression NC*NR; where NC is the number of columns and NR is the number of rows. This article addresses to this topic and proposes a novel solution for increasing the number of keys to (NC*NR)+NC without affecting the performance of the device. It can be effectively applied to scenarios where more number of keys is required to be applied with limited number of port-pins....Read More in 'My Wired World'

The Need of Higher Education in India - A thought

posted Apr 13, 2011, 9:14 PM by Pratik Panchal   [ updated Jul 19, 2011, 10:23 AM by Pratik Panchal ]

13th April, 2011, @Desk, Manthan, Surat.

I am of a strong opinion that the higher education propels the growth of my country and secures the future of coming generations. It has a tremendous positive impact on the overall development of India.

Although the literacy rate of India grew to 74.04% as per the latest survey (2011), most of this goes into the routine infrastructure operation and maintenance. This is because our graduate level of study in India does not develop and prepare an individual for scientific research work and to look into the brand-new developmental facets. We still very much depend upon external resources (read as ‘countries’) for the technology, products, and methodologies. With such a large economy and population, it is of vital importance that we become self-sustainable and come in the lane of claiming more ‘patents’ and developments. I strongly believe that this can be achieved if our youth power is guided down to the channel of higher studies and specializations.

Although our country has some of the best institutes where quality higher education is imparted, people are not truly inclined towards gaining the higher education. This is because people only think of individual socio-economic growth rather that national socio-economic growth which is only brought in by the higher education. Higher education also abridges cultures and brings in diversity. This results into broader views and brings in more developmental aspects. It acts as a catalyst for transformation of current developments into more sustainable ones. As Dr. Abdul Kalam has rightly said, ‘higher education provides skills for learning to know, learning to live together, learning to do and learning to be’. Higher education equips people with the capabilities to transform their visions into the reality; to have power to see the world of difference and to fuel-in the growth at a faster rate. Moreover, the higher education provides a platform for interaction between thinkers. It enables the professors and technologists to refurbish & renovate themselves with fresh ideas from the incomers and helps the incomers to gain the strenuous knowledge base that their seniors have gathered. The more obvious benefits of the higher education are more employability, better socio-economic growth, development of scientific outlook, enhancement of the research and experimentation capabilities, and advancement of knowledge base of the nation.

With the aid of higher education, we, as a people of one of the largest economy, gets a scope for expansion of our strengths with continual improvement on the quality facet of the developments. A sense of responsibility not only towards oneself, but towards society, nation and mankind on whole is implanted in the individual. This leads to production of efficient leaders of which we are in dire crises at the upper level of national administration committee.

Concluding, the higher education can be considered as a key ingredient in the overall development of our country and its large diversified population. It can help to create a common platform from where the burning issues of our society can be addressed. It can help in eliminating dependency and bring in confidence for the nation to stand straight. It can lead to development of efficient leaders in the world market space who can help in abridging the cross cultures, can help in channelizing the youth power, and in overall sense, can make this country a more beautiful place to live in.

Implementing UARTs in baseline and mid range PIC devices - An Experimentation

posted Mar 11, 2011, 9:01 AM by Pratik Panchal   [ updated Jul 19, 2011, 10:23 AM ]

11th March, 2011, Surat.

Although most of microcontrollers come with an inbuilt UART/USART peripheral, most of the baseline and mid range PIC devices don't have it (for example, PIC12F510 & PIC16F526). For hobbyist and armatures, buying a new chip for performing a UART related function may not seem to be an 'economical' option. For such geeks, building an algorithm for performing this function may be an adventurous and interesting path..... (Read More)

Wall-E: A potential project

posted Dec 21, 2010, 6:00 AM by Pratik Panchal   [ updated Jul 19, 2011, 10:26 AM ]

21st December, 2010, Surat:

Most of us have been bewildered by the Disney's Wall-E personality showcased in the movie 'Wall-E' in 2008; and I'm sure it would be a dream of every wizard to have one. 

Lately, I came across the 'real Wall-E' video on the web and it is extra-ordinarily impressive. 

I think some of our final year friends must build it. Structurally it is quite simple but it houses almost all the functionalities. The movement can be impressively built on a single shaft driven by a stepper motor. Wall-E's belly can be best used to encompass the electronics and the bulky battery. The limbs can be powered with hydraulics if planned for contraction & retraction. The joints at the neck and limbs need to be really smart since the CG of Wall-E depends on it. I can visualize that a combination of 18F series PIC controllers can be seamlessly integrated to bring Wall-E into life. Obviously, if video processing is planned, a 32 bit processor or DSP is required. Few of the Wall-E's famous grunts and audio clips can be recorded on APR9301 chip and can be integrated with the controller to produce a combined flavor of specialized movements and sound. Ultrasonic distance measurement algorithm can be implemented for giving a sense of walking to the 'Wall-E'. Even, small solar panels can be motor fitted on side ways, which can open-up in sunlight to charge up 'Wall-E'. 

I think, one can keep on pouring ideas to make a really lovely Wall-E. I hope some one comes up with it. I am sure, I'll try it as soon as I get some empty days..!

1-10 of 14