# node.pcduino
A node.js module for accessing the Arduino compatible pins on the pcDuino microcontroller. It tries to maintain as close a match as possible to the original Arduino C++ functions.
## Installing Node.js runtime on the pcDuino
It turns out the easiest way to install the latest version of node.js on the pcDuino is to use the precompiled binaries for the Raspberry Pi as provided by the folks at nodejs.org. Here's how to install it on the pcDuino from the command line:
```
wget http://nodejs.org/dist/v0.10.24/node-v0.10.24-linux-arm-pi.tar.gz
tar xvzf node-v0.10.24-linux-arm-pi.tar.gz
cd node-v0.10.24-linux-arm-pi
# Remove some extra files that we don't need
rm ChangeLog LICENSE README.md
sudo cp -R * /usr/local
```
You can replace the version to install later versions (0.10.24 was the latest as of this writing), but it does appear that the Raspberry Pi binaries tend to lag behind the latest version on the Node.js website by a couple versions.
## Installing the Node Package
From the command line:
npm install pcduino --save
Adding the --save switch will automatically add it to your package.json file.
## A digital example
```js
var pcduino = require("pcduino");
var digital = pcduino.digital;
// digital.simulate(true); - Can be used for testing purposes when you're not running on a pcDuino. This will read and write to dummy files.
console.log("There are " + digital.PIN_COUNT + " digital GPIO pins on the pcDuino.");
digital.pinMode(10, digital.INPUT); // Set pin #10 to input
digital.pinMode(10, digital.INPUT_PU); // Set pin #10 to input with pull-up
var state = digital.digitalRead(10);
console.log("The value of pin #10 is " + (state == digital.HIGH ? "HIGH" : "LOW"));
digital.pinMode(10, digital.OUTPUT); // Set pin #10 to output
digital.digitalWrite(10, digital.HIGH); // Set pin #10 HIGH
state = digital.digitalRead(10);
console.log("The value of pin #10 is now " + (state == digital.HIGH ? "HIGH" : "LOW"));
digital.digitalWrite(10, digital.LOW); // Set pin #10 LOW
state = digital.digitalRead(10);
console.log("The value of pin #10 is now " + (state == digital.HIGH ? "HIGH" : "LOW"));
```
## An analog example
```js
var pcduino = require("pcduino");
var analog = pcduino.analog;
console.log("There are " + analog.PIN_COUNT + " analog pins on the pcDuino.");
// Note that the only valid pins for analog output are 3, 5, 6, 9, 10, and 11. These are PWM (digital) pins on the pcDuino and not to be confused with the analog input pins. Any other pin specified will throw an error.
var maxValue = analog.maxWriteValue(5);
console.log("The maximum number that can be written to analog pin #5 is " + maxValue);
analog.analogWrite(5, maxValue); // Turn our pin fully up
// Note this is not the same as the analog write pin #5! This maps to the analog input pins on the pcDuino. Valid pins are 0, 1, 2, 3, 4, 5.
var readValue = analog.analogRead(5);
console.log("The analog value of pin #5 is " + readValue + ". Note this is not the same as the analog write pin #5!");
```
## Limitations
The current version of this module uses the standard unix filesystem mappings to the GPIO pins which, while fast enough for most general purposes, are not fast enough to perform high-speed protocols (like 1-wire for example).
There is a subdirectory called WIP, which is a start to some pure C++ native code access to the pins— although even it appears to be too slow and will probably require the use of interrupts or DMA at some point.
没有合适的资源?快使用搜索试试~ 我知道了~
一个 node.js 模块,用于访问 pcDuino微控制器上的 Arduino 兼容引脚_C++_代码_相关文件_下载
共42个文件
h:13个
cpp:11个
c:7个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 194 浏览量
2022-07-08
02:13:05
上传
评论
收藏 46KB ZIP 举报
温馨提示
一个 node.js 模块,用于访问 pcDuino 微控制器上的 Arduino 兼容引脚。它试图保持与原始 Arduino C++ 函数尽可能接近的匹配。 在 pcDuino 上安装 Node.js 运行时 事实证明,在 pcDuino 上安装最新版本的 node.js 最简单的方法是使用 nodejs.org 上提供的用于 Raspberry Pi 的预编译二进制文件。以下是从命令行在 pcDuino 上安装它的方法: 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
node.pcduino-master.zip (42个子文件)
node.pcduino-master
WIP
src
addon.cc 264B
onewire
onewire.cpp 6KB
onewire.h 627B
onewire-wrapper.cpp 3KB
onewire-wrapper.h 631B
gpio
gpio.cpp 1KB
gpio.h 791B
gpio-wrapper.cpp 5KB
gpio-wrapper.h 764B
binding.gyp 306B
package.json 442B
pcduino.js 102B
src
WInterrupts.c 3KB
Serial.h 2KB
wiring_shift.c 996B
node_pcduino_analog.cc 1KB
WString.h 6KB
wiring_private.h 1KB
Tone.cpp 13KB
Arduino.h 3KB
WMath.cpp 531B
Stream.h 4KB
wiring_analog.c 7KB
platform.c 1KB
Print.cpp 5KB
wiring_pulse.c 689B
pins_arduino.h 2KB
main.cpp 328B
binary.h 10KB
Serial.cpp 7KB
wiring.c 1KB
Print.h 2KB
WString.cpp 13KB
WCharacter.h 4KB
wiring_digital.c 3KB
Stream.cpp 7KB
.gitignore 25B
lib
analog.js 896B
gpio.js 3KB
.gitignore 3B
README.md 3KB
binding.gyp 277B
共 42 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功