russtheaerialist-retired-projects / node-spi

A NodeJS interface to the SPI bus on embedded linux machines
ISC License
95 stars 32 forks source link

Error installing on Raspberry Pi #17

Closed losttime closed 9 years ago

losttime commented 9 years ago

I get an error running npm install spi on my Raspberry Pi (model B) running Raspbian.

Error output in pastebin: http://pastebin.com/DuGqZyrv

Am I possibly missing some system dependencies?

graysonarts commented 9 years ago

From the errors, I'm guessing there is some work to be done to get it to work with 0.12.0. I haven't been actively developing or using the module in a while, so I haven't kept up to date on the latest versions of node. I'll take a look this weekend to see if I can figure it out with the latest node version.

From my brief investigation, it looks like ObjectWrap doesn't exist anymore, and that's leading to other errors.

haydockjp commented 9 years ago

I also have this issue. Is there a possibility of an update for 0.12?

haydockjp commented 9 years ago

I tried a couple of different versions of node. v0.11.9 - has the same issue v0.10.2 - works

losttime commented 9 years ago

I've started using pi-spi

He claims to have updated it for 0.12.0, but I haven't tested it yet.

goums commented 9 years ago

Hi, I have the same issue, would be lovely to benefit from your module on recent node version ;)

graysonarts commented 9 years ago

I'm not going to rev to a new version of node/io until the split has been resolved/addressed.

gthole commented 9 years ago

IO.js is joining the Node foundation. I'd like to use some libraries that depend on this one - can it be rev'd to 0.12.0? Thanks!

graysonarts commented 9 years ago

I'm working on it. There are a ton of breaking changes on the native side in the 0.12 release, so it's not going to be a super quick fix to get it building again.

I will need some help with testing it because I don't have any SPI devices right now, so I have no way of testing the actual functionality.

graysonarts commented 9 years ago

This compiles, though I do not have a SPI device to test it with right now. If someone wants to give this a shot while I wait for the SPI oled screen I ordered to come in: https://github.com/RussTheAerialist/node-spi/commit/a01fead772fcf71e1130b519700ff3dea9d9130d#diff-25d902c24283ab8cfbac54dfa101ad31

It cleans up the native code a bit also.

gthole commented 9 years ago

Thanks @RussTheAerialist! I'll pull this down tomorrow and give it a try against my Mcp3008 ADC too.

gthole commented 9 years ago

It compiles/installs correctly on my RasPi (woo!), but I only get 0 readings off of a trimpot connected to an Mcp3008. That said, I'm kinda new to hardware, so I might have something done something wrong.

graysonarts commented 9 years ago

Can you post your code? I might have an mcp3008 (need to check my parts collection), so I can see what's going on. I've had other reports of all zeros before, but I thought that was fixed, though in cleaning up the code, I might have done something stupid.

gthole commented 9 years ago

I cloned and modified the package.json for the Mcp3008 library to point the "node-spi" dependency to the master branch of this repo, then ran this (almost verbatim from the example code):

'use strict';

var Mcp3008 = require('mcp3008.js'),
    adc = new Mcp3008(),
    channel = 0;

adc.read(channel, function (value) {
    console.log(value);
});

(That's with SPI enabled, obviously, and using the wiring diagram on this page but with a trimpot instead of a light sensor.)

graysonarts commented 9 years ago

ah yeah, I'm not so familiar with the mcp3008 library. I'm reading up on the mcp3008 (I found one in my parts box). I'm not sure I'll get to troubleshooting today or not, but let me see if I can duplicate what you have setup, and I'll post when I have the troubleshooting done.

gthole commented 9 years ago

Amazing, thanks @RussTheAerialist!

graysonarts commented 9 years ago

Hey, I was able to get a test bed setup with the mcp3008, and I was able to get it to work. However, I did make a small mistake where it was having everything be zero. There are two clock pins on the raspberry pi. One is for I2C which is labeled SCL, and the other for SPI which is labeled SCLK.

Can you verify which pin off of the raspberry pi you are connecting pin 13 on the mcp3008 to? Using my logic analyzer, I was able to see data coming across and it was being read by node without a problem.

spi_capture This was just with a floating analog pin since I don't seem to have any free trim-pots right now.

graysonarts commented 9 years ago

I should mention a couple of things:

{
  mode: 0,
  chipSelect: 0, /* Low */
  maxSpeed: 15000 /* 15Khz to slow things down */
}
gthole commented 9 years ago

That worked! Thanks a bunch - I'm happy to put in a PR to the Mcp3008.js library to pass SPI options unless you'd prefer to do it.

Thanks again @RussTheAerialist.

graysonarts commented 9 years ago

I'll go ahead and put one in. Thanks for verifying that it worked for you too!

NiallNiall commented 9 years ago

Can I just register my interest in case you do end up updating thing? Just trying to get my MCP3008 working with node and keep getting errors nstalling with node gyp.

graysonarts commented 9 years ago

@NiallNiall - which version of node? I haven't had time to work on the documentation, but I'm going to push the Node 0.12.x compatible version to npm tonight.

graysonarts commented 9 years ago

0.2.0 has been pushed to npm. It's compatible with 0.12.x.

NiallNiall commented 9 years ago

Oh great! Thanks a lot! I'm away from my Pi till Monday, but looking forward to trying it out then.

It was on Node 0.12.1 (I think...) Although I did nvm to 10.0.2 and while the installation appeared to work, I got a different error saying the module didn't register correctly when trying to require it in a script.

Hopefully latest update will solve it. Thanks a bunch for pushing it either way though.