Browse Source

Added Arduino Scripts

manuel.lehe 2 years ago
parent
commit
13d54ae9b3

+ 34 - 0
External/BrakeSensor/ble_test/ttp223_touch_test.ino

@@ -0,0 +1,34 @@
+#include "BluetoothSerial.h"
+
+BluetoothSerial SerialBT;
+
+#define PIN_IO 12
+
+int touch_val = 0;
+void setup() {
+  // put your setup code here, to run once:
+  pinMode(PIN_IO,INPUT);
+  pinMode(LED_BUILTIN, OUTPUT);
+
+  Serial.begin(115200);
+  SerialBT.begin("brakeMonitor");
+  Serial.println("The brake monitor is ready. Connect via bluetooth");
+}
+
+void loop() {
+  // put your main code here, to run repeatedly:
+  touch_val = digitalRead(PIN_IO);
+  digitalWrite(LED_BUILTIN,touch_val);
+  SerialBT.println("Brake Status:");
+  if(touch_val == HIGH){
+    SerialBT.println("       X"); 
+    SerialBT.println("      XXX"); 
+    SerialBT.println("     XXXXX"); 
+    SerialBT.println("    XXXXXXX"); 
+    SerialBT.println("   XXXXXXXXX"); 
+    SerialBT.println("       X"); 
+  }else{
+    SerialBT.println("GRINCH");  
+  }
+  delay(500);
+}

+ 16 - 0
External/BrakeSensor/blink-test/blink-test.ino

@@ -0,0 +1,16 @@
+// the setup function runs once when you press reset or power the board
+void setup() {
+  // initialize digital pin LED_BUILTIN as an output.
+  pinMode(LED_BUILTIN, OUTPUT);
+  Serial.begin(9600);
+}
+
+// the loop function runs over and over again forever
+void loop() {
+  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
+  delay(2000);                       // wait for a second
+  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
+  delay(2000);
+  Serial.print("ENDODODODO");
+  Serial.println();
+}

+ 34 - 0
External/BrakeSensor/ttp223_touch_test/ttp223_touch_test.ino

@@ -0,0 +1,34 @@
+#include "BluetoothSerial.h"
+
+BluetoothSerial SerialBT;
+
+#define PIN_IO 12
+
+int touch_val = 0;
+void setup() {
+  // put your setup code here, to run once:
+  pinMode(PIN_IO,INPUT);
+  pinMode(LED_BUILTIN, OUTPUT);
+
+  Serial.begin(115200);
+  SerialBT.begin("brakeMonitor");
+  Serial.println("The brake monitor is ready. Connect via bluetooth");
+}
+
+void loop() {
+  // put your main code here, to run repeatedly:
+  touch_val = digitalRead(PIN_IO);
+  digitalWrite(LED_BUILTIN,touch_val);
+  SerialBT.println("Brake Status:");
+  if(touch_val == HIGH){
+    SerialBT.println("       X"); 
+    SerialBT.println("      XXX"); 
+    SerialBT.println("     XXXXX"); 
+    SerialBT.println("    XXXXXXX"); 
+    SerialBT.println("   XXXXXXXXX"); 
+    SerialBT.println("       X"); 
+  }else{
+    SerialBT.println("GRINCH");  
+  }
+  delay(500);
+}

+ 22 - 0
External/BrakeSensor/ttp223_usb_serial/ttp223_usb_serial.ino

@@ -0,0 +1,22 @@
+#define PIN_IO 12
+
+int touch_val = 0;
+void setup() {
+  pinMode(PIN_IO,INPUT);
+  pinMode(LED_BUILTIN, OUTPUT);
+  
+  Serial.begin(115200);
+}
+
+void loop() {
+  touch_val = digitalRead(PIN_IO);
+  digitalWrite(LED_BUILTIN,touch_val);
+  if(touch_val == HIGH){
+    Serial.println("BS=1");
+    Serial.write(1);
+  }else{
+    Serial.println("BS=0");  
+    Serial.write(1);
+  }
+  delay(1000);
+}

+ 77 - 0
External/BrakeSensor/udp_test/udp_test.ino

@@ -0,0 +1,77 @@
+/*
+ *  This sketch sends random data over UDP on a ESP32 device
+ *
+ */
+#include <WiFi.h>
+#include <WiFiUdp.h>
+
+// WiFi network name and password:
+const char * networkName = "Lord Voldemodem(2,4Ghz)";
+const char * networkPswd = "R4Eo62TPW06J00g";
+
+//IP address to send UDP data to:
+// either use the ip address of the server or 
+// a network broadcast address
+const char * udpAddress = "192.168.178.21";
+const int udpPort = 8888;
+
+//Are we currently connected?
+boolean connected = false;
+
+//The udp library class
+WiFiUDP udp;
+
+byte command[27] = {0x20, 0x00, 0x00, 0x00, 0x16, 0x02, 0x62, 0x3A, 0xD5, 0xED, 0xA3, 0x01, 0xAE, 0x08, 0x2D, 0x46, 0x61, 0x41, 0xA7, 0xF6, 0xDC, 0xAF, 0xD3, 0xE6, 0x00, 0x00, 0x1E};
+
+void setup(){
+  // Initilize hardware serial:
+  Serial.begin(115200);
+
+  //Connect to the WiFi network
+  connectToWiFi(networkName, networkPswd);
+}
+
+void loop(){
+  //only send data when connected
+  if(connected){
+    //Send a packet
+    udp.beginPacket(udpAddress,udpPort);
+    udp.write(command, 27);
+    udp.endPacket();
+  }
+  //Wait for 1 second
+  delay(1000);
+}
+
+void connectToWiFi(const char * ssid, const char * pwd){
+  Serial.println("Connecting to WiFi network: " + String(ssid));
+
+  // delete old config
+  WiFi.disconnect(true);
+  //register event handler
+  WiFi.onEvent(WiFiEvent);
+
+  //Initiate connection
+  WiFi.begin(ssid, pwd);
+
+  Serial.println("Waiting for WIFI connection...");
+}
+
+//wifi event handler
+void WiFiEvent(WiFiEvent_t event){
+    switch(event) {
+      case SYSTEM_EVENT_STA_GOT_IP:
+          //When connected set 
+          Serial.print("WiFi connected! IP address: ");
+          Serial.println(WiFi.localIP());  
+          //initializes the UDP state
+          //This initializes the transfer buffer
+          udp.begin(WiFi.localIP(),udpPort);
+          connected = true;
+          break;
+      case SYSTEM_EVENT_STA_DISCONNECTED:
+          Serial.println("WiFi lost connection");
+          connected = false;
+          break;
+    }
+}