Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    dtex @dtex needs a second set of eyes
    Rick Waldron
    @rwaldron
    I can look tomorrow :)
    Donovan Buck
    @dtex
    I'm stuck on something that really shouldn't be that hard. My I2C reads are not getting the data I expect. It seems like I'm reading from the wrong register or parsing the response incorrectly. I need to clean up some indentation/white space stuff that's polluting the diff real quick first.
    Donovan Buck
    @dtex
    Okay, I’ve done that. dtex/tyrion and dtex/imp-io have the latest. I’m using @briangenisio ’s MPU6050 to test with. It works great on an Arduino and the I2C reads will return values like [2, 228, 251, 40, 62, 72, 242, 16, 253, 0, 1, 70, 255, 59] when the device is at rest and room temperature. With reads from the Imp under the same conditions I’m seeing values like [0, 0, 0, 0, 1, 65, 232, 1, 0, 243, 92, 245, 128, 255] and they bounce around a lot (like I’m not reading the same registers each time). I even hard coded the read command and listened to the response in Squirrel to take out any confusion along the way but I got the same incorrect results.
    Rick Waldron
    @rwaldron
    I just pinged Matt on Twitter to come see us in here. I'm about to get in the car to drive to New York, but I can dive in with you later this afternoon
    Donovan Buck
    @dtex
    Groovy. Safe trip.
    Rick Waldron
    @rwaldron
    Thanks, I'll check in later :)
    Donovan Buck
    @dtex
    @beardedinventor I’ll build a super simple device.nut (no J5/Imp-io/Tyrion) to replicate the issue and share that. If it doesn’t replicate, that’ll help me too.
    Matt Haines
    @beardedinventor
    @dtex - cool, I have a couple devices in the office with i2c things on them, so i'm going to try testing with those
    i haven't done i2c with johnny-five though, so pointing me in the direction of how to get things setup would be great :)
    Matt Haines
    @beardedinventor
    can you show me what your i2c writes look like for the mpu6050 (either in Squirrel or in johnny-five)? might be something obvious like how you're sending addresses?
    Donovan Buck
    @dtex
    @beardedinventor Sure, but it’s read I’m wrestling with
    i2c_addr = pin[0] << 1; // where pin[0] = 0x68, the 7-bit address
    register = “0x3B"; // Where 0x3B is the register address
    numbytes = pin[2].tointeger(); // pin[2] = 14
    
    local result = i2c.read(i2c_addr, register, numbytes);
    Writes are working really well already.
    Matt Haines
    @beardedinventor
    oh, sorry i read that totally wrong..
    Donovan Buck
    @dtex
    Oh wait a minute...
    register = “0x3B”; is actually register = 0x3B.tostring();
    So, all
    i2c_addr = pin[0] << 1;
    register = 0x3B.tostring();
    numbytes = pin[2].tointeger();
    
    local result = i2c.read(i2c_addr, register, numbytes);
    Matt Haines
    @beardedinventor
    oh, geeze
    this should actually be an easy fix (for your squirrel)
    Donovan Buck
    @dtex
    :+1:
    Matt Haines
    @beardedinventor
    you want to change the register address you're reading from to "\x3B"
    Donovan Buck
    @dtex
    I’ve tried that, but I get this error when I do:
    2015-01-17 11:30:50 UTC-6    [Agent]    ERROR: cannot convert the string
    2015-01-17 11:30:50 UTC-6    [Agent]    ERROR:   in unknown vimp:68
    2015-01-17 11:30:50 UTC-6    [Agent]    ERROR:   from unknown overrides:3
    2015-01-17 11:30:50 UTC-6    [Agent]    ERROR:   from unknown vimp:31
    Matt Haines
    @beardedinventor
    register = "\x3B";

    i think this should also work:

    register = 0x3B.tochar();

    Donovan Buck
    @dtex
    Both give me that error.
    This is weird:
    server.log(0x3B.tochar()); <— logs ```;```
    server.log(0x3B.tostring()); <— logs ```59```
    server.log(“\x3B"); <— logs ```;```
    Matt Haines
    @beardedinventor
    0x3B is treated as a number (just represented in hex)
    so server.log(0x3B.tostring()) is equivalent to server.log(59.tostring())
    whereas the \x00 notation (inside of quotes) is a way of building strings with hex bytes
    so you can do things like:
    local someString = "\x00\x01\x02";
    for i2c.read you want a string of characters (a ; in your case)
    Donovan Buck
    @dtex
    Got it, but I don’t see why I would get the cannot convert string with:
    local word = i2c.read(i2c_addr, "\x3B", numbytes);
    Matt Haines
    @beardedinventor
    neither do i :/ I have an identical line in my code (with the only difference being the addresses im reading from) and im not getting a string conversation error
    Donovan Buck
    @dtex
    Okay. All my stuff is still mixed in with Tyrion so let me whip up a Squirrel only approach and see if it still happens.
    Thank you for looking at this. I’ll post back tonight with the Squirrel only result
    Matt Haines
    @beardedinventor
    no problem :) i'll probably pop back in throughout the day, and also keep playing with this to see if i can figure out some johnny-five i2c stuff :)
    Matt Haines
    @beardedinventor
    @dtex - found what was going on
    register is being passed in as a string, so we need to .tointeger() it before we can .tochar() it
    (or rather, it was getting .tostring()'ed in the update function).. I updated it to look like this, and I'm getting expected results:
    i2c_addr = pin[0] << 1;
    register = pin[1];
    numbytes = pin[2].tointeger();
    
    local word = i2c.read(i2c_addr, register.tochar(), numbytes);
    Donovan Buck
    @dtex
    Awesome, thank you so much! I'm away from the computer right now but when I get home I'll fix it in Tyrion. I owe you one for sure.
    Derek Wheelden
    @frxnz
    @dtex I just finished setting up my imp. I've got the IR sensor and I just finished soldering headers to the Adafruit I2C PWM driver, so let me know if I can do anything with those to help you test
    Donovan Buck
    @dtex
    @beardedinventor Woo hoo, it works!
    @rwaldron I just need to add support for i2cReadOnce, some tests and I’m done. I also think I should explore passing the frequency to Tyrion since so many posts to the agent will never even be read.
    @frxnz It’d be helpful to test the PWM driver and make sure I didn’t break that while trying to get I2C reads working.
    Derek Wheelden
    @frxnz
    Can do. Is imp-io up to date or do you have a branch I should pull down?
    Donovan Buck
    @dtex
    You should use dtex/imp-io and dtex/Tyrion to test I2C
    Derek Wheelden
    @frxnz
    @dtex Testing the PWM driver now. Something doesn't seem quite right
    I got servo.sweep() to work once, but it the steps were kind of erratic. And now I can't get the servo to move
    Also, guessing you'll want to add this line:
    Imp.prototype.sendI2CConfig = Imp.prototype.i2cConfig;
    Derek Wheelden
    @frxnz
    It started working again, not sure what happened there. Here's a video of servo.sweep() weirdness https://www.dropbox.com/s/bvbkm8mwfpr085a/servo.mov?dl=0
    I noticed there were timing issues even with led.blink(), so may not be an I2C issue?
    All of the other servo methods seem to work fine