# 2023-01-29 Simplifying Data Transfer With The Labii Serial Port Widget

<img src="https://www.labii.com/media/blogs/2023-01-29/serial-port.webp" alt="" data-size="original">

## **What is serial port?**

A [serial port](https://en.wikipedia.org/wiki/Serial_port) is a type of interface that allows communication between a computer and an external device. It transfers data one bit at a time over a single communication line (serial line) and is commonly used to connect a wide range of peripheral devices such as printers, scanners, and other industrial or scientific instruments. Serial ports use either the RS-232 or the RS-485 standard for communication, and are typically accessed through a DB-9 or DB-25 connector on the computer.

There are a variety of research equipment that use serial ports to transfer data. Some examples include:

1. Spectrometers: Used in chemical and physical research to measure the intensity of light across a range of wavelengths.
2. Data Loggers: Used in environmental and geological research to record data such as temperature, humidity, and pressure.
3. Microscopes: Used in biological and medical research to magnify and observe specimens.
4. Electroencephalography (EEG) Devices: Used in neuroscience research to measure electrical activity in the brain.
5. Chromatographs: Used in analytical chemistry to separate and analyze compounds in a mixture.
6. Mass Spectrometers: Used in molecular biology and biochemistry to identify and quantify the components of a sample.
7. X-ray Diffractometers: Used in materials science research to determine the crystal structure of a sample.

These devices typically use serial ports to transfer data from the equipment to a computer for analysis and storage. The serial port provides a reliable and low-cost means of data transfer that is well suited for many research applications.

## **Serial port support in Labii**

To help researchers to easily communicate with their equipment and retrieve the data needed for their research, Labii provides a [serial port widget](https://www.labii.com/widgets/serial-port/) for supporting data communication with research equipment. It provides a convenient and efficient means of data transfer that helps researchers focus on their work rather than worrying about the underlying technical details of data transfer.

{% embed url="<https://youtu.be/HazpAhwE7QY>" %}

## **BBC Micro Bit**

<figure><img src="https://www.labii.com/media/blogs/2023-01-29/bbc_microbit.webp" alt=""><figcaption></figcaption></figure>

In this article, I will utilize the [BBC micro bit](https://microbit.org/) to evaluate the capabilities of reading and writing through the serial port.

The BBC micro bit is a pocket-sized, programmable computer that was developed by the BBC for use in computer education. It has an ARM Cortex-M0 processor, accelerometer, compass, Bluetooth, and several programmable I/O pins. It can be used to create simple interactive projects, from games and music to art and robotics.

## **Programming Micro Bits to support serial ports**

<figure><img src="https://www.labii.com/media/blogs/2023-01-29/micro-bit-heart.webp" alt=""><figcaption></figcaption></figure>

1\. Open <https://makecode.microbit.org/#editor>

2\. Begin by displaying the heart icon, accompanied by the power up start melody, then proceed to configure the serial port. Within the serial port configuration, route all data to the USB and set the baud rate to 9600.

<figure><img src="https://www.labii.com/media/blogs/2023-01-29/micro-bit-on-start.webp" alt=""><figcaption></figcaption></figure>

```javascript
basic.showIcon(IconNames.Heart)
music.startMelody(music.builtInMelody(Melodies.PowerUp), MelodyOptions.Once)
serial.redirect(
	SerialPin.USB_TX,
	SerialPin.USB_RX,
	BaudRate.BaudRate9600
)
```

3\. For button A being pressed, add a high pitch tone, serial write the temperature number, and then display the temperature number.

<figure><img src="https://www.labii.com/media/blogs/2023-01-29/micro-bit-press-A.webp" alt=""><figcaption></figcaption></figure>

```javascript
input.onButtonPressed(Button.A, function () {
    music.playTone(988, music.beat(BeatFraction.Whole))
    serial.writeNumber(input.temperature())
    basic.showNumber(input.temperature())
})
```

4\. For button B being pressed, serial write string “LABII”, and then start melody “ba ding”.

<figure><img src="https://www.labii.com/media/blogs/2023-01-29/micro-bit-press-B.webp" alt=""><figcaption></figcaption></figure>

```javascript
input.onButtonPressed(Button.B, function () {
    serial.writeString("LABII")
    music.startMelody(music.builtInMelody(Melodies.BaDing), MelodyOptions.Once)
})
```

5\. For serial on data received “new line()”, show string for serial read until “new line()”, and then start melody “ba ding”.

<figure><img src="https://www.labii.com/media/blogs/2023-01-29/micro-bit-serial-on-data-received.webp" alt=""><figcaption></figcaption></figure>

```javascript
serial.onDataReceived(serial.delimiters(Delimiters.NewLine), function () {
    basic.showString(serial.readUntil(serial.delimiters(Delimiters.NewLine)))
    music.startMelody(music.builtInMelody(Melodies.BaDing), MelodyOptions.Once)
})
```

6\. Leave it empty for forever.

```javascript
basic.forever(function () {
	
})
```

7\. Paired to your micro bit and click Download to program it.

See all source code at <https://github.com/Labii/labii-serialport>&#x20;

## **Using the Labii serial port widget to read and write data**

1. Connect your micro bit to your computer
2. Login to Labii at [https://www.labii.app](https://www.labii.app/) , add a new column with widget “[Serial Port](https://docs.labii.com/widgets/column-widgets/device#serial-port)”.
3. Click **Edit** button under **Configuration** to update the configuration of the serial port. You can update the following parameters:\
   ![](https://www.labii.com/media/docs/widget-column-serialport-configuration.webp)
   1. baudRate: A positive, non-zero value indicating the baud rate at which serial communication should be established. Default to 9600.
   2. dataBits: The number of data bits per frame.
   3. stopBits: The number of stop bits at the end of a frame.
   4. parity: The parity mode.
   5. bufferSize: A positive, non-zero value indicating the size of the read and write buffers that should be created.\
      flowControl: The flow control mode.
4. Read data from micro bit via serial port\
   ![](https://www.labii.com/media/docs/widget-column-serialport-edit.webp)
   1. Open add record form
   2. Click **Connect** button, in the pomp out, select BBC micro:bit and click Connect
   3. Press button A in the micro bit
   4. You shall hear tone High B and a temperature number displayed in your micro bit. At the same time, your serial port in Labii will display the temperature.
   5. Click **Disconnect** button to close the connection.
5. Write data to micro bit via serial port\
   ![](https://www.labii.com/media/docs/widget-column-serialport-readonly.webp)
   1. Open a record contains the serial port column,
   2. Click **Edit** to provide a value “LABII”, click Submit.
   3. Once submitted, the Write button will show up.
   4. Click **Write** button, in the pomp out, select BBC micro:bit and click Connect
   5. Your micro bit should display “LABII” and play melody “ba ding”
   6. Click **Disconnect** to close the connection.

## **Other serial port widgets**

To support the research community and simplify data transfer, Labii is dedicated to developing more serial port-related widgets that facilitate communication between Labii and research equipment. By providing a wide range of software solutions for different equipment types, Labii aims to make data transfer more efficient, reliable, and accessible for researchers. This will allow researchers to focus on their work and minimize the time spent on technical details. With a commitment to innovation and an understanding of the research community's needs, Labii is poised to play a vital role in advancing research through improved data communication.

## **Summary**

The Labii Serial Port Widget is a software solution for supporting data communication between a computer and research equipment via the serial port. With its intuitive interface and customizable options, the Labii Serial Port Widget streamlines data communication in research and helps researchers focus on their work. To learn more, schedule a meeting with Labii representatives ([https://call.skd.labii.com](https://call.skd.labii.com/)) or create an account (<https://www.labii.com/signup/>) to try it out yourself.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blogs.labii.com/feature-updates/2023-01-29-simplifying-data-transfer-with-the-labii-serial-port-widget.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
