Arduino library writer guide and specification

Arduino Style Guide for Writing Libraries – Arduino Reference

This is a style guide to writing library APIs in an Arduino style.

Some of these run counter to professional programming practice. We’re aware of that, but it’s what’s made it possible for so many beginners to get started with Arduino easily.

So please code with these principles in mind. If you have suggestions on how to make Arduino libraries clearer for that core audience, please jump in the discussion. This is a work in progress.

Be kind to the end user.

Assume you are writing an API for an intelligent person who has not programmed before. Come up with a clear mental model of the concept you’re working with, and the terms and functions you will use.

Match your API to the underlying capabilities. You don’t want to expose implementation details to the user but you also don’t want an API that suggests an inaccurate mental model of the possibilities. For example, if there are only a few possible options for a particular setting, don’t use a function that takes an int, as it implies you can use any value you want.

Organize your public functions around the data and functionality that the user wants.

Quite often, the command set for a particular electronic module is overly complicated for the most common uses, or can be re-organized around higher level functionality.

Think about what the average person thinks the thing does, and try to organise your API functions around that.

Adafruit’s BMP085 library is a good example. The readPressure() command performs all the necessary steps to get the final pressure.

The library wraps this commonly executed series of functions into a high-level single command which returns the value the user’s looking for in a format she expects.

It abstracts away not only the low-level I2C commands, but also the mid-level temperature and pressure calculations, while still offering those mid-level functions as public functions for those who want them.

Use full, everyday words.

Don’t be terse with your function names or variables.

Use everyday terms instead of technical ones.

Pick terms that correspond to popular perception of the concept at hand. Don’t assume specialized knowledge.

For example, this is why we used analogWrite() rather than pwm().

Abbreviations are acceptable, though, if they’re in common use or are the primary name for something.

For example, “HTML” is relatively common and “SPI” is effectively the name of that protocol (“serial-peripheral interface” is probably too long). (“Wire” was probably a mistake, as the protocol it uses is typically called “TWI” or “I2C”.)

Avoid words that have different meanings to the general public. For example, to programmers, an error is a notification that something happened. To the general public, errors are bad things.

When you have to use a domain-specific term, write a sentence or two describing it to the general public FIRST. You’ll likely come across a better term, and if not, you’ll have started the documentation on your library.

Document and comment as you go. When writing examples and documentation, follow this style guide:

Use the established core libraries and styles.

Use read() to read inputs, and write() to write to outputs, e.g. digitalRead(), analogWrite(), etc.

Use the Stream.h and Print.h libraries when dealing with byte streams. If it’s not appropriate, at least try to use its API as a model.

For more on this, see below

For network applications, use the Client and Server libraries as the basis.

Use begin() to initialize a library instance, usually with some settings. Use end() to stop it.

Use camel case function names, not underscore.

For example, analogRead, not analog_read.

Or myNewFunction, not my_new_function. We’ve adopted this from for readability’s sake.

LONG_CONSTANT_NAMES_FULL_OF_CAPS are hard to read. Try to simplify when possible, without being terse.

Try to avoid boolean arguments.

Instead, consider providing two different functions with names the describe the differences between them.

Don’t assume knowledge of pointers.

Beginning users of C find this the biggest roadblock, and get very confused by & and *, so whenever you can avoid having them hanging out in the API, do so.

One way is to pass by reference using array notation rather than * notation,

for example.

void printArray( char* array);

can be replaced by

void printArray(char[ ] array);

Though there are some libraries where we pass pointers by using structures like const chars, avoid anything that requires the user to pass them. For example,rather than:

foo.readAccel(&x, &y, &z);

use something like this:

xAxis = adxl.readX();

yAxis = adxl.readY();

zAxis = adxl.readZ();

When using serial communication, allow the user to specify any Stream object, rather than hard-coding “Serial”.

This will make your library compatible all serial ports on Mega and the Due, and can also use alternate interfaces like SoftwareSerial.

The Stream object can be passed to your library’s constructor or to a begin() function (as a reference, not a pointer). See Firmata 2.3 or XBee 0.4 for examples of each approach.

When writing a library that provides byte-stream communication, inherit Arduino’s Stream class, so your library can be used with all other libraries that accept Stream objects.

If possible, buffer incoming data, so that read() immediately accesses data the buffer but does not wait for more data to arrive.

If possible, your write() method should store data to a transmit buffer, but write() must wait if the buffer does not have enough space to immediately store all outgoing data.

The yield() function should be called while waiting.

Here are a few libraries that are exemplary from Adafruit.

She breaks the functions of the devices down into their high-level activities really well.

This does a nice job of abstracting from the Wire (I2C) library: Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

Arduino IDE 1.5: Library specification – Arduino

Cristian Maglie edited this page on Feb 26 · 24 revisions Pages 4

Arduino IDE 1.5 3rd party Hardware specification

Arduino IDE 1.5 from command line

Arduino IDE 1.5: Library specification


Clone this wiki locally

Clone in Desktop

The updated (rev. 2) 1.5.x library format is implemented from IDE 1.5.6. We don’t expect to make any major changes but it may be tweaked while the 1.5.x releases remain in beta.

If you want to join the conversation subscribe to the Arduino developers list:!forum/developers

This specification is a proposal for a new 3rd party library format to be used in the Arduino IDE 1.5.x series.

rev.1 has been implemented starting with version 1.5.3 (now suprseded by rev.2)
rev.2 will be implemented starting from version 1.5.6.
This new library format is intended to be used in tandem with an automatic Library Manager, that will be implemented in future versions of the Arduino IDE. The Library Manager will allow users to automatically download and install the libraries needed in their projects, taking care of dependencies between libraries, with an easy to use graphic interface. Eventually, there will be an online centralized repository, provided by Arduino, where contributed libraries will reside.

Arduino 1.5.x supports multiple microcontroller architectures (e.g. AVR, SAM, etc), meaning that libraries may need to work on multiple architectures. The new 1.5.x library format doesn’t contain special support for cross-architecture libraries, but it does provide a pre-processor based mechanism for libraries to target sections of code to specific architectures.

See also

The Arduino library style guide is here :

The style guide for examples is here :

1.5 library format (rev. 2)
Library metadata

The most significant addition to the format is the ability to add information about the library itself through a properties file called

This file will allow the future Library Manager to search and install a library and its dependencies in an easy and automated way. file format

The file is a key=value properties list. Every field in this file is UTF-8 encoded. The available fields are:

name – the name of the library
version – version of the library
author – name/nickname of the authors and their email addresses (not mandatory) separated by comma “,”
maintainer – name and email of the maintainer
sentence – a sentence explaining the purpose of the library
paragraph – a longer description of the library. The value of sentence always will be prepended, so you should start by writing the second sentence here
url – the URL of the library project, for a person to visit. Can be a github or similar page as well
architectures – a comma separated list of architectures supported by the library. If the library doesn’t contain architecture specific code use “*” to match all architectures


author=Cristian Maglie <>, Pippo Pluto <>
maintainer=Cristian Maglie <>
sentence=A library that makes coding a Webserver a breeze.
paragraph=Supports HTTP1.1 and you can do GET and POST.
Layout of folders and files

Arduino libraries will be composed of a number of folders. Each folder has a specific purpose (sources, examples, documentation, etc). Folders not covered in this specification may be added as needed to future revisions.

Source code

For 1.5.x-only libraries, the source code resides in the src folder. For example:



The source code found in src folder and all its subfolders is compiled and linked in the user’s sketch. Only the src folder is added to the include search path (both when compiling the sketch and the library). When the user imports a library into their sketch (from the “Tools > Import Library” menu), an #include statement will be added for all header (.h) files in the src/ directory (but not its sub-folders). As a result, these header files form something of a de-facto interface to your library; in general, the only header files in the root src/ folder should be those that you want to expose to the user’s sketch and plan to maintain compatibility with in future versions of the library. Place internal header files in a sub-folder of the src/ folder.

For backward compatibility with Arduino 1.0.x, the library author may opt to not place source code into a folder called src. In this case the 1.0 library format is applied and the source code is searched from the library root folder and the utility folder, for example:





This will allow existing 1.0.x libraries to compile under 1.5.x as well and vice-versa. If a library only needs to run on 1.5.x, we recommend placing all source code in the src/ folder. If a library requires recursive compilation of nested source folders, its code must be in the src/ folder (since 1.0.x doesn’t support recursive compilation, backwards compatibility wouldn’t be possible anyway).

Library Examples

Library examples must be placed in the examples folder. Note that the examples folder must be written exactly like that (with lower case letters).


Sketches contained inside the examples folder will be shown in the Examples menu of the IDE.

Extra documentation

An extras folder can be used by the developer to put documentation or other items to be bundled with the library. Remember that files placed inside this folder will increase the size of the library, so putting a 20MB PDF in a library that weights a few kilobytes may be not a good idea.

