hybridgroup / cylon-i2c

Cylon.js drivers for i2c devices
http://cylonjs.com
Other
11 stars 21 forks source link

Driver MPU6050 not working as expected. #19

Closed edgarsilva closed 9 years ago

edgarsilva commented 10 years ago

Hello! I'm starting with Cylon, I'm testing with arduino and mpu6050, but I am getting this error below. Any idea?

C: \ Users \ Marcelo \ node_modules \ cylon-i2c \ lib \ mpu6050.js: 84 var x = makeSignedInteger (data [0], data [1]), ^ TypeError: Can not read property '0 'of null at C: \ Users \ Marcelo \ node_modules \ cylon-i2c \ lib \ mpu6050.js: 84:36 at null (C:. \ Users \ Marcelo \ node_modules \ cylon-Firmata \ lib \ Firmata . js: 103:5) at g (Events.js: 180:16) emit at (Events.js: 95:17) at Object.SYSEX_RESPONSE (anonymous function) the 119 at SerialPort (C:. \ Users \ Marcelo \ nodemodules \ cylon-Firmata \ node modules \ Firmata \ lib \ firmata.js: 444:59) at SerialPort.emit (Events.js: 95:17) Object.module.exports.raw at the parser at SerialPort.options.dataCallback (C: \ Users \ Marcelo \ node_modules \ cylon-firm ata \ node_modules \ Firmata \ node_modules \ serialport \ serialport.js: 145:15)

I'm sorry if you're making a mistake in the form to request help for this error.

Moved this from cylon to cylon-i2c, @MarceloTomaz @solojavier

edgarsilva commented 10 years ago

I'm checking this now.

edgarsilva commented 10 years ago

It seems nothing is being read from the i2c port on the arduino, either you have it incorrectly wired to the arduino, or it is not returning anything, damaged?...

I'll post a small fix to prevent this error from showing but when the read data from the arduino does not exist, give it another try after that, see if maybe the arduino is taking longer than expected to initialize the i2c device.

MarceloTomaz commented 10 years ago

Thank you for your attention ! I have arduino duemilanove, A4 (SDA) A5 (SCL) this is the wiring, this correct?

edgarsilva commented 10 years ago

That is correct, do you have any other way to check if the sensor is working correctly, it seems the firmata library is not being able to read anything back from the arduino, let me give the code another read, also could you pls paste here the code you are trying to run.

edgarsilva commented 10 years ago

I've added some error handling to this branch, give that branch a try see what we get.

https://github.com/hybridgroup/cylon-i2c/tree/fix-hmc6352

You can give it a try see if the error sends anything useful, you can use something like this for testing:

var Cylon = require('cylon');

Cylon.robot({
  connection: { name: 'uno', adaptor: 'firmata', port: '/dev/ttyACM0' },
  device: { name: 'mpu6050', driver: 'mpu6050' },

  work: function(my) {
    every((1).seconds(), function() {
      my.mpu6050.getMotionAndTemp(function(err, data) {
        if (err) {
          Cylon.Logger.error('Err ===>', err);
        } else {
          Cylon.Logger.info('Data ===>', data);
        }
      });

    });
  }
}).start();

Also share your code so we can check if you have any other type of error.

edgarsilva commented 10 years ago

@MarceloTomaz Just noticed you mentioned tyou have an arduino duemilanove, have you tried other examples like the blink LED or the servo one? some arduino boards have issues with the firmata protocol try this:

  1. Upload the firmata protocol to the arduino using our gort.io CLI tool.
  2. Try the Blink LED example.
  3. Make sure you have the correct serial port on the example, you can check it out in the arduino IDE.
var Cylon = require('cylon');

Cylon.robot({
   connection: { name: 'arduino', adaptor: 'firmata', port: 'COM0' },
   device: {name: 'led', driver: 'led', pin: 13},

   work: function(my) {
     every((1).second(), function() {
        my.led.toggle();
     });
   }
}).start();
MarceloTomaz commented 10 years ago

CONSIDERATIONS

doubts -

Thank you again!

edgarsilva commented 10 years ago

@MarceloTomaz

I do not have the sensor so it is difficult for me to test this, You do not need the pull-up resistors, at least on the Arduino UNO, it already has them internally, not sure about the duemilanove, you could investigate.

Standard firmata from the Arduino IDE examples should do the job, if the blink example I provided above works then firmata is good to go and the problem is likely with the sensor connections.

Just for the sake of it, could you please paste here the exact example you are trying to run.

As far as I know you only need 4 wires from the sensor to the arduino:

VCC -> 3.3V GND -> GND SCL -> A5 SDA -> A4

The int pin serves to tell the arduino when data is available to be read, or the buffer is ready, but only when the sensor is in buffer mode, should not be the case so you can probably not connect this.

Same thing with AD0 this serves the purpose of selecting a different address, try leaving it free, not connected. The driver tries to read from the default address, so this might be causing the sensor to setup in a different address, which makes cylon not able to find it in the I2C bus.

My suggestion first of all disconnect AD0 and run the example, if still does not work connect it to Grd and run, if does not work connect to 3.3v and run again check if that fixes it.

MarceloTomaz commented 10 years ago

@edgarsilva, would you like to test, how to send a simple message to the arduino? I tested the codes that suggested above and below the test code I've been running.


var Cylon = require('cylon');

Cylon.robot({ connection: { name: 'arduino', adaptor: 'firmata', port: 'COM3' }, device: { name: 'mpu6050', driver: 'mpu6050' },

work: function(my) { every((1).seconds(), function() { my.mpu6050.getMotionAndTemp(function(data) { Logger.info(data); });

});

} }).start();


TNKS !

edgarsilva commented 10 years ago

There is a mistake in that code, cylon no longer registers a Logger, but it seems you are not getting to that point yet, the code should look like this:

var Cylon = require('cylon');

Cylon.robot({
  connection: { name: 'arduino', adaptor: 'firmata', port: 'COM3' },
  device: { name: 'mpu6050', driver: 'mpu6050' },

  work: function(my) {
    every((1).seconds(), function() {
      my.mpu6050.getMotionAndTemp(function(data) {
        Cylon.Logger.info(data); // This should be referenced through cylon
      });
    });
  }
}).start();
  1. Did you do any changes to the sensor wires and setup?
  2. Did you try the branch I provided yesterday? Give it a try with the example code I provided above, just update the serialport for the correct one.
edgarsilva commented 10 years ago

@MarceloTomaz Hey any progress here? Anything else I can help you with?

MarceloTomaz commented 10 years ago

Hello, I did some testing, but no success. I decided to use the SERIALPORT library for reading data from the arduino, I uploaded the example MPU6050_DMP6 for arduino and so could receive using NodeJS, thus ruling out a hardware failure. My experience with NodeJS is minimal, so I think I will install the entire environment for Cylon.js on a computer with linux, talvem think something may be blocking the windows. I have a new doubt, what would extrutura folders within "node_module"? believe #npm may be importing the wrong way.

Thank you!

edgarsilva commented 10 years ago

In your project, where your code javascript code that will run on node.js resides, every time you install a npm module is installed inside the node_modules folder.

So if you install cylon you should have ./node_modules/cylon and cylon will have another node_modules folder inside with its dependencies.

so if you install everything you need to run cylon on the arduino you should have:

./node_modules
  cylon/
  cylon-firmata/
  cylon-gpio/
  cylon-i2c

and also any other dependency you might be using on your code.

MarceloTomaz commented 10 years ago

My question about that is inside the module cylon-Firmata, it repeats root dependence as the extrutura? Attached image for my directory structure. cylonfirmata

MarceloTomaz commented 10 years ago

I did test with servo motor and also got error, but did not save log

edgarsilva commented 10 years ago

@MarceloTomaz The stricture is find as you have it, cylon-firmata does have a dependency for cylon, and the way npm works it has to be included in the dependency tree like that, it does not get it from the root of the project.

if you have issues with other hardware there's probably some other issue with arduino duemilanove and firmata, and not with your sensor, do you have any other arduino or microcontroler? Raspberry Pi? Beaglebone black? arduino Uno?

I don't have a duemilanove, but I know firmata has issues with the mega and I think also with the leonardo, I'll test my arduino Uno with a servo and another i2c device just to make sure there is no other bug with the libraries. but it sounds like it might be a problem with firmata and duemilanove.

deadprogram commented 10 years ago

