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

Support different SPI devices. #509

Closed
bodokaiser opened this issue Apr 7, 2018 · 4 comments
Closed

Support different SPI devices. #509

bodokaiser opened this issue Apr 7, 2018 · 4 comments

Comments

@bodokaiser
Copy link

bodokaiser commented Apr 7, 2018

I would like to use the /dev/spidev1.0 (which works with python) but gobot only supports /dev/spidev0.0 and /dev/spidev0.1.

package main

import (
	"log"

	"gobot.io/x/gobot/platforms/beaglebone"
)

func main() {
	beagle := beaglebone.NewAdaptor()

	c, err := beagle.GetSpiConnection(0, 5e6, 0)
	if err != nil {
		log.Fatal(err)
	}

	w := []byte{0x00}
	r := []byte{0x00}

	err = c.Tx(w, r)
	if err != nil {
		log.Fatal(err)
	}
}

I can access /dev/spidev1.0 if I change the device path here.

To support different spi devices I would suggest to add another device int parameter to GetSpiConnection(), however this would break API compatibility.

@bodokaiser bodokaiser changed the title Segmentation Fault when using SPI with Beaglebone Black Cannot use /dev/spidev1.0 (Bus number 2 out of range) Apr 8, 2018
@bodokaiser bodokaiser changed the title Cannot use /dev/spidev1.0 (Bus number 2 out of range) Support different SPI devices. Apr 8, 2018
@deadprogram
Copy link
Member

There is a problem with reading SPI data that I am currently working on.

There is a very high probability of Gobot changing out the SPI API, which will fix the devices, but break the API for device implementors.

One of the needed changes would accommodate setting both the device bus ID, and chip ID. This would address your particular concerns, @bodokaiser

More soon...

@deadprogram
Copy link
Member

Hi @bodokaiser please take a look at the dev branch which has the new SPI implementation.

All the the spi drivers now support optional params. You can now set the specific device bus and chip like this:

a := raspi.NewAdaptor()
adc := spi.NewMCP3008Driver(a, spi.WithBus(1), spi.WithChip(0))

Which should give you access to /dev/spidev1.0 as you require.

Please give it a try, your feedback is appreciated.

@bodokaiser
Copy link
Author

I can confirm that

package main

import (
	"log"

	"gobot.io/x/gobot/platforms/beaglebone"
)

func main() {
	beagle := beaglebone.NewAdaptor()

	c, err := beagle.GetSpiConnection(1, 0, 0, 8, 5e6)
	if err != nil {
		log.Fatal(err)
	}

	w := []byte{
		8, 0, 0,
		1, 3, 64, 8, 32,
		14, 63, 255, 0, 0, 1, 137, 0, 0,
		0, 0, 128, 2, 2,
		9, 0, 0, 255, 252,
		7, 1, 137, 0, 0,
	}
	r := make([]byte, len(w))

	err = c.Tx(w, r)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("%v", r)
}

works as expected. Thank you!

@deadprogram deadprogram added the interface-request things like new protocols and/or interfaces label Apr 12, 2018
@deadprogram
Copy link
Member

This has now been released as part of v1.10.0 so now closing this issue. Thanks everyone!

@deadprogram deadprogram removed the interface-request things like new protocols and/or interfaces label Apr 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants