📜 ⬆️ ⬇️

As I stepped on a rake and figured out with the NanoPi2

About 3 months ago, I got the idea to make a race on typewriters controlled via the Internet.

Analogue micro- racing and race tarantasov . Both of these projects have stalled, for one reason or another.

I began to select a single-board, which would be most suitable for this project. You could use virt2real or Raspberry PI, well, or in extreme cases, tp-link tl-mr3020 with CyberWRT on board.

But I came across a NanoPi2 board, which, as I thought then, is a complete clone of the Raspberry PI, only smaller in size, and with WI-FI on board.
')
I ordered a fee in the amount of 2 pieces and began to expect when they would come, the seller was not very decent from Blagoveshchensk and first told me one thing, then the other, promised various buns in the form of gifts.

But somehow, after 1.5 months, the fees came to me. I want to pay tribute to the Chinese, when I ordered additional cameras from them for this board, they came in 1.5 weeks.

Actually, when the boards arrived, I started installing modules for my project.

The first deep disappointment struck me when I was unable to connect a Logitech c270 camera. I tried various programs under Debian, which I have installed as an operating system. In the end, I achieved the translation of the video stream into the grid, it turned out that the configuration file in the Motion program changed, and those variables that had to be changed were called differently. I upload the working configuration file for Motion here

Installation of motion is simple to disgrace.
-----------  ----------- # apt-get update # apt-get upgrade -----------  Motion ----------- # apt-get install motion ----------- ,    (   Logitech c270). ----------- #lsusb ----------- 

The console gives us something like this.

 Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 002: ID 046d:0825 Logitech, Inc. Webcam C270 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 


Where the 2nd line shows us that the camera is connected to our computer.

Next we need to fix the configuration file.

We pass to the folder / etc / motion and replace the file motion.conf (with the one I posted above by reference). For this, I use WinSCP.

Well, then the most interesting thing began, it was necessary to somehow manage the GPIO outputs. As I wrote earlier, the board was an incomplete clone of the Raspberry Pi. So all the libraries for working with GPIO, from the malinki were overboard.

I found 2 matrix-python and matrix libraries. But unfortunately both libraries didn't suit me very much.

In the first, there was functionality for working with GPIO, but there was no functionality for working with PWM to connect a servo drive. The second turned out to be at all on C, and I am not very friendly with the sami.

In general, I began to deal with ctypes , I’ll immediately tell you that a lot of copies were broken, it would connect to the library, but function calls returned various errors such as contact could not be used. I even started looking for a freelancer who would help me to make a wrapper for the matrix library, I found a couple of people but they were busy and I didn’t have time to talk specifically with a person on Skype. And then it dawned on me, we must completely repeat the code, which was cited as an example in C.

The very first attempt, even without one of the functions, was crowned with success; well, I did not think that the boardInit () function actually initialized the library. And that's what came out of it.

The program works with PWM in Python.

 import os import time from ctypes import * lib = cdll.LoadLibrary('/root/matrix-master/lib/libfahw.so') lib.boardInit() os.system("modprobe matrix_pwm") lib.PWMPlay(0, 1000, 1) time.sleep(5) i = 1 while i < 1000: print(i) i = i + 10 time.sleep(1) lib.PWMPlay(0, 1000, i) lib.PWMStop(0) 


Program for working with GPIO on Python.

 import os import time from ctypes import * lib = cdll.LoadLibrary('/root/matrix-master/lib/libfahw.so') lib.boardInit() os.system("modprobe matrix_gpio_int") lib.exportGPIOPin(22) lib.setGPIODirection(22, 2) lib.setGPIOValue(22, 1) time.sleep(5) lib.setGPIOValue(22, 0) lib.unexportGPIOPin(22) print 222 


Accordingly, in order to start working with the library, it is necessary to download it from the site and install it.

At the moment, I have already deployed the server on Flask, on the NanoPi2, and are already starting to connect the servo drive and the engine of the broken son's machine.

Source: https://habr.com/ru/post/372613/


All Articles