Showing posts with label hardware design. Show all posts
Showing posts with label hardware design. Show all posts

Friday, March 14, 2025

How to Build the TensorFlow Lite C API from Source Inside WSL

How to Build TensorFlow Lite C API from Source Inside WSL

TensorFlow Lite is a lightweight, efficient runtime for deploying machine learning models on edge devices. It's ideal for environments that are low-power and performance-critical such as embedded systems mobile devices, and microcontrollers.

Building the TensorFlow Lite C API from source inside Windows Subsystem for Linux (WSL) allows you to integrate AI inference into native C applications. This is useful when working on constrained devices, building low-level systems, or working with existing C/C++ codebases.

Step 1: Set Up WSL and Create a .wslconfig File (Optional)

+

To prevent Bazel crashes from memory exhaustion, increase the memory limit for WSL. First, Open the Terminal(Windows Powershell):

# On Windows (not WSL):
Create C:\Users\<yourname>\.wslconfig with the following content:

[wsl2]
memory=6GB
processors=4

To do this with Notepad:

  • Open the Start menu and type Notepad
  • Paste the above configuration text into the new file
  • Click File > Save As...
  • Set File name: .wslconfig
  • Set Save as type: to All Files
  • Save it to C:\Users\<yourname>\

Then from PowerShell:

wsl --shutdown

Step 2: Install Prerequisites

sudo apt update
sudo apt install -y build-essential clang git wget python3-pip

Step 3: Install Numpy

pip install numpy

Step 4: Install Bazelisk

wget https://github.com/bazelbuild/bazelisk/releases/download/v1.17.0/bazelisk-linux-amd64 -O bazelisk
chmod +x bazelisk
sudo mv bazelisk /usr/local/bin/bazelisk

Step 5: Set the Required Bazel Version

export USE_BAZEL_VERSION=5.3.0
echo 'export USE_BAZEL_VERSION=5.3.0' >> ~/.bashrc
source ~/.bashrc

Step 6: Clone TensorFlow and Check Out the Version

git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout v2.12.0

Step 7: Build TensorFlow Lite C API

Optional but recommended: limit RAM usage to avoid crashes.

export BAZEL_BUILD_OPTS="--local_ram_resources=2048"
cd tensorflow/tensorflow/lite/c
bazelisk build -c opt $BAZEL_BUILD_OPTS --define=flatbuffer_op_resolver=false //tensorflow/lite/c:libtensorflowlite_c.so

Step 8: Install the Library and Headers

cd ~/tensorflow
sudo cp bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so /usr/local/lib/
sudo ldconfig

# Copy required top-level headers
sudo mkdir -p /usr/local/include/tflite
sudo cp tensorflow/lite/c/c_api.h /usr/local/include/tflite/

# Copy all internal TensorFlow Lite C API dependencies
sudo mkdir -p /usr/local/include/tensorflow/lite/core/c
sudo cp tensorflow/lite/core/c/c_api.h /usr/local/include/tensorflow/lite/core/c/
sudo cp tensorflow/lite/core/c/c_api_types.h /usr/local/include/tensorflow/lite/core/c/

# Copy additional headers required by the C API
sudo mkdir -p /usr/local/include/tensorflow/lite
sudo cp tensorflow/lite/builtin_ops.h /usr/local/include/tensorflow/lite/

Step 9: Verify With a Simple C Program

#include "tflite/c_api.h"
#include <stdio.h>

int main() {
    TfLiteModel* model = TfLiteModelCreateFromFile("model.tflite");
    if (!model) {
        printf("Failed to load TensorFlow Lite model\n");
        return 1;
    }
    printf("TensorFlow Lite model loaded successfully!\n");
    TfLiteModelDelete(model);
    return 0;
}

Compile it with:

gcc -o tflite_test tflite_test.c -I/usr/local/include -L/usr/local/lib -ltensorflowlite_c
./tflite_test

Conclusion

Now that you’ve built the TensorFlow Lite C API from source inside WSL, you're ready to run AI inference directly in your C applications. This setup is ideal for embedded AI applications such as digital signal processing. By building from source, you gain control when integrating with systems where Python or heavy dependencies are incompatible.

Friday, November 26, 2021

Black Friday 2021 Electronics Deals

I haven't found as many Black Friday promotions this year for electronics - probably due to the ongoing supply chain issues.  If you see a good deal that is not in the list, please leave a comment.

Adafruit has a code for 15% off all weekend here.  It's also Feather Friday which means 20% off all Feather (mainboards) and wing (daughterboards) with the code shown in the site header today.

Parts Express (audio components) has 10% of sitewide.

Pololu Robotics & Electronics Black Friday and Cyber Monday deals on select products are here.

RobotShop has a sale on some items until November 30 here.

Jameco Electronics has free shipping with a code on all orders.

Friday, October 30, 2020

