Hallo nochmal,
irgendwie befinde ich mich gedanklich mit meinem Projekt in einer Sackgasse und hoffe ihr könnte mir aus Ihr heraushelfen.
Wie bereits von Doc hier erwähnt ist die Kommunikation, bzw. das Senden eines Tastatursignals (in meinem Falle "Leertaste") schwieriger als gedacht.
Was ich bereits erreicht habe ist, dass ich Kabelgebunden (über USB) über einen Arduino ein HID Keyboard Signal an mein Endgerät (Android Tablet) sendet, jedesmal wenn dort die Brücke von Pin 9 und GND geschlossen wird.
D.h. mein Endgerät denkt, dass eine USB Tastatur angeschlossen ist, obwohl es nur ein Arduino ist.
Nun wollte ich einfach die Kabelverbindung durch eine kabellose Bluetoothverbindung ersetzen, doch es gibt nun folgendes Problem --> mein Tablet erkennt das gesendete Bluetooth Signal nicht als HID Tastatur.
Habe mir aus diesem Grund jetzt den RN42 Bluetooth Module Chip gekauft.
Danach habe ich mir mit diesem Chip einen USB Bluetooth Adapter gebaut, welcher dazu dient normale Tastaturen und Mäuse (z.b. mit PS2 oder USB Anschluss) Bluetoothfähig zu machen.
Also sieht mein Momentanes Setup so aus:
Arduino (welcher die normale USB Tastaur simuliert)---> über USB Kabel verbunden mit ---> USB Tastatur zu Bluetooth Tastaturadapter --> verbunden über Bluetooth mit Androidtablet
dieses Zusammenstecken funktioniert ist aber vom Platz sehr Raumfordernd.
Jetzt habe ich folgende Frage an euch:
Wie schaffe ich es das Arduino Board des USB zu Bluetooth Adapters so zu konfigurieren das es selbstständig ein HID-Tastatursignal über Bluetooth sendet? (ich den zweiten Arduino also weglassen kann)
ich sozusagen beiden Codes zusammen auf ein Arduino vereint bekomme?
hier mal die Codes zum besseren Verständnis:
Code welcher das Arduino zur HID Tastatur macht und jedesmal ein Leerzeichen über USB sendet wenn Pin 9 und GND verbunden werden:
#include Keyboard.h
int buttonPin = 9; // Set a button to any pin
void setup()
{
pinMode(buttonPin, INPUT); // Set the button as an input
digitalWrite(buttonPin, HIGH); // Pull the button high
}
void loop()
{
if (digitalRead(buttonPin) == 0) // if the button goes low
{
Keyboard.write('z'); // send a 'z' to the computer via Keyboard HID
delay(1000); // delay so there aren't a kajillion z's
}
}
und der Code bzw. Link zur Github Seite des Bluetooth Adapters von Evan Kale:
USB Keyboard zu Bluetooth Keyboard Adapter (Github)
* Copyright (c) 2015 Evan Kale
* Email: EvanKale91@gmail.com
* Website: www.ISeeDeadPixel.com
* www.evankale.blogspot.ca
*
* This file is part of ArduinoBTPS2.
*
* ArduinoBTPS2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PS2Mouse.h"
#include "PS2Keyboard.h"
#include "Bluetooth.h"
#define MOUSE_CLOCK 2
#define MOUSE_DATA 3
#define KEYBOARD_CLOCK 4
#define KEYBOARD_DATA 5
#define _DEBUG 0
#if _DEBUG
#define HARDWARE_SERIAL_RATE 38400
#else
#define HARDWARE_SERIAL_RATE 115200
#endif
PS2Mouse mouse(MOUSE_CLOCK, MOUSE_DATA);
PS2Keyboard keyboard(KEYBOARD_CLOCK, KEYBOARD_DATA);
#if _DEBUG
#define BLUETOOTH_DEBUG_RX 7
#define BLUETOOTH_DEBUG_TX 8
#define BLUETOOTH_DEBUG_BAUD 9600
Bluetooth bluetooth(BLUETOOTH_DEBUG_BAUD, true, BLUETOOTH_DEBUG_RX, BLUETOOTH_DEBUG_TX);
#else
Bluetooth bluetooth(HARDWARE_SERIAL_RATE, false, 0, 0);
#endif
void setup()
{
#if _DEBUG
Serial.begin(HARDWARE_SERIAL_RATE);
Serial.println("Setup started");
#endif
delay(250);
#if _DEBUG
Serial.println("Initializing mouse...");
#endif
bool mouseStatus = mouse.init();
#if _DEBUG
if (mouseStatus)
Serial.println("Mouse detected!");
else
Serial.println("No mouse detected.");
Serial.println("Initializing keyboard...");
#endif
bool keyboardStatus = keyboard.init();
#if _DEBUG
if (keyboardStatus)
Serial.println("Keyboard detected!");
else
Serial.println("No keyboard detected.");
Serial.println("Setup complete");
#endif
}
void loop()
{
if (mouse.available())
{
bluetooth.sendMouseState(mouse.getBtnState(), mouse.getDeltaX(), -mouse.getDeltaY(), -mouse.getDeltaZ());
}
if (keyboard.available())
{
bluetooth.sendKeyboardState(keyboard.getKeyModifiers(), keyboard.getKeysPressed());
}
}
Vielen Dank für Eure Hilfe!!!!!!!!
VG Winni