Вы находитесь на странице: 1из 19

12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

RedAcacia
Just tech­oriented projects and sharing
them!

Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield
Posted on April 30, 2014

Introduction

The Freescale FRDM­KL25Z board is an ultra­low­cost development platform for Kinetis L

Series KL1x (KL14/15) and KL2x (KL24/25) MCUs built on ARM® Cortex™­M0+ processor. Features include

easy access to MCU I/O, battery­ready, low­power operation, a standard­based form factor with expansion board
options and a built­in debug interface for flash programming and run­control. The FRDM­KL25Z is supported by

a range of Freescale and third­party development software, including mbed platform.

The Digilent Basic I/O shield  is an input/output expansion board designed for use with chipKIT

microcontroller boards such as the Uno32™ and the Max32™.


The Basic I/O Shield provides simple digital input devices such as switches and buttons, and digital output devices

such as discrete LEDs and high current open FET drivers. It provides more advanced devices such as an I2C

EEPROM, an I2C temperature sensor, and organic LED graphic display. A potentiometer is also provided for use
as an analog input device.  The Basic I/O Shield is designed to the same form factor as the Uno32 board, but is
also usable with the FRDM­KL25Z board.

Remote viewing is an interesting proposition that we will dwell upon here with these two boards, and some extra
material, such as a Bluetooth module and, at the end, Bluetooth­enabled phones.
• •
Pre­Requirements:


You must have already done:

Installation in Windows of your FRDM­KL25Z board.
Tested FRDM­KL25Z with simple exercise such as blinking the RGB LED on it

If you done neither of the two above exercises, you ought to follow the introduction“Getting Started with mbed
and Freescale FRDM­KL25Z board”. •

Also you must have done temperature measurement with temperatur sensor TCN75A on Digilent Basic I/O shield.

Necessary material • •

You need the following boards:


https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 1/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

• •




And Bluetooth adapter, Buletooth module and power supply unit:

• •

                         

– Freescale FRDM­KL25Z board 
– Digilent BASIC I/O shield 

– Power supply unit (MB­102)for the set up 
– Mobile Processing software  • •

– Class I or II Bluetooth adapter  •
– JY­MCU Bluetooth Module (available from Aliatron)

Procedures: •


1 – Preparing our programming setup

The following connections will allow us to program the mbed board, and to prepare it


https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 2/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

FRDM KL­25Z board is going to communicate with Microchip’s TCN75A temperature sensor on Digilent Basic
I/O Shield.

2. Connect your mbed­enabled FRDM­KL25Z to your PC

Use the USB lead to connect your FRDM­KL25Z to a PC, using the USB female connector labelled OpenSDA.

The status light will come on, indicating FRDM­KL25Z has power. After a few seconds of activity, your PC will
recognise the mbed Microcontroller as a standard USB drive.

3. Visit the mbed website to get logged in, and to compile

https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 3/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

The URL for mbed website is:

http://mbed.org

Log in with your normal username and password.  This will give you access to the website, tools, libraries and
documentation.

4. Open the mbed Compiler 

Open the IOShield_Temp program and edit main.cpp (that you may have already written before) 

Write the following code (just copy and paste):

1 int main() {
2    char cmd[2];
3    while (1) {
4       cmd[0] = 0x01;
5       cmd[1] = 0x00;
6       i2c.write(addr, cmd, 2);
7  
8       cmd[0] = 0x00;
9       i2c.write(addr, cmd, 1);
10       i2c.read(addr, cmd, 2);
11  
12       float tmpC = (float((cmd[0]<<8)|cmd[1]) / 256.0);
13       float tmpF = (float(9.0*tmpC)/5.0 + 32.0);
14       // convert Centigrade into Fahrenheit
15       pc.printf("%.2f", tmpC);
16       pc.printf(",");
17       // comma (,) separator necessary for string splitting
18       pc.printf("%.2f", tmpF);
19       pc.printf("");
20       // somehow this extra line makes the reading more stable
21       wait(0.5); // wait 0.5s
22    }
23 }

Before anything else save your code.

5. Compile and Download the Program

To compile the program, click the Compile button in the top toolbar.

This will compile the program source code files within the program folder.

https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 4/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

And a binary program will be created.

After a successful compile, you will get a Success! message in the compiler output, and the download dialog
will pop up to Save the binary program, or it will be automatically downloaded to your PC’s
default Downloads folder. If you can Save, save it directly to FRDM­KL25Z board (acting as a drive), otherwise
drag and drop, or cut and paste into your FRDM­KL25Z.

If everything goes well, FRDM­KL25Z is programmed. Power reset your FRDM­KL25Z.

6. Display the temperature on Terminal of PC

Launch a Terminal program such as Putty, or Termite.  Ensure that the configuration settings of the port are
 Baud Rate 9600, Data bits 8, Stop bits 1, Parity none, Flow Controlnone. My port number is COM23 as can be
seen (Termite’s port settings). 

My FRDM­KL25Z board is connected to  port 23. The port number can be seen at Device Manager of your
Windows.

You will see immediately the temperature values being displayed:

https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 5/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

We are now ready to add the Bluetooth connection.

7. Final setup

Connect up the boards, JY­MCU Bluetooth module, and power supply as shown:

My actual set up looks like as the photo shows:

https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 6/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

Note: the power supply and the way to connect the voltage supply is just my proposition. You can connect power
supply in other ways.

Once the set up is powered you will see a blue LED blinking on your JY­MCU module.

Basic I/O shield must be installed on top of FRDM­KL25Z.

8 – Bluetooth installation in your PC

You must have your bluetooth adapter duly installed in your PC. My PC’s Bluetooth Sweex adapter shows in my
sytem tray a bluetooth symbol. After activating bluetooth, I have the option to find the local bluetooth
connections:

Do a search, and eventually you will find HC­06 (default name of JY­MCU module, a name that can be changed if
required):

Next, we will connect to JY­MCU bluetooth module (found in my PC in COM31):

https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 7/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

You will need to introduce the password which is ‘1234’:

I have blurred the MAC address of my bluetooth module. After introducing the password, click the OK button. You
will see HC­06 connection as paired.

We next connect HC­06 to the serial port of your PC (in my case it is COM31):

The HC­06 icon will now change to green:

9) Display the temperature on Terminal of PC

We are ready to run the Terminal program.  Ensure that the configuration settings of the port are  Baud
Rate 9600, Data bits 8, Stop bits 1, Parity none, Flow Control none. My port number is correct (in my case it is
COM31).  The result will be displayed as:

https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 8/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

Having tested remote readings of temperature, we are now ready to write Apps for Bluetooth­enabled cellphones
that will read the temperatures.

10) Display the temperatures on cellphones

The aim now is to display the temperature in a convenient way on:

– Android phone / tablet 
– Blackberry phone

a) For Android, I have written code on MIT’s App Inventor Classic. The code is based on one written by kerimil
at Instructables’ website.

I have modified kirimil’s code to read the incoming continuing string, and to split it into two variables, and made
other minor adjustments, and given the project new name TempMon. It is beyond the aims of this tutorial to teach
how to write code for App Inventor. There is ample teaching material on the Web, if you are interested.

So, if you want to write code, or modify, or even import, I have made it available on Bitbucket kept at Bitbucket,
an unlimited free private repositories’ site. You can download the zip file, and upload to App Inventor Classic’s
website. Click here to download the code.

The Android App, TempMonitor.apk, can be downloaded, if you do not want to write code. It is again available at
at Bitbucket repository.  Click here to download it.

I assume you know how to upload, and to install an Android app. Once installed you will need to launch the App,
but before that you need to enable Bluetooth in your Android phone, and to pair the JY­MCU module to your
Android phone.

https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 9/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

Next pair JY­MCU after searching for it, by pressing onto HC­06, and choosing to pair.

Introduce 1234 to pair, and click OK

You will see that JY­MCU (named as HC­06) is paired:

Now you are ready to launch the App which will be in your Android’s Apps folder:

https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 10/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

You will be greeted with following screen:

Click Choose device to connect to button, in next screen, click onto MAC address of your HC­06 (I have blurred
the MAC Address of my device).

 On clicking, you will see the first screen on top and you will see that the device is connected, and the temperature
will be displayed in ºC and ºF

https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 11/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

You can hear the temperature, by clicking Say temperature button.

b) For Blackberry (not BB10, but previous ones with Java OS – mine is Blackberry 9900) I have written code
in Mobile Processing. f you do not know how to write Blackberry Apps in Mobile Processing, I suggest you follow
my tutorial published here in this blog Write a Drawing App “myArtwork” for Blackberry with Social Networking
Sharing Capability. You will need Mobile Processing, that you can download from Mobile Processing website.

You’ll also need a slightly patched Mobile Processing Bluetooth library:mobileprocessing­bluetooth­patched.zip.
 In the “libraries” directory of the Mobile Processing application, move the existing “bluetooth” library directory
out of the way and unzip the above zipfile in its place.

The processing sketch is as follows:

1 import processing.bluetooth.*;
2 import processing.phone.*;
3  
4 Bluetooth bt; //new bt device
5 Service[] services;
6  
7 PFont font;
8  
9 int state;
10 String msg;
11 String DEGREE = "\u00b0"; //to display correctly degrees symbol
12 Client c;
13  
14 final int STATE_START = 0; //different states, similiar to events.
15 final int STATE_FIND = 1; //find devices
16 final int STATE_HOST = 2;
17 final int STATE_PLAY = 3; //once connected to device
18  
19 byte[] inBuffer = new byte[11]; //store the bytes read from mBed in array.
20 //For the temperature sensor, there are only 11 digits
21  
22 int counter;
23  
24 void setup() {
25 font = loadFont();
26 textFont(font);
27 bt = new Bluetooth(this, Bluetooth.UUID_SERIALPORT);
28  
29 counter = 1;
30 }
31  
32 void draw() {
33 background(255);
34  
35 if (state == STATE_START) {
36 fill(0);
37 textAlign(LEFT);
https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 12/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

37 textAlign(LEFT);
38 text("Welcome to mBed Bluetooth TempMon.\n\nFind device...\nPre   ss any key", 2,
39 }
40 else if (state == STATE_FIND) {
41 fill(0);
42 textAlign(LEFT);
43 if (services == null) {
44 text("Looking for SPP device...\n\n" + msg, 2, 2, width ‐ 4, he   ight ‐ 4);
45 }
46 else {
47 String list = "SPP device found\n\n";
48 for (int i = 0, length = length(services); i < length; i++) {
49 list += i + ". " + services[i].device.address + "\n"; //this will list 
50 }
51 text(list, 2, 2, width ‐ 4, height ‐ 4);
52 }
53 }
54 else if (state == STATE_PLAY) {
55 c.readBytes(inBuffer); //Assigning assign the readBytes data into the inBuffer array for st
56 String inB2 = new String(inBuffer); //change the byte values into strings data int chars = 
57 String[] dat = split(inB2, ','); // parse comma‐separated number string into numbers
58 if (inBuffer != null) {
59 String data = dat[0] + DEGREE + "C / " + dat[1] + DEGREE + "F" ;
60 text("Local Temperature:\n" + data, 2, 2, width ‐ 4, height ‐ 4); //draw the mess
61 }
62 text("Local Temperature:\n", 2, 2, width ‐ 4, height ‐ 4);
63 }
64 }
65  
66 void libraryEvent(Object library, int event, Object data) {
67 if (library == bt) {
68 switch (event) {
69 case Bluetooth.EVENT_DISCOVER_DEVICE:
70 msg = "Found device at: " + ((Device) data).address + "...";
71 break;
72 case Bluetooth.EVENT_DISCOVER_DEVICE_COMPLETED:
73 msg = "Found " + length((Device[]) data) + " devices, looking for service...
74 break;
75 case Bluetooth.EVENT_DISCOVER_SERVICE:
76 msg = "Found SPP service on " + ((Service[]) data)[0].device.address + "...&
77 break;
78 case Bluetooth.EVENT_DISCOVER_SERVICE_COMPLETED:
79 services = (Service[]) data;
80 msg = "Search complete.";
81 break;
82 case Bluetooth.EVENT_CLIENT_CONNECTED:
83 c = (Client) data;
84 state = STATE_PLAY;
85 break;
86 }
87 }
88 }
89  
90 void keyPressed() {
91 if (state == STATE_START) {
92 //if any key is pressed.
93 services = null; // it will begin the search
94 bt.find(); //bt.find goes through the whole process of bluetooth searching
95 state = STATE_FIND;
96 msg = "Looking for devices...";
97 }
98 else if (state == STATE_FIND) { //this section will help connect to which device is found
99 if (services != null) {
100 if ((key >= '0') && (key <= '9')) {
101 int i = key ‐ '0';
https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 13/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

101 int i = key ‐ '0';
102 if (i < length(services)) {
103 msg = "connecting...";
104 c = services[i].connect();
105 state = STATE_PLAY;
106 msg = "ready";
107 }
108 }
109 }
110 }
111 }
112 void destroy() {
113 bt.stop();
114 }
115  
116 catch (java.io.IOException err)
117 {
118 }
119 catch (java.lang.SecurityException e)
120 {
121 }
122 catch (java.lang.IllegalArgumentException iae)
123 {
124 }
125 catch (IOException ioe)</pre>
126 {
127 }

You will now save the project with a name such as TempMon with  File­>Save As in the main dropdown menu.

Before proceeding, you will create an Icon for our App. It needs to be 62×62 pixels.  You can download here an
icon we have designed, together with pde file of above code. The file is hosted by Bitbucket. Bitbucket offers
unlimited public and private repositories, and it is free for small teams. In your PC’s My Documents ­>
MobileProcessing ­>TempMon folder paste data folder that includes icon image
file icon.png and TempMon.pde sketch (Mobile Processing and other Processing codes are known as
‘sketches’).

Export as MIDlet with File­> Export MIDlet:

https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 14/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

The MIDlet will be created and your PC´s My Documents ­> MobileProcessing ­>TempMon ­
> MIDlet folder (will open automatically to show TempMon.jad, TempMon.jar and My Documents ­>
MobileProcessing ­>TempMon.java files:

Note: If you care to check TempMon folder you will also see a new folder proguard.ProGuard is included
in Mobile Processing to make the apps smaller, and more efficient jar files. We will not use the jad and jar files
in this folder.

We are now ready to copy TempMon.jad and TempMon.jar into the Blackberry.

After connecting your Blackberry to your PC with USB cable, run Blackberry Desktop software and
choose Files:

https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 15/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

Click the Start button. You will see the next screen:

In your PCs folder MIDlet folder select TempMon.jad and TempMon.jar files:

And with right click of your mouse button Copy these files, and paste them into theBlackberry Desktop folder
you have just opened:

Both files will be now in your Blackberry phone’s documents folder.

NOTE: If you are too lazy to write code you can  install jad and jad files found here  (after unzipping) into
your Blackberry as shown. Note jad and jar files are hosted at Bitbucket, a free and unlimited public and private
repositories hosting site.

https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 16/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

Now disconnect the USB cable between your Blackberry and your PC. In your Blackberry go to All group of
folders, and choose Applications folder:

Open the folder, and select Files folder:

Open the Files folder and navigate to the documents folder. In my Blackberry, I found it in File Folders ­>
Device ­> home ­> user. In documents folder within user folder, you will
find TempMon.jad and TempMon.jar .  Select TempMon.jad and click on it:

You will see the next screen:

Click the Download button. Our app will start to be installed. You will get next a warning window that the
application does not contain a signature, just click Yes and let the App be installed. If successful, you will be
invited to immediately Run it. 

Once installed, the App’s icon will be as show below:
https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 17/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

Make sure your Blackberry is paired to HC­06 (the name of JY­MCU Bluetooth module). The password is 1234. 

Run the App, and if everything is alright you will see the following screen:

Conclusions

We have achieved remote temperature viewing of temperature read by our Freescale FRDM­KL25Z
board from the temperature sensor Microchip TCN75A on Digilent Basic I/O shield.

We have used App Inventor Classic and Mobile Processing to read remotely temperature on two
smartphones, respectively Android and Blackberry.

I shall appreciate any comments, and suggestions.  I will also appreciate if you point out  any errors or omissions
in this tutorial.

About these ads

Tomy Piratskip Badeleke

259 kr
KJØP

Tomy Turtle Tots Badeleke

329 kr
KJØP

Ads by jollyroom.no

 Like
Be the first to like this.

https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 18/19
12/20/2016 Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic I/O Shield | RedAcacia

Related

Temperature measurement with Freescale Getting Started with mbed and Freescale Blackberry 10 Remote Temperature Viewing


FRDM­KL25Z and TCN75A on Digilent Basic FRDM­KL25Z board and Listening
I/O shield In "Electronic Projects" In "Electronic Projects"
In "Electronic Projects"

About Tayeb
Electronics engineer, part­time webmaster and owner of "Aliatron", a tech­oriented company registered in Portugal and
Mozambique.
View all posts by Tayeb →

This entry was posted in Electronic Projects and tagged ARM, Arm Cortex, BASIC I/O, Bluetooth, Digilent, FRDM­KL25Z, Freescale, JY­MCU, Kinetis, mbed, Microchip, Mobile
Processing, Processing, Remote, TCN75A, Temperature. Bookmark the permalink.

One Response to Remote Viewing of Temperature with FRDM­KL25Z and TCN75A on Basic
I/O Shield

Pingback: Blackberry 10 Remote Temperature Viewing and Listening | RedAcacia

RedAcacia
Create a free website or blog at WordPress.com.

https://redacacia.me/2014/04/30/remote­viewing­of­temperature­with­frdm­kl25z­and­tcn75a­on­basic­io­shield/ 19/19

Вам также может понравиться