Shop OBEX P1 Docs P2 Docs Learn Events
Blender GE to Python to BS2, you know what I mean... — Parallax Forums

Blender GE to Python to BS2, you know what I mean...

ionhunterionhunter Posts: 7
edited 2009-10-08 07:43 in General Discussion
Hey:

There really is not much on this topic, so I would really appreciate some clarification on this fascinating subject.

I need to have inputs/outputs from the Blender Game Engine (BGE) to BS2 via USB.

Example: reading state of potentiometer/variable and sending signal into BGE to effect game elements and visa-versa.

If you are familiar with BGE, you know it is easy to input keystrokes from keyboard/peripheral devices to control game elements.
Heck, if need be you can hack keyboard hardware keys to receive input from stamp (on/off switch if certain conditions in BS2 code is met)

The difficult part id in BGE sending communication back to the stamp, even just as a ping would help, to verify BS2 instruction was sent.

BGE runs on Python script, how can we bridge this gap?

Suggestions are: Interface through USB/RS232 converter using serial commands

Using pyserial and/or puUSB....how?

Even BS2 sending ASCII to BGE would be fine.

Also, Blender is able to read files, how about BS2 writting data to notepad , then Blender reading notepad via ASCII?
What about spreadsheets?

Bottom line: I need a method to pass BGE variable output that BS2 can receive in real-time, input into BGE is not really a problem.

Any leads/info would be greatly appreciated.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-06 13:33
    This is normally done by using a serial port to transfer data back and forth. On the PC side, you're using a standard serial port with whatever software features you need to access that. Python has it's own library packages for that purpose. On the Stamp side, you'd use the SERIN and SEROUT statements. What you send back and forth is of your own creation. Your biggest problem is that Stamps are single threaded ... they can only do one thing at a time. When the Stamp is using the information to do something, it's not listening to the serial line for the next item. You can avoid this by having the Stamp send a character to the PC when it's ready to listen for the next value. A good example of Stamp to PC communications is StampPlot Pro which can be downloaded from Parallax's Stamp Downloads webpage.
  • ionhunterionhunter Posts: 7
    edited 2009-10-07 09:09
    Thanks Mike

    This is the kind of info I need. Remember Mike, sending data to pc/Blender is not a huge deal,I can use hacked peripherals, it is the sending of info from pc/Blender to the BS2.

    You mentioned StampPlot Pro, is there an open source version? Similar software? What I really want to do, to put it in perspective, is for the BS2 to control a set of hardware devices/sensors and set the state to variables to import into Blender, and then for Blender to do the same, in turn, towards BS2.

    Your comment: "Stamps are single threaded ... they can only do one thing at a time. When the Stamp is using the information to do something, it's not listening to the serial line for the next item"........can you elaborate some more? Eg. Analog potentiometer to ADC to BS2 to Blender. As I adjust tho pot, a cube in Blender rotates.

    Also, Blender Graphical Slider to BS2 to LED. .............ie adjusting a virtual dimmer in Blender adjusts actual LED brightness.

    How are these two scenarios similar,disimilar? What resolution/bits can be had?
    Can both scenarios be handled by the stamp at the same time? You see, there is virtually nil out there, believe me, I have looked....any ideas anyone.... Mike?hint,,hint
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-07 13:52
    StampPlot Pro is free for non-commercial use. I'm not aware of anything like it in an open source version. You may have to write your own PC program to do what you want, but StampPlot Pro is a good example of what can be done.

    single threaded ... The Stamp is not buffered. It doesn't "listen" to a serial port all the time. When you execute a SERIN statement, the Stamp stops and listens to the specified I/O pin until the data you've asked for comes in (unless you've specified a timeout). If serial data is transmitted to the Stamp at any other time, it's completely ignored. When the Stamp is reading from an ADC or generating PWM pulses for an LED, it's ignoring any information from the PC.

    This limitation can be helped by adding external "co-processors" which are just preprogrammed single-function microcontrollers that take over the function. For example, there's a serial buffer chip that has a 32 byte buffer and can be polled by a Stamp. It listens to an incoming serial stream, saves it in the buffer, and retransmits the received characters on request from the Stamp when the Stamp is ready to process them.

    As I mentioned, this can also be helped by making the Stamp the "master". There are often times when the Stamp is briefly free. It can send a signal to the PC that says "Here's the current ADC value, what do I do now?" and the PC can respond with an update for the LED brightness while the Stamp can listen.

    Depending on the number of devices that need handling, you may be better off using something like the Propeller which has multiple processors and can do several things at once including PWM, ADC, serial I/O, etc.
  • ionhunterionhunter Posts: 7
    edited 2009-10-08 07:43
    Thanks again Mike

    Very helpful, this points me in the right direction...btw any useful links for further info, like Nuts and Volts?

    Appreciated
Sign In or Register to comment.