2011年6月17日星期五

Amarino- How to access your Android's compass and accelerator data

What is amarino? a maxican food? Nah!, Amarino mean "Android meets Arduino"

here is the cite from Amarino official site

Normally smartphone events are tightly coupled to your phone device itself. When your cell phone is ringing, your phone speaker plays a ringtone. When you get a new text message, your phone displays it on its screen. Wouldn't it be thrilling to make thoses phone events visible somewhere else, on your wearable, in your living room, on your robot, in your office or where ever you want it to occur? Or would you like to use your smartphone sensors, like the accelerometer, light sensor, compass or your touchscreen to control other devices? 'android meets arduino' is a toolkit, basically consisting of an Android application and an Arduino library which will help you to interface with your phone in a new dimension. You can build your own interfaces almost without any programming experience.


The basic concept for this tutorial is simple, Amarino API in your android phone will access your phone sensor and transmit the sensor data through Bluetooth over the air and received by Bluetooth module attached at Arduino's UART (pin 1 & 2), so the amarino API in Arduino will interprets the data and return the proper value at your end.

It is relatively easy to get this tutorial done.
But first of all, you needs some basic stuff before you start

1) Arduino board
2) Bluetooth module (get it from ebay for 8 USD)
3) Android phone with Bluetooth
4) Amarino library (http://www.amarino-toolkit.net/index.php/download)
5) Arduino IDE
6) LCD display (ebay for 5 USD)



You should follow these steps and get the magic done.

1) go to Amarino site

2) Download and install the Amarino_2_v0_55.apk into your phone

2) Extract MeetAndroid_3.zip into your IDE library path,
the path will looks like this arduino_IDE\libraries\MeetAndroid

3) Copy this code into your Arduino IDE
------------------------------------------------
/*
Receives compass and accelerator sensor events from your phone.
By Willer June 2011
*/
#include
#include

#define MAX_OUT_CHARS 16 //max nbr of characters to be sent on any one serial command
char buffer1[MAX_OUT_CHARS + 1]; //buffer used to format a line (+1 is for trailing 0)
char buffer2[MAX_OUT_CHARS + 1];

//Error capturing function
MeetAndroid meetAndroid(error);
void error(uint8_t flag, uint8_t values){
Serial.print("ERROR: ");
Serial.print(flag);
}

int onboardLed = 13;

//I use LCD to display debug message
extern LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

//buffer to store compasas and accelerator
extern int compass = 0;
extern float accelerator[3] = {0,0,0};

void setup()
{
lcd.begin(16, 2);
lcdDebug("We-Android-Freaks.com","Amarino Demo 01 by IChing");
// use the baud rate your bluetooth module is configured to
// not all baud rates are working well, i.e. ATMEGA168 works best with 57600
Serial.begin(57600);
// register callback functions, which will be called when an associated event occurs.
//naviCore is the function will be call for every incoming event,
//A & B is the events ID that you can get it from your amarino apps in your phone.
meetAndroid.registerFunction(naviCore, 'A');
meetAndroid.registerFunction(naviCore, 'B');

pinMode(onboardLed, OUTPUT);
digitalWrite(onboardLed, HIGH);
delay(2000);

}

void loop()
{
// you need to keep this in your loop() to receive events
meetAndroid.receive();
}

void naviCore(byte flag, byte numOfValues)
{

if(flag=='A'){

compass = meetAndroid.getInt(); //0-360
sprintf(buffer1,"Compass: %d",int(compass));
lcdDebug(buffer1, buffer2);
}else if(flag=='B'){
meetAndroid.getFloatValues(accelerator);
int mappedX = map(accelerator[0]*10, -50, 50, -1000, 1000);
int mappedY = map(accelerator[1]*10, -50, 50, -1000, 1000);
int mappedZ = map(accelerator[2]*10, -150, 150, -1000, 1000);
sprintf(buffer2,"X:%d,Y:%d,Z:%d",mappedX, mappedY, mappedZ);
lcdDebug(buffer1, buffer2);
}

}

void lcdDebug(String line1, String line2){
lcd.clear();
lcd.setCursor(0,0);
lcd.print(line1);
lcd.setCursor(0,1);
lcd.print(line2);
}
------------------------------------------------

4) Compile the code into your Arduino board, plug the LCD and bluetooth module into correct pin, power it up. be aware that Bluetooth is working on 3.3V

