## Getting Started with mbed and Freescale FRDM-KL25Z board

Introduction

mbed is a platform for developing smart devices that are based on 32-bit ARM Cortex-M microcontrollers. It is designed to provide a highly productive solution for rapid prototyping and product development, with a focus on connected Internet of Things devices.

It is a project developed by ARM, its technology partners and a community of core developers, and it is used by tens of thousands of professional developers to create intelligent products that take advantage of the power of modern microcontrollers and connectivity. (Source).

The Freescale FRDM-KL25Z board is an ultra-low-cost development platform forKinetis 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.

Objectives

This tutorial guides you through mbed-enabled Freescale Freedom FRDM-KL25Z board, and getting started with the mbed online tools platform. An mbed-enabled FRDM-KL25Z board gives you:

• USB drag and drop programming
• USB Virtual COM port for serial terminal
• CMSIS-DAP interface for programming and debugging from offline tools
• Free access to the mbed online compiler, mbed C/C++ SDK, and developer community

It is assumed from now on that you have a Freescale  FRDM-KL25Z board and that it is already mbed-enabled.

It is really simple to setup and program, and it is free, so let us get started!

Procedures

### 1. Connect your mbed-enabled FRDM-KL25Z to your PC

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

FRDM-KL25Z board. Red square shows poaition of OpenSDA USB connector

The status light will come on, indicating it has power. After a few seconds of activity, the PC will recognise the mbed Microcontroller as a standard USB drive. Also your PC will detect that a driver is needed.

2. Install the drivers in your PC

After your PC detecting the FRDM-KL25Z board, it will invite you to install drivers, Choose the second option of Advanced installation of driver as shown.

Windows’ requirement for a driver. The red rectangle shows Advanced installation

Note: This installation is under Windows XP in portuguese, your Windows will take you through similar procedures.

Click Next and choose to find the driver (by this time most certainly FRDM-KL25Z is recognised as a drive).

Red rectangles show the option to use a location and FRDM-KL25Z as drive

The required drivers are included in FRDM-KL25Z’s flash memory. Install the drivers, following all the normal steps of installation.

Install the drivers, following all the normal steps of installation.

NOTE: You may be warned that the driver is not officially recognised to be compatible with Windows. You will need to accept it as trustworthy.

Warning of  driver incompatability to be ignored

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

The URL for mbed website is:

http://mbed.org

If you do not have an mbed account, choose “Signup”, and create your mbed Account. Otherwise, log in with your normal username and password.

Login or signup at left corner of page

Login will give you access to the website, tools, libraries and documentation.

On top left of Home page you will see the menu where you will choose your platform by clicking on Platforms button.

Red rectangle indicates Platforms option of menu

Now choose the right Platform that for this case is FRDM-KL25Z, by clicking on this option.

Blue rectangle indicates Platform option to be chosen for FRDM-KL25Z

Having chosen the Platform, you will now add your FRDM-KL25Z board to your Compiler.

Red rectangle shows the option to be chosen for adding the board

After adding the board to the Compiler you are ready to compile your first code.

### 4. Open the mbed Compiler

Open the online Compiler clicking the Compiler button in the site menu (top-right of the page). This will open the Compiler in a new tab or window.

Red rectagnle shows the option to be chosen, and red arrow shows already logged in

NOTE: It will be your chosen name that will appear as logged in, obviously!

5. Write a New Program

To create a new program in your personal Program Workspace:

• Right-click on My Programs, and select New Program…

Adding “New Program…” in Program Workshpace

• Enter the name of the new program (e.g. “HelloWorld”), and click OK

Pop up window to create new program name

Your new program folder will be created under My Programs

### 6. Add a source code to the program

Add a new file by right clicking on HelloWorld program name.

Adding “New File…” to “HelloWorld” program name

• Enter the name of the new file main.cpp and click OK.

Pop up window to create new file name

After adding new file, click on the main.cpp file in your new program, to open it in the file editor window. This is the main source code file in your program, and by default it is empty. Write the following program.

#include "mbed.h"
DigitalOut myled(LED1);
int main() {
while(1) {
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}
}


The result will be as shown:

Code in main.cpp file

• Adding mbed library to the program folder

The other item in the program folder is the mbed library – this provides all the useful functions to start up and control the mbed Microcontroller, such as the DigitalOut interface used in this example. Right-click on HelloWorld, choose Import Library… and From Import Wizard…

Import library wizard

Now choose mbed library and then click on Import button on the top right-side.

Import mbed library

Program Workspace will show that mbed library has been added to HelloWorld program.

Program Workspace with HelloWorld and main.cpp file and mbed library

In our main.cpp file LED1 stands for red colour LED on the FRDM-KL25Z. Before proceeding any further, make changes to second line at the end of DigitalOut command, substituting LED1 with LED3. On the right-side of editor you will see the Enumerator telling you that LED3 corresponds to blue LED on FRDM-KL25 RGB LED.

LED3 enumerator indicating what it corresponds  to

Our main.cpp file’s content will be now:

#include "mbed.h"
DigitalOut myled(LED1);
int main() {
while(1) {
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}
}


Before proceeding save main.cpp file by right-clicking on it, and choosing the option Save…

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

Compile button

This will compile all the program source code files within the program folder to create a binary program.

Compiling “HelloWorld” program

• 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 default Downloads folder.

Compiler output for “HelloWorld”

• Save it to the location of your PC in case of download dialog pop up.

NOTE: In Goggle’s Chrome browser, the compiled file will be downloaded to Downloads folder.

Compiler output for “HelloWorld” in Downloads folder of PC

NOTE: If there are errors, they will show up in the “Compiler Output” window, and will need to be fixed!

• FRDM-KL25Z behaves a drive, so you find it in My Computer of your PC.

FRDM-KL25Z as a drive in My Computer

• Cut, or drag, the HelloWorld_KL25Z.bin file in your PC’s Downloads folder and paste, or drop, in the mbed Microcontroller folder, wait a few seconds for the drive folder to close automatically, and then hit reset on the microcontroller to start it running!

If everything goes well, FRDM-KL25Z is programmed and the blue LED on RGB LED on FRDM-KL25Z will blink!

Main source of this tutorial is mbed.org website, specially the Handbook section at: https://mbed.org/handbook/mbed-FRDM-KL25Z-Getting-Started

And an enormous wealth of information on mbed’s website!

Posted in Electronic Projects | | 4 Comments

## Design and Simulate a 4-Bit Parity Generator in Multisim and Implement on a Digilent Basys 2 Spartan-3E FPGA Board

Introduction

Parity bits are extra signals which are added to a data word to enable error checking. There are two types of parity – even and odd. An even Parity Generator will produce a logic 1 at its output if the data word contains an odd number of 1s. If the data word contains an even number of 1s then the output of the Parity Generator will be 0. By concatenating the parity bit to the dataword, a word will be formed which always has an even number of 1s i.e. has even parity.

Parity is used on communication links (e.g. modem lines) and is often included in memory systems. If a dataword is sent out with even parity, but has odd parity when it is received then the data has been corrupted and must be resent. As its name implies the operation of an Odd Parity generator is similar but it provides odd parity. The table shows the parity generator outputs for various 4-bit data words.

Objectives

• Use a Truth Table to construct odd parity generator.
• Derive the logic circuit from algebraic function obtained from Truth Table
• Design and simulate the Parity Generator in NI Multisim 13.0
• Implement the Parity Generato on a Digilent Basys 2 Spartan-3E FPGA board

Hardware Requirements

Digilent Basys2 Spartan-3E FPGA Board (the board comes with an USB programming cable)

Software Requirements

• ISE WebPACK Design Software (available here)
• Xilinx iMPACT 13.x or later, part of the ISE WebPack (link as shown in previous line)

Installation Instructions

• Download the attached Digilent Basys 2 file.
• Unzip the file to your local disk.

Two files will be unzipped: DigilentBasys2.mspc and DigilentBasys2.ucf.

• Copy and paste the two unzipped files to the pldconfig folder in the main Multisim 13.0 install directory, by default, this should be:

Program Files->National Instruments->Circuit Design Suite 13.0->pldconfig

In my PC it looks like as show using WinRAR (evaluation copy):

Pressing OK the files will be duly copied.

Procedure

A) Derive the Logic Circuit of 4-Bit Parity Generator

The Truth Table of 4-Bit Parity Generator is:

The equivalent Karnaugh Map (K-Map) is:

From K-Map, we can derive the algebraic function which is (P is the parity result):

P = A’B’C’D+A’B’CD’+A’BC’D’+A’BCD+AB’C’D’+AB’CD+ABC’D+ABCD’

This result can be simplified as:

P = A’B'(C’D + CD’) + A’B (C’D’+CD) + AB'(C’D’ + CD) + AB (C’D + CD’)

= (A’B’ + AB) . (C’D + CD’) + (A’B + AB’) . (C’D’ + CD)

P is the result in our case for Odd Parity.

We note that above algebraic simplification is representing XOR (short for Exclusive-OR) and XNOR (short for Exclusive-NOR) gates. You can read an excellent tutorial here.

Hence:

P = (A ⊕ B)’ . (C ⊕ D) +  (A ⊕ B) . (C ⊕ D)’

= (A ⊕ B) ⊕ (C ⊕ D)

This algebraic function is represented by following logic circuit:

B) Design the Schematic and Simulate

We will first design the top level schematic in NI Multisim 13.0 which is used for simulation purposes and contains the PLD subsheet.

The top level schematic, as part of this project, allows for simulation. It places the PLD logic in place around the IO contained on the board. To achieve this we use a PLD sub-circuit. The PLD sub-circuit allows us to place the PLD code within a single component as if it was being run on the FPGA.

The steps below describe the process for creating a sub-circuit.

1. Open a new schematic in Multisim.

2. Select Place » New PLD sub-circuit

3. Choose Digilent Basys 2 and click Next button

4. Provide a name for the PLD schematic. I chose “Parity Generator”, as can be seen in image, leaving the default PLD part number as it is:

5. Select the connectors that you will be using on the Basys 2 Spartan-3E FPGA board. For the Parity Generator in this tutorial we will be using:

sw_0, sw_1, sw_3 and sw_4 for simulating input values A, B, C and D respectively on Basys 2 FPGA board.  Led_0 for output on the Basys 2 board and to indicate Odd Parity.

We will keep all other default values as they are, and click Finish button.

6. Place the sub-circuit

The sub-circuit is created:

Save the Multisim schematic giving it a name. I have called it “my_Parity_Generator”.

After completing the top level circuit, we need to create the digital logic within the PLD schematic. We will next edit the sub-circuit and connect it up.

To create the PLD schematic right-click the PLD sub-circuit and select Properties. A window will pop up:

Click Open subsheet button. An empty schematic with connectors for sw_0, sw_1, sw_3, sw_4 and Led_0

Connect up the logic circuit obtained before as shown:

Save the circuit.

7. Simulating the Logic

The top-level  schematic can be simulated by adding a Logic Analyzer and a Word Generator as shown:

Set up the Word Generator first. Doube-click on XWG1.

Settings window will pop up. On Display group of options choose Binary

Controls group of options click Set… button

Choose up counter and keep the default Initial pattern.

Up counter will be generated. We will now limit at 1111. Click on this pattern and right-click with mouse and choose Set Final Position.

Now double-click on XLA1, Logic Analyzer. On Word Generator click the Step button. As you Step through the patterns you will see the Logic Analyzer displaying the patterns as well the Parity result.

You can verify the Truth Table for Odd Parity outputs:

In fact Even Parity is inverse of Odd Parity, therefore in our PLD sub-circuit we could have also obtained this result by just placing an Inverter at output.

We can also test the circuit by connecting a LED to the output of PLD, and by stepping through the patterns in Word Generator. Everytime the LED is ON it means that it is Odd Parity.

8. Deploying the Logic

There are three options for exporting the digital logic from the PLD schematic:

– Programming the connected Hardware – allows students to deploy the digital logic and learn the response of using the hardware.
– Generate a PLD bit file – students can take this away and deploy when they have the hardware available.
– Generate VHDL file – allows students to explore the VHDL behind the logic.We will focus on programming the connected hardware.

NOTE: If your Windows OS is not in english language,  you will need to edit the TEMP and TMP localization in My Computer  -> Properties -> Advanced -> Environment Variables. You will have to change it from %USERPROFILE%\Local definitions to %SYSTEMROOT% to avoid XST Synthesis failure. This happens as the command lines of compilation do not accept foreign language characters such as çõ and others of similar nature . Of course you will need to restart your PC, after having made these changes to your Windows’ Environment Variables.

Right-click the PLD sub-circuit and select Properties. A window will pop up:

Click Open subsheet button.  The logic circuit that we designed before will be shown:

• Make sure that your Basys 2 board is connected to your PC with USB cable that comes with it.
• Select: Transfer » Export to PLD from the menu bar.

• Here you will see the three export options. We want to export to physical hardware so select Program the Connected PLD.

We want to program the connected PLD. Click Next.In my Windows environment I have already installed Xilinx ISE Design Suite 14.2. Note that Device Status is not checked. Make sure first of all that Basys 2 board is connected. You may need to install Adept software and make sure that the board is recognised by your PC.

• Click on Refresh button. Multisim will try to detect the Basys 2 FPGA board. Note that Multisim 12.0 does not detect the board.

If detected you will see the following reassuring information on this step.

• Now click Next. You will see first of 11 steps that Multisim 13.0 will go through

If all goes well your Basys 2 FPGA board (or any other supported Digilent boards such as Nexys 2 and 3 – you will need to install in Multisim the adequate constraints files) , you will see the following reassuring result:

9. Testing the logic

On Basys 2 FPGA board test the logic by switching HIGH and LOW the switches sw_0, sw_1, sw_2 and sw_3, and confer with the Truth Table by the Led_0 being lit (in HIGH state) or not (in LOW state):

Conclusions

A parity bit is used for the purpose of detecting errors during transmission of binary information. We have used two excellent tools NI Multisim and Digilent Basys 2 FPGA board. We first derived the logic circuit of 4-Bit Parity Generator from the Truth Table, simulated the derived circuit in NI Multism, and then finally implemented it physically on a Digilent Basys 2 FPGA board.

Acknowledgments

(1)http://www.webopedia.com/TERM/P/parity_checking.html

Posted in Electronic Projects, Electronic Simulation | | 4 Comments

## Design and Simulate a Digital Circuit in NI Multisim and Implement on a Digilent Basys 2 Spartan-3E FPGA Board

Overview

NI Multisim (formerly MultiSIM) is an electronic schematic capture and simulation program which is part of a suite of circuit design programs, along with NI Ultiboard. Multisim is one of the few circuit design programs to employ the original Berkeley SPICE based software simulation. Multisim was originally created by a company named Electronics Workbench, which is now a division of National Instruments. Multisim includes microcontroller simulation (formerly known as MultiMCU), as well as integrated import and export features to the Printed Circuit Board layout software in the suite, NI Ultiboard.

Multisim is widely used in academia and industry for circuits education, electronic schematic design and SPICE simulation. (1)

The Programmable Logic Device (PLD) Schematic in NI Multisim enables students to easily learn digital concepts by using familar digital gate logic to translate boolean logic to symbols/simulation. The PLD schematic can also export and translate digital logic into raw VHDL that can be used to program field-programmable gate array (FPGA) technology used extensively in laboratories to reinforce this theory.

Digilent Inc. is a leading electrical engineering products company serving students, universities, and OEM’s worldwide with technology-based educational design tools.  Digilent offers a wide array of FPGA boards used by educational institutions to help reinforce such theory.

The combination of NI Multisim and Digilent FPGA boards offers now a new and powerful opportunity in quickly implmenting simple to medium sized logic circuits.

Objectives

Show step by step how to desing a digital logic circuit in Multisim, simulate, and for proof of concept export as raw VHDL and with specially developed configuration files that program a Digilent Basys2 Spartan-3E FGPA board.

Pre-Requisites

You must have done or at least browsed  through another two tutorials published here:

https://redacacia.me/2012/07/30/designing-simulating-and-implementing-a-simple-car-alarm-on-a-xilinx-fpga-part-i/

https://redacacia.me/2012/08/01/designing-simulating-and-implementing-a-simple-car-alarm-on-a-xilinx-fpga-part-ii/

Hardware Requirements

Software Requirements

• ISE WebPACK Design Software (available here)
• Xilinx iMPACT 13.x or later, part of the ISE WebPack (link as shown in previous line)

Installation Instructions

• Unzip the file to your local disk.

Two files will unzipped: DigilentBasys2.mspc and DigilentBasys2.ucf.

• Copy and paste the two unzipped files to the pldconfig folder in the main Multisim install directory, by default, this should be:

C:\Program Files\National Instruments\Circuit Design Suite 13.0\pldconfig

In my PC it looks like as show using WinRAR (evaluation copy):

Pressing OK the files will be duly copied.

Design and Simulation

We are going to design a Car Alarm. The alarm circuit will light up a LED (Led_0) on Basys 2 board board only when the key (sw_0) is in the ignition and either the door (sw_1) is open or the seatbelt (sw_2) is not fastened. The variables are:

Key = 0      key is not in the ignition
Key = 1      key is in the ignition
Door = 0    door is open
Door = 1    door is closed
Seat = 0     seat belt is not fastened
Seat = 1     seat belt is fastened
Alarm = 0   alarm is not ON
Alarm = 1   alarm is ON

Hence the Truth table is:

Truth Table of Car Alarm

Where A = Door, B= Key and C = Belt

The Karnaugh map of this Truth table is:

Karnaugh Map of Car Alarm

The resulting Boolean expression is Y = A’B + BC’ which translated into logic circuit is:

We will next simulate and test the Truth table in MultiSim 13.0.

Procedure

• Run Multisim 13.0. Start a new design in menu File ->  New
• Start a new PLD design, selecting File > New

Select PLD Design and click on Create

• This will start the New PLD Design Wizard. By default it will show NI Digital Electronics FPGA Board. In drop down menu we will choose Digilent Basys2.

• Click Next > button. In Step 2 we will give a name to our PLD Schematic. I have called it “myCarAlarm”

• By default Step 2 will show the PLD part number for Basys2. Click Next > button

• Check Led_0, sw_0, sw_1 and sw_2.  and click the Finish button. The reult will be an empty schematic with input and output