SparkFun A La Carte Custom Board Designer

SparkFun Electronics is offering a web based custom board design service called SparkFun A La Carte (ALC).  You can choose from a few different microcontrollers that can run Arduino programs.  You also have a choice of I/O, connectors and power options.  Communications options include RFID, WiFi and Bluetooth.  There is a one-time design fee for each board and a per unit cost calculated as you add the components.  You can get a 50% discount on the design fee until 12/31/2020 with the promocode ALCSPARKFUN50. For more information see this ALC post on the SparkFun Blog  

This YouTube video on the custom board designer goes over an example design.




Monday, July 8, 2019

WIZnet IoT iOffload Contest

WIZnet is running a contest this summer for IoT designs that use either the W6100 Internet controller chip or WIZ610io Ethernet  module.  They are looking for 'IoT innovation' and will award five $1000 and ten $500 prizes.  For more details see the IoT iOffload Contest.

WIZnet products include chips and modules to enable networking for microcontrollers.  For example, the Arduino Ethernet Shield 2 uses the W5500 Ethernet Controller.







Tuesday, February 21, 2017

IBM and Arrow Electronics Helping Indiegogo IoT Startups

IBM recently announced it will partner with Arrow Electronics and Indiegogo to help IoT startups.  IBM will give free access to Watson IoT platform and cloud service discounts.  Arrow has already been supporting some Indiegogo campaigns that have electronic components and meet certification criteria, This page lists many of the benefits of Arrow certification.  Indiegogo currently has 62 Arrow Certified Campaigns.


Wednesday, January 13, 2016

Free CADSTAR Schematic Design Software Offer

CADSTAR is offering a free license to its Schematic Design software.  This is a permanent node-locked to your MAC address.  You also receive CADSTAR Library Editor Software and a 68-page tutorial. This is a limited time offer and ends in March, 2016.  You can upgrade the free version to a dongle-based license if you pay for maintenance.  See this Zuken press release for more details on the offer and upgrades.  If you aren't familiar with CADSTAR by Zuken watch the video below.

 

If you are interested in maintenance or upgrades you will need to contact a CADSTAR reseller.  My local reseller is Algozen, they cover New York and Ontario Canada and they are great to work with - very knowledgeable and great support. 


Wednesday, March 25, 2015

Element14 Sci Fi Your Pi Challenge

The element14 community Sci Fi Your Pi design challenge is underway.  Competitors will be required to create an application inspired by Science Fiction.  You must to apply to compete but if selected you receive a Raspberry Pi 2, a few other Pi models and various add on boards.  For more details and some example projects see Sci Fi Your Pi Design Challenge Information.  The Grand Prize is a Star Wars Boba Fett Helmet, the community choice prize will be some additional electronics.  Recruitment closes on April 12, 2015.  Here's a great second chance to show off your tricorder design if you missed being a finalist in the $10 Million Qualcomm tricorder XPRIZE.

Monday, November 19, 2012

BeagleBone Design Contest

Design a new plug-in board for the BeagleBone CapeContest to win $1000 and production by Circuitco.  The contest deadline is December 31, 2012, with the top three winning the Grand Prize which includes the above plus an analyzer from Total Phase.  Entry requirements are a schematic, bill of materials and YouTube video describing the cape.  Weekly prizes are also be available including Total Phase tools, Adafruit ProtoCapes, and MetaWatches from Mouser.  There are already two submissions, a Geiger cape and a CollRunner-II CPLD cape, you can see them here.

Monday, July 9, 2012

Free 3D Design Software

Autodesk 123D allows you to design and create 3D objects with apps that run on a PC, iPad, or online.  The 123D family of products are aimed at the personal fabrication market. You may be familiar with Autodesk from it's popular AutoCAD products or from Instructables.com.


Another free 3D program is SketchUp. With SketchUp, it's possible to build 3D models of printed circuit boards using CadSoft Eagle files, using the EagleUp script and ImageMagick.  Google recently sold SketchUp to Trimble who plan on continuing to offer it for free.


Tuesday, March 6, 2012

Tiny Serial WiFi Module Includes ARM Cortex M3

The Inventek Systems 802.11 b/g/n Serial to WiFi module makes it easy to add Wi-Fi to your embedded design.  It can be programmed from a host with a choice of serial interfaces using a simple AT command set.



These serial interfaces are provided by an STM32 ARM Cortex M3 processor as shown on the block diagram.  No software development is required for the STM32, the AT command set interface is resident in firmware.  This means your host microcontroller does not need a TCP/IP stack or RTOS.  This simplifies software development for your application - you only need to write serial I/O code to send the AT commands and process data.

An embedded wireless evaluation board is available that make it easy to connect the module to your microcontroller board for development of your WiFi application.  Both the evaluation board and the module are available from the Inventek Systems online store.


For more information on the module and evaluation board watch this video that includes a description of the functional block diagram above.


Tuesday, September 21, 2010

STMicroelectronics Offers Low Cost ARM Cortex M3 Kit

The price war continues among microcontroller development kits with the STMicroelectronics STM32 Discovery Kit available worldwide from these major electronics distributors for about $10 US.  It features an ARM Cortex-M3 that is the basis of the STM32 Value line of processors.  It is programmable via USB and you can download development tools and example firmware projects.

See the STM32 Discovery Kit Press Release for more details.

Friday, August 27, 2010

Add USB Host Support To Your MCU Design

The Maxim MAX3421E allows you to add a USB Host port to any microprocessor with an SPI interface.  This IC has recently returned to active production after being listed as not recommended for new designs.  It is offered as an Arduino shield (daughter board) from Circuits@Home and the code library for the USB Host Shield is on github.  You can find many articles on the design and use of the USB shield on the Circuits@Home blog.  The design is open hardware and you can order it from Batch-PCB as well.



For commercial projects, the MAX3421E is supported by USB Stacks from HCC-Embedded and Micro Digital.  HCC-Embedded also has an SD card module to add a USB Host to any board with an SPI capable SD card socket.  The schematics and layout are a free download from the website.

The MAX3421EVKIT-1 from Maxim can also be used for developing a USB stack for individual devices.  It can be ordered directly from Maxim ($57) or from Digikey ($62).  You can start with the MAX3421E EVKIT-1 Software and User Guide to develop your own driver for targeted devices.  I have been working with the MAX3421E with an ARM processor board and have added support for a mouse, keyboard, and hub to the design.

Wednesday, August 11, 2010

Renesas Offers Free Evaluation Kit For High-Performance MCU

For a limited time you can get the Renesas RX610 Stick Renesas Demo Kit (RDK) for free. Register to become eligible for the RX-Stick and you will also be registered for the RX62N RDK to be released later this year.
The RX610 Stick includes some unique features like a 14x10 LED array, a slide volume potentiometer, and a 4-direction joystick.  It has an on-board debugger and you can download demo projects for audio, DSP, FPU, and benchmarking. Renesas has also created the RenasasRulz.com online community with a developer's forum and more information about  the RX610 Stick.  You can see the kit in action in the RX-Stick Demo Youtube Video below.



The RX600 series is at the high-end of the RX family which is the successor to the H8SX, R32C and 32-bit Renesas MCUs.

Wednesday, July 28, 2010

TI $4.30 Microcontroller Development Kit Sold Out Fast

The Texas Instruments wiki for the MSP430 LaunchPad (MSP-EXP430G2) reports unprecedented demand for the LaunchPad development tool.  TI's servers were extra busy and stock was sold out within the first few days of availability.  For $4.30 plus shipping you get a development board with debug capability, a few MSP-430 devices to program and a mini-USB cable.

Tuesday, July 27, 2010

Monday, July 26, 2010

Open Circuits Wiki for Electronics Design

At OpenCircuits.com you can find PCB footprints, electronic circuit building blocks, tutorials and general electronics design links.  This is an evolving resource and the members are looking for help from the community to improve the site.  The information on the site is not all related to open source.  For example, you can find PCB footprints for commercial EDA packages and a list of low-cost oscilloscopes.

Thursday, July 15, 2010

Open Source Hardware Gets Formal Definition

Open Source Hardware Draft Definition version 0.3 is up for review. You never know how these things can be used in the future so it might be good to review if you have an open hardware project in the works.

I would prefer there wasn't such strict requirements for documentation, technology neutrality, or source code. Generic hardware that could be used for many purposes don't seem to fit the definition for open hardware.  For example, processor modules have a specific interface and are pretty self-explanatory from the schematic and data-sheets.  Also, an open source hardware developer may not have the engineering staff to develop the formal documentation and source code required by the current definition. I think the software development and documentation could be left to separate open-source groups. Open-source projects like eLinux.org have reverse engineered commercial products to run useful software without access to any documentation or even schematics.

Thursday, June 10, 2010

PIC18F Starter kit design competition

The PIC18F Starter kit design competition deadline is June 30th, 2010.  The winners do not receive cash or other prizes, but have the opportunity to showcase their coding skill and advertise their company.  The next version of the starter kit will include the winning designs as demos.

Tuesday, June 8, 2010

New Lattice XP2 FPGA kit available for $29

Press Release: New Low Cost Brevia Development Kit Accelerates Application Development for Popular LatticeXP2 FPGA Family

The LatticeXP2 Brevia Development Kit comes with all you need to start developing including a board, parallel JTAG cable, serial RS-232 cable, and AC adapter.

Update: This kit has been replaced by the $49 LatticeXP2 Brevia2 Board WITH LatticeXP2 FPGA: LFXP2-5E-6TN144C and on-board FTDI-based USB JTAG programmer.