EdAlegrid / array-gpio

array-gpio is a low-level javascript library for Raspberry Pi using a direct register control.
MIT License
16 stars 2 forks source link

i2c setTransferSpeed problem #2

Open k3341095 opened 1 year ago

k3341095 commented 1 year ago

I am using raspberry pi zero 2 w. While using i2c communication is necessary i2c.setTransferSpeed(100000) is executed error: Clock delay is higher than cdiv/2. The Raspberry Pi is stuck with an error.

I am using raspberry pi os 64bit / node.js 18 lte.

EdAlegrid commented 1 year ago

Currently I don't have an Rpi Zero 2 W device. I've been trying to get one of this but it's always out of stock. However, it has a similar CPU (Arm Cortex-A53) w/ Rpi 3 Model B+. For Rpi Zero 2 W, it is using the same setup w/ Rpi 3. And I don't have any issues in Rpi 3 using i2c (MCP9808 and ads1115/1015). This will really depend on the i2c device module you are using. As expected this library will not work with every i2c device available in the market.

Would you be able to provide the model info you get from the command $ cat /proc/cpuinfo

The error you get is from an internal function set_clock_delay that should not caused any problem since it's value is fixed. It was added as recommendation from the BCM manual for i2c operation.

As a temp solution you can disable it. Go inside the node_modules/array-gpio folder. From the node_modules/array-gpio/src folder, open the rpi.c source file and comment out set_clock_delay(1, 1) as shown below. //set_clock_delay(1, 1);

Open a console interface inside array-gpio and recompile the rpi library. $ node-gyp rebuild

If you get a result - command not found, install node-gyp as shown below. $ sudo npm i node-gyp -g

After recompilation, restart your app and check if the issue goes away. I can disable it on the next release version.

If you get a new issue, then the Rpi Zero 2 W might be using a different peripheral register addresses compared to Rpi 3. I need to check the manual for the correct i2c peripheral addresses. This will take some time.

k3341095 commented 1 year ago

Currently I don't have an Rpi Zero 2 W device. I've been trying to get one of this but it's always out of stock. However, it has a similar CPU (Arm Cortex-A53) w/ Rpi 3 Model B+. For Rpi Zero 2 W, it is using the same setup w/ Rpi 3. And I don't have any issues in Rpi 3 using i2c (MCP9808 and ads1115/1015). This will really depend on the i2c device module you are using. As expected this library will not work with every i2c device available in the market.

Would you be able to provide the model info you get from the command $ cat /proc/cpuinfo

The error you get is from an internal function set_clock_delay that should not caused any problem since it's value is fixed. It was added as recommendation from the BCM manual for i2c operation.

As a temp solution you can disable it. Go inside the node_modules/array-gpio folder. From the node_modules/array-gpio/src folder, open the rpi.c source file and comment out set_clock_delay(1, 1) as shown below. //set_clock_delay(1, 1);

Open a console interface inside array-gpio and recompile the rpi library. $ node-gyp rebuild

If you get a result - command not found, install node-gyp as shown below. $ sudo npm i node-gyp -g

After recompilation, restart your app and check if the issue goes away. I can disable it on the next release version.

If you get a new issue, then the Rpi Zero 2 W might be using a different peripheral register addresses compared to Rpi 3. I need to check the manual for the correct i2c peripheral addresses. This will take some time.

// cat /proc/cpuinfo

processor : 0 BogoMIPS : 38.40 Features : fp asimd evtstrm crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd03 CPU revision : 4

processor : 1 BogoMIPS : 38.40 Features : fp asimd evtstrm crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd03 CPU revision : 4

processor : 2 BogoMIPS : 38.40 Features : fp asimd evtstrm crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd03 CPU revision : 4

processor : 3 BogoMIPS : 38.40 Features : fp asimd evtstrm crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd03 CPU revision : 4

Hardware : BCM2835 Revision : 902120 Serial : 00000000cf7df76d Model : Raspberry Pi Zero 2 W Rev 1.0

my i2c device is vl53l0x tof sensor

pi@raspberrypi:~ $ i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- 29 -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- pi@raspberrypi:~ $

very well detected!!

I will try the method you suggested and comment again.


k3341095 commented 1 year ago

pi@raspberrypi:~/nong/node_modules/array-gpio $ node-gyp rebuild gyp info it worked if it ends with ok gyp info using node-gyp@9.3.1 gyp info using node@18.13.0 | linux | arm64 gyp info find Python using Python version 3.9.2 found at "/usr/bin/python3" gyp info spawn /usr/bin/python3 gyp info spawn args [ gyp info spawn args '/usr/lib/node_modules/node-gyp/gyp/gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'make', gyp info spawn args '-I', gyp info spawn args '/home/pi/nong/node_modules/array-gpio/build/config.gypi', gyp info spawn args '-I', gyp info spawn args '/usr/lib/node_modules/node-gyp/addon.gypi', gyp info spawn args '-I', gyp info spawn args '/home/pi/.cache/node-gyp/18.13.0/include/node/common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=/home/pi/.cache/node-gyp/18.13.0', gyp info spawn args '-Dnode_gyp_dir=/usr/lib/node_modules/node-gyp', gyp info spawn args '-Dnode_lib_file=/home/pi/.cache/node-gyp/18.13.0/<(target_arch)/node.lib', gyp info spawn args '-Dmodule_root_dir=/home/pi/nong/node_modules/array-gpio', gyp info spawn args '-Dnode_engine=v8', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'build', gyp info spawn args '-Goutput_dir=.' gyp info spawn args ] gyp info spawn make gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ] make: Entering directory '/home/pi/nong/node_modules/array-gpio/build' CC(target) Release/obj.target/node_rpi/src/rpi.o CXX(target) Release/obj.target/node_rpi/src/node_rpi.o SOLINK_MODULE(target) Release/obj.target/node_rpi.node COPY Release/node_rpi.node make: Leaving directory '/home/pi/nong/node_modules/array-gpio/build' gyp info ok pi@raspberrypi:~/nong/node_modules/array-gpio $

image

I did it the way you told me. The div/2 error is gone but Raspberry Pi crashes immediately upon launch. The network goes down and everything freezes. While the screen of my capture device turns into green noise I thought the error was related to div/2 I guess there was no connection. Same symptoms as before.

EdAlegrid commented 1 year ago

Thanks for the information. This would indicate that array-gpio is not compatible w/ Rpi Zero 2 W. I would need to get this device to work on. Though I can see that the rpi library compilation is ok. This would mean that the peripheral registers are initialized correctly. If you still have time it would be interesting to see if gpio operation is working. Just connect one led in one of the GPIO pins and turn it on and off.