Open EloiStree opened 1 week ago
https://play.google.com/store/apps/details?id=com.keuwl.arduinobluetooth
https://assetstore.unity.com/search#q=bluetooth%20android
#include <SoftwareSerial.h> // use the software uart
SoftwareSerial bluetooth(10, 11); // RX, TX
bool switchLed=false;
void setup() {
pinMode(13, OUTPUT); // for LED status
bluetooth.begin(9600); // start the bluetooth uart at 9600 which is its default
delay(200); // wait for voltage stabilize
}
void loop() {
if (bluetooth.available()) { // check if anything in UART buffer
bluetooth.write(bluetooth.read()); // if so, echo it back!
switchLed = ! switchLed;
digitalWrite(13, switchLed? HIGH:LOW);
}
}
I guess I put the wrong resistance, I have some problem. I need to add delay on the write()
#include <SoftwareSerial.h> // use the software uart
SoftwareSerial bluetooth(10, 11); // RX, TX
bool switchLed=false;
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT); // for LED status
bluetooth.begin(9600); // start the bluetooth uart at 9600 which is its default
delay(200); // wait for voltage stabilize
}
int index;
byte buffer[256];
void loop() {
index=0;
while(bluetooth.available()){
int b =bluetooth.read();
buffer[index]=b;
index++;
}
for(int i=0;i<index;i++){
byte b = buffer[i];
delay(20);
bluetooth.write(b);
Serial.println(b);
char c = b;
switchLed = ! switchLed;
digitalWrite(13, switchLed? HIGH:LOW);
}
}
import serial.tools.list_ports
import random
import time
import struct
import threading
# Will be the open port
integer_type= 1300000000
wait_between_send = 1
wait_pressing =1
wait_for_receive = 1
#string_device_id = "5583834323335131E111"
# MY MEGA HC05 2560 Eloi
string_device_id="98DA5001A5A3"
# ARDUINO HC05 MEGA 2560 Eloi
string_device_id="98DA5001B650"
#98D371F97B44
bool_send_zero =True
def deal_with_received_integer(integer: int):
print(f"Received: {integer}")
##----------------------------------------------------------------------------------- ###
def list_serial_ports():
ports = serial.tools.list_ports.comports()
for port in ports:
print(f"Device: {port.device}")
print(f"Name: {port.name}")
print(f"Description: {port.description}")
print(f"HWID: {port.hwid}")
print(f"VID: {port.vid}")
print(f"PID: {port.pid}")
print(f"Serial Number: {port.serial_number}")
print(f"Location: {port.location}")
print(f"Manufacturer: {port.manufacturer}")
print(f"Product: {port.product}")
print(f"Interface: {port.interface}")
print("-" * 40)
def find_device_com(string_id):
ports = serial.tools.list_ports.comports()
for port in ports:
if port.serial_number == string_id:
return port.device
for port in ports:
if string_id in port.hwid:
return port.device
return None
def send_integer(open_port: serial.Serial,integer:int):
integer_to_send = integer
integer_to_send +=integer_type
byte_array_integer_little = struct.pack("<I", integer_to_send)
open_port.write(byte_array_integer_little)
debug_byte_255 =f"{byte_array_integer_little[0]} {byte_array_integer_little[1]} {byte_array_integer_little[2]} {byte_array_integer_little[3]}"
print(f"Sent: {integer_to_send}|{byte_array_integer_little}|{debug_byte_255}")
#time.sleep(0.1)
def send_zero(open_port: serial.Serial):
byte_array_integer_little = struct.pack("<I", 0)
open_port.write(byte_array_integer_little)
print(f"Sent: 0 0 0 0")
#time.sleep(0.1)
# def print_received_while_true(open_port):
# while open_port.in_waiting > 0:
# print(f"R{open_port.in_waiting}: {open_port.read(open_port.in_waiting).decode('utf-8')}")
# time.sleep(0.001)
def send_integer_press(open_port, integer):
integer_to_send = integer
integer_to_send +=1000
if bool_send_zero:
send_zero(open_port)
send_integer(open_port,integer_to_send)
def send_integer_release(open_port, integer):
integer_to_send = integer
integer_to_send +=2000
if bool_send_zero:
send_zero(open_port)
send_integer(open_port,integer_to_send)
def send_integer_to_port( open_port, integer):
send_integer_press(open_port,integer)
time.sleep(wait_pressing)
send_integer_release(open_port,integer)
time.sleep(wait_between_send)
def send_integer_random_to_port( open_port):
send_integer_to_port(open_port,random.randrange(22,53))
if __name__ == "__main__":
list_serial_ports()
string_com_name = find_device_com(string_device_id)
print(string_com_name)
baudrate= 115200
baudrate= 9600
open_port = serial.Serial(string_com_name, baudrate)
# Create a thread with print_received_while_true
# Create a thread to run the side_task function
while(True):
if False:
for _ in range(1,4):
send_integer_random_to_port( open_port)
for i in range(22,54):
send_integer_to_port(open_port, i)
b = open_port.read_all()
if(len(b)>0):
print("Received: ",b)
print("Size: ",len(b))
if len(b)>=8 and b[0]==0 and b[1]==0 and b[2]==0 and b[3]==0:
integer_received = struct.unpack("<I", b[4:8])[0]
print(f"R Int: {integer_received}")
#42 k
#43 K
deal_with_received_integer(integer_received)
if(len(b)%4==0):
for i in range(0,len(b),4):
integer_received = struct.unpack("<I", b[i:i+4])[0]
print(f"R Int: {integer_received}")
deal_with_received_integer(integer_received)
time.sleep(0.001)
🤖
When using Bluetooth with a resistor in the circuit, particularly in data transmission, missing bytes could be due to the resistor affecting signal quality, especially if it's part of a voltage divider or used in an attempt to control current flow for the Bluetooth module. This issue can stem from a few potential causes:
If the issue persists after these adjustments, it may help to check the Bluetooth module’s datasheet or try eliminating the resistor temporarily to confirm it as the root cause of the problem.
HC05/06 on Arduino Uno craft the voltage bridge DIY https://github.com/EloiStree/HelloEloiTeachingVideo/issues/101
Créer un pont diviseur Bluetooth HC-05 HC-06 afin d'assurer une transmission vers l'Arduino.
https://github.com/EloiStree/HelloEloiTeachingVideo/issues/102
The HC-05 and HC-06 modules are perfect for establishing communication between Android, Quest, and Windows devices and the real world through the UART protocol. They are easy to use once you take the time to learn, and they remain stable over time. I learned to use them eight years ago and still rely on them today. I hope the information I've gathered here is useful to you. Happy learning! 🧙♂️