Вы находитесь на странице: 1из 2

29/12/2011

Lisandro

Aplicacin grfica con Python para Arduino


dic 29 2011 Vamos a escribir una interfaz grfica para enviar datos a nuestra Arduino. Para eso vamos a usar la librera wxPython que es multiplataforma. En la Arduino tenemos que escribir el programa que se explic aqu y en nuestro IDE favorito vamos a escribir: #!/usr/bin/env python import wx import serial class wxGuiSerie(wx.Frame):<br /><br /> Este es el frame para nuestra aplicacion, esta derivado de el elemento wx.Frame. def __init__(self, *args, **kwargs):<br /><br /> Inicia, y pone las configuraciones del usuario para cualquier Frame.<br /><br /> wx.Frame.__init__(self, *args, **kwargs)<br /><br /> self.create_controls() def create_controls(self):<br /><br /> Llamada cuando los controles de la ventana son creados #Horizontal sizer<br /><br /> self.h_sizer = wx.BoxSizer(wx.HORIZONTAL)<br /><br /> #Vertical sizer<br /><br /> self.v_sizer = wx.BoxSizer(wx.VERTICAL) #Widget Creation<br /><br /> #Create the static text widget and set the text<br /><br /> self.text = wx.StaticText(self, label=Caracter:)<br /><br /> #Create the Edit Field (or TextCtrl)<br /><br /> self.edit = wx.TextCtrl(self, size=wx.Size(250, -1))<br /><br /> #Create the button<br /><br /> self.button = wx.Button(self, label=Enviar!)<br /><br /> #bind the button click to our press function<br /><br /> self.button.Bind(wx.EVT_BUTTON, self.on_button_ pressed) #Add to horizontal sizer<br /><br /> #add the static text to the sizer, tell it not to resize<br /><br /> self.h_sizer.Add(self.text, 0,)<br /><br /> #Add 5 pixels between the static text and the edit<br /><br /> self.h_sizer.AddSpacer((5,0))<br /><br /> #Add Edit<br /><br /> self.h_sizer.Add(self.edit, 1) #Add to the vertical sizer to create two rows<br /><br /> self.v_sizer.Add(self.h_sizer, 0, wx.EXPAND)<br /><br /> #Add button underneath<br /><br /> self.v_sizer.Add(self.button, 0) #Set the sizer<br /><br /> self.SetSizer(self.v_sizer)<br /><br /> #Fit ourselves to the sizer<br /><br /> self.v_sizer.Fit(self)<br /><br /> #Set the Minumum size<br /><br /> self.SetMinSize(self.v_sizer.GetMinSize()) def on_button_pressed(self, event):<br /><br /> Called when the button is clicked. It will<br /><br /> show a simple dialog with the text from the<br /><br /> edit feld.<br /><br /> #Get the message text<br /><br /> ser = serial.Serial(/dev/ttyACM0, 9600)<br /><br /> char = %s % (self.edit.GetValue())<br /><br /> ser.write(char)<br /><br /> message_text = Enviado: %s % (self.edit.

http://eltallerdelfondo.com.ar/2011/12/aplicacion-grafica-con-python-para-arduino/

Love this

PDF?

Add it to your Reading List! 4 joliprint.com/mag


Page 1

29/12/2011

Aplicacin grfica con Python para Arduino

GetValue())<br /><br /> msg_box = wx.MessageDialog(self<br /><br /> , message_text<br /><br /> , GuiSerie<br /><br /> , wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION)<br /><br /> #Show the Dialog<br /><br /> msg_box.ShowModal()<br /><br /> ser.flush()<br /><br /> ser.close() class wxGuiSerieApp(wx.App):<br /><br /> The wx.App for the wxGuiSerie application def OnInit(self):<br /><br /> Override OnInit to create our Frame<br /><br /> frame = wxGuiSerie(None, title=GuiSerie)<br /><br /> frame.Show()<br /><br /> self.SetTopWindow(frame) return True if __name__ == __main__:<br /><br /> app = wxGuiSerieApp()<br /><br /> app.MainLoop()<br /><br />
http://eltallerdelfondo.com.ar/2011/12/aplicacion-grafica-con-python-para-arduino/

Por supuesto este programa se puede ampliar para prender, apagar y comandar lo que necesitemos. By Lisandro Documentacin, Electrnica, Mvil, Programacin, Software libre 0 Tags: arduino, gui, programa, usb, wxpython

Lo guardamos como guiserie.py y desde una consola lo ejecutamos con: $ python guiserie.py

Enviando un carcter:

Love this

PDF?

Add it to your Reading List! 4 joliprint.com/mag


Page 2

Вам также может понравиться