The content of the extras folder is totally ignored by the IDE; you are free to put anything inside such as supporting documentation, etc.


The list of highlighted keywords must be placed in a file called keywords.txt. The format of this file is the same as the 1.0 libraries

A complete example

A hypothetical library named “Servo” that adheres to the specification follows:













Working with multiple architectures

In 1.5.x, libraries placed in the user’s sketchbook folder (in the libraries/ sub-folder) will be made available for all boards, which may include multiple different processor architectures. To provide architecture-specific code or optimizations, library authors can use the ARDUINO_ARCH_XXX preprocessor macro (#define), where XXX is the name of the architecture (as determined by the name of the folder containing it), e.g. ARDUINO_ARCH_AVR will be defined when compiling for AVR-based boards. For example,

#if defined(ARDUINO_ARCH_AVR)
// AVR-specific code
#elif defined(ARDUINO_ARCH_SAM)
// SAM-specific code
// generic, non-platform specific code
Alternatively, if a library only works on certain architectures, you can provide an explicit error message (instead of allowing the compilation to fail in an difficult to understand way):

#if defined(ARDUINO_ARCH_AVR)
// AVR-specific code
#elif defined(ARDUINO_ARCH_SAM)
// SAM-specific code
#error “This library only supports boards with an AVR or SAM processor.”
Old library format (pre-1.5)
In order to support old libraries (from Arduino 1.0.x), the Arduino 1.5.x will also compile libraries missing a metadata file. As a result, these libraries should behave as they did in Arduino 1.0.x, although they will be available for all boards, including non-AVR ones (which wouldn’t have been present in 1.0.x).


Leave a comment

Filed under Electronics DIY Project

大家對這個荒謬的社會還可以存有甚麼幻想?- 陳文敏

後佔領時代的香港年輕人 – 李怡 Apple 2014nov26






中共所謂做青年工作,不外兩手,一是誘之以實利,比如說要創造給青年向上流動的機會,讓他們較易置業,又或者搞點舞會、男女交誼等活動讓青年發洩精力,梁振英周六參加研討會,建議開放中環海濱的摩天輪一段時間,讓市民免費乘坐,讓青年人可以 Relax & Enjoy。掌權者以己之心度年輕人之腹,認為利益取向就能解決問題,年輕人有利益就不會抗爭了。







這兩手可以解決社會問題乎?且看大陸。經濟起飛了,GDP 居世界第二位,人民生活也改善了些,而










「後佔中」青年政策倒退50年 – 吳志森 2014nov26

■ 政府對青年不滿的真正原因視而不見,以為只要讓青年發洩精力就可解決問題。資料圖片













區家麟﹕如何失去一代人 – 明報 2014nov26

有些印象,近年愈發鮮明︰網上有關中國的評論文章,like 數少,點擊率愈來愈低,維權人士的遭遇,年輕一代開始不太關心;大學課堂上,談中國採訪,相對數年前,同學們不只不感興趣,作為老師,感覺到一種對牛彈琴的冷漠;有個別同學關心祖國,算是「大中華膠」,卻於友儕中感到格格不入,知心者少;大學裏的講座,有關國家時政的,多是內地生出席,關心的本地同學比例出奇地低,發問也不積極。



掌權者連環出招 加速失去一代人


撥龐大資源,資助學生參加祖國交流團,體驗內地互聯網的完善管理,讓每一位學生親身經歷被拒上facebook 與高登的驚愕;一過羅湖橋,就明白翻牆軟件與自由之可貴;原來,在祖國懷抱中,上網,不是理所當然的。









王慧麟 :發洩精力論 – am730 2014年11月26日








香港之青年,同其他發達國家之青年 (即係所謂後物質時代) 嘅成長背景,社會形態,家庭狀況都有相似之處。




王永平 :羅范與之鋒 – hkej 2014年11月26日





黃之鋒在 Facebook 回應,「請羅范轉告那位朋友,他可以移民到一個沒有共產黨的地方,但不能移民到一個沒有年輕人的地方」。這個回應,半日內有萬名網民 like。


羅范椒芬指香港的成年人 (應該包括特首和一眾政府官員及行會成員) 沒有好好引導香港的年輕人。她用「引導」一詞正好反映問題所在。合理假設是政府很想引導年輕人思想正確,但為甚麼他們不接受,例如在人大的普選決定上?政府內的成年人是否需要逆向思維,嘗試接受年輕人的「引導」。


港青不是跳廣場舞的大媽 – 林夕 Apple 2014nov26









羅范大媽,移民埋便 – 陳也 apple 2014nov26







區家麟: 移民的理由 – 2014nov26














你害怕的東西 – 高慧然 apple 2014nov26






陳文敏:國民和歷史教育 – 明報 2014nov26









蕭少滔: 滬港通改不了中國靠香港集資的格局 – 2014nov26



不過就在滬港通「出閘脫腳」之後,「中廣核」H 股在香港招股,還是賣個滿堂紅。集資額預算增加到36億美元。這是香港全年最大的一宗上市個案。而先前的中廣核美亞核電,也集資了超過30億美元、之後還要股價再漲50%。雖然先前阿里由董建華親自摻扶跑到美國去上市 (大家可以看看董事名單)[1],算是搶了香港一大塊肥肉,但基本的格局還是改不了:中國的主要股權資金融資,還是由香港和美國包辦。至於董老……還是…..非常愛國。

以下是 Dealogic 2014年11月11日刊登的「中國跨境股權融資」統計,大家可以看個清楚:

中國跨境在國外(包括香港) 發行的股票,在2014年首三季度,金額接近700億美元,宗數為235宗。其中阿里巴巴單一項目集資就超過250億美元。和香港相比,亞洲其他市場都在「食塵」。

其實如果不是因為阿里巴巴的單一案例,香港在過去多年,一直都是中國吸納外國股權資金的主要平台! 即使是國際金融風暴最風高浪急的幾年,香港仍然撐起了中國的集資需要。



金融發展局的統計顯示:在港上市集資的主要是「中國企業或基地在中國的企業」,但同時,只是12%在上市時仍然以「中國企業」身份上市,反而是86% 是以「開曼群島註冊公司」的方式上市!


反而在中國大陸,在滬港通未開通之前,股市的集資功能經已「大削」一半! 到2014按統計2014年上半年只是352億人民幣,大約57億美元。算盡全年俾一個 double, 都是114億美元。跌出全球主要排名榜[3]。中國股市的「後繼無力」早已不是新聞,因此從個角度去想想,到底滬港通的通與不通:於港何損? 真正着緊的中國,不是香港。

反觀香港市場,截至2014年10月的交易所統計,單是主板市場 IPO 的集資金額已經超過176億美元[4],還未計算最後一季的上市,例如中廣核的36億美元上市個案。由於經已超額多倍,並且有40% 由基石投資者認購,相信這個上市個案會將香港的金融市場地位再向上提升。

但這些又算不算是「惠港措施」? 還是在商言商,只是市場行為?


其實看看梁振英的「金融發展局」,看看顧問和成員名單:Blackrock, Citi, McKenzie, Morgan Stanley, Mapletree… 擺明是歡迎外國勢力介入香港的金融政策制訂啦! [6]






[5] 網誌 2014年7月18日【為什麼中共怕佔中:金融數據的啟示】


林行止:安倍贏面甚大 日圓滙價插水 – hkej 2014年11月26日





本報網站作者假才子,二十四日在免費報章 am730 發表《在野黨混亂有利安倍》的特稿,顧題思義,作者是從在野黨各有議題、群龍無首以至互相攻訐,推斷安倍即使民望趨下游亦能取勝。此非泛泛之論而有具體內涵,非熟悉日本政情者無法命筆,確是佳構。不過,筆者從日本國會實際情況看,亦見安倍勝算較高。一共有四百八十席的國會(下議院)被解散前,「自公聯盟」合共佔三百二十五席(自民黨二百九十四席,公明黨三十一席),即執政聯盟的席位比半數多達八十五席;在這種情形下,即使自民黨在十二月選舉中失五十席,仍能與公明黨組成穩穩控制國會的聯合政府。

除了「數字遊戲」,筆者認為當前日本的政治氛圍對「自公聯盟」絕非不利。首先是,在宣布提前選舉同日公布的競選政綱,包括新政府將削減日常食用品的稅率(及其他與民生有關的稅務寬減措施),有利爭取低下階層的選票;其次是,十一月十日安倍「終於」與中國(也許是亞洲)新強人習近平主席握手,以習大大拉長黑面,這次簡短之會不能說中日領袖「相見歡」,但自從去年十二月安倍參拜靖國神社觸怒北京因而被北京公開宣布他是不受中國歡迎的人物,至今未足一年,安倍便以貴賓身份抵達北京,「習安會」打破此一「詛咒」,會談(?)的氣氛如何以至有否成果,在日本人心中已不重要,這從日本輿情有安倍外交政策頗為成功的共識可見。過去數月,安倍對北京真是低聲下氣,求見習主席之意拳拳,路人皆見,所以如此,皆因配合美國「無暇東顧」的外交政策;事實擺明,美國為「中東北非」(MENA)局勢所困(昨天無力解困的國防部長「被辭職」,可知問題之嚴重),不希望與其有國防協約的日本和中國「擦槍走火」,而雙方對話是避免突生意外的不二途徑。安倍終於和習主席碰頭握手如儀了,這雖不意味中、日及中、美外交關係步上坦途,但中、日之間會商解決雙方關注的問題,大於兵戎相見分勝負,這種情況,正是國防經費捉襟見肘的美國目前最樂見的發展。當然,筆者不排除安倍真的希望和中國「重修舊好」,因為中國內銷市場龐大和對外購買力世界最 強,均為頹疲已久的日本經濟所急需。


如果十二月中旬「自公聯盟」勝出,安倍晉三連任(從二○一二至二○一八年〔不計○六年至○七年的一整年〕),他便成為日本現代史上任期第二長的首相(最長的是在位八年的佐藤榮作〔一 九六四—一九七二年〕),假如期間「安倍經濟學」收到預期效果,日本經濟脫離懸崖,則二○一八年自民黨再度勝出的可能性甚高。



這種情況令政府不得不想盡辦法壓低利率,在試過諸種正道和旁門方法而無法收效之後,安倍終於定出一項革命性的策略,那便是「第三支箭」通過央行吸納國庫券 (JGB),這即是說,財政部過去多年(以及今後)發行的債券,過往主要由企業和儲蓄率冠全球的個人認購,在通縮的年頭,債券持有人的進賬雖然似有若無,但購買力總算未被通脹這頭怪獸蠶食,因此債權人和債務人相安無事、和平共處;可是,安倍上台後為使經濟脫離退縮的宿命,定下通脹百分之二的目標,惟當局如何理順兩者的關係,大費躊躇。提高利率(孳息),政府吃不消;原地踏步,持有者會因不吃眼前虧(利息低於通脹率等於負收入)而拋售。

有異於世上大多數人, 日本人有為國家好而不惜啞忍吃虧(必須全民人人平等同受此苦)的「天性」,那是何以過去十多二十年,面對幾乎零實質收入的債券而持債者無怨尤的底因;但購買力受侵蝕,威脅日人的退休養老,便是另一回事……。十月底,央行以五對四票通過「雙化寬鬆」的額度由每年五十萬億(日圓.下同)提升至八十萬億(見十二日本欄),此變動十九日經央行「政策委員會」(Policy Board)以十八對一票確認,這可視為較早前公布日本已進行衰退的消息,令貨幣政策決策者只好同意採取極端手段。無論如何,「雙化寬鬆」的目的,在讓央行有財力吸納市上即個人法人(包括政府退休基金的機構投資者)的國庫券,以其可動用的資金大增,意味財政部發行多少債券央行便悉數購入,那明顯是把債務貨 幣化(debt monetization)的手法,但本報網站昨天上午十時許貼出央行委員「擔心擴QE被視為財赤融資」的消息,真是有點不知所謂,因為央行這樣做正正是「財赤融資」(印鈔買債)!


這方面的問題,昨 [ ] 天說之。

食屎啦你 – 香港網絡大典




Leave a comment

Filed under Electronics DIY Project

Maker Shed 3D Printer newsletter 2014nov

Maker Shed 3D Printer newsletter 2014nov


Leave a comment

Filed under Electronics DIY Project

Arduino Due delivery record



Arduino Due delivery record


Leave a comment

Filed under Electronics DIY Project

80%的中国富豪送子女出国留学 – 胡润研究院


80%富豪子女留学 大多读商科设计也受宠 – 2014-11-25 新京报 陈璐



香港圣诞打折季来 内地客逼爆口岸过关花两个小时 – 南方都市报 2014-11-25

南都讯 记者康殷











Leave a comment

Filed under Electronics DIY Project

Arduino IDE 1.5.8 installed and tested OK


Arduino IDE 1.5.8 installed and tested OK


Leave a comment

Filed under Electronics DIY Project

Ardunio Due Bootloader Explained – Arduino

Ardunio Due Bootloader Explained – Arduino

The official webpage goes through how one should program their Arduino Due using the Arduino software.

For those who are going to develop a project without Arduino but with basic g++, one must understand how to program his chip. Apparently, the Due – SAM3X – has a booting process somewhat different from the AVR, and it is not quite the same as firing up the “avrdude” and be done with it. Ardunio has designed the board such that flashing firmware is easier than what the stock SAM3X has offered, here explains the booting process and the tricks that Arduiro implemented.

SAM3X Flashing Explained

The SAM3X comes with a built-in bootloader, called SAM-BA. Standalone SAM-BA tools could be downloaded from the Atmel website. SAM-BA is permanently burned in the chip ROM straight out of factory, and is not using up any of the flash space. This is very different from AVR that AVR doesn’t come with any built-in bootloader.

In addition to SAM-BA, SAM3X could be booted in the middle of the flash, instead of the very beginning of the flash like they normally do. One could code their own userspace bootloader in the 0-256KB, and the real application in the 256KB-512KB.

So in short, there is three boot start points – SAM-BA, Flash 0 and Flash 1, this can be controlled by tweaking the GPNVM bits in EEFC0.

In Arduino, as well as most of the scenarios, the code is flashed with SAM-BA tools. Flash 0/1 userspace bootloader is not used in Arduino.

SAM3X will boot to SAM-BA when:

A) the GPNVM bits have been modified (set to 0) to instruct SAM3X to boot to SAM-BA. It can be done in userspace code.

