python to arduino serial read & write

前端 未结 3 1140
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 15:29

I\'m trying to \"ping pong\" info back and forth between some python code and arduino code. I want to send two setpoints to the arduino code periodically (for instance on th

3条回答
  •  半阙折子戏
    2020-12-08 16:21

    First you have to install a module call Serial. To do that go to the folder call Scripts which is located in python installed folder. If you are using Python 3 version it's normally located in location below,

    C:\Python34\Scripts  
    

    Once you open that folder right click on that folder with shift key. Then click on 'open command window here'. After that cmd will pop up. Write the below code in that cmd window,

    pip install PySerial
    

    and press enter.after that PySerial module will be installed. Remember to install the module u must have an INTERNET connection.


    after successfully installed the module open python IDLE and write down the bellow code and run it.

    import serial
    # "COM11" is the port that your Arduino board is connected.set it to port that your are using        
    ser = serial.Serial("COM11", 9600)
    while True:
        cc=str(ser.readline())
        print(cc[2:][:-5])   
    

提交回复
热议问题