I-Anaconda (iPython) yeArduino yakho

Logo yeAnaconda

I-Anaconda yindawo yasimahla kunye nevulekileyo yolwimi lwenkqubo yePython (kunye no-R). Khumbula, lolunye lweelwimi ezisetyenziswa kakhulu namhlanje kwaye oko kukuvumela ukuba wenze izikripthi, kuba lulwimi olutolikwayo. Ke ngoko, ixhomekeke kwitoliki yePython ukuze umatshini aqonde kwaye ayenze. Ngokwahlukileyo, iilwimi ezihlanganisiweyo ziguqulelwa kwi-binary enokuqondwa ngqo ngumatshini ngaphandle komlamli.

Ewe, Anaconda Isetyenziswa ngokubanzi kwicandelo lezemfundo kunye nokufunda ngomatshini. Kodwa yintoni ungasebenzisa ukulawula ibhodi yeArduino. Ewe ngokuchanekileyo, unokusebenzisa ulwimi lwenkqubo yePython ukwenza iinkqubo zakho zokulawula iArduino ngaphandle kwengxaki kwaye ngendlela elula. Apha siza kuchaza ukuba ungayenza njani inyathelo ngenyathelo ...

Yintoni iAnaconda

Ewe, sele uyazi ukuba yintoni i-python distribution, kwaye ke yabelana ngeempawu nePython esemthethweni. Kodwa inika izibonelelo ngaphezulu kwePython, ngaphandle kokuba yindawo enqamlezileyo kunye nomthombo ovulekileyo, onje:

  • Uyakuvumela faka kwaye ulawule iiphakheji, ukuxhomekeka kunye nemeko yenzululwazi yedatha ngendlela elula.
  • Ivumela ukusetyenziswa kweendawo ezahlukeneyo zenkqubo okanye ii-IDE, phakathi kwazo nazo ungayisebenzisa ngeArduino, Raspberry Pi, njl.
  • Akhawunti herramientas ezinje nge-numpy, Numba, Dask, Bokeh, Datashader, Holoviews, Matplotlib, njl, ukuhlalutya nokubona idatha.
  • Ivumela yenza python kwikhowudi yomatshini endaweni yokutolikwa ngokukhawuleza. Oko kukuthi, kuya kuba lulwimi oluhlanganisiweyo.
  • Ivumela bhala ngakumbi, ukusebenza okuphezulu, kunye neenkqubo eziphathwayo phakathi kwamaqonga okuthatha iiprojekthi zakho naphina apho ufuna khona.

Iinkcukacha ezithe xaxe - Faka uAnaconda

I-API yokusebenzisa neArduino

IArduino kunye nePython logo

ukuba ukusebenzisa iPython ukulawula iArduino uyakufuna i-API. Nje ukuba ufake iAnaconda kwinkqubo yakho yokusebenza, unga faka i-API ngendlela elula kakhulu. Ilula njengokutsalela i-anaconda kumgca wokuyalela, ngalo mzuzu iqokobhe lakho liya kutshintsha liye kwi-Anaconda Prompt, kwaye ngaphakathi ungasebenzisa lo myalelo ulandelayo kunye ne-conda iya kukhathalela yonke into

conda install -c auto arduino-python

Nje ukuba i-arduino-python ifakiwe, sele ikho ungaqala ukuyisebenzisa ngeeprojekthi zakho zeArduino. Kodwa okokuqala, kuya kufuneka ulungiselele imeko-bume ukudala imeko-bume entsha yeprojekthi yakho yokuqala yeArduino. Ukwenza oku, ngaphakathi kwe-Anaconda Prompt ungasebenzisa lo myalelo ulandelayo ucacisa igama kunye nohlobo lolwimi lwePython oza kulusebenzisa. Umzekelo:

conda create --name arduino python=3.7

Ngoku imeko ebonakalayo "i-arduino" sele yenziwe ukuba isetyenziswe nge-Python version 3.7. It elandelayo kukuyenza isebenze:

conda activate arduino

Nje ukuba usebenze, gcina le window, ungayivaleli, njengoko uza kuyisebenzisa kamva. Ungayibona njani lonto ukukhawuleza ngoku (arduino)> ukuze uqalise. Kuya kuba lula ukuba ufake ngoku iiphakheji oza kuzifuna, ezinje ngePySerial yokunxibelelana nebhodi yeArduino. Ukwenza oku, sebenzisa nje kwangoko kwangoko:

conda install pyserial

Kulungile ngoku khuphela kwaye ufake iArduino IDE Ukuba ubungenayo, ukuba ubuyenzile, emva koko ungaqhubekela kwinqanaba elilandelayo, elilelo lokubhala ikhowudi kwiPython ukulawula iprojekthi yeArduino. Ungabhala inkqubo elula okanye usebenzise imizekelo eza neArduino IDE ukuvavanya.

por ejemplo, yiya kwiArduino IDE> Ifayile> Imizekelo> Unxibelelwano> iPhysicalPixel kwaye uyilayishe kwibhodi yakho yeArduino edityaniswe kwiPC yakho. Nje ukuba umzobo usebenze, ungasebenzisa iPython njengokuba ubuya kwibhodi yeRaspberry Pi kunye nee-GPIOs ukutshintsha iziphumo. Umzekelo, kule meko ukucima i-LED okanye ukuyicima ngentando ngekhowudi elula yePython.

Ukwenza oku, unako buyela kwiwindows yakho kwaye ungene kwi-Anaconda Prompt Yenza oku kulandelayo:

> conda activate arduino
(arduino) > python

Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> import serial
>>> ser = serial.Serial('COM4', 9800, timeout=1)
>>> ser.write(b'H')
>>> ser.write(b'L')
>>> ser.close()
>>> exit()
(arduino) >

Oko kuyakwenza Umsebenzi obhalwayo unokucima (L) okanye uvule i-LED (H) ngokuthanda. Emva koko ser.close () iphela kwaye exit () iyaphuma. Ke unokulawula iiprojekthi zakho zeArduino ngePython. Ngokucacileyo lo ngumzekelo nje, kodwa unokucinga iimeko ezininzi ngakumbi ...

Unako kwakhona yenza iifayile ze-py ngeempendulo zePython bakwazi ukubenza nanini na ngaphandle kokukwenza ngokuthe ngqo kwi-anaconda Prompt. Umzekelo le enye:

# Ejemplo titileo_LED.py

import serial
import time

# Define el puerto serie
# Debes comprobar desde el gestor de dispositivos de tu sistma operativo a qué puerto se corresponde el USB de la placa Arduino, en Windows sería COM4 en nuestro caso
ser = serial.Serial('COM4', 9600)

def led_on_off():
    user_input = input("\n Elige comando: encendido / apagado / quitar : ")
    if user_input =="encendido":
        print("LED está encendido...")
        time.sleep(0.1) 
        ser.write(b'H') 
        led_on_off()
    elif user_input =="apagado":
        print("LED está apagado...")
        time.sleep(0.1)
        ser.write(b'L')
        led_on_off()
    elif user_input =="quitar" or user_input == "q":
        print("Salir del programa")
        time.sleep(0.1)
        ser.write(b'L')
        ser.close()
    else:
        print("Comando no válido")
        led_on_off()

time.sleep(2) # Espera a que el puerto serie inicialice 

led_on_off()

Inyaniso elula? Ngapha koko, ukuba ubusele uyazi ulwimi lwePython, konke oku kuya kuba lula kakhulu kuwe. Kuya kufuneka usebenze kuphela .py kwaye unxibelelane neenketho zonxibelelwano zenkqubo yokufaka imiyalelo yokuvula, ukucima okanye ukuphuma kwenkqubo kule meko.


Yiba ngowokuqala ukuphawula

Shiya uluvo lwakho

Idilesi yakho ye email aziyi kupapashwa. ezidingekayo ziphawulwe *

*

*

  1. Uxanduva lwedatha: UMiguel Ángel Gatón
  2. Injongo yedatha: Ulawulo lwe-SPAM, ulawulo lwezimvo.
  3. Umthetho: Imvume yakho
  4. Unxibelelwano lwedatha: Idatha ayizukuhanjiswa kubantu besithathu ngaphandle koxanduva lomthetho.
  5. Ukugcinwa kweenkcukacha
  6. Amalungelo: Ngalo naliphi na ixesha unganciphisa, uphinde uphinde ucime ulwazi lwakho.