如何在计算机上安装python以及如何在Arduino上使用python

步骤1:在计算机上安装python idle
如果您要已经在计算机中安装了python idle。如果是,请转到步骤2,否则请按照以下说明进行操作:
1。转到python网站并下载(此处)。
2。完成后,继续进行安装,方法是保留默认情况下安装python的目录。
注意:即使您的计算机运行在64位系统上,由于与arduino库的兼容性不足,您也可以使用32位python本身。
步骤2:观看视频以了解更多详细信息
步骤3:安装pyserial
pyserial是一个python api模块,用于向arduino或任何其他微控制器读取和写入串行数据。要在windows上安装,只需访问pyserial的下载页面,然后按照以下步骤操作:
1。从上面的链接下载pyserial。
2。通过将设置保留为默认值来安装它。您应该确保pyserial可以正常运行;为此,请输入:
import serial
(如果没有)没有遇到任何错误,所以您的状态很好,否则我建议您检查安装和python idle扩展。
步骤4:python代码
首先,我们需要一个简单的程序来使python通过串行端口发送数据。
import serial #serial imported for serial communication
import time #required to use delay functions
arduinounoserial = serial.serial(‘com15’,9600) #create serial port object called arduinounoserialdata time.sleep(2) #wait for 2 secounds for the communication to get established
print arduinounoserial.readline() #read the serial data and print it as line
print (“you have new message from arduino”)
while 1: #do this forever
var = raw_input() #get input from user
if (var == ‘1’): #if the value is 1
arduinounoserial.write(‘1’) #send 1 to the arduino‘s data code
print (“led turned on”)
time.sleep(1)
if (var == ’0‘): #if the value is 0
arduinounoserial.write(’0‘) #send 0 to the arduino’s data code
print (“led turned off”)
time.sleep(1)
if (var == ‘fine and you’): #if the answer is (fine and you)
arduinounoserial.write(‘0’) #send 0 to the arduino‘s data code
print (“i’m fine too,are you ready to !!!”)
print (“type 1 to turn on led and 0 to turn off led”)
time.sleep(1)
步骤5:arduino代码
要从python启动与arduino的连接,我们首先必须确定arduino处于哪个com端口。正如我在上图中通知的那样,此任务是由ardunio编程环境简单完成的。
int data;
int led=13;
void setup() {
serial.begin(9600); //initialize serial com at 9600 baudrate
pinmode(led, output); //declare the led pin (13) as output
digitalwrite (led, low); //turn off the led in the beginning
serial.println(“hello!,how are you python ?”);
}
void loop() {
while (serial.available()) //whatever the data that is coming in serially and assigning the value to the variable “data”
{
data = serial.read();
}
if (data == ‘1’)
digitalwrite (led, high); //turn on the led
else if (data == ‘0’)
digitalwrite (led, low); //turn off the led
}
步骤6:获得支持


利用供电线通讯实施的LED照明控制
ATECLOUD智能云测试平台助力企业创新发展数字化转型
摇摆LED时钟的设计及制作方法
锂亚电池基础知识
UPS与Wingcopter携手建立多种交付无人机机队
如何在计算机上安装python以及如何在Arduino上使用python
特斯拉对中央电源零组件进行严格测试
将人工智能技术应用于实验室进行科学研究
达尼丁正在寻求安装琥珀色LED照明的可能性
数字电路超声波发生器的基本原理
内存条作为电脑数据的中转站,其作用不可忽视
2012年半导体产业发展展望
亚洲电源展 | 国际交流贸易平台
E型载波系统基础知识
Maxim推出集成USB充电枚举器的汽车DC-DC转换器
金立S6Pro手机评测 既收敛了金属的锋芒又带来了无与伦比的视觉观感
浅谈铅酸蓄电池,电池致命的大电流杀手
改善无线充电器的方法
电源线RVV与RVS的对比,二者之间的区别是什么
特斯拉对日本铝进口产品实施关税豁免的请求获批