Skip navigation
>

Freescale Freedom FRDM-K64F Development Platform - Review

Scoring

Product Performed to Expectations: 10
Specifications were sufficient to design with: 8
Demo Software was of good quality: 10
Demo was easy to use: 10
Support materials were available: 8
The price to performance ratio was good: 9
TotalScore: 55 / 60
  • RoadTest: Freescale Freedom FRDM-K64F Development Platform
  • Buy Now
  • Evaluation Type: Evaluation Boards
  • Application you used the part in: WEB CONNECTIVITY/IOT DEMO
  • Was everything in the box required?: Yes - null
  • Comparable Products/Other parts you considered: null
  • What were the biggest problems encountered?: null

  • Detailed Review:

    Introduction

    I wanted to add web connectivity to my latest projects , reviewing the K64F gave me the ideal opportunity to investigate this.  I’ve been using the MBED platform for a while and find it a great way to build projects quickly. So for my review I looked at using the K64F with MBED and in particular looking at Web Connectivity. I investigated implementing a REST interface for accessing web services and  how you could use a socket interface to update a webpage real time without any polling or refreshing.  Before looking at these apps, I’ll cover the Hardware and the MBED environment. 

     

    The hardware

    Connectivity The K64F has a similar form factor to many dev boards and the connectors are compatible with  Arduino R3 shields.  The main connector are implemented using  2 rows female connectors on a 0.1inch pitch down the sides of the board. On some other freescale boards e.g. KZ25 you had to solder the connectors yourself but here they are ready populated. The board also has a micro SD connector which is a nice feature (although it’s not a very secure connector). The board also has add-on connections for Bluetooth JY_MCU and the nordic nRF24L01 modules .  There is nothing special about these interfaces, it just make it possible to connect the modules directly to the board, however the connectors are very close together and if you populate one you won’t be able to populate the other which seems a bit odd to have the connectors effectively overlapping.

    It’s also worth noting that these dedicated connectors use up a serial/SPI port, if you don’t use the Bluetooth or the RF modules you can use these connections to gain access to the Serial/SPI port but you will need to solder on connectors.

     

    Features

    The K64F packs in a lot of features which makes it a very capable board on it’s own without having to add on additional peripheral.  The 1MB of flash and 256K of RAM make it particular appealing for larger projects. This is also particularly useful for when prototyping as you may not have optimised the code so not being constrained by the memory is ideal

    • MK64FN1M0VLL12 MCU (120 MHz, 1 MB flash memory, 256 KB RAM)
    • RGB LED
    • FXOS8700CQ – accelerometer and magnetometer
    • Two user push buttons
    • Can be powered from USB or external
    • Drag and Drop programming (Mass storage device flash programming interface)
    • Ethernet
    • SDHC
    • Add-on RF module: nRF24L01+ Nordic 2.4GHz Radio
    • Add-on Bluetooth module: JY-MCU BT board V1.05 BT

     

    MBED

    I've written a seperate blog entry for getting started on MBED http://www.element14.com/community/people/colin_meikle@mentor.com/blog/2015/03/20/k64f-with-arm-mbed-part-1-getting-started  but here is a quick Intro

    MBED is a complete environment for developing ARM based micrcontrollers. One of the main attractions of MBed is you can get started very quickly and you can put together working prototypes extremely quickly.  So why would you use Mbed over a vendor specific flow ? There are a number of reasons but the biggest reason is you can get something working fast, very fast.  You don't have to worry about setting up toolchain, downloading and configuring support libraries, you can quite literally  be up and running in minutes. The Mbed environment comes with an online IDE with build in version management, so there is no setup to be done, just login and go! (the sign up is free). There is also an extensive library of drivers and code snippets, so for most applications you can find something that fits your needs exactly or at least comes close. Once you've completed your program you simply press the compile button and the programming image is downloaded. You simply plug in the board and it appears as a drive on your computer, drag and drop the programming file on the drive and the board is programmed. It couldn't be simpler!

    The K64F is a very good board to use with MBed it has Ethernet connectivity built in which gives you many more options without having to add on external boards and it has plenty of RAM and FLASH. One thing to note you need to update the Firmware on your board,  this is a simple procedure the step by step instructions can be found here http://developer.mbed.org/handbook/Firmware-FRDM-K64F


    Test Applications

    I created 2 separate test programs for the road test, again I’ve written separate blog post that cover each in more detail but here is an overview of each

     

     

    Weather Station

          A detailed write up can be found here K64F MBED Part 2 Weather Station

    You can get the Code from here: http://developer.mbed.org/users/colinmeikle/code/weather/

    If you are using the mbed online environment you can simply import the program into your workspace'

     

    Here are the feature I planned to implement

    1. Data and Time set automatically via NTP
    2. Data displayed on TFT display (I used a 240x320 display using ILI9341 controller, which is very common)
    3. SDCard for storing weather data and for holding image resources for TFT
    4. Temperature and Humidity Sensor, I will use external DHT22 sensor
    5. I will use forecast data for outside temperature and pressure
    6. I will plot the data on a graph using online service

     

     

    weather.jpg

    The intro video for the K64F claims you can build your first application with 30 seconds of opening the box. Building something useful obviously takes a little longer but I was able to implement all of this writing less than 200 lines of code (including comments)


    Connecting everything up

           

    There isn’t too much to connect here, the TFT uses SPI and because the SDCard and the (unpopulated) RF module also use SPI there is only one free SPI port available on the external connectors. The SDcard is on board so nothing to connect there, the Temp/Humidity sensor uses a shared single wire connection for TX/RX so it’s very simple to connect up, however you need to remember to add a pullup to the data line. My router isn’t close to my desk so I used a powerline adapter for the Ethernet, this worked flawlessly without any setup.

     

    Programming and  DEBUG

    Compiling and programming could not be easier in MBed, simple press the compile icon if successful it will download an image. You simply plug in the board to the USB port (the port nearest the reset button) and it appears a mass storage device, i.e. a drive that you can simply drag and drop the image to. That’s all that is required! Press the reset button and the board will start running your code.

    Debugging with the online MBED IDE is not the best debug environment, you can’t step through your code from the online environment. You can export your program to an external environment e.g. you can export to Kinetis. However for many simple issues printing messages to the terminal is sufficient.

    After programming the board,  I had a few issues to track down, there were some simple errors in my code, inserting a few debug messages sorted these. The biggest issue was the display, It remained  blank, I was confident the library worked OK with this display as I had used it before. Eventually I spotted an Errata that suggested you shouldn’t use port PTA10 as it was also used for the JTAG interface. I had originally used this port of the CS pin of the Display, moving this connection to a different pin fixed the problem and the  display spring into life. 

     

    Web Connectivity

    One of the advantages of the k64F is it has onboard Ethernet, using this with the MBED platform is very easy, it’s simply a matter of including the Ethernet library and any protocol layers you want to use e.g. HTTP Client,NTP,SMTP,WebSocket,Twitter, etc. You can see all the protocols and examples here http://developer.mbed.org/handbook/TCP-IP-protocols-and-APIs

    I set the RTC using the NTP service which gives me an accurate date and time. My application measure the temperature and humidity using a sensor connected to the board but for outside temperature and atmospheric pressure I use data from an online weather api.  I use the api from openweather.org. You can get the data in different formats, I’m using JSON which I parse using the picoJSON library.

    Just to show how easy this is, the code boils down to just a few lines:

    1. ntp.setTime("pool.ntp.org");

    ... 

    1. http.get("http://api.openweathermap.org/data/2.5/weather?q=Glasgow,uk", resp, 5000);

      json=&resp[0];   

      string err = picojson::parse(v, json, json + strlen(json));{

      forcastTemp=v.get("main").get("temp").get<double>();

      forcastPressure=v.get("main").get("pressure").get<double>();

     

    The display gives the current data however the easiest way to monitor the data is to log it using a cloud based service. There are various services for doing this, in my example I use thingSpeak (https://thingspeak.com/) you can signup for a free developer account. It’s pretty straight forward to create a “channel” that you send your data to, this can then be graphed real time You can view some of my charts here https://thingspeak.com/channels/26357

     

      

    The code for doing this is very simple and it makes monitoring data real time very very simple.

     

    2. Updating a webpage real time

     

     

     

    I wanted to send data to a webpage in real time, although you could do this using a REST interface much in the same way that the previous weather application got data from the WEB APIs. However this isn’t a very efficient method when you want to send a continual stream of data, in this case it would be much better to use a socket interface. To demo how this might work I’m sending the data from the inbuilt accelerometer/magnetometer to a webserver, the web browser connects to the server and the webpage data will updated automatically.

     

    Here is how the application is structured

     

     

     

     

    Connecting things up.

    There isn’t much to do here, just plugin your Ethernet cable can connect the USB cable to the PC and your done! Nothing else required, not even power.

     

    The Code

     

    There are 3 separate parts to the code

    The MBED based code that runs on the K64F, the sends the sensor data to the server.  The webserver that we send the data to, I’m using node and Express to do this (very easy)

    Finally we need to update the webpage running on web browser.  This is done using regular javascript but the socket interface uses socketIO javascript library (http://socket.io/ ) to implement the websocket interface. This simple example could be modified to suit many different scenarios and should scale reasonably well. I’ve keep the code simple so you can see how it works. Again I’ll make a blog post giving full details of how things work so it’s just an overview here.

     

     

     

    The K64F code.

    The code is a based  on some of the example code for the FXOS8700Q, I’ve modified it to add the socket interface. You could probably write the code here in less than 10 lines!

    eth.init(); //Use DHCP

    eth.connect();

    TCPSocketConnection socket;

    while(1){

      acc.getAxis(acc_data);

            mag.getAxis(mag_data);

            //format the data as JSON

            sprintf(buf,"{\"acc_data\":{\"x\":%1.4f,\"y\":%1.4f,\"z\":%1.4f},\"mag_data\":{\"x\":%1.4f,\"y\":%1.4f,\"z\":%1.4f}}\n",acc_data.x, acc_data.y, acc_data.z, mag_data.x, mag_data.y, mag_data.z); 

            socket.send_all(buf, strlen(buf));    //send it to the server

    }

     

    The code is pretty self explanatory, setup the Ethernet, get the data from the sensor, format it and send it through the socket!

    Server Code

    There is a bit more code here as we need to serve the webpage that we want to show and handle the socket connections from both the K64F and any web browser that connects.

    Here is a section of the code that receives the data from the k64f and sends it out to the web browser. The server used nodejs so this is all in javascript.

    var net = require('net');

    var server = net.createServer(function (k64fClient) {

        console.log('k64fClient connection');

        k64fClient.setEncoding('ascii');

        k64fClient.on('data', function (data) {

            //assign the data to k64fdata

            k64fdata=data;

            //writeData(k64fClient, 'thanks\r\n'); //send data back Not used in this example

            //*** Send an update to the browser

            io.emit('dataUpdate',k64fdata);

            console.log("received data on Port %d :$s \n", k64fClient.remotePort, data.toString());

            console.log("Bytes received : " + k64fClient.bytesRead);   

        });

     

    As you can see this is very simple, since the mbed code formats the data as JSON we don’t need to do anything to it on the server, we just send it unchanged the web browser. We could of course extract some of the data and store it,  we could then draw graphs or do something interesting with it (e.g. send an email if the temp drops to far).

     

    Javascript for the webpage.

    The web page  simply has some labels with an id e.g. data_label. (There is some other code to make t look a bit better). The Javascript uses the socket.io client library and connects to the server. When the server sends a dataUpdate event the data is decoded and the label content is replaced with the data value. Because this function runs every time the dataUpdate event happens the page updates in real time without any refreshes or polling.

    var socket = io.connect('http://localhost:3000');

      socket.on('dataUpdate', function (data) {

        console.log(data);

        //update the  

         dataJ=JSON.parse(data)

        var accx="X="+dataJ.acc_data.x+" ";

        var accy="Y="+dataJ.acc_data.y+" "; 

        var accz="Z="+dataJ.acc_data.z+" ";   

        var magx="X="+dataJ.mag_data.x+" ";

        var magy="Y="+dataJ.mag_data.y+" "; 

        var magz="Z="+dataJ.mag_data.z+" ";     

        var e = document.getElementById("data_label");

        e.innerHTML=data; 

        e = document.getElementById("data_acc");

        e.innerHTML="<p>"+accx+accy+accz+"</p>";   

        e = document.getElementById("data_mag");

        e.innerHTML="<p>"+magx+magy+magz+"</p>";     

         

      });

     

     

    If you start up the server and the k64F, you should see some messages in the server console, then you can navigate to the webpage using http://localhost:3000/ (assuming you are running this locally and haven’t changed the ports). You should see that data change as you move the K64F board, data is sent about once per second.

     

    You could easily expand this to do other things, the purpose of the demo was just to show the socket connectivity and how easy it is. You could do similar things using some of the cloud services available. This has its advantages in some cases depending on your requirements but building your own setup gives you ultimate flexibility and of course you learn a bit more this way

     

    Running the application

     

    This is pretty simple, run the webserver this uses node. Plug in the K64F and download the mbed code, finally connect to the webserver, As you move the board the data displayed on the webpage will change!

     

    Final notes.

     

    There are lots of dev boards available and many now work with the MBED platform, however the features of the K64F make it one of the best choices especially if you want to use web based connectivity.

    My board came as part of a MBED kit which has a plugin card with some additional sensors and has instructions for connecting to the IBM cloud based services. Rather than use this board I chose to show what you could do with the bare board, I think building your own application and connecting the pieces together gives a better feel for whats possible and the effort required.


Comments

Also Enrolling
Enrollment Closes: May 12 
Enroll
Enrollment Closes: May 29 
Enroll
Enrollment Closes: Jun 15 
Enroll
Enrollment Closes: May 23 
Enroll