简体   繁体   English

如何使用 USB 端口将数据从 Arduino Uno 发送到 PC

[英]How to send data from Arduino Uno to PC using the USB port

I'm building an NFC project in which I have an Arduino Uno with a PN532 NFC shield that reads stored messages from tags.我正在构建一个 NFC 项目,其中我有一个带有 PN532 NFC 屏蔽的 Arduino Uno,可以从标签读取存储的消息。 What I'm trying to achieve is to store/write the information to a .csv file, but I need to send the data over the USB cable through which the Uno is connected to on my PC.我想要实现的是将信息存储/写入 .csv 文件,但我需要通过 USB 电缆发送数据,Uno 通过 USB 电缆连接到我的 PC。

Is there any way to write the data to .csv file onto the Arduino, then send the .csv file to the PC over the USB cable to a given directory, or write a program that reads the data being sent from the Uno through the USB cable, and then write the data on the PC to a .csv file?有没有办法将数据写入 .csv 文件到 Arduino,然后通过 USB 电缆将 .csv 文件发送到 PC 到给定目录,或者编写一个程序来读取通过 USB 从 Uno 发送的数据电缆,然后将 PC 上的数据写入 .csv 文件? I'm aware I could get a breadboard with an SD card reader, and write the data to an SD card but I'm trying to avoid this solution if possible.我知道我可以得到一个带有 SD 读卡器的面包板,并将数据写入 SD 卡,但如果可能的话,我会尽量避免这种解决方案。 Is there any way to send files or data over USB from Arduino to PC?有没有办法通过 USB 将文件或数据从 Arduino 发送到 PC?

I would definitely have the Arduino send the values over the USB interface and have the host run a Python program that uses the CSV library to write a .csv file.我肯定会让 Arduino 通过 USB 接口发送值,并让主机运行一个 Python 程序,该程序使用CSV 库来编写一个 .csv 文件。

You could simply "print" the values from the Arduino to the USB interface and read them on the host using /dev/ttyUSBx.您可以简单地将 Arduino 中的值“打印”到 USB 接口,然后使用 /dev/ttyUSBx 在主机上读取它们。 But at some point you might want to send control commands to the Arduino.但在某些时候,您可能想向 Arduino 发送控制命令。 And you might want to do some logging, catch errors, etc. If so, I suggest that you look at a full-fledged communication protocol.你可能想做一些日志记录、捕获错误等。如果是这样,我建议你看看一个成熟的通信协议。 I realize you're not controlling a robot, but rosserial from Robot Operating System (ROS) would make this easy.我意识到你不是在控制机器人,但来自机器人操作系统 (ROS) 的rosserial会让这变得简单。 It might feel like overkill but I think you'll appreciate the features once you start using it.这可能感觉有点矫枉过正,但我​​认为一旦您开始使用它,您就会喜欢这些功能。

Do you need an example?你需要一个例子吗?

I found a solution using php.我找到了使用 php 的解决方案。 This way I can send and receive data from Arduino and PC.这样我就可以从 Arduino 和 PC 发送和接收数据。 This is the link https://stackoverflow.com/a/64593069/1735122这是链接https://stackoverflow.com/a/64593069/1735122

enjoy.请享用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM