mercoledì 6 gennaio 2016

GUI con Python: messaggi

La libreria per fare le GUI si chiama Tkinter 
ESEMPIO:

from Tkinter import *
# if you are working under Python 3, comment the previous line and comment out the following line
#from tkinter import *

root = Tk()

w = Label(root, text="Hello Tkinter!")
w.pack()

root.mainloop()

farà apparire:
Hello Tkinter Windows

sabato 2 gennaio 2016

come comandare da python tramite seriale

riferimento: comandare robot da python

1. serve la libreria PySerial

  • Downloading and Installing the PySerial Library
Head over to this page for detailed PySerial documentation and this page to download the package.
che si usa semplicemente così, per inviare il carattere 'a' al PSOC:

import serial
"""
usare una volta sola per aprire com4
PSOCSerialPort = serial.Serial("COM4", 115200)
"""
PSOCSerialPort.write('a')


2. serve la libreria Tkinter 

per fare l'interfaccia grafica.

import serial
from Tkinter import *

#preparare le definizioni dei comandi
def ledOn():
PSOCSerialPort.write('a')
def ledOff():
PSOCSerialPort.write('A')
#comando da emettere una volta per non avere errore:
#PSOCSerialPort = serial.Serial("COM4", 115200)

appWindow = Tk() # creates the application window (you can use any name)
appWindow.wm_title("LED Control") # displays title at the top left
# insert app widgets here (radiobuttons, checkboxes, buttons, etc.)

var = IntVar() # define var as an integer variable
onButton = Radiobutton(appWindow, text="LED ON", variable = var, value = 1, command=ledOn)
onButton.pack( anchor = W ) # this part adjusts the radiobuttons to the parent window
offButton = Radiobutton(appWindow, text="LED OFF", variable = var, value = 2, command=ledOff)
offButton.pack( anchor = W ) # this part adjusts the radiobuttons to the parent window

appWindow.mainloop() # main loop. From here, the GUI starts updating and responding to user inputs.

verrà creata questa GUI:

che manderà 'a' oppure 'A' a seconda della scelta

domenica 13 dicembre 2015

domenica 6 luglio 2014

come inviare dati al PC e mostrarli con Tcl/Tk, parte1: lato Psoc

https://docs.google.com/presentation/d/1yVqSKakMXubxopJJOOVE6l3E_l66NsgrmrtNUINhkUg/edit#slide=id.g35be91c2e_075

Come evitare di estrarre e reinserire continuamente il PSoC per il download

phttps://docs.google.com/presentation/d/1iZxSOHYDUNf9IbvFI0UG5RcPzml0kYCV3GEDBQPjCAg/edit#slide=id.p

il programma esempio del led lampeggiante

https://docs.google.com/presentation/d/125WleXXpL6ha2J9-2IJUe945K_ZGE29e3nV6kGL2RzQ/edit#slide=id.g35553dabc_02

leggere un pin e scrivere su un pin

https://docs.google.com/presentation/d/1-KBIk_JlmmUAp_NnzMKaZQgOPzv5XC6HlhyAfXmQllw/edit#slide=id.p

semplicissimo: spegne il led quando si preme il pulsante

https://docs.google.com/presentation/d/1l6r0fRIIrnJoJzd8cmdxhIHQ9rqiss-L6l4WyN60wds/edit#slide=id.g18a6b102f_036

ATTENZIONE se si usa un programma normale OCCORRE sempre renderlo bootloadable ecco come

https://docs.google.com/presentation/d/1PG7NbVM8PKZCNuUhQpPOGCVCe_bNN6Rr93W01ZMonhc/edit?usp=sharing