B) Erasing the chip (Erase button) which will also clear/zeroing the GPNVM bits and leads to the SAM-BA again.

In SAM-BA, firmware could be flashed over the native USB port, which will be put in CDC mode, or through the first UART channel. SAM-BA will wait indefinitely without timeout. In other words, once the GPNVM bit is cleared for SAM-BA booting, it will always be there waiting for flashing, even after power cycling.

Of course, the flash content and the GPNVM bits could be flashed over the JTAG, which will not be discussed here.

Arduino Tweaks

Two things have been done by Ardunio such that users need not to press the ERASE button everytime.

ATMEGA16U2 assistant

The ATMEGA16U2 chip, acting as a USB bridge to expose the UART as USB replacing the FTDI chip, actually does more than that.

If the host is connected to the programming port at baud rate 1200, the ATMEGA16U2 will assert the Erase pin and Reset pin of the SAM3X. Forcing it to the SAM-BA bootloader mode.

At any other baudrate, it will reset the SAM3X. This is done to simulate the behavior of the AVR-based Arduino – connect and reset.

The code, firmware of the ATMEGA16U2, currently lives in ide-1.5.x branch of /hardware/arduino/sam/firmwares/atmega16u2/arduino-usbserial/Arduino-usbserial.c.

On chip 1200 detection

When Arduino uploads the sketch, it will actually wire up some additional C-code. One in particular, is that it configs the native USB port as CDC for serial communication. That specific code has a similar detection of ATMEGA16U2 in place.

When the port is opened with baud rate 1200, it will set the GPNVM bits apporiately for booting to SAM-BA, and reset itself.

The corresponding code lives in ide-1.5.x branch in /hardware/arduino/sam/cores/arduino/USB/CDC.cpp.

After erase.

Everything after erase is just SAM-BA logics, user could connect to the SAM-BA through the SAM3X native USB, which is put into CDC mode by now. Or to the UART, through the Programming port which is also CDC but exposed by ATMEGA16U2.


If someone is going write C from scratch, it’s unlikely that the On-chip CDC 1200 hack would be taken care, hence opening 1200 baud rate on the native port won’t work. One could refer to Arduino’s implementation for keeping the same behavior if wished.

If the native USB port is put into other uses other than CDC, this obviously won’t work. It is a USB 2.0 High Speed 480Mbps port, someone would possibly have made a better use of it other than CDC.

The ATMEGA16U2 would always work. Anyone unhappy of the 1200 tricks of course could modify the firmware themselves, flash it over the ICSP header with AVRISP technique.

For opening the port in 1200, one could use Putty (an open source software commonly used for SSH in Windows) to connect to the corresponding COM port. If this is done over the native USB port, after closing the connection, the port will disappear shortly afterwards, and a new COM port with another identifier will come up, which is the SAM-BA native USB CDC.


Leave a comment

Filed under Electronics DIY Project

FongDuino01 libraries list


FongDuino01 libraries list


Leave a comment

Filed under Electronics DIY Project

Yellow Dragon Cave – Monk Huikai


How to Visit Yellow Dragon Cave in Hangzhou – China Travel Blogs –

Are you going to visit Yellow Dragon Cave during your Hangzhou trip? There are two famous attractions in China in the same name of “Yellow Dragon Cave”. One is in Hangzhou, Zhejiang Province; the other in Zhangjiajie, Hunan Province. The Yellow Dragon Cave in Zhangjiajie is a cave as its name suggests, a karst cave with 2 underground rivers and hundreds of thousands of stalagmites, columns and stalactites while the so called “Yellow Dragon Cave” in Hanghzou is now actually a typical Chinese traditional garden at the foot of Xixia Range of the Northern Hill in Hangzhou.

Historically the Yellow Dragon Cave in Hangzhou used to be a buddhist temple during the Song, Yuan, Ming and Qing Dynasties.

In 1922, the Yellow Dragon Cave turned into a taoist temple.

After 1949, the Yellow Dragon Cave was taken over by Hangzhou Municipal Bureau of Landscape and Cultural Relics. Trees were planted, bridges and pavilions repaired, made into an important attraction of the Northern Hill in Hangzhou.

The name of Yellow Dragon Cave comes from the legend that one day Monk Huikai in Southern Song Dynasty suddenly heard a loud thunder with the coming of a Yellow Dragon who brought ceaseless water gushing from its month, hence the name of “Yellow Dragon Cave”.

Now Yellow Dragon Cave in Hangzhou has less religious atmosphere. It has become a unique Chinese garden as well as a theme park or garden focused on “Good Luck”, a folk and custom of Chinese traditional culture.

So whether you are going to visit Yellow Dragon Cave during your Hangzhou tour largely depends on your person taste. Though it is not a must see sight in Hangzhou, if you are interestd in Chinese gardening or local folk and custom, it is advisable for you to visit this special atrraction in Hangzhou.

Entrance fee: RMB15, thee are several public buses running to the Yellow Dragon Cave in Hangzhou such as Y3, Y4 Y5, No.16, 21, 23, 28, K101, K599. Or you walk from Yuefei Temple up to Xixian range, then walk down to Yellow Dragon Cave, which takes about 1 hour.

Add: Shuguang Road in Hangzhou, Zhejiang Province, China

Admission fee: RMB 15

Opening hours: 8:00 am – 6:00 pm

Yellow Dragon Cave – China Travel Tour Guide > Attractions

The Yellow Dragon Cave situated on the rear hill of Xixialing (Rosy Clouds Hill) in West Lake tourist zone in Hangzhou City. Although called “cave”, it is actually a yard. It is a well-known place of interest in Hangzhou City.

The gate of the Yellow Dragon Cave is very simple, on which inscribed with an antithetical couple.

The scenes in the yard are half-artificial and half natural. The main scenic spot in the yard are Pavilion of Fragrant Snow, Pavilion of Standing Crane, and a dragonhead molded on a cliff.

The dragon’s head is the hero of the yard. Spring water comes out of the dragonhead and flows into the pond below.

Beside the pond stands a stone, on which inscribed with eight Chinese characters meaning, “If there is dragon in the pond, it will be charming. So, the depth of the pond is unimportant”.

The Bamboo Garden, which is opposite the Vermilion Corridor, is unique in the Yellow Dragon Cave. In the garden grows a great variety of bamboo, such as 33-meters high mao bamboo, several-inch-high white bamboo, purple bamboo, green bamboo with golden dots, square bamboo and so on.

While seeing so many kinds of bamboo, you will gasp in admiration for the superlative craftsmanship of the nature.

The Yellow Dragon Cave is simple but elegant yard. It lays out as an antique park by the Hangzhou local government. There are teahouse, wine shop, theater, Terrace of Praying for Rain, and other ancient entertainment.

After visiting the yard, you can also taste the local flavors, such as Tianhua Steamed Stuffed Dumplings, Ten-Flavor Dumpling Soup, Steam Cake, and so on. People said that these flavors were very popular in Song Dynasty (960 ~ 1279A.D.).

You can also listen to the ancient Chinese music in the pavilion. This antique yard can make your travel more interesting.


The Yellow Dragon Cave relates with two legendary figures in history. One is Lord Huangshi in Qin Dynasty (248 ~ 207B.C.). The old man saw Zhang Liang coming up and deliberately kick off his shoes and asked Zhang Liang to wear for him. The Cave of Immortal Huang in the yard was specially built for people to commemorate him.

