Follow us on Twitter!
Become the change you seek in the world. - Gandhi
Wednesday, April 23, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 26
Guests Online: 24
Members Online: 2

Registered Members: 82877
Newest Member: MWiki
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:
Moderate
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.facebo. . .937&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:
Code

' {$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:
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






www.userbars.com/74460/665255/337-7865-ubda3219.gif


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

RE: Python+Microcontroller=Mouse

MjWasHere
Member

Your avatar

Posts: 15
Location:
Joined: 03.07.07
Rank:
Guest
Warn Level: 5
Posted on 14-03-10 06:25
Awesome !!!
Great work there !!! Smile
Author

RE: Python+Microcontroller=Mouse


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
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 Smile

edit: video explains alot.




Edited by on 14-03-10 12:44
Author

RE: Python+Microcontroller=Mouse

yours31f
Member



Posts: 1678
Location: Dallas Texas
Joined: 27.04.07
Rank:
Elite
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.


img259.imageshack.us/img259/3713/sigr.png

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

RE: Python+Microcontroller=Mouse

fuser
Member



Posts: 960
Location: in front of a computer (duh)
Joined: 05.04.07
Rank:
Mad User
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.




img.userbarz.com/51/10006.png
img.userbarz.com/146/29144.gif
img.userbarz.com/99/19602.jpg
img.userbarz.com/4/600.png
img.userbarz.com/45/8814.gif
img360.imageshack.us/img360/9231/bfbarlr0.jpg
[url=http://userbarz.com/][img]ht
catinthecpu@hotmail.com
Author

RE: Python+Microcontroller=Mouse

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Moderate
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?


www.userbars.com/74460/665255/337-7865-ubda3219.gif


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:
Moderate
Posted on 14-03-10 20:51
I was thinking more of software.


www.userbars.com/74460/665255/337-7865-ubda3219.gif
kbcarte.wordpress.com
Author

RE: Python+Microcontroller=Mouse


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
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.


Author

RE: Python+Microcontroller=Mouse

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Moderate
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.


www.userbars.com/74460/665255/337-7865-ubda3219.gif
kbcarte.wordpress.com
Author

RE: Python+Microcontroller=Mouse


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
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? Smile




Edited by on 14-03-10 22:15
Author

RE: Python+Microcontroller=Mouse

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Moderate
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? Smile


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.


www.userbars.com/74460/665255/337-7865-ubda3219.gif
kbcarte.wordpress.com
Author

RE: Python+Microcontroller=Mouse

Demons Halo
Member



Posts: 261
Location: Sweden
Joined: 26.03.09
Rank:
Apprentice
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? Pfft
base_dropper@hotmail.com www.demonshalo.com
Author

RE: Python+Microcontroller=Mouse


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
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? Pfft

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???


Author

RE: Python+Microcontroller=Mouse

techb
Member



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


www.userbars.com/74460/665255/337-7865-ubda3219.gif
kbcarte.wordpress.com
Author

RE: Python+Microcontroller=Mouse


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
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 script years a go to get the aceleration data... I'll let you guys know if I get it working.video of that script in action wonder if I still have it it was in 2007 :/




Edited by on 15-03-10 08:49
Author

RE: Python+Microcontroller=Mouse

fuser
Member



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


how about this?

http://camstudio.. . .

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.


img.userbarz.com/51/10006.png
img.userbarz.com/146/29144.gif
img.userbarz.com/99/19602.jpg
img.userbarz.com/4/600.png
img.userbarz.com/45/8814.gif
img360.imageshack.us/img360/9231/bfbarlr0.jpg
[url=http://userbarz.com/][img]ht
catinthecpu@hotmail.com
Author

RE: Python+Microcontroller=Mouse

techb
Member



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


www.userbars.com/74460/665255/337-7865-ubda3219.gif
kbcarte.wordpress.com
Author

RE: Python+Microcontroller=Mouse

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Moderate
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 script years a go to get the aceleration data... I'll let you guys know if I get it working.video of that script 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....


www.userbars.com/74460/665255/337-7865-ubda3219.gif
kbcarte.wordpress.com
Author

RE: SOLVED

techb
Member



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

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:
Code

...
   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.


www.userbars.com/74460/665255/337-7865-ubda3219.gif
kbcarte.wordpress.com
Author

RE: Python+Microcontroller=Mouse


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 16-03-10 07:00
Cool shit man thats awesome.


Page 1 of 2 1 2 >