julianduque / beaglebone-io

BeagleBone Black IO Plugin for Johnny-Five
77 stars 29 forks source link

Unable to configure Debian 9.2 on a Beaglebone Black to use i2c with beaglebone-io and Jonny Five #71

Closed totem415 closed 6 years ago

totem415 commented 6 years ago

I'm trying to configure my system to use i2c with beaglebone-io and Johnny Five node modules.

This issue is stemming from another thread that seems to have gotten its water very muddy with different stuff. So I'm starting fresh with my current situation. Also I'm getting a little desperate to fix this, so I thought I'd put all of the latest info in one place.

I'm trying to activate i2c bus 2 (pins p9_19 and p9_20). This worked on a previous beagle bone black system but I have not been able to correctly configure the new system to work where i can see an arduino I have attached and set up as a slave at address 0x0c (12).

Formerly, I was attempting to make this line work in uEnv.txt:

uboot_overlay_addr4=/lib/firmware/BB-I2C2-00A0.dtbo

But I've switched over to using these:

config-pin P9.19 i2c
config-pin P9.20 i2c

...though I've tried both and neither one seems to work.

I am running Debian 9.2.

I have modified:

/opt/source/bb.org-overlays/src/arm/BB-12C2-00A0.dts

as follows:

        fragment@0 {
                target = <&ocp>;
                __overlay__ {
                        P9_19_pinmux { status = "i2c2_scl"; };  /* disabled or  i2c2_scl */
                        P9_20_pinmux { status = "i2c2_sda"; };  /* disabled or  i2c2_sda */
                };
        };

        fragment@1 {
                target = <&am33xx_pinmux>;
                __overlay__ {
                        bb_i2c2_pins: pinmux_bb_i2c2_pins {
                                pinctrl-single,pins = <
                                        BONE_P9_20 0x73 (PIN_INPUT_PULLUP | MUX_MODE2)  /* i2c2_sda, SLEWCTRL_SLOW | INPUT_PULLUP | MODE3 */
                                        BONE_P9_19 0x73 (PIN_INPUT_PULLUP | MUX_MODE2)  /* i2c2_scl, SLEWCTRL_SLOW | INPUT_PULLUP | MODE3 */
                                >;
                        };
                };
        };

Here's a bunch more info about my system:

root@1UpTester:~# cat /etc/dogtag
BeagleBoard.org Debian Image 2017-10-10
root@1UpTester:~# cat /etc/debian_version
9.2
root@1UpTester:~# cat /boot/uEnv.txt
#Docs: http://elinux.org/Beagleboard:U-boot_partitioning_layout_2.0

uname_r=4.16.0-bone7
#uuid=
#dtb=

###U-Boot Overlays###
###Documentation: http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#U-Boot_Overlays
###Master Enable
enable_uboot_overlays=1
###
###Overide capes with eeprom
#uboot_overlay_addr0=/lib/firmware/<file0>.dtbo
#uboot_overlay_addr1=/lib/firmware/<file1>.dtbo
#uboot_overlay_addr2=/lib/firmware/<file2>.dtbo
#uboot_overlay_addr3=/lib/firmware/<file3>.dtbo
###
###Additional custom capes
#uboot_overlay_addr4=/lib/firmware/<file4>.dtbo
#uboot_overlay_addr5=/lib/firmware/<file5>.dtbo
#uboot_overlay_addr6=/lib/firmware/<file6>.dtbo
#uboot_overlay_addr7=/lib/firmware/<file7>.dtbo
###
###Custom Cape
#dtb_overlay=/lib/firmware/<file8>.dtbo
###
###Disable auto loading of virtual capes (emmc/video/wireless/adc)
#disable_uboot_overlay_emmc=1
#disable_uboot_overlay_video=1
#disable_uboot_overlay_audio=1
#disable_uboot_overlay_wireless=1
#disable_uboot_overlay_adc=1
###
###PRUSS OPTIONS
###pru_rproc (4.4.x-ti kernel)
#uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-4-TI-00A0.dtbo
uboot_overlay_pru=/lib/firmware/AM335X-PRU-UIO-00A0.dtbo
###pru_uio (4.4.x-ti & mainline/bone kernel)
###
###Cape Universal Enable
enable_uboot_cape_universal=1
###
###Debug: disable uboot autoload of Cape
#disable_uboot_overlay_addr0=1
#disable_uboot_overlay_addr1=1
#disable_uboot_overlay_addr2=1
#disable_uboot_overlay_addr3=1
###
###U-Boot fdt tweaks...
#uboot_fdt_buffer=0x60000
###U-Boot Overlays###

