Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Android Open Accessory Programming with Arduino
This is the forum to discuss the Wrox book Professional Android Open Accessory Programming with Arduino by Andreas Goransson, David Cuartielles Ruiz; ISBN: 978-1-1184-5476-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android Open Accessory Programming with Arduino section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 28th, 2014, 06:41 PM
Registered User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2013
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Arduino Kit Not Consistent With Book?

I finally dropped the money on the Arduino for Android kit since I have the time to work on it, and I noticed that the kit does not come with a shield, but some of the sensors that came with it are Tinkerkit sensors, so they have a plastic piece behind the pins that prevent them from being used with the breadboard. The temperature sensor is also a Tinkerkit Tempt TMP36, and on page 85 the book calls for a LM35, though I don't know if this will make a difference. Is there a simple way to use the sensor and have it work with the Hello Open Accessory project?
Reply With Quote
  #2 (permalink)  
Old May 28th, 2014, 07:38 PM
Registered User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2013
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Went ahead and just bent back the plastic piece, and hosted the APK from the source code on Dropbox since it's not available online anymore. Not sure if it's reading correctly, but at least it's reading. Getting 1.13...E9k, which is definitely not within a normal range.
Reply With Quote
  #3 (permalink)  
Old December 21st, 2014, 09:29 AM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2014
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by PaulTR View Post
Went ahead and just bent back the plastic piece, and hosted the APK from the source code on Dropbox since it's not available online anymore. Not sure if it's reading correctly, but at least it's reading. Getting 1.13...E9k, which is definitely not within a normal range.
Disclaimer: I am totally new to electronics and Arduino, so I may be talking complete nonsense here.

I stripped one side of one of the female-female wires (just cut off the white plastic), and put a little solder on each tip to keep it together (to prevent the ends from fraying).

Once I was set up, I also got the value you got (1.13...E9k). After some digging, it looked like it's because the Arduino side is sending a 4-byte float:

Code:
int val = analogRead( sensorPin );
float voltage = (val * 5.0) / 1024.0;
float tempCelcius = voltage * 100;
float tempKelvin = tempCelcius + 273.15;
byte * b = (byte *) &tempKelvin;
usb.write(b, 4);
while the Android side is reading it into a 4 byte int:

Code:
int i = 0;
			while (i < bytes) {
				if (bytes >= 4) {
					int intbits = ((buffer[i + 3]) << 24)
							| ((buffer[i + 2] & 0xff) << 16)
							| ((buffer[i + 1] & 0xff) << 8)
							| ((buffer[i] & 0xff));

					mHandler.obtainMessage(NEW_TEMPERATURE,
							new Temperature(intbits)).sendToTarget();
				}
				i += 4;
So I did all my calculations in float, but cast to int just before sending to USB.

Code:
float tempKelvin = tempCelcius + 273.15;
int Kelvin = (int) tempKelvin;
byte * b = (byte *) &Kelvin;
usb.write(b, sizeof(Kelvin);
and I had to update the Android side, since int on Arduino (the board I have) is only 2 bytes:

Code:
while (i < bytes) {
				if (bytes >= 2) {
					int int_bits = 0;
                    int_bits = ((buffer[i + 1] & 0xff) << 8)
							| ((buffer[i] & 0xff));
					mHandler.obtainMessage(NEW_TEMPERATURE,
							new Temperature(int_bits)).sendToTarget();
				}
				i += 2;
My values were then much more reasonable, but still not realistic (80 °C )

Some more digging, and I realized that the algorithms in the book to calculate the temperature from the sensor pin reading are not consistent: the notes in the book gives one algorithm, and the code gives another. A bit of Googling and I think (note disclaimer above) the code's algorithm is for the LM35 sensor, whereas the notes' algorithm is for TMP36 (which is the one included in the K000008 Kit). Anyway, I just grabbed this algorithm for TMP36

Code:
int rawvoltage= analogRead(outputpin);
float volts= rawvoltage/205.0;
float celsiustemp= 100.0 * volts - 50;
(don't forget to add 273.15 to celciustemp if you want to send the temperature in Kelvin)
After plugging in the above (and sending a 2-byte int instead of the 4-byte float), it's working fine.

I've lost some accuracy since I'm throwing away the fractional part of the temperature, but I don't know how to parse floats on the Android side: how many bits are for the mantissa? do I do byte swapping like in the case of the int? I'd be very grateful if anyone can advise me on this.

ps: I know this is somewhat of a thread necro, but hopefully the above can be of some assistance to someone else.

pps: I'm a total newb to this stuff, so please post any corrections to the above.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ADK Kit from Arduino? PaulTR BOOK: Professional Android Open Accessory Programming with Arduino 6 May 7th, 2013 01:13 PM
connecting android with arduino salahjardali BOOK: Beginning Android Application Development 2 April 10th, 2013 08:34 PM
consistent pages zaid BOOK: Beginning ASP.NET 4 : in C# and VB 3 January 29th, 2013 01:27 PM
Consistent compilation error Chapters 11/12 mnielsen BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 March 31st, 2007 05:35 PM
wrox book on VB 2005 Express starter kit webgeo99 Visual Basic 2005 Basics 1 February 22nd, 2006 08:11 AM



All times are GMT -4. The time now is 02:21 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.