How to interface with a Nintendo WiiMote through Python 3.3? - python

I am trying to read the button states and accelerometer and IR camera values with Python 3.3 but none of the ways that I have tried work. The first way is through Bluetooth sockets with this code:
import socket
if __name__ == '__main__':
MAC = '00:1F:C5:35:91:5A'
blue = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
wm = blue.connect((MAC,1))
But this always generates errors. When the computer is already paired to the WiiMote I get No route to host, when I'm not connected but visible I get Operation now in progress and when I'm not visible I get Connection reset by peer.
I'm able to read the button states with pygame.joystick and cat /dev/input/js0 but this leaves me unable to send requests to the WiiMote which allow me to read the accelerometer and IR camera values.
The are also modules such as CWiiD and PyWiiUse but are only compatable with Python 2.x. I have also tried using the HID to send these requests but the modules install for Python 2.7 even though I don't have that version of Python installed.
Is there any way that this task can be accomplished? I'm running Ubuntu 13.10 on a 64 bit Intel i5 and the solution doesn't need to platform independent.

Related

How to connect to USB TTY from BeagleBone Black?

I would like to establish serial communication from a Windows PC to the BeagleBone Black. The purpose is to have a Python application on the BeagleBone interact with a terminal running on the PC. I would like to use the same USB cable I use for the SSH connection (from PC to micro-usb on the BB), but instead of SSH, I want to open a serial connection via something like TeraTerm, and have a running python application connect to the TTY, something like /dev/ttyUSB. However, this TTY does not exist.
Note that I'm not trying to do serial debugging, as this article suggests. I'm also not trying to do this connection over UART. I specifically want to communicate with a python application via a terminal running on the PC. The Python application would use a library like pyserial.
Since the TTY is not showing on the BeagleBone, how can I proceed?
A TTL to USB converter will work. I got an older model that is still produced from some company. Here is one I found easily online at Adafruit: https://www.adafruit.com/product/954.
That will give you TX, RX, GND, and PWR. Please make sure to get a 3.3v type if you are using it for the BBB.
Here is some write up w/ questions/answers: https://askubuntu.com/questions/40959/how-do-i-connect-to-tty-com-dev-ttyusb0
Sometimes when you use PuTTY w/ Win 10 COM ports, it is necessary to make sure you get the COM port correct. Actually, every time! Click on the connection ICON on the bottom, right of the screen under the "^", click on the Open Devices and Printers, and then go to the BBB on the photo screen. Once you right click and go to Properties, finally click on the Hardware tab to find your COM Port. Then, one can use a COM Port on Win 10 w/ the BBB along w/ PuTTY.
So, w/ PuTTY, you can click the serial connection, type your COM Port (COM6 or whatever), and finally click Open.
...

Trying to read data from old gadget with pylibftdi fails

I have a small USB device from Windows XP times. It receives a sea weather report on a special frequency and transmits it in text form. This requires a program and driver that only runs on Windows XP. (Old Page here: http://www.navichart.com/wettermaus.htm)
I would now like to try to get the device running with python3 under Linux in order to later turn it into a raspberry project.
The device is recognized by Linux:
lsusb results in:
Bus 001 Device 016: ID 0403: f9d9 Future Technology Devices International, Ltd NAVCODE weather mouse
I opened the Device and found some Chips on it: FTDI FT232BM, Atmel ATMEGA8L and some others, smaller ones.
For this reason I thought it might be possible to access the device with pylibfdti and read the weather report.
I proceeded here according to:
https://pylibftdi.readthedocs.io/en/latest/installation.html
But if I try the following code I only get an empty list and nothing to print.
#!/usr/bin/env python3
import sys
import pylibftdi
print(pylibftdi.Driver().list_devices())
Results in
[]
I checked in a VirtualBox running Windows XP: The old programm and the USB-Devive are working normal.
I have no experience with programming such chips and i have no other device to check wether i made an mistake.
Do I have a "mistake in my thoughts" and my project cannot work at all?
Thanks for your advice.
F.E.

How to send data through parallel port in Python?

I need to send some data via parallel port using Python. And for this I am using psychopy.parallel module.
I have two Windows 7 x64 machines connected via parallel port. This connection is tested and working because it is used by another software to send data via LPT1 port.
I have installed the necessary libraries for psychopy.parallel as described here.
Here is my naive intuition:
Machine 1 (Sending data):
from psychopy import parallel
port = parallel.ParallelPort(address="0xC010")
port.setData(3) # sets just pin 2, 3 high
Checking on Machine 1
port.readData()
> 3
Checking on Machine 2 (Receiving data):
from psychopy import prallel
port = parallel.ParallelPort(address="0xEC00")
port.readData()
> 0
I see that although I can set the pins correctly on Machine 1 and read the result, Machine 2 just gives me a 0.
How to send and receive a signal via parallel port correctly?
There are a few options:
Maybe you haven't got the right driver for pyparallel/psychopy to talk to. You'll need a 32bit parallel port driver if you're using the Standalone PsychoPy (which includes 32bit python). The answer in the link below tells you how to download another test utility that will insert the correct version of both 32bit and 64bit drivers, which you need to do on both machines obviously
your script sending the pules will finish immediately and conceivably the pins are all being set back to low when the script ends? (I think this isn't usually the case but worth checking)
have you set the right address for the parallel port? Your code currently uses the default address but there are various options.
Lastly, the link below tells you how to do it using inpout32.dll directly but I think the drivers are the first thing to get fixed
PsychoPy sending triggers on 64bit OS

Python Pyserial Windows No Port Found

I have just tried to connect to usb mobile to send sms through it using AT commands. But when i use pyserial to connect to it in a windows os, i get error could not open port, the file specified cannot be found.
>>> import serial
>>> ser = serial.Serial(0) # open first serial port
>>> print ser.name # check which port was really used
>>> ser.write("hello") # write a string
>>> ser.close()
even if i replace the 0 with any other value, like 0 -10 or 'com0','com1' etc, i still get error file specified not found, port cannot be open.
There is a command listed in pyserial documentation which lists ports or allows you to open a port
python -m serial.tools.miniterm
This command is supposed to list all serial ports. But it shows none.
I have 3 usb ports on my system. What is causing this issue.
Pyserial is not guaranteed to detect all ports. This depends on how the device and the OS communicate and if pyserial is designed to pick up on this. For Example, pyserial could not detect a LabJack U3-LV or a EPSOM-POS receipt printer I plugged in in a Win8 session (both could be detected using a linux session).
Try serial.tools.list_ports.comports() and see what it gives you.
You could also look at the pyusb module for usb connections.
Also: I recommend being careful when using numbers for ports, as the mapping may not be "common-sense" logical (i.e. 0 may not map to COM0). Use explicit string names instead.
I found the solution myself. Its pretty simple and uses the same code in the question.. I was getting blocked error because there was no modem(nokia phone) in my device manager. although i had plugged in my phone into the usb, there was no nokia pc suite installed. Once you install nokia pc suite and connect your nokia phone, in device manager -> modems your phone will appear. Just check its properties->modem and you will find the com5 or whichever number. Then use that id to connect. If you dont know this, just iterate till you find the right one.
Thanks everyone who tried to help

Half-duplex serial communications in Python

I have a device with a built-in USB/Serial adapter (shows up as a Prolific PL2303). The device documentation provides full details on how to communicate with it, and provides a sample Windows app. However, I need to use it on Linux - ideally with Python but I'm not too precious about that.
The device docs state the device runs at 9600, 8N1 with half duplex. The Windows app works fine - device works fine (so I know it's not a device problem). However, I can't communicate with it using Python on Linux. I'm using pySerial, and I've tried a similar (full duplex, also PL2303) device which works fine.
I've tried several combinations of setting xonxoff, rtscts etc. I've also tried RTS toggling using setRTS(True) and checking for CTS and DSR etc - gets all return False. I can successfully open the device using pySerial (I can see activity light flashing - simple but effective test) and pySerial complains if you unplug it during reads/writes.
Doesn't seem to matter what flags/lines I set or what data I send, always get the same result.
>>> s=serial.Serial()
>>> s.port('/dev/ttyUSB1')
>>> s.open()
>>> s
Serial<id=0x7fe94b533b50, open=True>(port='/dev/ttyUSB1', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=3, xonxoff=0, rtscts=0, dsrdtr=0)
>>> s.write('\2CMD2292\r')
>>> s.inWaiting()
0
>>> s.setRTS(True)
>>> s.getCTS()
False
(several iterations of above with different flags).
Ignore the data in the write command - that's just a status check command. Doesn't matter what goes there, the device should either respond with an answer or an error.
I've even resorted to closing and re-opening the device in between setting various ctsrts flags etc., and unplugging / replugging it to force resets. As above it continues to work fine using the Windows test app. I can't use Portmon etc. to sniff the Windows port traffic as it's a 64bit Win7 install and I don't currently have time to build an XP machine.
Any thoughts?
UPDATE: I've also tried all of the above using Python on the same Windows box that the demo app works on. It definitely opens the port and communicates, but again no info back regardless of what's written.
UPDATE2: It looks like it might be device-driver related. Some additional background research suggests that some PL2303 chips have functionality to support half-duplex, but this isn't supported by the Linux drivers. The Windows demo app comes with a dedicated device driver and the app doesn't work on a clean test machine using default Windows drivers. This makes me think that while I can connect to it successfully through Python, I can't control the duplex comms (e.g. even in an STX/ETX way) and therefore this might be a hopeless case. sigh.
UPDATE3: Thanks for the comments below. However, I couldn't find any way round this. I tried a USB protocol analyser, and I tried disassembling the driver but it just became rather time-consuming, so in the end I took the device apart and after some tinkering I managed to replace the existing usb-serial adapter with a proper PL2303 part - on the device side, it was just a basic 2-wire serial interface so it didn't care what was talking to it. I can't seem to close this question so I'll leave it as-is.
Try
s.flush()
just after your s.write call

Categories