We will now use test and measurement tools in Multisim to generate the Boolean expression from Truth table, and then obtain our respective logic circuit.

• Bring into Multisim workspace Logic converter instrument by pressing onto the icon forLogic converter found at instruments’ tool bar on the right side of Multisim worksapce. The image on workspace looks like this:

• Press onto the Logic converter instrument  and you will see the conversion setup.

Fill up the Truth table by pressing onto A, B, and C buttons and change the question marks of results ? into respective 0s or 1s according to the Truth table at the beginnng of this post, and as shown in the image above. Now press the button:

The result will be:

Boolean expression obtained from Truth table

This resulting Boolean expression A’B + BC’ is exactly the same as we obtained manually from Karnaugh map at the beginning of this post.

• We are now ready for the automatic logic conversion offered by Multism 12.0. Press onto the button:

It will result in the same circuit as we have obtained manually at the top of this post from Boolean expression.

• We are now ready to simulate, and test the logic circuit. Bring into Multisim workspace Word generator instrument by pressing onto the icon of Word generator found at the instruments’ tool bar on the right side of Multisim workspace. Connect up the Word generator as shown and place the Probe found at the icons bar below the menu bar at top of the workspace (note the input connectors in image have been moved to order sw_1, sw_0 and sw_2 – sw_0 is Key in our logic):

Press onto Word generator instrument. We will set the right word pattern. Press onto Set button:

Intial window. Press Set.. button to set up

The set up window will open. Change the Buffer size to 0010 and in Preset patterns chooseUp counter:

Press OK button. You will see the following window:

In Controls press Step button and in Display choose Binary. After you have done this, close the Word generator‘s window.

We are ready to simulate. Open the Word generator press onto the Step button and certify that the Truth table we have decided upon earlier is what is seen in the simulation:

As in our original Truth table, the logic circuit will behave as expected and results can be seen step by step on the Probe lighting up or switching off. We are now ready to export the Multisim circuit to VHDL.

• Connect the logic circuit as shown, and remove the Word generator instrument, the Probeas well as any other remnants of our simultaion:

Layout and connections before export to Basys 2 FPGA board

We are ready now to export and program our Basys 2 board. Save the schematic before you do anything else with File > Save

Export the PLD Logic
There are three options for exporting the digital logic from the PLD schematic:
– Programming the connected Hardware – allows students to deploy the digital logic and learn the response of using the hardware.
– Generate a PLD bit file – students can take this away and deploy when they have the hardware available.
– Generate VHDL file – allows students to explore the VHDL behind the logic.

We will focus on programming the connected hardware.

• Make sure that your Basys 2 board is connected to your PC with USB cable that comes with it.
• Select: Transfer » Export to PLD from the menu bar. Here you will see the three export options. We want to export to physical hardware so select Program the Connected PLD.

NOTE: If you are in a different language Windows OS, like I am,  you will need to edit the TEMP and TMP localization in My Computer  -> Properties -> Advanced -> Environment Variables, from %USERPROFILE%\Local definitions to %SYSTEMROOT% to avoid XST Synthesis failure as the command lines of compilation do not accept foreign language characters such as ç, õ and others. Of course you will need to restart your PC, after changing Windows’ Environment Variables.

We want to program the connected PLD. Click Next.

In my environment I have already installed Xilinx ISE Design Suite 14.2. Note that Device Status is not checked. Make sure first of all that Basys 2 board is connected. You may need to install Adept software and make sure that the board is recognised by your PC.

• Click on Refresh button. Multisim will try to detect the Basys 2 board. Note that Multisim 12.0 does not detect the board.

If detected you will see the following reassuring information on this step.

• Now click Next. You will see first of 11 steps that Multisim will go through

If all goes well your Basys 2 board (or any other supported Digilent boards such as Nexys – you will need to install in Multisim the adequate constraints files as you may have done with  Basys 2) , you will see the following reassuring result:

• You are now able to test the logic on Basys 2 using our Truth Table:

A = sw_1, B = sw_0 and C= sw_2. So if you have the key in ignition i.e.  sw_0 = 1, i.e. switch sw_0 is ON (pulled up on Basys 2 board), Alarm (Led_0) will sound (Led_0 will be ON) unless seat belt is fastned and door is closed.

We are now all done! Mission accomplished!

Conclusions

We have shown that one can easily combine Multisim’s industry-standard, best-in-class SPICE simulation environment with Digilent’s technology-based educational design tools such as entry-level Basys 2 FPGA board. Implementing on the board the logic circuit designed in Multisim is now made quite easy as we have learnt.

Resources

(1) http://en.wikipedia.org/wiki/NI_Multisim

Posted in Electronic Projects, Electronic Simulation | | 7 Comments

## Using the Chrome Serial API with chipKIT Digilent UNO32

Introduction

Chrome Packaged Apps are evolving to do more, work seamlessly offline, and give developers more control of their user interface.  New APIs allow applications to access OS-level features: networking, bluetooth, and even serial IO.

Renaun Erickson has shown how to use the Chrome Serial API with Arduino.  One can use the chrome.serial  API (stable since Chrome 23) to read from and write to a device connected to a serial port.

Objectives

Communicate through Chrome serial and html and Javascriot, to read from and write to external hardware, a chipKIT Digilent UNO32 board with Basic I/O shield.

Requirements

– chipKIT Digilent UNO32 development board
– MPIDE software
– Digilent BASIC I/O shield
– Google Chrome browser

MPIDE software for programming chipKIT Digilent UNO32 baord must be installed in your PC. Check previous tutorial on this blog LabVIEW Interface for chipKIT Digilent UNO32 Development Board.

Procedure

a) Install libraries of Basic I/O Shield in MPIDE environment for UNO32 board

On Uno32 you must have Jumpers JP6 and JP8 set in the RG3 and RG2 positions. Install the Basic I/O shield on top of UNO32 as shown on the above image . Connect to the PC with USB cable. USB connection will power UNO32 and the Basic I/O shield simultaneously.

We assume that you have already installed MPIDE environment.

You will need to know the location of MPIDE sketches folder:

Run MPIDE  (in my PC with Windows XP Pro I need to do it with Administrator’s priviledges). In menu do File -> Preferences find the sketchbook location:

Take note of the location of your sketches (MPIDE codes are called “sketches”). In your Windows navigate to where the folder is, and create a directory named ‘Libraries’.

Download from here the zipped file containing libraries and documentation for using the Basic I/O Shield™ with the chipKIT MPIDE and unzip into the Libraries folder you have just created:

Now if you do File -> Examples you will see three folders IOShieldEEPROM, IOShieldOled and IOShieldTemp. Open the sketch IOShieldTemp_Demo:

Next choose the board (in our case UNO32):

And Serial Port to which the board is connected:

To be sure of what you are doing, I advise that you read my previous tutorial here in this blog  LabVIEW Interface for chipKIT Digilent UNO32 Development Board.

Now we are ready to upload the sketch to the board. Click the Upload button  on MPIDE environment.

If successful you will see the following results at bottom of MPIDE environment:

We are now ready to check what is being sent to our COM21 port (your PC’s may be other) in Tools -> Serial Monitor:

A new window will pop up showing the readings sent to our PC’s serial port:

We are  getting readings in ºC and ºF. If you are here the rest will go smoothly.

We will later change this sketch and adapt it to chrome.serial.

In order not to prolong a lot this tutorial, I have made available for download from free repository for private use Bitbucketv all that is required for next stage . So download the zipped file from this link.

Unzip the file into a conveniente directory may be named chipkit that you may create in your C:\ or D:\ or other drive.

c) Install sketch in UNO32

Open the sketch you have just downloaded in your MPIDE environment doing File -> Open and navigating where the directory chrome-serial-chipkit-uno32 is.

Check the sub-directory IOShield_Chrome_Temp and open IOShield_Chrome_Temp.pde.

Upload this sketch to UNO32 clicking on Upload button .

If uploaded correctly you will be greeting with following message at bottom of your MPIDE environment:

Close MPIDE environment in order to release the port of your PC.

d) Install Google App

We will install the app as extension in Google Chrome.

First enable the experimental API in your browser.

Go to Chrome://flags, find “Experimental Extension APIs”, click its “Enable” link, and restart Chrome. From now on, unless you return to that page and disable experimental APIs, you’ll be able to run extensions and apps that use experimental APIs.

Our App is an experimental app.  Go to chrome://extensions then click “Load unpacked extension…”.

Then navisgate where the folder you donwloaded is and choose the folder:

Click OK.  Next on Launch “Chrome UNO32 Temperature” to get it working (in Portuguese it is “Iniciar”):

You will be greated with the Crome App:

Choose the correct port. In our case it is Port21.

Immediately you will be greeted (provided port of your PC is released) with blinking simulated LED and reading of temperature from chipKIT Digilent UNO32:

You can play with the App moving the slider and seeing the reduction of frequency of blinking LED (simulated on App and in real life on Basic I/O shield on UNO32.

If you restart your Chrome browser you will be greeted with the App which you can start directly clicking on to it:

A demo video I have uploaded to Youtube shows this Chrome App working:

Conclusions

Chrome can talk to external hardware and thus offers enormous potentiality towards future apps. The combination of Chrome (with serial API since Chrome 23), Javascript and easy to program UNO32 development board can be awesome. We can next add graphic presentation of temperature (with many Javascript gauges that are already available), add database, voice commands and responses, and why not Cloud logging and display with many services like Exosite.

Posted in Electronic Projects | | 2 Comments

## Remote Viewing with NI LabVIEW, Digilent UNO32 and Basic I/O Shield

Introduction

NI LabVIEW and chipKIT Digilent UNO32 are powerful tools that offer enormous potentialities. Remote monitoring and webserver capabilites of LabVIEW  further enhance our projects.

It has been shown here in this blog that NI LabVIEW can be easily connected to chipKIT Digilent UNO32 board with two step-by-step tutorials
LabVIEW and VISA interface, with chipKIT Digilent UNO32 and Basic I/O Shield and
LabVIEW Interface for chipKIT Digilent UNO32 Development Board.

A further enhancement with bluetooth monitoring and Webserver for remote viewing is an interesting proposition that will dwell upon here.

Pre-Requirements

It is advisable and necessary to carry out both of tutorials on LabVIEW and UNO32 found here in this blog:

Requirements

– chipKIT Digilent UNO32 development board
Power supply for UNO32
– MPIDE software
– Digilent BASIC I/O shield
– LabVIEW software and VISA drivers
– Class I or II Bluetooth adapter
– JY-MCU Bluetooth Module (available from ebay)

Precedures

1 – Preparing our setup

Connect JY-MCU as shown:

UNO32 must be connected to an adequate external power supply (my highly stable power supply is set 7,5V dc). Once UNO32 is powered will see a blue LED blinking on your JY-MCU module.

Basic I/O shield must be installed on top of UNO32. Check the tutorial here in this blog LabVIEW and VISA interface, with chipKIT Digilent UNO32 and Basic I/O Shield for setting up the LabVIEW, VISA and installing firmware in UNO32 with MPIDE environment.

2 – Bluetooth installation in your PC

You must have your bluetooth adapter duly installed in your PC. My Sweex adapter shows in my PC’s 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 linvor (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 COM4):

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 linvor connection changing to green.

3) Running our VI

We are ready to run our IOShield_LV_Temp.vi. You can download it from free repository Bitbucket, by clicking on the link IOShield_LV_Temp.zip.  The zip file you will download contains the VI we wrote in previous tutorials.

Set the port to your bluetooth module’s (in my set up it is COM4).

Run the VI clicking on button

If everything is right, you will see temperature being displayed on your VI’s Front Panel read by UNO32 from the temperature sensor on Basic I/O shield:

You can view the VI being run, with Ctrl + E in your keyboard.

In Block Diagram click on Highligh Execution button . It will show you the VI being run in slow motion, and any errors that may occur for debugging purposes.

4) Web publishing VI

In LabVIEW Front Panel do Tools -> Web Publishing Tool:

Next in Web Publsihing Tool select the VI:

Select Monitor and change the number fo snapshots to every 5 seconds:

Clich Next button

Now personalize your Webpage as shown (with your description)

Click Next button.

Here leave the default location as it is, but change the file name to index (by default it will be IOShield_LV_temp).

Click Save to Disk button.

Press OK button on Document URL pop up window.  Web Publishing Tool will close.

You can now access the webpage in your favourite browser, writing the URL http://localhost:8000 :

If for any reason, the webserver does not start automatically, do Tools -> Web Publishing Tool,  and then click Start Web Server button.

You can watch a demo video on Youtube:

Conclusions

We have achieved remote temperature viewing of temperature read by our chipKT Digilent UNO32 from the temperature sensor on Basic I/O shield.  LabVIEW is now publishing a Webpage of the fornt Panel of VI that can be accessed from outside by doing Port forward in one’s router.

We have shown again the potentialities of LabVIEW and chipKIT UNO32 development board.

For further reading I suggest you visit NI’s website.

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

Posted in Electronic Projects, Programming | | 6 Comments

## LabVIEW and VISA interface, with chipKIT Digilent UNO32 and Basic I/O Shield

Introduction

NI LabVIEW can communicate with external devices such as microcontrollers through VISA a standard I/O language for instrumentation programming.

LabVIEW ties the creation of user interfaces (called Front Panels) into the development cycle. A key feature of LabVIEW over other development environments is the extensive support for accessing instrumentation hardware.

Objectives

Write step by step a simple serial read VI that can communicate with chipKIT Digilent UNO32 and Basic I/O shield, and serial read  values processed in UNO32 and display  these on LabVIEW’s front panel.

Requirements

– chipKIT Digilent UNO32 development board
MPIDE software
– Digilent BASIC I/O shield
LabVIEW software and VISA drivers

Your LabVIEW software and VISA and drivers as well as MPIDE software for programming chipKIT Digilent UNO32 baord must be installed in your PC. Check previous tutorial on this blog LabVIEW Interface for chipKIT Digilent UNO32 Development Board.

Procedure

a) Install libraries of Basic I/O Shield in MPIDE environment for UNO32 board

On Uno32 you must have Jumpers JP6 and JP8 set in the RG3 and RG2 positions. Install the Basic I/O shield on top of UNO32 as shown on the above image . Connect to the PC with USB cable. USB connection will power UNO32 and the Basic I/O shield simultaneously.

We assume that you have already installed MPIDE environment.

You will need to know the location of MPIDE sketches folder:

Run MPIDE  (in my PC with Windows XP Pro I need to do it with Administrator’s priviledges). In menu do File -> Preferences find the sketchbook location:

Take note of the location of your sketches (MPIDE codes are called “sketches”). In your Windows navigate to where the folder is, and create a directory named ‘Libraries’.

Download from here the zipped file containing libraries and documentation for using the Basic I/O Shield™ with the chipKIT MPIDE and unzip into the Libraries folder you have just created:

Now if you do File -> Examples you will see three folders IOShieldEEPROM, IOShieldOled and IOShieldTemp. Open the sketch IOShieldTemp_Demo:

Next choose the board (in our case UNO32):

And Serial Port to which the board is connected:

To be sure of what you are doing, I advise that you read my previous tutorial here in this blog  LabVIEW Interface for chipKIT Digilent UNO32 Development Board.

Now we are ready to upload the sketch to the board. Click the Upload button on MPIDE environment.

If successful you will see the following results at bottom of MPIDE environment:

We are now ready to check what is being sent to our COM21 port (your PC’s may be other) in Tools -> Serial Monitor:

A new window will pop up showing the readings sent to our PC’s serial port:

We are  getting readings in ºC and ºF.

We will need now to modify our code in order to allow easy manipulations by LabVIEW communicating with micrcontroller through VISA.

Find //Print Temperature to serial port in IOShieldTemp_Demo sketch and substitute everyting up to delay(1000);  with the following code:

Serial.print(tempC);
Serial.print(",");
Serial.print(tempF);
Serial.print(",");
Serial.println("");


So the code with void loop will now look like as shown:

void loop()
{
float tempF, tempC;

//Get Temperature in Celsius.
tempC = IOShieldTemp.getTemp();

// Convert the result to Fahrenheit.
tempF = IOShieldTemp.convCtoF(tempC);

//Print Temperature to serial port
Serial.print(tempC);
Serial.print(",");
Serial.print(tempF);
Serial.print(",");
Serial.println("");
delay(1000);
}


We check again what is being sent by RS232 in Tools -> Serial Monitor:

The readings now are in a convenient format for LabVIEW hopefully. Exit MPIDE environment in order to free the serial port.

b) Write VI in LabVIEW to read the values of temperature processed by UNO32

You need to have VISA and LabVIEW installed in your PC.  I advise you to read my previous post in this blog LabVIEW Interface for chipKIT Digilent UNO32 Development Board.

Launch LabVIEW (my licensed version is LabVIEW 2010). Search for basic serial write and read.vi

And download it to a convenient directory, and run it by opening with LabVIEW.

Press Ctrl + E in your PC’s keyboard to get into Block Diagram of LabVIEW’s VI, and identify two Case Structures as shown:

Add While Do structure around them:

Next, delete the Write bytes to port loop and make adjustments to get the following result:

We are now ready to run the VI and see what we get. View the Front Panel and choose the right port of communication which in our case is COM21 :

Once port is selected Run the V,I clicking on the button Run

You will see immediately that some results are appearing on the Front Panel’s read string field. If you change bytes to read to 14 you will see immediately at least one line of readings:

You may get some inconsistencies in reading but this will be sorted out next.

We will now go back to the Block Diagram and make changes to get the right readings for later manipulation.

We will add character termination ‘\n’ to our VISA configuration, selecting it first:

And then with right button of your mouse create a constant on VISA serial:

The constant assumed will be ‘\n’ i.e. line return which in decimal is number 10.

Now we are ready to go back to Front Panel and Run the VI. The results will be not very consistent. Change bytes to read to 20 and bingo you will get a line of clear readings:

You can play with Basic I/O shield to check if readings are coming from the sensor. Place a finger on the sensor, and temperature reading will approximate to those of your body temperature:

It is fair to ask that you need save the VI, perhaps with a new name such as basic_serial_read.vi

Create a Flat Sequence within the Case Structure as shown bringing the read string within it:

Now right-click inside this loop and search palette ‘scan string’:

And select ‘Scan From String’:

And place it on Block Diagram as shown:

Now we will split the string to get both readings we are obtaining from UNO32 as shown:

The constant ‘%[^,]’ will split the first reading wich we can then display:

By now surely you know how to create Constant and Indicator (tip: point with mouse at the connection and right click your mouse and in the menu choose Create whatever you wanto to do).

We will now obtain the rest of string adding again the decimal string pallete and as shown we will need to add one more constant to let the second Scan palette know where the second part of the string is which will be after comma ‘,’ which in fact is the first character:

So we add constant 1:

Edit ‘output1’ to ‘Temp. ºC” and ‘output2’ to ‘Temp. ºF’.

Finally we will do only one last thing that will fix bytes to read to 20, so that we do not need to change this value on the Front Panel everytime we reinitiate our VI.

We will delete bytes to read control and replace with constant with number 20 in it:

Make sure the Front Panel looks a bit like the following image:

Make sure you have save your VI. Now after setting the port, run the VI.  You will see results as shown:

We are almost finished with our work. We will show a graphic display of centigrade temperature (there is more room for improvement but we will point these out when concluding).

In Front Panel place Thermometer’ found in Numeric Indicator set by right-clicking with mouse:

Thermometer reads numbers and not strings. So in our Block Diagram we need to place ‘decimal string’ palette. Do a search for it:

Choose ‘Decimal String to Number’  and place it as shown next to Thermometer:

Now if you go back to the Front Panel and Run the VI you will see the thermometer displaying the value read in centigrades:

Now in Block Diagram we will first change the description ‘Visa rsource name’ to ‘Port Number’:

And we will hide all other resources that are not needed on Front Panel, such as ‘baud rate’ etc., leaving out ‘Port Number’ that we may need to set:

So the final Front Panel should look like the following image shows:

Save the final work as IOShield_LV_Temp.vi.

Run VI and I think you should see something like the following image:

On the Block Diagram you can click the Highlight Execution button

You can see in slow motion the running of VI.

You can download IOShield_LV_Temp.zip at free repository Bitbucket The zip file  contains the VI we have just written

You may watch a video on this project at Youtube:

Conclusions

My main aim was to demonstrate that one can combine two powerful tools at disposal of engineers and students: LabVIEW and chipKIT Digilent UNO32.

There is room for improvement with UI (user interface) and to turn this project into full PID control.  Also the LabVIEW VI can have more controls to cater for errors, and other situations such as Alarms.

I will appreciate any comments on the project, specially if there are any errors.

Posted in Electronic Projects, Programming | | 5 Comments

## LabVIEW Interface for chipKIT Digilent UNO32 Development Board

Introduction

The chipKIT development platform with prototyping-friendly 32-bit MCU packages (based on PIC32 microcontrollers) from Microchip is an open-source hardware and software solution intended for beginners and users with little or no knowledge of embedded controllers wanting to explore embedded applications.

The chipKIT environment advances the art of open-source, physical computing by expanding support to more chip platforms and introducing new, high-performance libraries. It combines low-cost hardware with free software that is fast, powerful, and extendable. Inspired by Arduino™, chipKIT controller boards and software tools are easy to use by beginners of any age and specialists in any field. These boards and tools are compatible with the standards established for the hobbyist community and also offer a clear migration path to professional-grade tools for experienced engineers(1)

Most recently LabVIEW Interface for ChipKit has been made available.  The LabVIEW Interface for ChipKit (LIFCK) Toolkit is a FREE download that allows users to acquire data from a ChipKit development platform and process it in the LabVIEW Graphical Programming environment. LabVIEW (short for Laboratory Virtual Instrument Engineering Workbench) is a system-design platform and development environment for a visual programming language from NI (National Instruments). The graphical language is named “G” (not to be confused with G-code). Originally released for the Apple Macintosh in 1986, LabVIEW is commonly used for data acquisitioninstrument control, and industrial automation on a variety of platforms including Microsoft Windows, various versions of UNIXLinux, and Mac OS X. The latest version of LabVIEW is LabVIEW 2013. (2)

Objectives

Install the required hardware and software to interface NI’s LabVIEW to Digilent’s chipKIT UNO32 board,  and test an application that blinks a LED.

Requirements

– Digilent UNO 32 Development Board

MPIDE software
LabVIEW 2013 software

NOTE: If you do not own a copy of LabVIEW, you can download a non-commercial student license and request usage for 6 months.

A free, 45 day evaluation of LabVIEW is available at ni.com/trylabview. You are required to obtain a NI user profile to extend the 7-day evaluation to 45-days!

Procedure

1) chipKIT running on Windows

The fundamental steps to get chipKIT running on a PC are:

The MPIDE programming software can be dowloaded from chipKIT’s website. It is a zipped file that you can unzip to a location on your hard drive say C:\chipkit. You will end up with following file structure:

b) Connect UNO32 board

Connect the USB cable to one of the PC’s USB ports and then to the mini-A USB connector of UNO32. UNO32 can be powered via USB connection, or with an external power supply.  The power source is selected automatically by sensing circuitry on the board. So for this set up we will not need external power supply as UNO32 will be powered from USB port of your PC.

c) Install the USB drivers

The installation procedure will depend on the OS of your PC. UNO32 use a FTDI USB interface chip. Your OS should detect the device once it is connected:

If you allow Windows to search online, it should locate the driver and install it properly. Nevertheless if you do not want to risk you can install the drivers from the folder of MPIDE. Within drivers sub-folder you will find FTDI USB Drivers:

Alternatively drivers can be downloaded here on FTDI’s website. Once the driver is installed check in Definitions -> Control Panel -> System -> Hardware -> Device Management -> Ports (COM and LPT) and check the port number of your USB connection. In my case it is port 21:

d) Run MPIDE

Now we are ready to run MPIDE programming environment. In your chipKIT folder you will find the MPIDE icon. Click the icon (in my Windows XP  set up I have to start the program as Administrator, so you may have to do the same):

When it is launched you will see the following screen:

In Tools -> Board choose chipKIT UNO32:

Next again in Tools -> Serial Port choose the serial port where your USB connection is made (in my set up is port 21):

The codes for UNO32 are called sketches. The word “sketch” is inherited from Processing an open source programming language.

The Processing project was initiated in 2001 by Casey Reas and Benjamin Fry, both formerly of the Aesthetics and Computation Group at the MIT Media Lab. One of the stated aims of Processing is to act as a tool to get non-programmers started with programming, through the instant gratification of visual feedback. The language builds on the Java language, but uses a simplified syntax and graphics programming model.

Many example sketches are included with the MPIDE environment. We will blink a LED, so we will choose in File -> Sketchbook -> Examples -> Basics -> Blink:

As you will note the syntax is quite simple in MPIDE environment. If you are familiar Arduino Processing environment you will note they are the same.

e) Run the Blink sketch on UNO32

Click the “Upload” button in your MPIDE environment as shown:

If everything is OK, you will see that the sketch is uploaded into UNO32:

If it is successully uploaded in your MPIDE environment you will see “Done Uploading”:

And after few seconds you will see the green LED on your UNO32 blinking every one second.

You have successfully programmed UNO32! At this stage it is quite convenient, for learning purposes, to register yourself in ChipKIT forums, and to check around.

2) LabVIEW environment

This is your development environment where you will write your computer program to control the chipKIT device UNO32.

a) Install Labview 2013 and NI-VISA

Download and install LabVIEW 2013 if you do not have it already.

Next install NI-VISA device driver. This is a library of functions that enable LabVIEW to send and receive commands for various communication protocols such as RS-232 and IEEE488.2. VISA drivers are free for use and can be downloaded from ni.com/drivers.

If you have doubts, please check the NI website and follow instructions.  Installing Labview and drivers is quite an easy process!

b) Install JKI’s VI Package Manager

JKI is a NI Alliance Partner (jist like my company Aliatron is) and is an integrator of NI solutions. The Package Manager will allow you to install the LabVIEW interface for chipKIT add-on with all functions, examples and help files. Download JKI’s VI Package Manager and install it by clicking on the JKI’s icon in your PC’s folder where you have downloaded it.

c) Install LabVIEW interface for chipKIT

This is an API (set of functions) that allow LabVIEW to control and communicate with the chipkit UNO32 board. It is a free tool that for download on the Labview interface for chipKIT community.  Current release is 1.0.0.8. Click on the icon:

And JKI’s VI Package Manager will open inviting you to install the LabVIEW interface:

Once installed you will see the following re-assuring screen:

Click Show Examples button. And choose “chipKIT Blink (digital Write).vi” clicking on the icon.

Check if your UNO32 is connected to PC with USB cable.

LabVIEW will open with the launched VI. Change the chipKIT setting as shown in red box of the image:

Now Run the VI clicking the run botton . After few seconds an error will occur:

As the pop up indicates our UNO32 has not the latest firmware. In fact it has no firmware to communicate with LabVIEW. The firmware is found in LabVIEW folder in vi.lib\LabVIEW Interface for Chipkit\Firmware\Chipkit.

d) Deploy LabVIEW interface for chipKIT firmware (LIFCK)

Launch MPIDE environment as before.

After doing File-> Open, navigate to C:\Program Files\National Instruments\LabVIEW2013\vi.lib\LabVIEW Interface for ChipKit\Firmware\ChipKit\LIFCK_uC32 and choose LIFCK_uC32.pde sketch as shown:

Note: You may need to teak again  in Tools the Board and Serial Port number.

Once the fimware is loaded, click on Upload to board button

The firmware sketch will be uploaded to UNO32 board, and if everything goes well the result will be “Done uploading”:

The green LED on the board will now be permanently ON.

NOTE: The firmware for uC32 (another chipKIT board from Digilent) is same as for UNO32 board.

3) Run blinking VI in LabVIEW

Exit MPIDE environment, and launch LabVIEW 2013 again. Choose the VI as shown which should be now in LabVIEW screen:

Change the chipKIT setting as shown in red box of the image:

The port number will be the one found in your PC as shown earlier.

Now Run the VI clicking the run botton . After few seconds you will see the green LED on UNO32 blinking once every second.

In Tools choose Block Diagram. This will show the graphic components of LabVIEW.

NOTE: You will see a set up of how to connect UNO32 board in LabVIEW’s Block Diagram of a breadboard plus resistor and LED. In fact for this tutorial purpose, you do not need to connect to external LED on a breadboard, as the green LED on UNO32 is connected to port 13 andl LabVIEW sends the digital command to port 13:

Digilent offers many connectivity solutions including a quite interesting board Basic I/O Shield for UNO32:

I/O shield on top of UNO32 board

Also, if you want to write the VI we have used, there is an excellent step by step tutorial at https://decibel.ni.com/content/docs/DOC-29229

Watch our uploaded video on Youtube, showing the Digilent UNO32 board being controlled by LabVIEW:

And also watch video showing Digilent UNO32 board and Basic I/O shield and blinking of LED on port 29:

Resources

1) NI Community: https://decibel.ni.com/content/groups/labview-interface-for-chipkit
2) Digilent UNO32: http://www.digilentinc.com/Products/Detail.cfm?Prod=CHIPKIT-UNO32
3) Digilent Basic I/O Shield: http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,719,935&Prod=CHIPKIT-BASIC-IO-SHIELD

Conclusions

We have shown how to interface LabVIEW to chipKIT Digilent UNO32 development board. This solution of interfacing LabVIEW offers enormous potentiaties for projects. Though we did very little extra work (we based on already existing work), the idea behind this tutorial is to show how easy it is for LabVIEW to communicate with chipKIT devices. Check here in this blog other tutorials for LabVIEW that may interest you.

Posted in Electronic Projects, Programming | | 13 Comments

## Ethernet Relay Control with Blackberry Playbook

Introduction
Nowadays it is quite easy to implement Ethernet relay control of devices connected to a 10/100 network. An Ethernet relay board connects to the ethernet port of your local network hub, allowing controlled switching from anywhere on the network.

Requirements
– Blackberry Playbook
– 12V@500mA power supply
ETH-RLY02 board

Overview
The ETH-RLY02 provides two volt free contact relay outputs with a current rating of up to 16Amp each. The module is powered from a 12vdc supply which can be regulated or unregulated. The DC input jack is 2.1mm with positive core polarity, DC supplies are required to supply at least 500mA at 12vdc. The relays are SPCO (Single Pole Change Over) types. The normally open, normally closed and common pins are all available on the screw terminals.

Testing the ETH-RLY02 board

You will be greeted with the following page:

You can immediately test the board. Switch the relays ON and OFF by clicking the relay buttons (the red/gray circles). You can hear the click of relay switching ON or OFF. The following image shows that Relay1 has been switched ON:

This page also contains a link to Technical Documentation page and to Configuration. Click Configuration link, and you will see the following page:

Take note of board’s IP (here in my example is 192.168.1.82) and Port number (here is 17494). You will need these values in following next steps.

Installing the Playbook App
Our Playbook App is based on Android App. You can download the Playbook App from Bitbucket, an unlimited free private repositories’ site. I have converted the available app fron Android apk to Playbook bar.

You will need to sideload this App in your Playbook. For doing that, you need to enable Development Mode in your Playbook.

Enable your Playbook in Development Mode in Security > Development Mode from system preferences, and you will need to remember password which I suggest to be as simple as 123.

For Development Mode on your device, go to Security > Development Mode from system preferences. And set it ON. The following image shows Development Mode is OFF. Click the button to put it ON.

To sideload our App, we will use the easiest way of doing it, with the DDPB Installer. This small app lets you connect to your PlayBook, and install BAR files with just a few simple steps.

The installer has been updated with bug fixes and some other tweaks and now rests at version 1.0.9. The free utility is available for Windows from here.

Connect your PC to your Playbook with USB cable. Make sure Wifi of you Playbook is OFF. Run DDPB,and you will be greeted with following screen.

Add the bar file, you have just downloaded, by clicking the Add (A) button on top left of Installer, and click on the square next to app’s name, and the result will be as shown in the following image:

Now Scan to find the Playbook, clicking on Scan button on the left side of the Installer. Your Playbook’s IP will be found. Add Password you chose for Development Mode (I suggested before to be 123). Click the button Connect (C) and DDPB Installer will connect to your Playbook, and the result will be as shown:

I have blurred my Playbook’s PIN.  Now you are ready to install the App. Click the button Install (I) and you will get a reassuring pop up saying that installation is completed.

Testing our Set up
Now check your Playbook and see if the App is installed. The folowing image shows Relay Network app duly installed at bottom right:

Our App’s name is Relay Network as I have already indicated. Click the app’s icon. You will see the following first screen:

Accept the EULA Agremeent. Now you will see the following:

Click the button OK.

We will give the name Workshop to our Module. Click OK. We will now introduce the IP/DNS Address of our board. Ths was obtained when we tested the board in our PC.

Click OK. We will use default names Relay1 and Relay2. You can give the names you want for example “AC”, “Lights” etc. So now if we run our App and we will be greeted with:

Click Workshop button and you will see two large buttons:

I have already pressed button Relay1 (the color changed to pink from grey). When you click any of the buttons, you will hear the clicking of Relay1 or Relay2 switching on or off.

There are screw terminals on the board where you can connect your external devices that you want to switch ON or OFF.

Caution: Do not connect any device to the ETH-RLY02 board if you do not what you are doing. Please check the circuit diagram, and right connections form Robot Electronics’ website.

Acknowledgements
A special thank you is due to Robot Electronics for the Relay Network board ETH-RLY02, and their excellent technical information for the board. My company ALIATRON sells two ETH boards.

Also I want to thank Louis Keeper for his DDPB Installer that facilitates installion of bar apps for Playbook.

A word of gratitude is due to Bitbucket for their free and unlimited repository where our App is lodged for download.

Finally and foremost a thank you also to owners of free online Playbook apk to .bar converter service, where I converted Robot Electronics’ Android apk to Playbook bar.

Conclusions
We have shown how easy it is to use Blackberry Playbook to control external devices. There is ground for improvement using ideas on the Robot Electronics’ website, such as fixing IP address of ETH-RLY02 board, controlling from outside theough Internet etc.

I will gratedul for any feedback from visitors, and anyone that implements this project, or makes any modifications.

## Writing a “Resistor Code” App for Blackberry Smartphones

Introduction

I have shown in my previous post Writing a “Resistor Code” App for Blackberry Playbook that it is quite easy to design apps for Playbook. That said, it is quite easy also to design apps for Blackberry smartphones, with recourse to Blackberry WebWorks.

So what’s Webworks?  When you hear the words Blackberry WebWorks, think HTML5, JavaScript, and CSS. Essentially, a BlackBerry WebWorks application is a web application that runs on a BlackBerry smartphone or a BlackBerry PlayBook tablet.

BlackBerry WebWorks is an open source project that you can find on GitHub. Be sure to check out some of the BlackBerry WebWorks Samples.

Why create a BlackBerry WebWorks app? Some reasons to consider are:

• portability
• integration with core BlackBerry apps
• ease of access, even when users do not have an Internet connection available(3)

Requirements

The creating of Blackberry packages is done with not many external requirements. However, you need to use external tools in order to generate signing and debugging assets required to put deployments onto device.

Setting-up a Development Machine for Blackbber Deployment

Blackberry Web Works SDK must be installed in order to obtain various tools required for obtaining certificates and device provisioning.

1. Follow the instructions at https://bdsc.webapps.blackberry.com/native/ to download the SDK and any additional tools listed on the page.
2. Install the SDK to your development machine.

I assume that you have the Development Machine ready by now as you proceed to next steps. If not, I recommend you set up the Development Machine before proceeding.

Code-Signing Keys

We will start by requesting a code-signing keys at https://www.blackberry.com/SignedKeys/. They are absolutely free!

Enter your name, company, email, country and a 6-10 digit “PIN.” Take note of the PIN since you will need it in next steps. I suggest you write down in a file named says “keys.txt” in a folder say named “BB”.

RIM will tell you to allow up to two hours in order to receive your code-signing keys by email.

When you are registered you will receive code-signing keys.  You will receive 3 csi extension files with words like RBB, RCR and RRT. Copy then all to the folder you have created for keys. We suggested to be “BB” as the paragraph before last says.

Now we can associate our own password with each of the code-signing keys.  Enter into command-line of your PC , writing in your PC’s window in Start -> Run the command cmd/k

A full listing of DOS commands can be found at Wikipedia.

Next, in Command-line Terminal navigate to your Program Files with following:

bcd C:\Program Files\Research In Motion\BlackBerry WebWorks SDK 2.3.1.5\bin

If you know how to deal with DOS (check in previous paragraph Wikipedia’s link to learn about DOS commands) you can get there step by step. I advise you at this juncture revise DOS commands.

java -jar SignatureTool.jar c:\bb\(your RBB csi file)

In my PC I did the following:

Note that SignatureTool started immediately and a popup window will open asking to generate a new set of signing keys in case you do not have these yet:

Press Yes button in next popup write your password. Take note of this password, and keep it safe. You will require this password in next steps, and in the future.

A new popup will invite you to write the PIN and the password. These are the PIN you selected when you requested your signing keys and the password you have just created:

Next run again the command changing the name to RCR file:

java -jar SignatureTool.jar c:\bb\(your RCR csi file)

The same type of popup will invite you to write your PIN and password as you did before.

Repeat the same procedure with RRT csi file. If you have done all the signings and got reassuring popup windows telling you that you have registered and have also received email from websigner at Blackberry that you have successfully registered your keys you are ready to compile your App.
Preparing our App

We are now ready for our App. Our App will be a “Resistor Code Calculator” based on Danny Goodman’s quite old, and still popular, “Graphical Resistance Calculator”. You can view and play with the Resistance Calculator visiting Danny’s web application at:

http://www.dannyg.com/examples/res2/resistor.htm

I am proud owner of Javascript Bible that I bought many years ago from Amazon. Danny Goodman has authorised me to use his Javascript code to design our Blackberry Playbook App. The code we are using is quite old as old as my Javascript book. I don’t think the Javascript code has changed much, perhaps it has been fine tuned only.

In order not to reinvent the wheel, you will accept my zipped file “rescolbb.zip”  which you can download from Bitbucket, an unlimited free private repositories’ site.

Unzip the contents of zipped file. You will need an unzipper program perhaps. And now view the webpage (use Google’s Chrome as you will need it next). We are going to use the web app in the file to make our Playbook App.

You will notice there is a config.xml file in unzipped contents you have just downloaded. This file is required to compile our App.

You can preview how our App will look like on Playbook, by installing Chrome’s “Ripple” plugin. You can read about how to install it in Blackberry’s Developper pages.

When enabled “Ripple” runs a web server on port 9910 of your computer. You will need to tweak Ripple in Chrome’s extensions (you can access “extensions” directly with pointing the Chrome browser to chrome://extensions). As shown in following image (in Portuguese, but I think it will be something similar in English) we have tweaked Ripple to view your PC’s URLs:

Now open index.html in Chrome. In first run time of Ripple, after enabling, it will be asking you the platform you want to run the page. Choose WebWorks (2.0.0).:

Having chosend WebWorks (2.0.0) you will be next greeted with following as shown in the image:

The left and right popups will allow you to configure your environment. I did nothing of that sort, as I was unable to start Ripple services due to problems with portuguese language characters in my Windows. I suggest you close the popups, pressing with the mouse onto two little arrows on top, pointing to left and right. You can zoom to view, within Chrome’s personalization (surely you know to do it!), and you will see our App in a simulated Blackberry smartphone:

Compiling our App

We will next compile our zipped file (you just downloaded). If you have made any modifications to extracted files you will need to create a zipped file, that is if you want to implement your modded webpage.

So let us compile rescolbb.zip and output as install cod files. Return to DOS terminal as shown previously, and to directory where bbwp is, with the following DOS command:

cd C:\Program Files\Research In Motion\BlackBerry WebWorks SDK 2.3.1.5

To make it easy, create in C:\ a directory say myapp.  Drop rescolor.zip file into myapp directory (or one that you have modded) and run the DOS command:

bbwp c:\myapp\rescolbb.zip -g (password) -o c:\myapp\output

Your signing may hang up as it was happening to me until I found on the Web that there are problems with sigining with jdk1.7.x so pointed my browser to Oracle’s jdk-6’s googling for it-And downloaded jdk-6u35-windows-i586.exe and installed on my PC. Next I edited bbwp.properties found in bin folder of our WebWorks folder changing the jdk’s path as shown:

Now if we compile again with the same command:

java -jar bbwp.jar c:\myapp\rescolbb.zip -g (password) -o c:\myapp\output

We will compile and output folder will be created automatically . In my system I have rescolbb.zip in bb folder. The following image shows the successful compilation:

I have blurred my password and output is rescolbb_signed folder that was created automatically. Checking the output folder we will find there two folders OTAInstall and StandardInstall:

If you wonder why we took the trouble of signing our App is that otherwise our App will not work once installed in our Blackberry with an error like “Error starting AppName Module ‘AppName’ attempts to access a secure API”.

Installing our App

I assume you have Blackberry Desktop Software installed in your PC. You will need to connect your smartphone to your PC with an USB cable. You will need StandardInstall where your COD and ALX files are.

The following video shows how simple is to install your App:

You have to be patient and waith for your Blackberry to re-initiate. It may take a while.

Once installation is complete you will find the Resistor Code icon as shown in following screen capture of my Blackberry smartphone:

Run the App and you will see the following screen:
If you have reached this stage of the tutorial with success, congratulations! That is it. You can tweak the color bands of the resistor and see the corresponding values.

Acknowledgements

Credits are due to Blackberry for providing so much valuable and free information on the Web. A special thank you is also due to Danny Goodman for his “Graphical Resistance Calculator” web application which has served to design our App.  Once more  I thank Bitbucket for providing me a free of charge repository from where rescolbb.zip can be downloaded.

Conclusions

As you have already seen, and tried (I trust) it is quite easy to write, and to deploy a webpage in a Blacberry as an App. You can even deploy a web link as can be seen in this App we have just designed which will open webpages within the App.  The links at the bottom open Redacacia blog (this actual blog where you are!) and Danny Goodman’s webpage. If you have a “killer” webpage that you have written in Javascript, I bet you can deploy it as an App. As I wrote before in my Playbook tutorial, in order to deploy in Blackberry App World Store, and to monetize with it, you will need to sign your App to make it publicly available, and you will have to take into consideration more issues surely.

Posted in Mobile Apps, Programming | | Leave a comment

## Writing a “Resistor Code” App for Blackberry Playbook

The PlayBook, as it is known Blackberry’s tablet,  is the first device to run Blackberry Tablet OS, based on QNX Neutrino, and runs apps developed using Adobe AIR. It was later announced that the Blackberry Tablet OS would be merged with the existing Blackberry OS to produce a new operating system, Blackberry 10, that would be used universally across BlackBerry’s product line. A second major revision to the Blackberry PlayBook OS was released in February 2012.[3] The Playbook also supports Android OS applications, allowing them to be sold and installed through the Blackberry App World store (1).

Introduction

It is quite easy to design apps for Playbook, with recourse to Blackberry’s WebWorks SDK. Blackberry WebWorks for Tablet OS as the name “WebWorks” implies, is a platform for building deeply integrated web applications for the Blackberry PlayBook http://us.blackberry.com/developers/tablet/webworks.jsp. We are going to design a “Resistor Code” App with Blackberry WebWorks SDK.

What’s a Resistor?

resistor is a passive two-terminal electrical component that implements electrical resistance as a circuit element.

The current through a resistor is in direct proportion to the voltage across the resistor’s terminals. This relationship is represented by Ohm’s law:

where I is the current through the conductor in units of amperesV is the potential difference measured across the conductor in units of volts, and Ris the resistance of the conductor in units of ohms.

The ratio of the voltage applied across a resistor’s terminals to the intensity of current in the circuit is called its resistance, and this can be assumed to be a constant (independent of the voltage) for ordinary resistors working within their ratings.

Resistors are common elements of electrical networks and electronic circuits and are ubiquitous in electronic equipment. Practical resistors can be made of various compounds and films, as well as resistance wire (wire made of a high-resistivity alloy, such as nickel-chrome). Resistors are also implemented within integrated circuits, particularly analog devices, and can also be integrated into hybrid and printed circuits.

The electrical functionality of a resistor is specified by its resistance: common commercial resistors are manufactured over a range of more than nine orders of magnitude. When specifying that resistance in an electronic design, the required precision of the resistance may require attention to the manufacturing tolerance of the chosen resistor, according to its specific application.(2)

What’s Color Code of a Resistor?

Color code is used to indicate the values or ratings of electronic components, very commonly for resistors, but also for capacitorsinductors, and others. A separate code, the 25-pair color code, is used to identify wires in some telecommunications cables. (3)

The electronic color code was developed in the early 1920s by the Radio Manufacturers Association (now part of Electronic Industries Alliance(EIA)), and was published as EIA-RS-279. The current international standard is IEC 60062.

Colorbands were commonly used (especially on resistors) because they were easily printed on tiny components, decreasing construction costs. However, there were drawbacks, especially for color blind people. Overheating of a component, or dirt accumulation, may make it impossible to distinguish brown from red from orange. Advances in printing technology have made printed numbers practical for small components, which are often found in modern electronics.

What’s a WebWorks app?

When you hear the words Blackberry WebWorks, think HTML5, JavaScript, and CSS. Essentially, a BlackBerry WebWorks application is a web application that runs on a BlackBerry smartphone or BlackBerry PlayBook tablet.

BlackBerry WebWorks is an open source project that you can find on GitHub. Be sure to check out some of the BlackBerry WebWorks Samples.

Why create a BlackBerry WebWorks app? Some reasons to consider are:

• portability
• integration with core BlackBerry apps
• ease of access, even when users do not have an Internet connection available(3)

Requirements

The creating of Playbook packages is done with not many external requirements. However, you need to use external tools in order to generate signing and debugging assets required to put deployments onto device.

Setting-up a Development Machine for Playbook Deployment

Blackberry Web Works SDK must be installed in order to obtain various tools required for obtaining certificates and device provisioning.

1. Follow the instructions at https://bdsc.webapps.blackberry.com/native/ to download the SDK and any additional tools listed on the page.
2. Install the SDK to your development machine.

I assume that you have the Development Machine ready by now as you proceed to next steps. If not, I recommend you set up the Development Machine before proceeding.

Code-Signing Keys

We will start by requesting a code-signing keys at https://www.blackberry.com/SignedKeys/. They are absolutely free!

Enter your name, company, email, country and a 6-10 digit “PIN.” Take note of the PIN since you will need it in next steps. I suggest you write down in a file named says “keys.txt” in a folder say named “BB”.

RIM will tell you to allow up to two hours in order to receive your code-signing keys by email.

When you are registered you will receive code-signing keys.  You will receive a “PBDT” *.csj file, and an “RDT” *.csj file.

Now we can associate our own password with each of the code-signing keys.  Enter into command-line of your PC , writting in your PC’s window in Start -> Run the command cmd/k

A full listing of DOS commands can be found at Wikipedia.

Next, in Command-line Terminal navigate to your Program Files with following:

bcd C:\Program Files\Research In Motion\BlackBerry WebWorks SDK for TabletOS 2.2.0.5\bbwp\blackberry-tablet-sdk\bin

If you know how to deal with DOS (check in previous paragraph Wikipedia’s link to learn about DOS commands) you can get there step by step. I advise you at this juncture to review your knowledge of DOS commands.

blackberry-signer -csksetup -cskpass (your password)

On my PC I did the following:

I have blurred my password. Take note of the password you have just made up, and keep it safe. You will require this password in next steps, and in the future.

Next run the following DOS commands using PIN and password you have just decided upon.

Registering “PBDT” *.csj file

blackberry-signer -register -csjpin (PIN) -cskpass (PBDT file)

Where the brackets are, you have to write your PIN and your PBDT csj file name, the latter is sent to you by RIM.

Registering “RDT” *.csj file.

blackberry-signer -register -csjpin (PIN) -cskpass (RDT file)

We are now ready to generate keypair which will allow us to sign our apps.

blackberry-keytool -genkeypair -keystore (output file) -storepass (another password) -dname "cn=(your company name)" -alias author

My key generating DOS command looked like the following:

I have blurred author, and other relevant information. I hope it will not be too difficult for you to do it .

We will now generate a debug token for testing the App we are going to design.

The debug tokens has *.bar file extension, so our output name will be like “debugToken.bar” or any other you choose.

N. B. You can create multiple debug tokens for each of your Playbook using “-deviceId” arguments. I am not so rich, so I have only one Playbook.

Find the PIN of your Playbook, after turning on the device, and swiping from the top of the screen down, to show the system preferences. Go to About > Hardware to find the PIN number as you see in following image:

This is not my Playbooks’ PIN! I found this image on the web, and credit is due to the author of this image!

Next you will need to generate the debug token using this PIN:

blackberry-debugtokenrequest -cskpass (your password) -keystore (your keystore file) -storepass (another password) -deviceId 0x(your device PIN) (output bar file name)

First of all connect your Playbook to your PC with USB cable (recommended), but you can also do it with Wifi. You will now enable your Playbook in Development Mode in Security > Development Mode from system preferences, and you will need to have yet again a new password which I suggest to be as simple as 123.

For Development Mode on your device, go to Security > Development Mode from system preferences. And set it ON. The following image shows “No debug token” and Development Mode is OFF.

Take note of IP of your Playbook in Development Mode. We can certify the information on our IP in main screen of your Playbook, as show in following image of my Playbook:

Now we will install the token:

blackberry-deploy -installDebugToken (your debug token) -device (IP address) -password (device password)

Once you have uploaded your debug token with something like the following reassuring response you have reasons to be happy:

Preparing our App

We are now ready for our App. Our App will be a “Resistor Code Calculator” based on Danny Goodman’s quite old, and still popular, “Graphical Resistance Calculator”. You can view the web application and play with the Resistance Calculator visiting Danny’s site at:

http://www.dannyg.com/examples/res2/resistor.htm

I am proud owner of Javascript Bible that I bought many years ago from Amazon. Danny Goodman has authorised me to use his Javascript code to design our Blackberry Playbook App. The code we are using is quite old as old as my Javascript book. I don’t think the Javascript code has changed much, perhaps it has been fine tuned only.

In order not to reinvent the wheel, you will accept my zipped file “rescolor.zip”  which you can download from Bitbucket, an unlimited free private repositories’ site.

Unzip the contents of zipped file. You will need an unzipper program perhaps. And now view the webpage (use Google’s Chrome as you will need it from now on). We are going to use the web app in the file to make our Playbook App.

You will notice there is a config.xml file in unzipped contents you have just downloaded. This file is required to compile our App.

You can preview how our App will look like on Playbook, by installing Chrome’s “Ripple” plugin. You can read about how to install it in Blackberry’s Developper pages.

When enabled “Ripple” runs a web server on port 9910 of your computer. You will need to tweak Ripple in Chrome’s extensions (you can access “extensions” directly by pointing the Chrome browser to chrome://extensions). As shown in following image (in Portuguese, but I think it will be something similar in English) we have tweaked Ripple to view our PC’s URLs:

Now open index.html in Chrome. In first run-time of Ripple, after enabling, it will be asking you the platform you want to run the page. Choose WebWorks-TabletOS (2.0.0). You will be next greeted with following image:

The left and right popups will allow you to configure your environment. I did nothing of that sort, as I was unable to start Ripple services due to problems with portuguese language characters of my Windows. I suggest you close the popups, pressing with the mouse onto two little arrows on top, pointing to left and right. You can zoom to view, within Chrome’s personalization (surely you know to do it!), and you will see our App in a simulated Playbook:

We will next create a bar extension file of our zipped file (you just downloaded). If you have made any modifications to extracted files you will need to create a zipped file, that is if you want to implement your modded webpage.

So let us compile rescolor.zip and output as rescolor.bar. Return to DOS terminal as shown previously, to bbwp directory with following DOS command:

cd C:\Program Files\Research In Motion\BlackBerry WebWorks SDK for TabletOS 2.2.0.5\bbwp

To make it easy, create a directory myapp, and a sub-directory inside called output.  Drop rescolor.zip file into myapp directory (or one that you modded) and run the DOS command:

bbwp c:\myapp\rescolor.zip -d -o c:\myapp\output

You will immediately get this inconvenient result shown by following image with a Warning and an Error:

This error unknown protocol: c is what we need to sort out, as the Warning on feature is not so important at this stage.

To overcome this Error, you need to first create a temp directory in your C:\ drive (if you don’t have it already) and then issue the following commands in your DOS terminal

SET TEMP =C:\TEMP
SET TMP=C:\TEMP

This solution was found at Blackberry’s Discussion Forum. I did not find any alternative solution yet.

Now if you run the command again, you will get your compiled bar file in myapps/output directory. The following image shows these commands in my PC, plus the results of compilation:

If you check your output directory, you will now find rescolor.bar.

Install and run the App

Now we will deploy this App in our Playbook. Navigate to tablet-sdk with the following DOS command:

cd blackberry-tablet-sdk\bin

Run the following command to install the App:

blackberry-deploy -installApp -password 123 -device (your Playbook IP) -package c:\myapp\output\rescolor.bar

Hopefully it will install itself correctly, and you will get the reassuring output shown in following image:

You can now check your main screen and you will find the Resistor Color icon as shown on bottom left-side of the following image (these are actual screen shots of my Blackberry Playbook obtained by pressing simultaneously + and – buttons on top of the Playbook):

Run the App, and you can now play with color codes in your touch sensitive Playbook screen. The following image shows the App on my Playbook:

Acknowledgements

First of all thank you to Wikipedia for providing valuable information that I have used just about cut and paste at the beginning of this post. Also credits are due to Blackberry for providing so much valuable and free information on the Web. A special thank you is also due to Danny Goodman for his “Graphical Resistance Calculator” web application which has served to design our App. Also all credit is due to Joshua Granick for his easy to follow page on How to Create Keystore for Blackberry.  Once more  I thank Bitbucket for providing me a free of charge repository from where rescolor.zip can be downloaded.

Conclusions

As you have already seen, and tried (I trust) it is quite easy to write, and to deploy a webpage as an App. You can even deploy a weblink as can be seen in this App we have just designed which will open webpages within the App.  The links at the bottom open Redacacia blog (this actual blog where you are!) and Danny Goodman’s webpage. If you have a “killer” webpage that you have written in Javascript, I bet you can deploy it as an App. Of course, in order to deploy in Blackberry App World Store, and to monetize with it, you will need to sign your App to make it publicly available, and you will have to take into consideration more issues surely.

Posted in Mobile Apps, Programming, Uncategorized | | 2 Comments