SERob3 (python) - pyfirmata – Ինչպե՞ս SERob ղեկավարիչին միացնել Arduino

Post Reply
davbaghdasaryan
Posts: 101
Joined: Thu Apr 09, 2020 8:08 pm

SERob3 (python) - pyfirmata – Ինչպե՞ս SERob ղեկավարիչին միացնել Arduino

Post by davbaghdasaryan »

How to connect Arduino with SERob controller | Как к SERob контроллеру подключить Arduino


Այսօր մենք SERob3 ղեկավարիչին կմիացնենք Arduino Uno եւ կփորձենք կարդալ նրա Pin-երը եւ տալ նրանց արժեքներ։
Մեզ անհրաժեշտ է․
1) SERob3 ղեկավարիչ (controller),
2) Arduino Uno,
3) 2 լեդ լույս՝ իրենց ռեզիստորներով,
4) լարեր,
5) փոփոխական ռեզիստոր,
6) գծին հետեւող սենսոր,
7) մակետային սալիկ (breadboard)՝ ըստ ցանկության:

Սխեման կարող եք հավաքել ըստ հետեւյալ նկարի
Տեսնել նկարը
picture1.png
picture1.png (170.79 KiB) Viewed 10828 times
USB-ով Arduino-ն միացնենք SERob3 ղեկավարիչին անալոգ եւ թվային (digital) Pin-երից։ Մուտքագրելու ենք թվային (digital) եւ PWM Pin-երի արժեքները։
Տեսնել նկարը
picture2.png
picture2.png (159.36 KiB) Viewed 10828 times
Ծրագիրը ստեղծելու համար օգտվում ենք «pyfirmata» եւ «time» գրադարաններից։ «Pyfirmata»-ն գտնվում է «SERob3» կատալոգում։ Այնուհետեւ նշենք մեր սալիկը (board)՝ Arduino եւ թե ուր է այն միացված USB-ի միջոցով
Սեղմեք այստեղ

Code: Select all

