Python and hardware-Using RS232C with Python-

It's a memo that I'm looking into for studying because it's becoming necessary. Please note that it is a memo by a person who rarely confirms the contents on the actual machine.

When controlling hardware, the library used tends to differ depending on the type of CPU and OS.

#include <windows.h>


 Often contains the line.
 As it is, it cannot be used on other OS.


### ** Highly portable serial port library (C ++) Boost **
 Boost, which provides a common OS-independent library, provides a library for serial ports.
[Boost.Asio](http://www.boost.org/doc/libs/1_59_0/doc/html/boost_asio.html)
[Serial Ports](http://www.boost.org/doc/libs/1_60_0/doc/html/boost_asio/overview/serial_ports.html)
 Commentary article [[Boost] serial communication](http://blog.livedoor.jp/k_yon/archives/52145222.html)
 [Try serial communication with Boost.Asio](https://blog.myon.info/blog/2015-04-19/boost-asio-serial/)

[Boost C++ libraries for Raspberry Pi](https://www.raspberrypi.org/forums/viewtopic.php?&t=8111)
 It is stated that Boost C ++ libraries can be built on Raspberry Pi.
 Libraries only (static + dynamic) is open to the public.



### ** USB serial conversion cable **
 Recently, even PCs have no RS232C port, so a USB serial conversion cable and a USB serial conversion driver are required.



 [USB-serial conversion IC CP2102 driver installation method explanation](http://www.cqpub.co.jp/INTERFACE/contents/special/CP2102install/index.htm)


 How to change the COM port number via USB-serial on Windows
 [Change device manager COM port](http://www.geocities.jp/bokunimowakaru/diy/com/com_port.html)

 [Distinguishing multiple serial ports and devices on Linux](http://tclip.blog.fc2.com/blog-entry-86.html)

 On Linux (including Raspberry Pi), IO for USB-serial conversion is
/dev/ttyUSB0
 It is displayed with the device name such as.


 Zynq USB-UART driver
 [ISE & Vivado Settings on Ubuntu]
(http://masahir0y.blogspot.jp/2013_12_01_archive.html)
 even here
/dev/ttyUSB0
 Device name is displayed.


**PySerial**
 What I can do with Python is what I want to do with Python. For me, I decided to check out the library for Python.

 [Learn Python with hardware](http://www.slideshare.net/yutakitagami/python-6744817)

 Those with little OS dependency
 ・ [PySerial distributor](https://github.com/pyserial/pyserial)
 -[About pySerial module How to use serial device with Python](http://python.matrix.jp/pages/modules/pyserial.html) Example of sending with Python (windows)
 -[A python serial communication module that works on Macs that use pySerial. ](Https://sites.google.com/site/hananekosugan/manual-tips/python/pyserial) There are examples of sending and receiving
 ・ [Serial communication from mac to arduino using pyserial](https://dek1ymt2.wordpress.com/2014/05/03/pyserial%E3%82%92%E4%BD%BF%E3%81] % A3% E3% 81% A6-mac% E3% 81% 8B% E3% 82% 89arduino% E3% 81% AB% E3% 82% B7% E3% 83% AA% E3% 82% A2% E3% 83 % AB% E9% 80% 9A% E4% BF% A1% E3% 82% 92% E3% 81% 97% E3% 81% 9F /) Send from Python (Mac), receive example with arduino C ++
 -[Serial communication with Python](http://qiita.com/kosystem/items/0023cfee941fdf099087) Installation method, transmission example, reception example

 -[Serial communication with pySerial / pyWin32, but reception ...](http://omoitsuki-teck.cocolog-nifty.com/blog/2009/10/pyserialpywin32.html) Send / receive example
 -[Serial communication with Python (2)](http://blog.livedoor.jp/baruth_/tag/pyserial) Send / receive example
 -[Serial communication with Python](http://qiita.com/kosystem/items/0023cfee941fdf099087)

 The COM port number to be connected is the USB-serial port number when the COM port is displayed in Device Manager before and after the USB-serial is connected.


 On Linux machines, including the Raspberry Pi, you can see the device name under / dev by ls. I saw / dev / ttyUSB0.
 Even if you write using PySerial, the windows com port or Linux device name remains in the python script. But that's the only difference, so it's very easy to describe.
 Access to that port can be described in the same way as access to a file object, so it's easy to think about.


 [Serial communication with Raspberry Pi (same for Mac)](http://blog.livedoor.jp/hack_le/archives/44765804.html)
 > GPIO or USB
 > Since RPi does not have a serial port, it goes without saying that serial communication will be performed from other interfaces. Is it a GPIO pin on the board or a USB terminal? I think it's the GPIO pin that doesn't cost money.
 > USB-serial
 > When the other party's connection destination is a serial port. The IO-DATA conversion adapter USB-RSAQ6 worked.

[Install PySerial on Raspberry Pi (YouTube)](https://www.youtube.com/watch?v=I7fyFb7gNEQ)


 [Serial communication with RaspberryPi3](http://qiita.com/yamamotomanabu/items/33b6cf0d450051d33d41)



**PyUSB**
[PyUSB - Easy USB access on Python](https://walac.github.io/pyusb/) 
>PyUSB comes with builtin backends for libusb 0.1, libusb 1.0 and OpenUSB.

 [Source of module that executes bulk transfer by specifying pipe number using PyUSB](http://vega.ence.kyushu-u.ac.jp/wiki/Python/PyUSB)

 It does not matter when using USB-Serial.



### ** USB camera **
 If the power supplied to the USB camera is insufficient, the USB camera will not be recognized. Use a powered USB hub.
 If the USB camera is recognized by Windows without a special driver, it will be recognized by Raspberry Pi as it is.

 -[Use a UVC (USB Video Class) type USB camera on Linux]
(http://qiita.com/nonbiri15/items/9593d61a2be81f2b31a9)

 -[Surveillance camera with Raspberry Pi](http://qiita.com/matyapiro31/items/6e3edcd3d7f7dfc2771f)

 -[Troubleshooting with OpenCV installed on Raspberry Pi and capturing]
(http://qiita.com/sy_sft_/items/ddcad27f0ea13e2cd662)

 -[Try using an infrared camera module with Raspberry Pi](http://qiita.com/kinpira/items/940f34e11d1f856c5880)


### ** Machine dependencies are inevitable **

GPIO
 ・ [Raspberry Pi] LED blinking in GPIO (Python) http://make.bcde.jp/category/5/
 -Raspberry Pi GPIO input / output sample (Python, C language, shell script)
http://netlog.jpn.org/r271-635/2013/01/raspberry_pi_gpio_test.html

 ・ [[Raspberry Pi] Control the DC motor with the motor driver board](http://denshi.blog.jp/Raspberry+Pi/DC%E3%83%A2%E3%83%BC%E3%82%BF % E3% 83% BC% E5% 88% B6% E5% BE% A1
)

 -[Communication between serial and Arduino on GPIO of Raspberry PI]
(http://qiita.com/ryugyoku/items/bf5fd10512c84a55d030)

 ・ [I tried GPIO of Raspberry Pi (LED Pika version)](http://qiita.com/thuydg@github/items/bd5f3e2cd0fabac9195e)


### Notes on Python on FPGA-enabled boards
 [Install OpenCV 2.4.10 on Ubuntu 14.04 LTS of ARMhf of ZYBO](http://marsee101.blog19.fc2.com/blog-category-113.html)
 Since this page is building OpenCV and python is specified at CMake, it seems certain that python can be used on a board using Zilinx's Zynq.


#### A collection of frequently used libraries for Raspberry Pi
 [Import Python modules into Raspberry Pi](http://okuzawats.com/python-20140917)
 Used by scipy, numpy, PySerial on Raspberry Pi

[Numpy/Scipy/Matplotlib on Raspberry Pi]
(http://wyolum.com/numpyscipymatplotlib-on-raspberry-pi/)
 You can display the graph using matplotlib as shown in.

[Upgrading skimage version on Raspberry pi](http://stackoverflow.com/questions/29950941/upgrading-skimage-version-on-raspberry-pi)
 You can compile from source code as described in.


 About the port number of the COM port
 > In Microsoft's MS-DOS and Windows environments, refer to the serial port as a COM port. As COM1, COM2, .. etc. Ports with numbers higher than COM9 must be referenced using \\. \ COM10 syntax
https://ja.wikipedia.org/wiki/%E3%82%B7%E3%83%AA%E3%82%A2%E3%83%AB%E3%83%9D%E3%83%BC%E3%83%88



**RS485**
 There is a Python library that supports the serial communication standard called RS485.

pyserial/serial/rs485.py

https://github.com/pyserial/pyserial/blob/master/serial/rs485.py


 It's interesting how it can be used.



### Other IO

 Raspberry Pi IO information by ryo
http://rest-term.com/technote/index.php/IoT


 Reference articles not limited to Python
 [Serial connection of Raspberry Pi](http://qiita.com/tamamius/items/c0bca839e1ec97125413)


Recommended Posts

Python and hardware-Using RS232C with Python-
Programming with Python and Tkinter
Encryption and decryption with Python
python with pyenv and venv
Works with Python and R
Communicate with FX-5204PS with Python and PyUSB
Shining life with Python and OpenCV
Robot running with Arduino and python
Install Python 2.7.9 and Python 3.4.x with pip.
AM modulation and demodulation with python
[Python] font family and font with matplotlib
Scraping with Node, Ruby and Python
Scraping with Python, Selenium and Chromedriver
Scraping with Python and Beautiful Soup
JSON encoding and decoding with python
Hadoop introduction and MapReduce with Python
[GUI with Python] PyQt5-Drag and drop-
Reading and writing NetCDF with Python
I played with PyQt5 and Python3
Reading and writing CSV with Python
Multiple integrals with Python and Sympy
Coexistence of Python2 and 3 with CircleCI (1.0)
Easy modeling with Blender and Python
Sugoroku game and addition game with python
FM modulation and demodulation with Python
Communicate between Elixir and Python with gRPC
Data pipeline construction with Python and Luigi
Monitor Mojo outages with Python and Skype
Statistics with python
FM modulation and demodulation with Python Part 3
[Automation] Manipulate mouse and keyboard with Python
Scraping with Python
Passwordless authentication with RDS and IAM (Python)
Python with Go
Python installation and package management with pip
Using Python and MeCab with Azure Databricks
POST variously with Python and receive with Flask
Capturing images with Pupil, python and OpenCV
Twilio with Python
Fractal to make and play with Python
A memo with Python2.7 and Python3 on CentOS
Integrate with Python
Play with 2016-Python
Use PIL and Pillow with Cygwin Python
AES256 with python
Tested with Python
Create and decrypt Caesar cipher with python
python starts with ()
CentOS 6.4 with Python 2.7.3 with Apache with mod_wsgi and Django
Reading and writing JSON files with Python
Dealing with "years and months" in Python
with syntax (Python)
I installed and used Numba with Python3.5
Tweet analysis with Python, Mecab and CaboCha
Linking python and JavaScript with jupyter notebook
Traffic monitoring with Kibana, ElasticSearch and Python
FM modulation and demodulation with Python Part 2
Bingo with python
Zundokokiyoshi with python
Encrypt with Ruby (Rails) and decrypt with Python
Easily download mp3 / mp4 with python and youtube-dl!