How to interface an I2S microphone with Beaglebone Black(BBB)

I have been writing a large variety of computer programs since a long time, but there was this question, the answer to which was elusive for a long time.

How are they converted to binary data, and how is that interpreted by my computer?

How do we create devices, and how do they work?

My fascination started with a smart wall clock (http://ingrein.com) that I thought was a very cool gadget to have at home. I wanted to build something like that on my own, but didn’t had know how. So I started on a journey to learn embedded systems and their functioning.

I moved from Arduino to Raspberry Pi, and then to RedBear Duo, learning new things at every step. And then finally came BeagleBone Black. I had always wondered how Linux kernel works, is it something that I can compile on my own, and execute? I have been trying to solve this problem for so long and I want to thank Pavel Botev for helping me out on this.

Once the TI Processor SDK is installed, you will find the following file structure in the install location.

This SDK contains both the Linux kernel, and the Root File System, and other cross compile binaries (compiler) to compile the kernel. Assuming ti-processor-sdk-home is the SDK install location, you will find the kernel files at

<ti-processor-sdk-home>/board-support/linux-4.9.69+gitAUTOINC+xxxx (The exact version may vary depending on the version of the processor SDK)

and the RFS at

<ti-processor-sdk-home>/filesystem

You can copy these to separate folders so you always have the original SDK copy. In case anything goes wrong, and you want to restart from beginning, you have the kernel, and RFS that you can copy again from the Processor SDK.

Lets assume you copied the kernel files to location ~/linux-4.9.69, and changed your current directory to where you copied the kernel.

$ cd ~/linux-4.9.69

Before you compile the kernel, we must prepare the kernel by telling what is the board that we want to compile the kernel for? In other words you define the configuration by selecting appropriate defconfig file. For BeagleBone Black, we need to use “tisdk_am335x-evm_defconfig”. All config files are present in arch/arm/configs folder.

Please note the space between “arm-linux-gnueabihf-” and “tisdk_am335x-evm_defconfig” in the above command.

You may want to configure your linux distribution further by informing the compiler what all files/modules should be included for compilation. “menuconfig” is the target for this configuration, and the full command to run menuconfig is below.

But before you run menuconfig target, there is one more step. We need to tell menuconfig what all options should be shown in menuconfig, and how. Though most of the settings are good by default, we need to do one change in the kernel

Please note again that menuconfig is the target name, and the value for CROSS_COMPILE flag ends with a hyphen as “arm-linux-gnueabihf-”. There should be space between “arm-linux-gnueabihf-” and “menuconfig”.

Running “menuconfig” target opens up a menu through which you can select which modules you would like to be compiled in-line, i.e. along with rest of kernel code, and which ones to be compiled, and included as modules. Mark module PCM5102a to be inline compiled along with other kernel files.

Now in order to compile the Linux Kernel, you have the kernel source files, and the cross compile binaries needed to compile the source. Compile the kernel using

The above command compiles the kernel and keeps the image at arch/arm/boot/uImage. You can copy this image and flash it to the board, or transfer it via tftp. I shall explain the process of using tftp later.

The device tree source files are present in linux-4.9.69/arch/arm/boot/dts folder in the kernel. The device tree is the code that tells the kernel what all hardware is available on the board, and how is it configured.

Before we compile the device tree, we need to know which device tree we will be using. As this experiment is about BBB, it is obvious that BeagleBone’s device tree should be used. It is present as linux-4.9.69/arch/arm/boot/dts/am335x-boneblack.dts.

But we want to interface an I2S mems microphone (SPH0645LM4H, https://www.adafruit.com/product/3421) with BBB, we will need to tell the device tree of its presence, and its configuration. We will include all microphone related configuration in a separate DTSI file (include file, which can be included in the parent device tree source).

$ vi am335x-boneblack-pcm5102a.dtsi

The content of this include file is as below

/*
* Copyright(C) 2016 Texas Instruments Incorporated- http://www.ti.com/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

The above command will result in a device tree binary within arch/arm/boot/dts/ folder. The file is named am335x-boneblack.dtb

Lets now talk about how the MEMS microphone should be wired up. We can focus only on the BeagleBone column of the image below.

Booting the BBB

Now that all configuration is setup, we should march ahead with booting of your BBB. But wait, what you have is a kernel image (uImage) and a device tree binary (am335x-boneblack.dtb). But how do we send these to our BBB?

Instead of flashing the kernel, device tree, and the RFS to an SD card, and then putting the SD card to BBB, we will makes these available to BBB directly from the host computer via TFTP (for uImage, & DTB) and NFS (for RFS).

TFTP

We will use TFTP to provide the kernel image, and DTB to the BBB. Go ahead and install TFTP on your host computer.

sudo apt-get install tftpd-hpa

Now let us configure TFTP and tell it the location of the files we need to transfer to the BBB. TFTP configuration files is present as/etc/default/tftpd-hpa. Example configuration is below

The above configuration makes “/home/parag/linux-4.9.69/arch/arm/boot” as TFTP_DIRECTORY, which is the default directory where tftp looks for files that it can transfer. TFTP is not known to work very well with nested directories, so we must ensure that both files (uImage, and DTB) are available in this directory.

As uImage is created in above directory itself, so its not a problem, and TFTP can easily transfer it. However DTB is formed within boot/dts. We can create a symbolic link in the boot itself, and make it point to DTB file present in dts directory to make it work.

ln -s dts/am335x-boneblack.dtb am335x-boneblack.dtb

Sharing RFS (Root File System) over NFS (Network File System)

RFS or the Root File System contains binaries that you typically see in any linux distribution. RFS is made available by TI SDK as indicated early in this article. You can just copy those files from SDK, and keep it at a desired location from where you can share them over network via NFS.

NFS server can be installed on ubuntu host computer with the following commands

sudo apt-get update
sudo apt-get install nfs-kernel-server

Once NFS is installed, you can proceed with its configuration. Edit /etc/exports

sudo vim /etc/exports

You can configure the above file with the following setting

/home/parag/bbone/rootfs *(rw,sync,no_root_squash,no_subtree_check)

Note, I have kept my RFS files in /home/parag/bbone/rootfs. You change this setting depending upon where you have copied the RFS files to.

Finally, booting the BBB!!

After all this hard work, its time to see the magic. Connect BBB with LAN cable, and connect it to the same network as your host computer.

Power up the BBB. Assuming you have minicom or any other serial monitor set up, you should be able to see the uboot logs. Immediately press space key so the bootloader (uboot) does not boot the kernel available in BBB, but stops for further commands. Type commands as below to help BBB connect to the network.

I have used 192.168.1.101 as IP of my host computer, and 192.168.1.1 as the gateway. You will need to choose these according to your setup. Finally dhcp command will help BBB to be allocated an IP address from your router.

If everything goes on file, you will see output from BBB uboot that an IP has been assigned. Next command as follows

The above command instructs u-boot to download the device tree image from the serverip instructed earlier, and copy the same to address 0x80F80000 in RAM. Kernel uImage is also downloaded from the host serverip and copied to 0x80007FC0.

The first command above sets up the bootargs. Change the setting as per your environment. The last command starts the boot process.

Soon you should see the kernel boot to complete, and a login prompt to appear. Login using root as user. No password should be needed.

Unexpected Signal on P9_41 :(

Now you will find (on your oscilloscope) that the moment you boot the kernel, you start getting a signal (square wave) on the data pin (P9–41). Ideally there should be no signal on the data pin till you start recording using the “arecord” command.

You would notice there is pinmux settings for clkout2 (mode 3) for Pin P9_41A which is the data pin. We need to disable this setting so that data pin receives only the data we record from microphone, and not from any other source.

The above observation is because of a configuration in the am335x-bone-common.dtsi (a file included in am335x-boneblack.dts).

&am335x_pinmux{
pinctrl-names = "default"
pinctrl-0 = <&clkout2_pins>

It is this line `pinctrl-0 = <&clkout2_pins>` that causes the signals on data pin. We need to comment this out like below.

After this above change, we need to build again the device tree, and reboot the kernel. The data pin should not have any signal now till we start recording with the command.

$ arecord -Dhw:1,0 -f S32_LE -t wav -c 1 -d 60 -vvv /tmp/audio.wav

The above command shall start recording mono sound (single channel) at /tmp/audio.wav. The above command’s -D flag (-Dhw:1,0) assumes your PCM5102a sound card is listed at index 1. This index can be confirmed by listing down all cards and seeing the output of the command below

$ arecord -l
If you found this article helpful, let me know in the comment section below.

According to the International Monetary Fund (IMF), the global economy is expected to shrink by over 3 percent in 2020 – the steepest slowdown since the Great Depression of the 1930s. To understand the impact of the COVID crisis in the Latin American Insurance Industry, we interviewed Mr. Horacio Sanchez- Granel from Buenos Aires, Argentina, and Insurance & Reinsurance Consultant.

Mr. Horacio has been Chairman and CEO of Boston Seguros, P&C and Life Insurance company for 21 years. Previously, he held senior executive positions in three insurance companies and has several years of experience managing financial service institutions. He has also held other executive positions in an Argentinian oil company and a tractor and industrial machinery international company. Currently, he is a Board Member and part of the Executive Committee in Nacion Seguros, the state-owned insurance company. He also works as an insurance and reinsurance consultant for Argentine and Latin American markets.

Customer Relationship during the pandemic

Insurance companies play a pivotal role during times of economic stress by helping companies and individuals manage risks and cushion against losses. How should Insurers respond to their customer’s needs, especially since there will be scrutiny about how they respond during this critical time — and it will dictate public perception for many years to come?

Mr. Horacio: Insurers must safeguard the interests of their clients and advise them on the scope of the coverage. They must communicate that the coverage is not infinite but rather has limits in terms of the risks covered, amount insured, and the origin of the claim. There are doubtful cases but insurers should be flexible enough and protect their client from damages. It was not possible to predict COVID-19. Both Life and P&Cs have been affected and have huge arrears to be paid.

On the other hand, claims processes need to be more transparent. They should adhere to the compliances of the insurance companies. In these times, selling agents and insurance brokers should be more flexible and build close relationships with the clients. They should explain to them the possibility of the claim they are trying to reimburse. In Latin America, we don’t have many claims related to business interruption. That coverage is not very common here.

Especially in Argentina, businesses have slowed down due to lockdowns. The claims ratio in this area is going down but claims in life insurance policies have increased a bit. However, the impact here is not as big as the USA or Europe.

Business Continuity in the time of Pandemics

What are some new business models that Insurance Carriers are considering to meet the expectations of life in ‘The New Normal’? More specifically, where is the new business going to come from, for Insurance, over the next two years?

Mr. Horacio: The outbreak of the COVID-19 pandemic has changed the dynamics of work culture, human relationships, and daily routines. Many companies including insurers are adopting digital solutions within their operations. Organizations are reimagining their business models to adapt to new paradigms to be more sustainable and profitable.

The New Normal has given rise to new coverages in various insurance lines to cover risks originated by this pandemic or any possible future pandemics.

For example, new clauses such as Loss of Profit due to business interruption and pandemics in Life and Health insurance, and worker’s compensation will now be included in the respective policies. Interruption of business processes entails new set-up and investment. Some other new coverages will also be introduced such as the cost of maintenance due to the non-use of offices, premises, or industrial facilities. Cyber Insurance will now be a must as most of the workforce is working remotely. The rate of cybercrimes was much higher in developed countries before the pandemic, but now even the developing countries are at risk. This will accelerate the need for Cyber Insurance in developing countries.

Road to recovery

Many General Insurance lines are hit- Travel, Motor, Home – what will be the road to recovery for these Insurance lines?

Mr. Horacio: Since people are avoiding travel altogether, the travel and motor insurance industry are hit badly. Many customers in Argentina are asking Insurance companies to give some discount on the premiums. We will see some big changes in these insurance lines. Going forward, on-demand or pay-as-you-use policies will prevail more in these insurance lines.

Role of AI in pandemic crisis management

Before the Pandemic crisis began, technologies like AI have been instrumental in modernizing the business of insurance and advancing their digital transformation. Where are some of the biggest gaps being exposed to insurance organizations, and How is technology going to solve these problems?

Mr. Horacio: Going forward, AI along with IoT and other technologies will play a crucial role in the Insurance industry as a whole. They will rely on statistical analysis of large databases to predict future behaviors. The new challenge is how to incorporate unknown risks into the existing models to be able to properly underwrite and price risks, anticipate client behavior, facilitate complex operating processes, manage complex claims and detect possible frauds.

Financial assets are the main asset of an insurance company. They are under the influence of the volatility of financial markets. Technology here can help by analyzing different scenarios but the ultimate decision is in the hands of the banks.

Challenges & opportunities in adoption of AI

Why Insurers hesitate to invest in AI?

Mr. Horacio: Companies were investing in technology earlier, but now it has accelerated due to the unprecedented change brought about by COVID-19 pandemic. Not just the developed countries but in developing countries such as Latin America, I see a big wave of new investments in technology. Technology companies are also looking forward to this change. Insurers will eventually overcome their hesitation and invest more in AI and other technologies.

Which area will see max Investment in AI- claims, underwriting, fraud detection, marketing in Argentina, and Latin American Insurance markets?

Mr. Horacio: Before the outbreak of the COVID-19 pandemic, investment in AI was more targeted towards claims, fraud, underwriting, back-office operations, etc. Going forward, predicting future scenarios will be a challenge. Historical data might not be useful here. Therefore, in the New Normal, all aspects of an Insurance company will have to be developed under the umbrella of AI.

Product Innovation

Consumers, now more than ever are seeking value-added experiences with the products & services they buy. How will these expectations amidst this Pandemic backdrop impact new product innovation within insurance?

Mr. Horacio: Customers want a more palpable relationship with their insurers. Customer Experience is going to be a fundamental aspect during the purchase of insurance coverage. In addition to being simple, the purchase and subscription process will have to be perceived as a service that accompanies the client at every moment they need it. These additions will help insurers gain more information on their customer’s actions and behavior. Based on this data, they can dynamically adapt the coverage and pricing of the product. I call it — Dynamic-on-demand coverage.

Challenges in Latin American Insurance industry

What are some of the technological challenges faced by Insurers in Argentina and Latin American markets operating in the New Normal?

Mr. Horacio: Insurance industry for many years has been static but now is moving forward in many ways. The world including the Latin American Insurance is witnessing rapid development in terms of technology. The InsurTech industry is parallel to the Insurance industry. It aids in the development of the insurance companies. The whole world of insurance is making advances in technology. Different economics have different buying patterns for insurance products. One such insurance product that should develop is Microinsurance.

Microinsurance needs technology, without which it is very difficult to manage. In a sense, the outbreak of COVID-19 was beneficial in accelerating these technological developments.

Insurance buying behavior in the post-pandemic world

In a post-pandemic World, will insurance ever be bought offline? Or have we crossed the threshold for now buying policies purely online?

Mr. Horacio: Personal line insurances such as car, accident, personal, travel, microinsurance are mostly purchased online. In Argentina, 60% of the insurance policies are sold by traditional marketing and sales through brokers. However, in commercial, industrial, energy, transport, and large companies in general, the marketing and sales will continue the traditional ways but through electronic means. The use of IoT, sensors, drones dynamically monitoring the facilities and processes in different industries is increasing. Argentina, which is an agro-based country already has technologies such as drones and IoT which monitor the crops in place. AI will surely be crucial here to analyze the data and enable quick decisions in case of a fire or an accident.

Wrapping up

Summing up — Mr. Horacio Sanchez-Granel shared valuable insights on the challenges in the Latin American Insurance Industry, how AI technologies can aid in policymaking and rise in dynamic-on-demand policies in the post-pandemic world.

AI is going to be essential for Insurers to gain that competitive edge in the post-pandemic world. Check out Hitee — an Insurance specific chatbot for driving customer engagement. For your specific requirements, please feel free to write to us at hello@mantralabsglobal.com.