Hi,
I encountered and issue with my kivy program. I want to turn on and off a LED using 2 kivy buttons. The program is running, but doing nothing, no error nothing. The connection scheme with Arduino is correct, I tried with a code without kivy and it worked. I this the issue is by the serial communication.
Do someone please has a clue, where the issue is?
Thanks,
Andra
I paste the code here kivy:
import serial
import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
class ChatApp(App):
def build(self):
#reconnaissance de la carte Arduino:
self.Arduino = serial.Serial("COM6", 9600, timeout = 1)
#On cree une disposition pour l'affichage:
Layout=BoxLayout(orientation='vertical',spacing=40,padding=(200,20))
self.Bouton5=Button(text='5')
self.Bouton5.bind(on_press=self.send)
#On ajoute le bouton dans l'affichage:
Layout.add_widget(self.Bouton5)
self.Bouton6=Button(text='0')
self.Bouton6.bind(on_press=self.send)
#On ajoute le bouton dans l'affichage:
Layout.add_widget(self.Bouton6)
#On renvoie l'affichage:
return Layout
def send(self,instance):
self.Arduino.write(b'instance.text')
if name == 'main':
ChatApp().run()
Arduino Code:
#include <SoftwareSerial.h>
SoftwareSerial HC06(10, 11); //HC06-TX Pin 10, HC06-RX to Arduino Pin 11
int LED = 12; //Use whatever pins you want
void setup() {
HC06.begin(9600); //Baudrate 9600 , Choose your own baudrate
pinMode(LED, OUTPUT);
}
void loop() {
if(HC06.available() > 0) //When HC06 receive something
{
char receive = HC06.read(); //Read from Serial Communication
if(receive == '5') //If received data is 1, turn on the LED and send back the sensor data
{
digitalWrite(12, HIGH);
}
else digitalWrite(12, LOW);//If received other data, turn off LED
}
}