Another figure is the Founder of the Yellow Dragon Cave. According to the legend, the founder was monk Huikai who left Jiangxi Province and came to Xixiashan to expound the Buddhism. Huikai founded the yard so that the devotees to Buddha could come here to listen to him to expound the scriptures of Buddhism.

Yellow Dragon Cave-The entrance of Yellow Dragon Cave –

Yellow Dragon Cave is located at the northern foot of Qixia Ridge in beautiful Zhejiang. The formation of this natural spectacle has a legend that a monk from Yellow Dragon Hill in Jiangxi Province in the Southern Song Dynasty came to the site and decided to build a temple.

One day, a yellow dragon suddenly appeared and hit the ground; then, the place miraculously turned out to be what we see today. In the surrounding of various kinds of bamboo, Yellow Dragon Cave seems to be dressed in Green. And there is also a spring issuing from the mouth of the yellow dragon, the cracked rock.

Beside the spring, the famous quotation was engraved on the rock,

“Regardless of the depth, Divine is the dragon pool.”

In the neighborhood, there are also two lovely pavilions, Fragrant Snow and Crane’s Stopover.

The scenery as a whole becomes one of the Ten Scenes of The West Lake,

Yellow Dragon Cave Dressed in Green.

At times, tourists will have the chance to enjoy the beautiful Chinese music conducted by the orchestra in ancient costumes with the Chinese musical instruments and indulge in the delightful China travel.

For the convenience of your Hangzhou travel in China, below is a selection of nearby hotels. For more sightseeing attractions in Hangzhou, please visit our Hangzhou Tourism website for a map to guide your China tour and to find your ideal China hotel.


Leave a comment

Filed under Electronics DIY Project

Free Memory checking notes

Binary sketch size: 30,260 bytes (of a 258,048 byte maximum) = = 30K of 256K byte flash

At FongTest01::Test01( ) = = 1.5K bytes of 8K SRAM

Free Memory = 7374 bytes.

ATTACH_LOCAL_ISR() // Attach local ISR [156 bytes]
Free Memory = 7218 bytes.

CREATE_FONG_SERIAL_OBJECT(Test0, DebugPrint1) [78 bytes]
Free Memory = 7144 bytes.


initAll(testNum, debugNum);

Serial.print(“Free Memory = “);
Serial.println(” bytes.”); [1566 bytes]

test(testNum, debugNum); [5 bytes]

Free Memory = 5578 bytes.

else if (selectChar == ‘f’)
Serial.print(“Free Memory = “);
Serial.println(” bytes.”);
selectChar = resetSelectChar();

Test01 Menu >>>

f = Free memory. >>> [5 bytes]
m = Menu. >>>
h = Help. >>>
x = Exit. >>>
Main Test Selection (m = print menu, x = exit.) = ? >>>

Free Memory = 5561 bytes.

// *** fongmain2014nov25hkt1156.ino ****
// ********************************************************************
// FongMain01r 2014nov
// ********************************************************************
#include “Arduino.h”
#include “HardwareSerial.h”
#include “SoftwareSerial.h”
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
// #include <PinChangeInt.h>
#include <FongSetup01.h>
#include <FongGlobalIsr01.h>
#include <FongLocalIsr01.h>
#include <FongGlobalVar01.h>
#include <FongInt01.h>
#include <FongSerial01.h>
#include <FongDebug01.h>
#include <FongBuzzer01.h>
#include <FongDigitalIo01.h>
#include <FongDigitalControl01.h>
#include <FongAnalogIo01.h>
#include <FongText01.h>
#include <FongBlueTooth01.h>
#include <FongBtm01.h>
#include <FongPicoNet01.h>
#include <FongTest01.h>
#include <MemoryFree01.h>


void setup()
ATTACH_LOCAL_ISR() // Attach local ISR // 7218 bytes

void loop()
FongTest01 ftest1(&fgisr1, &fserial1, Test0, DebugPrint0); // Select test
// FongTest01 ftest1(&fgisr1, &fserial1, TestBlueTooth, DebugPrint0); // BlueTooth
// FongTest01 ftest1(&fgisr1, &fserial1, TestBtm, DebugPrint0); // Btm (BlueTooth Module)
// FongTest01 ftest1(&fgisr1, &fserial1, TestPicoNet, DebugPrint0); // PicoNet

Serial.print(“Free Memory = “);
Serial.println(” bytes.”);
while (true) {}; // 7374 bytes

// *** End ***


Leave a comment

Filed under Electronics DIY Project