Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to call wiringPiSPIDataRW? #9

Open
Tuckie opened this issue Sep 15, 2012 · 11 comments
Open

unable to call wiringPiSPIDataRW? #9

Tuckie opened this issue Sep 15, 2012 · 11 comments

Comments

@Tuckie
Copy link

Tuckie commented Sep 15, 2012

How are you supposed to pass the data variable into wiringPiSPIDataRW by reference? I've tried a variety of ctypes with no luck.
Trying something like:

mydata = (ctypes.c_ubyte * 2)()
returncode = wiringpi.wiringPiSPIDataRW(pin,ctypes.byref(mydata), 2)

All I get is:
TypeError: in method 'wiringPiSPIDataRW', argument 2 of type 'char *'

@prusnak
Copy link

prusnak commented Nov 5, 2012

Same question here, I tried string, array of numbers and nothing works. I guess one would need to change the Python binding to make this working, meaning that no-one tried this functionality before :-/

@andig
Copy link

andig commented Nov 17, 2012

Would like to know, too

@tpansino
Copy link

So I take it no one has found a solution to this problem? I'm amazed that this still hasn't been fixed or even addressed by any of the package maintainers...

@prusnak
Copy link

prusnak commented Feb 22, 2013

JFYI: I decided to use https://pypi.python.org/pypi/spidev/2.0 for SPI in the meantime.

@Tuckie
Copy link
Author

Tuckie commented Feb 22, 2013

I switched over to https://github.com/quick2wire/quick2wire-python-api

@Gadgetoid
Copy link
Member

Amazingly late to the game here, but I have started maintaining WiringPi again in the form of a new version which you can find here: https://github.com/WiringPi/WiringPi2-Python

The function wiringPiSPIDataRW now takes two arguments, pin and the string. Length and conversion to the correct datatype is handled internally. You should be able to call it thus: wiringPiSPIDataRW(1,'badger')

I am the sole maintainer of this package, and had more pressing distractions. I'm tremendously late in getting it updated and offer my apologies. I'd love to see you guys come back to WiringPi2-Python and test it out; I'll be around to attempt to fix any problems you might have.

@talkingnews
Copy link

Hi all,

Anyone know what I might be doing wrong here? All I get back is a number representing the number of characters I SENT, not the data I expect back from the Arduino.

import wiringpi2
wiringpi2.wiringPiSPISetup(1,500000)
b=1
while b < 8 :
    myData=wiringpi2.wiringPiSPIDataRW(1,'\n')
    print myData
    b=b+1

Been at this since last Thursday - I kid you not. I bought a second logic level shifter just in case the first was dud.
This morning, a logic analyzer arrived from ebay - I can SEE the data is being returned from the Arduino, which sends back

SPI.transfer(0x48);

every time wiringpi2 sends it a \n.

I've put the logic analyzer on all points, I've taken the speed down as low as it will go.

And all I get, every single time, is the number 1 returned. If I put two characters like A\n I get "2", if I send "HELLO", I get "4".

I've googled myself silly trying to find an answer. Any ideas greatly appreciated.

@Gadgetoid
Copy link
Member

I think your problem is that you're setting myData to the return value of wiringpi2.wiringPiSPIDataRW which is, in fact, not the data being read.

What you need to do is this:

myData = '\n'
wiringpi2.wiringPiSPIDataRW(1,myData)
print myData

If this doesn't work, then some nuance of the wrapped library means that the buffer value ( the second parameter ) is not being correctly overwritten in C, or not bubbling back up to Python. There might be a way around this, but I'd have to hack about with the C library itself.

Edit: If it doesn't work, and you'd like to post some counterpart Arduino code, I'd be happy to try and replicate your setup. I run my Arduinos on a breadboard at 3.3v so I don't have to worry about logic levels and should be able to get up and running pretty quickly.

@talkingnews
Copy link

1: You, sir, are a God-like genius. And I should have asked at some point during the weekend. In other words, spot on. Absolutely kicking myself. On the bright side, I now have a spare logic level converter and a useful probe for future use.

2: I never realised you could run the Arduino at 3.3v. Another useful lesson learnt!

Once again, massive thanks for your quick reply. I was starting to go spare here!

@Gadgetoid
Copy link
Member

Glad to have helped!

I build my Arduinos using an ATMega 328P on a breadboard and run it at 3.3v using an FTDI breakout board or a voltage regulator hooked to the Pi's 5v line ( cutting it close to dropout though ). 3.3v @ 16Mhz works, but it's not recommended for any serious usage as far as I understand. You can drive 'em lower than that, too.

I've got to get a probe sooner or later. Not because I need it, but the portable ones look so shiny! What did you get, and is it any good?

@talkingnews
Copy link

Re: probe. I'm pretty sure the purists won't like this, but I got this SALAEA clone. If you're in the UK http://www.ebay.co.uk/itm/161052042090 would be the one. NOTE: It's £9.97 and NOT normally £109.97! Apparently because it's low stock or something to do with not wanting to unlist from ebay but also not wanting to sell the last 3 so the listing stays, and they've got more coming soon - I got it for £10 including postage and a bundle of probes.
I just downloaded SALAEA 1.1.18 beta and I was up and running within 10 minutes, which is quite remarkable seeing as I'm normally so thick at stuff. It's very intuitive - click "SPI monitor", put cables in right holes, select a sample rate faster than your SPI mode, select a trigger, and off you go. If even I can do it, I'm fairly sure anyone else could breeze it!

*Yes, I do realise the "clones don't support development" argument before anyone kicks me, but this is a one-off non-commercial project, no-one is paying me. I'd love to be able to afford £110 for a "real" one, but I can't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants