element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Test Instrumentation
  • Challenges & Projects
  • Project14
  • Test Instrumentation
  • More
  • Cancel
Test Instrumentation
Blog micro:bit as Pass / Fail indicator in an automated test setup
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Test Instrumentation to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 30 Oct 2018 4:55 PM Date Created
  • Views 3788 views
  • Likes 15 likes
  • Comments 19 comments
  • advanced micro:bit projects
  • microbit projects
  • microbit
  • micro bit
  • advanced_microbit_projects
  • labview
  • scpi
  • diytestinstruch
Related
Recommended

micro:bit as Pass / Fail indicator in an automated test setup

Jan Cumps
Jan Cumps
30 Oct 2018
image

Test Instrumentation

Enter Your Electronics & Design Project for a chance to win a Grand Prize for Originality, a Tool Set, and a $100 Shopping Cart!

Back to The Project14 homepage image

Project14 Home
Monthly Themes
Monthly Theme Poll

 

I received a micro:bit from element14. My first project is to turn it into a LabVIEW test device as a pass and fail indicator.

 

It will perform two functions:

  • display an image or image if a test passes or fails. A physical indicator for the test operator.
  • drive an output high if a test passes and another one if a test fails. This can be used to drive a buzzer or, in a full automatic setup, to push the failed device off the production line into a rework bin.

 

image

It's a project that fits the Project14 size. It should be easy to replicate. I add no hardware to the micro:bit.

 

I have never used this device and plan to program it in C or C++. I’ll blog the learning experience here.

If everything goes fine, there will be 3 deliverables:

 

  • Firmware for the micro:bit that listens to SCPI commands on its USB port, and acts upon those commands by displaying the image/image.
  • a LabVIEW driver library with easy to use init and control blocks.
  • a simple test setup with an automated LabVIEW flow that tests ‘something’.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

video: the device in action, controlled by a LabVIEW process

 

First Firmware Program

 

I'm using the Mbed web editor. I created an Mbed account, then added the BBC micro:bit as a board.

image

 

After that, I imported the Hello, world! example. It compiled without any difficulties and worked straight away when I loaded the firmware to the board.

But to be sure that I can use it as a LabVIEW programmable device, I had to try if the SCPI parser library that I use in most of my project works on the micro:bit.

I cloned the Hello, world! project, added the sources of the SCPI lib and did a test compile.

I had one unexpected error. The compiler did not appreciate this (re)definition of bool in the lib's types.h file.

 

#if !HAVE_STDBOOL
    typedef unsigned char bool;
#endif

 

The fix was to comment them out and replace by:

 

#include <stdbool.h>

 

Another option is to define the HAVE_STDBOOL symbol.

 

I also had a few expected errors because the SCPI lib does not define all functions. You need to provide a few yourself.

Once I did that - I simply copied the lib's parser testcase, it contains a definition for all necessary functions - all compiled well.

And it works. I attached a console to the USB port (speed: 115200) and could see the test result stream.

 

image

In the image above, you see MICRO_BIT and PASS_FAIL in the output.

Those are the values I programmed for the manufacturer and device name (the SCPI attributes for the *IDN? command).

 

That's it for the first program. My second project will try to read from the USB port.

 

image

Figure: display and IO behaviour for all 3 states.

 

Second Firmware Version: SCPI Commands, USB and Display

 

The next version of the program has improved a few things.

The micro:bit is now listening for commands in sleep mode. Only when a character appears, it'll wake up and send that character to the SCPI parser.

 

#include "MicroBitSerial.h"
// ...
MicroBitSerial serial(USBTX, USBRX);
// ...
    while(1) { // the device goes into low power when no characters arrive
        character = serial.read(SYNC_SLEEP);
        SCPI_Input(&scpi_context, (const char *) (&character), 1);
    }

 

The SCPI output function is also using the serial class:

 

size_t SCPI_Write(scpi_t * context, const char * data, size_t len) {
    (void) context;
    return serial.send((uint8_t *)data, len);
}

 

To display the success and fail status, I've created two bitmaps. A plus and a cross drawing. I first tried to write these with the micro:bit built-in font, but did not like how the X is displayed.

 

MicroBitImage imgPass("0, 0, 255, 0, 0\n0, 0, 255, 0, 0\n255, 255, 255, 255, 255\n0, 0, 255, 0, 0\n0, 0, 255, 0, 0\n"); // plus
MicroBitImage imgFail("255, 0, 0, 0, 255\n0, 255, 0, 255, 0\n0, 0, 255, 0, 0\n0, 255, 0, 255, 0\n255, 0, 0, 0, 255\n"); // X

 

To control the device, I've written a single SCPI command that can set the state. Here is the syntax

 

[:INDicator:]STAte PASs
[:INDicator:]STAte FAIl
[:INDicator:]STAte CLEar

 

E.g.: you can send the STA PAS command to display the cross image.

 

The three possible states are defined as SCPI enumerators:

 

enum scpi_state_t {
    SCPI_STATE_PASS,
    SCPI_STATE_FAIL,
    SCPI_STATE_CLEAR
};

const scpi_choice_def_t scpi_state_def[] = {
    {/* name */ "PASs",      /* type */ SCPI_STATE_PASS  },
    {/* name */ "FAIl",      /* type */ SCPI_STATE_FAIL  },
    {/* name */ "CLEar",    /* type */ SCPI_STATE_CLEAR  },
    SCPI_CHOICE_LIST_END,
};

 

The SCPI command handler acts based on the requested state:

 

static scpi_result_t setState(scpi_t * context) {

    int32_t param1;
    scpi_bool_t result;
    scpi_result_t retval;

    result = SCPI_ParamChoice( context, scpi_state_def, &param1, TRUE );
    if ( false == result )
    {
        return SCPI_RES_ERR;
    }
    else
    {
        switch (param1) {
        case SCPI_STATE_PASS:
            uBit.display.clear();
            uBit.display.print(imgPass);
            retval = SCPI_RES_OK;
            break;
        case SCPI_STATE_FAIL:
            uBit.display.clear();
            uBit.display.print(imgFail);
            retval = SCPI_RES_OK;
            break;
        case SCPI_STATE_CLEAR:
            uBit.display.clear();
            retval = SCPI_RES_OK;
            break;
        default:
            SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
            retval = SCPI_RES_ERR;
       }
    }

    return retval;
}

 

That handler is registered into the SCPI lib as follows:

 

    {.pattern = "[:INDicator]:STAte", .callback = setState,},

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

video: initial test of the SCPI commands and the LED matrix

 

That's all that's needed to make this work. In the next version I'll add the GPIO functionality to pull a pin high at Pass or Fail.

 

Third and Final Firmware Version: Add GPIO

 

The final firmware version adds two output pins. Pin 0 on the micro:bit sets high on success. Pin 1 on failure status.

This requires little changes. In the main() function we set both pins to 0, just after initialising the board.

 

    // Initialise the micro:bit runtime.
    uBit.init();
    uBit.io.P0.setDigitalValue(0);
    uBit.io.P1.setDigitalValue(0);

 

Then, in the SCPI handler, based on the state, the appropriate pin is set:

 

        case SCPI_STATE_PASS:
            uBit.io.P1.setDigitalValue(0);
            uBit.io.P0.setDigitalValue(1);
            // ...
            break;
        case SCPI_STATE_FAIL:
            uBit.io.P0.setDigitalValue(0);
            uBit.io.P1.setDigitalValue(1);
            // ...
            break;
        case SCPI_STATE_CLEAR:
            uBit.io.P0.setDigitalValue(0);
            uBit.io.P1.setDigitalValue(0);
            // ...
            break;

 

The Mbed project is attached to this blog post.

 

LabVIEW Driver

 

The driver library contains the necessary blocks to control the micro:bit and an example process. This is also attached at the end of this blog post.

 

State Control block:

 

imageimage

 

Initialize block:

 

image

image

image

 

Reset block:

 

imageimage

 

Default Setup block:

 

imageimageimage

 

Close block:

 

imageimage

 

LabVIEW Example Process

 

I've used the simplest process that shows the micro:bit Pass / Fail device functions.

 

image

image: demo process runs through the three statuses of the micro:bit pass / fail device

 

Because it uses the driver's functional blocks, all is fairly easy.

It connects to the micro:bit over USB. Then it steps through PAS, FAIL and CLEAR status until you press the stop button. At the end the connection is closed and resources freed.

When you execute this flow, you can see the micro:bit LED matrix represent the statuses.

You can also measure the signals on pin 0 and 1 during the execution.

 

Before executing the process, select the COM port that's assigned to the micro:bit.

If you've installed the Mbed USB serial driver (Windows only, neccessary for Windows versions < 10), set the "Uses Mbed USB driver True. Else set this witch off.

You can see if the USB driver is the MBed one by opening the device manager, open the Ports node and check if the micro:bit entry says mbed serial.

If yes, you use the driver and youhave to flip the switch.

 

image

image: take care to select the COM port and USB driver of your micro:bit before starting.

 

In a real world process, the device is intended to be part of an automated test jig.

The state would be set based upon a successful or failed test.

The fail pin can be used to sound a horn or to drive a gizmo that kicks the device under test into a repair bin.

 

Source Code for micro:bit and LabView

 

The LabVIEW driver is attached as a ZIP archive below.

The source code can be imported and built by following these steps:

In Mbed, click import. Then click on the link to import from URL:

image

Enter https://os.mbed.com/users/jancumps/code/microbit_scpi_pass_fail/

Select these options:

image

 

After Import, you can select the project and press compile.

If all works OK, Mbed creates a hex file and places it in your Download folder.

If you drop that file on your micro:bit, it should be programmed as a Pass / Fail device.

You can test this by connecting to its COM port with PuTTY, 115200.

type STA PAS then enter (you don't see what you type)

It should show a + on the led matrix.

 

This is a WIP type of blog that will get updated each time I make progress finished blog. This Project14 theme runs until November 14. That’s the time I’ll give myself to complete this.

Attachments:
LabVIEW.zip
  • Sign in to reply

Top Comments

  • Jan Cumps
    Jan Cumps over 6 years ago +5
    I unpacked the micro:bit today and tried if I can create a C program that uses the SCPI library. This works. I was able to run a SCPI parse test set and stream the results to USB. It's a small step. I…
  • Jan Cumps
    Jan Cumps over 6 years ago +5
    The program can now read serial input. #include "MicroBitSerial.h" // ... MicroBitSerial serial(USBTX, USBRX); // ... while(1) { character = serial.read(); SCPI_Input(&scpi_context, (const char *)…
  • Jan Cumps
    Jan Cumps over 6 years ago +5
    I've got most things working now: listen to USB commands in sleep mode parse and execute SCPI commands Show a bitmap (in this case a X or a +) on the display The remaining things are the two GPIO pins…
  • Jan Cumps
    Jan Cumps over 6 years ago

    With some changes - none of them intrusive or complex - this design can become a binning device.

    You can put an instrument at the start of the cycle that evaluates the device under test and gives it a binning grade.

    One example is for a transistor (this is used by manufacturers to give it a postfix A, B or C)

    • hfe < 80,
    • hfe between 80 and 120,
    • hfe > 120

    The micro:bit can then - instead of rejecting or passing the device as it's doing in the blog's design - push it into the right bin.

     

    Now that I have a meter with binning and automation capability (DMM6500) I may take this design further and turn it into a binning line driver.

    I bet it 'll be less than 20 lines of code to change.

    Hang on ...

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Workshopshed
    Workshopshed over 6 years ago

    Great stuff. I knew that the Microbit would work with MBed but I've never seen a worked example before.

    I had to google the meanining of SCPI  https://www.rohde-schwarz.com/us/driver-pages/remote-control/remote-programming-environments_231250.html

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 6 years ago in reply to Jan Cumps

    I had to make that buffer block conditional, because the device stopped working reliable with that block in place and the normal Windows 10 USB Serial driver:

     

    image

     

    image

    image

     

    Enable it only when the Mbed serial driver is installed and active for your micro:bit. I'll upload a new LabVIEW archive with this functionality.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 6 years ago in reply to mahmood.hassan

    mahmood.hassan  wrote:

     

     

    Yup In lab view u need VISA drivers to use com ports.

    I was using the VISA driver, but it failed after installing the mbed driver. When I uninstalled the mbed USB driver, LabVIEW worked again with the micro:bit.

    I have found a resolution: https://os.mbed.com/users/MichaelW/notebook/installing-and-setting-up-labview/

    Note on writing over serial to Mbed

    To prevent Error:-1073807298 (could not perform operation due to I/O error) when attempting to write to serial do the following.

    Insert a VISA Set I/O Buffer Size  just after configuring the COM port.
    Set the mask to 48 and the size to 4k or the maximum number of bytes you will ever need to read or write.
    The VISA set IO buffer is found under Instrumention I/O --> Serial --> VSet Buffer Size

     

    I have done what's explained above (see the red square in the process). I only had to set the mask. The buffer was 4K by default.

     

     

    image

    It now works with the mbed USB driver.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mahmood.hassan
    mahmood.hassan over 6 years ago in reply to Jan Cumps

    Both link refer to same drivers but it tells how u can debug your code.

    Yup In lab view u need VISA drivers to use com ports.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube