I'm writing code with the johnny five library to pilote a process. Sometime I find some i2c device not include in the johnny-five library. One of them is the Adafruit AS7262 (https://www.adafruit.com/product/3779)
With johnny-five we could read and write i2c like describe here : http://johnny-five.io/api/board/
With :
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
this.i2cConfig();
this.i2cWrite(0x01, 0x00, [0x02, 0x03]);
});
enter code here
And :
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
this.i2cConfig();
this.i2cRead(0x01, 0x00, 6, function(bytes) {
console.log("Bytes read: ", bytes);
});
});
In the documentation of the Adafruit AS7262 https://cdn-learn.adafruit.com/assets/assets/000/052/623/original/AS7262_DS000486_2-00_%281%29.pdf?1522179774
or in the code of the library for arduino use : https://github.com/adafruit/Adafruit_AS726x/blob/master/Adafruit_AS726x.h
I find some HEX adress that I have try to use for acess the datas from the device but i get nothing and when i put some light on the device the output value doesn't changes here my code :
this.i2cConfig();
this.i2cRead(0x49,0x0D,16,(byte)=>{
console.log("Bytes read : " + byte)
})
0x49 is suppose to be the adress of the device
0x0D is suppose to be the register adress for the value of intensity of green light
and I read 16 bytes from there if i well understand but i get this :
Bytes read : 0,0,0,114,64,0,0,0,0,0,0,0,0,0,0,0
And nothing change with light intensity changes (it's work when i run the Arduino library, so the device works)
I try to initiate the device with the write method but i dont understand what put in to make it work.
I never use i2c protocol before so I probably don't understand something basic.
Related
I am trying to make a connection between Matlab and a Javascript (typescript in my case) program with a COM automation server as suggested on the MathWorks website. The docs on the website have examples for some languages created by MS, not for javascript.
I can't seem to find a lot of information on how to establish such a COM connection with JS. From what I've read, it's an old Microsoft feature that was only used with Internet Explorer.
Problem
The program I am writing is a VS Code extension, thus I am not using Internet Explorer at all. As a result, I do not believe I can use ActiveXObjects.
Question
Is there another way to establish a connection between my typescript code and the Matlab instance?
Goal
I am trying to run Matlab files from the VS Code terminal without opening a custom Matlab terminal or the complete Matlab GUI. The output should be displayed in the VS Code terminal as well. On MacOS and Linux, I can simply use the CLI tools, but due to the differences between the Windows version and MacOS/Linux versions, this is not possible on Windows.
I haven't used TypeScript very much, and what little I did, it was a long time ago when it was completely new.
However, the NPM package win32ole can be used in NodeJS, so I would assume you would be able to use it in Typescript as well (perhaps with some minor modifications to the example, or a small wrapper).
win32ole npm page
This is an example from that page, showing how to interact with Excel to create and save a worksheet.
try{
var win32ole = require('win32ole');
// var xl = new ActiveXObject('Excel.Application'); // You may write it as:
var xl = win32ole.client.Dispatch('Excel.Application');
xl.Visible = true;
var book = xl.Workbooks.Add();
var sheet = book.Worksheets(1);
try{
sheet.Name = 'sheetnameA utf8';
sheet.Cells(1, 2).Value = 'test utf8';
var rg = sheet.Range(sheet.Cells(2, 2), sheet.Cells(4, 4));
rg.RowHeight = 5.18;
rg.ColumnWidth = 0.58;
rg.Interior.ColorIndex = 6; // Yellow
var result = book.SaveAs('testfileutf8.xls');
console.log(result);
}catch(e){
console.log('(exception cached)\n' + e);
}
xl.ScreenUpdating = true;
xl.Workbooks.Close();
xl.Quit();
}catch(e){
console.log('*** exception cached ***\n' + e);
}
To develop an algorithm I used TurfJs library to avoid to do some calculations my self, and I have been asked to integrate the algorithm to an Eclipse Vert.x server, in which I'm new.
So I tried to import it directly like usual: var turf = require("#turf/turf");
and when I execute using this command: ./node_modules/.bin/vertx run server.js, I get this error:
Thread Thread[vert.x-eventloop-thread-1,5,main] has been blocked for 2762 ms, time limit is 2000
javax.script.ScriptException: TypeError: Cannot redefine property "name" of function IndexOutOfBoundsException (message) {
Error.call(this);
this.message = message || '';
} in node_modules/#turf/turf/turf.js at line number 26251
Here is server.js code if needed:
var Router = require("vertx-web-js/router");
var turf = require("#turf/turf");
var server = vertx.createHttpServer();
var router = Router.router(vertx);
router.get("/").handler(function (ctx) {
var response = ctx.response();
response.putHeader("content-type", "application/json; charset=utf-8");
response.end("[\"foo\",\"bar\"]");
});
server.requestHandler(router.accept).listen(8080);
Note: here I haven't yet used turf, because just importing it causes the above problem.
Please help, Is it possible to use Javascript/nodejs library in Vert.x ?
So I'm answering my question, after a lot of searches I ended that the problem is with TurfJs which is deprecated from turf to #turf/turf according to this link
so I tried to to use turf rather than #turf/turf, and it works even it show this message:
Thread Thread[vert.x-eventloop-thread-1,5,main] has been blocked for 2627 ms, time limit is 2000
Succeeded in deploying verticle
I have two sound sensors which both are Arduino compatible. One is AVR PIC F Arduino Sensitive Audio Sound Microphone Mic Sensor Detection Module, another is just a different brand comes with Arduino kit. I tried to use the following code with Johnny-five:
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var mic = new five.Sensor("A0");
mic.on("data", function() {
console.log(this.value);
});
});
I connected Digital output to A1 and Analog output to A0, and I tried only connecting to A0 without digital too. However, the AO output which is the (this.value in the code) are appearing a bit fluctuating but mainly steady value that is not affected by sound input at all.
I tried C code to test the sensor, it works. So the hardware is good but I am sure the connection is correct or I need any extra code for this?
Anyone has a sound sensor working with Johnny-five, please advise.
Thank you so much!
Node.js (on Ubuntu) uses the XBee API library as the ZigBee coordinator API to send data to XBee as ZigBee router AT every one minute. It's fine for 10 minutes, but after that it reports an error:
Error: Checksum Mismatch
How do I solve this problem?
var util = require('util');
var SerialPort = require('serialport').SerialPort;
var xbee_api = require('xbee-api');
var C = xbee_api.constants;
var xbeeAPI = new xbee_api.XBeeAPI({
api_mode: 1
});
var serialport = new SerialPort("COM19", {
baudrate: 57600,
parser: xbeeAPI.rawParser()
});
serialport.on("open", function() {
var frame_obj = {
type: 0x10, // xbee_api.constants.FRAME_TYPE.ZIGBEE_TRANSMIT_REQUEST
id: 0x01, // Optional, nextFrameId() is called per default
destination64: "0013a200400a0127",
destination16: "fffe", // Optional, "fffe" is default
broadcastRadius: 0x00, // Optional, 0x00 is default
options: 0x00, // Optional, 0x00 is default
data: "TxData0A" // Can either be a string or byte array.
};
serialport.write(xbeeAPI.buildFrame(frame_obj));
});
// All frames parsed by the XBee will be emitted here
xbeeAPI.on("frame_object", function(frame) {
console.log(">>", frame);
});
Is it possible to print (to stdout) a hex dump of each frame sent, and the checksum frame so you can see which frame is flagged with the error? Can you monitor the serial line in some way to see what you're actually sending? How is the XBee module connected to the host? Does it use a long serial cable that could be encountering noise?
Do you always get the error after 10 packets, or does it vary? If you change the baud rate to 9600 or 115200, does the error rate stay the same, become more frequent or go away?
You probably shouldn't hard code the frame ID to be the same on every packet -- it could be contributing to the problem, and you won't know which frame had the checksum error, if they're all using the same ID. The error frame includes a field for the frame ID that generated the error.
I was having the same issue as you. The problem in my case was that in the configuration of the XBee coordinator module, I had set the API mode (Parameter AP) to be 2 (API with escaping). In the node.js code I set the API mode to be 1, as you have in your code. The API mode must be set to be the same in both or the parser will throw an error, so the fix is to set the change the code to be API 2 or change the configuration of the module to be API 1.
I'm a bit late I know but thought I'd answer in case anyone else is having the same trouble that I was!
This happens in case of a mismatch between your code configuration and the xbee module configuration, just be sure if you have configured the same API mode in both cases,then you must call the serialport parser and pass the data to the xbee parser :
serialport.on('data', function (data) {
xbeeAPI.parseRaw(data);
});
then you can deal with the received frame the way you want
xbeeAPI.on("frame_object", function(frame) { ... };
I've got the same problem when using the "ND" AT command to scan the network, the devices should send a frame that contain the ID, MAC 64 and 16 etc separately, in this case the problem appear when receiving all devices answers at the same time, specially when using more than two devices or routers, buffers will be damaged and the xbee-api parser couldn't work properly. So you need to used a higher baud rate.
The problem disappear using API 2 mode with the baud rate 57600(option 6) or 115200(option 7), it work fine for me.
I am using the ExternalInterface on Flex 3. We are actually using flex to compress a large amount of DOM data, so this is specifically being used with LARGE data.
To further investigate, if there is a limitation, is this universal? (IE. Silverlight)
First, let me state that this is being done with an application that was made by inexperienced software engineers. This is an app that we need to buy time by compressing the data so that we can build a long-term solution. We have no other options, unfortunately.
Background: This is an application that is actually a web-spreadsheet. Our long term solution is to make a Office Business Application.
No, Flash do not impose any size limits on ExternalInterface communication.
I think it does, or there is some other configuration which governs this. I was testing a file upload using FileReference object and wanted to pass the data sent from server back to hosting page via external interface call. Below is a snippet of my UPLOAD_COMPLETE_DATA event handler
private function onFileUploadCompleteData (e:DataEvent):void
{
var file:FileReference = FileReference(e.target);
Alert.show("onFileUploadCompleteData : " + e.data );
if(ExternalInterface.available && callBackOnUploadCompleteData.length > 0)
{
var data:Object = new Object();
data.FileName = file.name;
data.ServerData = e.data;
//data.ServerData = e.data.substr(0, 50);
ExternalInterface.call(callBackOnUploadCompleteData, data);
}
}
This event gets fired but the call to my javascript is never made. If I uncomment the line which trims the returned data to first 50 characters, it start working and calls the javascript correctly.
Either there is a size restriction imposed by flash (10.2) or IE9 (which is what I was using), or there is something else I am missing.