<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; ">Ciao a tutti :) è la prima volta che scrivo, anche se vi seguo da tanto, anche perché sono un amatore poco esperto, ma se posso dare il mio contributo lo do volentieri :)</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; ">Veniamo a noi, io per dialogare con arduino ho usato il modulo serial.</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; ">La prima difficoltà è trovare il nome giusto della porta, lo risolvi o con il programma java di arduino per compilare gli sketch che ti dice il nome della porta, oppure con questo listato artigianale:</div><div
style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "><br></div><div><div>import serial</div><div><br></div><div><span style="font-size: 10px; font-family: 'lucida console', sans-serif;">def analizza_porte():</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> lista = []</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> for x in range(16):</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> n = "com" + str(x)</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> try:</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> z = serial.Serial(n)</span></div><div><span style="font-size: x-small;
font-family: 'lucida console', sans-serif;"> z.close()</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> lista.append(n)</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> except:</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> continue</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> for x in range(16):</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> n = "/dev/ttyACM" + str(x)</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> try:</span></div><div><span style="font-size:
x-small; font-family: 'lucida console', sans-serif;"> z = serial.Serial(n)</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> z.close()</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> lista.append(n)</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> except:</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> continue</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> for x in range(16):</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> n = "/dev/ttyS" +
str(x)</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> try:</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> z = serial.Serial(n)</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> z.close()</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> lista.append(n)</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> except:</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"> continue</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;">
return lista</span></div><div><span style="font-size: x-small; font-family: 'lucida console', sans-serif;"><br></span></div><div><span style="font-size: 10px; font-family: 'lucida console', sans-serif;">print(analizza_porte())</span></div><div><br></div><div><span style="font-family: 'lucida console', sans-serif; ">Per dialogare con arduino ho fatto qualcosa del genere, in pratica mi invia del testo "DO", "RE", eccetera e arduino quando lo legge suona una nota</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;"><br></span></div><div><div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;">from tkinter import *</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;">import serial</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;"><br></span></div><div><span style="font-family: 'lucida console',
sans-serif; font-size: x-small;">try:</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;"> arduino=serial.Serial("/dev/ttyACM0",9600)</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;">except:</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;"> exit</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;"> </span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;">def suona(nota):</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;"> arduino.write(nota.encode("utf-8"))</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;">root=Tk()<br></span></div><div><span style="font-family: 'lucida console', sans-serif; font-size:
x-small;"> </span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;">do=Button(root,text="DO",command=lambda: suona("C")).pack()</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;">re=Button(root,text="RE",command=lambda: suona("D")).pack()</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;">mi=Button(root,text="MI",command=lambda: suona("E")).pack()</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;">fa=Button(root,text="FA",command=lambda: suona("F")).pack()</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;">sol=Button(root,text="SOL",command=lambda: suona("G")).pack()</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size:
x-small;">la=Button(root,text="LA",command=lambda: suona("A")).pack()</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: x-small;">si=Button(root,text="SI",command=lambda: suona("B")).pack()</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: 10px; ">root.mainloop()</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: 10px; "><br></span></div><div><span style="font-family: 'lucida console', sans-serif; ">E infine lo sketch su arduino, ciao e scusate la lunghezza:</span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: 10px; "><br></span></div><div><span style="font-family: 'lucida console', sans-serif; font-size: 11px;"><div>#define NOTE_B0 31</div><div>#define NOTE_C1 33</div><div>#define NOTE_CS1 35</div><div>#define NOTE_D1 37</div><div>#define NOTE_DS1 39</div><div>#define NOTE_E1 41</div><div>#define
NOTE_F1 44</div><div>#define NOTE_FS1 46</div><div>#define NOTE_G1 49</div><div>#define NOTE_GS1 52</div><div>#define NOTE_A1 55</div><div>#define NOTE_AS1 58</div><div>#define NOTE_B1 62</div><div>#define NOTE_C2 65</div><div>#define NOTE_CS2 69</div><div>#define NOTE_D2 73</div><div>#define NOTE_DS2 78</div><div>#define NOTE_E2 82</div><div>#define NOTE_F2 87</div><div>#define NOTE_FS2 93</div><div>#define NOTE_G2 98</div><div>#define NOTE_GS2 104</div><div>#define NOTE_A2 110</div><div>#define NOTE_AS2 117</div><div>#define NOTE_B2 123</div><div>#define NOTE_C3 131</div><div>#define NOTE_CS3 139</div><div>#define NOTE_D3 147</div><div>#define NOTE_DS3 156</div><div>#define NOTE_E3 165</div><div>#define NOTE_F3 175</div><div>#define NOTE_FS3 185</div><div>#define NOTE_G3 196</div><div>#define NOTE_GS3 208</div><div>#define NOTE_A3
220</div><div>#define NOTE_AS3 233</div><div>#define NOTE_B3 247</div><div>#define NOTE_C4 262</div><div>#define NOTE_CS4 277</div><div>#define NOTE_D4 294</div><div>#define NOTE_DS4 311</div><div>#define NOTE_E4 330</div><div>#define NOTE_F4 349</div><div>#define NOTE_FS4 370</div><div>#define NOTE_G4 392</div><div>#define NOTE_GS4 415</div><div>#define NOTE_A4 440</div><div>#define NOTE_AS4 466</div><div>#define NOTE_B4 494</div><div>#define NOTE_C5 523</div><div>#define NOTE_CS5 554</div><div>#define NOTE_D5 587</div><div>#define NOTE_DS5 622</div><div>#define NOTE_E5 659</div><div>#define NOTE_F5 698</div><div>#define NOTE_FS5 740</div><div>#define NOTE_G5 784</div><div>#define NOTE_GS5 831</div><div>#define NOTE_A5 880</div><div>#define NOTE_AS5 932</div><div>#define NOTE_B5 988</div><div>#define NOTE_C6 1047</div><div>#define NOTE_CS6
1109</div><div>#define NOTE_D6 1175</div><div>#define NOTE_DS6 1245</div><div>#define NOTE_E6 1319</div><div>#define NOTE_F6 1397</div><div>#define NOTE_FS6 1480</div><div>#define NOTE_G6 1568</div><div>#define NOTE_GS6 1661</div><div>#define NOTE_A6 1760</div><div>#define NOTE_AS6 1865</div><div>#define NOTE_B6 1976</div><div>#define NOTE_C7 2093</div><div>#define NOTE_CS7 2217</div><div>#define NOTE_D7 2349</div><div>#define NOTE_DS7 2489</div><div>#define NOTE_E7 2637</div><div>#define NOTE_F7 2794</div><div>#define NOTE_FS7 2960</div><div>#define NOTE_G7 3136</div><div>#define NOTE_GS7 3322</div><div>#define NOTE_A7 3520</div><div>#define NOTE_AS7 3729</div><div>#define NOTE_B7 3951</div><div>#define NOTE_C8 4186</div><div>#define NOTE_CS8 4435</div><div>#define NOTE_D8 4699</div><div>#define NOTE_DS8 4978</div><div><br></div><div>int ledPin=2;</div><div>char
msg;</div><div><br></div><div>void setup() {</div><div> pinMode(ledPin,OUTPUT);</div><div> Serial.begin(9600);</div><div>}</div><div><br></div><div>void loop () { </div><div><br></div><div>if (Serial.available()>0)</div><div> { </div><div> msg=Serial.read();</div><div> } </div><div>else</div><div>{ </div><div> if (msg=='C') { </div><div> tone(3, NOTE_C3,1000);</div><div> Serial.print("Note C");</div><div> msg=' ';</div><div> } </div><div> else if (msg=='D') { </div><div> tone(3, NOTE_D3,1000);</div><div>
Serial.print("Note D");</div><div> msg=' ';</div><div> } </div><div> else if (msg=='E') { </div><div> tone(3, NOTE_E3,1000);</div><div> Serial.print("Note D");</div><div> msg=' ';</div><div> } </div><div> else if (msg=='F') { </div><div> tone(3, NOTE_F3,1000);</div><div> Serial.print("Note D");</div><div> msg=' ';</div><div> } </div><div> else if
(msg=='G') { </div><div> tone(3, NOTE_G3,1000);</div><div> Serial.print("Note D");</div><div> msg=' ';</div><div> } </div><div> else if (msg=='A') { </div><div> tone(3, NOTE_A3,1000);</div><div> Serial.print("Note D");</div><div> msg=' ';</div><div> } </div><div> else if (msg=='B') { </div><div> tone(3, NOTE_B3,1000);</div><div> Serial.print("Note D");</div><div>
msg=' ';</div><div> } </div><div><br></div><div>}</div><div>}</div></span></div></div></div></div> </div></body></html>