We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Basic Stamp

Is there a way to grab values from a basic stamp with python?

I just bought a Accelerometer and want to read the values with python.

2
Contributors
3
Replies
2 Months
Discussion Span
3 Years Ago
Last Updated
4
Views
Question
Answered
Tech B
Posting Whiz in Training
268 posts since May 2009
Reputation Points: 59
Solved Threads: 33
Skill Endorsements: 0

Hi!

Can you be more specific?

programmersbook
Junior Poster
121 posts since Nov 2009
Reputation Points: 29
Solved Threads: 30
Skill Endorsements: 0

I have values in the Basic Stamps debugger and only in the debugger. I want python to be able to read the values. I'm going to map the mouse movements on the computer with the values, and possibly port the values into excel to be graphed. I can do all of that with python except read the values from the stamp.

Tech B
Posting Whiz in Training
268 posts since May 2009
Reputation Points: 59
Solved Threads: 33
Skill Endorsements: 0

After putting down this project and revisiting it after several months, I solved it. No click events yet, but it wont be hard at all.
here is the BASIC code that is loaded into the microcontrollers memory:

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

x VAR Word
y VAR Word

DO

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

LOOP

And this is the python code to map the accelorometer to the mouse movements.
Requires PySerial.

from ctypes import *
import serial
s = serial.Serial('COM5') # this will be different for everyone, I used a Serial to USB cable.
user = windll.user32
x = 0
y = 0
speed = 10
while 1:
  try:
    d = s.readline()
    d = d.split()
    if int(d[2]) > 2700:
        print 'right'
        if x < 1400:
            x += speed
    elif int(d[2]) < 2400:
        print 'left'
        if x > 0:
            x -= speed
    if int(d[5]) > 2600:
        print 'up'
        if y > 0:
            y -= speed
    elif int(d[5]) < 2400:
        print 'down'
        if y < 900:
            y += speed
    user.SetCursorPos(x,y)
  except: pass
Tech B
Posting Whiz in Training
268 posts since May 2009
Reputation Points: 59
Solved Threads: 33
Skill Endorsements: 0
Question Answered as of 3 Years Ago by programmersbook

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0622 seconds using 2.66MB