5) Run your Amarino on your Android phone, press the green cross (Add BT device) to search for your Bluetooth module, Add it into your list, do not connect it.

6) Press a little bit longer on your newly added Bluetooth device, an option screen will be pop out and click "Show Events", then Add your sensor event to monitor by pressing "Add Event"

7) Add the Compass Sensor (ID:A) then follow by Accelerometer sensor (ID:B)

8) Hit the back button and go to the Amarino main menu, and connect to your Bluetooth device.

9) done, you should see the LCD screen displaying your sensor data.

2011年5月21日星期六

arduino ethernet shield











这是project的一部分,ethernet shield 到底能拿来做什么?

我会需要它来
1)fast cronjob
我们都知道 cronjob 最快也只有一分钟一次,如果要做到5秒一次那么,很大可能我们就需要一个电脑程序来启动,但是开着一台电脑很浪费电。用arduino就不一样了,一个电池,一个5V的usb charger绰绰有余。

2)由于它链接arduino,我用它来收集感应器的资料然后,上载到网上,或从网上下载指令来控制arduino “开灯关灯”。。。哈哈哈。



这个是昨天12am-10am 的温度资料,你可以看到凌晨温度开始下降然后太阳升起后开始上升。
不过这个arduino ethernet library真的让我搞了3天,原本的code有问题,跑一下,几分钟到几小时arduino就当机了。找了几天都没有方案,网上太多人也是用原本的code来改,没有什么解决的方法。后来意外发现这个library return的status本身有问题。看来arduino真的很原始,没法走到像电脑program那样高级。

同时需要表扬一下myduino.com,我的零件是和myduino买的,这次他们给错了一个零件,所以他们决定重新发过对的零件,完全无需附加费,也不需要退回错的零件,看来他们亏了不少,那个零件售价100零吉,aliexpress看到也值70零吉。

2011年5月13日星期五

Intel DeskBoard D525MW power consumption







终于做到了, 用12V 来 驱动dual-core Atom cpu。
大家应该很好奇一架用Intel DeskBoard D525MW主板的耗电量会是多少呢???

先列出我用的零件。
1) Intel DeskBoard D525MW
2) 320Gb 2.5"寸 SATA, WD的hardisk
3) 旧的AMD CPU风扇和一个大的风扇
4) picoPSU-120 120W DC-DC mini ITX 12V Tiny Power Regulator
5) Industrial Switching Power supply, 110V-240V in, 12V 5A (60Watt) out
6) Power Logic slim ATX Casing
7)WindowsXP sp3
8)320Gb USB WD passport
9)普通的Logitech Keyboard
10)Microsoft Mobile Mouse 3500
11)2GB DDR3 1333 x1
12)3A fuse

由于这个picoPSU是20Pin ATX, 也没有P4 connector, 所以就从旧的PSU剪出P4 Connector再接上这个picoPSU的12V(黄色)电线,还有一点,D525MW是用24pin的ATX接口,不过不必管那多出来的4个接口,20pin可以直接插下去。

按下电脑的电源开关,一切如常的启动,用电表测量出整架电脑耗的电流只有1.3A-1.8A。

以下是测量出的电流指数
启动电脑到进入作业系统 1.35A - 1.38A
普通状态 1.32A - 1.40A
播放rmvb 1.42A - 1.47A
插入320Gb WD passport,XP扫描里面的文件 1.78A - 1.81A
插入320Gb WD passport,扫描完毕 1.55A - 1.61A
玩Facebook的restaurant city 1.66A - 1.69A

所以大致上这架电脑的耗电量在1.5A上下,也就是说average 18Watt(1.5Ax12V),这和一盏小的荧光灯相等。
当然也别忘了,Monitor(屏幕)的耗电量才是真正的可怕,
不过拿来当家庭伺服器,屏幕是多余的东西,所以还是很省电的。

至于散发的热量,picoPSU几乎是毫无热量,只有微温。Switching Power supply也是温一些罢了。

(这个picoPSU是正版,从欧美卖家买来的,有专利认证,有一些中国/香港牌,便宜了接近10美金,但零件上的号码都被磨掉了,好像山寨货,所以不是那么放心使用,不建议使用)

2011年4月27日星期三

PLC VS thin client,和我要做的东西



今天和一位老同学谈了一些有关微处理器或微型电脑哪一个比较好。当中他说了用微处理器,有太多限制,最大的问题是内置记忆体不够,就拿Arduino来说只有几十K到几Mb的容量,如果写的太复杂,根本不够。这个我非常认同,因为我也在头痛着Ethernet Shield和arduino并不能处理太大的文件。还有要debug那些微处理器的程序很难,不如在电脑上打开一些普通的程序(VB,Java等)来debug。现在的atom thin client已经可以做到6x6公分的大小。是可以和Plc不相上下。
先睡觉,改天谈。.。

有兴趣者,可以留言我这位朋友。
微处理器专科,曾在几个大厂做,现在在新加坡开了公司,转为生产线设置微处理,测试平台和处理方案。

2011年4月23日星期六

What is the difference between a normal lead-acid car battery and a deep cycle battery?


深循环电池


车的电池

汽车蓄电池的作用是在较短的时间内提供较大量的电流。汽车在起动时需要用此冲击电流来起动发动机。 发动机起动后,交流发电机将提供汽车需要的所有动力,因此汽车蓄电池终其一生所消耗的容量也不会超过其总容量的20%。 采用这种方式,汽车蓄电池能够持续使用若干年。 为获得大量电流,汽车蓄电池使用薄极板来扩大表面区域。

深循环蓄电池的作用是在较长的一段时间内提供较稳定的电流。如果需要,深循环蓄电池也能够提供冲击电流,但不如汽车蓄电池提供的强大。 深循环电池还得反复进行深放电(汽车蓄电池这样做将会迅速导致其报废)。为此,深循环蓄电池使用较厚的极板。


原来车的电池和深循环电池有酱大的分别,车的电池是属于高输出但输出时间短,而深循环电池是属于长时间保持稳定输出的电池。由于目前在研究着用电池来驱动Atom电脑。想到用车的电池来做电源。看来需要重新考量了。

"What is the difference between a normal lead-acid car battery and a deep cycle battery?" 01 April 2000. HowStuffWorks.com. 23 April 2011.

2011年3月22日星期二

avalanche breakdown



早前,异想天开,开始了一个用Android phone 遥控的直升机。几乎做了七七八八,到最后卡在主引擎的驱动问题上。我这架RC直升机S031G 有两颗马达驱动,全速上升的耗电量为(大过)3A,9V/马达。马达的控制采用PWM, 试过了几种电子玩家常用的驱动IC,例如L293D,结果热能产生的太快,后来改用32A的power MOSFET,结果顶不得所谓的“avalanche breakdown” 几秒内就烧掉了三颗Power MOSFET。(最惨的是MOSFET烧了后,是处在短路状态,所以直升机转个不停),后来就再卖了两颗蛮贵的IRF4905,一个76A,防“avalanche” 效应的power MOSFET. 烧毁是不会,但又有新的问题(下篇才谈),试过拿来驱动我的电动螺丝起子,没问题。

说了那么多,到底什么是“avalanche breakdown”?
其实,用一个简单的解释是,有些电子零件,比如说马达,(inductor,capacitor之类),在一开始接上电源时,会有无限量大的能源吸取。就是接近短路。所以有些高输出的零件马上就烧毁了。

2011年1月4日星期二

Prolific PL-2303

前几天在lowyat买了一个USB-RS232 的转换卡。准备来玩烧录arduino。
结果发现到在 64-bit 的 Win7 不跑,在普通的XP是没有这个问题, 去了他们的官方网站下载,还是一样出现问题 device not started (code 10),
在网上乱找一通,式了五六个driver,最后发现到了这个才能用 :)

2011年1月3日星期一

ATMEGA 386











玩了几天Arduino,功能有一点让我感到吃惊,或许以前没玩过Microcontroller,所以不知道。上面是拆开在家乐福买的滑鼠,把它接上,写一个简单的程序再烧录进arduino。


有两个版本,



第一是把滑鼠的移动资讯转到bar LED上,






第二个是加了马达驱动IC(H-Bridge motor driver L293D, RM8一颗),如果滑鼠往上移马达就会顺着转,往下移就会反方向转。



接下来是玩电话的控制,用我非常旧的T630作为GSM modem。
由于不知道要用什么感应器,就随便放了灯光感应。
下面的,如果灯暗下来,他就会自己播个电话给指定号码。



看来制造我小小智慧型屋子的梦想又跨越一步!!!哈哈哈