Half-soldered boards, sensors taped to anything that moves — every prototype begins with chaos and hope. Your idea feels promising, but even before you start, capturing real-time sensor data becomes the major roadblock. Suddenly, you are buried in embedded C drivers, broken logs, and mysterious bugs, just trying to answer: “What did the sensor actually sense?” That spark of inspiration fades behind a wall of tedious setup.
With our DEEPCRAFT™ MicroPython integration, data capture becomes refreshingly simple. One MicroPython script running on your board streams data wirelessly to your host. On the host side, DEEPCRAFT’s Capture Server handles the rest — real-time logging, timestamping, and formatting your data, ready to be dropped straight into the DEEPCRAFT™ Studio for training. No clunky drivers. No corrupted CSVs. Just clean, timestamped data — exactly how you imagined it. From sensor to dataset, it’s smoother than ever. Below is how the workflow looks like:
The Capture Server provides multiple interfaces, but this integration focuses on wireless transmission of sensor data using TCP over Wi-Fi — making the entire pipeline both, flexible and cable-free.
Let’s get started to see how easy this is. We will walk through this Protip with a focus on audio data streaming as the application example. If you need a refresher on PDM microphones, we have got you covered in our this article.
Hardware SetupAll you need is the CY8CKIT-062S2-AI kit. The kit has two built-in IM72D128 digital microphones. The pins connected to the PDM-PCM bus in this kit are:
- CLK :
P10_4
- DATA:
P10_5
1. First, you need to have the MicroPython firmware running on your PSOC™ device. Find all the details on setting this up here.
2. Clone and set up the Capture Server repository by following the instructions provided in the Capture Server documentation.
3. Clone the GitHub repository where you will find the data acquisition scripts.
git clone https://github.com/Infineon/deepcraft-micropython-data-acquisition.git
Step 2. Start Sensor Data Acquisition on Device1. Once you have cloned the GitHub repository, open the location in any MicroPython supported IDE, like Thonny. Select all sources and copy them to the device by clicking on "Upload to / ".
Once they are successfully copied to device, you should see the following screen.
2. Now open config.py
on your MicroPython device, add your network credentials and save it on device.
# Add user configuration details
SSID = 'your-ssid'
PASSWORD = 'your-password'
PORT = 5000
3. Open the data_acquisition.py
script and click the play button.
1. From a command prompt terminal, navigate to the root of the cloned Capture Server repository. You must be already inside the folder called captureserver. Then go to the folder examples/generic.
cd examples/generic
2. Execute the Capture Server by running the following after replacing with actual parameters:
python generic_local_capture_interface.py --output-dir "Your output directory" --protocol TCP --ip-address "Your board's IP address" --port 5000 --data-format ".data or .wav" --data-type h --samples-per-packet "no. of samples" --features "no. of features" --sample-rate "sampling-rate" --video-disabled
Note that the parameters here should match your sensor configuration values in the data acquisition script as well. Taking the configuration for PDM microphone as example:
ip-address
: Is the ip-address of your device which you will see as printed output in terminal on running the data_acquisition.py script.data-format
:.wav (as for audio data)data-type
: h (short)samples-per-packet
: 512 (No. of samples in each packet also resembles the buffer size)features
: 1 (no. of features)sampling-rate
: 16000 (acceptable sampling rate by sensor)
The corresponding config in data_acquisition.py hence would look like:
For explanation on each of the parameters, please check the Capture Server documentation. With parameter values mentioned above, the command is as below:
python generic_local_capture_interface.py --output-dir data_out/ --protocol TCP --ip-address 192.168.1.3 --port 5000 --data-format .wav --data-type h --samples-per-packet 512 --features 1 --sample-rate 16000 --video-disabled
On running the Capture Server successfully, you would see an option to start recording, stop recording and quit as shown below:
Once done, the recorded data will be stored in the output directory mentioned above.
Step 4: Import to DEEPCRAFT™ Studio1. Launch DEEPCRAFT™ Studio and create a new project or open an existing one. Go to the DATA tab, click on the Add Data button, and choose the output directory containing the captured .wav
or .data
files along with their corresponding label files.
2. After selecting the output directory, DEEPCRAFT™ Studio will automatically import the audio/data files and their corresponding label files into a new data session.
3. After creating the data session, your dataset will be accessible within DEEPCRAFT™ Studio, ready for preprocessing, labeling, and training machine learning models. 🚀
And just like that, your sensor data is in the studio — ready for training in no time.
Code ExplanationCurious about what’s under the hood? Here's a deeper dive into the Python script running on the filesystem of your hardware.
1. Start with required imports.
import struct
import network_utils
from network_utils import connect_wifi
from tcp_server import create_server_socket
from sensors.pdm_pcm import PDM_PCM
struct
: Used to pack the buffer data into binary format before sending over TCP.network_utils
: Module handles Wi-Fi connection.tcp_server
: Sets up a TCP socket to listen for incoming connections.pdm_pcm
: Audio sensor module; this can be swapped with other sensors as needed.
2. Connects to Wi-Fi, sets up a TCP server using the device's IP address and waits for Capture Server (on your host machine) to connect.
def main(sensor):
ip = connect_wifi()
server_socket = create_server_socket(ip)
3. Initialize the sensor along with buffer to store the sensor data. Also prepare the format to stream the data.
sensor.init()
rx_buf = sensor.get_buffer()
endianness, fmt_str = sensor.get_format()
full_format = f"{endianness}{len(rx_buf)}{fmt_str}"
sensor.init()
: Initializes the sensor (e.g., sets clock, configures bus).get_buffer()
: Prepares a buffer to hold sampled data.get_format()
: Returns endianness (< or >) and data format (h, H, etc.).full_format
: Used for struct.pack to convert raw samples into a binary packet.
4. Wait for Capture Server to connect. This will show connected by printing the IP address only after you run the Capture Server script.
print("Waiting for capture-server to connect...")
conn, addr = server_socket.accept()
print(f"capture-server connected from {addr}")
5. Once done with all setup, start capturing data into the buffer, convert it to the required format and send it over TCP.
try:
while True:
sensor.read_samples(rx_buf)
packet = struct.pack(full_format, *rx_buf)
conn.sendall(packet)
6. Afterwards, close the connection and release all the resources.
finally:
conn.close()
server_socket.close()
sensor.deinit()
print("\nStreaming stopped.")
Using other SensorsWorking with a different sensor? It’s just as simple!
Head over to the Add your own sensor section to integrate your custom sensor and start streaming.
Got Problems with MicroPython for PSOC™ 6?Leave us a note here and we will do all it takes to fix it! 🚀
Curious for More?This article is covering the data acquisition process using MicroPython and DEEPCRAFT™ Studio. If you're looking for instructions on how to deploy your trained model using MicroPython stay tuned for our next Protip! Meanwhile, you have time to train & optimize your model.👩💻
Find additional information related to the PSOC™ 6 MicroPython enablement in our documentation or open a topic in our discussion section on GitHub.
Comments