forum

osu tatacon using arduino uno

posted
Total Posts
12
Topic Starter
mygntay
Hi, i'm trying to create a real sized tatacon and need your help with something. :)
i will explain how i did it when everything will work properly. (don't worry! )

for know everything is OK, my arduino returns one d, f , j or k each time a piezo sensor is activated
then, a python script take this input and do like a key was pressed.
work properly everywhere but in osu. :(
could someone help me figuring out what's happening ?

the script:
SPOILER
# don't forget to install pyserial if not already done.
#"pip install pyserial" on command prompt :
#if python is installed on C:\ it should look like that:
# C:\users\yourname> set PATH = %PATH%;C:\python\scripts
# C:\users\yourname> pip install requests
##########################
import serial
import win32com.client

ser = serial.Serial("COM4",9600)
# COM4 might be diferent for you. choose the port where your arduino is
ser.isOpen()
shell = win32com.client.Dispatch("WScript.Shell")

while (0==0): # because why not
command = ser.read()
if (command == 'f'):
shell.SendKeys('F')

elif (command == 'd'):
shell.SendKeys('D')

elif (command == 'j'):
shell.SendKeys('J')

elif (command == 'k'):
shell.SendKeys('K')
Angelo
I would like to help but I can't because :(
Faishal Akbar
Actually instead of using python for changing from Serial output to keypress, you can directly use Arduino Uno to send keypress with arduino uno Keyboard Hex File (yep, since Uno can't used as HID Natively, you need to flash another hex file for it). all you need to do is upload your sketch to arduino while arduino still detected as Arduino (not a keyboard) and flash Arduino uno keyboard hex file after that with Flip / avrdude / whatever you prefer

you can read the refrence here or you can see the examples of code usage for Arduino Uno Keyboard here

tl;dr you can send your code to me if you need for help :D
Topic Starter
mygntay
wouah,
I have to admit, this is something i've never done before, so i've downlad all arduino-keyboards (. hex (*2), .pde and .zip )
i've also download atmel flip. but i don't know how i'm suposed to flash arduino uno with that.

moreover, i have a question :)
will i be abble to modify the sketch after flash the arduino uno ?

and here is the script btw:

SPOILER
// code inspired from: this
const char N = 4; // number of piezos
int seuil = 375; // threhold
int valeur1[N] = {0}; //first value of the N piezos
int valeur2[N] = {0}; //second value of the N piezos
unsigned long lt[N] = {0}; //time of last activation of piezos N

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:

for (char i = 0; i<N; i++) { //for piezo 1 to 4 (i = 0, 1, 2, 3)
valeur1[i] = analogRead(i); //read first value
}
delay(1); // wait
for (char i = 0; i<N; i++) { //for piezo 1 to 4
valeur2[i] = analogRead(i); //read second value
}
while ((valeur1[0] < valeur2[0] || valeur1[1] < valeur2[1] || valeur1[2] < valeur2[2] ||valeur1[3] < valeur2[3]) && (valeur2[0] > seuil || valeur2[1] > seuil || valeur2[2] > seuil || valeur2[3] > seuil) ) {
//well this while can be shorter i'm sure but ... i don't know if "valeur1<valeur2" is working so ... i have to try
// while one of the piezo have an increasing signal and that the peak registered (valeur2) is better than the trehold (seuil)


for (char i = 0; i<N; i++) { //continue to read value
valeur1[i] = valeur2[i];
valeur2[i] = analogRead(i);
}

// delay(0.5);

/*
* next is looking for a decreasing value AND with 40ms of delay
* when OK, it send a signal to the computer (signal can be d, f , j or k (it depends of the piezos and how they are linked to the arduino))
* then lt is refreshed
*/

if (valeur1>valeur2) {

if (valeur1[0] >= seuil && millis()>=lt[0]+40) {
Serial.print('d');
lt[0] = millis();

}
if (valeur1[1] >= seuil && millis()>=lt[1]+40) {
Serial.print('k');
lt[1] = millis();
}
if (valeur1[2] >= seuil && millis()>=lt[2]+40) {
Serial.print('j');
lt[2] = millis();
}
if (valeur1[3] >= seuil && millis()>=lt[3]+40) {
Serial.print('f');
lt[3] = millis();
}
}
}

}
Faishal Akbar
I Assume you're using 16u2 variant (Uno R3). but actually this is fine on 8u2 for some people but yea. Do with your own risk.

Long Story, but important to read :p
You only need .hex file, and flip. and flash it after put your Uno into DFU mode , and you can flash the hex file directly with Flip. also, if you want to modify your Arduino Sketch, you need to flash Arduino to original Firmware Serial hex file (in case you don't have you can download it). so i can imagine more like this

Upload Sketch -> DFU -> Arduino Keyboard Hex flash -> Reconnect after Flash finished -> Done. or if you want to modify sketch
DFU -> Arduino Original Firmware Serial flash with flip -> Reconnect after Flash finished -> Upload Sketch -> DFU -> Uno Hex Flash -> Reconnect -> Done.

In case there's a failure when flashing the Firmware, you can try reconnect the cable, put into DFU mode again, open USB Connection (use USB icon from top left) , and flash it again.

actually if you want to make serious project with output as Mouse or Keyboard input *cough*likeosukeyboard*cough*, you can switch over to Arduino Leonardo, Micro, or Due since they're already support HID without flashinganyotherfilethatmakesyouconfused.

you can try the modified code here. make sure your uno already detected as Arduino Uno serial port instead HID keyboard to flash it (see above). let me know if there's something wrong with that code

Tips : You can use "Online Diff tool" to see what changed from the original Code if you're curious enough.
Topic Starter
mygntay
so far i've been able to put arduino in DFU mode but in flip, after choosing atmega16u2 (it's an arduino uno R3), i still have "communication off" in the bottom right hand corner. so... i've tried to click
this button:
then USB // click open ... and
:/

i don't know what to think about it :[

btw thank you for your help it might not work (and it's not done yet), but i've already learned a lot of things thanks to you

oh and, a project with arduino leonardo already exist there: https://osu.ppy.sh/forum/t/385813
but ... well, i have an arduino uno so ... i'd like to try with it :)
Faishal Akbar
You're Welcome, well. maybe if i have time i will try reproduce the Tatacon leonardo to arduino Uno (maybe :p ) . but yea. if you can't open connection. make sure you've installed the Flip driver before. and your device detected as Flip device. otherwise. if still can't open the communication port. maybe you need to reconnect your device, and put it to DFU once again
The Gambler
Use a Teensy... Makes life a helluva lot easier...

Also the guide I posted can be modified for a piezo sensor input as well.
Topic Starter
mygntay
@the gambler, the thing is that i don't want to buy anything else if it can work like that (and it's more interesting when it's not easy) :) but thanks for the tips! might be usefull for an other project or if it don't work or² for someone else

So i've download driver for ATmega16u2 that i've found here: C:\Program Files (x86)\Atmel\Flip 3.4.7\usb
then, on ATMEL FLIP, i've clicked file/load hex file, select "Arduino-keyboard-0.3.hex" and click this

reconect,

Load sketch to arduino


load "Arduino-keyboard-0.3.hex". Again, "program target device memory" ()

reconect.

...

let's try

....

hmmm .. ok some issues but better than nothing (might have missunderstood something? :/)

so the A0 input of arduino returns '>' when the piezo sensor is "activated"
A1 returns 'F16' key
A2 returns ' F15' key
A3 returns nothing
buuut... osu can read the input! that's how i know the value of A1 and A2.

btw some change in code:
40 ms => 30 ms
seuil = 350
Faishal Akbar
ah sorry for late reply, seems i've put wrong number at the keyboard arrays

d is 7
k is 14
j is 13
and f is 9
you can read the refrence here (page 53) http://amaury-laurent.fr/wp-content/upl ... ut1_11.pdf
Mafumafu
Arduino hmm
I once had similar ideas, trying to implement this by SCMs though.
but it's python so.... ;w;
Topic Starter
mygntay
and ...
It work !!
thank you!
here is a little video!


https://youtu.be/wP8i5E8pdnU

btw, i've been looking at Serial.write() on arduino website: https://www.arduino.cc/en/Serial/Write
so i didn't change the '"len" value but the "buf" value (wich is kb in the script)
PLUS
osu seems to take the input in function of fps
the input of arduino is too quick so i've added time before release ( a bit less than the time between each frames at 60fps (my osu is running at 240fps ~)):)
the final script:

SPOILER
const char N = 4; // number of piezos
int seuil = 350; // threhold
int valeur1[N] = {0}; //first value of the N piezos
int valeur2[N] = {0}; //second value of the N piezos
unsigned long lt[N] = {0}; //time of last activation of piezos N
uint8_t kb[8] = { 0 }; //Array that Used for Key Sending for UnoKeyboard

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:

for (char i = 0; i<N; i++) { //for piezo 1 to 4 (i = 0, 1, 2, 3)
valeur1[i] = analogRead(i); //read first value
}
delay(1); // wait
for (char i = 0; i<N; i++) { //for piezo 1 to 4
valeur2[i] = analogRead(i); //read second value
}
while ((valeur1[0] < valeur2[0] || valeur1[1] < valeur2[1] || valeur1[2] < valeur2[2] ||valeur1[3] < valeur2[3]) && (valeur2[0] > seuil || valeur2[1] > seuil || valeur2[2] > seuil || valeur2[3] > seuil) ) {
//well this while can be shorter i'm sure but ... i don't know if "valeur1<valeur2" is working so ... i have to try
// while one of the piezo have an increasing signal and that the peak registered (valeur2) is better than the trehold (seuil)

for (char i = 0; i<N; i++) { //continue to read value
valeur1[i] = valeur2[i];
valeur2[i] = analogRead(i);
}

// delay(0.5);

/*
* next is looking for a decreasing value AND with 40ms of delay
* when OK, it send a signal to the computer (signal can be d, f , j or k (it depends of the piezos and how they are linked to the arduino))
* then lt is refreshed
*/

if (valeur1>valeur2) {

if (valeur1[0] >= seuil && millis()>=lt[0]+30) {
kb[2] = 7; //What's this? Read Here : https://www.arduino.cc/en/Reference/ASCIIchart
Serial.write(kb, 8); //Print the Data as Keypress output at Arduino Uno Keyboard
releaseKey(); //Release Key
//Serial.print('d');
lt[0] = millis();
}
if (valeur1[1] >= seuil && millis()>=lt[1]+30) {
kb[3] = 14;
Serial.write(kb, 8);
releaseKey();
//Serial.print('k');
lt[1] = millis();
}
if (valeur1[2] >= seuil && millis()>=lt[2]+30) {
kb[4] = 13;
Serial.write(kb, 8);
releaseKey();
//Serial.print('j');
lt[2] = millis();
}
if (valeur1[3] >= seuil && millis()>=lt[3]+30) {
kb[5] = 9;
Serial.write(kb, 8);
releaseKey();
//Serial.print('f');
lt[3] = millis();
}
}
}

}

void releaseKey(){
kb[2] = 0;
kb[3] = 0;
kb[4] = 0;
kb[5] = 0;
delay(16); //wait for osu to capture the key
Serial.write(kb, 8); //Release key after keypress
}

need to practice now :D
@peppy (lol) need local multiplayer for taiko X)

thanks a lot for your help!
Please sign in to reply.

New reply