Tuesday, June 29, 2010

Solar Controller

I've been working on a simple solar heating controller based on an Arduino open source hardware microcontroller.

The design was inspired by Tristan Lea's unit on his openenergymonitor blog, and it was a project that I had been meaning to get around to doing on return from China.

Trystan's unit used PT1000 sensors and an analogue multiplexer and op amp circuit to scale the sensor readings. I decided to use 10K NTC thermistors because they are cheap and easy to use and accurate enough for this sort of application.


It started with a nice blue LCD from Moderndevice, which comes with a LCD117 PIC based controller kit which makes displaying text as simple as serial.print statements from the Arduino.


It connects via a 3 wire interface, making it easy to have the display some distance away from the Arduino board. There are 3 spare outputs on the PIC for driving LEDS, and one can drive a piezo buzzer. The PIC allows the brightness of the display to be controlled using pwm.

It took about an hour to assemble the kit and get the display to show analogue readings from the Arduino. I also wrote a bit of code to display the time, counting in seconds and displaying leading zeros where required.

The next thing was to interface the analogue input channels to the temperature sensing thermistors. I had some pipe clip thermistors from Rapid Electronics, which will clip directly to 15 or 22mm copper pipe.

Using code on the Arduino forum to linearise the signal from the thermistors, I soon had them displaying in degrees centigrade. The linearisation uses the Hart-Steinhart equation which is simple in C, but previously had been stumping me to try to write it in assembler.


The Arduino will read up to 6 thermistors on its analogue inputs, but I chose to fit 3 and a variable resistor "pot" which allows me to define a set-point.

I'm not quite ready to fit the controller onto my solar panel system, so I thought I'd use it to monitor the various temperatures of my hot water tank. The Arduino outputs its thermistor readings to the display once per second, and also via the serial/USB interface to the laptop. They are generated as a CSV delimited file which can be read in and stored using the likes of Hyperterminal and then manipulated and graphed using Excel. The graph shows temperature of my hot water tank (red) heat up when hot water from the gas boiler (blue) is pumped through the heat exchanger coil.

I've realised for sometime that the Arduino could be much improved with the addition of a dedicated Real Time Clock and data storage using a SDcard interface. I learnt this week that NuElectronics have recently released a new shield combining RTC and SDcard. It also has 6+2 connectors allowing 1-wire or 2-wire sensor devices to be connected to it. More details here:

Similar products combining SDcard and RTC are also available from Lady Ada and Seeeduino Studios.

This new shield will transform the Arduino into a datalogging hub forming the basis of an integrated energy monitoring system - along the lines of Trystan Lea's openenergymonitor. With an ethernet gateway, the real time and logged data could be made available to the net via such services as Pachube.

Here are a few ideas how it could be used:

1. Solar Water Heating Controller - simple control with circulation pump relay
2. Central Heating / woodburner controller - determines best usage of hot water
3. Electricity Monitor - whole house electricity consumption
4. Gas consumption monitor - pulse counter on optical sensor on gas meter
5. pV / battery charge controller/datalogger
6. Gasifier controller
7. CHP controller - engine start/stop, rpm, voltage monitor etc
8. Battery management system for wind or solar pV.
9. General purpose sensing, datalogging and control tasks
10. Temperature, climate and weather monitoring and datalogging.

What is needed now are some standardised communication protocols to allow Arduino based hardware modules to communicate with one another, and the central hub and thus via the ethernet link to the web.

Sunday, June 20, 2010

Eating Out in China

I now come to the third part of my short series of observations about everyday life in modern China.

We have all seen TV documentaries of the bizarre cuisine in China, such as a couple of years ago when Paul Merton had lunch and interviewed a crazy woman in a restaurant that served snake and donkey penis.

Fortunately I have not yet stumbled across such establishments (or women), mainly because of self-preservation mantra “Stick to what you know”.

A Hong Kong friend man told me many years ago “If it moves – the Chinaman will eat it” – this was of course the abridged version, it should actually have been:

“If it slides, slithers, swims, scurries, scuttles, slips, creeps, crawls, climbs, dips, dives, hops, hobbles, jumps, jives, walks, wades, waddles, flys, flaps, flounders, flutters, frolics or f**ks – the Chinaman will eat almost every part of it”.

