Join us at IRC!
Hacking isn't just Computers & Exploits. It's a Philosophy. - Mr_Cheese
Friday, May 25, 2012
Navigation
Members Online
Total Online: 32
Web Spiders: 15
Guests Online: 31
Members Online: 1

Registered Members: 70209
Newest Member: KalareShou
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Page 1 of 2 1 2 >
Author

Python+Microcontroller=Mouse

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Hacker Level 2
Posted on 14-03-10 05:39
After working with the IR tracking I remembered about an accelerometer I had laying around. i decided to map the mouse to it instead. This way is a lot more efficient. It doesn't really touch the CPU and with the throttling isn't noticeable.
It uses PySerial to read the debugged data from the chip. Win32api/win32con is used for the clicks, and windll.user32 for the mouse movements.

I have a video demonstration the use, its on face book so you might have to be a member to view it.
here's the link
http://www.facebook.com/#!/video/video.php?v=1236239189937&ref=nf

I know I probably should have posted this in the code bank, but I never get any responses there, I wouldn't be surprised if no one looked in there.

Here is the code that's loaded onto the chip:

' {$STAMP BS2}
' {$PBASIC 2.5}

x VAR Word
y VAR Word

DO

PULSIN 8, 1, x
PULSIN 7, 1, y
DEBUG LF, ? x , ? y , ? IN9, ? IN10

LOOP


And now for the python code:

#Accelorometer mouse (Basic Stamp 2)
#3-12-10
#Tech B.

from ctypes import *
import serial
import win32api
import win32con

s = serial.Serial('COM5') #Will differ between systems. I use Serial to USB cable
user = windll.user32

#inital x,y values
x = 0
y = 0
speed = 10


def lUP():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
def lDOWN():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
def rUP():
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, 0, 0)
def rDOWN():
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0)


c1 = 0
#Main Loop
while 1:
try:
d = s.readline()
d = d.split()
if int(d[2]) > 2700:
if x < 1400:
x += speed
elif int(d[2]) < 2400:
if x > 0:
x -= speed
if int(d[5]) > 2600:
if y > 0:
y -= speed
elif int(d[5]) < 2400:
if y < 900:
y += speed
if int(d[8]) == 1 and c1 == 0:
lDOWN()
c1 += 1
elif int(d[8]) == 0:
lUP()
c1 = 0
if int(d[11]) == 1:
rDOWN()
rUP()

user.SetCursorPos(x,y)
except:
pass





Edited by techb on 14-03-10 05:41
kbcarte.wordpress.com
Author

RE: Python+Microcontroller=Mouse

MjWasHere
Member

Posts: 14
Location:
Joined: 03.07.07
Rank:
Hacker Level 1
Warn Level: 5
Posted on 14-03-10 06:25
Awesome !!!
Great work there !!! :)
Author

RE: Python+Microcontroller=Mouse

wolfmankurd
Member