cmdline=coherent_pool=1M net.ifnames=0 quiet

#In the event of edid real failures, uncomment this next line:
#cmdline=coherent_pool=1M net.ifnames=0 quiet video=HDMI-A-1:1024x768@60e

##Example v3.8.x
#cape_disable=capemgr.disable_partno=
#cape_enable=capemgr.enable_partno=

##Example v4.1.x
#cape_disable=bone_capemgr.disable_partno=
#cape_enable=bone_capemgr.enable_partno=

#uboot_overlay_addr0=/lib/firmware/BB-UART1-00A0.dtbo
#uboot_overlay_addr1=/lib/firmware/BB-UART2-00A0.dtbo
#uboot_overlay_addr2=/lib/firmware/BB-UART4-00A0.dtbo
#uboot_overlay_addr3=/lib/firmware/BB-UART5-00A0.dtbo
#uboot_overlay_addr4=/lib/firmware/BB-I2C1-00A0.dtbo
#uboot_overlay_addr4=/lib/firmware/BB-I2C2-00A0.dtbo
disable_uboot_overlay_video=1

config-pin P9.19 i2c
config-pin P9.20 i2c

##enable Generic eMMC Flasher:
##make sure, these tools are installed: dosfstools rsync
#cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh

root@1UpTester:~# ls -l /sys/devices/platform/ocp/
total 0
drwxr-xr-x 3 root root    0 Apr 18 23:38 40300000.ocmcram
drwxrwxr-x 5 root gpio    0 Apr 18 23:38 44e07000.gpio
drwxr-xr-x 4 root root    0 Apr 18 23:38 44e09000.serial
drwxr-xr-x 4 root root    0 Apr 18 23:38 44e0b000.i2c
drwxr-xr-x 4 root root    0 Apr 18 23:38 44e0d000.tscadc
drwxr-xr-x 5 root root    0 Apr 18 23:38 44e35000.wdt
drwxr-xr-x 4 root root    0 Apr 18 23:38 44e3e000.rtc
drwxr-xr-x 9 root root    0 Apr 18 23:38 47400000.usb
drwxr-xr-x 4 root root    0 Apr 18 23:38 48022000.serial
drwxr-xr-x 4 root root    0 Apr 18 23:38 48024000.serial
drwxr-xr-x 3 root root    0 Apr 18 23:38 48042000.timer
drwxr-xr-x 3 root root    0 Apr 18 23:38 48044000.timer
drwxr-xr-x 3 root root    0 Apr 18 23:38 48046000.timer
drwxr-xr-x 3 root root    0 Apr 18 23:38 48048000.timer
drwxr-xr-x 3 root root    0 Apr 18 23:38 4804a000.timer
drwxrwxr-x 5 root gpio    0 Apr 18 23:38 4804c000.gpio
drwxr-xr-x 4 root root    0 Apr 18 23:38 48060000.mmc
drwxr-xr-x 4 root root    0 Apr 18 23:38 480c8000.mailbox
drwxr-xr-x 3 root root    0 Apr 18 23:38 480ca000.spinlock
drwxr-xr-x 4 root root    0 Apr 18 23:38 4819c000.i2c
drwxr-xr-x 4 root root    0 Apr 18 23:38 481a6000.serial
drwxr-xr-x 4 root root    0 Apr 18 23:38 481a8000.serial
drwxr-xr-x 4 root root    0 Apr 18 23:38 481aa000.serial
drwxrwxr-x 5 root gpio    0 Apr 18 23:38 481ac000.gpio
drwxrwxr-x 5 root gpio    0 Apr 18 23:38 481ae000.gpio
drwxr-xr-x 4 root root    0 Apr 18 23:38 481cc000.can
drwxr-xr-x 4 root root    0 Apr 18 23:38 481d0000.can
drwxr-xr-x 4 root root    0 Apr 18 23:38 481d8000.mmc
drwxr-xr-x 3 root root    0 Apr 18 23:38 48310000.rng
drwxr-xr-x 4 root root    0 Apr 18 23:38 49000000.edma
drwxr-xr-x 3 root root    0 Apr 18 23:38 49800000.tptc
drwxr-xr-x 3 root root    0 Apr 18 23:38 49900000.tptc
drwxr-xr-x 3 root root    0 Apr 18 23:38 49a00000.tptc
drwxr-xr-x 7 root root    0 Apr 18 23:38 4a100000.ethernet
drwxr-xr-x 4 root root    0 Apr 18 23:38 4a300000.pruss
drwxr-xr-x 3 root root    0 Apr 18 23:38 4c000000.emif
drwxr-xr-x 3 root root    0 Apr 18 23:38 53100000.sham
drwxr-xr-x 3 root root    0 Apr 18 23:38 53500000.aes
drwxr-xr-x 3 root root    0 Apr 18 23:38 56000000.sgx
-rw-r--r-- 1 root root 4096 Apr 18 23:41 driver_override
-r--r--r-- 1 root root 4096 Apr 18 23:41 modalias
drwxr-xr-x 3 root root    0 Apr 18 23:38 ocp:cape-universal
drwxr-xr-x 6 root root    0 Apr 18 23:38 ocp:l4_wkup@44c00000
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_07_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_08_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_09_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_10_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_11_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_12_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_13_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_14_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_15_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_16_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_17_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_18_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_19_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_26_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_27_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_28_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_29_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_30_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_31_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_32_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_33_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_34_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_35_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_36_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_37_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_38_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_39_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_40_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_41_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_42_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_43_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_44_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_45_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P8_46_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_11_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_12_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_13_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_14_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_15_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_16_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_17_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_18_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_19_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_20_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_21_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_22_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_23_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_24_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_25_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_26_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_27_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_28_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_29_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_30_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_31_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_41_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_42_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_91_pinmux
drwxrwxr-x 3 root gpio    0 Apr 18 23:38 ocp:P9_92_pinmux
lrwxrwxrwx 1 root root    0 Apr 18 23:41 of_node -> ../../../firmware/devicetree/base/ocp
drwxr-xr-x 2 root root    0 Apr 18 23:41 power
lrwxrwxrwx 1 root root    0 Apr 18 23:38 subsystem -> ../../../bus/platform
-rw-r--r-- 1 root root 4096 Apr 18 23:38 uevent
root@1UpTester:~# sudo /opt/scripts/tools/version.sh
sudo: unable to resolve host 1UpTester
git:/opt/scripts/:[d36fe9a7be9ebfc872b10a470e904ab4c61c4516]
eeprom:[A335BNLT00C05014BBBK09A6]
dogtag:[BeagleBoard.org Debian Image 2017-10-10]
bootloader:[eMMC-(default)]:[/dev/mmcblk1]:[U-Boot 2018.03-00002-gac9cce7c6a]
kernel:[4.16.0-bone7]
nodejs:[v6.11.4]
uboot_overlay_options:[enable_uboot_overlays=1]
uboot_overlay_options:[uboot_overlay_pru=/lib/firmware/AM335X-PRU-UIO-00A0.dtbo]
uboot_overlay_options:[enable_uboot_cape_universal=1]
uboot_overlay_options:[disable_uboot_overlay_video=1]
pkg:[bb-cape-overlays]:[4.4.20171009.0-0rcnee1~stretch+20171009]
pkg:[bb-wl18xx-firmware]:[1.20170829-0rcnee1~stretch+20170829]
pkg:[firmware-ti-connectivity]:[20170823-1rcnee0~stretch+20170830]

