Code Monkey home page Code Monkey logo

Comments (5)

oberstet avatar oberstet commented on May 26, 2024

Could you describe the parts of your setup in detail? Eg are you using AutobahnJS or AutobahnPython on the Yun? What library to talk to the Arduino side of the Yun. etc etc Ideally, also post some code - even non-working.

from crossbar-examples.

adrianardu avatar adrianardu commented on May 26, 2024

Mainly I go through the detailed setup described at the crossbar.io website (The Quick Setup makes problems with the SD card).
I installed node, node serialport on the yun. arduino-firmata and autobahn on centos (where I also installed crossbar.io) and then copied it to the yun (the node modules).
On the MCU I installed the StandardFirmataYun.ino (from 07.11.15).

For using sysex commands I add to Firmata (in the sysexCallback function):

switch(command){
  case 0x01: // LED Blink Command
    if(argc < 3) break;
    byte blink_pin;
    byte blink_count;
    blink_pin = argv[0];
    blink_count = argv[1];
    delayTime = argv[2] * 100;
  argv[1] = 22;
    pinMode(blink_pin, OUTPUT);
    byte i;
    for(i = 0; i < blink_count; i++){
      digitalWrite(blink_pin, true);
      delay(delayTime);
      digitalWrite(blink_pin, false);
      delay(delayTime);
    }
    Firmata.sendSysex(command, argc, argv); // callback
    break;

I called it with node at the command line with:

arduino.sysex(0x01, [22, 6, 6], function(r2) { 
    arduino.on('sysex', function(e){
    console.log("Data 2: ", e.command);
    console.log("data    : " + JSON.stringify(e.data));

This code works and let the led 13 blink.

I thought that I can call the I2C commands in the same way:

var device_port = '/dev/ttyATH0';
var firmata = require('arduino-firmata');
var arduino = new firmata();
arduino.on('connect', function(){
  arduino.pinMode(3, firmata.PIN_MODE_I2C);
  arduino.pinMode(2, firmata.PIN_MODE_I2C);
  arduino.sysex(0x78);  // 0x78 = I2C_CONFIG
  arduino.sysex(0x76, [0x58, 'I2C_READ'], function(x){   //0x76 = I2C_REQUEST
      arduino.on('sysex', function(e){
    console.log("Data: ", e.command);
     console.log("data    : " + JSON.stringify(e.data));
  });
  });
   console.log("connected");
});

arduino.connect(device_port);

I'm sure that the I2C sensor is working, because I tested it with another yun with standard setup.
unfortunately I have no idea how to parameterize sysex. And also If my logic is correct that I have to switch pin 2 and 3 to I2C Mode then enable I2C with I2C_CONFIG and then use command I2C_REQUEST with I2C_READ as Mode.

Here is the code with which I succesfully work without firmata (standard yun setup with bridge.h wire.h yunserver.h yunclient.h etc.)

Wire.beginTransmission(hytaddr[i]); // Begin transmission with given device on I2C bus
      Wire.requestFrom(hytaddr[i], 4); // Request 4 bytes
      // Read the bytes if they are available
      // The first two bytes are humidity the last two are temperature
      if(Wire.available() == 4) 
      {
        int b1 = Wire.read();
        int b2 = Wire.read();
        int b3 = Wire.read();
        int b4 = Wire.read();
        Wire.endTransmission(); // End transmission and release I2C bus
        // combine humidity bytes and calculate humidity
        int rawHumidity = b1 << 8 | b2;
        // compound bitwise to get 14 bit measurement first two bits
        // are status/stall bit (see intro text)
        rawHumidity = (rawHumidity &= 0x3FFF);
        humidity = 100.0 / pow(2,14) * rawHumidity;
        // combine temperature bytes and calculate temperature
        b4 = (b4 >> 2); // Mask away 2 least significant bits see HYT 221 doc
        int rawTemperature = b3 << 6 | b4;
        temperature = 165.0 / pow(2,14) * rawTemperature - 40;

Thank you for your help

from crossbar-examples.

oberstet avatar oberstet commented on May 26, 2024

Thanks for the detailed info!

I thought that I can call the I2C commands in the same way

Yes, this is actually a question. I don't have an answer as I haven't played with I2C stuff. I'd ask in the Firmata community / mailing list about that. Because this question/issue isn't related to Autobahn/Crossbar.io

If you have working code to talk to I2C from Firmata/node, adding that to the AutobahnJS/Firmata example will be trivial.

The real question hence is: "How do I talk I2C using Firmata from Node on the Yun?"

from crossbar-examples.

adrianardu avatar adrianardu commented on May 26, 2024

Yes, this sounds like the real question.

from crossbar-examples.

goeddea avatar goeddea commented on May 26, 2024

Closing this as an issue, as it's not directly related to Crossbar.io itself.

@adrianardu - If you come up with a solution, then we'd be grateful if you could tell us about it (maybe with a minimal working example). We won't investigate this ourselves at the moment, but we'd certainly want to add it to the cookbook if you get it working.

from crossbar-examples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.