With this in mind, there is a high probability that you will encounter unfamiliar foodstuffs – so I offer this short guide to eating out in China.

The working title of this episode ought to be "How to retain your health and body weight - whilst all around you are trying to poison you".

Whilst living in a 5 star hotel, there are of course the hotel restaurants, Western, Chinese and Japanese style - as well as a revolving restaurant on the 24th floor, from where you get a panaoramic view of this area of Shenzhen's surrounding suburbs. We're next to Shenzhen airport here - so imagine it a bit like Staines or Houslow but a lot more densley built with high rise appartments. The Western style restaurant is at best disappointing, the others are over priced - so by way of adventure - and to get out of the hotel at night, I risk life and limb, cross the streets to the town centre and seek out local culinary diversions.

There are many outlets offering food in China, these range from market stalls selling snacks in the street, small makeshift eateries – that look that they adopt a fly by night strategy to avoid hygiene inspection, “mom & pop” family run restaurants – which is what folks drift into when they accidently end up with more than one daughter, and finally a multitude of specialist restaurants, offering food from all regions of China.

There are of course a plague of Western franchises, KFC, McDonalds, Pizza Hut, Starbucks – these tend to be common in the cities and the larger towns – the restaurants of last resort. In 30 years the next generation of Chinese will be unrecognisable - already the Hong Kong youth suffer from imported obesity from a diet of western junk food. (There's gotta be a pun there somewhere).

Street Cuisine.

This is literally prepared in the street and consists of simple foodstuffs or snacks, cooked or barbequed on charcoal or gas braziers mounted on modified tricycle stalls. The food often consists of barbequed or deep fried fritters/critters on sticks and sell for 2 or 3 Yuan. In homage to Monty Pythons “Chocolate Box” sketch, “Crunchy Frog” or “Lark Surprise” may well be on offer. A disguise of golden batter makes even the most exotic appear appetising.

Other stalls offer omelettes, pancakes, hard boiled eggs and fried waffles. Some traders offer carved pineapple, lychees, grapes, bananas – fruit that can be eaten “on the go” plus lengths of sugar cane to chew on – and then have to spit out great wads of sugar cane “cud”. Some stalls have a special cane-crusher machine mounted on the back of a trike – and offer freshly squeezed cane juice.

My advice with all street food – is try at your peril. The cooking facilities are at best basic, the vendors have no means to keep hygienic conditions, and any water used may be straight from the local tap – and really should be boiled before consumption. Bear this in mind with any fruit, that may have been handled or washed in the local water.

So how bad can it be – everyone will have had a “dodgy burger” from a catering trailer at an outside event – but here in China, the implications can be a little more severe. Best advice is stay clear of street food – just ‘cause the local factory workers can eat it – is no guarantee that your metabolism is quite ready for it.

“Fly by Night Cafes”

These consist of a mixed assortment of plastic tables and stools arranged outside an open shop, often under a fold out canopy to keep out the sun and rain. They are found predominantly in the industrial zones – directly across from the factories. They offer low cost eating for factory workers – as an alternative to the rather institutionalised works canteen. Meals will be about 10 Yuan (£1) per dish, and are served with a plastic mug of warmish water. If you eat in these outlets – don’t look too closely at the decor nor the serving conditions. Make sure they use new, disposable chop sticks – individually packed in a paper wrapper. These cafes offer budget eating, but at the end of the day – you get what you pay for.

Next up the hierarchy, are the family run restaurants. These usually have about 30 to 50 seats arranged around plain wooden tables. The service is polite and if you attend frequently, they get to know you and what you prefer to eat. A meal consisting of a bowl of soup, a rice or noodle dish and a large (600ml) bottle of Tsing Tao beer can be had for 21 Yuan (£2.10). I usually have fried rice with shredded beef or pork for lunch at such a place close by the factory. Fried rice by its nature is cooked at high temperature and the thin shreds of meat are also well cooked and easy to eat with chop sticks – this is an important consideration if you new to chop sticks. Whilst more elaborate dishes are available, such as pork chop, beef medallion or roast chicken – these are not so easy with chop sticks and involve either a lot of gnashing of teeth or man-handling like barbeque food.

The Chinese have a particular desire for food that offers “mouth feel”. To the unaccustomed Westerner, this means bony, lumpy, gristley or chewy and downright awkward to eat without having to eject bits onto your plate. Whilst this might appear bad mannered in the UK, it is common for anything inedible to be ejected directly onto the table cloth – so no need to be embarrassed – you won’t offend anyone. Table manners, like driving skills, are mostly absent here. Soup is slurped, rice scoffed from bowl to mouth, bones spat out, extra gas belched and teeth customley picked at the table.

A particular note about roast chicken – for the uninitiated. In the UK we generally joint our chicken into easy to manage portions, legs, wings breasts, making it easy to eat, either by fingers at barbeques or with a knife and fork. In China, after roasting a chicken, they put it on a chopping board, and section it laterally across the rib cage with a very sharp cleaver. This leaves a series of strips of flesh, about half an inch wide, each featuring its own bits of cut rib bone – another hazard and pitfall for the chop-stick newbie. This means that if you order chicken, it will be served on an oval plate, in the above fashion – still with the head at the end of the plate.

Specialist Restaurants. These abound in all the big towns. They are normally based on some regional speciality, such as Hunan, Szechuan, Cantonese (Hong Kong Style), plus Vietnamese, Thai and Japanese. I will describe two that I have had some recent experience of.

Hot Pot. This is a style from the north west of China, close to the nomadic sheep and goat herding areas of Mongolia. If the restauranteurs are genuinely from this area, they will be tall, muscular and ruddy faced. The dish consists of a large stainless steel pot of hot, spiced lamb broth – similar to a round washing up bowl, full of a liquid that looks like dirty dish water, which is kept hot by a gas burner set into the centre of the circular table. During the course of what is usually a 2 hour meal, you order various types of wafer thin sliced meats, meat balls, vegetables and mushrooms which you broil for a few minutes in the broth and eat with bowls of rice. As the evening proceeds, the broth thickens with the fats and juices from the cooked mutton. The hot pot is a very sociable meal, and a good opportunity to chat – so best attended with at least 4 people. Remember to take your interpreter – it’s almost impossible to order the right mix of dishes without someone who speaks the lingo. Wash the whole lot down with copious quantities of cold Tsing Tao beer. They do a spicy variant of the above dish – which is definitely not for the faint hearted. I tried it once and it was disappointing – way too hot for general consumption.

Maojia Restaurant.

This is often called “Mao Style” and it is a regional style from the Hunan province, where Mao was born. It is characterised as being hot and spicy, copiously involving the use of red and green chillies. If you are “up for a curry” this might just suit you – as curries are either non-existent or disappointing in this area. Dishes consist of meat or fish, served on a sizzling iron platter of red and green chillies. If you are lucky, the restaurant will have a picture menu – so best is to look for the ones that don’t have so much chilli – this can however be a bit of a “point and prey” lottery – rather like pinning the tail on the donkey. If you are lucky, the dish will be more or less what you expected, but I did once order liver rather than beef, as the picture was a bit unclear. The chefs tend to chuck in a lot more chillies than the picture might suggest – and I had one dish earlier this week, that was over-endowed with green chillies and almost too hot to enjoy.

Ordering from anything other than a picture menu is difficult, if dining alone. Fortunately I often have a Chinese friend with me, who keeps me out of trouble. I have however picked up a few words that usually result in the right dish being delivered.

A typical conversation in the restaurant might be:

Nihau - “hello, how are you”, then raise one digit to indicate that you are a sad lonely, singular western diner.

Nu yo chow fan - this normally is understood as fried rice with shredded beef.

Tsing Tao pee-jew – this will bring you a bottle of the local lager and a very small tumbler glass – this week there was a Tsing Tao promotion, and the nice girl in the Tsing Tao T-shirt put down a shot-glass not noticing that there was a small dead cockroach in the bottom. I pointed out her error and she got me a fresh one.

Fuwu yuan - “Waiter”

My Fan - reminds them you want a bowl of steamed rice

Ma Dan - bill please

She-she - thankyou

Bye bye - good night and thanks for having a giggle at my expense but hopefully not poisoning me. I’ll know within the next four hours.

Here’s some things I learnt during my odyssey:

During the course of your meal, expect lots of shouting from neighbouring tables when it comes to either place the order or discuss the bill. Smoking is still common in restaurants.

Don’t fret if you see a waiter with a fishing net go to the fish tank and bring back a live fish and head for the kitchen. They like their fish very fresh here. One barbaric delicacy is a live fish dunked tail first into hot oil, with its head and the chef's hand wrapped in a wet tea-towel. It is still (barely) alive when served at the table. Makes the "Spooks"/ deep fat fryer scene look quite tame really.

The “mom & pop” restaurant where I have lunch has a back kitchen with blazing gas burners. Occasionally there are minor explosions and loud “whooshes” and flames seen from the kitchen as the oil mist ignites over the gas burner – makes for a more exciting cooking experience.

If it looks like battered onion rings but very chewy, it’s probably sliced rings of pig intestine fried in batter.

Having started a meal in a small restaurant, I once saw a large rat make a bid for freedom, run from the kitchen area, across the restaurant and out of the front door. Rat was probably not on the menu – so I didn’t fret too much.

So now that we have got the polite aspects of eating out in China out of the way – I would like to warn you about some of the after effects and how best to cope with them.

Fortunately restaurants give you a plastic packet of about 8 or 10 folded napkins. These are great for wiping grease off your chin when struggling with chop-sticks – but at the end of the meal, keep the rest of the packet, put them in your pocket and take them with you – you may need them later.
Chinese restaurants seldom have western style toilets, so plan your evening so you are not caught short at the restaurant. Aim to base your daily business about the hotel, as western toilets, loo paper and soap are seldom found outside the hotel.

Last year, three of us staying here, who had a hot pot, suffered in the night and for most of the following morning. We had a bit of a laugh about it – put it down to bad luck, and returned to the same restaurant a week later with no similar effect. The effects are short lived and soon over within 12 hours.

Fuelling the Fires of Industry

The second of a short series of posts about day to day life in Southern China.

The miracle of economic growth that has blessed China in the last decade, has left a population rapidly trying to catch up with the rate of change. Agricultural villages in the Shenzhen, Dong Guan, Guang Zhou "Triangle", have expanded into bustling industrial towns in the matter of just a few years. Farm fields sold off to developers to produce industrial zones of identical factories and tracts of urban housing apartment blocks.

The rate of growth can probably be likened to that of the London boroughs during the 1830s in our own Industrial revolution - just on a much larger scale.

Modern factories compete with simple workshops - often located in the main street. It is common for the various traders to group together - for example, one Sunday morning in Chang An, I passed about 20 shopfronts all of which specialised in stainless steel wire and pipe.

The photo at the top shows a metal fabrication workshop in Chang An. Steel stock is piled up in the street and cut into the necessary profiles with simple jigs and gas cutting torches. Here a worker is cutting circles from heavy gauge steel plate.

Amongst this new urban chaos, live the bemused population, - factory workers, shop keepers, handymen, porters and the recyclers of which I spoke last time. The three cities named above are home to nearly 35 million. Equivalent to half the population of the UK, shoe-horned into an area less than the size of the southern Home Counties.

Keeping this population moving are a series of modern dual carriageway roads and 3 to 4 lane expressways. Competing on these roads are a mix of trucks, buses, vans, cars, motorbikes, auto-rickshaws, electric scooters/mopeds, bicycles and pedestrians - in roughly that pecking order.

To the uninitiated Westerner, the road traffic looks like total chaos, ungoverned by any rules or regulations. However, somehow, the system seems to work in a way that would seem impossible in the UK.

To understand the system, you have to discover a few things the hard way - if you survive the first time you cross a pedestrian crossing - you have cleared the first Darwinian hurdle. So here are the 3 things you need to know - "Three Steps to (avoid) Heaven".

First of all, there is no concept of "right of way". Most drivers will cut across the path of oncoming vehicles, loosely based on the pecking order above, and a quick decision on the size, speed and braking capability of the oncoming vehicle. It seems perfectly normal for a car to turn left across an on coming stream of motorcycles and electric mopeds, expecting them to slow down, stop or change their direction.

Secondly, road markings, such as centre-lines, double centre lines, stop lines and zebra crossings mean little if anything to the average road user. If your lane is blocked - then use the other carriageway, even though it might involve playing "chicken" across the centreline (or double centreline) with the oncoming traffic. If they are "just" bikes and scooters, they will probably part out of the way, if they are bigger than you, just barge in front of the obstruction you just overtook, and carve them up. My driver has scared me on many occasion by first overtaking and then carving up a 40-tonner with a fully laden shipping container on the back!

Thirdly, blowing the horn at every second vehicle appears to be mandatory, whenever other road users come in your way. Chinese cars should be designed with no indicators - totally redundant - but an extra horn or two controlled off the redundant indicator stalk.

Horns are used in advance to warn other slower road users or pedestrians that you have either no intention of stopping (see concrete trucks - below), so they should get out of your way, or as an indication to other slow road users that they are in your way and should change lanes or yield. There is no lane discipline, so you will commonly find a poor soul on a pedal-trike, or auto-rickshaw, holding up a queue of traffic in the outside lane of a 2-lane street. No problem, just undertake on the inside, comandeer the opposite carriageway or even the pavement if it looks easier - just keep moving, by whatever means possible.

The worst offenders are concrete trucks - the revolving type. Time, tide and setting concrete waits for no man - and the drivers of these trucks drive to the max, often with the horn on at all times - especially if there may be bikes or people crossing the road that might get in the way of them.

Pedestrian crossings are widely ignored. If you are a pedestrian on a zebra crossing, you often have to dodge oncoming vehicles or freeze like a bunny in the headlights as buses and trucks pass you on each side. Light controlled pedestrian crossings are almost as bad. Even if the green man is illuminated, there will be someone jumping the lights, sneaking a right turn on red, and generally trying to wipe you out.

One way steets are generally ignored - it is common to have to avoid oncoming traffic driving the wrong way on the slip road to the dual carrigeways. Exiting a carriageway on the "on ramp" is a common dodge if it will save you a few seconds - regardless of what happens when you come into conflict with those trying to get onto the carriageway. Even the buses and 40 tonners do this!

At night, the perils are a bit greater. Electric bikes are virtually silent and few use their lights after dark - a way of extending the range. Car drivers often drive without lights, use of lights and windscreen wipers appears to be arbitrary.

Even on the pavement, the pedestrian will still encounter road users. Cars will drive on the pavement if the road ahead is blocked. Bikes, trikes and e-bikes will sneak up on you on the pavement and then expect you to yield.

Most residents in the industrial towns are young and inexperienced of road traffic. Factory workers from rural towns flock to the urban areas and have little or no traffic awareness. Just by looking at oncoming traffic when they blindly stroll across the road would be a good starting point. Many are oblivious to oncoming traffic until they hear the blast of the horn. As darkness falls at 7:30 in this lattitude - workers exiting from an evening shift, at the end of a 13 hour day are generally oblivious to the container trucks that thunder through the industrial zones.

China still has a relatively low traffic density, which is probably the only reason that it can move in this manner. If car and vehicle ownership is to rise, then it must be followed with a roadsense awareness campaign - starting in primary school. Only then will they manage to increase their vehicle numbers and keep it flowing - and slowly move to a system like the West, based on discipline, rules and awareness of other road users. Currently you have to drive here in a manner that assumes that there will be a stationary object around the next bend - or at least expect a vehicle of any size or type to inexplicedly cross your path without notice.

Seatbelts are seldom fitted to cars. Taxis fold away the buckles under the back seats so that they cannot be fastened.

Youngsters are rapidly becoming more mobile with the introduction of affordable electric mopeds. It is common to see a lad riding, with his girlfriend riding side saddle on the back. "Three-up" on a scooter is not uncommon, and I once saw a family of 4 conveyed on one - oblivious to the danger that their children might be in, should they be struck by another vehicle. The other day, I saw a young mother riding a moped, with a toddler, squeezed between her knees, riding on the "footplate" at the bottom of the battery housing. He was unable to hold on, but just gripped between his mothers legs.

Every day one witnesses the bizarre, the foolhardy and the downright dangerous, but somehow the system works, and there does not appear to be a huge amount of carnage on the roads, ambulances or wrecked vehicles littering the highway.

To those of us that have learned our driving skills in the West, the traffic conditions here are alien at best. Who knows what our very own Health and Safety Inspectorate would make of it - perhaps they would become deeply traumatised, realising that they were powerless to change the ways of the population here. Perhaps we could wholesale export the HSE and all their minions to China?

Next time I will cover food, eating out, and coping with other unpredictabilities brought on when living in this quaintly crazy place!

Steet Life in Modern China

Some of you will know that I have spent most of the last month in Southern China, working in an electronics factory.

After 3 weeks of "putting up" with the basic living conditions, the squalor, squat toilets, the mad traffic and the lack of written or spoken English, I guess cabin fever begins to set in.

It came to a head last night when my boss decided that it would be good if I spent another week here, but sadly I only have a 30 day visa - so I'm back on a plane next Wednesday.

Whilst cooped up in the hotel room in the evenings - it is dark by 7:15pm, and the streets are not safe more than a few 100 metres from the hotel, you spend the time reading internet forums and blogs, listening to the BBC World Service and Radio 4 - and having a couple of beers.

Tsing Tao Beer, sells for about 30 - 45p a 600ml bottle in the convenience store around the block, but in the hotel bar, a 330ml bottle is £3.50 - talk about exploiting the guests! So I tend to support the local shopkeepers and buy my beer outside of the mad oasis, I find myself bunkered in.

The empty bottles are recyclable, and 4 bottles will fetch about 1 Yuan or 10p. Tonight I dropped off 8 empties, on the way around to the store.

At night, the streets become alive with those that perform the recycling function. Men and women on trikes and motorised 3 wheelers, tidy up the streets of all the cardboard, glass, packaging, food waste that is produced by the businesses in a busy town during the day. If it were not for these nocturnal workers the town would drown in it's own filth. Nothing goes to waste - this economy cannot afford to waste anything of value - no matter how small that value might be.

Particularly noticeable is the 3-wheelers with a couple of blue barrels on the back. These belong to the grease collectors, and they perform a nightly function of clearing the hotel and restaurant drains of the coagulated fat that collects in the grease traps. Tonight I passed a couple of them, clearing the traps of this hotel, using a sieve on the end of a bamboo pole. The stinking grease is collected in the plastic barrels and then taken somewhere where it is rendered down, filtered and probably goes towards making fuel for the basic tractors that they run around here.

As I left the £60 a night, 5 star hotel, I spared a thought for the old man collecting cardboard onto his tricycle at the back of the hotel. I gave him the 8 empty beer bottles, which he gratefully accepted - with not a little incredulity. The 2 yuan that these fetch, will probably mean that he eats a little better tonight.

The minimum wage for registered workers in this area is 1000 Yuan (£100) a month. For those that have migrated from the rural areas and do not have the correct urban "hukou" registration papers - their chances of a minimum wage are totally non-existent - they are not recognised by the state and have no entitlements - a virtual slave class in what was supposed to be an equal Communist society. Hence their seemingly scavenging life, not only provides an essential service for the district, but provides for them a very meagre source of income. China provides no welfare safety net for the elderly, infirm or out of work. The Hukou system has effectively forced a two tier society of the waged and the unwaged. The rural migrants do not appear on any unemployment statistics and are thus effectively hidden from the official figures - however, they are very much in existence, and very much present for those who only care to look.

So when you buy your laptops, iPhones, iPods and solar panels from China - don't worry about the factory workers. They are the lucky ones working in relatively well paid jobs. Of greater concern is their parents generation, outcast in the 1960s by Mao's radical reforms, and in 40 years are still out of kilter with "modern" China, and will remain so until they work themselves towards an early grave.

A View of Modern China

For the last 4 weeks, I have been working out in southern China, helping out with production of a consumer telecom product.

I was staying in the industrial town of Fu Yong, which is very close to Shenzhen Airport.

During my stay there, I had the opportunity to write a few entries based on my daily observations.

These will now be reproduced in this blog over the next few days.

I have been traveling to southern China since 2000, and have seen the rapid rate of change over the last 10 years. My job takes me onto the factory floor of the modern electronic manufacturers and I spend time working with Chinese workers on the line.

As a design engineer, the move to Globalisation has meant that the products I work on invariably get manufactured in China. So in ten years, I have nurtured five products through the initial stages of manufacturing, solving design problems, testing for faults and generally ensuring that production goes as smoothly as possible.

Language is often a problem, but I have been lucky that I have generally been accompanied by an English speaking local engineer.

Life in 21st Century China is basic, but fascinating - as I hope the next few posts will illustrate.