One more thing I think is a clue. On boot it seems to be waiting for 'bus ready' for i2c2 which never happens:

root@1UpTester:~# dmesg | grep i2c
[    0.501649] omap_i2c 44e0b000.i2c: could not find pctldev for node /ocp/l4_wkup@44c00000/scm@210000/pinmux@800/pinmux_i2c0_pins, deferring probe
[    0.503106] omap_i2c 4819c000.i2c: bus 2 rev0.11 at 100 kHz
[    1.938758] omap_i2c 4819c000.i2c: timeout waiting for bus ready
[    2.946752] omap_i2c 4819c000.i2c: timeout waiting for bus ready
[    3.954750] omap_i2c 4819c000.i2c: timeout waiting for bus ready
[    4.962750] omap_i2c 4819c000.i2c: timeout waiting for bus ready
[    5.122484] i2c /dev entries driver
[    5.293492] input: tps65217_pwr_but as /devices/platform/ocp/44e0b000.i2c/i2c-0/0-0024/tps65217-pwrbutton/input/input0
[    5.295097] omap_i2c 44e0b000.i2c: bus 0 rev0.11 at 400 kHz
[  126.211695] omap_i2c 4819c000.i2c: timeout waiting for bus ready
[  127.219510] omap_i2c 4819c000.i2c: timeout waiting for bus ready
[  128.227326] omap_i2c 4819c000.i2c: timeout waiting for bus ready
[  129.235147] omap_i2c 4819c000.i2c: timeout waiting for bus ready
[  130.242963] omap_i2c 4819c000.i2c: timeout waiting for bus ready
[  131.250790] omap_i2c 4819c000.i2c: timeout waiting for bus ready
[  132.258632] omap_i2c 4819c000.i2c: timeout waiting for bus ready
[  133.266480] omap_i2c 4819c000.i2c: timeout waiting for bus ready

Any advice is greatly appreciated. I'm not trying to do anything fancy on this system in terms of hardware, I just need a bunch of GPIO pins and i2c bus 2 (P9_19 & P9_20).

Thanks!

-roger

fivdi commented 6 years ago

I'd suggest going back to square one and taking things from there.

fivdi commented 6 years ago

/config/boot.txt above should be /boot/uEnv.txt.

totem415 commented 6 years ago

Hi Fivdi.

OK, sorry I moved to Debian 9.3 as you mentioned, no modification whatsoever to uEnv.txt and I still get the same problem.

Here's my Node JS program:

var five = require('johnny-five');
var BeagleBone = require('beaglebone-io');

var board = new five.Board({
    io: new BeagleBone()
});

var write;
board.on('ready', function() {
    write = (message) => {
        board.i2cWrite(0x0c, Array.from(message, c => c.charCodeAt(0))); 
    };
    board.i2cConfig({address:0x0c});  
    board.repl.inject({ write });
    write("first message");
});

Here's my error:

root@beaglebone:/var/lib/cloud9/MercuryDesign/trunk# node i2cTest2
1524706314862 Available BeagleBone-IO
1524706314933 Connected BeagleBone-IO
1524706314994 Repl Initialized
>> fs.js:796
    return binding.writeBuffer(fd, buffer, offset, length, position);
                   ^

Error: EBUSY: resource busy or locked, write
    at Error (native)
    at Object.fs.writeSync (fs.js:796:20)
    at Bus.i2cWriteSync (/var/lib/cloud9/MercuryDesign/trunk/node_modules/i2c-bus/i2c-bus.js:348:13)
    at BeagleBone.LinuxIO.i2cWrite (/var/lib/cloud9/MercuryDesign/trunk/node_modules/linux-io/lib/linux-io.js:357:9)
    at Board.(anonymous function) [as i2cWrite] (/var/lib/cloud9/MercuryDesign/trunk/node_modules/johnny-five/lib/board.js:502:21)
    at write (/var/lib/cloud9/MercuryDesign/trunk/i2cTest2.js:12:15)
    at Board.<anonymous> (/var/lib/cloud9/MercuryDesign/trunk/i2cTest2.js:17:5)
    at emitNone (events.js:91:20)
    at Board.emit (events.js:185:7)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)

Note: here is the line that is causing the error (line 12 of i2cTest2.js:

board.i2cWrite(0x0c, Array.from(message, c => c.charCodeAt(0)));

I'm now hooked up to the Arduino with 5 kOhm pullup resistors. No dice. I've already replaced all of the wiring and tested the old . . . it was working.

totem415 commented 6 years ago

One more thing.

Just as a reality check, I change the address of my i2c device to 0x0b (wrong address) and it's very interesting that I get a different error message when I run that:

root@beaglebone:/var/lib/cloud9/MercuryDesign/trunk# node i2cTest2
1524707437946 Available BeagleBone-IO
1524707438017 Connected BeagleBone-IO
1524707438079 Repl Initialized
>> /var/lib/cloud9/MercuryDesign/trunk/node_modules/linux-io/lib/linux-io.js:357
    i2c.i2cWriteSync(address, buffer.length, buffer);
       ^

TypeError: Cannot read property 'i2cWriteSync' of undefined
    at BeagleBone.LinuxIO.i2cWrite (/var/lib/cloud9/MercuryDesign/trunk/node_modules/linux-io/lib/linux-io.js:357:8)
    at Board.(anonymous function) [as i2cWrite] (/var/lib/cloud9/MercuryDesign/trunk/node_modules/johnny-five/lib/board.js:502:21)
    at write (/var/lib/cloud9/MercuryDesign/trunk/i2cTest2.js:13:15)
    at Board.<anonymous> (/var/lib/cloud9/MercuryDesign/trunk/i2cTest2.js:18:5)
    at emitNone (events.js:91:20)
    at Board.emit (events.js:185:7)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickDomainCallback (internal/process/next_tick.js:128:9)

So it seems that it's getting farther (and a different error) when you give it the correct address which implies that it's actually connected and trying to communicate.

One more piece of info:

oot@beaglebone:/var/lib/cloud9/MercuryDesign/trunk# i2cdetect -r 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2 using read byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- UU UU UU UU -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
root@beaglebone:/var/lib/cloud9/MercuryDesign/trunk#

The device at 0x0c isn't appearing here either.

totem415 commented 6 years ago

Hi.

OK, just as a reality check, I replaced the Arduino I have been trying to talk to (that used to work great) with a different Arduino that I had lying around. I have a very simple program that's running that would at least print something to the serial monitor if something came in.

Using the same Node JS tester program pasted in above, I tried to send a message to the new Arduino and I get a different error (interesting!):

root@1upTester:/var/lib/cloud9/MercuryDesign/trunk# node i2cTest2
1524768389568 Available BeagleBone-IO
1524768389639 Connected BeagleBone-IO
1524768389701 Repl Initialized
>> fs.js:796
    return binding.writeBuffer(fd, buffer, offset, length, position);
                   ^

Error: ETIMEDOUT: connection timed out, write
    at Error (native)
    at Object.fs.writeSync (fs.js:796:20)
    at Bus.i2cWriteSync (/var/lib/cloud9/MercuryDesign/trunk/node_modules/i2c-bus/i2c-bus.js:348:13)
    at BeagleBone.LinuxIO.i2cWrite (/var/lib/cloud9/MercuryDesign/trunk/node_modules/linux-io/lib/linux-io.js:357:9)
    at Board.(anonymous function) [as i2cWrite] (/var/lib/cloud9/MercuryDesign/trunk/node_modules/johnny-five/lib/board.js:502:21)
    at write (/var/lib/cloud9/MercuryDesign/trunk/i2cTest2.js:13:15)
    at Board.<anonymous> (/var/lib/cloud9/MercuryDesign/trunk/i2cTest2.js:18:5)
    at emitNone (events.js:91:20)
    at Board.emit (events.js:185:7)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)

Note that I tried this both with and without pullup resistors in my circuit. Same error both ways.

Any help would be appreciated. Thanks.

fivdi commented 6 years ago

Please post the Arduino sketch.

fivdi commented 6 years ago

Also, please post the output of

sudo /opt/scripts/tools/version.sh
cat /boot/uEnv.txt
ls -l /sys/devices/platform/ocp/
totem415 commented 6 years ago

Thanks a million for taking a look, @fivdi.

Arduino Sketch:

#include "Arduino.h"
#include <string.h>
#include <stdio.h>
#include <Wire.h>
//#include "I2C_Anything.h"

// this is the i2c 7-bit bus address assignment for a slave:
#define CTRL_I2C_ADDR 11  

// i2c variables:
const int maxlength = 72;
char buffer[maxlength];
char printable[maxlength];
int received = 0;
char i2cCmdResponse[maxlength];
const int RESP_BYTES_COUNT = 64;
const int REPORT_IMPULSE_PIN = 2;

void setup() {
  digitalWrite(13,HIGH);  //13 is the led pin on the Arduino Uno

  Serial.begin(115200);   // RAC: Mechauino setup for Serial instead of Serial (for Serial Monitor)
  delay(3000); 
  //i2c:
  Wire.begin(CTRL_I2C_ADDR);       // join i2c bus with address #11 or 0x0b
  Wire.onReceive(receiveI2CEvent); // register event
  Wire.onRequest(requestI2CEvent); // register event
  pinMode(REPORT_IMPULSE_PIN, OUTPUT); 

  Serial.println("i2c tester initialization complete.  Listening for i2c events over the wire.");
  digitalWrite(13, LOW);
}

void loop() {
}

// Message from i2c Master (no response)
void receiveI2CEvent(int howMany) {
  received = howMany;
  memset(buffer, 0, maxlength);
  for (int i = 0; i < howMany; i++) {
    buffer[i] = Wire.read();
  }
  if (received > 0) {
    memcpy(printable, buffer, maxlength);
    for (int i = 0; i < received; i++) {
      Serial.print(printable[i]);
    }
    Serial.println(""); 
    received = 0;  
  }
}

// Requested bytes from i2c Master (send response)
void requestI2CEvent() {
  Serial.println("requestEvent() called");
  Wire.write("thanks");  // 6 characters
}

And here's the other stuff you were asking for:

root@1upTester:/home/debian# /opt/scripts/tools/version.sh
git:/opt/scripts/:[e307a944e0be0610ff5296e0abe4ad31a6e70daa]
eeprom:[A335BNLT00C05014BBBK09A6]
model:[TI_AM335x_BeagleBone_Black]
dogtag:[BeagleBoard.org Debian Image 2018-03-05]
bootloader:[microSD-(push-button)]:[/dev/mmcblk0]:[U-Boot 2018.01-00002-ge9ff418fb8]:[location: dd MBR]
bootloader:[eMMC-(default)]:[/dev/mmcblk1]:[U-Boot 2018.01-00002-ge9ff418fb8]:[location: dd MBR]
kernel:[4.9.82-ti-r102]
nodejs:[v6.13.0]
uboot_overlay_options:[enable_uboot_overlays=1]
uboot_overlay_options:[enable_uboot_cape_universal=1]
pkg:[bb-cape-overlays]:[4.4.20180305.0-0rcnee0~stretch+20180305]
pkg:[bb-wl18xx-firmware]:[1.20170829-0rcnee2~stretch+20180104]
pkg:[firmware-ti-connectivity]:[20170823-1rcnee0~stretch+20170830]
groups:[debian : debian adm kmem dialout cdrom floppy audio dip video plugdev users systemd-journal i2c bluetooth netdev cloud9ide gpio pwm eqep admin spi tisdk weston-launch xenomai]
cmdline:[console=ttyO0,115200n8 bone_capemgr.uboot_capemgr_enabled=1 root=/dev/mmcblk0p1 ro rootfstype=ext4 rootwait coherent_pool=1M net.ifnames=0 quiet]
dmesg | grep pinctrl-single
[    1.419494] pinctrl-single 44e10800.pinmux: 142 pins at pa f9e10800 size 568
dmesg | grep gpio-of-helper
[    1.426567] gpio-of-helper ocp:cape-universal: ready
END

root@1upTester:/home/debian# cat /boot/uEnv.txt
#Docs: http://elinux.org/Beagleboard:U-boot_partitioning_layout_2.0

uname_r=4.9.82-ti-r102
#uuid=
#dtb=

###U-Boot Overlays###
###Documentation: http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#U-Boot_Overlays
###Master Enable
enable_uboot_overlays=1
###
###Overide capes with eeprom
#uboot_overlay_addr0=/lib/firmware/<file0>.dtbo
#uboot_overlay_addr1=/lib/firmware/<file1>.dtbo
#uboot_overlay_addr2=/lib/firmware/<file2>.dtbo
#uboot_overlay_addr3=/lib/firmware/<file3>.dtbo
###
###Additional custom capes
#uboot_overlay_addr4=/lib/firmware/<file4>.dtbo
#uboot_overlay_addr5=/lib/firmware/<file5>.dtbo
#uboot_overlay_addr6=/lib/firmware/<file6>.dtbo
#uboot_overlay_addr7=/lib/firmware/<file7>.dtbo
###
###Custom Cape
#dtb_overlay=/lib/firmware/<file8>.dtbo
###
###Disable auto loading of virtual capes (emmc/video/wireless/adc)
#disable_uboot_overlay_emmc=1
#disable_uboot_overlay_video=1
#disable_uboot_overlay_audio=1
#disable_uboot_overlay_wireless=1
#disable_uboot_overlay_adc=1
###
###PRUSS OPTIONS
###pru_rproc (4.4.x-ti kernel)
#uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-4-TI-00A0.dtbo
###pru_uio (4.4.x-ti, 4.14.x-ti & mainline/bone kernel)
#uboot_overlay_pru=/lib/firmware/AM335X-PRU-UIO-00A0.dtbo
###
###Cape Universal Enable
enable_uboot_cape_universal=1
###
###Debug: disable uboot autoload of Cape
#disable_uboot_overlay_addr0=1
#disable_uboot_overlay_addr1=1
#disable_uboot_overlay_addr2=1
#disable_uboot_overlay_addr3=1
###
###U-Boot fdt tweaks... (60000 = 384KB)
#uboot_fdt_buffer=0x60000
###U-Boot Overlays###