I think this issue was addressed by the most recent release of cylon-i2c. Can you please give this a try?

MarceloTomaz commented 10 years ago

Ok deadprogram, I will test and return the results.

deadprogram commented 10 years ago

I also have an MPU6050, so I can solder it up and check it out. Do note that this is a 3.3v device, you might need a level shifter.

MarceloTomaz commented 10 years ago

Hello! I did the test, but with no success MPU6050. The example blink this works, below the return.

|======================================================================| C:\Users\marcelo.tomaz\Documents\NODEJS\cylon>node cylon_test.js I, [2014-10-04T15:45:07.310Z] INFO -- : Initializing connections. I, [2014-10-04T15:45:07.312Z] INFO -- : Initializing connection 'arduino'. D, [2014-10-04T15:45:07.313Z] DEBUG -- : Loading adaptor 'firmata'. D, [2014-10-04T15:45:07.412Z] DEBUG -- : Registering Firmata adaptor for Robot 25785 D, [2014-10-04T15:45:07.416Z] DEBUG -- : Registering i2c BlinkM driver for Robot 25785 D, [2014-10-04T15:45:07.419Z] DEBUG -- : Registering i2c HMC6352 driver for Robot 25785 D, [2014-10-04T15:45:07.420Z] DEBUG -- : Registering i2c MPL115A2 driver for Robot 25785 D, [2014-10-04T15:45:07.421Z] DEBUG -- : Registering i2c BMP180 driver for Robot 25785 D, [2014-10-04T15:45:07.422Z] DEBUG -- : Registering i2c MPU6050 driver for Robot 25785 D, [2014-10-04T15:45:07.423Z] DEBUG -- : Registering i2c LCD driver for Robot 25785 D, [2014-10-04T15:45:07.424Z] DEBUG -- : Registering i2c LSM9DS0G driver for Robot 25785 D, [2014-10-04T15:45:07.425Z] DEBUG -- : Registering i2c LSM9DS0XM driver for Robot 25785 I, [2014-10-04T15:45:07.426Z] INFO -- : Initializing devices. I, [2014-10-04T15:45:07.427Z] INFO -- : Initializing device 'mpu6050'. D, [2014-10-04T15:45:07.428Z] DEBUG -- : Loading driver 'mpu6050'. I, [2014-10-04T15:45:07.431Z] INFO -- : Starting connections. I, [2014-10-04T15:45:07.434Z] INFO -- : Connecting to 'arduino' on port com3. I, [2014-10-04T15:45:10.661Z] INFO -- : Starting devices. I, [2014-10-04T15:45:10.662Z] INFO -- : Starting device 'mpu6050'. I, [2014-10-04T15:45:10.666Z] INFO -- : Working. null null null null null null null I, [2014-10-04T15:45:29.052Z] INFO -- : Halting device 'mpu6050'. I, [2014-10-04T15:45:29.053Z] INFO -- : Disconnecting from 'arduino' on port com3.

|====================================================================|

Is there any documentation for more functions MPU6050 as "getMotionAndTemp"?

MarceloTomaz commented 10 years ago

Test image cylon

MarceloTomaz commented 10 years ago

@deadprogram , based on image, this correct?

deadprogram commented 10 years ago

@MarceloTomaz where did you get your MPU6050 from? Looks like it might take 5V in instead of 3.3V.

edgarsilva commented 9 years ago

@MarceloTomaz did you ever get this to work? have you seen any issues or tried the latest release?

janaka commented 9 years ago

Hi, The example code here http://cylonjs.com/documentation/drivers/mpu6050/ seems to have a bug.

Should be

    every((1).seconds(), function() {
      my.motionsensor.getMotionAndTemp(function(err, data) {
        console.log(data);
      });

    });

Note the err param

My environment:

This fixed my issue.

I think @edgarsilva Aug 5th tweak adding extra error handling broke the example in to doco

Thanks

janaka commented 9 years ago

@edgarsilva have fixed the documentation and sent a pull request

https://github.com/hybridgroup/cylon-site/pull/83

edgarsilva commented 9 years ago

@janaka seems to be correct, checking the PR now.

edgarsilva commented 9 years ago

Any news on this, seems the problem was solved but never logged here, I'm closing the issue.