from SERob3 import pyfirmata
import time
board = pyfirmata.Arduino('/dev/ttyACM0')
Գծին հետեւող սենսորը միացված է 7-րդ Pin-ին: Դրա արժեքը կարդալու համար գրում ենք «d:7:i», որտեղ «d»-ն նշանակում է թվային (digital), 7-ը Pin-ի համարն է, «i»՝ ներմուծում (input)։
Առաջին լույսին տալիս ենք «d:5:p», որտեղ «d»-ն նշանակում է թվային (digital), 5-ը Pin-ի համարն է, «p»՝ pwm, որը կարող է ստանալ 0-255 արժեք։
Երկրորդ լույսին, որը միացված է 6-րդ Pin-ին, տալիս ենք «d:6:օ», որտեղ «о» նշանակում է թվային (digital) output․ կարող է ունենալ 0 կամ 1 արժեքը։
Փոփոխական ռեզիստորի արժեքը կարդալու համար գրում ենք «a:0:i», որտեղ «а»-ն նշանակում է անալոգային, 0, Input` ներմուծում.
Սեղմեք այստեղ

Code: Select all

pin = board.get_pin('d:7:i')
led = board.get_pin('d:5:p')
led2 = board.get_pin('d:6:o')
potentiometer = board.get_pin('a:0:i')
Անալոգը կարդալու համար անպայման է սկսել «Iterator» գործողությունը հետեւյալ հրամանով. «i=pyfirmata.until.Iterator(board)»:
Սեղմեք այստեղ

Code: Select all

i = pyfirmata.util.Iterator(board)
i.start()	
Այնուհետեւ՝ ստուգումները կատարելուց առաջ, սպասում ենք 0․1 վայրկյան՝ «time.sleep(0.3)»։
Աշխատանքը հեշտացնելու համար տպում ենք գծին հետեւող սենսորից եւ փոփոխական ռեզիստորից ստացված արժեքները։
Առաջին լույսին տալիս ենք փոփոխական ռեզիստորից ստացված արժեք, իսկ երկրորդ լեդին՝ գծին հետեւող սենսորից ստացված արժեքը։
Սեղմեք այստեղ

Code: Select all

while True:
    time.sleep(0.1)
    print(pin.read())
    print(potentiometer.read())
    led.write(potentiometer.read())
    led2.write(pin.read())
Code example:

Code: Select all

from SERob3 import pyfirmata
import time
board = pyfirmata.Arduino('/dev/ttyACM0')
pin = board.get_pin('d:7:i')
led = board.get_pin('d:5:p')
led2 = board.get_pin('d:6:o')
potentiometer = board.get_pin('a:0:i')

i = pyfirmata.util.Iterator(board)
i.start()	

while True:
    time.sleep(0.1)
    print(pin.read())
    print(potentiometer.read())
    led.write(potentiometer.read())
    led2.write(pin.read())

Նշում ենք այն կատալոգը, որտեղ գտնվում է ծրագիրը։ Դրա համար գրում ենք․ «cd projects», «cd SERob3»։ Այնուհետեւ աշխատացնում ենք ծրագիրը․ «sudo python2» եւ ֆայլի անվանումը՝ «ardpins.py»:
Տերմինալի հրամաններ

Code: Select all

cd projects
cd SERob3
sudo python2 ardpins.py
Արդյունքում տպվում են սենսորներից ստացված տվյալները եւ դրանց համապատասխան վառվում են լույսերը։

Հավելյալ ՝ viewtopic.php?f=8&t=32&sid=bb54feab3b41 ... eb098c916d

Last edited by davbaghdasaryan on Mon Aug 02, 2021 3:02 pm, edited 2 times in total.

davbaghdasaryan
Posts: 101
Joined: Thu Apr 09, 2020 8:08 pm

Урок #8 (pyfirmata) – Как к SERob контроллеру подключить Arduino

Post by davbaghdasaryan »

Сегодня мы к SERob контроллеру подключим Arduino Uno, попытаемся прочитать его Pin-ы и присвоить им значения.
Нам необходимы:
1) SERob3 контроллер (controller),
2) Arduino Uno,
3) 2 светодиода со своими резисторами,
4) провода,
5) переменный резистор,
6) датчик отслеживания линии,
7) макетная плата (breadboard), по желанию.

Собрать схему можно по следующему рисунку:
picture1.png
picture1.png (170.79 KiB) Viewed 10530 times
Подключим Arduino к SERob3 контроллеру с аналоговых и цифровых (digital) Pin-ов через USB. Будем вводить значения цифровых (digital) и PWM Pin-ов.
picture2.png
picture2.png (159.36 KiB) Viewed 10530 times
Для создания программы воспользуемся библиотеками "pyfirmata" и "time". "Pyfirmata" находится в каталоге "SERob3". Далее укажем нашу плату (board)- Arduino, и куда она подключена через USB.
Датчик отслеживания линии подключен к 7-му Pin-у. Чтобы прочитать его значение, мы пишем "d: 7: i", где "d" означает цифровой (digital), 7 - номер Pin-а, "i" - ввод (input).
Первому светодиоду присваиваем "d:5:p", где "d" означает цифровой (digital), 5 - номер Pin-а, "p" - pwm, который может принимать значения от 0 до 255.
Второму светодиоду, который подключен к 6-му Pin-у, задаем "d:6:օ", где "о" означает цифровой (digital) output․ Может принимать значения 0 или 1.
Чтобы прочитать значение переменного резистора, мы пишем "a: 0: i", где "a" означает аналоговый, 0, а Input означает ввод.
Code:

Code: Select all

pin = board.get_pin('d:7:i')
led = board.get_pin('d:5:p')
led2 = board.get_pin('d:6:o')
potentiometer = board.get_pin('a:0:i')
Чтобы прочитать аналог, обязательно запустить операцию "Iterator" по следующей команде: "i=pyfirmata.until.Iterator(board)".
Code:

Code: Select all

i = pyfirmata.util.Iterator(board)
i.start()
Затем перед выполнением проверок ждем 0–1 секунду - "time.sleep (0.3)".
Для облегчения задачи печатаем значения, полученные с датчика отслеживания линии и переменного резистора.
Первому светодиоду задаем значение, полученное от переменного резистора, а второму - значение, полученное от датчика отслеживания линии.
Code:

Code: Select all

while True:
    time.sleep(0.1)
    print(pin.read())
    print(potentiometer.read())
    led.write(potentiometer.read())
    led2.write(pin.read())
Code example:

Code: Select all

from SERob3 import pyfirmata
import time
board = pyfirmata.Arduino('/dev/ttyACM0')
pin = board.get_pin('d:7:i')
led = board.get_pin('d:5:p')
led2 = board.get_pin('d:6:o')
potentiometer = board.get_pin('a:0:i')

i = pyfirmata.util.Iterator(board)
i.start()	

while True:
    time.sleep(0.1)
    print(pin.read())
    print(potentiometer.read())
    led.write(potentiometer.read())
    led2.write(pin.read())

Указываем каталог, в котором находится программа. Для этого пишем: "cd projects", "cd SERob3". Затем запускаем программу - "sudo python2", и название файла - "ardpins.py".
В результате данные, полученные от датчиков, печатаются, и в соответствии с ними включаются светодиоды.
Terminal:

Code: Select all

cd projects/
cd SERob3/
sudo python2 ardpins.py

davbaghdasaryan
Posts: 101
Joined: Thu Apr 09, 2020 8:08 pm

How to connect Arduino with SERob controller

Post by davbaghdasaryan »

Today we will connect the Arduino with the SERob3 controller and try to read its Pin-s and give them values.
This requires:
1)SERob3 controller
2)Arduino Uno
3)2 LED lights with their resistors
4)wires
5)variable resistor
6)line tracking sensor
7)breadboard(optionally)

The scheme
You can assemble the scheme according to the following picture.

picture
picture1.png
picture1.png (170.79 KiB) Viewed 10501 times
Connect the Arduino with the analog and digital Pin-s of the SERob3 controller by USB.
picture
picture2.png
picture2.png (159.36 KiB) Viewed 10501 times
For creating the program we use “pyfirmata” and “time” libraries. “Pyfirmata” is located in “SERob3” catalogue. Then mention our (board) Arduino and the place where it is connected via USB.
Code:

Code: Select all

from SERob3 import pyfirmata
import time
board = pyfirmata.Arduino('/dev/ttyACM0')
The line tracking sensor is being connected with the Pin 7. In order to read its value, type “d:7:i”, where the “d” means digital, the “7” is the Pin number and the “i” means input.
Let’s give “d:5:p” to the first light where the “d” means digital, the “5” is the Pin number and the “p” is pwm and it can receive values 0-255.
Give the “d:6:o” to the second light which is connected with Pin 6, where the “o” means digital output and can have 0 or 1 values.
In order to read the variable resistor value, type “a:0:i:, where “a” means analog, 0, “i” means input.

Code:

Code: Select all

pin = board.get_pin('d:7:i')
led = board.get_pin('d:5:p')
led2 = board.get_pin('d:6:o')
potentiometer = board.get_pin('a:0:i')
For reading the analog it’s necessary to start the “Iterator” process with such a command as follows: “i=pyfirmata.until.Iterator(board)”.
Code:

Code: Select all

i = pyfirmata.util.Iterator(board)
i.start()	
Then wait for 0.1 seconds before turning to checkings (“time.sleep(0.3)).
In order to ease the process print the values received from the line tracking sensor and variable resistor.
Give the value received from the variable resistor to the first light and give the value received from the line tracking sensor to the second LED
Code:

Code: Select all

while True:
    time.sleep(0.1)
    print(pin.read())
    print(potentiometer.read())
    led.write(potentiometer.read())
    led2.write(pin.read())
Code example:

Code: Select all

from SERob3 import pyfirmata
import time
board = pyfirmata.Arduino('/dev/ttyACM0')
pin = board.get_pin('d:7:i')
led = board.get_pin('d:5:p')
led2 = board.get_pin('d:6:o')
potentiometer = board.get_pin('a:0:i')

i = pyfirmata.util.Iterator(board)
i.start()	

while True:
    time.sleep(0.1)
    print(pin.read())
    print(potentiometer.read())
    led.write(potentiometer.read())
    led2.write(pin.read())

Mention the catalogue where the program is located as follows: “cd projects”, “cd SERov3”. Then let’s run the program as follows: “sudo python2” and the filename as “ardpins.ру”.
The data received from sensors are being printed as a result and the lights are on depending on this data.

Terminal:

Code: Select all

cd projects
cd SERob3
sudo python2 ardpins.py
learn more ՝ viewtopic.php?f=8&t=32&sid=bb54feab3b41 ... eb098c916d


Post Reply