cmdline=coherent_pool=1M net.ifnames=0 quiet

#In the event of edid real failures, uncomment this next line:
#cmdline=coherent_pool=1M net.ifnames=0 quiet video=HDMI-A-1:1024x768@60e

##enable Generic eMMC Flasher:
##make sure, these tools are installed: dosfstools rsync
#cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh

root@1upTester:/home/debian# ls -l /sys/devices/platform/ocp/
total 0
drwxr-xr-x 3 root root    0 Jan  1  2000 40300000.ocmcram
drwxrwxr-x 5 root gpio    0 Jan  1  2000 44e07000.gpio
drwxr-xr-x 4 root root    0 Jan  1  2000 44e09000.serial
drwxr-xr-x 4 root root    0 Jan  1  2000 44e0b000.i2c
drwxr-xr-x 4 root root    0 Jan  1  2000 44e0d000.tscadc
drwxr-xr-x 5 root root    0 Jan  1  2000 44e35000.wdt
drwxr-xr-x 4 root root    0 Jan  1  2000 44e3e000.rtc
drwxr-xr-x 9 root root    0 Jan  1  2000 47400000.usb
drwxr-xr-x 4 root root    0 Jan  1  2000 48022000.serial
drwxr-xr-x 4 root root    0 Jan  1  2000 48024000.serial
drwxr-xr-x 4 root root    0 Jan  1  2000 4802a000.i2c
drwxr-xr-x 4 root root    0 Jan  1  2000 48030000.spi
drwxr-xr-x 3 root root    0 Jan  1  2000 48038000.mcasp
drwxr-xr-x 3 root root    0 Jan  1  2000 48042000.timer
drwxr-xr-x 3 root root    0 Jan  1  2000 48044000.timer
drwxr-xr-x 3 root root    0 Jan  1  2000 48046000.timer
drwxr-xr-x 3 root root    0 Jan  1  2000 48048000.timer
drwxr-xr-x 3 root root    0 Jan  1  2000 4804a000.timer
drwxrwxr-x 5 root gpio    0 Jan  1  2000 4804c000.gpio
drwxr-xr-x 4 root root    0 Jan  1  2000 48060000.mmc
drwxr-xr-x 4 root root    0 Jan  1  2000 480c8000.mailbox
drwxr-xr-x 3 root root    0 Jan  1  2000 480ca000.spinlock
drwxr-xr-x 4 root root    0 Jan  1  2000 4819c000.i2c
drwxr-xr-x 4 root root    0 Jan  1  2000 481a0000.spi
drwxr-xr-x 4 root root    0 Jan  1  2000 481a8000.serial
drwxrwxr-x 5 root gpio    0 Jan  1  2000 481ac000.gpio
drwxrwxr-x 5 root gpio    0 Jan  1  2000 481ae000.gpio
drwxr-xr-x 4 root root    0 Jan  1  2000 481cc000.can
drwxr-xr-x 4 root root    0 Jan  1  2000 481d0000.can
drwxr-xr-x 4 root root    0 Jan  1  2000 481d8000.mmc
drwxr-xr-x 6 root root    0 Jan  1  2000 48300000.epwmss
drwxr-xr-x 5 root root    0 Jan  1  2000 48302000.epwmss
drwxr-xr-x 6 root root    0 Jan  1  2000 48304000.epwmss
drwxr-xr-x 5 root root    0 Jan  1  2000 4830e000.lcdc
drwxr-xr-x 3 root root    0 Jan  1  2000 48310000.rng
drwxr-xr-x 4 root root    0 Jan  1  2000 49000000.edma
drwxr-xr-x 3 root root    0 Jan  1  2000 49800000.tptc
drwxr-xr-x 3 root root    0 Jan  1  2000 49900000.tptc
drwxr-xr-x 3 root root    0 Jan  1  2000 49a00000.tptc
drwxr-xr-x 7 root root    0 Jan  1  2000 4a100000.ethernet
drwxr-xr-x 4 root root    0 Jan  1  2000 4a326000.pruss-soc-bus
drwxr-xr-x 3 root root    0 Jan  1  2000 4c000000.emif
drwxr-xr-x 3 root root    0 Jan  1  2000 53100000.sham
drwxr-xr-x 3 root root    0 Jan  1  2000 53500000.aes
drwxr-xr-x 3 root root    0 Jan  1  2000 56000000.sgx
-rw-r--r-- 1 root root 4096 Apr 26 20:13 driver_override
-r--r--r-- 1 root root 4096 Apr 26 20:13 modalias
drwxr-xr-x 3 root root    0 Jan  1  2000 ocp:cape-universal
drwxr-xr-x 6 root root    0 Jan  1  2000 ocp:l4_wkup@44c00000
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P8_07_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P8_08_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P8_09_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P8_10_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P8_11_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P8_12_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P8_13_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P8_14_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P8_15_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P8_16_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P8_17_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P8_18_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P8_19_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P8_26_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_11_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_12_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_13_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_14_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_15_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_16_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_17_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_18_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_19_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_20_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_21_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_22_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_23_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_24_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_26_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_27_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_30_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_41_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_42_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_91_pinmux
drwxrwxr-x 3 root gpio    0 Jan  1  2000 ocp:P9_92_pinmux
lrwxrwxrwx 1 root root    0 Apr 26 20:13 of_node -> ../../../firmware/devicetree/base/ocp
drwxr-xr-x 2 root root    0 Apr 26 20:13 power
lrwxrwxrwx 1 root root    0 Jan  1  2000 subsystem -> ../../../bus/platform
-rw-r--r-- 1 root root 4096 Jan  1  2000 uevent
totem415 commented 6 years ago

Please note that I changed the address in my node js test app to connect with 0x0b for the Arduino sketch above.

fivdi commented 6 years ago

I tried your code out and everything works correctly for me.

debian@beaglebone:~/beaglebone-io$ i2cdetect -y -r 2
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- 0b -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- UU UU UU UU -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
debian@beaglebone:~/beaglebone-io$ cat t.js
var five = require('johnny-five');
var BeagleBone = require('beaglebone-io');

var board = new five.Board({
    io: new BeagleBone()
});

var write;
board.on('ready', function() {
    write = (message) => {
        board.i2cWrite(0x0b, Array.from(message, c => c.charCodeAt(0))); 
    };
    board.i2cConfig({address:0x0b});  
    board.repl.inject({ write });
    write("first message");
});
debian@beaglebone:~/beaglebone-io$ node t.js
1524778408291 Available BeagleBone-IO  
1524778408345 Connected BeagleBone-IO  
1524778408416 Repl Initialized  
>> 

The output on the Arduino serial monitor:

requestEvent() called
first message

Note that it was necessary to use external 4.7K pullup resistors on SDA and SCL. (Pullup to 3.3V.) It didn't work without the external pullups. Also, don't forget to connect 0V on the Arduino and BeagleBone Black.

totem415 commented 6 years ago

No kidding.

I'm currently using 5K resistor (all I had around) but I figure it's got to be close enough.

Regarding the 0V, do you mean I should connect the ground pins on the 2 boards to each other?

Thanks so much for taking the time to do this. Maybe I have a bad wire or something? Not sure, but it gives me some stuff to try.

-roger

fivdi commented 6 years ago

I'm currently using 5K resistor (all I had around) but I figure it's got to be close enough.

Correct.

Regarding the 0V, do you mean I should connect the ground pins on the 2 boards to each other?

Yes.

totem415 commented 6 years ago

Hi @fivdi .

OK, so after fooling around with the wires a bit I did get the thing working. Yay! Closing ticket.

Sadly I haven't been able to get the original Arduino Zero to show up yet. I'm still replacing wires and such, but clearly at this point it's not beaglebone-io's fault.

Thank you so much for helping me out with this, @fivdi . You are really awesome.

-roger