Posts: 1519
Location: UK
Joined: 30.05.05
Rank:
God
Posted on 14-03-10 12:14
A video would be nice( just saw it I don't have facebook), whats an accerometer driven mouse like? It seems liek to use it you'd need to be jerky but also it could be used in 3d?

I have so many questions...

Most of my mouse movements is more of a glide with only acceration at the beginging and end. Does this mean you have to continually be accerating to move your mouse? Have you thought about integrating the acceration to get velocity?

What chip are you using? Looks like a basic stamp from code.

If you put this on a pen, then you could track the tip or the top with a IR LED( you'd need two really) like your last thing and use g for orientation. that could be very useful. Essentially wii mote with lower accuracy.

Keep up the awesome work :)

edit: video explains alot.


BY READING MY POST, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE USE OF THIS (MIS)INFORMATION.




Edited by wolfmankurd on 14-03-10 12:44
Widowmakr@hotmail.com http://LetsHackStuff.com
Author

RE: Python+Microcontroller=Mouse

yours31f
Second to one



Posts: 1678
Location: Dallas Texas
Joined: 27.04.07
Rank:
Satan
Posted on 14-03-10 15:49
develop a hat and sell it! make yourself rich.


Debugging is what programmers do to beta software to make it take up more room on your hard drive if it is running too efficiently.



yours31f@live.com yours31f@yahoo.com rpwd.info
Author

RE: Python+Microcontroller=Mouse

fuser
Member



Posts: 959
Location: in front of a computer (duh)
Joined: 05.04.07
Rank:
HBH Guru
Posted on 14-03-10 17:41
wow, op, this seems pretty cool.

make a video demo of it, so that we know it's true.












Telling modern Internet users to stop whining is like telling them to stop breathing — it seems unrealistic and inhumane. Paul Lutus

catinthecpu@hotmail.com
Author

RE: Python+Microcontroller=Mouse

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Hacker Level 2
Posted on 14-03-10 20:36
It is BasicStamp2 specifically the Homework Board. The mouse movements are more of a stepper motion. It reads the values from the accelerometer and if the value is above or below the given threshold, 10 pixels is added to the mouses current position.

I plan on making headgear, the parts are in the mail now, and am waiting for a patent on my design.

There is now a video demonstrating the use on photobucket for those who don't believe me.

Link: http://s880.photobucket.com/albums/ac6/Tech_B/?action=view¤t=te.flv&newest=1

The video is kinda glitchy, I am trying out windows encoder as the screen capturing method. I don't like it. I've used CamStudio but its not the quality I want. Any suggestions for free screen capturing?




Edited by techb on 14-03-10 20:54
kbcarte.wordpress.com
Author

RE: Python+Microcontroller=Mouse

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Hacker Level 2
Posted on 14-03-10 20:51
I was thinking more of software.


kbcarte.wordpress.com
Author

RE: Python+Microcontroller=Mouse

wolfmankurd
Member



Posts: 1519
Location: UK
Joined: 30.05.05
Rank:
God
Posted on 14-03-10 20:57
techb wrote:
I plan on making headgear, the parts are in the mail now, and am waiting for a patent on my design.


Not entirely sure it's patenable cause it's not novel. let us know how it goes.


BY READING MY POST, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE USE OF THIS (MIS)INFORMATION.


Widowmakr@hotmail.com http://LetsHackStuff.com
Author

RE: Python+Microcontroller=Mouse

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Hacker Level 2
Posted on 14-03-10 21:05
If I don't get a patent I'm going to pitch it to the school board, and hopefully it can be at least in school for handicapped/disabled to use a computer since the schools around here are emphasizing use of technology. If anything maybe they can make an intro class to programming and microcontrollers for high schools or middle schools.


kbcarte.wordpress.com
Author

RE: Python+Microcontroller=Mouse

wolfmankurd
Member



Posts: 1519
Location: UK
Joined: 30.05.05
Rank:
God
Posted on 14-03-10 22:12
Have you tried the double integrating the acceleration? All you'd have to do is add up the values.

So, you total up the values in each direction. then do the same again.

so, say,
x_v += x
x_d += x_v
and x_d would give you how much the mouse has moved in the x-axis from the start poisition. Not sure if I'm explaining myself properly, but I'd like to see how accurate it is if you'd oblige? :)


BY READING MY POST, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE USE OF THIS (MIS)INFORMATION.




Edited by wolfmankurd on 14-03-10 22:15
Widowmakr@hotmail.com http://LetsHackStuff.com
Author

RE: Python+Microcontroller=Mouse

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Hacker Level 2
Posted on 15-03-10 00:02
wolfmankurd wrote:
Have you tried the double integrating the acceleration? All you'd have to do is add up the values.

So, you total up the values in each direction. then do the same again.

so, say,
x_v += x
x_d += x_v
and x_d would give you how much the mouse has moved in the x-axis from the start poisition. Not sure if I'm explaining myself properly, but I'd like to see how accurate it is if you'd oblige? :)


Yeah, I'm game. I just don't quite understand what your talking about. you could PM me with more detailed explanation of what you mean.


kbcarte.wordpress.com
Author

RE: Python+Microcontroller=Mouse

Demons Halo
Member



Posts: 261
Location: Sweden
Joined: 26.03.09
Rank:
Hacker Level 1
Posted on 15-03-10 00:41
correct me if I'm wrong but I think he means that the longer you hold the device in a non horizontal position, the faster the arrow moves toward that direction?

Or am I wrong once again? :p
base_dropper@hotmail.com www.demonshalo.com
Author

RE: Python+Microcontroller=Mouse

wolfmankurd
Member



Posts: 1519
Location: UK
Joined: 30.05.05
Rank:
God
Posted on 15-03-10 01:43
Demons Halo wrote:
correct me if I'm wrong but I think he means that the longer you hold the device in a non horizontal position, the faster the arrow moves toward that direction?

Or am I wrong once again? :p

pm'd. kind of. the chip outputs acceleration( or well force) right? so if you use that output to fiond out it's speed, you can then use that to find out how far it's moved. withthe help of some fudge factors which you might be able to get from it's value for g???


BY READING MY POST, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE USE OF THIS (MIS)INFORMATION.


Widowmakr@hotmail.com http://LetsHackStuff.com
Author

RE: Python+Microcontroller=Mouse

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Hacker Level 2
Posted on 15-03-10 02:16
For clairty, the values are pulse rates. Between roughly 1000 and 3000 in respective tilt directions.


kbcarte.wordpress.com
Author

RE: Python+Microcontroller=Mouse

wolfmankurd
Member



Posts: 1519
Location: UK
Joined: 30.05.05
Rank:
God
Posted on 15-03-10 08:37
So long as the value is proportional( and hopefully linear) to the force on the chip it should work. If 1000 is the lowest factor then divide all values by 1000?

Another option would be divding the value it gievs under for gravity by 9.98 (as this is g) which would give you a conversion factor from pulse rate to m/s/s. well I think at least. Or by 1000 then by 9.98 might even be best.

x_d( displacement) and x_v(velocity) should initially be zero as the mouse has not moved and is not moving. but if the mouse starts displaced (say at the center of the screen but the oftware takes the corner to be the starting point then an initial displacement may be convienient.)

If you don't buy the maths I can show you proof but it wouldn't be particulaly interesting.

But if ya can't get it to work you can't get it to work. Thanks for trying. tempted to get a chip from sparkfun and try it out for myself


update: I'm being stupid, I have a wiimote and a bluetooth laptop also I wrote a python scblockedript years a go to get the aceleration data... I'll let you guys know if I get it working.video of that scblockedript in action wonder if I still have it it was in 2007 :/


BY READING MY POST, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE USE OF THIS (MIS)INFORMATION.




Edited by wolfmankurd on 15-03-10 08:49
Widowmakr@hotmail.com http://LetsHackStuff.com
Author

RE: Python+Microcontroller=Mouse

fuser
Member



Posts: 959
Location: in front of a computer (duh)
Joined: 05.04.07
Rank:
HBH Guru
Posted on 15-03-10 10:11
techb wrote:
I was thinking more of software.


how about this?

http://camstudio.org/

I heard about it during a radio program on IT, and the dev was interviewed in person, it seems pretty impressive, and free as well.










Telling modern Internet users to stop whining is like telling them to stop breathing — it seems unrealistic and inhumane. Paul Lutus

catinthecpu@hotmail.com
Author

RE: Python+Microcontroller=Mouse

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Hacker Level 2
Posted on 15-03-10 10:38
I've used camstudio, I really liked it. All except for the quality.


kbcarte.wordpress.com
Author

RE: Python+Microcontroller=Mouse

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Hacker Level 2
Posted on 15-03-10 10:43
wolfmankurd wrote:
So long as the value is proportional( and hopefully linear) to the force on the chip it should work. If 1000 is the lowest factor then divide all values by 1000?

Another option would be divding the value it gievs under for gravity by 9.98 (as this is g) which would give you a conversion factor from pulse rate to m/s/s. well I think at least. Or by 1000 then by 9.98 might even be best.

x_d( displacement) and x_v(velocity) should initially be zero as the mouse has not moved and is not moving. but if the mouse starts displaced (say at the center of the screen but the oftware takes the corner to be the starting point then an initial displacement may be convienient.)

If you don't buy the maths I can show you proof but it wouldn't be particulaly interesting.

But if ya can't get it to work you can't get it to work. Thanks for trying. tempted to get a chip from sparkfun and try it out for myself


update: I'm being stupid, I have a wiimote and a bluetooth laptop also I wrote a python scblockedript years a go to get the aceleration data... I'll let you guys know if I get it working.video of that scblockedript in action wonder if I still have it it was in 2007 :/


I belive you 100% on the math. I also kinda understand how it works. I just can't figure out how to get the accelerometer data to mouse data. I'm going to ask my math teacher to explain in detail tomorrow(er.. well today). I really thank you for helping.

And can anyone see my signature? I can't....


kbcarte.wordpress.com
Author

RE: SOLVED

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Hacker Level 2
Posted on 16-03-10 00:45
I got it working with the physics. It cam it me in class today.

v = accelValue
Leftthreshold = 2700
Rightthreshold = 2400
BaseSpeed

if v > Leftthreshold:
x += (v-Leftthreshold)/BaseSpeed

if v < Rightthreshold:
x -= (Rightthreshold-v)/BaseSpeed


The actual code looks like:

...
if int(d[2]) > 2700:
if x < 1400:
x += (int(d[2])-2700)/10
elif int(d[2]) < 2400:
if x > 0:
x -= (2400-int(d[2]))/10
if int(d[5]) > 2600:
if y > 0:
y -= (int(d[5])-2600)/10
elif int(d[5]) < 2400:
if y < 900:
y += (2400-int(d[5]))/10
...


This gives me the desired effect.


kbcarte.wordpress.com
Author

RE: Python+Microcontroller=Mouse

ShadyTyrant
Member



Posts: 113
Location: United States Of America
Joined: 07.09.08
Rank:
Hacker Level 3
Posted on 16-03-10 07:00
Cool shit man thats awesome.


588838530 shadytyrant@hotmail.com shadytyrant@ymail.com http://shadytyrant.blogspot.com/
Page 1 of 2 1 2 >
Guest
Username

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 

 

Links
By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2008- 2009. Since 3rd December 2004.