Archive Page 2

10
Aug
11

Android arduino communication

Now to the fun part!

In the previous post I explained how to interface and configure a Bluetooth Module with a Bus Pirate.

Here I will show how to toggle the Arduinos LED through an Android app!

Note that I’m using a Arduino Duemilanove.

You’ll need to connect the module to the Arduino. The +5V and GND pins are already there. The digital 0 and 1 pins are reserved for the PC/Arduino interface through the FTDI.
I used the digital pins 2 and 3 for the communication with the module.

The rxPin(2) is connected to the tx pin of the module.
The txPin(3) is connected to the rx pin of the module.

Arduino Code
Available here:
http://pastebin.com/EjCFqAVR

Notes:
I could have implemented it without the use of
NewSoftSerial but didn’t. The delay when reading was added because of the baud rate configuration problem I was having, at 1200 bauds. At 9600 it is perhaps not needed. There is no need to actually return if the message was understood, I added it to experiment on possible information polling events.


Here is a short python code I wrote for my Ubuntu to test the communication.

Python test code
Available here:
http://pastebin.com/saFwneNa
Ubuntu will automatically ask if you want to pair with the device. It usually is called linvor and has the pin 1234 as default.

I based my code on the examples found here:
http://people.csail.mit.edu/albert/bluez-intro/c212.html(which also finds your device by name and gives you it’s mac address)


As for the Android code, you must add the permissions for bluetooth connections to the Manifest.

<uses-permission android:name=”android.permission.BLUETOOTH” />
<uses-permission android:name=”android.permission.BLUETOOTH_ADMIN” />

BLUETOOTH_ADMIN is only needed if you are to set your device visible or manage paired devices.

My main and only java class is available here:
http://pastebin.com/tkqhi1S2
(wasn’t going to get indented here in WordPress)

It should be noted that after creating a socket with

UUID mUUID = UUID.fromString(“00001101-0000-1000-8000-00805F9B34FB”);
BluetoothSocket mBTSock = device.createRfcommSocketToServiceRecord(mUUID);

which uses the default device UUID, you must still connect the socket.
It seems a socket cannot be reused after closing it. Probably would have to open a new socket.
Note that this implementation is far from being totally bug and idiot proof. I do the most of the error checks which probably would go wrong, but there are always more to add.

I used the DeviceListActivity from the BluetoothChat example available in the Android SDK. This class needs the res/layout/device_list.xml and res/layout/device_name.xml. I used it so the user can select a paired device from the list and it returns the Bluetooth address(mac) to the calling activity, so it knows to which device to connect.

Here is the whole project:
http://dl.dropbox.com/u/19070953/Wordpress/Arduino-Android/btcon.tar.gz

So, I hope this works for you. Will not run on Android Emulator(I think, since Bluetooth is not available) and was built/tested for android 2.1(SDK 7)

Obs.:
Sorry for the embedded images for the code. WordPress without decent plugins does not allow code to be displayed properly. And the android code was too long to paste together.

03
Aug
11

Bluetooth TTL module and Murphy

I bought a new Bluetooth Serial TTL module at eBay for a project of mine, which I will probably documenting here.

It is from MDFLY, as can be seen in the pictures below. The model is RF-BT0417CB.

Since at the time I had not yet received my Arduino 2009, a friend of mine suggested I test it with his Bus Pirate v3.5(BP for short).

He had bought one but never really used it, so there were the two of us, trying to get the BP to work. It is accessed through serial through USB, so to talk to it we discovered that screen does emulate serial connections!

screen /dev/ttyUSB0 115200

(BAUD rate does not need to be 115200, could be any other probably, and device may not be /dev/ttyUSB0… check your dmesg)

Obs.: screen is a Linux program, not Windows. Deal with it or install Cygwin. ‘Ctrl+a, k, y’ kills the screen so you can close it if you need to(probably will).

After connecting, screen is black. Hit ENTER to have ‘HiZ>’ appear. Now we need to set the mode that the BP will operate, since it has many available features.

HiZ>m
1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
9. DIO
x. exit(without change)

(1)>3
Set serial port speed: (bps)
1. 300
2. 1200
3. 2400
4. 4800
5. 9600
6. 19200
7. 38400
8. 57600
9. 115200
10. BRG raw value

(1)>5
Data bits and parity:
1. 8, NONE *default
2. 8, EVEN
3. 8, ODD
4. 9, NONE
(1)>
Stop bits:
1. 1 *default
2. 2
(1)>
Receive polarity:
1. Idle 1 *default
2. Idle 0
(1)>
Select output type:
1. Open drain (H=Hi-Z, L=GND)
2. Normal (H=3.3V, L=GND)
(1)>2
Ready
UART>

Explained:
UART is so the BP can comunicate through serial, 9600 is normally the default speed, most of the rest are default options, and I prefer to use the ‘Normal’ output type because my Bluetooth module is TTL.

You will also need to connect the pins of the BP to the module:

BP -> MODULE
GND->GND
+5V->+5V
MOSI->RX
MISO->TX

Now we need to set the BP to power the module:

UART>W
Power supplies ON

The modules LED should begin to blink. If it stays on steadily it means that the module is connected through Bluetooth to another device. If it is off.. recheck the previous steps.

UART>{
UART LIVE DISPLAY, } TO STOP

This sets the BP to listen to incoming serial data. If there is a stream of data that should not be, it usually means that the TX is not connected properly to the MISO pin or that the module is turned off.

To test the communication with the device, send “AT” to it with:

WRITE: “AT”
UART>
READ: 0x4F
UART>
READ: 0x4B

The AT command should return “OK”(O=0x4F, K=0x4B).
If this doesn’t happen, recheck the TX->MISO connection or the BAUD rate for the module may be wrong. Try setting the BAUD rate to other values by redoing the mode setup.
Note: the ‘b’ command for the BP sets the BAUD rate for the pc side communication, not the module side.

Now comes the ‘problem’. Somewhere I read that the command to set/see the BAUD rate of the device was “AT+BAUD1”. This actually sets the BAUD rate to 1200. Great!. The recommended setting is “AT+BAUD4”, which will set it to 9600.

Second problem. The Bluetooth module is kind of picky when sending a ‘complex’ command. “AT” should work at almost any place, “AT+…” will probably not.
As I showed above, sending “AT” will return “OK” but in hex, not as chars. When using “AT+BAUD4” or “AT+VERSION”(check the version), the hex numbers representing the string will be shown, and not characters, which is a pain.
Also, when sending and receiving data through other devices, the data will be shown as hex, which normally isn’t very practical.

You can run the BP in Macro mode.

UART>(0)
0.Macro menu
1.Transparent bridge
2. Live monitor
3.Bridge with flow control

2 and 3 can be used on to read. When pressing a key the exit the mode. So pretty useless for normal applications.
The ‘Transparent bridge’ mode connects you ‘directly’ to the module. In this mode you receive the characters normally, not in hex, but everything you write does not appear for you AND every char you send, is sent as you type, not after you press enter. So while “A” and then “T” will work and you will receive “OK” as an answer; “A”, “T”, “+”, and then the command will not work since apparently it takes to long for each char to reach the module, so the command is discarded and you don’t even receive the “OK” for the “AT” part.

12
Jul
11

And there goes my new N1…

A friend of mine was in the US and I ordered a Nexus One through eBay which he brought back. I spent USD$270 on the N1, which is less than I spent on my XT300. (Great…)

First experience was AWESOME. Having a phone with android 2.3.4, faster and smoother experience than the XT300, no more that tiny screen, far better camera(5MP) than the XT300 3MP with flash and autofocus.

Of course, first thing I did was to unlock the bootloader through fastboot and flash the Clockwork recovery mod onto it. The mod even supports the N1’s trackball!

Then cyanogenmod 7.10-RC1-N1.

So, I was using the phone happily but had been noticing that sometimes the touchscreen hick-upped and I had to turn the screen off and on again to fix it. Nothing serious. Until it got worse, that is.

The first, say, 3-5 touches go correctly… then it all goes downhill. Using the Nexus live wallpaper, which lights up when it’s touched, I was able to track down the discrepancy of the touch. The faulty touch gets detected 2-3 cm above the lower screen end, but just height of the position is affected, the horizontal position continues to be acquired correctly.

First I thought it could be the cyanogen mod, so I switched to the 7.0.3 stable version. At first it was less frequent but then it got worse again.

Then I tried the stock, which is 2.2.1(FRG83)
The problem also got better than worsened as before.
After the OTA update to 2.3.4 nothing changed.

I’ve read that using the phone with low brightness helps somewhat.
Powering it on, I can unlock it. I go to a blank screen, and start playing with the nexus’s live wallpaper.
The third click goes to 2-3cm above the lower bar. For a time I the clicks register at the right place. Then the desktop tries to change screens, flickers.
The most annoying problem is that this happens while I try to use the back button, or select something from a menu and it simply registers my click with the wrong height.

Now I’m trying to get someone to fix this.
Since I don’t know if the problem can be fixed simply by replacing the digitizer(capacitive sensor), I won’t do it myself(digitizer could be bought at eBay and youtube shows how to replace).

I didn’t find any seemingly reliable repair shop that should be able to repair the phone.

I emailed my country’s HTC, they told to contact Google. In the htc’s international website it says that they would provide customer service. They say they are not responsible for hardware not sold in my country.Great.

The eBay seller is not able to ship it Brazil(my country, yes). I have no one that is going or coming back from the US to perhaps make the switch for me, and even if I were able to get a replacement phone from the seller, does not mean it would not present the same problem.

I was thinking of sending it back for a refund. Pity I don’t have the box anymore, just the accessories…

All in all, the thing I learned was to never buy a frigging HTC phone again. Having high hopes for the Nexus Prime. It’s not that I don’t like the phone. I find it very comfortable to hold and nice looking. The gray, which I thought would bother me, does not. The trackball is great for navigating in the Clockwork mod recovery.

UPDATE:
As it stands, I will try to send it back to the seller, with all accessories I have. He will send a new phone to a friend of mine in the US. Let’s see if this works out.

09
Jul
11

New addition: Arduino

W00t! My new and only arduino just arrived!

Ordered it from eBay(HK, cough cough) instead of buying it here in Brazil. Obvious choice because it would cost me 62.6 USD instead of the 15 I payed.

I bought the Duemilanove, discovered later I should have bought the UNO, which has the ATmega8U2 instead of the FTDI to communicate via USB. This is better because the ATmega8U2 is programmable, so you could make it act as any USB device instead of just a virtual com.

Getting started is ridiculous, in ubuntu at least. Just download the arduino software available at arduino.cc, extract and run.

Select your board in Tools, and other minor configurations, paste the LED Tutorial(also available at the official site) onto the sketch and upload. There! Your first arduino code running!(Note that the 2009 already comes with a LED connected to the pin 13, no need to connect another)

The interesting thing is, the USB-TTL used to program the arduino can be used to communicate with your code that’s running inside the arduino! When using this feature, the pins 0 and 1 (digital), which are named RX and TX respectively, are/can be used to connect a serial ttl device directly to the computer.

Why is this so nice? I bought a bluetooth TTL module which I plan to connect to the arduino and make it talk to android!

 

Further ramblings:
With the launch of the ADK(Open Accessory Development Kit for android, which is basically an arduino with various sensors) you can now connect it via usb on the android an do all sort of stuff.

With a non-official ADK arduino, you must make use of the USB-Host shield and use the new lib.

First, ADK should be able to be host OR client, depending on the power source. Don’t know if the USB-Host shield supports this and/or the android device must be able to provide power via the usb interface. I should look into it… someday.

Second, the arduino UNO allows for USB device ’emulation’. Is the USB-Host shield really needed or could the ATmega8U2 be programmed to act as an ADK device/proxy?

 

 

So, a new hope a new turn. I should be posting stuff about the arduino and what I’m trying to do with it in the not that near future.

Some other posts are coming along slowly, when I have the opportunity to write. Must stop procrastinating!

06
Jul
11

A Message From The Author

Hi,

this blog was initially created to enable me to write my experiences and other informations I wanted to pass on to others and myself, if I ever need something again.
This has not changed.

The problem is, since I started writing about android and more specifically, the XT300 the number of visits of the blog have risen somewhat(in comparison of what they were before, the most visited post was about vBox and Vmware migration).

This is a problem since it tends to increase my guilt of not keeping the blog updated.

And it’s not that I don’t have some things to write about:
SESGC rom(SESGC_U3_10.10.0), which was in the motorola open-source projects in Sourceforge, apparently has the GPU activated, though it is mostly in chinese and does not have google integration.
-Back to hacking the XT300, since it now is recoverable with RSD(should test this first)
-My experiences with the Nexus One(vs the XT300) and details about the buggy touchscreen

If anyone has any other idea or suggestion, please tell me in the comments. Note that this blog is focused on specific knowledge, I try to consider all related info and warnings, but I’m not inclined to make very specific and n00b-proof guides.

Well, I feel a little better now, and you know now what’s to come.
This post is like TODO’s in src… not really useful but relieves the guild 😀

26
Apr
11

Compiling GnuRadio on RHEL5 (5.6 Tikanga)

Since my android phone is taking a trip to the central technical assistance, I have time to write about some other things.

I’m currently trying to get gnuradio running on a Redhat 5 x64 machine.

Since the machines where I work have a custom repo, which updates all of them concurrently, the objective of this tutorial is to install gnuradio with minimal interference of customized packages which could induce presently or futurely a dependecy hell or any other problems…

If you don’t care for customized packages mayhem, I suggest taking a look at http://blackopsoft.com/Main_Page repository, which includes gnuradio and all it’s dependencies.

I’m compiling it onto my own account for now, will try to redistribute to the users in need of the software sometime.

Install via yum:
cppunit-devel
guile-devel
fftw3-devel

You need to get the following sources:

package (current version)
boost (1.46)
swig(1.3.40)
gnuradio(3.3.0)

Extract all of them.

swig:

./configure –prefix=~/swig_install/
make
make install

boost:

./bootstrap.sh –with-libraries=thread,date_time,program_options –prefix=~/boost_install/
./bjam install

gnuradio:

env PATH=~/swig_install/bin/:$PATH ./configure –with-boost=~/boost_install/ –prefix=~/gnuradio_install/ LDFLAGS=”-L~/gnuradio_install/lib64/” –prefix=~/gnuradio_install/
make
make install

Note: this throws error when trying to install python24 swig libs… Did not overcome those yet…
Obs.: the LDFLAGS=”-L~/gnuradio_install/lib64/” is a bug in gnuradio make install. make install tries to link to the lib without checking that it was installed to a custom prefix…

Testing the install:

env LD_LIBRARY_PATH=~/boost_install/lib/ ~/gnuradio_install/bin/gnuradio-config-info

Would have to test a compile using the libs…

UPDATE
Sorry, it was decided that the best would be to use a more upstream linux and we installed Fedora, so the installation was as complicated as running sudo yum install gnuradio-*.

25
Apr
11

More dumping!

Since I got a brand new refurbished not-completely-working version of my very own phone, I started hacking it again.

And dumping it.


Just to remember how the partition table looks:

dev: size erasesize name
mtd0: 00700000 00020000 “boot”
mtd1: 0b400000 00020000 “system”
mtd2: 0dea0000 00020000 “userdata”
mtd3: 00a20000 00020000 “cdrom”
mtd4: 00060000 00020000 “misc”
mtd5: 00580000 00020000 “recovery”
mtd6: 02800000 00020000 “cache”
mtd7: 00060000 00020000 “fota_bbuf”
mtd8: 00060000 00020000 “fota_usd”
mtd9: 000a0000 00020000 “fota_bua”
mtd10: 000a0000 00020000 “fota_ua”
mtd11: 00600000 00020000 “fota_up”
mtd12: 00060000 00020000 “kpanic”


The cdrom partition contains a CD image, with the files:

Autorun.inf
config.ini
MotoHelper_2.0.24_Driver_4.7.1.exe
setup.exe

and the config.ini content is:

[MC]
file=MotoHelper_2.0.24_Driver_4.7.1.exe
version= 02.00.23

[driver]
version=4.7.1


The contents of all the fota* partitions:

fota_bbuf.img:
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
00060000

fota_bua.img:
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
000a0000

fota_ua.img:
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
000a0000

fota_up.img:
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
00600000

fota_usd.img:
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
00060000


The misc partition:

00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
00000800 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…………….|
*
00000c40 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
00001800 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…………….|
*
00020000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
00060000


kpanic partition content:

00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
00060000


I dumped the system partition via cat but unyaffs complained it was not valid…

No idea why really… and the tar backup I created previously was good for shit… stuck in bootloop… perhaps this one does it… who knows..




The Author

Older Ramblings

Tweets

Linux User Sig